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

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

Closed
matthiaskrgr opened this issue Mar 21, 2020 · 1 comment · Fixed by #5350
Closed

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

matthiaskrgr opened this issue Mar 21, 2020 · 1 comment · Fixed by #5350
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 L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@matthiaskrgr
Copy link
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:/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
                        })
@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Mar 21, 2020
@ThibsG
Copy link
Contributor

ThibsG commented Mar 21, 2020

Thanks for reporting this, I will work on a fix

bors added a commit that referenced this issue Mar 23, 2020
Fix single binding closure

Fix the `match_single_binding` lint when triggered inside a closure.

Fixes: #5347

Changelog: none
bors added a commit that referenced this issue Mar 23, 2020
Fix single binding closure

Fix the `match_single_binding` lint when triggered inside a closure.

Fixes: #5347

changelog: none
@bors bors closed this as completed in 1ff81c1 Mar 23, 2020
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants