Rust-clippy: False positive for_kv_map in a consuming loop

Created on 14 Oct 2016  路  5Comments  路  Source: rust-lang/rust-clippy

fn main() {
  let c: std::collections::HashMap<i32, String> = Default::default();
  for (_, b) in c {
    println!("{:?}", b);
  }
}

The lint suggests to use values() but AFAIK there is no consuming alternative to values(). (And if it exists, the message should mention it.)

Similar issue: #709.

L-bug

Most helpful comment

I'll raise a PR when I have a spare moment.

All 5 comments

Imo this is correct for copy types.

Imo this is correct for copy types.

indeed it may be. I've changed value type to String in the example, just to make it more clear.

The example in the OP works now without triggering a clippy attack. Seems like this has been fixed.

If it is fixed, it would be nice to add this example to tests/ui/for_kv_map.rs as well.

I'll raise a PR when I have a spare moment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevincox picture kevincox  路  17Comments

mikerite picture mikerite  路  17Comments

b1zzu picture b1zzu  路  28Comments

BenjaminGill-Metaswitch picture BenjaminGill-Metaswitch  路  22Comments

Manishearth picture Manishearth  路  20Comments