rust-lang / rust-lang/rust-clippy
`manual_unwrap_or_default` invalid suggestion on macro expanded code
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
manual_unwrap_or_default invalid suggestion on macro expanded code
Reproducer
I tried this code: https://github.com/dj8yfo/clppy_bug/blob/master/src/lib.rs#L1-L10
I expected to see this happen: no clippy suggestion is produced
Instead, this happened:
❯ cargo clippy
warning: if let can be simplified with `.unwrap_or_default()`
--> src/lib.rs:8:15
|
8 | #[darling(skip)]
| ^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or_default
= note: `#[warn(clippy::manual_unwrap_or_default)]` on by default
help: replace it with
|
8 ~ #[darling(skip)]
9 ~ bar.unwrap_or_default())]
|
Version
rustc 1.79.0 (129f3b996 2024-06-10)
binary: rustc
commit-hash: 129f3b9964af4d4a709d1383930ade12dfe7c081
commit-date: 2024-06-10
host: x86_64-unknown-linux-gnu
release: 1.79.0
LLVM version: 18.1.7
KK
Additional Notes
It looks like clippy suggests to change this code inside of darling macro expansion:
::darling::export::Ok(Self {
qux: qux
.1
.expect("Uninitialized fields without defaults were already checked"),
bar: if let Some(__val) = bar.1 {
__val
} else {
::darling::export::Default::default()
},
})
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 linked src/lib.rs reproducer and run cargo clippy to observe the manual_unwrap_or_default warning at the darling attribute. Trace the manual_unwrap_or_default lint and its handling of macro-expanded code. Done means the reproducer no longer receives an invalid suggestion for code generated inside the macro expansion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100