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

new lint: find unneccessary Some(x).and_then(|y| Some(y ..)) #6472

Closed
matthiaskrgr opened this issue Dec 19, 2020 · 3 comments · Fixed by #11413
Closed

new lint: find unneccessary Some(x).and_then(|y| Some(y ..)) #6472

matthiaskrgr opened this issue Dec 19, 2020 · 3 comments · Fixed by #11413
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Dec 19, 2020

What it does

Catch Some(..).and_then(|..| Some(..)) patterns.

What does this lint do?
Suggest to simplify the statement to Some(do something with x and y)
For example Some(3).and_then(|x| Some(x+4)); could be simplified to Some(3+4)

Categories (optional)

Complexity, maybe pedantic.

What is the advantage of the recommended code over the original code
It's way easier to understand

Drawbacks

None.

Example

Some(3).and_then(|x| Some(x+4));

Could be written as:

Some(3+4)
@matthiaskrgr matthiaskrgr added the A-lint Area: New lints label Dec 19, 2020
@alex-700
Copy link
Contributor

@matthiaskrgr
.and_then(|x| Some(..)) perfectly triggers bind_instead_of_map lint. So it seems this lint idea should be about Some(x).map(|x| foo(x)), which should be replaced with Some(foo(x)) for every expression foo.

@matthiaskrgr
Copy link
Member Author

Yes, Some(..).map() could be futher simplified if we know that we will have Some(x..) at the beginning of the statement.

@camsteffen camsteffen added good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group labels Feb 7, 2021
@jonboh
Copy link
Contributor

jonboh commented Aug 22, 2023

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-complexity Lint: Belongs in the complexity lint group
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants