Closed
Description
Code
Code provided by Discord user baltdev on the Rust Programming Language Discord server (message link).
macro_rules! sample { () => {} }
#[sample]
pub struct S {}
Current output
error: cannot find attribute `sample` in this scope
--> src/lib.rs:3:3
|
3 | #[sample]
| ^^^^^^ consider moving the definition of `sample` before this call
|
note: a macro with the same name exists, but it appears later at here
--> src/lib.rs:1:14
|
1 | macro_rules! sample { () => {} }
| ^^^^^^
warning: unused macro definition: `sample`
--> src/lib.rs:1:14
|
1 | macro_rules! sample { () => {} }
| ^^^^^^
|
= note: `#[warn(unused_macros)]` on by default
Desired output
error: `sample` is not an attribute macro
help: `macro_rules!` macros cannot be used as attribute macros
Rationale and extra context
The error message is about a missing definition that is not missing, and incorrectly suggests that reordering the code might help. It should instead explain the fundamental problem with what is being attempted.
This issue is moot if rust-lang/rfcs#3697 is implemented.
Other cases
Rust Version
1.82.0
Anything else?
No response