Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[manual_let_else] does not take binding variable name into account #10424

Closed
KisaragiEffective opened this issue Feb 28, 2023 · 2 comments · Fixed by #10866
Closed

[manual_let_else] does not take binding variable name into account #10424

KisaragiEffective opened this issue Feb 28, 2023 · 2 comments · Fixed by #10866
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@KisaragiEffective
Copy link
Contributor

Summary

manual_let_else suggestion ignores variable name whether binding pattern have same name or not.

Reproducer

I tried this code:

let name = if let Token::Identifier { inner } = ident_token.data {
    inner
} else {
    return Err(SimpleErrorWithPos {
        position: ident_token.position,
        kind: ParserError::UnexpectedToken {
            pat: TokenKind::Identifier,
            unmatch: ident_token.data,
        }
    })
}

I expected to see this happen:

help: consider writing
    |
498 ~         let Token::Identifier { inner: name } = ident_token.data else {
499 +             return Err(SimpleErrorWithPos {
500 +                 position: ident_token.position,
501 +                 kind: ParserError::UnexpectedToken {
502 +                     pat: TokenKind::Identifier,
503 +                     unmatch: ident_token.data,
504 +                 }
505 +             })
506 +         };
    |

Instead, this happened:

help: consider writing
    |
498 ~         let Token::Identifier { inner } = ident_token.data else {
499 +             return Err(SimpleErrorWithPos {
500 +                 position: ident_token.position,
501 +                 kind: ParserError::UnexpectedToken {
502 +                     pat: TokenKind::Identifier,
503 +                     unmatch: ident_token.data,
504 +                 }
505 +             })
506 +         };
    |

Version

rustc 1.69.0-nightly (d962ea578 2023-02-26)
binary: rustc
commit-hash: d962ea57899d64dc8a57040142c6b498a57c8064
commit-date: 2023-02-26
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

@rustbot label I-suggestion-causes-error

@KisaragiEffective KisaragiEffective added the C-bug Category: Clippy is not doing the correct thing label Feb 28, 2023
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Feb 28, 2023
@est31
Copy link
Member

est31 commented Mar 1, 2023

See #9939 . PR #10175 is improving the suggestions but I think it won't be enough for this particular issue.

@est31
Copy link
Member

est31 commented May 18, 2023

Yeah #10175 adds support for tuple struct patterns (those with ()), so renaming now correctly works for them. But your examples have struct patterns (those with {}), which are a bit harder.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: Clippy is not doing the correct thing 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