rust-lang / rust-lang/rust-clippy
allow() fails when other warnings trigger (possibly on macro)
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When a statement (macro?) triggers two different warnings and one of them is allow-ed, the allow-ed warning triggers anyway
Lint Name
No response
Reproducer
I tried this code:
#[allow(clippy::write_with_newline)]
write!(w, "{}\n", val);
I saw this happen:
warning: unused attribute `allow`
--> src/lib.rs:9:5
|
9 | #[allow(clippy::write_with_newline)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `write`
--> src/lib.rs:10:5
|
10 | write!(w, "{}\n", val);
| ^^^^^
= note: `#[warn(unused_attributes)]` on by default
warning: using `write!()` with a format string that ends in a single newline
--> src/lib.rs:10:5
|
10 | write!(w, "{}\n", val);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
= note: `#[warn(clippy::write_with_newline)]` on by default
help: use `writeln!` instead
|
10 - write!(w, "{}\n", val);
10 + writeln!(w, "{}", val);
|
warning: unused `std::result::Result` that must be used
--> src/lib.rs:10:5
|
10 | write!(w, "{}\n", val);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: `#[warn(unused_must_use)]` on by default
= note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
I expected to see this happen:
warning: unused `std::result::Result` that must be used
--> src/lib.rs:10:5
|
10 | write!(w, "{}\n", val);
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: `#[warn(unused_must_use)]` on by default
= note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)
The version which does not trigger unused_must_use:
#[allow(clippy::write_with_newline)]
write!(w, "{}\n", val).unwrap();
does not trigger any warning
Version
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
Also current playground
Additional Labels
No response
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.
Research direction
Start with the Rust reproducer using write! and #[allow(clippy::write_with_newline)], comparing the diagnostics with and without .unwrap(). Investigate how the Clippy lint and the unused attribute, unused_must_use, and macro invocation interact; done when allowing write_with_newline suppresses that lint without suppressing the unrelated unused_must_use warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100