提交 2d4e34ca 编写于 作者: B bors

Auto merge of #53778 - petrochenkov:shadrelax2, r=nikomatsakis

resolve: Relax shadowing restrictions on macro-expanded macros

Previously any macro-expanded macros weren't allowed to shadow macros from outer scopes.
Now only "more macro-expanded" macros cannot shadow "less macro-expanded" macros.
See comments to `fn may_appear_after` and added tests for more details and examples.

The functional changes are a21f6f588fc28c97533130ae44a6957b579ab58c and 46dd365ce9ca0a6b8653849b80267763c542842a, other commits are refactorings.
......@@ -946,7 +946,7 @@ fn legacy_macro_imports(&mut self, attrs: &[ast::Attribute]) -> LegacyMacroImpor
pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
pub resolver: &'a mut Resolver<'b, 'c>,
pub legacy_scope: LegacyScope<'b>,
pub current_legacy_scope: LegacyScope<'b>,
pub expansion: Mark,
}
......@@ -956,7 +956,8 @@ fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
let invocation = self.resolver.invocations[&mark];
invocation.module.set(self.resolver.current_module);
invocation.legacy_scope.set(self.legacy_scope);
invocation.parent_legacy_scope.set(self.current_legacy_scope);
invocation.output_legacy_scope.set(self.current_legacy_scope);
invocation
}
}
......@@ -982,29 +983,30 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
fn visit_item(&mut self, item: &'a Item) {
let macro_use = match item.node {
ItemKind::MacroDef(..) => {
self.resolver.define_macro(item, self.expansion, &mut self.legacy_scope);
self.resolver.define_macro(item, self.expansion, &mut self.current_legacy_scope);
return
}
ItemKind::Mac(..) => {
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(item.id));
self.current_legacy_scope = LegacyScope::Invocation(self.visit_invoc(item.id));
return
}
ItemKind::Mod(..) => self.resolver.contains_macro_use(&item.attrs),
_ => false,
};
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
let orig_current_module = self.resolver.current_module;
let orig_current_legacy_scope = self.current_legacy_scope;
self.resolver.build_reduced_graph_for_item(item, self.expansion);
visit::walk_item(self, item);
self.resolver.current_module = parent;
self.resolver.current_module = orig_current_module;
if !macro_use {
self.legacy_scope = legacy_scope;
self.current_legacy_scope = orig_current_legacy_scope;
}
}
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
if let ast::StmtKind::Mac(..) = stmt.node {
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(stmt.id));
self.current_legacy_scope = LegacyScope::Invocation(self.visit_invoc(stmt.id));
} else {
visit::walk_stmt(self, stmt);
}
......@@ -1021,11 +1023,12 @@ fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
}
fn visit_block(&mut self, block: &'a Block) {
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
let orig_current_module = self.resolver.current_module;
let orig_current_legacy_scope = self.current_legacy_scope;
self.resolver.build_reduced_graph_for_block(block, self.expansion);
visit::walk_block(self, block);
self.resolver.current_module = parent;
self.legacy_scope = legacy_scope;
self.resolver.current_module = orig_current_module;
self.current_legacy_scope = orig_current_legacy_scope;
}
fn visit_trait_item(&mut self, item: &'a TraitItem) {
......
......@@ -1177,9 +1177,7 @@ struct UseError<'a> {
}
struct AmbiguityError<'a> {
span: Span,
name: Name,
lexical: bool,
ident: Ident,
b1: &'a NameBinding<'a>,
b2: &'a NameBinding<'a>,
}
......@@ -1283,6 +1281,26 @@ fn is_macro_def(&self) -> bool {
fn descr(&self) -> &'static str {
if self.is_extern_crate() { "extern crate" } else { self.def().kind_name() }
}
// Suppose that we resolved macro invocation with `invoc_id` to binding `binding` at some
// expansion round `max(invoc_id, binding)` when they both emerged from macros.
// Then this function returns `true` if `self` may emerge from a macro *after* that
// in some later round and screw up our previously found resolution.
// See more detailed explanation in
// https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049
fn may_appear_after(&self, invoc_id: Mark, binding: &NameBinding) -> bool {
// self > max(invoc_id, binding) => !(self <= invoc_id || self <= binding)
// Expansions are partially ordered, so "may appear after" is an inversion of
// "certainly appears before or simultaneously" and includes unordered cases.
let self_parent_expansion = self.expansion;
let other_parent_expansion = binding.expansion;
let invoc_parent_expansion = invoc_id.parent();
let certainly_before_other_or_simultaneously =
other_parent_expansion.is_descendant_of(self_parent_expansion);
let certainly_before_invoc_or_simultaneously =
invoc_parent_expansion.is_descendant_of(self_parent_expansion);
!(certainly_before_other_or_simultaneously || certainly_before_invoc_or_simultaneously)
}
}
/// Interns the names of the primitive types.
......@@ -1416,8 +1434,6 @@ pub struct Resolver<'a, 'b: 'a> {
proc_mac_errors: Vec<macros::ProcMacError>,
/// crate-local macro expanded `macro_export` referred to by a module-relative path
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
/// macro-expanded `macro_rules` shadowing existing macros
disallowed_shadowing: Vec<&'a LegacyBinding<'a>>,
arenas: &'a ResolverArenas<'a>,
dummy_binding: &'a NameBinding<'a>,
......@@ -1729,7 +1745,6 @@ pub fn new(session: &'a Session,
ambiguity_errors: Vec::new(),
use_injections: Vec::new(),
proc_mac_errors: Vec::new(),
disallowed_shadowing: Vec::new(),
macro_expanded_macro_export_errors: BTreeSet::new(),
arenas,
......@@ -1815,7 +1830,7 @@ fn new_module(
self.arenas.alloc_module(module)
}
fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'a>, span: Span)
fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'a>)
-> bool /* true if an error was reported */ {
match binding.kind {
NameBindingKind::Import { directive, binding, ref used }
......@@ -1824,13 +1839,11 @@ fn record_use(&mut self, ident: Ident, ns: Namespace, binding: &'a NameBinding<'
directive.used.set(true);
self.used_imports.insert((directive.id, ns));
self.add_to_glob_map(directive.id, ident);
self.record_use(ident, ns, binding, span)
self.record_use(ident, ns, binding)
}
NameBindingKind::Import { .. } => false,
NameBindingKind::Ambiguity { b1, b2 } => {
self.ambiguity_errors.push(AmbiguityError {
span, name: ident.name, lexical: false, b1, b2,
});
self.ambiguity_errors.push(AmbiguityError { ident, b1, b2 });
true
}
_ => false
......@@ -2850,7 +2863,7 @@ fn resolve_pattern(&mut self,
Def::Const(..) if is_syntactic_ambiguity => {
// Disambiguate in favor of a unit struct/variant
// or constant pattern.
self.record_use(ident, ValueNS, binding.unwrap(), ident.span);
self.record_use(ident, ValueNS, binding.unwrap());
Some(PathResolution::new(def))
}
Def::StructCtor(..) | Def::VariantCtor(..) |
......@@ -3483,6 +3496,20 @@ fn resolve_path(
record_used: bool,
path_span: Span,
crate_lint: CrateLint,
) -> PathResult<'a> {
self.resolve_path_with_invoc_id(base_module, path, opt_ns, Mark::root(),
record_used, path_span, crate_lint)
}
fn resolve_path_with_invoc_id(
&mut self,
base_module: Option<ModuleOrUniformRoot<'a>>,
path: &[Ident],
opt_ns: Option<Namespace>, // `None` indicates a module path
invoc_id: Mark,
record_used: bool,
path_span: Span,
crate_lint: CrateLint,
) -> PathResult<'a> {
let mut module = base_module;
let mut allow_super = true;
......@@ -3572,8 +3599,9 @@ fn resolve_path(
self.resolve_ident_in_module(module, ident, ns, record_used, path_span)
} else if opt_ns == Some(MacroNS) {
assert!(ns == TypeNS);
self.resolve_lexical_macro_path_segment(ident, ns, record_used, record_used,
false, path_span).map(|(b, _)| b)
self.resolve_lexical_macro_path_segment(ident, ns, invoc_id, record_used,
record_used, false, path_span)
.map(|(binding, _)| binding)
} else {
let record_used_id =
if record_used { crate_lint.node_id().or(Some(CRATE_NODE_ID)) } else { None };
......@@ -4514,35 +4542,33 @@ fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
vis.is_accessible_from(module.normal_ancestor_id, self)
}
fn report_ambiguity_error(
&self, name: Name, span: Span, _lexical: bool,
def1: Def, is_import1: bool, is_glob1: bool, from_expansion1: bool, span1: Span,
def2: Def, is_import2: bool, _is_glob2: bool, _from_expansion2: bool, span2: Span,
) {
fn report_ambiguity_error(&self, ident: Ident, b1: &NameBinding, b2: &NameBinding) {
let participle = |is_import: bool| if is_import { "imported" } else { "defined" };
let msg1 = format!("`{}` could refer to the name {} here", name, participle(is_import1));
let msg1 =
format!("`{}` could refer to the name {} here", ident, participle(b1.is_import()));
let msg2 =
format!("`{}` could also refer to the name {} here", name, participle(is_import2));
let note = if from_expansion1 {
Some(if let Def::Macro(..) = def1 {
format!("`{}` could also refer to the name {} here", ident, participle(b2.is_import()));
let note = if b1.expansion != Mark::root() {
Some(if let Def::Macro(..) = b1.def() {
format!("macro-expanded {} do not shadow",
if is_import1 { "macro imports" } else { "macros" })
if b1.is_import() { "macro imports" } else { "macros" })
} else {
format!("macro-expanded {} do not shadow when used in a macro invocation path",
if is_import1 { "imports" } else { "items" })
if b1.is_import() { "imports" } else { "items" })
})
} else if is_glob1 {
Some(format!("consider adding an explicit import of `{}` to disambiguate", name))
} else if b1.is_glob_import() {
Some(format!("consider adding an explicit import of `{}` to disambiguate", ident))
} else {
None
};
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
err.span_note(span1, &msg1);
match def2 {
Def::Macro(..) if span2.is_dummy() =>
err.note(&format!("`{}` is also a builtin macro", name)),
_ => err.span_note(span2, &msg2),
let mut err = struct_span_err!(self.session, ident.span, E0659, "`{}` is ambiguous", ident);
err.span_label(ident.span, "ambiguous name");
err.span_note(b1.span, &msg1);
match b2.def() {
Def::Macro(..) if b2.span.is_dummy() =>
err.note(&format!("`{}` is also a builtin macro", ident)),
_ => err.span_note(b2.span, &msg2),
};
if let Some(note) = note {
err.note(&note);
......@@ -4551,7 +4577,6 @@ fn report_ambiguity_error(
}
fn report_errors(&mut self, krate: &Crate) {
self.report_shadowing_errors();
self.report_with_use_injections(krate);
self.report_proc_macro_import(krate);
let mut reported_spans = FxHashSet();
......@@ -4567,15 +4592,9 @@ fn report_errors(&mut self, krate: &Crate) {
);
}
for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {
if reported_spans.insert(span) {
self.report_ambiguity_error(
name, span, lexical,
b1.def(), b1.is_import(), b1.is_glob_import(),
b1.expansion != Mark::root(), b1.span,
b2.def(), b2.is_import(), b2.is_glob_import(),
b2.expansion != Mark::root(), b2.span,
);
for &AmbiguityError { ident, b1, b2 } in &self.ambiguity_errors {
if reported_spans.insert(ident.span) {
self.report_ambiguity_error(ident, b1, b2);
}
}
......@@ -4595,20 +4614,6 @@ fn report_with_use_injections(&mut self, krate: &Crate) {
}
}
fn report_shadowing_errors(&mut self) {
let mut reported_errors = FxHashSet();
for binding in replace(&mut self.disallowed_shadowing, Vec::new()) {
if self.resolve_legacy_scope(&binding.parent, binding.ident, false).is_some() &&
reported_errors.insert((binding.ident, binding.span)) {
let msg = format!("`{}` is already in scope", binding.ident);
self.session.struct_span_err(binding.span, &msg)
.note("macro-expanded `macro_rules!`s may not shadow \
existing macros (see RFC 1560)")
.emit();
}
}
}
fn report_conflict<'b>(&mut self,
parent: Module,
ident: Ident,
......
此差异已折叠。
......@@ -242,22 +242,19 @@ pub fn resolve_ident_in_module_unadjusted(&mut self,
if record_used {
if let Some(binding) = resolution.binding {
if let Some(shadowed_glob) = resolution.shadowed_glob {
let name = ident.name;
// Forbid expanded shadowing to avoid time travel.
if restricted_shadowing &&
binding.expansion != Mark::root() &&
ns != MacroNS && // In MacroNS, `try_define` always forbids this shadowing
binding.def() != shadowed_glob.def() {
self.ambiguity_errors.push(AmbiguityError {
span: path_span,
name,
lexical: false,
ident,
b1: binding,
b2: shadowed_glob,
});
}
}
if self.record_use(ident, ns, binding, path_span) {
if self.record_use(ident, ns, binding) {
return Ok(self.dummy_binding);
}
if !self.is_accessible(binding.vis) {
......@@ -937,7 +934,7 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
if let Ok(binding) = result[ns].get() {
all_ns_err = false;
if this.record_use(ident, ns, binding, directive.span) {
if this.record_use(ident, ns, binding) {
if let ModuleOrUniformRoot::Module(module) = module {
this.resolution(module, ident, ns).borrow_mut().binding =
Some(this.dummy_binding);
......
......@@ -966,6 +966,10 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
"the `#[rustc_test_marker]` attribute \
is used internally to track tests",
cfg_fn!(rustc_attrs))),
("rustc_transparent_macro", Whitelisted, Gated(Stability::Unstable,
"rustc_attrs",
"used internally for testing macro hygiene",
cfg_fn!(rustc_attrs))),
// RFC #2094
("nll", Whitelisted, Gated(Stability::Unstable,
......
......@@ -100,6 +100,11 @@ pub fn from_u32(raw: u32) -> Mark {
Mark(raw)
}
#[inline]
pub fn parent(self) -> Mark {
HygieneData::with(|data| data.marks[self.0 as usize].parent)
}
#[inline]
pub fn expn_info(self) -> Option<ExpnInfo> {
HygieneData::with(|data| data.marks[self.0 as usize].expn_info.clone())
......
error[E0659]: `foo` is ambiguous
--> $DIR/E0659.rs:25:5
--> $DIR/E0659.rs:25:15
|
LL | collider::foo(); //~ ERROR E0659
| ^^^^^^^^^^^^^
| ^^^ ambiguous name
|
note: `foo` could refer to the name imported here
--> $DIR/E0659.rs:20:13
......
......@@ -13,10 +13,10 @@ LL | use a::foo as other_foo; //~ ERROR the name `foo` is defined multiple t
| ^^^^^^^^^^^^^^^^^^^
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:56:9
--> $DIR/duplicate.rs:56:15
|
LL | use self::foo::bar; //~ ERROR `foo` is ambiguous
| ^^^^^^^^^^^^^^
| ^^^ ambiguous name
|
note: `foo` could refer to the name imported here
--> $DIR/duplicate.rs:53:9
......@@ -31,10 +31,10 @@ LL | use self::m2::*;
= note: consider adding an explicit import of `foo` to disambiguate
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:45:5
--> $DIR/duplicate.rs:45:8
|
LL | f::foo(); //~ ERROR `foo` is ambiguous
| ^^^^^^
| ^^^ ambiguous name
|
note: `foo` could refer to the name imported here
--> $DIR/duplicate.rs:34:13
......@@ -49,10 +49,10 @@ LL | pub use b::*;
= note: consider adding an explicit import of `foo` to disambiguate
error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:46:5
--> $DIR/duplicate.rs:46:8
|
LL | g::foo(); //~ ERROR `foo` is ambiguous
| ^^^^^^
| ^^^ ambiguous name
|
note: `foo` could refer to the name imported here
--> $DIR/duplicate.rs:39:13
......@@ -70,7 +70,7 @@ error[E0659]: `foo` is ambiguous
--> $DIR/duplicate.rs:59:9
|
LL | foo::bar(); //~ ERROR `foo` is ambiguous
| ^^^^^^^^
| ^^^ ambiguous name
|
note: `foo` could refer to the name imported here
--> $DIR/duplicate.rs:53:9
......
......@@ -2,7 +2,7 @@ error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:21:17
|
LL | let x = env!("PATH"); //~ ERROR `env` is ambiguous
| ^^^
| ^^^ ambiguous name
|
note: `env` could refer to the name imported here
--> $DIR/glob-shadowing.rs:19:9
......@@ -16,7 +16,7 @@ error[E0659]: `env` is ambiguous
--> $DIR/glob-shadowing.rs:29:21
|
LL | let x = env!("PATH"); //~ ERROR `env` is ambiguous
| ^^^
| ^^^ ambiguous name
|
note: `env` could refer to the name imported here
--> $DIR/glob-shadowing.rs:27:13
......@@ -30,7 +30,7 @@ error[E0659]: `fenv` is ambiguous
--> $DIR/glob-shadowing.rs:39:21
|
LL | let x = fenv!(); //~ ERROR `fenv` is ambiguous
| ^^^^
| ^^^^ ambiguous name
|
note: `fenv` could refer to the name imported here
--> $DIR/glob-shadowing.rs:37:13
......
......@@ -8,7 +8,7 @@ error[E0659]: `mac` is ambiguous
--> $DIR/issue-53269.rs:18:5
|
LL | mac!(); //~ ERROR `mac` is ambiguous
| ^^^
| ^^^ ambiguous name
|
note: `mac` could refer to the name defined here
--> $DIR/issue-53269.rs:13:1
......
......@@ -43,7 +43,6 @@ mod inner2 {
fn main() {
panic!(); //~ ERROR `panic` is ambiguous
//~^ ERROR `panic` is ambiguous
}
mod inner3 {
......
......@@ -2,7 +2,7 @@ error[E0659]: `exported` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:38:1
|
LL | exported!(); //~ ERROR `exported` is ambiguous
| ^^^^^^^^
| ^^^^^^^^ ambiguous name
|
note: `exported` could refer to the name defined here
--> $DIR/local-modularized-tricky-fail-1.rs:15:5
......@@ -22,10 +22,10 @@ LL | use inner1::*;
= note: macro-expanded macros do not shadow
error[E0659]: `include` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:57:1
--> $DIR/local-modularized-tricky-fail-1.rs:56:1
|
LL | include!(); //~ ERROR `include` is ambiguous
| ^^^^^^^
| ^^^^^^^ ambiguous name
|
note: `include` could refer to the name defined here
--> $DIR/local-modularized-tricky-fail-1.rs:27:5
......@@ -44,7 +44,7 @@ error[E0659]: `panic` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:45:5
|
LL | panic!(); //~ ERROR `panic` is ambiguous
| ^^^^^
| ^^^^^ ambiguous name
|
note: `panic` could refer to the name defined here
--> $DIR/local-modularized-tricky-fail-1.rs:21:5
......@@ -60,10 +60,10 @@ LL | define_panic!();
= note: macro-expanded macros do not shadow
error[E0659]: `panic` is ambiguous
--> $DIR/local-modularized-tricky-fail-1.rs:45:5
--> <panic macros>:1:13
|
LL | panic!(); //~ ERROR `panic` is ambiguous
| ^^^^^^^^^
LL | ( ) => ( { panic ! ( "explicit panic" ) } ) ; ( $ msg : expr ) => (
| ^^^^^ ambiguous name
|
note: `panic` could refer to the name defined here
--> $DIR/local-modularized-tricky-fail-1.rs:21:5
......@@ -77,7 +77,6 @@ LL | define_panic!();
| ---------------- in this macro invocation
= note: `panic` is also a builtin macro
= note: macro-expanded macros do not shadow
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 4 previous errors
......
......@@ -2,7 +2,7 @@ error[E0659]: `bar` is ambiguous
--> $DIR/macro-paths.rs:23:5
|
LL | bar::m! { //~ ERROR ambiguous
| ^^^^^^
| ^^^ ambiguous name
|
note: `bar` could refer to the name defined here
--> $DIR/macro-paths.rs:24:9
......@@ -20,7 +20,7 @@ error[E0659]: `baz` is ambiguous
--> $DIR/macro-paths.rs:33:5
|
LL | baz::m! { //~ ERROR ambiguous
| ^^^^^^
| ^^^ ambiguous name
|
note: `baz` could refer to the name defined here
--> $DIR/macro-paths.rs:34:9
......
......@@ -2,7 +2,7 @@ error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:48:5
|
LL | m!(); //~ ERROR ambiguous
| ^
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/macros.rs:46:5
......@@ -19,7 +19,7 @@ error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:26:5
|
LL | m! { //~ ERROR ambiguous
| ^
| ^ ambiguous name
|
note: `m` could refer to the name imported here
--> $DIR/macros.rs:27:13
......@@ -37,7 +37,7 @@ error[E0659]: `m` is ambiguous
--> $DIR/macros.rs:39:9
|
LL | m! { //~ ERROR ambiguous
| ^
| ^ ambiguous name
|
note: `m` could refer to the name imported here
--> $DIR/macros.rs:40:17
......
......@@ -2,7 +2,7 @@ error[E0659]: `Foo` is ambiguous
--> $DIR/rfc-1560-warning-cycle.rs:19:17
|
LL | fn f(_: Foo) {} //~ ERROR `Foo` is ambiguous
| ^^^
| ^^^ ambiguous name
|
note: `Foo` could refer to the name imported here
--> $DIR/rfc-1560-warning-cycle.rs:17:13
......
......@@ -2,7 +2,7 @@ error[E0659]: `panic` is ambiguous
--> $DIR/shadow_builtin_macros.rs:43:5
|
LL | panic!(); //~ ERROR `panic` is ambiguous
| ^^^^^
| ^^^^^ ambiguous name
|
note: `panic` could refer to the name defined here
--> $DIR/shadow_builtin_macros.rs:40:9
......@@ -19,7 +19,7 @@ error[E0659]: `panic` is ambiguous
--> $DIR/shadow_builtin_macros.rs:25:14
|
LL | fn f() { panic!(); } //~ ERROR ambiguous
| ^^^^^
| ^^^^^ ambiguous name
|
note: `panic` could refer to the name imported here
--> $DIR/shadow_builtin_macros.rs:24:9
......@@ -33,7 +33,7 @@ error[E0659]: `panic` is ambiguous
--> $DIR/shadow_builtin_macros.rs:30:14
|
LL | fn f() { panic!(); } //~ ERROR ambiguous
| ^^^^^
| ^^^^^ ambiguous name
|
note: `panic` could refer to the name imported here
--> $DIR/shadow_builtin_macros.rs:29:26
......@@ -47,7 +47,7 @@ error[E0659]: `n` is ambiguous
--> $DIR/shadow_builtin_macros.rs:59:5
|
LL | n!(); //~ ERROR ambiguous
| ^
| ^ ambiguous name
|
note: `n` could refer to the name imported here
--> $DIR/shadow_builtin_macros.rs:58:9
......
......@@ -17,3 +17,8 @@
macro_rules! inline {
() => ()
}
#[macro_export]
macro_rules! from_prelude {
() => ()
}
......@@ -2,7 +2,7 @@ error[E0659]: `std` is ambiguous
--> $DIR/macro-path-prelude-shadowing.rs:39:9
|
LL | std::panic!(); //~ ERROR `std` is ambiguous
| ^^^^^^^^^^
| ^^^ ambiguous name
|
note: `std` could refer to the name imported here
--> $DIR/macro-path-prelude-shadowing.rs:37:9
......
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-pass
// aux-build:macro-in-other-crate.rs
#![feature(decl_macro)]
macro_rules! my_include {() => {
// Outer
macro m() {}
#[macro_use(from_prelude)] extern crate macro_in_other_crate;
fn inner() {
// Inner
macro m() {}
macro_rules! from_prelude { () => {} }
// OK, both `m` and `from_prelude` are macro-expanded,
// but no more macro-expanded than their counterpart from outer scope.
m!();
from_prelude!();
}
}}
my_include!();
fn main() {}
......@@ -17,14 +17,14 @@
#[macro_use(macro_two)] extern crate two_macros;
macro_rules! m1 { () => {
macro_rules! foo { () => {} } //~ ERROR `foo` is already in scope
macro_rules! foo { () => {} }
#[macro_use] //~ ERROR `macro_two` is already in scope
extern crate two_macros as __;
}}
m1!();
foo!();
foo!(); //~ ERROR `foo` is ambiguous
macro_rules! m2 { () => {
macro_rules! foo { () => {} }
......
......@@ -9,16 +9,27 @@ LL | m1!();
|
= note: macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)
error: `foo` is already in scope
error[E0659]: `foo` is ambiguous
--> $DIR/macro-shadowing.rs:27:1
|
LL | foo!(); //~ ERROR `foo` is ambiguous
| ^^^ ambiguous name
|
note: `foo` could refer to the name defined here
--> $DIR/macro-shadowing.rs:20:5
|
LL | macro_rules! foo { () => {} } //~ ERROR `foo` is already in scope
LL | macro_rules! foo { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | m1!();
| ------ in this macro invocation
note: `foo` could also refer to the name defined here
--> $DIR/macro-shadowing.rs:15:1
|
= note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560)
LL | macro_rules! foo { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: macro-expanded macros do not shadow
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0659`.
// Legend:
// `N` - number of combination, from 0 to 4*4*4=64
// `Outer < Invoc` means that expansion that produced macro definition `Outer`
// is a strict ancestor of expansion that produced macro definition `Inner`.
// `>`, `=` and `Unordered` mean "strict descendant", "same" and
// "not in ordering relation" for parent expansions.
// `+` - possible configuration
// `-` - configuration impossible due to properties of partial ordering
// `-?` - configuration impossible due to block/scope syntax
// `+?` - configuration possible only with legacy scoping
// N | Outer ~ Invoc | Invoc ~ Inner | Outer ~ Inner | Possible |
// 1 | < | < | < | + |
// 2 | < | < | = | - |
// 3 | < | < | > | - |
// 4 | < | < | Unordered | - |
// 5 | < | = | < | + |
// 6 | < | = | = | - |
// 7 | < | = | > | - |
// 8 | < | = | Unordered | - |
// 9 | < | > | < | + |
// 10 | < | > | = | + |
// 11 | < | > | > | -? |
// 12 | < | > | Unordered | -? |
// 13 | < | Unordered | < | + |
// 14 | < | Unordered | = | - |
// 15 | < | Unordered | > | - |
// 16 | < | Unordered | Unordered | -? |
// 17 | = | < | < | + |
// 18 | = | < | = | - |
// 19 | = | < | > | - |
// 20 | = | < | Unordered | - |
// 21 | = | = | < | - |
// 22 | = | = | = | + |
// 23 | = | = | > | - |
// 24 | = | = | Unordered | - |
// 25 | = | > | < | - |
// 26 | = | > | = | - |
// 27 | = | > | > | -? |
// 28 | = | > | Unordered | - |
// 29 | = | Unordered | < | - |
// 30 | = | Unordered | = | - |
// 31 | = | Unordered | > | - |
// 32 | = | Unordered | Unordered | -? |
// 33 | > | < | < | +? |
// 34 | > | < | = | +? |
// 35 | > | < | > | +? |
// 36 | > | < | Unordered | + |
// 37 | > | = | < | - |
// 38 | > | = | = | - |
// 39 | > | = | > | + |
// 40 | > | = | Unordered | - |
// 41 | > | > | < | - |
// 42 | > | > | = | - |
// 43 | > | > | > | -? |
// 44 | > | > | Unordered | - |
// 45 | > | Unordered | < | - |
// 46 | > | Unordered | = | - |
// 47 | > | Unordered | > | -? |
// 48 | > | Unordered | Unordered | -? |
// 49 | Unordered | < | < | -? |
// 50 | Unordered | < | = | - |
// 51 | Unordered | < | > | - |
// 52 | Unordered | < | Unordered | + |
// 53 | Unordered | = | < | - |
// 54 | Unordered | = | = | - |
// 55 | Unordered | = | > | - |
// 56 | Unordered | = | Unordered | + |
// 57 | Unordered | > | < | - |
// 58 | Unordered | > | = | - |
// 59 | Unordered | > | > | + |
// 60 | Unordered | > | Unordered | + |
// 61 | Unordered | Unordered | < | +? |
// 62 | Unordered | Unordered | = | +? |
// 63 | Unordered | Unordered | > | +? |
// 64 | Unordered | Unordered | Unordered | + |
#![feature(decl_macro, rustc_attrs)]
struct Right;
// struct Wrong; // not defined
macro_rules! include { () => {
macro_rules! gen_outer { () => {
macro_rules! m { () => { Wrong } }
}}
macro_rules! gen_inner { () => {
macro_rules! m { () => { Right } }
}}
macro_rules! gen_invoc { () => {
m!()
}}
// -----------------------------------------------------------
fn check1() {
macro_rules! m { () => {} }
macro_rules! gen_gen_inner_invoc { () => {
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}}
gen_gen_inner_invoc!();
}
fn check5() {
macro_rules! m { () => { Wrong } }
macro_rules! gen_inner_invoc { () => {
macro_rules! m { () => { Right } }
m!(); // OK
}}
gen_inner_invoc!();
}
fn check9() {
macro_rules! m { () => { Wrong } }
macro_rules! gen_inner_gen_invoc { () => {
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}}
gen_inner_gen_invoc!();
}
fn check10() {
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}
fn check13() {
macro_rules! m { () => {} }
gen_inner!();
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
gen_invoc!();
}
fn check17() {
macro_rules! m { () => {} }
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
fn check22() {
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
m!(); // OK
}
fn check36() {
gen_outer!();
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
fn check39() {
gen_outer!();
macro_rules! m { () => { Right } }
m!(); // OK
}
fn check52() {
gen_outer!();
macro_rules! gen_gen_inner_invoc { () => {
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}}
gen_gen_inner_invoc!();
}
fn check56() {
gen_outer!();
macro_rules! gen_inner_invoc { () => {
macro_rules! m { () => { Right } }
m!(); // OK
}}
gen_inner_invoc!();
}
fn check59() {
gen_outer!();
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}
fn check60() {
gen_outer!();
macro_rules! gen_inner_gen_invoc { () => {
macro_rules! m { () => { Right } }
gen_invoc!(); // OK
}}
gen_inner_gen_invoc!();
}
fn check64() {
gen_outer!();
gen_inner!();
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
gen_invoc!();
}
// -----------------------------------------------------------
// These configurations are only possible with legacy macro scoping
fn check33() {
macro_rules! gen_outer_gen_inner { () => {
macro_rules! m { () => {} }
gen_inner!();
}}
gen_outer_gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
fn check34() {
macro_rules! gen_outer_inner { () => {
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
}}
gen_outer_inner!();
m!(); // OK
}
fn check35() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();
m!(); // OK
}
fn check61() {
macro_rules! gen_outer_gen_inner { () => {
macro_rules! m { () => {} }
gen_inner!();
}}
gen_outer_gen_inner!();
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
gen_invoc!();
}
fn check62() {
macro_rules! gen_outer_inner { () => {
macro_rules! m { () => { Wrong } }
macro_rules! m { () => { Right } }
}}
gen_outer_inner!();
gen_invoc!(); // OK
}
fn check63() {
macro_rules! gen_gen_outer_inner { () => {
gen_outer!();
macro_rules! m { () => { Right } }
}}
gen_gen_outer_inner!();
gen_invoc!(); // OK
}
}}
include!();
fn main() {}
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:101:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:97:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:139:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:135:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:148:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:144:9
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:164:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:180:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:218:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:85:9
|
LL | macro_rules! m { () => { Wrong } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:232:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:227:13
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-legacy.rs:262:42
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! m { () => { Right } }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-legacy.rs:257:13
|
LL | macro_rules! m { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0659`.
// Legend:
// `N` - number of combination, from 0 to 4*4*4=64
// `Outer < Invoc` means that expansion that produced macro definition `Outer`
// is a strict ancestor of expansion that produced macro definition `Inner`.
// `>`, `=` and `Unordered` mean "strict descendant", "same" and
// "not in ordering relation" for parent expansions.
// `+` - possible configuration
// `-` - configuration impossible due to properties of partial ordering
// `-?` - configuration impossible due to block/scope syntax
// `+?` - configuration possible only with legacy scoping
// N | Outer ~ Invoc | Invoc ~ Inner | Outer ~ Inner | Possible |
// 1 | < | < | < | + |
// 2 | < | < | = | - |
// 3 | < | < | > | - |
// 4 | < | < | Unordered | - |
// 5 | < | = | < | + |
// 6 | < | = | = | - |
// 7 | < | = | > | - |
// 8 | < | = | Unordered | - |
// 9 | < | > | < | + |
// 10 | < | > | = | + |
// 11 | < | > | > | -? |
// 12 | < | > | Unordered | -? |
// 13 | < | Unordered | < | + |
// 14 | < | Unordered | = | - |
// 15 | < | Unordered | > | - |
// 16 | < | Unordered | Unordered | -? |
// 17 | = | < | < | + |
// 18 | = | < | = | - |
// 19 | = | < | > | - |
// 20 | = | < | Unordered | - |
// 21 | = | = | < | - |
// 22 | = | = | = | + |
// 23 | = | = | > | - |
// 24 | = | = | Unordered | - |
// 25 | = | > | < | - |
// 26 | = | > | = | - |
// 27 | = | > | > | -? |
// 28 | = | > | Unordered | - |
// 29 | = | Unordered | < | - |
// 30 | = | Unordered | = | - |
// 31 | = | Unordered | > | - |
// 32 | = | Unordered | Unordered | -? |
// 33 | > | < | < | -? |
// 34 | > | < | = | -? |
// 35 | > | < | > | -? |
// 36 | > | < | Unordered | + |
// 37 | > | = | < | - |
// 38 | > | = | = | - |
// 39 | > | = | > | + |
// 40 | > | = | Unordered | - |
// 41 | > | > | < | - |
// 42 | > | > | = | - |
// 43 | > | > | > | -? |
// 44 | > | > | Unordered | - |
// 45 | > | Unordered | < | - |
// 46 | > | Unordered | = | - |
// 47 | > | Unordered | > | -? |
// 48 | > | Unordered | Unordered | -? |
// 49 | Unordered | < | < | -? |
// 50 | Unordered | < | = | - |
// 51 | Unordered | < | > | - |
// 52 | Unordered | < | Unordered | + |
// 53 | Unordered | = | < | - |
// 54 | Unordered | = | = | - |
// 55 | Unordered | = | > | - |
// 56 | Unordered | = | Unordered | + |
// 57 | Unordered | > | < | - |
// 58 | Unordered | > | = | - |
// 59 | Unordered | > | > | + |
// 60 | Unordered | > | Unordered | + |
// 61 | Unordered | Unordered | < | -? |
// 62 | Unordered | Unordered | = | -? |
// 63 | Unordered | Unordered | > | -? |
// 64 | Unordered | Unordered | Unordered | + |
#![feature(decl_macro, rustc_attrs)]
struct Right;
// struct Wrong; // not defined
#[rustc_transparent_macro]
macro include() {
#[rustc_transparent_macro]
macro gen_outer() {
macro m() { Wrong }
}
#[rustc_transparent_macro]
macro gen_inner() {
macro m() { Right }
}
#[rustc_transparent_macro]
macro gen_invoc() {
m!()
}
// -----------------------------------------------------------
fn check1() {
macro m() {}
{
#[rustc_transparent_macro]
macro gen_gen_inner_invoc() {
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
gen_gen_inner_invoc!();
}
}
fn check5() {
macro m() { Wrong }
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
}
}
fn check9() {
macro m() { Wrong }
{
#[rustc_transparent_macro]
macro gen_inner_gen_invoc() {
macro m() { Right }
gen_invoc!(); // OK
}
gen_inner_gen_invoc!();
}
}
fn check10() {
macro m() { Wrong }
{
macro m() { Right }
gen_invoc!(); // OK
}
}
fn check13() {
macro m() {}
{
gen_inner!();
#[rustc_transparent_macro]
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
gen_invoc!();
}
}
fn check17() {
macro m() {}
{
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
}
fn check22() {
macro m() { Wrong }
{
macro m() { Right }
m!(); // OK
}
}
fn check36() {
gen_outer!();
{
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
}
fn check39() {
gen_outer!();
{
macro m() { Right }
m!(); // OK
}
}
fn check52() {
gen_outer!();
{
#[rustc_transparent_macro]
macro gen_gen_inner_invoc() {
gen_inner!();
m!(); //~ ERROR `m` is ambiguous
}
gen_gen_inner_invoc!();
}
}
fn check56() {
gen_outer!();
{
#[rustc_transparent_macro]
macro gen_inner_invoc() {
macro m() { Right }
m!(); // OK
}
gen_inner_invoc!();
}
}
fn check59() {
gen_outer!();
{
macro m() { Right }
gen_invoc!(); // OK
}
}
fn check60() {
gen_outer!();
{
#[rustc_transparent_macro]
macro gen_inner_gen_invoc() {
macro m() { Right }
gen_invoc!(); // OK
}
gen_inner_gen_invoc!();
}
}
fn check64() {
gen_outer!();
{
gen_inner!();
#[rustc_transparent_macro]
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
gen_invoc!();
}
}
}
include!();
fn main() {}
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:106:17
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:101:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:149:33
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:145:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:158:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:155:9
|
LL | macro m() {}
| ^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:174:13
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:192:17
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error[E0659]: `m` is ambiguous
--> $DIR/restricted-shadowing-modern.rs:235:33
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^ ambiguous name
|
note: `m` could refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro m() { Right }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
note: `m` could also refer to the name defined here
--> $DIR/restricted-shadowing-modern.rs:87:9
|
LL | macro m() { Wrong }
| ^^^^^^^^^^^^^^^^^^^
...
LL | include!();
| ----------- in this macro invocation
= note: macro-expanded macros do not shadow
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0659`.
......@@ -9,11 +9,10 @@
// except according to those terms.
// aux-build:define_macro.rs
// error-pattern: `bar` is already in scope
macro_rules! bar { () => {} }
define_macro!(bar);
bar!();
bar!(); //~ ERROR `bar` is ambiguous
macro_rules! m { () => { #[macro_use] extern crate define_macro; } }
m!();
......
error: `bar` is already in scope
error[E0659]: `bar` is ambiguous
--> $DIR/out-of-order-shadowing.rs:15:1
|
LL | bar!(); //~ ERROR `bar` is ambiguous
| ^^^ ambiguous name
|
note: `bar` could refer to the name defined here
--> $DIR/out-of-order-shadowing.rs:14:1
|
LL | define_macro!(bar);
| ^^^^^^^^^^^^^^^^^^^
note: `bar` could also refer to the name defined here
--> $DIR/out-of-order-shadowing.rs:13:1
|
= note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560)
LL | macro_rules! bar { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: macro-expanded macros do not shadow
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0659`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册