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 dbb73f8

Browse files
committedSep 12, 2020
Auto merge of #73461 - calebzulawski:validate-attribute-placement, r=matthewjasper
Validate built-in attribute placement Closes #54584, closes #47725, closes #54044. I've changed silently ignoring some incorrectly placed attributes to errors. I'm not sure what the policy is since this can theoretically break code (should they be warnings instead? does it warrant a crater run?).
2 parents 9891908 + 82cb379 commit dbb73f8

18 files changed

+1156
-462
lines changed
 

‎compiler/rustc_passes/src/check_attr.rs

Lines changed: 183 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,26 @@ impl CheckAttrVisitor<'tcx> {
6666
} else if self.tcx.sess.check_name(attr, sym::marker) {
6767
self.check_marker(attr, span, target)
6868
} else if self.tcx.sess.check_name(attr, sym::target_feature) {
69-
self.check_target_feature(attr, span, target)
69+
self.check_target_feature(hir_id, attr, span, target)
7070
} else if self.tcx.sess.check_name(attr, sym::track_caller) {
7171
self.check_track_caller(&attr.span, attrs, span, target)
7272
} else if self.tcx.sess.check_name(attr, sym::doc) {
7373
self.check_doc_alias(attr, hir_id, target)
74+
} else if self.tcx.sess.check_name(attr, sym::no_link) {
75+
self.check_no_link(&attr, span, target)
76+
} else if self.tcx.sess.check_name(attr, sym::export_name) {
77+
self.check_export_name(&attr, span, target)
7478
} else {
79+
// lint-only checks
80+
if self.tcx.sess.check_name(attr, sym::cold) {
81+
self.check_cold(hir_id, attr, span, target);
82+
} else if self.tcx.sess.check_name(attr, sym::link_name) {
83+
self.check_link_name(hir_id, attr, span, target);
84+
} else if self.tcx.sess.check_name(attr, sym::link_section) {
85+
self.check_link_section(hir_id, attr, span, target);
86+
} else if self.tcx.sess.check_name(attr, sym::no_mangle) {
87+
self.check_no_mangle(hir_id, attr, span, target);
88+
}
7589
true
7690
};
7791
}
@@ -109,12 +123,12 @@ impl CheckAttrVisitor<'tcx> {
109123
lint.build("`#[inline]` is ignored on constants")
110124
.warn(
111125
"this was previously accepted by the compiler but is \
112-
being phased out; it will become a hard error in \
113-
a future release!",
126+
being phased out; it will become a hard error in \
127+
a future release!",
114128
)
115129
.note(
116130
"see issue #65833 <https://github.com/rust-lang/rust/issues/65833> \
117-
for more information",
131+
for more information",
118132
)
119133
.emit();
120134
});
@@ -153,7 +167,7 @@ impl CheckAttrVisitor<'tcx> {
153167
.emit();
154168
false
155169
}
156-
Target::Fn | Target::Method(..) | Target::ForeignFn => true,
170+
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
157171
_ => {
158172
struct_span_err!(
159173
self.tcx.sess,
@@ -202,10 +216,31 @@ impl CheckAttrVisitor<'tcx> {
202216
}
203217

204218
/// Checks if the `#[target_feature]` attribute on `item` is valid. Returns `true` if valid.
205-
fn check_target_feature(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
219+
fn check_target_feature(
220+
&self,
221+
hir_id: HirId,
222+
attr: &Attribute,
223+
span: &Span,
224+
target: Target,
225+
) -> bool {
206226
match target {
207227
Target::Fn
208228
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
229+
// FIXME: #[target_feature] was previously erroneously allowed on statements and some
230+
// crates used this, so only emit a warning.
231+
Target::Statement => {
232+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
233+
lint.build("attribute should be applied to a function")
234+
.warn(
235+
"this was previously accepted by the compiler but is \
236+
being phased out; it will become a hard error in \
237+
a future release!",
238+
)
239+
.span_label(*span, "not a function")
240+
.emit();
241+
});
242+
true
243+
}
209244
_ => {
210245
self.tcx
211246
.sess
@@ -277,6 +312,136 @@ impl CheckAttrVisitor<'tcx> {
277312
true
278313
}
279314

315+
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
316+
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
317+
match target {
318+
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {}
319+
_ => {
320+
// FIXME: #[cold] was previously allowed on non-functions and some crates used
321+
// this, so only emit a warning.
322+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
323+
lint.build("attribute should be applied to a function")
324+
.warn(
325+
"this was previously accepted by the compiler but is \
326+
being phased out; it will become a hard error in \
327+
a future release!",
328+
)
329+
.span_label(*span, "not a function")
330+
.emit();
331+
});
332+
}
333+
}
334+
}
335+
336+
/// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
337+
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
338+
match target {
339+
Target::ForeignFn | Target::ForeignStatic => {}
340+
_ => {
341+
// FIXME: #[cold] was previously allowed on non-functions/statics and some crates
342+
// used this, so only emit a warning.
343+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
344+
let mut diag =
345+
lint.build("attribute should be applied to a foreign function or static");
346+
diag.warn(
347+
"this was previously accepted by the compiler but is \
348+
being phased out; it will become a hard error in \
349+
a future release!",
350+
);
351+
352+
// See issue #47725
353+
if let Target::ForeignMod = target {
354+
if let Some(value) = attr.value_str() {
355+
diag.span_help(
356+
attr.span,
357+
&format!(r#"try `#[link(name = "{}")]` instead"#, value),
358+
);
359+
} else {
360+
diag.span_help(attr.span, r#"try `#[link(name = "...")]` instead"#);
361+
}
362+
}
363+
364+
diag.span_label(*span, "not a foreign function or static");
365+
diag.emit();
366+
});
367+
}
368+
}
369+
}
370+
371+
/// Checks if `#[no_link]` is applied to an `extern crate`. Returns `true` if valid.
372+
fn check_no_link(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
373+
if target == Target::ExternCrate {
374+
true
375+
} else {
376+
self.tcx
377+
.sess
378+
.struct_span_err(attr.span, "attribute should be applied to an `extern crate` item")
379+
.span_label(*span, "not an `extern crate` item")
380+
.emit();
381+
false
382+
}
383+
}
384+
385+
/// Checks if `#[export_name]` is applied to a function or static. Returns `true` if valid.
386+
fn check_export_name(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
387+
match target {
388+
Target::Static | Target::Fn | Target::Method(..) => true,
389+
_ => {
390+
self.tcx
391+
.sess
392+
.struct_span_err(
393+
attr.span,
394+
"attribute should be applied to a function or static",
395+
)
396+
.span_label(*span, "not a function or static")
397+
.emit();
398+
false
399+
}
400+
}
401+
}
402+
403+
/// Checks if `#[link_section]` is applied to a function or static.
404+
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
405+
match target {
406+
Target::Static | Target::Fn | Target::Method(..) => {}
407+
_ => {
408+
// FIXME: #[link_section] was previously allowed on non-functions/statics and some
409+
// crates used this, so only emit a warning.
410+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
411+
lint.build("attribute should be applied to a function or static")
412+
.warn(
413+
"this was previously accepted by the compiler but is \
414+
being phased out; it will become a hard error in \
415+
a future release!",
416+
)
417+
.span_label(*span, "not a function or static")
418+
.emit();
419+
});
420+
}
421+
}
422+
}
423+
424+
/// Checks if `#[no_mangle]` is applied to a function or static.
425+
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
426+
match target {
427+
Target::Static | Target::Fn | Target::Method(..) => {}
428+
_ => {
429+
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
430+
// crates used this, so only emit a warning.
431+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
432+
lint.build("attribute should be applied to a function or static")
433+
.warn(
434+
"this was previously accepted by the compiler but is \
435+
being phased out; it will become a hard error in \
436+
a future release!",
437+
)
438+
.span_label(*span, "not a function or static")
439+
.emit();
440+
});
441+
}
442+
}
443+
}
444+
280445
/// Checks if the `#[repr]` attributes on `item` are valid.
281446
fn check_repr(
282447
&self,
@@ -321,7 +486,11 @@ impl CheckAttrVisitor<'tcx> {
321486
}
322487
sym::simd => {
323488
is_simd = true;
324-
if target != Target::Struct { ("a", "struct") } else { continue }
489+
if target != Target::Struct {
490+
("a", "struct")
491+
} else {
492+
continue;
493+
}
325494
}
326495
sym::transparent => {
327496
is_transparent = true;
@@ -358,7 +527,11 @@ impl CheckAttrVisitor<'tcx> {
358527
| sym::isize
359528
| sym::usize => {
360529
int_reprs += 1;
361-
if target != Target::Enum { ("an", "enum") } else { continue }
530+
if target != Target::Enum {
531+
("an", "enum")
532+
} else {
533+
continue;
534+
}
362535
}
363536
_ => continue,
364537
};
@@ -421,10 +594,8 @@ impl CheckAttrVisitor<'tcx> {
421594
fn check_stmt_attributes(&self, stmt: &hir::Stmt<'_>) {
422595
// When checking statements ignore expressions, they will be checked later
423596
if let hir::StmtKind::Local(ref l) = stmt.kind {
597+
self.check_attributes(l.hir_id, &l.attrs, &stmt.span, Target::Statement, None);
424598
for attr in l.attrs.iter() {
425-
if self.tcx.sess.check_name(attr, sym::inline) {
426-
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
427-
}
428599
if self.tcx.sess.check_name(attr, sym::repr) {
429600
self.emit_repr_error(
430601
attr.span,
@@ -442,10 +613,8 @@ impl CheckAttrVisitor<'tcx> {
442613
hir::ExprKind::Closure(..) => Target::Closure,
443614
_ => Target::Expression,
444615
};
616+
self.check_attributes(expr.hir_id, &expr.attrs, &expr.span, target, None);
445617
for attr in expr.attrs.iter() {
446-
if self.tcx.sess.check_name(attr, sym::inline) {
447-
self.check_inline(expr.hir_id, attr, &expr.span, target);
448-
}
449618
if self.tcx.sess.check_name(attr, sym::repr) {
450619
self.emit_repr_error(
451620
attr.span,

‎compiler/rustc_typeck/src/collect.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,10 +2525,17 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
25252525
codegen_fn_attrs.export_name = Some(s);
25262526
}
25272527
} else if tcx.sess.check_name(attr, sym::target_feature) {
2528-
if !tcx.features().target_feature_11 {
2529-
check_target_feature_safe_fn(tcx, id, attr.span);
2530-
} else if let Some(local_id) = id.as_local() {
2531-
if tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
2528+
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
2529+
if !tcx.features().target_feature_11 {
2530+
let mut err = feature_err(
2531+
&tcx.sess.parse_sess,
2532+
sym::target_feature_11,
2533+
attr.span,
2534+
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
2535+
);
2536+
err.span_label(tcx.def_span(id), "not an `unsafe` function");
2537+
err.emit();
2538+
} else if let Some(local_id) = id.as_local() {
25322539
check_target_feature_trait_unsafe(tcx, local_id, attr.span);
25332540
}
25342541
}
@@ -2785,21 +2792,6 @@ fn check_link_name_xor_ordinal(
27852792
}
27862793
}
27872794

2788-
/// Checks the function annotated with `#[target_feature]` is unsafe,
2789-
/// reporting an error if it isn't.
2790-
fn check_target_feature_safe_fn(tcx: TyCtxt<'_>, id: DefId, attr_span: Span) {
2791-
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
2792-
let mut err = feature_err(
2793-
&tcx.sess.parse_sess,
2794-
sym::target_feature_11,
2795-
attr_span,
2796-
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
2797-
);
2798-
err.span_label(tcx.def_span(id), "not an `unsafe` function");
2799-
err.emit();
2800-
}
2801-
}
2802-
28032795
/// Checks the function annotated with `#[target_feature]` is not a safe
28042796
/// trait method implementation, reporting an error if it is.
28052797
fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {

‎src/test/ui/check-static-recursion-foreign.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// run-pass
22

3-
#![allow(dead_code)]
43
// Static recursion check shouldn't fail when given a foreign item (#18279)
54

65
// aux-build:check_static_recursion_foreign_helper.rs
@@ -15,12 +14,10 @@ extern crate libc;
1514

1615
use libc::c_int;
1716

18-
#[link_name = "check_static_recursion_foreign_helper"]
1917
extern "C" {
20-
#[allow(dead_code)]
2118
static test_static: c_int;
2219
}
2320

24-
static B: &'static c_int = unsafe { &test_static };
21+
pub static B: &'static c_int = unsafe { &test_static };
2522

2623
pub fn main() {}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// This is testing whether various builtin attributes signals an
2+
// error or warning when put in "weird" places.
3+
//
4+
// (This file sits on its own because it actually signals an error,
5+
// which would mess up the treatment of other cases in
6+
// issue-43106-gating-of-builtin-attrs.rs)
7+
8+
// ignore-tidy-linelength
9+
10+
// Crate-level is accepted, though it is almost certainly unused?
11+
#![inline]
12+
13+
#[inline]
14+
//~^ ERROR attribute should be applied to function or closure
15+
mod inline {
16+
//~^ NOTE not a function or closure
17+
18+
mod inner { #![inline] }
19+
//~^ ERROR attribute should be applied to function or closure
20+
//~| NOTE not a function or closure
21+
22+
#[inline = "2100"] fn f() { }
23+
//~^ ERROR attribute must be of the form
24+
//~| WARN this was previously accepted
25+
//~| NOTE #[deny(ill_formed_attribute_input)]` on by default
26+
//~| NOTE for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
27+
28+
#[inline] struct S;
29+
//~^ ERROR attribute should be applied to function or closure
30+
//~| NOTE not a function or closure
31+
32+
#[inline] type T = S;
33+
//~^ ERROR attribute should be applied to function or closure
34+
//~| NOTE not a function or closure
35+
36+
#[inline] impl S { }
37+
//~^ ERROR attribute should be applied to function or closure
38+
//~| NOTE not a function or closure
39+
}
40+
41+
#[no_link]
42+
//~^ ERROR attribute should be applied to an `extern crate` item
43+
mod no_link {
44+
//~^ NOTE not an `extern crate` item
45+
46+
mod inner { #![no_link] }
47+
//~^ ERROR attribute should be applied to an `extern crate` item
48+
//~| NOTE not an `extern crate` item
49+
50+
#[no_link] fn f() { }
51+
//~^ ERROR attribute should be applied to an `extern crate` item
52+
//~| NOTE not an `extern crate` item
53+
54+
#[no_link] struct S;
55+
//~^ ERROR attribute should be applied to an `extern crate` item
56+
//~| NOTE not an `extern crate` item
57+
58+
#[no_link]type T = S;
59+
//~^ ERROR attribute should be applied to an `extern crate` item
60+
//~| NOTE not an `extern crate` item
61+
62+
#[no_link] impl S { }
63+
//~^ ERROR attribute should be applied to an `extern crate` item
64+
//~| NOTE not an `extern crate` item
65+
}
66+
67+
#[export_name = "2200"]
68+
//~^ ERROR attribute should be applied to a function or static
69+
mod export_name {
70+
//~^ NOTE not a function or static
71+
72+
mod inner { #![export_name="2200"] }
73+
//~^ ERROR attribute should be applied to a function or static
74+
//~| NOTE not a function or static
75+
76+
#[export_name = "2200"] fn f() { }
77+
78+
#[export_name = "2200"] struct S;
79+
//~^ ERROR attribute should be applied to a function or static
80+
//~| NOTE not a function or static
81+
82+
#[export_name = "2200"] type T = S;
83+
//~^ ERROR attribute should be applied to a function or static
84+
//~| NOTE not a function or static
85+
86+
#[export_name = "2200"] impl S { }
87+
//~^ ERROR attribute should be applied to a function or static
88+
//~| NOTE not a function or static
89+
}
90+
91+
fn main() {}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
2+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:5
3+
|
4+
LL | #[inline = "2100"] fn f() { }
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[deny(ill_formed_attribute_input)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
10+
11+
error[E0518]: attribute should be applied to function or closure
12+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:13:1
13+
|
14+
LL | #[inline]
15+
| ^^^^^^^^^
16+
LL |
17+
LL | / mod inline {
18+
LL | |
19+
LL | |
20+
LL | | mod inner { #![inline] }
21+
... |
22+
LL | |
23+
LL | | }
24+
| |_- not a function or closure
25+
26+
error: attribute should be applied to an `extern crate` item
27+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:41:1
28+
|
29+
LL | #[no_link]
30+
| ^^^^^^^^^^
31+
LL |
32+
LL | / mod no_link {
33+
LL | |
34+
LL | |
35+
LL | | mod inner { #![no_link] }
36+
... |
37+
LL | |
38+
LL | | }
39+
| |_- not an `extern crate` item
40+
41+
error: attribute should be applied to a function or static
42+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:1
43+
|
44+
LL | #[export_name = "2200"]
45+
| ^^^^^^^^^^^^^^^^^^^^^^^
46+
LL |
47+
LL | / mod export_name {
48+
LL | |
49+
LL | |
50+
LL | | mod inner { #![export_name="2200"] }
51+
... |
52+
LL | |
53+
LL | | }
54+
| |_- not a function or static
55+
56+
error[E0518]: attribute should be applied to function or closure
57+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:18:17
58+
|
59+
LL | mod inner { #![inline] }
60+
| ------------^^^^^^^^^^-- not a function or closure
61+
62+
error[E0518]: attribute should be applied to function or closure
63+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:28:5
64+
|
65+
LL | #[inline] struct S;
66+
| ^^^^^^^^^ --------- not a function or closure
67+
68+
error[E0518]: attribute should be applied to function or closure
69+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:5
70+
|
71+
LL | #[inline] type T = S;
72+
| ^^^^^^^^^ ----------- not a function or closure
73+
74+
error[E0518]: attribute should be applied to function or closure
75+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:5
76+
|
77+
LL | #[inline] impl S { }
78+
| ^^^^^^^^^ ---------- not a function or closure
79+
80+
error: attribute should be applied to an `extern crate` item
81+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:17
82+
|
83+
LL | mod inner { #![no_link] }
84+
| ------------^^^^^^^^^^^-- not an `extern crate` item
85+
86+
error: attribute should be applied to an `extern crate` item
87+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:50:5
88+
|
89+
LL | #[no_link] fn f() { }
90+
| ^^^^^^^^^^ ---------- not an `extern crate` item
91+
92+
error: attribute should be applied to an `extern crate` item
93+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
94+
|
95+
LL | #[no_link] struct S;
96+
| ^^^^^^^^^^ --------- not an `extern crate` item
97+
98+
error: attribute should be applied to an `extern crate` item
99+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:58:5
100+
|
101+
LL | #[no_link]type T = S;
102+
| ^^^^^^^^^^----------- not an `extern crate` item
103+
104+
error: attribute should be applied to an `extern crate` item
105+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:5
106+
|
107+
LL | #[no_link] impl S { }
108+
| ^^^^^^^^^^ ---------- not an `extern crate` item
109+
110+
error: attribute should be applied to a function or static
111+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:72:17
112+
|
113+
LL | mod inner { #![export_name="2200"] }
114+
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
115+
116+
error: attribute should be applied to a function or static
117+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:5
118+
|
119+
LL | #[export_name = "2200"] struct S;
120+
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
121+
122+
error: attribute should be applied to a function or static
123+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:82:5
124+
|
125+
LL | #[export_name = "2200"] type T = S;
126+
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
127+
128+
error: attribute should be applied to a function or static
129+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
130+
|
131+
LL | #[export_name = "2200"] impl S { }
132+
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static
133+
134+
error: aborting due to 17 previous errors
135+
136+
For more information about this error, try `rustc --explain E0518`.

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

Lines changed: 115 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@
3131
// occurrences in the source text.
3232

3333
// check-pass
34+
// ignore-tidy-linelength
3435

3536
#![feature(test, plugin_registrar)]
3637
#![warn(unused_attributes, unknown_lints)]
38+
//~^ NOTE the lint level is defined here
39+
//~| NOTE the lint level is defined here
3740

3841
// Exception, a gated and deprecated attribute.
3942

40-
#![plugin_registrar] //~ WARN unused attribute
43+
#![plugin_registrar]
44+
//~^ WARN unused attribute
4145
//~| WARN use of deprecated attribute
46+
//~| HELP may be removed in a future compiler version
4247

4348
// UNGATED WHITE-LISTED BUILT-IN ATTRIBUTES
4449

@@ -72,7 +77,7 @@
7277
#![doc = "2400"]
7378
#![cold]
7479
#![export_name = "2200"]
75-
// see issue-43106-gating-of-inline.rs
80+
// see issue-43106-gating-of-builtin-attrs-error.rs
7681
#![link()]
7782
#![link_name = "1900"]
7883
#![link_section = "1800"]
@@ -88,12 +93,18 @@
8893
#![crate_name = "0900"]
8994
#![crate_type = "bin"] // cannot pass "0800" here
9095

91-
#![crate_id = "10"] //~ WARN use of deprecated attribute
96+
#![crate_id = "10"]
97+
//~^ WARN use of deprecated attribute
98+
//~| HELP remove this attribute
9299

93100
// FIXME(#44232) we should warn that this isn't used.
94-
#![feature(rust1)] //~ WARN no longer requires an attribute to enable
101+
#![feature(rust1)]
102+
//~^ WARN no longer requires an attribute to enable
103+
//~| NOTE `#[warn(stable_features)]` on by default
95104

96-
#![no_start] //~ WARN use of deprecated attribute
105+
#![no_start]
106+
//~^ WARN use of deprecated attribute
107+
//~| HELP remove this attribute
97108

98109
// (cannot easily gating state of crate-level #[no_main]; but non crate-level is below at "0400")
99110
#![no_builtins]
@@ -217,24 +228,30 @@ mod macro_export {
217228
#[plugin_registrar]
218229
//~^ WARN unused attribute
219230
//~| WARN use of deprecated attribute
231+
//~| HELP may be removed in a future compiler version
220232
mod plugin_registrar {
221233
mod inner { #![plugin_registrar] }
222234
//~^ WARN unused attribute
223235
//~| WARN use of deprecated attribute
236+
//~| HELP may be removed in a future compiler version
237+
//~| NOTE `#[warn(deprecated)]` on by default
224238

225239
// for `fn f()` case, see gated-plugin_registrar.rs
226240

227241
#[plugin_registrar] struct S;
228242
//~^ WARN unused attribute
229243
//~| WARN use of deprecated attribute
244+
//~| HELP may be removed in a future compiler version
230245

231246
#[plugin_registrar] type T = S;
232247
//~^ WARN unused attribute
233248
//~| WARN use of deprecated attribute
249+
//~| HELP may be removed in a future compiler version
234250

235251
#[plugin_registrar] impl S { }
236252
//~^ WARN unused attribute
237253
//~| WARN use of deprecated attribute
254+
//~| HELP may be removed in a future compiler version
238255
}
239256

240257
#[main]
@@ -355,35 +372,31 @@ mod automatically_derived {
355372
}
356373

357374
#[no_mangle]
375+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
376+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
358377
mod no_mangle {
378+
//~^ NOTE not a function or static
359379
mod inner { #![no_mangle] }
380+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
381+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
382+
//~| NOTE not a function or static
360383

361384
#[no_mangle] fn f() { }
362385

363386
#[no_mangle] struct S;
387+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
388+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
389+
//~| NOTE not a function or static
364390

365391
#[no_mangle] type T = S;
392+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
393+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
394+
//~| NOTE not a function or static
366395

367396
#[no_mangle] impl S { }
368-
}
369-
370-
#[no_link]
371-
//~^ WARN unused attribute
372-
mod no_link {
373-
mod inner { #![no_link] }
374-
//~^ WARN unused attribute
375-
376-
#[no_link] fn f() { }
377-
//~^ WARN unused attribute
378-
379-
#[no_link] struct S;
380-
//~^ WARN unused attribute
381-
382-
#[no_link]type T = S;
383-
//~^ WARN unused attribute
384-
385-
#[no_link] impl S { }
386-
//~^ WARN unused attribute
397+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
398+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
399+
//~| NOTE not a function or static
387400
}
388401

389402
#[should_panic]
@@ -468,6 +481,7 @@ mod reexport_test_harness_main {
468481
mod macro_escape {
469482
mod inner { #![macro_escape] }
470483
//~^ WARN `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
484+
//~| HELP try an outer attribute: `#[macro_use]`
471485

472486
#[macro_escape] fn f() { }
473487
//~^ WARN unused attribute
@@ -525,73 +539,119 @@ mod doc {
525539
}
526540

527541
#[cold]
542+
//~^ WARN attribute should be applied to a function
543+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
528544
mod cold {
545+
//~^ NOTE not a function
546+
529547
mod inner { #![cold] }
548+
//~^ WARN attribute should be applied to a function
549+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
550+
//~| NOTE not a function
530551

531552
#[cold] fn f() { }
532553

533554
#[cold] struct S;
555+
//~^ WARN attribute should be applied to a function
556+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
557+
//~| NOTE not a function
534558

535559
#[cold] type T = S;
560+
//~^ WARN attribute should be applied to a function
561+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
562+
//~| NOTE not a function
536563

537564
#[cold] impl S { }
538-
}
539-
540-
#[export_name = "2200"]
541-
mod export_name {
542-
mod inner { #![export_name="2200"] }
543-
544-
#[export_name = "2200"] fn f() { }
545-
546-
#[export_name = "2200"] struct S;
547-
548-
#[export_name = "2200"] type T = S;
549-
550-
#[export_name = "2200"] impl S { }
551-
}
552-
553-
// Note that this is a `check-pass` test, so it
554-
// will never invoke the linker. These are here nonetheless to point
555-
// out that we allow them at non-crate-level (though I do not know
556-
// whether they have the same effect here as at crate-level).
557-
558-
#[link()]
559-
mod link {
560-
mod inner { #![link()] }
561-
562-
#[link()] fn f() { }
563-
564-
#[link()] struct S;
565-
566-
#[link()] type T = S;
567-
568-
#[link()] impl S { }
565+
//~^ WARN attribute should be applied to a function
566+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
567+
//~| NOTE not a function
569568
}
570569

571570
#[link_name = "1900"]
571+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
572+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
572573
mod link_name {
574+
//~^ NOTE not a foreign function or static
575+
576+
#[link_name = "1900"]
577+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
578+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
579+
//~| HELP try `#[link(name = "1900")]` instead
580+
extern { }
581+
//~^ NOTE not a foreign function or static
582+
573583
mod inner { #![link_name="1900"] }
584+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
585+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
586+
//~| NOTE not a foreign function or static
574587

575588
#[link_name = "1900"] fn f() { }
589+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
590+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
591+
//~| NOTE not a foreign function or static
576592

577593
#[link_name = "1900"] struct S;
594+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
595+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
596+
//~| NOTE not a foreign function or static
578597

579598
#[link_name = "1900"] type T = S;
599+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
600+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
601+
//~| NOTE not a foreign function or static
580602

581603
#[link_name = "1900"] impl S { }
604+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
605+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
606+
//~| NOTE not a foreign function or static
582607
}
583608

584609
#[link_section = "1800"]
610+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
611+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
585612
mod link_section {
613+
//~^ NOTE not a function or static
614+
586615
mod inner { #![link_section="1800"] }
616+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
617+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
618+
//~| NOTE not a function or static
587619

588620
#[link_section = "1800"] fn f() { }
589621

590622
#[link_section = "1800"] struct S;
623+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
624+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
625+
//~| NOTE not a function or static
591626

592627
#[link_section = "1800"] type T = S;
628+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
629+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
630+
//~| NOTE not a function or static
593631

594632
#[link_section = "1800"] impl S { }
633+
//~^ WARN attribute should be applied to a function or static [unused_attributes]
634+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
635+
//~| NOTE not a function or static
636+
}
637+
638+
639+
// Note that this is a `check-pass` test, so it
640+
// will never invoke the linker. These are here nonetheless to point
641+
// out that we allow them at non-crate-level (though I do not know
642+
// whether they have the same effect here as at crate-level).
643+
644+
#[link()]
645+
mod link {
646+
mod inner { #![link()] }
647+
648+
#[link()] fn f() { }
649+
650+
#[link()] struct S;
651+
652+
#[link()] type T = S;
653+
654+
#[link()] impl S { }
595655
}
596656

597657
struct StructForDeprecated;

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

Lines changed: 424 additions & 241 deletions
Large diffs are not rendered by default.

‎src/test/ui/feature-gate/issue-43106-gating-of-inline.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎src/test/ui/issues/issue-2214.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ fn lgamma(n: c_double, value: &mut isize) -> c_double {
2323
mod m {
2424
use libc::{c_double, c_int};
2525

26-
#[link_name = "m"]
2726
extern {
2827
#[cfg(any(all(unix, not(target_os = "vxworks")), target_os = "cloudabi"))]
2928
#[link_name="lgamma_r"]

‎src/test/ui/issues/issue-47725.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ignore-tidy-linelength
2+
#![warn(unused_attributes)] //~ NOTE lint level is defined here
3+
4+
#[link_name = "foo"]
5+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
6+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7+
struct Foo; //~ NOTE not a foreign function or static
8+
9+
#[link_name = "foobar"]
10+
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
11+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
//~| HELP try `#[link(name = "foobar")]` instead
13+
extern "C" {
14+
fn foo() -> u32;
15+
}
16+
//~^^^ NOTE not a foreign function or static
17+
18+
#[link_name]
19+
//~^ ERROR malformed `link_name` attribute input
20+
//~| HELP must be of the form
21+
//~| WARN attribute should be applied to a foreign function or static [unused_attributes]
22+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
//~| HELP try `#[link(name = "...")]` instead
24+
extern "C" {
25+
fn bar() -> u32;
26+
}
27+
//~^^^ NOTE not a foreign function or static
28+
29+
fn main() {}

‎src/test/ui/issues/issue-47725.stderr

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error: malformed `link_name` attribute input
2+
--> $DIR/issue-47725.rs:18:1
3+
|
4+
LL | #[link_name]
5+
| ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]`
6+
7+
warning: attribute should be applied to a foreign function or static
8+
--> $DIR/issue-47725.rs:4:1
9+
|
10+
LL | #[link_name = "foo"]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
...
13+
LL | struct Foo;
14+
| ----------- not a foreign function or static
15+
|
16+
note: the lint level is defined here
17+
--> $DIR/issue-47725.rs:2:9
18+
|
19+
LL | #![warn(unused_attributes)]
20+
| ^^^^^^^^^^^^^^^^^
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22+
23+
warning: attribute should be applied to a foreign function or static
24+
--> $DIR/issue-47725.rs:9:1
25+
|
26+
LL | #[link_name = "foobar"]
27+
| ^^^^^^^^^^^^^^^^^^^^^^^
28+
...
29+
LL | / extern "C" {
30+
LL | | fn foo() -> u32;
31+
LL | | }
32+
| |_- not a foreign function or static
33+
|
34+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
35+
help: try `#[link(name = "foobar")]` instead
36+
--> $DIR/issue-47725.rs:9:1
37+
|
38+
LL | #[link_name = "foobar"]
39+
| ^^^^^^^^^^^^^^^^^^^^^^^
40+
41+
warning: attribute should be applied to a foreign function or static
42+
--> $DIR/issue-47725.rs:18:1
43+
|
44+
LL | #[link_name]
45+
| ^^^^^^^^^^^^
46+
...
47+
LL | / extern "C" {
48+
LL | | fn bar() -> u32;
49+
LL | | }
50+
| |_- not a foreign function or static
51+
|
52+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
53+
help: try `#[link(name = "...")]` instead
54+
--> $DIR/issue-47725.rs:18:1
55+
|
56+
LL | #[link_name]
57+
| ^^^^^^^^^^^^
58+
59+
error: aborting due to previous error; 3 warnings emitted
60+

‎src/test/ui/issues/issue-54044.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// ignore-tidy-linelength
2+
#![deny(unused_attributes)] //~ NOTE lint level is defined here
3+
4+
#[cold]
5+
//~^ ERROR attribute should be applied to a function
6+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
7+
struct Foo; //~ NOTE not a function
8+
9+
fn main() {
10+
#[cold]
11+
//~^ ERROR attribute should be applied to a function
12+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
13+
5; //~ NOTE not a function
14+
}

‎src/test/ui/issues/issue-54044.stderr

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: attribute should be applied to a function
2+
--> $DIR/issue-54044.rs:4:1
3+
|
4+
LL | #[cold]
5+
| ^^^^^^^
6+
...
7+
LL | struct Foo;
8+
| ----------- not a function
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/issue-54044.rs:2:9
12+
|
13+
LL | #![deny(unused_attributes)]
14+
| ^^^^^^^^^^^^^^^^^
15+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16+
17+
error: attribute should be applied to a function
18+
--> $DIR/issue-54044.rs:10:5
19+
|
20+
LL | #[cold]
21+
| ^^^^^^^
22+
...
23+
LL | 5;
24+
| - not a function
25+
|
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
28+
error: aborting due to 2 previous errors
29+

‎src/test/ui/macros/issue-68060.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ fn main() {
22
(0..)
33
.map(
44
#[target_feature(enable = "")]
5-
//~^ ERROR: the feature named `` is not valid for this target
6-
//~| ERROR: `#[target_feature(..)]` can only be applied to `unsafe` functions
5+
//~^ ERROR: attribute should be applied to a function
6+
//~| ERROR: the feature named `` is not valid for this target
7+
//~| NOTE: `` is not valid for this target
78
#[track_caller]
8-
//~^ ERROR: `#[track_caller]` requires Rust ABI
9+
//~^ ERROR: `#[track_caller]` requires Rust ABI [E0737]
910
|_| (),
11+
//~^ NOTE: not a function
1012
)
1113
.next();
1214
}

‎src/test/ui/macros/issue-68060.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
1+
error: attribute should be applied to a function
22
--> $DIR/issue-68060.rs:4:13
33
|
44
LL | #[target_feature(enable = "")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
...
77
LL | |_| (),
8-
| ------ not an `unsafe` function
9-
|
10-
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
11-
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
8+
| ------ not a function
129

1310
error: the feature named `` is not valid for this target
1411
--> $DIR/issue-68060.rs:4:30
@@ -17,12 +14,11 @@ LL | #[target_feature(enable = "")]
1714
| ^^^^^^^^^^^ `` is not valid for this target
1815

1916
error[E0737]: `#[track_caller]` requires Rust ABI
20-
--> $DIR/issue-68060.rs:7:13
17+
--> $DIR/issue-68060.rs:8:13
2118
|
2219
LL | #[track_caller]
2320
| ^^^^^^^^^^^^^^^
2421

2522
error: aborting due to 3 previous errors
2623

27-
Some errors have detailed explanations: E0658, E0737.
28-
For more information about an error, try `rustc --explain E0658`.
24+
For more information about this error, try `rustc --explain E0737`.

‎src/test/ui/target-feature/invalid-attribute.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ignore-sparc64
1414

1515
#![feature(target_feature)]
16+
#![warn(unused_attributes)]
1617

1718
#[target_feature = "+sse2"]
1819
//~^ ERROR malformed `target_feature` attribute
@@ -48,17 +49,20 @@ struct Foo;
4849

4950
#[target_feature(enable = "sse2")]
5051
//~^ ERROR attribute should be applied to a function
51-
enum Bar { }
52+
enum Bar {}
5253
//~^ NOTE not a function
5354

5455
#[target_feature(enable = "sse2")]
5556
//~^ ERROR attribute should be applied to a function
56-
union Qux { f1: u16, f2: u16 }
57+
union Qux {
5758
//~^ NOTE not a function
59+
f1: u16,
60+
f2: u16,
61+
}
5862

5963
#[target_feature(enable = "sse2")]
6064
//~^ ERROR attribute should be applied to a function
61-
trait Baz { }
65+
trait Baz {}
6266
//~^ NOTE not a function
6367

6468
#[inline(always)]
@@ -79,13 +83,16 @@ impl Quux for Foo {
7983
}
8084

8185
fn main() {
86+
#[target_feature(enable = "sse2")]
87+
//~^ ERROR attribute should be applied to a function
8288
unsafe {
8389
foo();
8490
bar();
8591
}
92+
//~^^^^ NOTE not a function
93+
8694
#[target_feature(enable = "sse2")]
87-
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
88-
//~| NOTE see issue #69098
95+
//~^ ERROR attribute should be applied to a function
8996
|| {};
90-
//~^ NOTE not an `unsafe` function
97+
//~^ NOTE not a function
9198
}
Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error: malformed `target_feature` attribute input
2-
--> $DIR/invalid-attribute.rs:17:1
2+
--> $DIR/invalid-attribute.rs:18:1
33
|
44
LL | #[target_feature = "+sse2"]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]`
66

77
error: the feature named `foo` is not valid for this target
8-
--> $DIR/invalid-attribute.rs:19:18
8+
--> $DIR/invalid-attribute.rs:20:18
99
|
1010
LL | #[target_feature(enable = "foo")]
1111
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
1212

1313
error: malformed `target_feature` attribute input
14-
--> $DIR/invalid-attribute.rs:22:18
14+
--> $DIR/invalid-attribute.rs:23:18
1515
|
1616
LL | #[target_feature(bar)]
1717
| ^^^ help: must be of the form: `enable = ".."`
1818

1919
error: malformed `target_feature` attribute input
20-
--> $DIR/invalid-attribute.rs:24:18
20+
--> $DIR/invalid-attribute.rs:25:18
2121
|
2222
LL | #[target_feature(disable = "baz")]
2323
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
2424

2525
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
26-
--> $DIR/invalid-attribute.rs:28:1
26+
--> $DIR/invalid-attribute.rs:29:1
2727
|
2828
LL | #[target_feature(enable = "sse2")]
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -35,7 +35,7 @@ LL | fn bar() {}
3535
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
3636

3737
error: attribute should be applied to a function
38-
--> $DIR/invalid-attribute.rs:34:1
38+
--> $DIR/invalid-attribute.rs:35:1
3939
|
4040
LL | #[target_feature(enable = "sse2")]
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -44,7 +44,7 @@ LL | mod another {}
4444
| -------------- not a function
4545

4646
error: attribute should be applied to a function
47-
--> $DIR/invalid-attribute.rs:39:1
47+
--> $DIR/invalid-attribute.rs:40:1
4848
|
4949
LL | #[target_feature(enable = "sse2")]
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -53,7 +53,7 @@ LL | const FOO: usize = 7;
5353
| --------------------- not a function
5454

5555
error: attribute should be applied to a function
56-
--> $DIR/invalid-attribute.rs:44:1
56+
--> $DIR/invalid-attribute.rs:45:1
5757
|
5858
LL | #[target_feature(enable = "sse2")]
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -62,52 +62,65 @@ LL | struct Foo;
6262
| ----------- not a function
6363

6464
error: attribute should be applied to a function
65-
--> $DIR/invalid-attribute.rs:49:1
65+
--> $DIR/invalid-attribute.rs:50:1
6666
|
6767
LL | #[target_feature(enable = "sse2")]
6868
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6969
LL |
70-
LL | enum Bar { }
71-
| ------------ not a function
70+
LL | enum Bar {}
71+
| ----------- not a function
7272

7373
error: attribute should be applied to a function
74-
--> $DIR/invalid-attribute.rs:54:1
74+
--> $DIR/invalid-attribute.rs:55:1
7575
|
76-
LL | #[target_feature(enable = "sse2")]
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
LL | #[target_feature(enable = "sse2")]
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7878
LL |
79-
LL | union Qux { f1: u16, f2: u16 }
80-
| ------------------------------ not a function
79+
LL | / union Qux {
80+
LL | |
81+
LL | | f1: u16,
82+
LL | | f2: u16,
83+
LL | | }
84+
| |_- not a function
8185

8286
error: attribute should be applied to a function
83-
--> $DIR/invalid-attribute.rs:59:1
87+
--> $DIR/invalid-attribute.rs:63:1
8488
|
8589
LL | #[target_feature(enable = "sse2")]
8690
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8791
LL |
88-
LL | trait Baz { }
89-
| ------------- not a function
92+
LL | trait Baz {}
93+
| ------------ not a function
9094

9195
error: cannot use `#[inline(always)]` with `#[target_feature]`
92-
--> $DIR/invalid-attribute.rs:64:1
96+
--> $DIR/invalid-attribute.rs:68:1
9397
|
9498
LL | #[inline(always)]
9599
| ^^^^^^^^^^^^^^^^^
96100

97-
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
101+
error: attribute should be applied to a function
98102
--> $DIR/invalid-attribute.rs:86:5
99103
|
104+
LL | #[target_feature(enable = "sse2")]
105+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106+
LL |
107+
LL | / unsafe {
108+
LL | | foo();
109+
LL | | bar();
110+
LL | | }
111+
| |_____- not a function
112+
113+
error: attribute should be applied to a function
114+
--> $DIR/invalid-attribute.rs:94:5
115+
|
100116
LL | #[target_feature(enable = "sse2")]
101117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102-
...
118+
LL |
103119
LL | || {};
104-
| ----- not an `unsafe` function
105-
|
106-
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
107-
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
120+
| ----- not a function
108121

109122
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
110-
--> $DIR/invalid-attribute.rs:74:5
123+
--> $DIR/invalid-attribute.rs:78:5
111124
|
112125
LL | #[target_feature(enable = "sse2")]
113126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,6 +131,6 @@ LL | fn foo() {}
118131
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
119132
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
120133

121-
error: aborting due to 14 previous errors
134+
error: aborting due to 15 previous errors
122135

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

0 commit comments

Comments
 (0)
Please sign in to comment.