Skip to content

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

Closed
@KisaragiEffective

Description

@KisaragiEffective

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions