Skip to content

Commit bc49117

Browse files
committed
Add more hacks necessary for bootstrapping rustc
Fix visiting order for attributes on modules, it's significant for `macro_rules!` resolution
1 parent 90641fc commit bc49117

File tree

6 files changed

+64
-57
lines changed

6 files changed

+64
-57
lines changed

Diff for: src/librustc_resolve/macros.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -943,17 +943,22 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
943943

944944
for &(ident, parent_expansion, parent_legacy_scope)
945945
in module.builtin_attrs.borrow().iter() {
946-
let resolution = if ident.name == "doc" {
946+
let resolution = if ident.name == "doc" || ident.name == "test" {
947947
// HACK: Some sugared doc comments in macros lose their memory about being
948948
// sugared doc comments and become shadowed by other macros.
949949
// We need to come up with some more principled approach instead.
950950
None
951951
} else {
952952
self.resolve_legacy_scope(ident, parent_expansion, parent_legacy_scope, true)
953953
}.or_else(|| {
954-
self.resolve_lexical_macro_path_segment(ident, MacroNS, parent_expansion, true,
955-
true, true, ident.span)
956-
.map(|(binding, _)| binding).ok()
954+
let binding = self.resolve_lexical_macro_path_segment(
955+
ident, MacroNS, parent_expansion, true, true, true, ident.span
956+
).map(|(binding, _)| binding).ok();
957+
match binding.map(|binding| binding.def_ignoring_ambiguity()) {
958+
// HACK: More hacks necessary for bootstrapping rustc.
959+
Some(Def::Macro(_, MacroKind::Bang)) if ident.name == "warn" => None,
960+
_ => binding,
961+
}
957962
});
958963

959964
if let Some(binding) = resolution {
@@ -1082,7 +1087,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
10821087
self.define(module, ident, MacroNS,
10831088
(def, vis, item.span, expansion, IsMacroExport));
10841089
} else {
1085-
self.check_reserved_macro_name(ident, MacroNS);
1090+
if !attr::contains_name(&item.attrs, "rustc_doc_only_macro") {
1091+
self.check_reserved_macro_name(ident, MacroNS);
1092+
}
10861093
self.unused_macros.insert(def_id);
10871094
}
10881095
} else {

Diff for: src/libsyntax/visit.rs

+2-2
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,

Diff for: src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr

+17-17
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>

Diff for: src/test/ui/feature-gates/feature-gate-link_args.stderr

+8-8
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`.

Diff for: src/test/ui/lint/suggestions.stderr

+8-8
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
|

Diff for: src/test/ui/macros/ambiguous-builtin-attrs.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ error: name `derive` is reserved in macro namespace
1616
LL | macro derive() {} //~ ERROR name `derive` is reserved in macro namespace
1717
| ^^^^^^
1818

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+
1936
error[E0659]: `repr` is ambiguous
2037
--> $DIR/ambiguous-builtin-attrs.rs:7:3
2138
|
@@ -135,23 +152,6 @@ note: `repr` could also refer to the name defined here
135152
LL | #[repr(C)] //~ ERROR `repr` is ambiguous
136153
| ^^^^
137154

138-
error[E0659]: `feature` is ambiguous
139-
--> $DIR/ambiguous-builtin-attrs.rs:1:4
140-
|
141-
LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous
142-
| ^^^^^^^
143-
|
144-
note: `feature` could refer to the name defined here
145-
--> $DIR/ambiguous-builtin-attrs.rs:3:1
146-
|
147-
LL | macro feature() {}
148-
| ^^^^^^^^^^^^^^^^^^
149-
note: `feature` could also refer to the name defined here
150-
--> $DIR/ambiguous-builtin-attrs.rs:1:4
151-
|
152-
LL | #![feature(decl_macro)] //~ ERROR `feature` is ambiguous
153-
| ^^^^^^^
154-
155155
error: aborting due to 11 previous errors
156156

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

0 commit comments

Comments
 (0)