Skip to content

Commit

Permalink
Auto merge of #56573 - petrochenkov:macrel, r=<try>
Browse files Browse the repository at this point in the history
resolve: Relax one restriction on macro namespace

It was assumed to be necessary to resolve multi-segment macro paths reliably, but it's likely that the assumption was incorrect.
  • Loading branch information
bors committed Dec 6, 2018
2 parents cd48ce1 + de6eadb commit 1e86cd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
let unexpanded_macros = !module.unresolved_invocations.borrow().is_empty();
if let Some(binding) = resolution.binding {
if !unexpanded_macros || ns == MacroNS || restricted_shadowing {
if !unexpanded_macros || restricted_shadowing {
return check_usable(self, binding);
} else {
return Err((Undetermined, Weak::No));
Expand Down Expand Up @@ -492,14 +492,8 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
} else {
(binding, old_binding)
};
if glob_binding.def() != nonglob_binding.def() &&
ns == MacroNS && nonglob_binding.expansion != Mark::root() {
resolution.binding = Some(this.ambiguity(AmbiguityKind::GlobVsExpanded,
nonglob_binding, glob_binding));
} else {
resolution.binding = Some(nonglob_binding);
resolution.shadowed_glob = Some(glob_binding);
}
resolution.binding = Some(nonglob_binding);
resolution.shadowed_glob = Some(glob_binding);
}
(false, false) => {
if let (&NameBindingKind::Def(_, true), &NameBindingKind::Def(_, true)) =
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/macros/ambiguity-glob-vs-expanded-in-mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// compile-pass

#![feature(decl_macro)]

macro_rules! gen_mac { () => {
pub macro mac() { () }
}}

mod m1 {
pub macro mac() { 0 }
}

mod m2 {
use m1::*;

gen_mac!();
}

fn main() {
m2::mac!() // OK
}

0 comments on commit 1e86cd8

Please sign in to comment.