- Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions
Description
Hi,
Given the following code:
fn test(idx: usize) -> bool { idx % 2 == 0 } fn algo(mut x: usize, y: usize, height: usize, width: usize) { let mut last_row_length = 0; let mut sx = x; if last_row_length != 0 && test(y * width + x) { loop { last_row_length -= 1; if last_row_length == 0 { return; } x += 1; if !test(y * width + x) { break; } } sx = x; } else { while x != 0 && !test(y * width + x - 1) { x -= 1; if y != 0 && !test((y - 1) * width + x) { algo(x, y - 1, width, height); } last_row_length += 1; } } println!("{}", sx); }clippy suggests the following:
warning: `if _ { .. } else { .. }` is an expression --> src/main.rs:7:5 | 7 | / let mut sx = x; 8 | | 9 | | if last_row_length != 0 && test(y * width + x) { 10 | | loop { ... | 30 | | } 31 | | } | |_____^ help: it is more idiomatic to write: `let <mut> sx = if last_row_length != 0 && test(y * width + x) { ..; x } else { ..; x };` | = note: #[warn(useless_let_if_seq)] on by default = note: you might not need `mut` at all = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#useless_let_if_seq This is incorrect, since x is modified in the loop in the else path, but NOT assigned to sx.
(Note: the code itself is not the most idiomatic, since I'm transcribing an algorithm from another language...)
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedL-suggestionLint: Improving, adding or fixing lint suggestionsLint: Improving, adding or fixing lint suggestions