[bug] `#[warn(unused_result)]` gives syntactically incorrect code suggestion.
Open
@eggyal is already working on this.
Since Feb 10, 2026.
A-diagnostics
C-bug
D-invalid-suggestion
S-has-mcve
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
type Result<T> = std::result::Result<T, ()>;
macro_rules! bad_suggestion {
() => {{ bs_2!() }};
}
#[macro_export]
macro_rules! bs_2 {
() => {
Result::<()>::Ok(())
};
}
fn main() -> Result<()> {
bad_suggestion!();
Ok(())
}
Current output
warning: unused `std::result::Result` that must be used
--> src/main.rs:15:5
|
15 | bad_suggestion!();
| ^^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default
help: use `let _ = ...` to ignore the resulting value
|
15 | let _ = bad_suggestion!();;
| +++++++ +
Desired output
warning: unused `std::result::Result` that must be used
--> src/main.rs:15:5
|
15 | bad_suggestion!();
| ^^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default
help: use `let _ = ...` to ignore the resulting value
|
15 | let _ = bad_suggestion!();
| +++++++
Rationale and extra context
Nesting macros within each other, when the top-level macro statement block with 2 (or more) balanced pairs of braces gives this output. I found this while using the execute!() macro from crossterm.
Other cases
changing it to the following fixes the issue:
// ----
macro_rules! bad_suggestion {
() => {
bs_2!()
};
}
// ----
Rust Version
rustc 1.93.0 (254b59607 2026-01-19)
binary: rustc
commit-hash: 254b59607d4417e9dffbc307138ae5c86280fe4c
commit-date: 2026-01-19
host: aarch64-apple-darwin
release: 1.93.0
LLVM version: 21.1.8
Anything else?
PFA playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=1be23105720ff4b714e4ab4f0a86c568
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.