- Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
I tried this code:
use std::collections::BTreeMap; struct SomeLargeContainer {} pub struct Handle(u32); struct Test { sections: BTreeMap<u32, SomeLargeContainer>, } impl Test { pub fn find_section_by_index(&self, index: u32) -> Option<Handle> { let mut idx: u32 = 0; for (handle, _) in &self.sections { if idx == index { return Some(Handle(*handle)); } idx += 1; } return None; } }
I expected to see this happen: Clippy fixing this explicit_counter_loop
Instead, this happened: I got a bug report from clippy:
warning: failed to automatically apply fixes suggested by rustc to crate `testafs` after fixes were automatically applied the compiler reported errors within these files: * src/lib.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[E0308]: mismatched types --> src/lib.rs:19:23 | 19 | if idx == index { | ^^^^^ expected `usize`, found `u32` | help: you can convert a `u32` to a `usize` and panic if the converted value doesn't fit | 19 | if idx == index.try_into().unwrap() { | ~~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error For more information about this error, try `rustc --explain E0308`. Original diagnostics will follow.
Meta
Rust version (rustc -Vv
):
rustc 1.56.0 (09c42c458 2021-10-18) binary: rustc commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa commit-date: 2021-10-18 host: x86_64-unknown-linux-gnu release: 1.56.0 LLVM version: 13.0.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing