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 does not consider type changes and suggests wrong code #12928

Closed
sdroege opened this issue Jun 14, 2024 · 1 comment · Fixed by #12961
Closed

manual_unwrap_or_default does not consider type changes and suggests wrong code #12928

sdroege opened this issue Jun 14, 2024 · 1 comment · Fixed by #12961
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@sdroege
Copy link

sdroege commented Jun 14, 2024

Summary

See code below

Lint Name

manual_unwrap_or_default

Reproducer

I tried this code:

fn main() {
    let x = Some((1, 2));
    let y = if let Some((a, _)) = x {
        a
    } else {
        0
    };
    
    println!("{y}");
}

I saw this happen:

warning: if let can be simplified with `.unwrap_or_default()`
 --> src/main.rs:3:13
  |
3 |       let y = if let Some((a, _)) = x {
  |  _____________^
4 | |         a
5 | |     } else {
6 | |         0
7 | |     };
  | |_____^ help: replace it with: `x.unwrap_or_default()`
  |
  = 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

I expected to see this happen: [nothing]

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

Additional Labels

@rustbot label +I-suggestion-causes-error

@sdroege sdroege added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jun 14, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jun 14, 2024
@GuillaumeGomez GuillaumeGomez self-assigned this Jun 19, 2024
@GuillaumeGomez
Copy link
Member

Taking a look.

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 I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants