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 f8807cc

Browse files
authoredOct 27, 2023
Rollup merge of rust-lang#116868 - estebank:suggestion, r=petrochenkov
Tweak suggestion span for outer attr and point at item following invalid inner attr After: ``` error: `unix_sigpipe` attribute cannot be used at crate level --> $DIR/unix_sigpipe-crate.rs:2:1 | LL | #![unix_sigpipe = "inherit"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | fn main() {} | ------------ the inner attribute doesn't annotate this function | help: perhaps you meant to use an outer attribute | LL - #![unix_sigpipe = "inherit"] LL + #[unix_sigpipe = "inherit"] | ``` Before: ``` error: `unix_sigpipe` attribute cannot be used at crate level --> $DIR/unix_sigpipe-crate.rs:2:1 | LL | #![unix_sigpipe = "inherit"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: perhaps you meant to use an outer attribute | LL | #[unix_sigpipe = "inherit"] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` CC rust-lang#89566.
2 parents 9af5c37 + 27919ce commit f8807cc

11 files changed

+160
-60
lines changed
 

‎compiler/rustc_passes/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ passes_invalid_attr_at_crate_level =
393393
`{$name}` attribute cannot be used at crate level
394394
.suggestion = perhaps you meant to use an outer attribute
395395
396+
passes_invalid_attr_at_crate_level_item =
397+
the inner attribute doesn't annotate this {$kind}
398+
396399
passes_invalid_deprecation_version =
397400
invalid deprecation version found
398401
.label = invalid deprecation version

‎compiler/rustc_passes/src/check_attr.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -2534,10 +2534,30 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
25342534
if attr.style == AttrStyle::Inner {
25352535
for attr_to_check in ATTRS_TO_CHECK {
25362536
if attr.has_name(*attr_to_check) {
2537+
let item = tcx
2538+
.hir()
2539+
.items()
2540+
.map(|id| tcx.hir().item(id))
2541+
.find(|item| !item.span.is_dummy()) // Skip prelude `use`s
2542+
.map(|item| errors::ItemFollowingInnerAttr {
2543+
span: item.ident.span,
2544+
kind: item.kind.descr(),
2545+
});
25372546
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
25382547
span: attr.span,
2539-
snippet: tcx.sess.source_map().span_to_snippet(attr.span).ok(),
2548+
sugg_span: tcx
2549+
.sess
2550+
.source_map()
2551+
.span_to_snippet(attr.span)
2552+
.ok()
2553+
.filter(|src| src.starts_with("#!["))
2554+
.map(|_| {
2555+
attr.span
2556+
.with_lo(attr.span.lo() + BytePos(1))
2557+
.with_hi(attr.span.lo() + BytePos(2))
2558+
}),
25402559
name: *attr_to_check,
2560+
item,
25412561
});
25422562
}
25432563
}

‎compiler/rustc_passes/src/errors.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -856,8 +856,15 @@ pub struct UnknownLangItem {
856856

857857
pub struct InvalidAttrAtCrateLevel {
858858
pub span: Span,
859-
pub snippet: Option<String>,
859+
pub sugg_span: Option<Span>,
860860
pub name: Symbol,
861+
pub item: Option<ItemFollowingInnerAttr>,
862+
}
863+
864+
#[derive(Clone, Copy)]
865+
pub struct ItemFollowingInnerAttr {
866+
pub span: Span,
867+
pub kind: &'static str,
861868
}
862869

863870
impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
@@ -871,15 +878,18 @@ impl IntoDiagnostic<'_> for InvalidAttrAtCrateLevel {
871878
diag.set_arg("name", self.name);
872879
// Only emit an error with a suggestion if we can create a string out
873880
// of the attribute span
874-
if let Some(src) = self.snippet {
875-
let replacement = src.replace("#!", "#");
881+
if let Some(span) = self.sugg_span {
876882
diag.span_suggestion_verbose(
877-
self.span,
883+
span,
878884
fluent::passes_suggestion,
879-
replacement,
885+
String::new(),
880886
rustc_errors::Applicability::MachineApplicable,
881887
);
882888
}
889+
if let Some(item) = self.item {
890+
diag.set_arg("kind", item.kind);
891+
diag.span_label(item.span, fluent::passes_invalid_attr_at_crate_level_item);
892+
}
883893
diag
884894
}
885895
}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ error: `unix_sigpipe` attribute cannot be used at crate level
33
|
44
LL | #![unix_sigpipe = "inherit"]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL |
7+
LL | fn main() {}
8+
| ---- the inner attribute doesn't annotate this function
69
|
710
help: perhaps you meant to use an outer attribute
811
|
9-
LL | #[unix_sigpipe = "inherit"]
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
12+
LL - #![unix_sigpipe = "inherit"]
13+
LL + #[unix_sigpipe = "inherit"]
14+
|
1115

1216
error: aborting due to previous error
1317

‎tests/ui/derives/issue-36617.stderr

+30-10
Original file line numberDiff line numberDiff line change
@@ -43,55 +43,75 @@ error: `derive` attribute cannot be used at crate level
4343
|
4444
LL | #![derive(Copy)]
4545
| ^^^^^^^^^^^^^^^^
46+
...
47+
LL | fn main() {}
48+
| ---- the inner attribute doesn't annotate this function
4649
|
4750
help: perhaps you meant to use an outer attribute
4851
|
49-
LL | #[derive(Copy)]
50-
| ~~~~~~~~~~~~~~~
52+
LL - #![derive(Copy)]
53+
LL + #[derive(Copy)]
54+
|
5155

5256
error: `test` attribute cannot be used at crate level
5357
--> $DIR/issue-36617.rs:4:1
5458
|
5559
LL | #![test]
5660
| ^^^^^^^^
61+
...
62+
LL | fn main() {}
63+
| ---- the inner attribute doesn't annotate this function
5764
|
5865
help: perhaps you meant to use an outer attribute
5966
|
60-
LL | #[test]
61-
| ~~~~~~~
67+
LL - #![test]
68+
LL + #[test]
69+
|
6270

6371
error: `test_case` attribute cannot be used at crate level
6472
--> $DIR/issue-36617.rs:7:1
6573
|
6674
LL | #![test_case]
6775
| ^^^^^^^^^^^^^
76+
...
77+
LL | fn main() {}
78+
| ---- the inner attribute doesn't annotate this function
6879
|
6980
help: perhaps you meant to use an outer attribute
7081
|
71-
LL | #[test_case]
72-
| ~~~~~~~~~~~~
82+
LL - #![test_case]
83+
LL + #[test_case]
84+
|
7385

7486
error: `bench` attribute cannot be used at crate level
7587
--> $DIR/issue-36617.rs:10:1
7688
|
7789
LL | #![bench]
7890
| ^^^^^^^^^
91+
...
92+
LL | fn main() {}
93+
| ---- the inner attribute doesn't annotate this function
7994
|
8095
help: perhaps you meant to use an outer attribute
8196
|
82-
LL | #[bench]
83-
| ~~~~~~~~
97+
LL - #![bench]
98+
LL + #[bench]
99+
|
84100

85101
error: `global_allocator` attribute cannot be used at crate level
86102
--> $DIR/issue-36617.rs:13:1
87103
|
88104
LL | #![global_allocator]
89105
| ^^^^^^^^^^^^^^^^^^^^
106+
...
107+
LL | fn main() {}
108+
| ---- the inner attribute doesn't annotate this function
90109
|
91110
help: perhaps you meant to use an outer attribute
92111
|
93-
LL | #[global_allocator]
94-
| ~~~~~~~~~~~~~~~~~~~
112+
LL - #![global_allocator]
113+
LL + #[global_allocator]
114+
|
95115

96116
error: aborting due to 10 previous errors
97117

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ error: `bench` attribute cannot be used at crate level
1111
|
1212
LL | #![bench = "4100"]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
...
15+
LL | fn main() {}
16+
| ---- the inner attribute doesn't annotate this function
1417
|
1518
help: perhaps you meant to use an outer attribute
1619
|
17-
LL | #[bench = "4100"]
20+
LL - #![bench = "4100"]
21+
LL + #[bench = "4100"]
1822
|
1923

2024
error: aborting due to 2 previous errors

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

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
//~^ ERROR attribute should be applied to function or closure
3333
mod inline {
3434
//~^ NOTE not a function or closure
35+
//~| NOTE the inner attribute doesn't annotate this module
36+
//~| NOTE the inner attribute doesn't annotate this module
37+
//~| NOTE the inner attribute doesn't annotate this module
38+
//~| NOTE the inner attribute doesn't annotate this module
39+
//~| NOTE the inner attribute doesn't annotate this module
40+
//~| NOTE the inner attribute doesn't annotate this module
3541

3642
mod inner { #![inline] }
3743
//~^ ERROR attribute should be applied to function or closure

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

+60-36
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #![rustc_main]
77
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
88

99
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
10-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:40:5
10+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
1111
|
1212
LL | #[inline = "2100"] fn f() { }
1313
| ^^^^^^^^^^^^^^^^^^
@@ -17,31 +17,31 @@ LL | #[inline = "2100"] fn f() { }
1717
= note: `#[deny(ill_formed_attribute_input)]` on by default
1818

1919
error: `start` attribute can only be used on functions
20-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119:1
20+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:125:1
2121
|
2222
LL | #[start]
2323
| ^^^^^^^^
2424

2525
error: `start` attribute can only be used on functions
26-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:122:17
26+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:128:17
2727
|
2828
LL | mod inner { #![start] }
2929
| ^^^^^^^^^
3030

3131
error: `start` attribute can only be used on functions
32-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5
32+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:133:5
3333
|
3434
LL | #[start] struct S;
3535
| ^^^^^^^^
3636

3737
error: `start` attribute can only be used on functions
38-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:130:5
38+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:136:5
3939
|
4040
LL | #[start] type T = S;
4141
| ^^^^^^^^
4242

4343
error: `start` attribute can only be used on functions
44-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:133:5
44+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:139:5
4545
|
4646
LL | #[start] impl S { }
4747
| ^^^^^^^^
@@ -55,14 +55,14 @@ LL |
5555
LL | / mod inline {
5656
LL | |
5757
LL | |
58-
LL | | mod inner { #![inline] }
58+
LL | |
5959
... |
6060
LL | |
6161
LL | | }
6262
| |_- not a function or closure
6363

6464
error: attribute should be applied to an `extern crate` item
65-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:59:1
65+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:65:1
6666
|
6767
LL | #[no_link]
6868
| ^^^^^^^^^^
@@ -77,7 +77,7 @@ LL | | }
7777
| |_- not an `extern crate` item
7878

7979
error: attribute should be applied to a free function, impl method or static
80-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:85:1
80+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:91:1
8181
|
8282
LL | #[export_name = "2200"]
8383
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -92,7 +92,7 @@ LL | | }
9292
| |_- not a free function, impl method or static
9393

9494
error[E0517]: attribute should be applied to a struct, enum, or union
95-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:8
95+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:143:8
9696
|
9797
LL | #[repr(C)]
9898
| ^
@@ -129,177 +129,201 @@ error: `macro_export` attribute cannot be used at crate level
129129
|
130130
LL | #![macro_export]
131131
| ^^^^^^^^^^^^^^^^
132+
...
133+
LL | mod inline {
134+
| ------ the inner attribute doesn't annotate this module
132135
|
133136
help: perhaps you meant to use an outer attribute
134137
|
135-
LL | #[macro_export]
138+
LL - #![macro_export]
139+
LL + #[macro_export]
136140
|
137141

138142
error: `rustc_main` attribute cannot be used at crate level
139143
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:14:1
140144
|
141145
LL | #![rustc_main]
142146
| ^^^^^^^^^^^^^^
147+
...
148+
LL | mod inline {
149+
| ------ the inner attribute doesn't annotate this module
143150
|
144151
help: perhaps you meant to use an outer attribute
145152
|
146-
LL | #[rustc_main]
147-
| ~~~~~~~~~~~~~
153+
LL - #![rustc_main]
154+
LL + #[rustc_main]
155+
|
148156

149157
error: `start` attribute cannot be used at crate level
150158
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
151159
|
152160
LL | #![start]
153161
| ^^^^^^^^^
162+
...
163+
LL | mod inline {
164+
| ------ the inner attribute doesn't annotate this module
154165
|
155166
help: perhaps you meant to use an outer attribute
156167
|
157-
LL | #[start]
168+
LL - #![start]
169+
LL + #[start]
158170
|
159171

160172
error: `repr` attribute cannot be used at crate level
161173
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:18:1
162174
|
163175
LL | #![repr()]
164176
| ^^^^^^^^^^
177+
...
178+
LL | mod inline {
179+
| ------ the inner attribute doesn't annotate this module
165180
|
166181
help: perhaps you meant to use an outer attribute
167182
|
168-
LL | #[repr()]
183+
LL - #![repr()]
184+
LL + #[repr()]
169185
|
170186

171187
error: `path` attribute cannot be used at crate level
172188
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1
173189
|
174190
LL | #![path = "3800"]
175191
| ^^^^^^^^^^^^^^^^^
192+
...
193+
LL | mod inline {
194+
| ------ the inner attribute doesn't annotate this module
176195
|
177196
help: perhaps you meant to use an outer attribute
178197
|
179-
LL | #[path = "3800"]
198+
LL - #![path = "3800"]
199+
LL + #[path = "3800"]
180200
|
181201

182202
error: `automatically_derived` attribute cannot be used at crate level
183203
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:1
184204
|
185205
LL | #![automatically_derived]
186206
| ^^^^^^^^^^^^^^^^^^^^^^^^^
207+
...
208+
LL | mod inline {
209+
| ------ the inner attribute doesn't annotate this module
187210
|
188211
help: perhaps you meant to use an outer attribute
189212
|
190-
LL | #[automatically_derived]
213+
LL - #![automatically_derived]
214+
LL + #[automatically_derived]
191215
|
192216

193217
error[E0518]: attribute should be applied to function or closure
194-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:17
218+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:42:17
195219
|
196220
LL | mod inner { #![inline] }
197221
| ------------^^^^^^^^^^-- not a function or closure
198222

199223
error[E0518]: attribute should be applied to function or closure
200-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
224+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:52:5
201225
|
202226
LL | #[inline] struct S;
203227
| ^^^^^^^^^ --------- not a function or closure
204228

205229
error[E0518]: attribute should be applied to function or closure
206-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:50:5
230+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:56:5
207231
|
208232
LL | #[inline] type T = S;
209233
| ^^^^^^^^^ ----------- not a function or closure
210234

211235
error[E0518]: attribute should be applied to function or closure
212-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
236+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:60:5
213237
|
214238
LL | #[inline] impl S { }
215239
| ^^^^^^^^^ ---------- not a function or closure
216240

217241
error: attribute should be applied to an `extern crate` item
218-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:17
242+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:70:17
219243
|
220244
LL | mod inner { #![no_link] }
221245
| ------------^^^^^^^^^^^-- not an `extern crate` item
222246

223247
error: attribute should be applied to an `extern crate` item
224-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:68:5
248+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:74:5
225249
|
226250
LL | #[no_link] fn f() { }
227251
| ^^^^^^^^^^ ---------- not an `extern crate` item
228252

229253
error: attribute should be applied to an `extern crate` item
230-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:72:5
254+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:5
231255
|
232256
LL | #[no_link] struct S;
233257
| ^^^^^^^^^^ --------- not an `extern crate` item
234258

235259
error: attribute should be applied to an `extern crate` item
236-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:76:5
260+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:82:5
237261
|
238262
LL | #[no_link]type T = S;
239263
| ^^^^^^^^^^----------- not an `extern crate` item
240264

241265
error: attribute should be applied to an `extern crate` item
242-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:5
266+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
243267
|
244268
LL | #[no_link] impl S { }
245269
| ^^^^^^^^^^ ---------- not an `extern crate` item
246270

247271
error: attribute should be applied to a free function, impl method or static
248-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:90:17
272+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:17
249273
|
250274
LL | mod inner { #![export_name="2200"] }
251275
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a free function, impl method or static
252276

253277
error: attribute should be applied to a free function, impl method or static
254-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:5
278+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:102:5
255279
|
256280
LL | #[export_name = "2200"] struct S;
257281
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
258282

259283
error: attribute should be applied to a free function, impl method or static
260-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:100:5
284+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:5
261285
|
262286
LL | #[export_name = "2200"] type T = S;
263287
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
264288

265289
error: attribute should be applied to a free function, impl method or static
266-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:104:5
290+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:110:5
267291
|
268292
LL | #[export_name = "2200"] impl S { }
269293
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a free function, impl method or static
270294

271295
error: attribute should be applied to a free function, impl method or static
272-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:9
296+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:115:9
273297
|
274298
LL | #[export_name = "2200"] fn foo();
275299
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
276300

277301
error: attribute should be applied to a free function, impl method or static
278-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113:9
302+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119:9
279303
|
280304
LL | #[export_name = "2200"] fn bar() {}
281305
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
282306

283307
error[E0517]: attribute should be applied to a struct, enum, or union
284-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:25
308+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147:25
285309
|
286310
LL | mod inner { #![repr(C)] }
287311
| --------------------^---- not a struct, enum, or union
288312

289313
error[E0517]: attribute should be applied to a struct, enum, or union
290-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:145:12
314+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:12
291315
|
292316
LL | #[repr(C)] fn f() { }
293317
| ^ ---------- not a struct, enum, or union
294318

295319
error[E0517]: attribute should be applied to a struct, enum, or union
296-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:12
320+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:157:12
297321
|
298322
LL | #[repr(C)] type T = S;
299323
| ^ ----------- not a struct, enum, or union
300324

301325
error[E0517]: attribute should be applied to a struct, enum, or union
302-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12
326+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:161:12
303327
|
304328
LL | #[repr(C)] impl S { }
305329
| ^ ---------- not a struct, enum, or union

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ error: `test` attribute cannot be used at crate level
1111
|
1212
LL | #![test = "4200"]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
...
15+
LL | fn main() {}
16+
| ---- the inner attribute doesn't annotate this function
1417
|
1518
help: perhaps you meant to use an outer attribute
1619
|
17-
LL | #[test = "4200"]
20+
LL - #![test = "4200"]
21+
LL + #[test = "4200"]
1822
|
1923

2024
error: aborting due to 2 previous errors

‎tests/ui/imports/issue-28134.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ LL | #![test]
1414
|
1515
help: perhaps you meant to use an outer attribute
1616
|
17-
LL | #[test]
18-
| ~~~~~~~
17+
LL - #![test]
18+
LL + #[test]
19+
|
1920

2021
error: aborting due to 2 previous errors
2122

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ error: `derive` attribute cannot be used at crate level
1111
|
1212
LL | #![derive(Debug, PartialEq, Eq)] // should be an outer attribute!
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
...
15+
LL | struct DerivedOn;
16+
| --------- the inner attribute doesn't annotate this struct
1417
|
1518
help: perhaps you meant to use an outer attribute
1619
|
17-
LL | #[derive(Debug, PartialEq, Eq)] // should be an outer attribute!
18-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
LL - #![derive(Debug, PartialEq, Eq)] // should be an outer attribute!
21+
LL + #[derive(Debug, PartialEq, Eq)] // should be an outer attribute!
22+
|
1923

2024
error: aborting due to 2 previous errors
2125

0 commit comments

Comments
 (0)
Please sign in to comment.