Skip to content

Commit 255f6c3

Browse files
committed
Address review comments
- Factor `define_extern` into a closure - Add a test for cross-crate GlobVsExpanded ambiguity
1 parent a0806fb commit 255f6c3

File tree

4 files changed

+76
-33
lines changed

4 files changed

+76
-33
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
290290
};
291291
(self.arenas.new_res_binding(res, vis, span, expansion), ambig_kind)
292292
});
293+
293294
// Record primary definitions.
295+
let define_extern = |ns| {
296+
self.define_extern(parent, ident, ns, child_index, res, vis, span, expansion, ambig)
297+
};
294298
match res {
295299
Res::Def(
296300
DefKind::Mod
@@ -307,17 +311,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
307311
_,
308312
)
309313
| Res::PrimTy(..)
310-
| Res::ToolMod => self.define_extern(
311-
parent,
312-
ident,
313-
TypeNS,
314-
child_index,
315-
res,
316-
vis,
317-
span,
318-
expansion,
319-
ambig,
320-
),
314+
| Res::ToolMod => define_extern(TypeNS),
321315
Res::Def(
322316
DefKind::Fn
323317
| DefKind::AssocFn
@@ -326,28 +320,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
326320
| DefKind::AssocConst
327321
| DefKind::Ctor(..),
328322
_,
329-
) => self.define_extern(
330-
parent,
331-
ident,
332-
ValueNS,
333-
child_index,
334-
res,
335-
vis,
336-
span,
337-
expansion,
338-
ambig,
339-
),
340-
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => self.define_extern(
341-
parent,
342-
ident,
343-
MacroNS,
344-
child_index,
345-
res,
346-
vis,
347-
span,
348-
expansion,
349-
ambig,
350-
),
323+
) => define_extern(ValueNS),
324+
Res::Def(DefKind::Macro(..), _) | Res::NonMacroAttr(..) => define_extern(MacroNS),
351325
Res::Def(
352326
DefKind::TyParam
353327
| DefKind::ConstParam
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//@ aux-crate: glob_vs_expanded=glob-vs-expanded.rs
2+
3+
fn main() {
4+
glob_vs_expanded::mac!(); //~ ERROR `mac` is ambiguous
5+
//~| WARN this was previously accepted
6+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error: `mac` is ambiguous
2+
--> $DIR/ambiguous-glob-vs-expanded-extern.rs:4:21
3+
|
4+
LL | glob_vs_expanded::mac!();
5+
| ^^^ ambiguous name
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
9+
= note: ambiguous because of multiple glob imports of a name in the same module
10+
note: `mac` could refer to the macro defined here
11+
--> $DIR/auxiliary/glob-vs-expanded.rs:18:9
12+
|
13+
LL | pub use m::*;
14+
| ^
15+
note: `mac` could also refer to the macro defined here
16+
--> $DIR/auxiliary/glob-vs-expanded.rs:18:9
17+
|
18+
LL | pub use m::*;
19+
| ^
20+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
21+
22+
error: aborting due to 1 previous error
23+
24+
Future incompatibility report: Future breakage diagnostic:
25+
error: `mac` is ambiguous
26+
--> $DIR/ambiguous-glob-vs-expanded-extern.rs:4:21
27+
|
28+
LL | glob_vs_expanded::mac!();
29+
| ^^^ ambiguous name
30+
|
31+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
32+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
33+
= note: ambiguous because of multiple glob imports of a name in the same module
34+
note: `mac` could refer to the macro defined here
35+
--> $DIR/auxiliary/glob-vs-expanded.rs:18:9
36+
|
37+
LL | pub use m::*;
38+
| ^
39+
note: `mac` could also refer to the macro defined here
40+
--> $DIR/auxiliary/glob-vs-expanded.rs:18:9
41+
|
42+
LL | pub use m::*;
43+
| ^
44+
= note: `#[deny(ambiguous_glob_imports)]` (part of `#[deny(future_incompatible)]`) on by default
45+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ edition:2018..
2+
3+
#![feature(decl_macro)]
4+
5+
mod m {
6+
// Glob import in macro namespace
7+
mod inner { pub macro mac() {} }
8+
pub use inner::*;
9+
10+
// Macro-expanded single import in macro namespace
11+
macro_rules! define_mac {
12+
() => { pub macro mac() {} }
13+
}
14+
define_mac!();
15+
}
16+
17+
// Ambiguous reexport
18+
pub use m::*;

0 commit comments

Comments
 (0)