mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
Regression test for attributes on macro calls
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
This commit is contained in:
parent
3851e6c7b6
commit
fe81a79e59
73
tests/ui/attributes/attr-on-mac-call.rs
Normal file
73
tests/ui/attributes/attr-on-mac-call.rs
Normal file
@ -0,0 +1,73 @@
|
||||
//@ check-pass
|
||||
// Regression test for https://github.com/rust-lang/rust/issues/145779
|
||||
#![warn(unused_attributes)]
|
||||
|
||||
fn main() {
|
||||
#[export_name = "x"]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[unsafe(naked)]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[track_caller]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[used]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[target_feature(enable = "x")]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[deprecated]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[inline]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[link_name = "x"]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[link_section = "x"]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[link_ordinal(42)]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[non_exhaustive]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[proc_macro]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[cold]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[no_mangle]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[deprecated]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[automatically_derived]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[macro_use]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[must_use]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[no_implicit_prelude]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[path = ""]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[ignore]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
#[should_panic]
|
||||
//~^ WARN attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
unreachable!();
|
||||
}
|
205
tests/ui/attributes/attr-on-mac-call.stderr
Normal file
205
tests/ui/attributes/attr-on-mac-call.stderr
Normal file
@ -0,0 +1,205 @@
|
||||
warning: `#[export_name]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:6:5
|
||||
|
|
||||
LL | #[export_name = "x"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[export_name]` can be applied to functions and statics
|
||||
note: the lint level is defined here
|
||||
--> $DIR/attr-on-mac-call.rs:3:9
|
||||
|
|
||||
LL | #![warn(unused_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: `#[naked]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:9:5
|
||||
|
|
||||
LL | #[unsafe(naked)]
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[naked]` can only be applied to functions
|
||||
|
||||
warning: `#[track_caller]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:12:5
|
||||
|
|
||||
LL | #[track_caller]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[track_caller]` can only be applied to functions
|
||||
|
||||
warning: `#[used]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:15:5
|
||||
|
|
||||
LL | #[used]
|
||||
| ^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[used]` can only be applied to statics
|
||||
|
||||
warning: `#[target_feature]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:18:5
|
||||
|
|
||||
LL | #[target_feature(enable = "x")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[target_feature]` can only be applied to functions
|
||||
|
||||
warning: `#[deprecated]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:21:5
|
||||
|
|
||||
LL | #[deprecated]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
|
||||
|
||||
warning: `#[inline]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:24:5
|
||||
|
|
||||
LL | #[inline]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[inline]` can only be applied to functions
|
||||
|
||||
warning: `#[link_name]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:27:5
|
||||
|
|
||||
LL | #[link_name = "x"]
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[link_name]` can be applied to foreign functions and foreign statics
|
||||
|
||||
warning: `#[link_section]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:30:5
|
||||
|
|
||||
LL | #[link_section = "x"]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[link_section]` can be applied to statics and functions
|
||||
|
||||
warning: `#[link_ordinal]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:33:5
|
||||
|
|
||||
LL | #[link_ordinal(42)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[link_ordinal]` can be applied to foreign functions and foreign statics
|
||||
|
||||
warning: `#[non_exhaustive]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:36:5
|
||||
|
|
||||
LL | #[non_exhaustive]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[non_exhaustive]` can be applied to data types and enum variants
|
||||
|
||||
warning: `#[proc_macro]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:39:5
|
||||
|
|
||||
LL | #[proc_macro]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[proc_macro]` can only be applied to functions
|
||||
|
||||
warning: `#[cold]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:42:5
|
||||
|
|
||||
LL | #[cold]
|
||||
| ^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[cold]` can only be applied to functions
|
||||
|
||||
warning: `#[no_mangle]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:45:5
|
||||
|
|
||||
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
|
||||
|
||||
warning: `#[deprecated]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:48:5
|
||||
|
|
||||
LL | #[deprecated]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
|
||||
|
||||
warning: `#[automatically_derived]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:51:5
|
||||
|
|
||||
LL | #[automatically_derived]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[automatically_derived]` can only be applied to trait impl blocks
|
||||
|
||||
warning: `#[macro_use]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:54:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[macro_use]` can be applied to modules, extern crates, and crates
|
||||
|
||||
warning: `#[must_use]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:57:5
|
||||
|
|
||||
LL | #[must_use]
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[must_use]` can be applied to functions, data types, unions, and traits
|
||||
|
||||
warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:60:5
|
||||
|
|
||||
LL | #[no_implicit_prelude]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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_implicit_prelude]` can be applied to modules and crates
|
||||
|
||||
warning: `#[path]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:63:5
|
||||
|
|
||||
LL | #[path = ""]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[path]` can only be applied to modules
|
||||
|
||||
warning: `#[ignore]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:66:5
|
||||
|
|
||||
LL | #[ignore]
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[ignore]` can only be applied to functions
|
||||
|
||||
warning: `#[should_panic]` attribute cannot be used on macro calls
|
||||
--> $DIR/attr-on-mac-call.rs:69:5
|
||||
|
|
||||
LL | #[should_panic]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[should_panic]` can only be applied to functions
|
||||
|
||||
warning: 22 warnings emitted
|
||||
|
@ -1,6 +1,5 @@
|
||||
//@ check-pass
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![warn(unused)]
|
||||
|
||||
macro_rules! foo {
|
||||
@ -8,16 +7,18 @@ macro_rules! foo {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[rustc_dummy] foo!(); //~ WARN unused attribute `rustc_dummy`
|
||||
#[inline] foo!(); //~ WARN `#[inline]` attribute cannot be used on macro calls
|
||||
//~^ WARN previously accepted
|
||||
|
||||
// This does nothing, since `#[allow(warnings)]` is itself
|
||||
// an inert attribute on a macro call
|
||||
#[allow(warnings)] #[rustc_dummy] foo!(); //~ WARN unused attribute `allow`
|
||||
//~^ WARN unused attribute `rustc_dummy`
|
||||
#[allow(warnings)] #[inline] foo!(); //~ WARN unused attribute `allow`
|
||||
//~^ WARN `#[inline]` attribute cannot be used on macro calls
|
||||
//~| WARN previously accepted
|
||||
|
||||
// This does work, since the attribute is on a parent
|
||||
// of the macro invocation.
|
||||
#[allow(warnings)] { #[rustc_dummy] foo!(); }
|
||||
#[allow(warnings)] { #[inline] foo!(); }
|
||||
|
||||
// Ok, `cfg` and `cfg_attr` are expanded eagerly and do not warn.
|
||||
#[cfg(true)] foo!();
|
||||
|
@ -1,16 +1,13 @@
|
||||
warning: unused attribute `rustc_dummy`
|
||||
--> $DIR/inert-attr-macro.rs:11:5
|
||||
warning: `#[inline]` attribute cannot be used on macro calls
|
||||
--> $DIR/inert-attr-macro.rs:10:5
|
||||
|
|
||||
LL | #[rustc_dummy] foo!();
|
||||
| ^^^^^^^^^^^^^^
|
||||
LL | #[inline] foo!();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: the built-in attribute `rustc_dummy` will be ignored, since it's applied to the macro invocation `foo`
|
||||
--> $DIR/inert-attr-macro.rs:11:20
|
||||
|
|
||||
LL | #[rustc_dummy] foo!();
|
||||
| ^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[inline]` can only be applied to functions
|
||||
note: the lint level is defined here
|
||||
--> $DIR/inert-attr-macro.rs:4:9
|
||||
--> $DIR/inert-attr-macro.rs:3:9
|
||||
|
|
||||
LL | #![warn(unused)]
|
||||
| ^^^^^^
|
||||
@ -19,26 +16,23 @@ LL | #![warn(unused)]
|
||||
warning: unused attribute `allow`
|
||||
--> $DIR/inert-attr-macro.rs:15:5
|
||||
|
|
||||
LL | #[allow(warnings)] #[rustc_dummy] foo!();
|
||||
LL | #[allow(warnings)] #[inline] foo!();
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
|
||||
--> $DIR/inert-attr-macro.rs:15:39
|
||||
--> $DIR/inert-attr-macro.rs:15:34
|
||||
|
|
||||
LL | #[allow(warnings)] #[rustc_dummy] foo!();
|
||||
| ^^^
|
||||
LL | #[allow(warnings)] #[inline] foo!();
|
||||
| ^^^
|
||||
|
||||
warning: unused attribute `rustc_dummy`
|
||||
warning: `#[inline]` attribute cannot be used on macro calls
|
||||
--> $DIR/inert-attr-macro.rs:15:24
|
||||
|
|
||||
LL | #[allow(warnings)] #[rustc_dummy] foo!();
|
||||
| ^^^^^^^^^^^^^^
|
||||
LL | #[allow(warnings)] #[inline] foo!();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
note: the built-in attribute `rustc_dummy` will be ignored, since it's applied to the macro invocation `foo`
|
||||
--> $DIR/inert-attr-macro.rs:15:39
|
||||
|
|
||||
LL | #[allow(warnings)] #[rustc_dummy] foo!();
|
||||
| ^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= help: `#[inline]` can only be applied to functions
|
||||
|
||||
warning: 3 warnings emitted
|
||||
|
||||
|
@ -65,7 +65,6 @@ extern "Rust" {
|
||||
fn foreign_foo() -> i64;
|
||||
}
|
||||
|
||||
//~ ERROR unused attribute
|
||||
//~^ ERROR `#[must_use]` attribute cannot be used on macro calls
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
global_asm!("");
|
||||
|
@ -65,7 +65,7 @@ extern "Rust" {
|
||||
fn foreign_foo() -> i64;
|
||||
}
|
||||
|
||||
#[must_use] //~ ERROR unused attribute
|
||||
#[must_use]
|
||||
//~^ ERROR `#[must_use]` attribute cannot be used on macro calls
|
||||
//~| WARN this was previously accepted by the compiler but is being phased out
|
||||
global_asm!("");
|
||||
|
@ -12,18 +12,6 @@ note: the lint level is defined here
|
||||
LL | #![deny(unused_attributes, unused_must_use)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused attribute `must_use`
|
||||
--> $DIR/unused_attributes-must_use.rs:68:1
|
||||
|
|
||||
LL | #[must_use]
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
note: the built-in attribute `must_use` will be ignored, since it's applied to the macro invocation `global_asm`
|
||||
--> $DIR/unused_attributes-must_use.rs:71:1
|
||||
|
|
||||
LL | global_asm!("");
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: `#[must_use]` attribute cannot be used on extern crates
|
||||
--> $DIR/unused_attributes-must_use.rs:7:1
|
||||
|
|
||||
@ -295,5 +283,5 @@ help: use `let _ = ...` to ignore the resulting value
|
||||
LL | let _ = ().get_four();
|
||||
| +++++++
|
||||
|
||||
error: aborting due to 30 previous errors
|
||||
error: aborting due to 29 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user