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

Add real suggestion to option_map_unwrap_or #2320

Closed
killercup opened this issue Jan 3, 2018 · 0 comments · Fixed by #4634
Closed

Add real suggestion to option_map_unwrap_or #2320

killercup opened this issue Jan 3, 2018 · 0 comments · Fixed by #4634
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@killercup
Copy link
Member

I'm not saying this is a lint I'd enable—but I just came across the fact that it currently generates outpt like this:

error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
   --> $DIR/methods.rs:103:13
    |
103 |       let _ = opt.map(|x| x + 1)
    |  _____________^
104 | |
105 | |                .unwrap_or(0); // should lint even though this call is on a separate line
    | |____________________________^
    |
    = note: `-D option-map-unwrap-or` implied by `-D warnings`
    = note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)`

It looks like the suggestion is pretty stable, right? Let's turn it into an actual rustfix-able suggestion, then!

killercup added a commit to killercup/rust-clippy that referenced this issue Jan 4, 2018
@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Jan 9, 2018
bors added a commit that referenced this issue Dec 30, 2019
Add real suggestion to option_map_unwrap_or

Fixes #2320
@bors bors closed this as completed in cecaca3 Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
3 participants