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

clippy redundant pattern matching suggestion not compiling #5766

Closed
BenjaminRi opened this issue Jul 5, 2020 · 2 comments
Closed

clippy redundant pattern matching suggestion not compiling #5766

BenjaminRi opened this issue Jul 5, 2020 · 2 comments
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

@BenjaminRi
Copy link

I ran cargo clippy on the following piece of code:

fn main() {
	let s = "foo";
	if let Ok(_) = &s[1..s.len()].parse::<u32>() {
	}
}

Clippy (correctly) detects a redundant pattern matching and (incorrectly) suggests replacing if let Ok(_) = &s[1..s.len()].parse::<u32>() with if &s[1..s.len()].parse::<u32>().is_ok(). But that snippet does not compile if you insert it. It should be replaced with if s[1..s.len()].parse::<u32>().is_ok() (dropping the reference), that is the correct suggestion.

Meta

Tested on clippy:
0.0.212 (bb37a0f 2020-06-16)

@BenjaminRi BenjaminRi added the C-bug Category: Clippy is not doing the correct thing label Jul 5, 2020
@flip1995 flip1995 added 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 Jul 13, 2020
@JarredAllen
Copy link
Contributor

I can fix this.

bors added a commit that referenced this issue Jul 18, 2020
Redundant pattern bugfix

changelog: Fixes the bug reported #5766
bors added a commit that referenced this issue Jul 18, 2020
Redundant pattern bugfix

changelog: Fixes the bug reported #5766
@JarredAllen
Copy link
Contributor

I believe this issue can be closed, as it has been fixed.

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

No branches or pull requests

3 participants