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

The suggested code by option_map_or_none is warned again in some case #7960

Closed
giraffate opened this issue Nov 11, 2021 · 0 comments · Fixed by #7971
Closed

The suggested code by option_map_or_none is warned again in some case #7960

giraffate opened this issue Nov 11, 2021 · 0 comments · Fixed by #7971
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

@giraffate
Copy link
Contributor

fn main() {
    let opt = Some(3);
    opt.map_or(None, |a| Some(a + 1));
}

Clippy warns like below on this:

  |
3 |     opt.map_or(None, |a| Some(a + 1));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(|a| Some(a + 1))`
  |

So I updated it according to the warning:

fn main() {
    let opt = Some(3);
    opt.and_then(|a| Some(a + 1));
}

But, Clippy warns like below again:

  |
3 |     opt.and_then(|a| Some(a + 1));
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `opt.map(|a| a + 1)`
  |

In this case, I want option_map_or_none to suggest the last code suggested from the beginning.

@giraffate giraffate 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 Nov 11, 2021
@bors bors closed this as completed in 6ac42fe Nov 17, 2021
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
Development

Successfully merging a pull request may close this issue.

1 participant