You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mmstick opened this issue
Jun 12, 2016
· 5 comments
Labels
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupT-middleType: Probably requires verifiying types
Clippy should be able to detect instances where an if statement is being used to calculate the min or max of two or more values and recommend using the cmp::min/max functions instead. These two examples were taken from real-world code directly translated from C into Rust.
Example 1:
Unnecessary
letmut x = if a < b { a }else{ b };if x > y { x = y;}
could even be [a, b, y].iter().min().unwrap() which is better IMO.
mcarton
added
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
T-AST
Type: Requires working with the AST
A-lint
Area: New lints
L-style
Lint: Belongs in the style lint group
labels
Jun 12, 2016
I'd disagree that the iterator version is better. It introduces the potential for failure (the unwrap) when the original one didn't have that potential. Chained min or max calls would be better.
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupT-middleType: Probably requires verifiying types
Clippy should be able to detect instances where an if statement is being used to calculate the min or max of two or more values and recommend using the
cmp::min/max
functions instead. These two examples were taken from real-world code directly translated from C into Rust.Example 1:
Unnecessary
Recommended
Example 2:
Unnecessary
Recommended
The text was updated successfully, but these errors were encountered: