Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,20 @@ impl NoArgsAttributeParser for NoMangleParser {
note: "the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them",
unsafe_since: Some(Edition2024),
};
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowListWarnRest(&[
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::Fn),
Allow(Target::Static),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
AllowSilent(Target::Const), // Handled in the `InvalidNoMangleItems` pass
Error(Target::Closure),
Error(Target::Param),
// Removing these warnings has shown to cause breakage in crater run on https://github.com/rust-lang/rust/pull/164789
Warn(Target::ForeignStatic),
Warn(Target::ForeignFn),
Warn(Target::ForeignMod),
Warn(Target::Struct),
Warn(Target::Enum),
Warn(Target::Use),
Warn(Target::TyAlias),
]);
const STABILITY: AttributeStability = AttributeStability::Stable;
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/attributes/attr-on-mac-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ fn main() {
//~| WARN previously accepted
unreachable!();
#[no_mangle]
//~^ WARN attribute cannot be used on macro calls
//~| WARN previously accepted
//~^ ERROR attribute cannot be used on macro calls
unreachable!();
#[deprecated]
//~^ WARN attribute cannot be used on macro calls
Expand Down
75 changes: 37 additions & 38 deletions tests/ui/attributes/attr-on-mac-call.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
error: the `no_mangle` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:60:7
|
LL | #[no_mangle]
| ^^^^^^^^^
LL |
LL | unreachable!();
|
= help: the `no_mangle` attribute can be applied to functions and statics
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error: the `sanitize` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:100:7
--> $DIR/attr-on-mac-call.rs:99:7
|
LL | #[sanitize(address = "off")]
| ^^^^^^^^
Expand All @@ -10,7 +21,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error[E0658]: SIMD types are experimental and possibly buggy
--> $DIR/attr-on-mac-call.rs:129:12
--> $DIR/attr-on-mac-call.rs:128:12
|
LL | #[repr(simd)]
| ^^^^
Expand All @@ -20,7 +31,7 @@ LL | #[repr(simd)]
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: the `repr(simd)` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:129:7
--> $DIR/attr-on-mac-call.rs:128:7
|
LL | #[repr(simd)]
| ^^^^^^^^^^
Expand All @@ -31,31 +42,31 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![register_tool]`
--> $DIR/attr-on-mac-call.rs:133:5
--> $DIR/attr-on-mac-call.rs:132:5
|
LL | #[register_tool(xyz)]
| ^^^^^^^^^^^^^^^^^^^^^
|
note: this attribute does not have an `!`, which means it is applied to this macro call
--> $DIR/attr-on-mac-call.rs:135:5
--> $DIR/attr-on-mac-call.rs:134:5
|
LL | unreachable!();
| ^^^^^^^^^^^^^^

error: attribute value must be a literal
--> $DIR/attr-on-mac-call.rs:136:20
--> $DIR/attr-on-mac-call.rs:135:20
|
LL | #[deprecated = concat!("woah", "dude")]
| ^^^^^^^^^^^^^^^^^^^^^^^

error: attribute value must be a literal
--> $DIR/attr-on-mac-call.rs:138:13
--> $DIR/attr-on-mac-call.rs:137:13
|
LL | #[doc = concat!("woah", "dude")]
| ^^^^^^^^^^^^^^^^^^^^^^^

error: attribute value must be a literal
--> $DIR/attr-on-mac-call.rs:141:13
--> $DIR/attr-on-mac-call.rs:140:13
|
LL | #[doc = {
| _____________^
Expand All @@ -67,7 +78,7 @@ LL | | }]
| |_____^

error: attribute value must be a literal
--> $DIR/attr-on-mac-call.rs:149:13
--> $DIR/attr-on-mac-call.rs:148:13
|
LL | #[doc = {
| _____________^
Expand Down Expand Up @@ -236,20 +247,8 @@ LL | unreachable!();
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `no_mangle` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:60:7
|
LL | #[no_mangle]
| ^^^^^^^^^
...
LL | unreachable!();
|
= help: the `no_mangle` attribute can be applied to functions and statics
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `deprecated` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:64:7
--> $DIR/attr-on-mac-call.rs:63:7
|
LL | #[deprecated]
| ^^^^^^^^^^
Expand All @@ -261,7 +260,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `automatically_derived` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:68:7
--> $DIR/attr-on-mac-call.rs:67:7
|
LL | #[automatically_derived]
| ^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -273,7 +272,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `macro_use` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:72:7
--> $DIR/attr-on-mac-call.rs:71:7
|
LL | #[macro_use]
| ^^^^^^^^^
Expand All @@ -285,7 +284,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `must_use` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:76:7
--> $DIR/attr-on-mac-call.rs:75:7
|
LL | #[must_use]
| ^^^^^^^^
Expand All @@ -297,7 +296,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `no_implicit_prelude` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:80:7
--> $DIR/attr-on-mac-call.rs:79:7
|
LL | #[no_implicit_prelude]
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -309,7 +308,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `path` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:84:7
--> $DIR/attr-on-mac-call.rs:83:7
|
LL | #[path = ""]
| ^^^^
Expand All @@ -321,7 +320,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `ignore` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:88:7
--> $DIR/attr-on-mac-call.rs:87:7
|
LL | #[ignore]
| ^^^^^^
Expand All @@ -333,7 +332,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `should_panic` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:92:7
--> $DIR/attr-on-mac-call.rs:91:7
|
LL | #[should_panic]
| ^^^^^^^^^^^^
Expand All @@ -345,7 +344,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `link_name` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:96:7
--> $DIR/attr-on-mac-call.rs:95:7
|
LL | #[link_name = "x"]
| ^^^^^^^^^
Expand All @@ -357,7 +356,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `repr()` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:104:7
--> $DIR/attr-on-mac-call.rs:103:7
|
LL | #[repr()]
| ^^^^^^
Expand All @@ -369,15 +368,15 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: unused attribute
--> $DIR/attr-on-mac-call.rs:104:5
--> $DIR/attr-on-mac-call.rs:103:5
|
LL | #[repr()]
| ^^^^^^^^^ help: remove this attribute
|
= note: using `repr` with an empty list has no effect

warning: the `repr(u8)` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:109:7
--> $DIR/attr-on-mac-call.rs:108:7
|
LL | #[repr(u8)]
| ^^^^^^^^
Expand All @@ -389,7 +388,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `repr(align(...))` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:113:7
--> $DIR/attr-on-mac-call.rs:112:7
|
LL | #[repr(align(8))]
| ^^^^^^^^^^^^^^
Expand All @@ -401,7 +400,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `repr(packed)` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:117:7
--> $DIR/attr-on-mac-call.rs:116:7
|
LL | #[repr(packed)]
| ^^^^^^^^^^^^
Expand All @@ -413,7 +412,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `repr(C)` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:121:7
--> $DIR/attr-on-mac-call.rs:120:7
|
LL | #[repr(C)]
| ^^^^^^^
Expand All @@ -425,7 +424,7 @@ LL | unreachable!();
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `repr(Rust)` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:125:7
--> $DIR/attr-on-mac-call.rs:124:7
|
LL | #[repr(Rust)]
| ^^^^^^^^^^
Expand All @@ -436,6 +435,6 @@ LL | unreachable!();
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error: aborting due to 8 previous errors; 30 warnings emitted
error: aborting due to 9 previous errors; 29 warnings emitted

For more information about this error, try `rustc --explain E0658`.
5 changes: 2 additions & 3 deletions tests/ui/extern/extern-no-mangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// The previous warning only talks about a "function or static" but foreign fns/statics
// are also not allowed to have #[no_mangle]

//@ build-pass
//@ check-fail

extern "C" {
#[no_mangle]
Expand All @@ -22,8 +22,7 @@ extern "C" {
fn no_new_warn() {
// Should emit the generic "not a function or static" warning
#[no_mangle]
//~^ WARNING attribute cannot be used on
//~| WARN previously accepted
//~^ ERROR attribute cannot be used on
let x = 0_u8;
}

Expand Down
17 changes: 8 additions & 9 deletions tests/ui/extern/extern-no-mangle.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
warning: the `no_mangle` attribute cannot be used on statements
error: the `no_mangle` attribute cannot be used on statements
--> $DIR/extern-no-mangle.rs:24:7
|
LL | #[no_mangle]
| ^^^^^^^^^
...
LL |
LL | let x = 0_u8;
|
= help: the `no_mangle` attribute can be applied to functions and statics
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/extern-no-mangle.rs:1:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^

warning: the `no_mangle` attribute cannot be used on foreign statics
--> $DIR/extern-no-mangle.rs:11:7
Expand All @@ -24,6 +18,11 @@ LL | pub static FOO: u8;
|
= help: the `no_mangle` attribute can be applied to functions and statics
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
note: the lint level is defined here
--> $DIR/extern-no-mangle.rs:1:9
|
LL | #![warn(unused_attributes)]
| ^^^^^^^^^^^^^^^^^

warning: the `no_mangle` attribute cannot be used on foreign functions
--> $DIR/extern-no-mangle.rs:16:7
Expand All @@ -36,5 +35,5 @@ LL | pub fn bar();
= help: the `no_mangle` attribute can be applied to functions with a body and statics
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

warning: 3 warnings emitted
error: aborting due to 1 previous error; 2 warnings emitted

Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
//~^ WARN may not be used in combination with `#[export_name]`
//~| NOTE is ignored
//~| NOTE requested on the command line
//~| WARN cannot be used on crates
//~| WARN previously accepted
//~| ERROR cannot be used on crates
#![no_link]
//~^ ERROR: the `no_link` attribute cannot be used on crates
//~| ERROR use of deprecated `no_link` attribute
Expand Down Expand Up @@ -186,4 +185,23 @@ mod repr_rust {
//~^ ERROR: attribute cannot be used on
}

#[no_mangle]
//~^ ERROR attribute cannot be used on
mod no_mangle {
mod inner { #![no_mangle] }
//~^ ERROR attribute cannot be used on

struct S;
#[no_mangle] impl S { }
//~^ ERROR attribute cannot be used on

trait Tr {
#[no_mangle] fn foo();
//~^ ERROR attribute cannot be used on

#[no_mangle] fn bar() {}
//~^ ERROR attribute cannot be used on
}
}

fn main() {}
Loading
Loading