From ebb7a7bff5b44ff8de6701e82b0cf4e887b0f4e4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 3 Sep 2018 05:17:52 +0300 Subject: [PATCH] Add more hacks necessary for bootstrapping rustc Fix visiting order for attributes on modules, it's significant for `macro_rules!` resolution --- src/librustc_resolve/macros.rs | 18 +++++++--- src/libsyntax/visit.rs | 4 +-- ...issue-43106-gating-of-builtin-attrs.stderr | 34 +++++++++---------- .../feature-gate-link_args.stderr | 16 ++++----- src/test/ui/lint/suggestions.stderr | 16 ++++----- .../ui/macros/ambiguous-builtin-attrs.stderr | 34 +++++++++---------- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 2a90c91dcd1b9..59131b60515b8 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -943,7 +943,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> { for &(ident, parent_expansion, parent_legacy_scope) in module.builtin_attrs.borrow().iter() { - let resolution = if ident.name == "doc" { + let resolution = if ident.name == "doc" || ident.name == "test" || + ident.name == "thread_local" { // HACK: Some sugared doc comments in macros lose their memory about being // sugared doc comments and become shadowed by other macros. // We need to come up with some more principled approach instead. @@ -951,9 +952,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> { } else { self.resolve_legacy_scope(ident, parent_expansion, parent_legacy_scope, true) }.or_else(|| { - self.resolve_lexical_macro_path_segment(ident, MacroNS, parent_expansion, true, - true, true, ident.span) - .map(|(binding, _)| binding).ok() + let binding = self.resolve_lexical_macro_path_segment( + ident, MacroNS, parent_expansion, true, true, true, ident.span + ).map(|(binding, _)| binding).ok(); + match binding.map(|binding| binding.def_ignoring_ambiguity()) { + // HACK: More hacks necessary for bootstrapping rustc. + Some(Def::Macro(_, MacroKind::Bang)) if ident.name == "warn" => None, + _ => binding, + } }); if let Some(binding) = resolution { @@ -1082,7 +1088,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> { self.define(module, ident, MacroNS, (def, vis, item.span, expansion, IsMacroExport)); } else { - self.check_reserved_macro_name(ident, MacroNS); + if !attr::contains_name(&item.attrs, "rustc_doc_only_macro") { + self.check_reserved_macro_name(ident, MacroNS); + } self.unused_macros.insert(def_id); } } else { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 77311bf53fd1e..bc0e492ddbdc4 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -178,8 +178,8 @@ pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, ident: Ident) { } pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) { - visitor.visit_mod(&krate.module, krate.span, &krate.attrs, CRATE_NODE_ID); walk_list!(visitor, visit_attribute, &krate.attrs); + visitor.visit_mod(&krate.module, krate.span, &krate.attrs, CRATE_NODE_ID); } 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 } pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { + walk_list!(visitor, visit_attribute, &item.attrs); visitor.visit_vis(&item.vis); visitor.visit_ident(item.ident); match item.node { @@ -288,7 +289,6 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { ItemKind::Mac(ref mac) => visitor.visit_mac(mac), ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id), } - walk_list!(visitor, visit_attribute, &item.attrs); } pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V, diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr index fd38fb6f97641..9ebd2b9f7428c 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr @@ -187,56 +187,56 @@ LL | mod inner { #![macro_escape] } = help: consider an outer attribute, #[macro_use] mod ... warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:317:17 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:1 | -LL | mod inner { #![repr="3900"] } - | ^^^^^^^^^^^^^^^ needs a hint +LL | #![repr = "3900"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs a hint | = note: #[warn(bad_repr)] on by default = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:321:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:313:1 | -LL | #[repr = "3900"] fn f() { } - | ^^^^^^^^^^^^^^^^ needs a hint +LL | #[repr = "3900"] + | ^^^^^^^^^^^^^^^^ needs a hint | = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:327:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:317:17 | -LL | #[repr = "3900"] type T = S; - | ^^^^^^^^^^^^^^^^ needs a hint +LL | mod inner { #![repr="3900"] } + | ^^^^^^^^^^^^^^^ needs a hint | = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:331:5 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:321:5 | -LL | #[repr = "3900"] impl S { } +LL | #[repr = "3900"] fn f() { } | ^^^^^^^^^^^^^^^^ needs a hint | = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:313:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:327:5 | -LL | #[repr = "3900"] - | ^^^^^^^^^^^^^^^^ needs a hint +LL | #[repr = "3900"] type T = S; + | ^^^^^^^^^^^^^^^^ needs a hint | = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit warning: `repr` attribute isn't configurable with a literal - --> $DIR/issue-43106-gating-of-builtin-attrs.rs:63:1 + --> $DIR/issue-43106-gating-of-builtin-attrs.rs:331:5 | -LL | #![repr = "3900"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ needs a hint +LL | #[repr = "3900"] impl S { } + | ^^^^^^^^^^^^^^^^ needs a hint | = help: valid hints include `#[repr(C)]`, `#[repr(packed)]`, `#[repr(rust)]` and `#[repr(transparent)]` = note: for more information, visit diff --git a/src/test/ui/feature-gates/feature-gate-link_args.stderr b/src/test/ui/feature-gates/feature-gate-link_args.stderr index 86a2818b34420..314890b9fa596 100644 --- a/src/test/ui/feature-gates/feature-gate-link_args.stderr +++ b/src/test/ui/feature-gates/feature-gate-link_args.stderr @@ -1,3 +1,11 @@ +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) + --> $DIR/feature-gate-link_args.rs:19:1 + | +LL | #![link_args = "-l unexpected_use_as_inner_attr_on_mod"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(link_args)] to the crate attributes to enable + 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) --> $DIR/feature-gate-link_args.rs:22:1 | @@ -14,14 +22,6 @@ LL | #[link_args = "-l unexected_use_on_non_extern_item"] | = help: add #![feature(link_args)] to the crate attributes to enable -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) - --> $DIR/feature-gate-link_args.rs:19:1 - | -LL | #![link_args = "-l unexpected_use_as_inner_attr_on_mod"] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = help: add #![feature(link_args)] to the crate attributes to enable - error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr index 8e5dac8be7827..6dc87c7109804 100644 --- a/src/test/ui/lint/suggestions.stderr +++ b/src/test/ui/lint/suggestions.stderr @@ -1,3 +1,11 @@ +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 + --> $DIR/suggestions.rs:57:1 + | +LL | #[no_debug] // should suggest removal of deprecated attribute + | ^^^^^^^^^^^ help: remove this attribute + | + = note: #[warn(deprecated)] on by default + warning: unnecessary parentheses around assigned value --> $DIR/suggestions.rs:64:21 | @@ -10,14 +18,6 @@ note: lint level defined here LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896 | ^^^^^^^^^^^^^ -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 - --> $DIR/suggestions.rs:57:1 - | -LL | #[no_debug] // should suggest removal of deprecated attribute - | ^^^^^^^^^^^ help: remove this attribute - | - = note: #[warn(deprecated)] on by default - warning: variable does not need to be mutable --> $DIR/suggestions.rs:64:13 | diff --git a/src/test/ui/macros/ambiguous-builtin-attrs.stderr b/src/test/ui/macros/ambiguous-builtin-attrs.stderr index e485157f30780..19f38e72548bc 100644 --- a/src/test/ui/macros/ambiguous-builtin-attrs.stderr +++ b/src/test/ui/macros/ambiguous-builtin-attrs.stderr @@ -16,6 +16,23 @@ error: name `derive` is reserved in macro namespace LL | macro derive() {} //~ ERROR name `derive` is reserved in macro namespace | ^^^^^^ +error[E0659]: `feature` is ambiguous + --> $DIR/ambiguous-builtin-attrs.rs:1:4 + | +LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous + | ^^^^^^^ + | +note: `feature` could refer to the name defined here + --> $DIR/ambiguous-builtin-attrs.rs:3:1 + | +LL | macro feature() {} + | ^^^^^^^^^^^^^^^^^^ +note: `feature` could also refer to the name defined here + --> $DIR/ambiguous-builtin-attrs.rs:1:4 + | +LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous + | ^^^^^^^ + error[E0659]: `repr` is ambiguous --> $DIR/ambiguous-builtin-attrs.rs:7:3 | @@ -135,23 +152,6 @@ note: `repr` could also refer to the name defined here LL | #[repr(C)] //~ ERROR `repr` is ambiguous | ^^^^ -error[E0659]: `feature` is ambiguous - --> $DIR/ambiguous-builtin-attrs.rs:1:4 - | -LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous - | ^^^^^^^ - | -note: `feature` could refer to the name defined here - --> $DIR/ambiguous-builtin-attrs.rs:3:1 - | -LL | macro feature() {} - | ^^^^^^^^^^^^^^^^^^ -note: `feature` could also refer to the name defined here - --> $DIR/ambiguous-builtin-attrs.rs:1:4 - | -LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous - | ^^^^^^^ - error: aborting due to 11 previous errors For more information about this error, try `rustc --explain E0659`.