Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad43424

Browse files
committedSep 3, 2018
Auto merge of #53913 - petrochenkov:biattr4, r=<try>
resolve: Future proof resolutions for potentially built-in attributes Based on #53778 This is not full "pass all attributes through name resolution", but a more conservative solution. If built-in attribute is ambiguous with any other macro in scope, then an error is reported. TODO: Explain what complications arise with the full solution.
2 parents 9395f0a + bc49117 commit ad43424

25 files changed

+1577
-247
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use syntax::ext::base::{MacroKind, SyntaxExtension};
3939
use syntax::ext::base::Determinacy::Undetermined;
4040
use syntax::ext::hygiene::Mark;
4141
use syntax::ext::tt::macro_rules;
42+
use syntax::feature_gate::is_builtin_attr;
4243
use syntax::parse::token::{self, Token};
4344
use syntax::std_inject::injected_crate_name;
4445
use syntax::symbol::keywords;
@@ -933,7 +934,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
933934

934935
pub struct BuildReducedGraphVisitor<'a, 'b: 'a, 'c: 'b> {
935936
pub resolver: &'a mut Resolver<'b, 'c>,
936-
pub legacy_scope: LegacyScope<'b>,
937+
pub current_legacy_scope: LegacyScope<'b>,
937938
pub expansion: Mark,
938939
}
939940

@@ -943,7 +944,8 @@ impl<'a, 'b, 'cl> BuildReducedGraphVisitor<'a, 'b, 'cl> {
943944
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
944945
let invocation = self.resolver.invocations[&mark];
945946
invocation.module.set(self.resolver.current_module);
946-
invocation.legacy_scope.set(self.legacy_scope);
947+
invocation.parent_legacy_scope.set(self.current_legacy_scope);
948+
invocation.output_legacy_scope.set(self.current_legacy_scope);
947949
invocation
948950
}
949951
}
@@ -969,29 +971,30 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
969971
fn visit_item(&mut self, item: &'a Item) {
970972
let macro_use = match item.node {
971973
ItemKind::MacroDef(..) => {
972-
self.resolver.define_macro(item, self.expansion, &mut self.legacy_scope);
974+
self.resolver.define_macro(item, self.expansion, &mut self.current_legacy_scope);
973975
return
974976
}
975977
ItemKind::Mac(..) => {
976-
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(item.id));
978+
self.current_legacy_scope = LegacyScope::Invocation(self.visit_invoc(item.id));
977979
return
978980
}
979981
ItemKind::Mod(..) => self.resolver.contains_macro_use(&item.attrs),
980982
_ => false,
981983
};
982984

983-
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
985+
let orig_current_module = self.resolver.current_module;
986+
let orig_current_legacy_scope = self.current_legacy_scope;
984987
self.resolver.build_reduced_graph_for_item(item, self.expansion);
985988
visit::walk_item(self, item);
986-
self.resolver.current_module = parent;
989+
self.resolver.current_module = orig_current_module;
987990
if !macro_use {
988-
self.legacy_scope = legacy_scope;
991+
self.current_legacy_scope = orig_current_legacy_scope;
989992
}
990993
}
991994

992995
fn visit_stmt(&mut self, stmt: &'a ast::Stmt) {
993996
if let ast::StmtKind::Mac(..) = stmt.node {
994-
self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(stmt.id));
997+
self.current_legacy_scope = LegacyScope::Invocation(self.visit_invoc(stmt.id));
995998
} else {
996999
visit::walk_stmt(self, stmt);
9971000
}
@@ -1008,11 +1011,12 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
10081011
}
10091012

10101013
fn visit_block(&mut self, block: &'a Block) {
1011-
let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope);
1014+
let orig_current_module = self.resolver.current_module;
1015+
let orig_current_legacy_scope = self.current_legacy_scope;
10121016
self.resolver.build_reduced_graph_for_block(block, self.expansion);
10131017
visit::walk_block(self, block);
1014-
self.resolver.current_module = parent;
1015-
self.legacy_scope = legacy_scope;
1018+
self.resolver.current_module = orig_current_module;
1019+
self.current_legacy_scope = orig_current_legacy_scope;
10161020
}
10171021

10181022
fn visit_trait_item(&mut self, item: &'a TraitItem) {
@@ -1057,4 +1061,13 @@ impl<'a, 'b, 'cl> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b, 'cl> {
10571061
}
10581062
}
10591063
}
1064+
1065+
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
1066+
if !attr.is_sugared_doc && is_builtin_attr(attr) {
1067+
self.resolver.current_module.builtin_attrs.borrow_mut().push((
1068+
attr.path.segments[0].ident, self.expansion, self.current_legacy_scope
1069+
));
1070+
}
1071+
visit::walk_attribute(self, attr);
1072+
}
10601073
}

‎src/librustc_resolve/lib.rs

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use std::mem::replace;
8181
use rustc_data_structures::sync::Lrc;
8282

8383
use resolve_imports::{ImportDirective, ImportDirectiveSubclass, NameResolution, ImportResolver};
84-
use macros::{InvocationData, LegacyBinding};
84+
use macros::{InvocationData, LegacyBinding, LegacyScope};
8585

8686
// NB: This module needs to be declared first so diagnostics are
8787
// registered before they are used.
@@ -1010,8 +1010,9 @@ pub struct ModuleData<'a> {
10101010
normal_ancestor_id: DefId,
10111011

10121012
resolutions: RefCell<FxHashMap<(Ident, Namespace), &'a RefCell<NameResolution<'a>>>>,
1013-
legacy_macro_resolutions: RefCell<Vec<(Mark, Ident, MacroKind, Option<Def>)>>,
1013+
legacy_macro_resolutions: RefCell<Vec<(Ident, MacroKind, Mark, LegacyScope<'a>, Option<Def>)>>,
10141014
macro_resolutions: RefCell<Vec<(Box<[Ident]>, Span)>>,
1015+
builtin_attrs: RefCell<Vec<(Ident, Mark, LegacyScope<'a>)>>,
10151016

10161017
// Macro invocations that can expand into items in this module.
10171018
unresolved_invocations: RefCell<FxHashSet<Mark>>,
@@ -1050,6 +1051,7 @@ impl<'a> ModuleData<'a> {
10501051
resolutions: RefCell::new(FxHashMap()),
10511052
legacy_macro_resolutions: RefCell::new(Vec::new()),
10521053
macro_resolutions: RefCell::new(Vec::new()),
1054+
builtin_attrs: RefCell::new(Vec::new()),
10531055
unresolved_invocations: RefCell::new(FxHashSet()),
10541056
no_implicit_prelude: false,
10551057
glob_importers: RefCell::new(Vec::new()),
@@ -1166,7 +1168,6 @@ struct UseError<'a> {
11661168
struct AmbiguityError<'a> {
11671169
span: Span,
11681170
name: Name,
1169-
lexical: bool,
11701171
b1: &'a NameBinding<'a>,
11711172
b2: &'a NameBinding<'a>,
11721173
}
@@ -1270,6 +1271,23 @@ impl<'a> NameBinding<'a> {
12701271
fn descr(&self) -> &'static str {
12711272
if self.is_extern_crate() { "extern crate" } else { self.def().kind_name() }
12721273
}
1274+
1275+
// Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding`
1276+
// at some expansion round `max(invoc, binding)` when they both emerged from macros.
1277+
// Then this function returns `true` if `self` may emerge from a macro *after* that
1278+
// in some later round and screw up our previously found resolution.
1279+
fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding) -> bool {
1280+
// self > max(invoc, binding) => !(self <= invoc || self <= binding)
1281+
// Expansions are partially ordered, so "may appear after" is an inversion of
1282+
// "certainly appears before or simultaneously" and includes unordered cases.
1283+
let self_parent_expansion = self.expansion;
1284+
let other_parent_expansion = binding.expansion;
1285+
let certainly_before_other_or_simultaneously =
1286+
other_parent_expansion.is_descendant_of(self_parent_expansion);
1287+
let certainly_before_invoc_or_simultaneously =
1288+
invoc_parent_expansion.is_descendant_of(self_parent_expansion);
1289+
!(certainly_before_other_or_simultaneously || certainly_before_invoc_or_simultaneously)
1290+
}
12731291
}
12741292

12751293
/// Interns the names of the primitive types.
@@ -1403,8 +1421,6 @@ pub struct Resolver<'a, 'b: 'a> {
14031421
proc_mac_errors: Vec<macros::ProcMacError>,
14041422
/// crate-local macro expanded `macro_export` referred to by a module-relative path
14051423
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
1406-
/// macro-expanded `macro_rules` shadowing existing macros
1407-
disallowed_shadowing: Vec<&'a LegacyBinding<'a>>,
14081424

14091425
arenas: &'a ResolverArenas<'a>,
14101426
dummy_binding: &'a NameBinding<'a>,
@@ -1715,7 +1731,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17151731
ambiguity_errors: Vec::new(),
17161732
use_injections: Vec::new(),
17171733
proc_mac_errors: Vec::new(),
1718-
disallowed_shadowing: Vec::new(),
17191734
macro_expanded_macro_export_errors: BTreeSet::new(),
17201735

17211736
arenas,
@@ -1814,7 +1829,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
18141829
NameBindingKind::Import { .. } => false,
18151830
NameBindingKind::Ambiguity { b1, b2 } => {
18161831
self.ambiguity_errors.push(AmbiguityError {
1817-
span, name: ident.name, lexical: false, b1, b2,
1832+
span, name: ident.name, b1, b2,
18181833
});
18191834
true
18201835
}
@@ -3468,6 +3483,20 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
34683483
record_used: bool,
34693484
path_span: Span,
34703485
crate_lint: CrateLint,
3486+
) -> PathResult<'a> {
3487+
self.resolve_path_with_parent_expansion(base_module, path, opt_ns, Mark::root(),
3488+
record_used, path_span, crate_lint)
3489+
}
3490+
3491+
fn resolve_path_with_parent_expansion(
3492+
&mut self,
3493+
base_module: Option<ModuleOrUniformRoot<'a>>,
3494+
path: &[Ident],
3495+
opt_ns: Option<Namespace>, // `None` indicates a module path
3496+
parent_expansion: Mark,
3497+
record_used: bool,
3498+
path_span: Span,
3499+
crate_lint: CrateLint,
34713500
) -> PathResult<'a> {
34723501
let mut module = base_module;
34733502
let mut allow_super = true;
@@ -3557,8 +3586,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
35573586
self.resolve_ident_in_module(module, ident, ns, record_used, path_span)
35583587
} else if opt_ns == Some(MacroNS) {
35593588
assert!(ns == TypeNS);
3560-
self.resolve_lexical_macro_path_segment(ident, ns, record_used, record_used,
3561-
false, path_span).map(|(b, _)| b)
3589+
self.resolve_lexical_macro_path_segment(ident, ns, parent_expansion, record_used,
3590+
record_used, false, path_span)
3591+
.map(|(binding, _)| binding)
35623592
} else {
35633593
let record_used_id =
35643594
if record_used { crate_lint.node_id().or(Some(CRATE_NODE_ID)) } else { None };
@@ -4499,35 +4529,32 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
44994529
vis.is_accessible_from(module.normal_ancestor_id, self)
45004530
}
45014531

4502-
fn report_ambiguity_error(
4503-
&self, name: Name, span: Span, _lexical: bool,
4504-
def1: Def, is_import1: bool, is_glob1: bool, from_expansion1: bool, span1: Span,
4505-
def2: Def, is_import2: bool, _is_glob2: bool, _from_expansion2: bool, span2: Span,
4506-
) {
4532+
fn report_ambiguity_error(&self, name: Name, span: Span, b1: &NameBinding, b2: &NameBinding) {
45074533
let participle = |is_import: bool| if is_import { "imported" } else { "defined" };
4508-
let msg1 = format!("`{}` could refer to the name {} here", name, participle(is_import1));
4534+
let msg1 =
4535+
format!("`{}` could refer to the name {} here", name, participle(b1.is_import()));
45094536
let msg2 =
4510-
format!("`{}` could also refer to the name {} here", name, participle(is_import2));
4511-
let note = if from_expansion1 {
4512-
Some(if let Def::Macro(..) = def1 {
4537+
format!("`{}` could also refer to the name {} here", name, participle(b2.is_import()));
4538+
let note = if b1.expansion != Mark::root() {
4539+
Some(if let Def::Macro(..) = b1.def() {
45134540
format!("macro-expanded {} do not shadow",
4514-
if is_import1 { "macro imports" } else { "macros" })
4541+
if b1.is_import() { "macro imports" } else { "macros" })
45154542
} else {
45164543
format!("macro-expanded {} do not shadow when used in a macro invocation path",
4517-
if is_import1 { "imports" } else { "items" })
4544+
if b1.is_import() { "imports" } else { "items" })
45184545
})
4519-
} else if is_glob1 {
4546+
} else if b1.is_glob_import() {
45204547
Some(format!("consider adding an explicit import of `{}` to disambiguate", name))
45214548
} else {
45224549
None
45234550
};
45244551

45254552
let mut err = struct_span_err!(self.session, span, E0659, "`{}` is ambiguous", name);
4526-
err.span_note(span1, &msg1);
4527-
match def2 {
4528-
Def::Macro(..) if span2.is_dummy() =>
4553+
err.span_note(b1.span, &msg1);
4554+
match b2.def() {
4555+
Def::Macro(..) if b2.span.is_dummy() =>
45294556
err.note(&format!("`{}` is also a builtin macro", name)),
4530-
_ => err.span_note(span2, &msg2),
4557+
_ => err.span_note(b2.span, &msg2),
45314558
};
45324559
if let Some(note) = note {
45334560
err.note(&note);
@@ -4536,7 +4563,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45364563
}
45374564

45384565
fn report_errors(&mut self, krate: &Crate) {
4539-
self.report_shadowing_errors();
45404566
self.report_with_use_injections(krate);
45414567
self.report_proc_macro_import(krate);
45424568
let mut reported_spans = FxHashSet();
@@ -4552,15 +4578,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45524578
);
45534579
}
45544580

4555-
for &AmbiguityError { span, name, b1, b2, lexical } in &self.ambiguity_errors {
4581+
for &AmbiguityError { span, name, b1, b2 } in &self.ambiguity_errors {
45564582
if reported_spans.insert(span) {
4557-
self.report_ambiguity_error(
4558-
name, span, lexical,
4559-
b1.def(), b1.is_import(), b1.is_glob_import(),
4560-
b1.expansion != Mark::root(), b1.span,
4561-
b2.def(), b2.is_import(), b2.is_glob_import(),
4562-
b2.expansion != Mark::root(), b2.span,
4563-
);
4583+
self.report_ambiguity_error(name, span, b1, b2);
45644584
}
45654585
}
45664586

@@ -4580,20 +4600,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45804600
}
45814601
}
45824602

4583-
fn report_shadowing_errors(&mut self) {
4584-
let mut reported_errors = FxHashSet();
4585-
for binding in replace(&mut self.disallowed_shadowing, Vec::new()) {
4586-
if self.resolve_legacy_scope(&binding.parent, binding.ident, false).is_some() &&
4587-
reported_errors.insert((binding.ident, binding.span)) {
4588-
let msg = format!("`{}` is already in scope", binding.ident);
4589-
self.session.struct_span_err(binding.span, &msg)
4590-
.note("macro-expanded `macro_rules!`s may not shadow \
4591-
existing macros (see RFC 1560)")
4592-
.emit();
4593-
}
4594-
}
4595-
}
4596-
45974603
fn report_conflict<'b>(&mut self,
45984604
parent: Module,
45994605
ident: Ident,

‎src/librustc_resolve/macros.rs

Lines changed: 228 additions & 139 deletions
Large diffs are not rendered by default.

‎src/librustc_resolve/resolve_imports.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
251251
self.ambiguity_errors.push(AmbiguityError {
252252
span: path_span,
253253
name,
254-
lexical: false,
255254
b1: binding,
256255
b2: shadowed_glob,
257256
});
@@ -455,13 +454,24 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
455454
})
456455
}
457456

457+
crate fn check_reserved_macro_name(&self, ident: Ident, ns: Namespace) {
458+
// Reserve some names that are not quite covered by the general check
459+
// performed on `Resolver::builtin_attrs`.
460+
if ns == MacroNS &&
461+
(ident.name == "cfg" || ident.name == "cfg_attr" || ident.name == "derive") {
462+
self.session.span_err(ident.span,
463+
&format!("name `{}` is reserved in macro namespace", ident));
464+
}
465+
}
466+
458467
// Define the name or return the existing binding if there is a collision.
459468
pub fn try_define(&mut self,
460469
module: Module<'a>,
461470
ident: Ident,
462471
ns: Namespace,
463472
binding: &'a NameBinding<'a>)
464473
-> Result<(), &'a NameBinding<'a>> {
474+
self.check_reserved_macro_name(ident, ns);
465475
self.update_resolution(module, ident, ns, |this, resolution| {
466476
if let Some(old_binding) = resolution.binding {
467477
if binding.is_glob_import() {

‎src/libsyntax/ext/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,9 @@ pub trait Resolver {
727727
fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<Attribute>, allow_derive: bool)
728728
-> Option<Attribute>;
729729

730-
fn resolve_macro_invocation(&mut self, invoc: &Invocation, scope: Mark, force: bool)
730+
fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force: bool)
731731
-> Result<Option<Lrc<SyntaxExtension>>, Determinacy>;
732-
fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, scope: Mark,
732+
fn resolve_macro_path(&mut self, path: &ast::Path, kind: MacroKind, invoc_id: Mark,
733733
derives_in_scope: &[ast::Path], force: bool)
734734
-> Result<Lrc<SyntaxExtension>, Determinacy>;
735735

@@ -763,11 +763,11 @@ impl Resolver for DummyResolver {
763763
fn resolve_imports(&mut self) {}
764764
fn find_legacy_attr_invoc(&mut self, _attrs: &mut Vec<Attribute>, _allow_derive: bool)
765765
-> Option<Attribute> { None }
766-
fn resolve_macro_invocation(&mut self, _invoc: &Invocation, _scope: Mark, _force: bool)
766+
fn resolve_macro_invocation(&mut self, _invoc: &Invocation, _invoc_id: Mark, _force: bool)
767767
-> Result<Option<Lrc<SyntaxExtension>>, Determinacy> {
768768
Err(Determinacy::Determined)
769769
}
770-
fn resolve_macro_path(&mut self, _path: &ast::Path, _kind: MacroKind, _scope: Mark,
770+
fn resolve_macro_path(&mut self, _path: &ast::Path, _kind: MacroKind, _invoc_id: Mark,
771771
_derives_in_scope: &[ast::Path], _force: bool)
772772
-> Result<Lrc<SyntaxExtension>, Determinacy> {
773773
Err(Determinacy::Determined)

‎src/libsyntax/feature_gate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
959959
attribute is just used for rustc unit \
960960
tests and will never be stable",
961961
cfg_fn!(rustc_attrs))),
962+
("rustc_transparent_macro", Whitelisted, Gated(Stability::Unstable,
963+
"rustc_attrs",
964+
"used internally for testing macro hygiene",
965+
cfg_fn!(rustc_attrs))),
962966

963967
// RFC #2094
964968
("nll", Whitelisted, Gated(Stability::Unstable,

‎src/libsyntax/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, ident: Ident) {
178178
}
179179

180180
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
181-
visitor.visit_mod(&krate.module, krate.span, &krate.attrs, CRATE_NODE_ID);
182181
walk_list!(visitor, visit_attribute, &krate.attrs);
182+
visitor.visit_mod(&krate.module, krate.span, &krate.attrs, CRATE_NODE_ID);
183183
}
184184

185185
pub fn walk_mod<'a, V: Visitor<'a>>(visitor: &mut V, module: &'a Mod) {
@@ -217,6 +217,7 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
217217
}
218218

219219
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
220+
walk_list!(visitor, visit_attribute, &item.attrs);
220221
visitor.visit_vis(&item.vis);
221222
visitor.visit_ident(item.ident);
222223
match item.node {
@@ -288,7 +289,6 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
288289
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
289290
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id),
290291
}
291-
walk_list!(visitor, visit_attribute, &item.attrs);
292292
}
293293

294294
pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V,

‎src/libsyntax_pos/hygiene.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ impl Mark {
100100
Mark(raw)
101101
}
102102

103+
#[inline]
104+
pub fn parent(self) -> Mark {
105+
HygieneData::with(|data| data.marks[self.0 as usize].parent)
106+
}
107+
103108
#[inline]
104109
pub fn expn_info(self) -> Option<ExpnInfo> {
105110
HygieneData::with(|data| data.marks[self.0 as usize].expn_info.clone())

‎src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,56 +187,56 @@ LL | mod inner { #![macro_escape] }
187187
= help: consider an outer attribute, #[macro_use] mod ...
188188

189189
warning: `repr` attribute isn't configurable with a literal
190-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:317:17
190+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:1
191191
|
192-
LL | mod inner { #![repr="3900"] }
193-
| ^^^^^^^^^^^^^^^ needs a hint
192+
LL | #![repr = "3900"]
193+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs a hint
194194
|
195195
= note: #[warn(bad_repr)] on by default
196196
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
197197
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
198198

199199
warning: `repr` attribute isn't configurable with a literal
200-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:321:5
200+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:313:1
201201
|
202-
LL | #[repr = "3900"] fn f() { }
203-
| ^^^^^^^^^^^^^^^^ needs a hint
202+
LL | #[repr = "3900"]
203+
| ^^^^^^^^^^^^^^^^ needs a hint
204204
|
205205
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
206206
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
207207

208208
warning: `repr` attribute isn't configurable with a literal
209-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:327:5
209+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:317:17
210210
|
211-
LL | #[repr = "3900"] type T = S;
212-
| ^^^^^^^^^^^^^^^^ needs a hint
211+
LL | mod inner { #![repr="3900"] }
212+
| ^^^^^^^^^^^^^^^ needs a hint
213213
|
214214
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
215215
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
216216

217217
warning: `repr` attribute isn't configurable with a literal
218-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:331:5
218+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:321:5
219219
|
220-
LL | #[repr = "3900"] impl S { }
220+
LL | #[repr = "3900"] fn f() { }
221221
| ^^^^^^^^^^^^^^^^ needs a hint
222222
|
223223
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
224224
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
225225

226226
warning: `repr` attribute isn't configurable with a literal
227-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:313:1
227+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:327:5
228228
|
229-
LL | #[repr = "3900"]
230-
| ^^^^^^^^^^^^^^^^ needs a hint
229+
LL | #[repr = "3900"] type T = S;
230+
| ^^^^^^^^^^^^^^^^ needs a hint
231231
|
232232
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
233233
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>
234234

235235
warning: `repr` attribute isn't configurable with a literal
236-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:1
236+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:331:5
237237
|
238-
LL | #![repr = "3900"]
239-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs a hint
238+
LL | #[repr = "3900"] impl S { }
239+
| ^^^^^^^^^^^^^^^^ needs a hint
240240
|
241241
= help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]`
242242
= note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html>

‎src/test/ui/feature-gates/feature-gate-link_args.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead (see issue #29596)
2+
--> $DIR/feature-gate-link_args.rs:19:1
3+
|
4+
LL | #![link_args = "-l unexpected_use_as_inner_attr_on_mod"]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: add #![feature(link_args)] to the crate attributes to enable
8+
19
error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead (see issue #29596)
210
--> $DIR/feature-gate-link_args.rs:22:1
311
|
@@ -14,14 +22,6 @@ LL | #[link_args = "-l unexected_use_on_non_extern_item"]
1422
|
1523
= help: add #![feature(link_args)] to the crate attributes to enable
1624

17-
error[E0658]: the `link_args` attribute is experimental and not portable across platforms, it is recommended to use `#[link(name = "foo")] instead (see issue #29596)
18-
--> $DIR/feature-gate-link_args.rs:19:1
19-
|
20-
LL | #![link_args = "-l unexpected_use_as_inner_attr_on_mod"]
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22-
|
23-
= help: add #![feature(link_args)] to the crate attributes to enable
24-
2525
error: aborting due to 3 previous errors
2626

2727
For more information about this error, try `rustc --explain E0658`.

‎src/test/ui/lint/suggestions.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
warning: use of deprecated attribute `no_debug`: the `#[no_debug]` attribute was an experimental feature that has been deprecated due to lack of demand. See https://github.com/rust-lang/rust/issues/29721
2+
--> $DIR/suggestions.rs:57:1
3+
|
4+
LL | #[no_debug] // should suggest removal of deprecated attribute
5+
| ^^^^^^^^^^^ help: remove this attribute
6+
|
7+
= note: #[warn(deprecated)] on by default
8+
19
warning: unnecessary parentheses around assigned value
210
--> $DIR/suggestions.rs:64:21
311
|
@@ -10,14 +18,6 @@ note: lint level defined here
1018
LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
1119
| ^^^^^^^^^^^^^
1220

13-
warning: use of deprecated attribute `no_debug`: the `#[no_debug]` attribute was an experimental feature that has been deprecated due to lack of demand. See https://github.com/rust-lang/rust/issues/29721
14-
--> $DIR/suggestions.rs:57:1
15-
|
16-
LL | #[no_debug] // should suggest removal of deprecated attribute
17-
| ^^^^^^^^^^^ help: remove this attribute
18-
|
19-
= note: #[warn(deprecated)] on by default
20-
2121
warning: variable does not need to be mutable
2222
--> $DIR/suggestions.rs:64:13
2323
|
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags:--test
2+
3+
#![feature(decl_macro, test)]
4+
5+
extern crate test;
6+
7+
macro test() {}
8+
9+
#[test] //~ ERROR `test` is ambiguous
10+
fn test() {}
11+
12+
macro bench() {}
13+
14+
#[bench] //~ ERROR `bench` is ambiguous
15+
fn bench(b: &mut test::Bencher) {}
16+
17+
fn main() {}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0659]: `test` is ambiguous
2+
--> $DIR/ambiguous-builtin-attrs-test.rs:9:3
3+
|
4+
LL | #[test] //~ ERROR `test` is ambiguous
5+
| ^^^^
6+
|
7+
note: `test` could refer to the name defined here
8+
--> $DIR/ambiguous-builtin-attrs-test.rs:7:1
9+
|
10+
LL | macro test() {}
11+
| ^^^^^^^^^^^^^^^
12+
note: `test` could also refer to the name defined here
13+
--> $DIR/ambiguous-builtin-attrs-test.rs:9:3
14+
|
15+
LL | #[test] //~ ERROR `test` is ambiguous
16+
| ^^^^
17+
18+
error[E0659]: `bench` is ambiguous
19+
--> $DIR/ambiguous-builtin-attrs-test.rs:14:3
20+
|
21+
LL | #[bench] //~ ERROR `bench` is ambiguous
22+
| ^^^^^
23+
|
24+
note: `bench` could refer to the name defined here
25+
--> $DIR/ambiguous-builtin-attrs-test.rs:12:1
26+
|
27+
LL | macro bench() {}
28+
| ^^^^^^^^^^^^^^^^
29+
note: `bench` could also refer to the name defined here
30+
--> $DIR/ambiguous-builtin-attrs-test.rs:14:3
31+
|
32+
LL | #[bench] //~ ERROR `bench` is ambiguous
33+
| ^^^^^
34+
35+
error: aborting due to 2 previous errors
36+
37+
For more information about this error, try `rustc --explain E0659`.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#![feature(decl_macro)] //~ ERROR `feature` is ambiguous
2+
3+
macro feature() {}
4+
5+
macro repr() {}
6+
7+
#[repr(C)] //~ ERROR `repr` is ambiguous
8+
struct S;
9+
#[cfg_attr(all(), repr(C))] //~ ERROR `repr` is ambiguous
10+
struct SCond;
11+
12+
macro cfg() {} //~ ERROR name `cfg` is reserved in macro namespace
13+
14+
#[cfg(all())] //~ ERROR `cfg` is ambiguous
15+
struct A;
16+
#[cfg(any())] // ERROR FIXME
17+
struct A;
18+
19+
macro cfg_attr() {} //~ ERROR name `cfg_attr` is reserved in macro namespace
20+
21+
#[cfg_attr(all(), cold)] // ERROR FIXME
22+
fn g() {}
23+
#[cfg_attr(any(), cold)] // ERROR FIXME
24+
fn h() {}
25+
26+
macro derive() {} //~ ERROR name `derive` is reserved in macro namespace
27+
28+
#[derive(Clone)] // ERROR FIXME
29+
struct B;
30+
31+
macro test() {}
32+
33+
#[test] // ERROR FIXME
34+
fn test() {}
35+
36+
macro bench() {}
37+
38+
#[bench] // ERROR FIXME
39+
fn bench() {}
40+
41+
macro_rules! inline { () => () }
42+
43+
#[inline] //~ ERROR `inline` is ambiguous
44+
fn f() {}
45+
#[cfg_attr(all(), inline)] //~ ERROR `inline` is ambiguous
46+
fn f_cond() {}
47+
48+
fn non_macro_expanded_location<#[inline] T>() { //~ ERROR `inline` is ambiguous
49+
match 0u8 {
50+
#[repr(C)] //~ ERROR `repr` is ambiguous
51+
_ => {}
52+
}
53+
}
54+
55+
fn main() {}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
error: name `cfg` is reserved in macro namespace
2+
--> $DIR/ambiguous-builtin-attrs.rs:12:7
3+
|
4+
LL | macro cfg() {} //~ ERROR name `cfg` is reserved in macro namespace
5+
| ^^^
6+
7+
error: name `cfg_attr` is reserved in macro namespace
8+
--> $DIR/ambiguous-builtin-attrs.rs:19:7
9+
|
10+
LL | macro cfg_attr() {} //~ ERROR name `cfg_attr` is reserved in macro namespace
11+
| ^^^^^^^^
12+
13+
error: name `derive` is reserved in macro namespace
14+
--> $DIR/ambiguous-builtin-attrs.rs:26:7
15+
|
16+
LL | macro derive() {} //~ ERROR name `derive` is reserved in macro namespace
17+
| ^^^^^^
18+
19+
error[E0659]: `feature` is ambiguous
20+
--> $DIR/ambiguous-builtin-attrs.rs:1:4
21+
|
22+
LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous
23+
| ^^^^^^^
24+
|
25+
note: `feature` could refer to the name defined here
26+
--> $DIR/ambiguous-builtin-attrs.rs:3:1
27+
|
28+
LL | macro feature() {}
29+
| ^^^^^^^^^^^^^^^^^^
30+
note: `feature` could also refer to the name defined here
31+
--> $DIR/ambiguous-builtin-attrs.rs:1:4
32+
|
33+
LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous
34+
| ^^^^^^^
35+
36+
error[E0659]: `repr` is ambiguous
37+
--> $DIR/ambiguous-builtin-attrs.rs:7:3
38+
|
39+
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
40+
| ^^^^
41+
|
42+
note: `repr` could refer to the name defined here
43+
--> $DIR/ambiguous-builtin-attrs.rs:5:1
44+
|
45+
LL | macro repr() {}
46+
| ^^^^^^^^^^^^^^^
47+
note: `repr` could also refer to the name defined here
48+
--> $DIR/ambiguous-builtin-attrs.rs:7:3
49+
|
50+
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
51+
| ^^^^
52+
53+
error[E0659]: `repr` is ambiguous
54+
--> $DIR/ambiguous-builtin-attrs.rs:9:19
55+
|
56+
LL | #[cfg_attr(all(), repr(C))] //~ ERROR `repr` is ambiguous
57+
| ^^^^
58+
|
59+
note: `repr` could refer to the name defined here
60+
--> $DIR/ambiguous-builtin-attrs.rs:5:1
61+
|
62+
LL | macro repr() {}
63+
| ^^^^^^^^^^^^^^^
64+
note: `repr` could also refer to the name defined here
65+
--> $DIR/ambiguous-builtin-attrs.rs:9:19
66+
|
67+
LL | #[cfg_attr(all(), repr(C))] //~ ERROR `repr` is ambiguous
68+
| ^^^^
69+
70+
error[E0659]: `cfg` is ambiguous
71+
--> $DIR/ambiguous-builtin-attrs.rs:14:3
72+
|
73+
LL | #[cfg(all())] //~ ERROR `cfg` is ambiguous
74+
| ^^^
75+
|
76+
note: `cfg` could refer to the name defined here
77+
--> $DIR/ambiguous-builtin-attrs.rs:12:1
78+
|
79+
LL | macro cfg() {} //~ ERROR name `cfg` is reserved in macro namespace
80+
| ^^^^^^^^^^^^^^
81+
note: `cfg` could also refer to the name defined here
82+
--> $DIR/ambiguous-builtin-attrs.rs:14:3
83+
|
84+
LL | #[cfg(all())] //~ ERROR `cfg` is ambiguous
85+
| ^^^
86+
87+
error[E0659]: `inline` is ambiguous
88+
--> $DIR/ambiguous-builtin-attrs.rs:43:3
89+
|
90+
LL | #[inline] //~ ERROR `inline` is ambiguous
91+
| ^^^^^^
92+
|
93+
note: `inline` could refer to the name defined here
94+
--> $DIR/ambiguous-builtin-attrs.rs:41:1
95+
|
96+
LL | macro_rules! inline { () => () }
97+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98+
note: `inline` could also refer to the name defined here
99+
--> $DIR/ambiguous-builtin-attrs.rs:43:3
100+
|
101+
LL | #[inline] //~ ERROR `inline` is ambiguous
102+
| ^^^^^^
103+
104+
error[E0659]: `inline` is ambiguous
105+
--> $DIR/ambiguous-builtin-attrs.rs:45:19
106+
|
107+
LL | #[cfg_attr(all(), inline)] //~ ERROR `inline` is ambiguous
108+
| ^^^^^^
109+
|
110+
note: `inline` could refer to the name defined here
111+
--> $DIR/ambiguous-builtin-attrs.rs:41:1
112+
|
113+
LL | macro_rules! inline { () => () }
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+
note: `inline` could also refer to the name defined here
116+
--> $DIR/ambiguous-builtin-attrs.rs:45:19
117+
|
118+
LL | #[cfg_attr(all(), inline)] //~ ERROR `inline` is ambiguous
119+
| ^^^^^^
120+
121+
error[E0659]: `inline` is ambiguous
122+
--> $DIR/ambiguous-builtin-attrs.rs:48:34
123+
|
124+
LL | fn non_macro_expanded_location<#[inline] T>() { //~ ERROR `inline` is ambiguous
125+
| ^^^^^^
126+
|
127+
note: `inline` could refer to the name defined here
128+
--> $DIR/ambiguous-builtin-attrs.rs:41:1
129+
|
130+
LL | macro_rules! inline { () => () }
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
note: `inline` could also refer to the name defined here
133+
--> $DIR/ambiguous-builtin-attrs.rs:48:34
134+
|
135+
LL | fn non_macro_expanded_location<#[inline] T>() { //~ ERROR `inline` is ambiguous
136+
| ^^^^^^
137+
138+
error[E0659]: `repr` is ambiguous
139+
--> $DIR/ambiguous-builtin-attrs.rs:50:11
140+
|
141+
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
142+
| ^^^^
143+
|
144+
note: `repr` could refer to the name defined here
145+
--> $DIR/ambiguous-builtin-attrs.rs:5:1
146+
|
147+
LL | macro repr() {}
148+
| ^^^^^^^^^^^^^^^
149+
note: `repr` could also refer to the name defined here
150+
--> $DIR/ambiguous-builtin-attrs.rs:50:11
151+
|
152+
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
153+
| ^^^^
154+
155+
error: aborting due to 11 previous errors
156+
157+
For more information about this error, try `rustc --explain E0659`.

‎src/test/ui/macros/auxiliary/macro-in-other-crate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ macro_rules! mac {
1717
macro_rules! inline {
1818
() => ()
1919
}
20+
21+
#[macro_export]
22+
macro_rules! from_prelude {
23+
() => ()
24+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
// aux-build:macro-in-other-crate.rs
13+
14+
#![feature(decl_macro)]
15+
16+
macro_rules! my_include {() => {
17+
// Outer
18+
macro m() {}
19+
#[macro_use(from_prelude)] extern crate macro_in_other_crate;
20+
21+
fn inner() {
22+
// Inner
23+
macro m() {}
24+
macro_rules! from_prelude { () => {} }
25+
26+
// OK, both `m` and `from_prelude` are macro-expanded,
27+
// but no more macro-expanded than their counterpart from outer scope.
28+
m!();
29+
from_prelude!();
30+
}
31+
}}
32+
33+
my_include!();
34+
35+
fn main() {}

‎src/test/ui/macros/macro-shadowing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ macro_rules! macro_one { () => {} }
1717
#[macro_use(macro_two)] extern crate two_macros;
1818

1919
macro_rules! m1 { () => {
20-
macro_rules! foo { () => {} } //~ ERROR `foo` is already in scope
20+
macro_rules! foo { () => {} }
2121

2222
#[macro_use] //~ ERROR `macro_two` is already in scope
2323
extern crate two_macros as __;
2424
}}
2525
m1!();
2626

27-
foo!();
27+
foo!(); //~ ERROR `foo` is ambiguous
2828

2929
macro_rules! m2 { () => {
3030
macro_rules! foo { () => {} }

‎src/test/ui/macros/macro-shadowing.stderr

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ LL | m1!();
99
|
1010
= note: macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)
1111

12-
error: `foo` is already in scope
12+
error[E0659]: `foo` is ambiguous
13+
--> $DIR/macro-shadowing.rs:27:1
14+
|
15+
LL | foo!(); //~ ERROR `foo` is ambiguous
16+
| ^^^
17+
|
18+
note: `foo` could refer to the name defined here
1319
--> $DIR/macro-shadowing.rs:20:5
1420
|
15-
LL | macro_rules! foo { () => {} } //~ ERROR `foo` is already in scope
21+
LL | macro_rules! foo { () => {} }
1622
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1723
...
1824
LL | m1!();
1925
| ------ in this macro invocation
26+
note: `foo` could also refer to the name defined here
27+
--> $DIR/macro-shadowing.rs:15:1
2028
|
21-
= note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560)
29+
LL | macro_rules! foo { () => {} }
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
= note: macro-expanded macros do not shadow
2232

2333
error: aborting due to 2 previous errors
2434

35+
For more information about this error, try `rustc --explain E0659`.
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
// Legend:
2+
// `+` - possible configuration
3+
// `-` - configuration impossible due to properties of partial ordering
4+
// `-?` - configuration impossible due to block/scope syntax
5+
// `+?` - configuration possible only with legacy scoping
6+
7+
// N | Outer ~ Invoc | Invoc ~ Inner | Outer ~ Inner | Possible |
8+
// 1 | < | < | < | + |
9+
// 2 | < | < | = | - |
10+
// 3 | < | < | > | - |
11+
// 4 | < | < | Unordered | - |
12+
// 5 | < | = | < | + |
13+
// 6 | < | = | = | - |
14+
// 7 | < | = | > | - |
15+
// 8 | < | = | Unordered | - |
16+
// 9 | < | > | < | + |
17+
// 10 | < | > | = | + |
18+
// 11 | < | > | > | -? |
19+
// 12 | < | > | Unordered | -? |
20+
// 13 | < | Unordered | < | + |
21+
// 14 | < | Unordered | = | - |
22+
// 15 | < | Unordered | > | - |
23+
// 16 | < | Unordered | Unordered | -? |
24+
// 17 | = | < | < | + |
25+
// 18 | = | < | = | - |
26+
// 19 | = | < | > | - |
27+
// 20 | = | < | Unordered | - |
28+
// 21 | = | = | < | - |
29+
// 22 | = | = | = | + |
30+
// 23 | = | = | > | - |
31+
// 24 | = | = | Unordered | - |
32+
// 25 | = | > | < | - |
33+
// 26 | = | > | = | - |
34+
// 27 | = | > | > | -? |
35+
// 28 | = | > | Unordered | - |
36+
// 29 | = | Unordered | < | - |
37+
// 30 | = | Unordered | = | - |
38+
// 31 | = | Unordered | > | - |
39+
// 32 | = | Unordered | Unordered | -? |
40+
// 33 | > | < | < | +? |
41+
// 34 | > | < | = | +? |
42+
// 35 | > | < | > | +? |
43+
// 36 | > | < | Unordered | + |
44+
// 37 | > | = | < | - |
45+
// 38 | > | = | = | - |
46+
// 39 | > | = | > | + |
47+
// 40 | > | = | Unordered | - |
48+
// 41 | > | > | < | - |
49+
// 42 | > | > | = | - |
50+
// 43 | > | > | > | -? |
51+
// 44 | > | > | Unordered | - |
52+
// 45 | > | Unordered | < | - |
53+
// 46 | > | Unordered | = | - |
54+
// 47 | > | Unordered | > | -? |
55+
// 48 | > | Unordered | Unordered | -? |
56+
// 49 | Unordered | < | < | -? |
57+
// 50 | Unordered | < | = | - |
58+
// 51 | Unordered | < | > | - |
59+
// 52 | Unordered | < | Unordered | + |
60+
// 53 | Unordered | = | < | - |
61+
// 54 | Unordered | = | = | - |
62+
// 55 | Unordered | = | > | - |
63+
// 56 | Unordered | = | Unordered | + |
64+
// 57 | Unordered | > | < | - |
65+
// 58 | Unordered | > | = | - |
66+
// 59 | Unordered | > | > | + |
67+
// 60 | Unordered | > | Unordered | + |
68+
// 61 | Unordered | Unordered | < | +? |
69+
// 62 | Unordered | Unordered | = | +? |
70+
// 63 | Unordered | Unordered | > | +? |
71+
// 64 | Unordered | Unordered | Unordered | + |
72+
73+
#![feature(decl_macro, rustc_attrs)]
74+
75+
macro_rules! include { () => {
76+
macro_rules! gen_outer { () => {
77+
macro_rules! m { () => {} }
78+
}}
79+
macro_rules! gen_inner { () => {
80+
macro_rules! m { () => {} }
81+
}}
82+
macro_rules! gen_invoc { () => {
83+
m!()
84+
}}
85+
86+
// -----------------------------------------------------------
87+
88+
fn check1() {
89+
macro_rules! m { () => {} }
90+
91+
macro_rules! gen_gen_inner_invoc { () => {
92+
gen_inner!();
93+
m!(); //~ ERROR `m` is ambiguous
94+
}}
95+
gen_gen_inner_invoc!();
96+
}
97+
98+
fn check5() {
99+
macro_rules! m { () => {} }
100+
101+
macro_rules! gen_inner_invoc { () => {
102+
macro_rules! m { () => {} }
103+
m!(); // OK
104+
}}
105+
gen_inner_invoc!();
106+
}
107+
108+
fn check9() {
109+
macro_rules! m { () => {} }
110+
111+
macro_rules! gen_inner_gen_invoc { () => {
112+
macro_rules! m { () => {} }
113+
gen_invoc!(); // OK
114+
}}
115+
gen_inner_gen_invoc!();
116+
}
117+
118+
fn check10() {
119+
macro_rules! m { () => {} }
120+
121+
macro_rules! m { () => {} }
122+
123+
gen_invoc!(); // OK
124+
}
125+
126+
fn check13() {
127+
macro_rules! m { () => {} }
128+
129+
gen_inner!();
130+
131+
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
132+
gen_invoc!();
133+
}
134+
135+
fn check17() {
136+
macro_rules! m { () => {} }
137+
138+
gen_inner!();
139+
140+
m!(); //~ ERROR `m` is ambiguous
141+
}
142+
143+
fn check22() {
144+
macro_rules! m { () => {} }
145+
146+
macro_rules! m { () => {} }
147+
148+
m!(); // OK
149+
}
150+
151+
fn check36() {
152+
gen_outer!();
153+
154+
gen_inner!();
155+
156+
m!(); //~ ERROR `m` is ambiguous
157+
}
158+
159+
fn check39() {
160+
gen_outer!();
161+
162+
macro_rules! m { () => {} }
163+
164+
m!(); // OK
165+
}
166+
167+
fn check52() {
168+
gen_outer!();
169+
170+
macro_rules! gen_gen_inner_invoc { () => {
171+
gen_inner!();
172+
m!(); //~ ERROR `m` is ambiguous
173+
}}
174+
gen_gen_inner_invoc!();
175+
}
176+
177+
fn check56() {
178+
gen_outer!();
179+
180+
macro_rules! gen_inner_invoc { () => {
181+
macro_rules! m { () => {} }
182+
m!(); // OK
183+
}}
184+
gen_inner_invoc!();
185+
}
186+
187+
fn check59() {
188+
gen_outer!();
189+
190+
macro_rules! m { () => {} }
191+
192+
gen_invoc!(); // OK
193+
}
194+
195+
fn check60() {
196+
gen_outer!();
197+
198+
macro_rules! gen_inner_gen_invoc { () => {
199+
macro_rules! m { () => {} }
200+
gen_invoc!(); // OK
201+
}}
202+
gen_inner_gen_invoc!();
203+
}
204+
205+
fn check64() {
206+
gen_outer!();
207+
208+
gen_inner!();
209+
210+
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
211+
gen_invoc!();
212+
}
213+
214+
// -----------------------------------------------------------
215+
// These configurations are only possible with legacy macro scoping
216+
217+
fn check33() {
218+
macro_rules! gen_outer_gen_inner { () => {
219+
macro_rules! m { () => {} }
220+
gen_inner!();
221+
}}
222+
gen_outer_gen_inner!();
223+
224+
m!(); //~ ERROR `m` is ambiguous
225+
}
226+
227+
fn check34() {
228+
macro_rules! gen_outer_inner { () => {
229+
macro_rules! m { () => {} }
230+
macro_rules! m { () => {} }
231+
}}
232+
gen_outer_inner!();
233+
234+
m!(); // OK
235+
}
236+
237+
fn check35() {
238+
macro_rules! gen_gen_outer_inner { () => {
239+
gen_outer!();
240+
macro_rules! m { () => {} }
241+
}}
242+
gen_gen_outer_inner!();
243+
244+
m!(); // OK
245+
}
246+
247+
fn check61() {
248+
macro_rules! gen_outer_gen_inner { () => {
249+
macro_rules! m { () => {} }
250+
gen_inner!();
251+
}}
252+
gen_outer_gen_inner!();
253+
254+
macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
255+
gen_invoc!();
256+
}
257+
258+
fn check62() {
259+
macro_rules! gen_outer_inner { () => {
260+
macro_rules! m { () => {} }
261+
macro_rules! m { () => {} }
262+
}}
263+
gen_outer_inner!();
264+
265+
gen_invoc!(); // OK
266+
}
267+
268+
fn check63() {
269+
macro_rules! gen_gen_outer_inner { () => {
270+
gen_outer!();
271+
macro_rules! m { () => {} }
272+
}}
273+
gen_gen_outer_inner!();
274+
275+
gen_invoc!(); // OK
276+
}
277+
}}
278+
279+
include!();
280+
281+
fn main() {}
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
error[E0659]: `m` is ambiguous
2+
--> $DIR/restricted-shadowing-legacy.rs:93:13
3+
|
4+
LL | m!(); //~ ERROR `m` is ambiguous
5+
| ^
6+
|
7+
note: `m` could refer to the name defined here
8+
--> $DIR/restricted-shadowing-legacy.rs:80:9
9+
|
10+
LL | macro_rules! m { () => {} }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
...
13+
LL | include!();
14+
| ----------- in this macro invocation
15+
note: `m` could also refer to the name defined here
16+
--> $DIR/restricted-shadowing-legacy.rs:89:9
17+
|
18+
LL | macro_rules! m { () => {} }
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
...
21+
LL | include!();
22+
| ----------- in this macro invocation
23+
= note: macro-expanded macros do not shadow
24+
25+
error[E0659]: `m` is ambiguous
26+
--> $DIR/restricted-shadowing-legacy.rs:131:42
27+
|
28+
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
29+
| ^
30+
|
31+
note: `m` could refer to the name defined here
32+
--> $DIR/restricted-shadowing-legacy.rs:80:9
33+
|
34+
LL | macro_rules! m { () => {} }
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
...
37+
LL | include!();
38+
| ----------- in this macro invocation
39+
note: `m` could also refer to the name defined here
40+
--> $DIR/restricted-shadowing-legacy.rs:127:9
41+
|
42+
LL | macro_rules! m { () => {} }
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
...
45+
LL | include!();
46+
| ----------- in this macro invocation
47+
= note: macro-expanded macros do not shadow
48+
49+
error[E0659]: `m` is ambiguous
50+
--> $DIR/restricted-shadowing-legacy.rs:140:9
51+
|
52+
LL | m!(); //~ ERROR `m` is ambiguous
53+
| ^
54+
|
55+
note: `m` could refer to the name defined here
56+
--> $DIR/restricted-shadowing-legacy.rs:80:9
57+
|
58+
LL | macro_rules! m { () => {} }
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
...
61+
LL | include!();
62+
| ----------- in this macro invocation
63+
note: `m` could also refer to the name defined here
64+
--> $DIR/restricted-shadowing-legacy.rs:136:9
65+
|
66+
LL | macro_rules! m { () => {} }
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
...
69+
LL | include!();
70+
| ----------- in this macro invocation
71+
= note: macro-expanded macros do not shadow
72+
73+
error[E0659]: `m` is ambiguous
74+
--> $DIR/restricted-shadowing-legacy.rs:156:9
75+
|
76+
LL | m!(); //~ ERROR `m` is ambiguous
77+
| ^
78+
|
79+
note: `m` could refer to the name defined here
80+
--> $DIR/restricted-shadowing-legacy.rs:80:9
81+
|
82+
LL | macro_rules! m { () => {} }
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
84+
...
85+
LL | include!();
86+
| ----------- in this macro invocation
87+
note: `m` could also refer to the name defined here
88+
--> $DIR/restricted-shadowing-legacy.rs:77:9
89+
|
90+
LL | macro_rules! m { () => {} }
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
...
93+
LL | include!();
94+
| ----------- in this macro invocation
95+
= note: macro-expanded macros do not shadow
96+
97+
error[E0659]: `m` is ambiguous
98+
--> $DIR/restricted-shadowing-legacy.rs:172:13
99+
|
100+
LL | m!(); //~ ERROR `m` is ambiguous
101+
| ^
102+
|
103+
note: `m` could refer to the name defined here
104+
--> $DIR/restricted-shadowing-legacy.rs:80:9
105+
|
106+
LL | macro_rules! m { () => {} }
107+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
...
109+
LL | include!();
110+
| ----------- in this macro invocation
111+
note: `m` could also refer to the name defined here
112+
--> $DIR/restricted-shadowing-legacy.rs:77:9
113+
|
114+
LL | macro_rules! m { () => {} }
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
116+
...
117+
LL | include!();
118+
| ----------- in this macro invocation
119+
= note: macro-expanded macros do not shadow
120+
121+
error[E0659]: `m` is ambiguous
122+
--> $DIR/restricted-shadowing-legacy.rs:210:42
123+
|
124+
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
125+
| ^
126+
|
127+
note: `m` could refer to the name defined here
128+
--> $DIR/restricted-shadowing-legacy.rs:80:9
129+
|
130+
LL | macro_rules! m { () => {} }
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
...
133+
LL | include!();
134+
| ----------- in this macro invocation
135+
note: `m` could also refer to the name defined here
136+
--> $DIR/restricted-shadowing-legacy.rs:77:9
137+
|
138+
LL | macro_rules! m { () => {} }
139+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
...
141+
LL | include!();
142+
| ----------- in this macro invocation
143+
= note: macro-expanded macros do not shadow
144+
145+
error[E0659]: `m` is ambiguous
146+
--> $DIR/restricted-shadowing-legacy.rs:224:9
147+
|
148+
LL | m!(); //~ ERROR `m` is ambiguous
149+
| ^
150+
|
151+
note: `m` could refer to the name defined here
152+
--> $DIR/restricted-shadowing-legacy.rs:80:9
153+
|
154+
LL | macro_rules! m { () => {} }
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
156+
...
157+
LL | include!();
158+
| ----------- in this macro invocation
159+
note: `m` could also refer to the name defined here
160+
--> $DIR/restricted-shadowing-legacy.rs:219:13
161+
|
162+
LL | macro_rules! m { () => {} }
163+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
164+
...
165+
LL | include!();
166+
| ----------- in this macro invocation
167+
= note: macro-expanded macros do not shadow
168+
169+
error[E0659]: `m` is ambiguous
170+
--> $DIR/restricted-shadowing-legacy.rs:254:42
171+
|
172+
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
173+
| ^
174+
|
175+
note: `m` could refer to the name defined here
176+
--> $DIR/restricted-shadowing-legacy.rs:80:9
177+
|
178+
LL | macro_rules! m { () => {} }
179+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
180+
...
181+
LL | include!();
182+
| ----------- in this macro invocation
183+
note: `m` could also refer to the name defined here
184+
--> $DIR/restricted-shadowing-legacy.rs:249:13
185+
|
186+
LL | macro_rules! m { () => {} }
187+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
188+
...
189+
LL | include!();
190+
| ----------- in this macro invocation
191+
= note: macro-expanded macros do not shadow
192+
193+
error: aborting due to 8 previous errors
194+
195+
For more information about this error, try `rustc --explain E0659`.
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
// Legend:
2+
// `+` - possible configuration
3+
// `-` - configuration impossible due to properties of partial ordering
4+
// `-?` - configuration impossible due to block/scope syntax
5+
// `+?` - configuration possible only with legacy scoping
6+
7+
// N | Outer ~ Invoc | Invoc ~ Inner | Outer ~ Inner | Possible |
8+
// 1 | < | < | < | + |
9+
// 2 | < | < | = | - |
10+
// 3 | < | < | > | - |
11+
// 4 | < | < | Unordered | - |
12+
// 5 | < | = | < | + |
13+
// 6 | < | = | = | - |
14+
// 7 | < | = | > | - |
15+
// 8 | < | = | Unordered | - |
16+
// 9 | < | > | < | + |
17+
// 10 | < | > | = | + |
18+
// 11 | < | > | > | -? |
19+
// 12 | < | > | Unordered | -? |
20+
// 13 | < | Unordered | < | + |
21+
// 14 | < | Unordered | = | - |
22+
// 15 | < | Unordered | > | - |
23+
// 16 | < | Unordered | Unordered | -? |
24+
// 17 | = | < | < | + |
25+
// 18 | = | < | = | - |
26+
// 19 | = | < | > | - |
27+
// 20 | = | < | Unordered | - |
28+
// 21 | = | = | < | - |
29+
// 22 | = | = | = | + |
30+
// 23 | = | = | > | - |
31+
// 24 | = | = | Unordered | - |
32+
// 25 | = | > | < | - |
33+
// 26 | = | > | = | - |
34+
// 27 | = | > | > | -? |
35+
// 28 | = | > | Unordered | - |
36+
// 29 | = | Unordered | < | - |
37+
// 30 | = | Unordered | = | - |
38+
// 31 | = | Unordered | > | - |
39+
// 32 | = | Unordered | Unordered | -? |
40+
// 33 | > | < | < | -? |
41+
// 34 | > | < | = | -? |
42+
// 35 | > | < | > | -? |
43+
// 36 | > | < | Unordered | + |
44+
// 37 | > | = | < | - |
45+
// 38 | > | = | = | - |
46+
// 39 | > | = | > | + |
47+
// 40 | > | = | Unordered | - |
48+
// 41 | > | > | < | - |
49+
// 42 | > | > | = | - |
50+
// 43 | > | > | > | -? |
51+
// 44 | > | > | Unordered | - |
52+
// 45 | > | Unordered | < | - |
53+
// 46 | > | Unordered | = | - |
54+
// 47 | > | Unordered | > | -? |
55+
// 48 | > | Unordered | Unordered | -? |
56+
// 49 | Unordered | < | < | -? |
57+
// 50 | Unordered | < | = | - |
58+
// 51 | Unordered | < | > | - |
59+
// 52 | Unordered | < | Unordered | + |
60+
// 53 | Unordered | = | < | - |
61+
// 54 | Unordered | = | = | - |
62+
// 55 | Unordered | = | > | - |
63+
// 56 | Unordered | = | Unordered | + |
64+
// 57 | Unordered | > | < | - |
65+
// 58 | Unordered | > | = | - |
66+
// 59 | Unordered | > | > | + |
67+
// 60 | Unordered | > | Unordered | + |
68+
// 61 | Unordered | Unordered | < | -? |
69+
// 62 | Unordered | Unordered | = | -? |
70+
// 63 | Unordered | Unordered | > | -? |
71+
// 64 | Unordered | Unordered | Unordered | + |
72+
73+
#![feature(decl_macro, rustc_attrs)]
74+
75+
#[rustc_transparent_macro]
76+
macro include() {
77+
#[rustc_transparent_macro]
78+
macro gen_outer() {
79+
macro m() {}
80+
}
81+
#[rustc_transparent_macro]
82+
macro gen_inner() {
83+
macro m() {}
84+
}
85+
#[rustc_transparent_macro]
86+
macro gen_invoc() {
87+
m!()
88+
}
89+
90+
// -----------------------------------------------------------
91+
92+
fn check1() {
93+
macro m() {}
94+
{
95+
#[rustc_transparent_macro]
96+
macro gen_gen_inner_invoc() {
97+
gen_inner!();
98+
m!(); //~ ERROR `m` is ambiguous
99+
}
100+
gen_gen_inner_invoc!();
101+
}
102+
}
103+
104+
fn check5() {
105+
macro m() {}
106+
{
107+
#[rustc_transparent_macro]
108+
macro gen_inner_invoc() {
109+
macro m() {}
110+
m!(); // OK
111+
}
112+
gen_inner_invoc!();
113+
}
114+
}
115+
116+
fn check9() {
117+
macro m() {}
118+
{
119+
#[rustc_transparent_macro]
120+
macro gen_inner_gen_invoc() {
121+
macro m() {}
122+
gen_invoc!(); // OK
123+
}
124+
gen_inner_gen_invoc!();
125+
}
126+
}
127+
128+
fn check10() {
129+
macro m() {}
130+
{
131+
macro m() {}
132+
gen_invoc!(); // OK
133+
}
134+
}
135+
136+
fn check13() {
137+
macro m() {}
138+
{
139+
gen_inner!();
140+
#[rustc_transparent_macro]
141+
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
142+
gen_invoc!();
143+
}
144+
}
145+
146+
fn check17() {
147+
macro m() {}
148+
{
149+
gen_inner!();
150+
m!(); //~ ERROR `m` is ambiguous
151+
}
152+
}
153+
154+
fn check22() {
155+
macro m() {}
156+
{
157+
macro m() {}
158+
m!(); // OK
159+
}
160+
}
161+
162+
fn check36() {
163+
gen_outer!();
164+
{
165+
gen_inner!();
166+
m!(); //~ ERROR `m` is ambiguous
167+
}
168+
}
169+
170+
fn check39() {
171+
gen_outer!();
172+
{
173+
macro m() {}
174+
m!(); // OK
175+
}
176+
}
177+
178+
fn check52() {
179+
gen_outer!();
180+
{
181+
#[rustc_transparent_macro]
182+
macro gen_gen_inner_invoc() {
183+
gen_inner!();
184+
m!(); //~ ERROR `m` is ambiguous
185+
}
186+
gen_gen_inner_invoc!();
187+
}
188+
}
189+
190+
fn check56() {
191+
gen_outer!();
192+
{
193+
#[rustc_transparent_macro]
194+
macro gen_inner_invoc() {
195+
macro m() {}
196+
m!(); // OK
197+
}
198+
gen_inner_invoc!();
199+
}
200+
}
201+
202+
fn check59() {
203+
gen_outer!();
204+
{
205+
macro m() {}
206+
gen_invoc!(); // OK
207+
}
208+
}
209+
210+
fn check60() {
211+
gen_outer!();
212+
{
213+
#[rustc_transparent_macro]
214+
macro gen_inner_gen_invoc() {
215+
macro m() {}
216+
gen_invoc!(); // OK
217+
}
218+
gen_inner_gen_invoc!();
219+
}
220+
}
221+
222+
fn check64() {
223+
gen_outer!();
224+
{
225+
gen_inner!();
226+
#[rustc_transparent_macro]
227+
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
228+
gen_invoc!();
229+
}
230+
}
231+
}
232+
233+
include!();
234+
235+
fn main() {}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
error[E0659]: `m` is ambiguous
2+
--> $DIR/restricted-shadowing-modern.rs:98:17
3+
|
4+
LL | m!(); //~ ERROR `m` is ambiguous
5+
| ^
6+
...
7+
LL | include!();
8+
| ----------- in this macro invocation
9+
|
10+
note: `m` could refer to the name defined here
11+
--> $DIR/restricted-shadowing-modern.rs:83:9
12+
|
13+
LL | macro m() {}
14+
| ^^^^^^^^^^^^
15+
...
16+
LL | include!();
17+
| ----------- in this macro invocation
18+
note: `m` could also refer to the name defined here
19+
--> $DIR/restricted-shadowing-modern.rs:93:9
20+
|
21+
LL | macro m() {}
22+
| ^^^^^^^^^^^^
23+
...
24+
LL | include!();
25+
| ----------- in this macro invocation
26+
= note: macro-expanded macros do not shadow
27+
28+
error[E0659]: `m` is ambiguous
29+
--> $DIR/restricted-shadowing-modern.rs:141:33
30+
|
31+
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
32+
| ^
33+
...
34+
LL | include!();
35+
| ----------- in this macro invocation
36+
|
37+
note: `m` could refer to the name defined here
38+
--> $DIR/restricted-shadowing-modern.rs:83:9
39+
|
40+
LL | macro m() {}
41+
| ^^^^^^^^^^^^
42+
...
43+
LL | include!();
44+
| ----------- in this macro invocation
45+
note: `m` could also refer to the name defined here
46+
--> $DIR/restricted-shadowing-modern.rs:137:9
47+
|
48+
LL | macro m() {}
49+
| ^^^^^^^^^^^^
50+
...
51+
LL | include!();
52+
| ----------- in this macro invocation
53+
= note: macro-expanded macros do not shadow
54+
55+
error[E0659]: `m` is ambiguous
56+
--> $DIR/restricted-shadowing-modern.rs:150:13
57+
|
58+
LL | m!(); //~ ERROR `m` is ambiguous
59+
| ^
60+
...
61+
LL | include!();
62+
| ----------- in this macro invocation
63+
|
64+
note: `m` could refer to the name defined here
65+
--> $DIR/restricted-shadowing-modern.rs:83:9
66+
|
67+
LL | macro m() {}
68+
| ^^^^^^^^^^^^
69+
...
70+
LL | include!();
71+
| ----------- in this macro invocation
72+
note: `m` could also refer to the name defined here
73+
--> $DIR/restricted-shadowing-modern.rs:147:9
74+
|
75+
LL | macro m() {}
76+
| ^^^^^^^^^^^^
77+
...
78+
LL | include!();
79+
| ----------- in this macro invocation
80+
= note: macro-expanded macros do not shadow
81+
82+
error[E0659]: `m` is ambiguous
83+
--> $DIR/restricted-shadowing-modern.rs:166:13
84+
|
85+
LL | m!(); //~ ERROR `m` is ambiguous
86+
| ^
87+
...
88+
LL | include!();
89+
| ----------- in this macro invocation
90+
|
91+
note: `m` could refer to the name defined here
92+
--> $DIR/restricted-shadowing-modern.rs:83:9
93+
|
94+
LL | macro m() {}
95+
| ^^^^^^^^^^^^
96+
...
97+
LL | include!();
98+
| ----------- in this macro invocation
99+
note: `m` could also refer to the name defined here
100+
--> $DIR/restricted-shadowing-modern.rs:79:9
101+
|
102+
LL | macro m() {}
103+
| ^^^^^^^^^^^^
104+
...
105+
LL | include!();
106+
| ----------- in this macro invocation
107+
= note: macro-expanded macros do not shadow
108+
109+
error[E0659]: `m` is ambiguous
110+
--> $DIR/restricted-shadowing-modern.rs:184:17
111+
|
112+
LL | m!(); //~ ERROR `m` is ambiguous
113+
| ^
114+
...
115+
LL | include!();
116+
| ----------- in this macro invocation
117+
|
118+
note: `m` could refer to the name defined here
119+
--> $DIR/restricted-shadowing-modern.rs:83:9
120+
|
121+
LL | macro m() {}
122+
| ^^^^^^^^^^^^
123+
...
124+
LL | include!();
125+
| ----------- in this macro invocation
126+
note: `m` could also refer to the name defined here
127+
--> $DIR/restricted-shadowing-modern.rs:79:9
128+
|
129+
LL | macro m() {}
130+
| ^^^^^^^^^^^^
131+
...
132+
LL | include!();
133+
| ----------- in this macro invocation
134+
= note: macro-expanded macros do not shadow
135+
136+
error[E0659]: `m` is ambiguous
137+
--> $DIR/restricted-shadowing-modern.rs:227:33
138+
|
139+
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
140+
| ^
141+
...
142+
LL | include!();
143+
| ----------- in this macro invocation
144+
|
145+
note: `m` could refer to the name defined here
146+
--> $DIR/restricted-shadowing-modern.rs:83:9
147+
|
148+
LL | macro m() {}
149+
| ^^^^^^^^^^^^
150+
...
151+
LL | include!();
152+
| ----------- in this macro invocation
153+
note: `m` could also refer to the name defined here
154+
--> $DIR/restricted-shadowing-modern.rs:79:9
155+
|
156+
LL | macro m() {}
157+
| ^^^^^^^^^^^^
158+
...
159+
LL | include!();
160+
| ----------- in this macro invocation
161+
= note: macro-expanded macros do not shadow
162+
163+
error: aborting due to 6 previous errors
164+
165+
For more information about this error, try `rustc --explain E0659`.

‎src/test/ui/out-of-order-shadowing.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
// except according to those terms.
1010

1111
// aux-build:define_macro.rs
12-
// error-pattern: `bar` is already in scope
1312

1413
macro_rules! bar { () => {} }
1514
define_macro!(bar);
16-
bar!();
15+
bar!(); //~ ERROR `bar` is ambiguous
1716

1817
macro_rules! m { () => { #[macro_use] extern crate define_macro; } }
1918
m!();
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
error: `bar` is already in scope
1+
error[E0659]: `bar` is ambiguous
22
--> $DIR/out-of-order-shadowing.rs:15:1
33
|
4+
LL | bar!(); //~ ERROR `bar` is ambiguous
5+
| ^^^
6+
|
7+
note: `bar` could refer to the name defined here
8+
--> $DIR/out-of-order-shadowing.rs:14:1
9+
|
410
LL | define_macro!(bar);
511
| ^^^^^^^^^^^^^^^^^^^
12+
note: `bar` could also refer to the name defined here
13+
--> $DIR/out-of-order-shadowing.rs:13:1
614
|
7-
= note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560)
15+
LL | macro_rules! bar { () => {} }
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= note: macro-expanded macros do not shadow
818
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
919

1020
error: aborting due to previous error
1121

22+
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)
Please sign in to comment.