Rollup merge of #150072 - Bryntet:parse_no_link, r=JonathanBrouwer

Port #[no_link] to use attribute parser

Adds `#[no_link]` to the attribute parser, as well as adds tests making sure to FCW warn on `field`, `arm`, and `macrodef `
This commit is contained in:
Jacob Pratt
2025-12-16 23:10:12 -05:00
committed by GitHub
12 changed files with 189 additions and 174 deletions
+9 -8
View File
@@ -147,14 +147,6 @@ error: malformed `thread_local` attribute input
LL | #[thread_local()]
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[thread_local]`
error: malformed `no_link` attribute input
--> $DIR/malformed-attrs.rs:214:1
|
LL | #[no_link()]
| ^^^^^^^^^^^^ help: must be of the form: `#[no_link]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute>
error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
--> $DIR/malformed-attrs.rs:105:1
|
@@ -626,6 +618,15 @@ LL | #[non_exhaustive = 1]
| | didn't expect any arguments here
| help: must be of the form: `#[non_exhaustive]`
error[E0565]: malformed `no_link` attribute input
--> $DIR/malformed-attrs.rs:214:1
|
LL | #[no_link()]
| ^^^^^^^^^--^
| | |
| | didn't expect any arguments here
| help: must be of the form: `#[no_link]`
error[E0539]: malformed `macro_use` attribute input
--> $DIR/malformed-attrs.rs:216:1
|
@@ -1,4 +1,3 @@
//~ NOTE: not an `extern crate` item
// This is testing whether various builtin attributes signals an
// error or warning when put in "weird" places.
//
@@ -29,7 +28,7 @@
//~| WARN cannot be used on crates
//~| WARN previously accepted
#![no_link]
//~^ ERROR: attribute should be applied to an `extern crate` item
//~^ ERROR: `#[no_link]` attribute cannot be used on crates
#![export_name = "2200"]
//~^ ERROR: attribute cannot be used on
//~| NOTE takes precedence
@@ -60,29 +59,40 @@ mod inner { #![inline] }
}
#[no_link]
//~^ ERROR attribute should be applied to an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on modules
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
//~^ ERROR `#[no_link]` attribute cannot be used on modules
#[no_link] fn f() { }
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
#[no_link] fn f() {
//~^ ERROR `#[no_link]` attribute cannot be used on functions
match () {
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on match arms [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!
_ => ()
}
}
#[no_link] struct S;
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
#[no_link]
//~^ ERROR `#[no_link]` attribute cannot be used on structs
struct S {
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on struct fields [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!
field: ()
}
#[no_link]type T = S;
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on type aliases
#[no_link] impl S { }
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on inherent impl blocks
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on macro defs
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
macro_rules! m{() => {}}
}
#[export_name = "2200"]
@@ -1,5 +1,5 @@
error[E0658]: use of an internal attribute
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:11:1
|
LL | #![rustc_main]
| ^^^^^^^^^^^^^^
@@ -9,7 +9,7 @@ LL | #![rustc_main]
= note: the `#[rustc_main]` attribute is used internally to specify test entry point function
error: `#[macro_export]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:10:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:9:1
|
LL | #![macro_export]
| ^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | #![macro_export]
= help: `#[macro_export]` can only be applied to macro defs
error: `#[rustc_main]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:11:1
|
LL | #![rustc_main]
| ^^^^^^^^^^^^^^
@@ -25,7 +25,7 @@ LL | #![rustc_main]
= help: `#[rustc_main]` can only be applied to functions
error: `#[path]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:21:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1
|
LL | #![path = "3800"]
| ^^^^^^^^^^^^^^^^^
@@ -33,15 +33,23 @@ LL | #![path = "3800"]
= help: `#[path]` can only be applied to modules
error: `#[automatically_derived]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:23:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:1
|
LL | #![automatically_derived]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[automatically_derived]` can only be applied to trait impl blocks
error: `#[no_link]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:30:1
|
LL | #![no_link]
| ^^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[export_name]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:33:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1
|
LL | #![export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -49,7 +57,7 @@ LL | #![export_name = "2200"]
= help: `#[export_name]` can be applied to functions and statics
error: `#[inline]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:35:1
|
LL | #![inline]
| ^^^^^^^^^^
@@ -57,7 +65,7 @@ LL | #![inline]
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:38:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:37:1
|
LL | #[inline]
| ^^^^^^^^^
@@ -65,7 +73,7 @@ LL | #[inline]
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:42:17
|
LL | mod inner { #![inline] }
| ^^^^^^^^^^
@@ -73,7 +81,7 @@ LL | mod inner { #![inline] }
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:52:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:51:5
|
LL | #[inline] struct S;
| ^^^^^^^^^
@@ -81,7 +89,7 @@ LL | #[inline] struct S;
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:55:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
|
LL | #[inline] type T = S;
| ^^^^^^^^^
@@ -89,15 +97,63 @@ LL | #[inline] type T = S;
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:58:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:57:5
|
LL | #[inline] impl S { }
| ^^^^^^^^^
|
= help: `#[inline]` can only be applied to functions
error: `#[no_link]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:61:1
|
LL | #[no_link]
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:17
|
LL | mod inner { #![no_link] }
| ^^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on functions
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:5
|
LL | #[no_link] fn f() {
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:77:5
|
LL | #[no_link]
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
|
LL | #[no_link]type T = S;
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:89:5
|
LL | #[no_link] impl S { }
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[export_name]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:88:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:98:1
|
LL | #[export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -105,7 +161,7 @@ LL | #[export_name = "2200"]
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:91:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:101:17
|
LL | mod inner { #![export_name="2200"] }
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -113,7 +169,7 @@ LL | mod inner { #![export_name="2200"] }
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:5
|
LL | #[export_name = "2200"] struct S;
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -121,7 +177,7 @@ LL | #[export_name = "2200"] struct S;
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:99:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:5
|
LL | #[export_name = "2200"] type T = S;
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,7 +185,7 @@ LL | #[export_name = "2200"] type T = S;
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:102:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:5
|
LL | #[export_name = "2200"] impl S { }
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -137,29 +193,15 @@ LL | #[export_name = "2200"] impl S { }
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on required trait methods
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:9
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:116:9
|
LL | #[export_name = "2200"] fn foo();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:1
|
LL | #[no_link]
| ^^^^^^^^^^
LL |
LL | / mod no_link {
LL | |
LL | |
LL | | mod inner { #![no_link] }
... |
LL | | }
| |_- not an `extern crate` item
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113:8
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:8
|
LL | #[repr(C)]
| ^
@@ -172,7 +214,7 @@ LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:8
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147:8
|
LL | #[repr(Rust)]
| ^^^^
@@ -184,20 +226,14 @@ LL | | mod inner { #![repr(Rust)] }
LL | | }
| |_- not a struct, enum, or union
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:31:1
|
LL | #![no_link]
| ^^^^^^^^^^^ not an `extern crate` item
warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1
|
LL | #![no_mangle]
| ^^^^^^^^^^^^^ `#[no_mangle]` is ignored
|
note: `#[export_name]` takes precedence
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:33:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1
|
LL | #![export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^^
@@ -208,7 +244,7 @@ LL - #![no_mangle]
|
error: `repr` attribute cannot be used at crate level
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:17:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
|
LL | #![repr()]
| ^^^^^^^^^^
@@ -222,86 +258,56 @@ LL - #![repr()]
LL + #[repr()]
|
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67: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:71: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:75: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:79: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:83:5
|
LL | #[no_link] impl S { }
| ^^^^^^^^^^ ---------- not an `extern crate` item
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:25
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:25
|
LL | mod inner { #![repr(C)] }
| --------------------^---- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12
|
LL | #[repr(C)] fn f() { }
| ^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:12
|
LL | #[repr(C)] type T = S;
| ^ ----------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:12
|
LL | #[repr(C)] impl S { }
| ^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:25
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:25
|
LL | mod inner { #![repr(Rust)] }
| --------------------^^^^---- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:145:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12
|
LL | #[repr(Rust)] fn f() { }
| ^^^^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:161:12
|
LL | #[repr(Rust)] type T = S;
| ^^^^ ----------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:165:12
|
LL | #[repr(Rust)] impl S { }
| ^^^^ ---------- not a struct, enum, or union
error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5
|
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^
@@ -310,8 +316,35 @@ LL | #[inline = "2100"] fn f() { }
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
warning: `#[no_link]` attribute cannot be used on match arms
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:70:13
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: `#[no_link]` attribute cannot be used on struct fields
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:9
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: `#[no_link]` attribute cannot be used on macro defs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:92:5
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: unused attribute
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:17:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
|
LL | #![repr()]
| ^^^^^^^^^^ help: remove this attribute
@@ -319,7 +352,7 @@ LL | #![repr()]
= note: using `repr` with an empty list has no effect
warning: `#[no_mangle]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1
|
LL | #![no_mangle]
| ^^^^^^^^^^^^^
@@ -327,13 +360,13 @@ LL | #![no_mangle]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_mangle]` can be applied to functions and statics
error: aborting due to 37 previous errors; 3 warnings emitted
error: aborting due to 37 previous errors; 6 warnings emitted
Some errors have detailed explanations: E0517, E0658.
For more information about an error, try `rustc --explain E0517`.
Future incompatibility report: Future breakage diagnostic:
error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5
|
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^
@@ -16,18 +16,6 @@ note: the lint level is defined here
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:37:1
|
LL | #[no_link]
| ^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:36:1
|
LL | #[no_link]
| ^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:34:1
|
@@ -40,6 +28,18 @@ note: attribute also specified here
LL | #![no_builtins]
| ^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:37:1
|
LL | #[no_link]
| ^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:36:1
|
LL | #[no_link]
| ^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:41:1
|