rust/tests/ui/for-loop-while/foreach-external-iterators-hashmap.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
338 B
Rust
Raw Normal View History

//@ run-pass
use std::collections::HashMap;
pub fn main() {
let mut h = HashMap::new();
2015-01-25 21:05:03 +00:00
let kvs = [(1, 10), (2, 20), (3, 30)];
2015-01-31 17:20:46 +00:00
for &(k,v) in &kvs {
h.insert(k,v);
}
2015-01-25 21:05:03 +00:00
let mut x = 0;
let mut y = 0;
2015-01-31 17:20:46 +00:00
for (&k,&v) in &h {
x += k;
y += v;
}
assert_eq!(x, 6);
assert_eq!(y, 60);
}