Skip to content

Commit 90c9b57

Browse files
committed
Add test
1 parent d3c4dbd commit 90c9b57

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::collections::HashMap;
2+
struct X(usize);
3+
struct Y {
4+
v: u32
5+
}
6+
7+
fn main() {
8+
let mut buzz = HashMap::new();
9+
buzz.insert("a", Y { v: 0 });
10+
11+
for mut t in buzz.values() {
12+
//~^ HELP
13+
//~| SUGGESTION values_mut()
14+
t.v += 1;
15+
//~^ ERROR cannot assign
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0594]: cannot assign to `t.v` which is behind a `&` reference
2+
--> $DIR/suggest-mut-method-for-loop.rs:14:9
3+
|
4+
LL | for mut t in buzz.values() {
5+
| -------------
6+
| | |
7+
| | help: use mutable method: `values_mut()`
8+
| this iterator yields `&` references
9+
...
10+
LL | t.v += 1;
11+
| ^^^^^^^^ `t` is a `&` reference, so the data it refers to cannot be written
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0594`.

0 commit comments

Comments
 (0)