Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error when attempting to use macro_rules as an attribute #132928

Open
kpreid opened this issue Nov 12, 2024 · 0 comments · May be fixed by #132949
Open

Misleading error when attempting to use macro_rules as an attribute #132928

kpreid opened this issue Nov 12, 2024 · 0 comments · May be fixed by #132949
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Nov 12, 2024

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

@kpreid kpreid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant