-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-inferenceArea: Type inferenceArea: Type inference
Description
fn foo(_: &mut String) {}
fn bug1() {
let _ = |a: &mut String| for _ in 0..0 {
foo(a)
}; //works fine
let _ = |a| for _ in 0..0 {
foo(a)
}; //fails
}
fn bug2() {
let mut a = String::new();
let mut b = String::new();
let f = |a: &mut String| foo(a);
let g = |b| foo(b);
f(&mut a); //works
f(&mut a); //works
g(&mut b); //works
g(&mut b); //fails
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0382]: use of moved value: `a`
--> src/lib.rs:8:13
|
7 | let _ = |a| for _ in 0..0 {
| - move occurs because `a` has type `&mut std::string::String`, which does not implement the `Copy` trait
8 | foo(a)
| ^ value moved here, in previous iteration of loop
error[E0499]: cannot borrow `b` as mutable more than once at a time
--> src/lib.rs:20:7
|
19 | g(&mut b); //works
| ------ first mutable borrow occurs here
20 | g(&mut b); //fails
| - ^^^^^^ second mutable borrow occurs here
| |
| first borrow later used by call
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0382, E0499.
For more information about an error, try `rustc --explain E0382`.
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
hellow554, tomprogrammer and aliemjay
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-inferenceArea: Type inferenceArea: Type inference