Skip to content

match_single_binding: suggests broken code (missing curly braces) #5347

@matthiaskrgr

Description

@matthiaskrgr
Member
warning: this match could be written as a `let` statement
    --> src/librustc_builtin_macros/deriving/generic/mod.rs:1059:34
     |
1059 |                           .map(|l| match l.next().unwrap() {
     |  __________________________________^
1060 | |                             (.., ex, _) => ex,
1061 | |                         })
     | |_________________________^
     |
     = note: `#[warn(clippy::match_single_binding)]` on by default
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
help: consider using `let` statement
     |
1059 |                         .map(|l| let (.., ex, _) = l.next().unwrap();
1060 |                         ex)
     |

The suggested code does not compile,

error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
    --> src/librustc_builtin_macros/deriving/generic/mod.rs:1060:64
     |
1060 | ...                   let (.., ex, _) = l.next().unwrap();
     |                                                          ^
     |                                                          |
     |                                                          expected one of `)`, `,`, `.`, `?`, or an operator
     |                                                          help: missing `,`

error[E0425]: cannot find value `ex` in this scope
    --> src/librustc_builtin_macros/deriving/generic/mod.rs:1061:29
     |
1061 | ...                   ex
     |                       ^^ help: a local variable with a similar name exists: `cx`

error[E0658]: `let` expressions in this position are experimental
    --> src/librustc_builtin_macros/deriving/generic/mod.rs:1060:29
     |
1060 | ...                   let (.., ex, _) = l.next().unwrap();
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
     = help: add `#![feature(let_chains)]` to the crate attributes to enable

we need curly braces around the let + return statement like this:

                        .map(|l| {
                            let (.., ex, _) = l.next().unwrap();
                            ex
                        })

Activity

added
C-bugCategory: Clippy is not doing the correct thing
L-suggestionLint: Improving, adding or fixing lint suggestions
I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
on Mar 21, 2020
ThibsG

ThibsG commented on Mar 21, 2020

@ThibsG
Contributor

Thanks for reporting this, I will work on a fix

added 3 commits that reference this issue on Mar 23, 2020
c2a1f54
3abac70
1ff81c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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 appliedL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @matthiaskrgr@ThibsG

      Issue actions

        match_single_binding: suggests broken code (missing curly braces) · Issue #5347 · rust-lang/rust-clippy