Skip to content

Cargo clippy --fix error #8826

@MMukundi

Description

@MMukundi

I tried this code:

cargo clippy --fix

In this repo: https://github.com/MMukundi/aoc

I expected to see this happen: Clippy successfully fixes lint issues

Instead, this happened: Clippy runs into a compiler error after fixing a linting issue; specifically, after changing

.any(|i| self.all_true(&mut i.into_iter()))

to

.any(|i| self.all_true(&mut i))

where

fn all_true<I: Iterator<Item = usize>>(&self, iter: &mut I) -> bool { // --snip-- }

The expression thus far was of type impl Iterator<Item = impl Iterator<Item=usize>>

Meta

rustc --version --verbose:

rustc 1.60.0 (7737e0b5c 2022-04-04) binary: rustc commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c commit-date: 2022-04-04 host: x86_64-apple-darwin release: 1.60.0 LLVM version: 14.0.0 
Backtrace

➜ aoc git:(master) RUST_BACKTRACE=1 cargo clippy --fix Checking aoc v0.1.0 (/Users/marcelmukundi/Desktop/Desktop - Marcel’s MacBook Pro/aoc) warning: failed to automatically apply fixes suggested by rustc to crate `aoc` after fixes were automatically applied the compiler reported errors within these files: * src/solutions/day4.rs This likely indicates a bug in either rustc or cargo itself, and we would appreciate a bug report! You're likely to see a number of compiler warnings after this message which cargo attempted to fix but failed. If you could open an issue at https://github.com/rust-lang/rust/issues quoting the full output of this command we'd be very appreciative! Note that you may be able to make some more progress in the near-term fixing code with the `--broken-code` flag The following errors were reported: error[E0596]: cannot borrow `i` as mutable, as it is not declared as mutable --> src/solutions/day4.rs:31:40 | 31 | .any(|i| self.all_true(&mut i)) | - ^^^^^^ cannot borrow as mutable | | | help: consider changing this to be mutable: `mut i` error: aborting due to previous error For more information about this error, try `rustc --explain E0596`. Original diagnostics will follow. warning: if let .. else expression looks like `matches!` macro --> src/solutions/day10/mod.rs:107:13 | 107 | / if let SyntaxError::Corrupted(_) = s { 108 | | true 109 | | } else { 110 | | false 111 | | } | |_____________^ help: try this: `matches!(s, SyntaxError::Corrupted(_))` | = note: `#[warn(clippy::match_like_matches_macro)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro warning: if let .. else expression looks like `matches!` macro --> src/solutions/day10/mod.rs:119:17 | 119 | / if let SyntaxError::Incomplete(_) = s { 120 | | true 121 | | } else { 122 | | false 123 | | } | |_________________^ help: try this: `matches!(s, SyntaxError::Incomplete(_))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro warning: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` --> src/solutions/day4.rs:11:13 | 11 | / self.0 12 | | .iter() 13 | | .position(|b| b == ball) 14 | | .map(|i| self.1[i] = true); | |__________________________________________^ | = note: `#[warn(clippy::option_map_unit_fn)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn help: try this | 11 ~ if let Some(i) = self.0 12 + .iter() 13 + .position(|b| b == ball) { ... } | warning: useless conversion to the same type: `std::iter::StepBy<std::iter::Skip<std::ops::Range<usize>>>` --> src/solutions/day4.rs:31:45 | 31 | .any(|i| self.all_true(&mut i.into_iter())) | ^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `i` | = note: `#[warn(clippy::useless_conversion)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion warning: single-character string constant used as pattern --> src/solutions/day6.rs:45:20 | 45 | .split(",") | ^^^ help: try using a `char` instead: `','` | = note: `#[warn(clippy::single_char_pattern)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern warning: this `impl` can be derived --> src/solutions/day8/entry.rs:15:1 | 15 | / impl Default for Segments { 16 | | fn default() -> Self { 17 | | Self { 18 | | bits: Default::default(), 19 | | } 20 | | } 21 | | } | |_^ | = note: `#[warn(clippy::derivable_impls)]` on by default = help: try annotating `solutions::day8::entry::Segments` with `#[derive(Default)]` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls warning: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` --> src/solutions/day8/entry.rs:101:9 | 101 | entry_str.next().map(|s| { | _________^ | |_________| | || 102 | || let pattern_iter = s.split_whitespace(); 103 | || entry 104 | || .signal_patterns ... || 107 | || .for_each(|(dest, src)| *dest = src.parse::<Segments>().unwrap()); 108 | || }); | ||__________^- help: try this: `if let Some(s) = entry_str.next() { ... }` | |___________| | | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn warning: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()` --> src/solutions/day8/entry.rs:109:9 | 109 | entry_str.next().map(|s| { | _________^ | |_________| | || 110 | || let outputs_iter = s.split_whitespace(); 111 | || entry 112 | || .outputs ... || 115 | || .for_each(|(dest, src)| *dest = src.parse::<Segments>().unwrap()); 116 | || }); | ||__________^- help: try this: `if let Some(s) = entry_str.next() { ... }` | |___________| | | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn warning: match expression looks like `matches!` macro --> src/solutions/day8/mod.rs:27:33 | 27 | .filter(|o| match o.count_active() { | _________________________________^ 28 | | 2 | 3 | 4 | 7 => true, 29 | | _ => false, 30 | | }) | |_____________________^ help: try this: `matches!(o.count_active(), 2 | 3 | 4 | 7)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro warning: you are deriving `Hash` but have implemented `PartialEq` explicitly --> src/utils/point.rs:5:39 | 5 | #[derive(Debug, Clone, Copy, Default, Hash, Eq)] | ^^^^ | = note: `#[warn(clippy::derive_hash_xor_eq)]` on by default note: `PartialEq` implemented here --> src/utils/point.rs:93:1 | 93 | / impl PartialEq for Point { 94 | | fn eq(&self, other: &Self) -> bool { 95 | | self.x == other.x && self.y == other.y 96 | | } 97 | | } | |_^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_hash_xor_eq = note: this warning originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) warning: called `.iter_mut().nth()` on a Vec --> src/main.rs:42:38 | 42 | if let Some(s) = solutions.iter_mut().nth(0) { s.solve() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::iter_nth)]` on by default = help: calling `.get_mut()` is both faster and more readable = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth warning: `aoc` (bin "aoc") generated 11 warnings warning: `aoc` (bin "aoc" test) generated 11 warnings (11 duplicates) Finished dev [unoptimized + debuginfo] target(s) in 2.94s 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions