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

manual_unwrap_or_default invalid suggestion on macro expanded code #12967

Open
dj8yfo opened this issue Jun 20, 2024 · 1 comment
Open

manual_unwrap_or_default invalid suggestion on macro expanded code #12967

dj8yfo opened this issue Jun 20, 2024 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@dj8yfo
Copy link

dj8yfo commented Jun 20, 2024

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

@dj8yfo dj8yfo added the C-bug Category: Clippy is not doing the correct thing label Jun 20, 2024
@dj8yfo
Copy link
Author

dj8yfo commented Jun 20, 2024

may or may not be related to #12928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

No branches or pull requests

1 participant