Skip to content

Commit bb0ff3e

Browse files
committed
tweak span and avoid doing work on happy path
1 parent 671107b commit bb0ff3e

File tree

7 files changed

+42
-78
lines changed

7 files changed

+42
-78
lines changed

compiler/rustc_passes/src/check_attr.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2522,20 +2522,20 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
25222522
];
25232523

25242524
for attr in attrs {
2525-
let item = tcx
2526-
.hir()
2527-
.items()
2528-
.map(|id| tcx.hir().item(id))
2529-
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
2530-
.map(|item| errors::ItemFollowingInnerAttr {
2531-
span: item.span,
2532-
kind: item.kind.descr(),
2533-
});
25342525
// This function should only be called with crate attributes
25352526
// which are inner attributes always but lets check to make sure
25362527
if attr.style == AttrStyle::Inner {
25372528
for attr_to_check in ATTRS_TO_CHECK {
25382529
if attr.has_name(*attr_to_check) {
2530+
let item = tcx
2531+
.hir()
2532+
.items()
2533+
.map(|id| tcx.hir().item(id))
2534+
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
2535+
.map(|item| errors::ItemFollowingInnerAttr {
2536+
span: item.ident.span,
2537+
kind: item.kind.descr(),
2538+
});
25392539
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
25402540
span: attr.span,
25412541
snippet: tcx.sess.source_map().span_to_snippet(attr.span).ok(),

tests/ui/attributes/unix_sigpipe/unix_sigpipe-crate.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | #![unix_sigpipe = "inherit"]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
LL |
77
LL | fn main() {}
8-
| ------------ the inner attribute doesn't annotate this function
8+
| ---- the inner attribute doesn't annotate this function
99
|
1010
help: perhaps you meant to use an outer attribute
1111
|

tests/ui/derives/issue-36617.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ LL | #![derive(Copy)]
4545
| ^^^^^^^^^^^^^^^^
4646
...
4747
LL | fn main() {}
48-
| ------------ the inner attribute doesn't annotate this function
48+
| ---- the inner attribute doesn't annotate this function
4949
|
5050
help: perhaps you meant to use an outer attribute
5151
|
@@ -60,7 +60,7 @@ LL | #![test]
6060
| ^^^^^^^^
6161
...
6262
LL | fn main() {}
63-
| ------------ the inner attribute doesn't annotate this function
63+
| ---- the inner attribute doesn't annotate this function
6464
|
6565
help: perhaps you meant to use an outer attribute
6666
|
@@ -75,7 +75,7 @@ LL | #![test_case]
7575
| ^^^^^^^^^^^^^
7676
...
7777
LL | fn main() {}
78-
| ------------ the inner attribute doesn't annotate this function
78+
| ---- the inner attribute doesn't annotate this function
7979
|
8080
help: perhaps you meant to use an outer attribute
8181
|
@@ -90,7 +90,7 @@ LL | #![bench]
9090
| ^^^^^^^^^
9191
...
9292
LL | fn main() {}
93-
| ------------ the inner attribute doesn't annotate this function
93+
| ---- the inner attribute doesn't annotate this function
9494
|
9595
help: perhaps you meant to use an outer attribute
9696
|
@@ -105,7 +105,7 @@ LL | #![global_allocator]
105105
| ^^^^^^^^^^^^^^^^^^^^
106106
...
107107
LL | fn main() {}
108-
| ------------ the inner attribute doesn't annotate this function
108+
| ---- the inner attribute doesn't annotate this function
109109
|
110110
help: perhaps you meant to use an outer attribute
111111
|

tests/ui/feature-gates/issue-43106-gating-of-bench.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![bench = "4100"]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
...
1515
LL | fn main() {}
16-
| ------------ the inner attribute doesn't annotate this function
16+
| ---- the inner attribute doesn't annotate this function
1717
|
1818
help: perhaps you meant to use an outer attribute
1919
|

tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr

+24-60
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,11 @@ LL | #![inline]
127127
error: `macro_export` attribute cannot be used at crate level
128128
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
129129
|
130-
LL | #![macro_export]
131-
| ^^^^^^^^^^^^^^^^
130+
LL | #![macro_export]
131+
| ^^^^^^^^^^^^^^^^
132132
...
133-
LL | / mod inline {
134-
LL | |
135-
LL | |
136-
LL | |
137-
... |
138-
LL | |
139-
LL | | }
140-
| |_- the inner attribute doesn't annotate this module
133+
LL | mod inline {
134+
| ------ the inner attribute doesn't annotate this module
141135
|
142136
help: perhaps you meant to use an outer attribute
143137
|
@@ -148,17 +142,11 @@ LL + #[macro_export]
148142
error: `rustc_main` attribute cannot be used at crate level
149143
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:14:1
150144
|
151-
LL | #![rustc_main]
152-
| ^^^^^^^^^^^^^^
145+
LL | #![rustc_main]
146+
| ^^^^^^^^^^^^^^
153147
...
154-
LL | / mod inline {
155-
LL | |
156-
LL | |
157-
LL | |
158-
... |
159-
LL | |
160-
LL | | }
161-
| |_- the inner attribute doesn't annotate this module
148+
LL | mod inline {
149+
| ------ the inner attribute doesn't annotate this module
162150
|
163151
help: perhaps you meant to use an outer attribute
164152
|
@@ -169,17 +157,11 @@ LL + #[rustc_main]
169157
error: `start` attribute cannot be used at crate level
170158
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
171159
|
172-
LL | #![start]
173-
| ^^^^^^^^^
160+
LL | #![start]
161+
| ^^^^^^^^^
174162
...
175-
LL | / mod inline {
176-
LL | |
177-
LL | |
178-
LL | |
179-
... |
180-
LL | |
181-
LL | | }
182-
| |_- the inner attribute doesn't annotate this module
163+
LL | mod inline {
164+
| ------ the inner attribute doesn't annotate this module
183165
|
184166
help: perhaps you meant to use an outer attribute
185167
|
@@ -190,17 +172,11 @@ LL + #[start]
190172
error: `repr` attribute cannot be used at crate level
191173
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:18:1
192174
|
193-
LL | #![repr()]
194-
| ^^^^^^^^^^
175+
LL | #![repr()]
176+
| ^^^^^^^^^^
195177
...
196-
LL | / mod inline {
197-
LL | |
198-
LL | |
199-
LL | |
200-
... |
201-
LL | |
202-
LL | | }
203-
| |_- the inner attribute doesn't annotate this module
178+
LL | mod inline {
179+
| ------ the inner attribute doesn't annotate this module
204180
|
205181
help: perhaps you meant to use an outer attribute
206182
|
@@ -211,17 +187,11 @@ LL + #[repr()]
211187
error: `path` attribute cannot be used at crate level
212188
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1
213189
|
214-
LL | #![path = "3800"]
215-
| ^^^^^^^^^^^^^^^^^
190+
LL | #![path = "3800"]
191+
| ^^^^^^^^^^^^^^^^^
216192
...
217-
LL | / mod inline {
218-
LL | |
219-
LL | |
220-
LL | |
221-
... |
222-
LL | |
223-
LL | | }
224-
| |_- the inner attribute doesn't annotate this module
193+
LL | mod inline {
194+
| ------ the inner attribute doesn't annotate this module
225195
|
226196
help: perhaps you meant to use an outer attribute
227197
|
@@ -232,17 +202,11 @@ LL + #[path = "3800"]
232202
error: `automatically_derived` attribute cannot be used at crate level
233203
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:1
234204
|
235-
LL | #![automatically_derived]
236-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
205+
LL | #![automatically_derived]
206+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
237207
...
238-
LL | / mod inline {
239-
LL | |
240-
LL | |
241-
LL | |
242-
... |
243-
LL | |
244-
LL | | }
245-
| |_- the inner attribute doesn't annotate this module
208+
LL | mod inline {
209+
| ------ the inner attribute doesn't annotate this module
246210
|
247211
help: perhaps you meant to use an outer attribute
248212
|

tests/ui/feature-gates/issue-43106-gating-of-test.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![test = "4200"]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
...
1515
LL | fn main() {}
16-
| ------------ the inner attribute doesn't annotate this function
16+
| ---- the inner attribute doesn't annotate this function
1717
|
1818
help: perhaps you meant to use an outer attribute
1919
|

tests/ui/span/issue-43927-non-ADT-derive.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute!
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414
...
1515
LL | struct DerivedOn;
16-
| ----------------- the inner attribute doesn't annotate this struct
16+
| --------- the inner attribute doesn't annotate this struct
1717
|
1818
help: perhaps you meant to use an outer attribute
1919
|

0 commit comments

Comments
 (0)