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?).
This commit is contained in:
commit
dbb73f8f79
18 changed files with 1167 additions and 473 deletions
|
@ -66,12 +66,26 @@ impl CheckAttrVisitor<'tcx> {
|
|||
} else if self.tcx.sess.check_name(attr, sym::marker) {
|
||||
self.check_marker(attr, span, target)
|
||||
} else if self.tcx.sess.check_name(attr, sym::target_feature) {
|
||||
self.check_target_feature(attr, span, target)
|
||||
self.check_target_feature(hir_id, attr, span, target)
|
||||
} else if self.tcx.sess.check_name(attr, sym::track_caller) {
|
||||
self.check_track_caller(&attr.span, attrs, span, target)
|
||||
} else if self.tcx.sess.check_name(attr, sym::doc) {
|
||||
self.check_doc_alias(attr, hir_id, target)
|
||||
} else if self.tcx.sess.check_name(attr, sym::no_link) {
|
||||
self.check_no_link(&attr, span, target)
|
||||
} else if self.tcx.sess.check_name(attr, sym::export_name) {
|
||||
self.check_export_name(&attr, span, target)
|
||||
} else {
|
||||
// lint-only checks
|
||||
if self.tcx.sess.check_name(attr, sym::cold) {
|
||||
self.check_cold(hir_id, attr, span, target);
|
||||
} else if self.tcx.sess.check_name(attr, sym::link_name) {
|
||||
self.check_link_name(hir_id, attr, span, target);
|
||||
} else if self.tcx.sess.check_name(attr, sym::link_section) {
|
||||
self.check_link_section(hir_id, attr, span, target);
|
||||
} else if self.tcx.sess.check_name(attr, sym::no_mangle) {
|
||||
self.check_no_mangle(hir_id, attr, span, target);
|
||||
}
|
||||
true
|
||||
};
|
||||
}
|
||||
|
@ -153,7 +167,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
.emit();
|
||||
false
|
||||
}
|
||||
Target::Fn | Target::Method(..) | Target::ForeignFn => true,
|
||||
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => true,
|
||||
_ => {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
@ -202,10 +216,31 @@ impl CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
|
||||
/// Checks if the `#[target_feature]` attribute on `item` is valid. Returns `true` if valid.
|
||||
fn check_target_feature(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
fn check_target_feature(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: &Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
// FIXME: #[target_feature] was previously erroneously allowed on statements and some
|
||||
// crates used this, so only emit a warning.
|
||||
Target::Statement => {
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
lint.build("attribute should be applied to a function")
|
||||
.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function")
|
||||
.emit();
|
||||
});
|
||||
true
|
||||
}
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
|
@ -277,6 +312,136 @@ impl CheckAttrVisitor<'tcx> {
|
|||
true
|
||||
}
|
||||
|
||||
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
|
||||
fn check_cold(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
match target {
|
||||
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {}
|
||||
_ => {
|
||||
// FIXME: #[cold] was previously allowed on non-functions and some crates used
|
||||
// this, so only emit a warning.
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
lint.build("attribute should be applied to a function")
|
||||
.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
|
||||
fn check_link_name(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
match target {
|
||||
Target::ForeignFn | Target::ForeignStatic => {}
|
||||
_ => {
|
||||
// FIXME: #[cold] was previously allowed on non-functions/statics and some crates
|
||||
// used this, so only emit a warning.
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
let mut diag =
|
||||
lint.build("attribute should be applied to a foreign function or static");
|
||||
diag.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
);
|
||||
|
||||
// See issue #47725
|
||||
if let Target::ForeignMod = target {
|
||||
if let Some(value) = attr.value_str() {
|
||||
diag.span_help(
|
||||
attr.span,
|
||||
&format!(r#"try `#[link(name = "{}")]` instead"#, value),
|
||||
);
|
||||
} else {
|
||||
diag.span_help(attr.span, r#"try `#[link(name = "...")]` instead"#);
|
||||
}
|
||||
}
|
||||
|
||||
diag.span_label(*span, "not a foreign function or static");
|
||||
diag.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[no_link]` is applied to an `extern crate`. Returns `true` if valid.
|
||||
fn check_no_link(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
if target == Target::ExternCrate {
|
||||
true
|
||||
} else {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(attr.span, "attribute should be applied to an `extern crate` item")
|
||||
.span_label(*span, "not an `extern crate` item")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[export_name]` is applied to a function or static. Returns `true` if valid.
|
||||
fn check_export_name(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
|
||||
match target {
|
||||
Target::Static | Target::Fn | Target::Method(..) => true,
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
.struct_span_err(
|
||||
attr.span,
|
||||
"attribute should be applied to a function or static",
|
||||
)
|
||||
.span_label(*span, "not a function or static")
|
||||
.emit();
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[link_section]` is applied to a function or static.
|
||||
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
match target {
|
||||
Target::Static | Target::Fn | Target::Method(..) => {}
|
||||
_ => {
|
||||
// FIXME: #[link_section] was previously allowed on non-functions/statics and some
|
||||
// crates used this, so only emit a warning.
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
lint.build("attribute should be applied to a function or static")
|
||||
.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function or static")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if `#[no_mangle]` is applied to a function or static.
|
||||
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
|
||||
match target {
|
||||
Target::Static | Target::Fn | Target::Method(..) => {}
|
||||
_ => {
|
||||
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
|
||||
// crates used this, so only emit a warning.
|
||||
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
|
||||
lint.build("attribute should be applied to a function or static")
|
||||
.warn(
|
||||
"this was previously accepted by the compiler but is \
|
||||
being phased out; it will become a hard error in \
|
||||
a future release!",
|
||||
)
|
||||
.span_label(*span, "not a function or static")
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks if the `#[repr]` attributes on `item` are valid.
|
||||
fn check_repr(
|
||||
&self,
|
||||
|
@ -321,7 +486,11 @@ impl CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
sym::simd => {
|
||||
is_simd = true;
|
||||
if target != Target::Struct { ("a", "struct") } else { continue }
|
||||
if target != Target::Struct {
|
||||
("a", "struct")
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
sym::transparent => {
|
||||
is_transparent = true;
|
||||
|
@ -358,7 +527,11 @@ impl CheckAttrVisitor<'tcx> {
|
|||
| sym::isize
|
||||
| sym::usize => {
|
||||
int_reprs += 1;
|
||||
if target != Target::Enum { ("an", "enum") } else { continue }
|
||||
if target != Target::Enum {
|
||||
("an", "enum")
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
|
@ -421,10 +594,8 @@ impl CheckAttrVisitor<'tcx> {
|
|||
fn check_stmt_attributes(&self, stmt: &hir::Stmt<'_>) {
|
||||
// When checking statements ignore expressions, they will be checked later
|
||||
if let hir::StmtKind::Local(ref l) = stmt.kind {
|
||||
self.check_attributes(l.hir_id, &l.attrs, &stmt.span, Target::Statement, None);
|
||||
for attr in l.attrs.iter() {
|
||||
if self.tcx.sess.check_name(attr, sym::inline) {
|
||||
self.check_inline(l.hir_id, attr, &stmt.span, Target::Statement);
|
||||
}
|
||||
if self.tcx.sess.check_name(attr, sym::repr) {
|
||||
self.emit_repr_error(
|
||||
attr.span,
|
||||
|
@ -442,10 +613,8 @@ impl CheckAttrVisitor<'tcx> {
|
|||
hir::ExprKind::Closure(..) => Target::Closure,
|
||||
_ => Target::Expression,
|
||||
};
|
||||
self.check_attributes(expr.hir_id, &expr.attrs, &expr.span, target, None);
|
||||
for attr in expr.attrs.iter() {
|
||||
if self.tcx.sess.check_name(attr, sym::inline) {
|
||||
self.check_inline(expr.hir_id, attr, &expr.span, target);
|
||||
}
|
||||
if self.tcx.sess.check_name(attr, sym::repr) {
|
||||
self.emit_repr_error(
|
||||
attr.span,
|
||||
|
|
|
@ -2525,10 +2525,17 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
|
|||
codegen_fn_attrs.export_name = Some(s);
|
||||
}
|
||||
} else if tcx.sess.check_name(attr, sym::target_feature) {
|
||||
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
if !tcx.features().target_feature_11 {
|
||||
check_target_feature_safe_fn(tcx, id, attr.span);
|
||||
let mut err = feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::target_feature_11,
|
||||
attr.span,
|
||||
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
|
||||
);
|
||||
err.span_label(tcx.def_span(id), "not an `unsafe` function");
|
||||
err.emit();
|
||||
} else if let Some(local_id) = id.as_local() {
|
||||
if tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
check_target_feature_trait_unsafe(tcx, local_id, attr.span);
|
||||
}
|
||||
}
|
||||
|
@ -2785,21 +2792,6 @@ fn check_link_name_xor_ordinal(
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks the function annotated with `#[target_feature]` is unsafe,
|
||||
/// reporting an error if it isn't.
|
||||
fn check_target_feature_safe_fn(tcx: TyCtxt<'_>, id: DefId, attr_span: Span) {
|
||||
if tcx.is_closure(id) || tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
|
||||
let mut err = feature_err(
|
||||
&tcx.sess.parse_sess,
|
||||
sym::target_feature_11,
|
||||
attr_span,
|
||||
"`#[target_feature(..)]` can only be applied to `unsafe` functions",
|
||||
);
|
||||
err.span_label(tcx.def_span(id), "not an `unsafe` function");
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks the function annotated with `#[target_feature]` is not a safe
|
||||
/// trait method implementation, reporting an error if it is.
|
||||
fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// run-pass
|
||||
|
||||
#![allow(dead_code)]
|
||||
// Static recursion check shouldn't fail when given a foreign item (#18279)
|
||||
|
||||
// aux-build:check_static_recursion_foreign_helper.rs
|
||||
|
@ -15,12 +14,10 @@ extern crate libc;
|
|||
|
||||
use libc::c_int;
|
||||
|
||||
#[link_name = "check_static_recursion_foreign_helper"]
|
||||
extern "C" {
|
||||
#[allow(dead_code)]
|
||||
static test_static: c_int;
|
||||
}
|
||||
|
||||
static B: &'static c_int = unsafe { &test_static };
|
||||
pub static B: &'static c_int = unsafe { &test_static };
|
||||
|
||||
pub fn main() {}
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
// This is testing whether various builtin attributes signals an
|
||||
// error or warning when put in "weird" places.
|
||||
//
|
||||
// (This file sits on its own because it actually signals an error,
|
||||
// which would mess up the treatment of other cases in
|
||||
// issue-43106-gating-of-builtin-attrs.rs)
|
||||
|
||||
// ignore-tidy-linelength
|
||||
|
||||
// Crate-level is accepted, though it is almost certainly unused?
|
||||
#![inline]
|
||||
|
||||
#[inline]
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
mod inline {
|
||||
//~^ NOTE not a function or closure
|
||||
|
||||
mod inner { #![inline] }
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
//~| NOTE not a function or closure
|
||||
|
||||
#[inline = "2100"] fn f() { }
|
||||
//~^ ERROR attribute must be of the form
|
||||
//~| WARN this was previously accepted
|
||||
//~| NOTE #[deny(ill_formed_attribute_input)]` on by default
|
||||
//~| NOTE for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
|
||||
|
||||
#[inline] struct S;
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
//~| NOTE not a function or closure
|
||||
|
||||
#[inline] type T = S;
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
//~| NOTE not a function or closure
|
||||
|
||||
#[inline] impl S { }
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
//~| NOTE not a function or closure
|
||||
}
|
||||
|
||||
#[no_link]
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
mod no_link {
|
||||
//~^ NOTE not an `extern crate` item
|
||||
|
||||
mod inner { #![no_link] }
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
//~| NOTE not an `extern crate` item
|
||||
|
||||
#[no_link] fn f() { }
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
//~| NOTE not an `extern crate` item
|
||||
|
||||
#[no_link] struct S;
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
//~| NOTE not an `extern crate` item
|
||||
|
||||
#[no_link]type T = S;
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
//~| NOTE not an `extern crate` item
|
||||
|
||||
#[no_link] impl S { }
|
||||
//~^ ERROR attribute should be applied to an `extern crate` item
|
||||
//~| NOTE not an `extern crate` item
|
||||
}
|
||||
|
||||
#[export_name = "2200"]
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
mod export_name {
|
||||
//~^ NOTE not a function or static
|
||||
|
||||
mod inner { #![export_name="2200"] }
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[export_name = "2200"] fn f() { }
|
||||
|
||||
#[export_name = "2200"] struct S;
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[export_name = "2200"] type T = S;
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[export_name = "2200"] impl S { }
|
||||
//~^ ERROR attribute should be applied to a function or static
|
||||
//~| NOTE not a function or static
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,136 @@
|
|||
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:5
|
||||
|
|
||||
LL | #[inline = "2100"] fn f() { }
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[deny(ill_formed_attribute_input)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:13:1
|
||||
|
|
||||
LL | #[inline]
|
||||
| ^^^^^^^^^
|
||||
LL |
|
||||
LL | / mod inline {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | mod inner { #![inline] }
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_- not a function or closure
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:41:1
|
||||
|
|
||||
LL | #[no_link]
|
||||
| ^^^^^^^^^^
|
||||
LL |
|
||||
LL | / mod no_link {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | mod inner { #![no_link] }
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:1
|
||||
|
|
||||
LL | #[export_name = "2200"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | / mod export_name {
|
||||
LL | |
|
||||
LL | |
|
||||
LL | | mod inner { #![export_name="2200"] }
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_- not a function or static
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:18:17
|
||||
|
|
||||
LL | mod inner { #![inline] }
|
||||
| ------------^^^^^^^^^^-- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:28:5
|
||||
|
|
||||
LL | #[inline] struct S;
|
||||
| ^^^^^^^^^ --------- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:5
|
||||
|
|
||||
LL | #[inline] type T = S;
|
||||
| ^^^^^^^^^ ----------- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:5
|
||||
|
|
||||
LL | #[inline] impl S { }
|
||||
| ^^^^^^^^^ ---------- not a function or closure
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:17
|
||||
|
|
||||
LL | mod inner { #![no_link] }
|
||||
| ------------^^^^^^^^^^^-- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:50:5
|
||||
|
|
||||
LL | #[no_link] fn f() { }
|
||||
| ^^^^^^^^^^ ---------- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
|
||||
|
|
||||
LL | #[no_link] struct S;
|
||||
| ^^^^^^^^^^ --------- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:58:5
|
||||
|
|
||||
LL | #[no_link]type T = S;
|
||||
| ^^^^^^^^^^----------- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to an `extern crate` item
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:5
|
||||
|
|
||||
LL | #[no_link] impl S { }
|
||||
| ^^^^^^^^^^ ---------- not an `extern crate` item
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:72:17
|
||||
|
|
||||
LL | mod inner { #![export_name="2200"] }
|
||||
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:78:5
|
||||
|
|
||||
LL | #[export_name = "2200"] struct S;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:82:5
|
||||
|
|
||||
LL | #[export_name = "2200"] type T = S;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
|
||||
|
|
||||
LL | #[export_name = "2200"] impl S { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0518`.
|
|
@ -31,14 +31,19 @@
|
|||
// occurrences in the source text.
|
||||
|
||||
// check-pass
|
||||
// ignore-tidy-linelength
|
||||
|
||||
#![feature(test, plugin_registrar)]
|
||||
#![warn(unused_attributes, unknown_lints)]
|
||||
//~^ NOTE the lint level is defined here
|
||||
//~| NOTE the lint level is defined here
|
||||
|
||||
// Exception, a gated and deprecated attribute.
|
||||
|
||||
#![plugin_registrar] //~ WARN unused attribute
|
||||
#![plugin_registrar]
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
|
||||
// UNGATED WHITE-LISTED BUILT-IN ATTRIBUTES
|
||||
|
||||
|
@ -72,7 +77,7 @@
|
|||
#![doc = "2400"]
|
||||
#![cold]
|
||||
#![export_name = "2200"]
|
||||
// see issue-43106-gating-of-inline.rs
|
||||
// see issue-43106-gating-of-builtin-attrs-error.rs
|
||||
#![link()]
|
||||
#![link_name = "1900"]
|
||||
#![link_section = "1800"]
|
||||
|
@ -88,12 +93,18 @@
|
|||
#![crate_name = "0900"]
|
||||
#![crate_type = "bin"] // cannot pass "0800" here
|
||||
|
||||
#![crate_id = "10"] //~ WARN use of deprecated attribute
|
||||
#![crate_id = "10"]
|
||||
//~^ WARN use of deprecated attribute
|
||||
//~| HELP remove this attribute
|
||||
|
||||
// FIXME(#44232) we should warn that this isn't used.
|
||||
#![feature(rust1)] //~ WARN no longer requires an attribute to enable
|
||||
#![feature(rust1)]
|
||||
//~^ WARN no longer requires an attribute to enable
|
||||
//~| NOTE `#[warn(stable_features)]` on by default
|
||||
|
||||
#![no_start] //~ WARN use of deprecated attribute
|
||||
#![no_start]
|
||||
//~^ WARN use of deprecated attribute
|
||||
//~| HELP remove this attribute
|
||||
|
||||
// (cannot easily gating state of crate-level #[no_main]; but non crate-level is below at "0400")
|
||||
#![no_builtins]
|
||||
|
@ -217,24 +228,30 @@ mod macro_export {
|
|||
#[plugin_registrar]
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
mod plugin_registrar {
|
||||
mod inner { #![plugin_registrar] }
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
//~| NOTE `#[warn(deprecated)]` on by default
|
||||
|
||||
// for `fn f()` case, see gated-plugin_registrar.rs
|
||||
|
||||
#[plugin_registrar] struct S;
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
|
||||
#[plugin_registrar] type T = S;
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
|
||||
#[plugin_registrar] impl S { }
|
||||
//~^ WARN unused attribute
|
||||
//~| WARN use of deprecated attribute
|
||||
//~| HELP may be removed in a future compiler version
|
||||
}
|
||||
|
||||
#[main]
|
||||
|
@ -355,35 +372,31 @@ mod automatically_derived {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
mod no_mangle {
|
||||
//~^ NOTE not a function or static
|
||||
mod inner { #![no_mangle] }
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[no_mangle] fn f() { }
|
||||
|
||||
#[no_mangle] struct S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[no_mangle] type T = S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[no_mangle] impl S { }
|
||||
}
|
||||
|
||||
#[no_link]
|
||||
//~^ WARN unused attribute
|
||||
mod no_link {
|
||||
mod inner { #![no_link] }
|
||||
//~^ WARN unused attribute
|
||||
|
||||
#[no_link] fn f() { }
|
||||
//~^ WARN unused attribute
|
||||
|
||||
#[no_link] struct S;
|
||||
//~^ WARN unused attribute
|
||||
|
||||
#[no_link]type T = S;
|
||||
//~^ WARN unused attribute
|
||||
|
||||
#[no_link] impl S { }
|
||||
//~^ WARN unused attribute
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
}
|
||||
|
||||
#[should_panic]
|
||||
|
@ -468,6 +481,7 @@ mod reexport_test_harness_main {
|
|||
mod macro_escape {
|
||||
mod inner { #![macro_escape] }
|
||||
//~^ WARN `#[macro_escape]` is a deprecated synonym for `#[macro_use]`
|
||||
//~| HELP try an outer attribute: `#[macro_use]`
|
||||
|
||||
#[macro_escape] fn f() { }
|
||||
//~^ WARN unused attribute
|
||||
|
@ -525,31 +539,103 @@ mod doc {
|
|||
}
|
||||
|
||||
#[cold]
|
||||
//~^ WARN attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
mod cold {
|
||||
//~^ NOTE not a function
|
||||
|
||||
mod inner { #![cold] }
|
||||
//~^ WARN attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function
|
||||
|
||||
#[cold] fn f() { }
|
||||
|
||||
#[cold] struct S;
|
||||
//~^ WARN attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function
|
||||
|
||||
#[cold] type T = S;
|
||||
//~^ WARN attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function
|
||||
|
||||
#[cold] impl S { }
|
||||
//~^ WARN attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function
|
||||
}
|
||||
|
||||
#[export_name = "2200"]
|
||||
mod export_name {
|
||||
mod inner { #![export_name="2200"] }
|
||||
#[link_name = "1900"]
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
mod link_name {
|
||||
//~^ NOTE not a foreign function or static
|
||||
|
||||
#[export_name = "2200"] fn f() { }
|
||||
#[link_name = "1900"]
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| HELP try `#[link(name = "1900")]` instead
|
||||
extern { }
|
||||
//~^ NOTE not a foreign function or static
|
||||
|
||||
#[export_name = "2200"] struct S;
|
||||
mod inner { #![link_name="1900"] }
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a foreign function or static
|
||||
|
||||
#[export_name = "2200"] type T = S;
|
||||
#[link_name = "1900"] fn f() { }
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a foreign function or static
|
||||
|
||||
#[export_name = "2200"] impl S { }
|
||||
#[link_name = "1900"] struct S;
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a foreign function or static
|
||||
|
||||
#[link_name = "1900"] type T = S;
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a foreign function or static
|
||||
|
||||
#[link_name = "1900"] impl S { }
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a foreign function or static
|
||||
}
|
||||
|
||||
#[link_section = "1800"]
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
mod link_section {
|
||||
//~^ NOTE not a function or static
|
||||
|
||||
mod inner { #![link_section="1800"] }
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[link_section = "1800"] fn f() { }
|
||||
|
||||
#[link_section = "1800"] struct S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[link_section = "1800"] type T = S;
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
|
||||
#[link_section = "1800"] impl S { }
|
||||
//~^ WARN attribute should be applied to a function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| NOTE not a function or static
|
||||
}
|
||||
|
||||
|
||||
// Note that this is a `check-pass` test, so it
|
||||
// will never invoke the linker. These are here nonetheless to point
|
||||
// out that we allow them at non-crate-level (though I do not know
|
||||
|
@ -568,32 +654,6 @@ mod link {
|
|||
#[link()] impl S { }
|
||||
}
|
||||
|
||||
#[link_name = "1900"]
|
||||
mod link_name {
|
||||
mod inner { #![link_name="1900"] }
|
||||
|
||||
#[link_name = "1900"] fn f() { }
|
||||
|
||||
#[link_name = "1900"] struct S;
|
||||
|
||||
#[link_name = "1900"] type T = S;
|
||||
|
||||
#[link_name = "1900"] impl S { }
|
||||
}
|
||||
|
||||
#[link_section = "1800"]
|
||||
mod link_section {
|
||||
mod inner { #![link_section="1800"] }
|
||||
|
||||
#[link_section = "1800"] fn f() { }
|
||||
|
||||
#[link_section = "1800"] struct S;
|
||||
|
||||
#[link_section = "1800"] type T = S;
|
||||
|
||||
#[link_section = "1800"] impl S { }
|
||||
}
|
||||
|
||||
struct StructForDeprecated;
|
||||
|
||||
#[deprecated]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,31 +0,0 @@
|
|||
// This is testing whether `#[inline]` signals an error or warning
|
||||
// when put in "weird" places.
|
||||
//
|
||||
// (This file sits on its own because it actually signals an error,
|
||||
// which would mess up the treatment of other cases in
|
||||
// issue-43106-gating-of-builtin-attrs.rs)
|
||||
|
||||
// Crate-level is accepted, though it is almost certainly unused?
|
||||
#![inline]
|
||||
|
||||
#[inline]
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
mod inline {
|
||||
mod inner { #![inline] }
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
|
||||
#[inline = "2100"] fn f() { }
|
||||
//~^ ERROR attribute must be of the form
|
||||
//~| WARN this was previously accepted
|
||||
|
||||
#[inline] struct S;
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
|
||||
#[inline] type T = S;
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
|
||||
#[inline] impl S { }
|
||||
//~^ ERROR attribute should be applied to function or closure
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,52 +0,0 @@
|
|||
error: attribute must be of the form `#[inline]` or `#[inline(always|never)]`
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:17:5
|
||||
|
|
||||
LL | #[inline = "2100"] fn f() { }
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[deny(ill_formed_attribute_input)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:11:1
|
||||
|
|
||||
LL | #[inline]
|
||||
| ^^^^^^^^^
|
||||
LL |
|
||||
LL | / mod inline {
|
||||
LL | | mod inner { #![inline] }
|
||||
LL | |
|
||||
LL | |
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:14:17
|
||||
|
|
||||
LL | mod inner { #![inline] }
|
||||
| ------------^^^^^^^^^^-- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:21:5
|
||||
|
|
||||
LL | #[inline] struct S;
|
||||
| ^^^^^^^^^ --------- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:24:5
|
||||
|
|
||||
LL | #[inline] type T = S;
|
||||
| ^^^^^^^^^ ----------- not a function or closure
|
||||
|
||||
error[E0518]: attribute should be applied to function or closure
|
||||
--> $DIR/issue-43106-gating-of-inline.rs:27:5
|
||||
|
|
||||
LL | #[inline] impl S { }
|
||||
| ^^^^^^^^^ ---------- not a function or closure
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0518`.
|
|
@ -23,7 +23,6 @@ fn lgamma(n: c_double, value: &mut isize) -> c_double {
|
|||
mod m {
|
||||
use libc::{c_double, c_int};
|
||||
|
||||
#[link_name = "m"]
|
||||
extern {
|
||||
#[cfg(any(all(unix, not(target_os = "vxworks")), target_os = "cloudabi"))]
|
||||
#[link_name="lgamma_r"]
|
||||
|
|
29
src/test/ui/issues/issue-47725.rs
Normal file
29
src/test/ui/issues/issue-47725.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
// ignore-tidy-linelength
|
||||
#![warn(unused_attributes)] //~ NOTE lint level is defined here
|
||||
|
||||
#[link_name = "foo"]
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
struct Foo; //~ NOTE not a foreign function or static
|
||||
|
||||
#[link_name = "foobar"]
|
||||
//~^ WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| HELP try `#[link(name = "foobar")]` instead
|
||||
extern "C" {
|
||||
fn foo() -> u32;
|
||||
}
|
||||
//~^^^ NOTE not a foreign function or static
|
||||
|
||||
#[link_name]
|
||||
//~^ ERROR malformed `link_name` attribute input
|
||||
//~| HELP must be of the form
|
||||
//~| WARN attribute should be applied to a foreign function or static [unused_attributes]
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
//~| HELP try `#[link(name = "...")]` instead
|
||||
extern "C" {
|
||||
fn bar() -> u32;
|
||||
}
|
||||
//~^^^ NOTE not a foreign function or static
|
||||
|
||||
fn main() {}
|
60
src/test/ui/issues/issue-47725.stderr
Normal file
60
src/test/ui/issues/issue-47725.stderr
Normal file
|
@ -0,0 +1,60 @@
|
|||
error: malformed `link_name` attribute input
|
||||
--> $DIR/issue-47725.rs:18:1
|
||||
|
|
||||
LL | #[link_name]
|
||||
| ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]`
|
||||
|
||||
warning: attribute should be applied to a foreign function or static
|
||||
--> $DIR/issue-47725.rs:4:1
|
||||
|
|
||||
LL | #[link_name = "foo"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | struct Foo;
|
||||
| ----------- not a foreign function or static
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-47725.rs:2:9
|
||||
|
|
||||
LL | #![warn(unused_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
warning: attribute should be applied to a foreign function or static
|
||||
--> $DIR/issue-47725.rs:9:1
|
||||
|
|
||||
LL | #[link_name = "foobar"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | / extern "C" {
|
||||
LL | | fn foo() -> u32;
|
||||
LL | | }
|
||||
| |_- not a foreign function or static
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
help: try `#[link(name = "foobar")]` instead
|
||||
--> $DIR/issue-47725.rs:9:1
|
||||
|
|
||||
LL | #[link_name = "foobar"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: attribute should be applied to a foreign function or static
|
||||
--> $DIR/issue-47725.rs:18:1
|
||||
|
|
||||
LL | #[link_name]
|
||||
| ^^^^^^^^^^^^
|
||||
...
|
||||
LL | / extern "C" {
|
||||
LL | | fn bar() -> u32;
|
||||
LL | | }
|
||||
| |_- not a foreign function or static
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
help: try `#[link(name = "...")]` instead
|
||||
--> $DIR/issue-47725.rs:18:1
|
||||
|
|
||||
LL | #[link_name]
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error; 3 warnings emitted
|
||||
|
14
src/test/ui/issues/issue-54044.rs
Normal file
14
src/test/ui/issues/issue-54044.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// ignore-tidy-linelength
|
||||
#![deny(unused_attributes)] //~ NOTE lint level is defined here
|
||||
|
||||
#[cold]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
struct Foo; //~ NOTE not a function
|
||||
|
||||
fn main() {
|
||||
#[cold]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
5; //~ NOTE not a function
|
||||
}
|
29
src/test/ui/issues/issue-54044.stderr
Normal file
29
src/test/ui/issues/issue-54044.stderr
Normal file
|
@ -0,0 +1,29 @@
|
|||
error: attribute should be applied to a function
|
||||
--> $DIR/issue-54044.rs:4:1
|
||||
|
|
||||
LL | #[cold]
|
||||
| ^^^^^^^
|
||||
...
|
||||
LL | struct Foo;
|
||||
| ----------- not a function
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-54044.rs:2:9
|
||||
|
|
||||
LL | #![deny(unused_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/issue-54044.rs:10:5
|
||||
|
|
||||
LL | #[cold]
|
||||
| ^^^^^^^
|
||||
...
|
||||
LL | 5;
|
||||
| - not a function
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
|
@ -2,11 +2,13 @@ fn main() {
|
|||
(0..)
|
||||
.map(
|
||||
#[target_feature(enable = "")]
|
||||
//~^ ERROR: the feature named `` is not valid for this target
|
||||
//~| ERROR: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
//~^ ERROR: attribute should be applied to a function
|
||||
//~| ERROR: the feature named `` is not valid for this target
|
||||
//~| NOTE: `` is not valid for this target
|
||||
#[track_caller]
|
||||
//~^ ERROR: `#[track_caller]` requires Rust ABI
|
||||
//~^ ERROR: `#[track_caller]` requires Rust ABI [E0737]
|
||||
|_| (),
|
||||
//~^ NOTE: not a function
|
||||
)
|
||||
.next();
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/issue-68060.rs:4:13
|
||||
|
|
||||
LL | #[target_feature(enable = "")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | |_| (),
|
||||
| ------ not an `unsafe` function
|
||||
|
|
||||
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
|
||||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
|
||||
| ------ not a function
|
||||
|
||||
error: the feature named `` is not valid for this target
|
||||
--> $DIR/issue-68060.rs:4:30
|
||||
|
@ -17,12 +14,11 @@ LL | #[target_feature(enable = "")]
|
|||
| ^^^^^^^^^^^ `` is not valid for this target
|
||||
|
||||
error[E0737]: `#[track_caller]` requires Rust ABI
|
||||
--> $DIR/issue-68060.rs:7:13
|
||||
--> $DIR/issue-68060.rs:8:13
|
||||
|
|
||||
LL | #[track_caller]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0737.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0737`.
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
// ignore-sparc64
|
||||
|
||||
#![feature(target_feature)]
|
||||
#![warn(unused_attributes)]
|
||||
|
||||
#[target_feature = "+sse2"]
|
||||
//~^ ERROR malformed `target_feature` attribute
|
||||
|
@ -53,8 +54,11 @@ enum Bar { }
|
|||
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
union Qux { f1: u16, f2: u16 }
|
||||
union Qux {
|
||||
//~^ NOTE not a function
|
||||
f1: u16,
|
||||
f2: u16,
|
||||
}
|
||||
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
|
@ -79,13 +83,16 @@ impl Quux for Foo {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
unsafe {
|
||||
foo();
|
||||
bar();
|
||||
}
|
||||
//~^^^^ NOTE not a function
|
||||
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
//~| NOTE see issue #69098
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
|| {};
|
||||
//~^ NOTE not an `unsafe` function
|
||||
//~^ NOTE not a function
|
||||
}
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
error: malformed `target_feature` attribute input
|
||||
--> $DIR/invalid-attribute.rs:17:1
|
||||
--> $DIR/invalid-attribute.rs:18:1
|
||||
|
|
||||
LL | #[target_feature = "+sse2"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]`
|
||||
|
||||
error: the feature named `foo` is not valid for this target
|
||||
--> $DIR/invalid-attribute.rs:19:18
|
||||
--> $DIR/invalid-attribute.rs:20:18
|
||||
|
|
||||
LL | #[target_feature(enable = "foo")]
|
||||
| ^^^^^^^^^^^^^^ `foo` is not valid for this target
|
||||
|
||||
error: malformed `target_feature` attribute input
|
||||
--> $DIR/invalid-attribute.rs:22:18
|
||||
--> $DIR/invalid-attribute.rs:23:18
|
||||
|
|
||||
LL | #[target_feature(bar)]
|
||||
| ^^^ help: must be of the form: `enable = ".."`
|
||||
|
||||
error: malformed `target_feature` attribute input
|
||||
--> $DIR/invalid-attribute.rs:24:18
|
||||
--> $DIR/invalid-attribute.rs:25:18
|
||||
|
|
||||
LL | #[target_feature(disable = "baz")]
|
||||
| ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
|
||||
|
||||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
--> $DIR/invalid-attribute.rs:28:1
|
||||
--> $DIR/invalid-attribute.rs:29:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -35,7 +35,7 @@ LL | fn bar() {}
|
|||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:34:1
|
||||
--> $DIR/invalid-attribute.rs:35:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -44,7 +44,7 @@ LL | mod another {}
|
|||
| -------------- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:39:1
|
||||
--> $DIR/invalid-attribute.rs:40:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -53,7 +53,7 @@ LL | const FOO: usize = 7;
|
|||
| --------------------- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:44:1
|
||||
--> $DIR/invalid-attribute.rs:45:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -62,52 +62,65 @@ LL | struct Foo;
|
|||
| ----------- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:49:1
|
||||
--> $DIR/invalid-attribute.rs:50:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | enum Bar {}
|
||||
| ------------ not a function
|
||||
| ----------- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:54:1
|
||||
--> $DIR/invalid-attribute.rs:55:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | union Qux { f1: u16, f2: u16 }
|
||||
| ------------------------------ not a function
|
||||
LL | / union Qux {
|
||||
LL | |
|
||||
LL | | f1: u16,
|
||||
LL | | f2: u16,
|
||||
LL | | }
|
||||
| |_- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:59:1
|
||||
--> $DIR/invalid-attribute.rs:63:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | trait Baz {}
|
||||
| ------------- not a function
|
||||
| ------------ not a function
|
||||
|
||||
error: cannot use `#[inline(always)]` with `#[target_feature]`
|
||||
--> $DIR/invalid-attribute.rs:64:1
|
||||
--> $DIR/invalid-attribute.rs:68:1
|
||||
|
|
||||
LL | #[inline(always)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:86:5
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | || {};
|
||||
| ----- not an `unsafe` function
|
||||
LL |
|
||||
LL | / unsafe {
|
||||
LL | | foo();
|
||||
LL | | bar();
|
||||
LL | | }
|
||||
| |_____- not a function
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/invalid-attribute.rs:94:5
|
||||
|
|
||||
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
|
||||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | || {};
|
||||
| ----- not a function
|
||||
|
||||
error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
|
||||
--> $DIR/invalid-attribute.rs:74:5
|
||||
--> $DIR/invalid-attribute.rs:78:5
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -118,6 +131,6 @@ LL | fn foo() {}
|
|||
= note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
|
||||
= help: add `#![feature(target_feature_11)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue