Rollup merge of #81158 - 1000teslas:issue-80313-fix, r=Aaron1011

Point to span of upvar making closure FnMut

For #80313.
This commit is contained in:
Yuki Okushi 2021-01-29 09:17:31 +09:00 committed by GitHub
commit 4283623bc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 152 additions and 4 deletions

View file

@ -20,7 +20,9 @@ error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
|
LL | let f = || {
| - help: consider changing this to be mutable: `mut f`
...
LL | let y = &raw mut x;
| - calling `f` requires mutable binding due to mutable borrow of `x`
LL | };
LL | f();
| ^ cannot borrow as mutable

View file

@ -0,0 +1,7 @@
fn main() {
let mut my_var = false;
let callback = || {
&mut my_var;
};
callback(); //~ ERROR E0596
}

View file

@ -0,0 +1,14 @@
error[E0596]: cannot borrow `callback` as mutable, as it is not declared as mutable
--> $DIR/issue-80313-mutable-borrow-in-closure.rs:6:5
|
LL | let callback = || {
| -------- help: consider changing this to be mutable: `mut callback`
LL | &mut my_var;
| ------ calling `callback` requires mutable binding due to mutable borrow of `my_var`
LL | };
LL | callback();
| ^^^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View file

@ -0,0 +1,7 @@
fn main() {
let mut my_var = false;
let callback = move || {
&mut my_var;
};
callback(); //~ ERROR E0596
}

View file

@ -0,0 +1,14 @@
error[E0596]: cannot borrow `callback` as mutable, as it is not declared as mutable
--> $DIR/issue-80313-mutable-borrow-in-move-closure.rs:6:5
|
LL | let callback = move || {
| -------- help: consider changing this to be mutable: `mut callback`
LL | &mut my_var;
| ------ calling `callback` requires mutable binding due to possible mutation of `my_var`
LL | };
LL | callback();
| ^^^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View file

@ -0,0 +1,7 @@
fn main() {
let mut my_var = false;
let callback = || {
my_var = true;
};
callback(); //~ ERROR E0596
}

View file

@ -0,0 +1,14 @@
error[E0596]: cannot borrow `callback` as mutable, as it is not declared as mutable
--> $DIR/issue-80313-mutation-in-closure.rs:6:5
|
LL | let callback = || {
| -------- help: consider changing this to be mutable: `mut callback`
LL | my_var = true;
| ------ calling `callback` requires mutable binding due to mutable borrow of `my_var`
LL | };
LL | callback();
| ^^^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View file

@ -0,0 +1,7 @@
fn main() {
let mut my_var = false;
let callback = move || {
my_var = true;
};
callback(); //~ ERROR E0596
}

View file

@ -0,0 +1,14 @@
error[E0596]: cannot borrow `callback` as mutable, as it is not declared as mutable
--> $DIR/issue-80313-mutation-in-move-closure.rs:6:5
|
LL | let callback = move || {
| -------- help: consider changing this to be mutable: `mut callback`
LL | my_var = true;
| ------ calling `callback` requires mutable binding due to possible mutation of `my_var`
LL | };
LL | callback();
| ^^^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View file

@ -3,6 +3,8 @@ error[E0596]: cannot borrow `tick1` as mutable, as it is not declared as mutable
|
LL | let tick1 = || {
| ----- help: consider changing this to be mutable: `mut tick1`
LL | counter += 1;
| ------- calling `tick1` requires mutable binding due to mutable borrow of `counter`
...
LL | tick1();
| ^^^^^ cannot borrow as mutable
@ -12,6 +14,8 @@ error[E0596]: cannot borrow `tick2` as mutable, as it is not declared as mutable
|
LL | let tick2 = || {
| ----- help: consider changing this to be mutable: `mut tick2`
LL | tick1();
| ----- calling `tick2` requires mutable binding due to mutable borrow of `tick1`
...
LL | tick2();
| ^^^^^ cannot borrow as mutable

View file

@ -2,7 +2,9 @@ error[E0596]: cannot borrow `tick` as mutable, as it is not declared as mutable
--> $DIR/unboxed-closures-infer-fnmut-missing-mut.rs:7:5
|
LL | let tick = || counter += 1;
| ---- help: consider changing this to be mutable: `mut tick`
| ---- ------- calling `tick` requires mutable binding due to mutable borrow of `counter`
| |
| help: consider changing this to be mutable: `mut tick`
LL | tick();
| ^^^^ cannot borrow as mutable

View file

@ -2,7 +2,9 @@ error[E0596]: cannot borrow `tick` as mutable, as it is not declared as mutable
--> $DIR/unboxed-closures-infer-fnmut-move-missing-mut.rs:7:5
|
LL | let tick = move || counter += 1;
| ---- help: consider changing this to be mutable: `mut tick`
| ---- ------- calling `tick` requires mutable binding due to possible mutation of `counter`
| |
| help: consider changing this to be mutable: `mut tick`
LL | tick();
| ^^^^ cannot borrow as mutable