-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
2229: Fix issues with move closures and mutability #80092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b421cd5
3488082
1373f98
0897db5
604cbdc
c748f32
ffd5327
fadf03e
0f4bab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ fn main() { | |
| let mut c = || { | ||
| //~^ ERROR: cannot borrow `z.0.0.0` as mutable, as it is behind a `&` reference | ||
| z.0.0.0 = format!("X1"); | ||
|
||
| //~^ ERROR: cannot assign to `z`, as it is not declared as mutable | ||
| }; | ||
|
|
||
| c(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #![feature(capture_disjoint_fields)] | ||
| //~^ WARNING: the feature `capture_disjoint_fields` is incomplete | ||
|
|
||
| // Ensure that diagnostics for mutability error (because the root variable | ||
| // isn't mutable) work with `capture_disjoint_fields` enabled. | ||
|
|
||
| fn mut_error_struct() { | ||
| let x = (10, 10); | ||
| let y = (x, 10); | ||
| let z = (y, 10); | ||
|
|
||
| let mut c = || { | ||
arora-aman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| z.0.0.0 = 20; | ||
| //~^ ERROR: cannot assign to `z`, as it is not declared as mutable | ||
| }; | ||
|
|
||
| c(); | ||
| } | ||
|
|
||
| fn mut_error_box() { | ||
| let x = (10, 10); | ||
| let bx = Box::new(x); | ||
|
|
||
| let mut c = || { | ||
| bx.0 = 20; | ||
| //~^ ERROR: cannot assign to `bx`, as it is not declared as mutable | ||
| }; | ||
|
|
||
| c(); | ||
| } | ||
|
|
||
| fn main() { | ||
| mut_error_struct(); | ||
| mut_error_box(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes | ||
| --> $DIR/cant-mutate-imm.rs:1:12 | ||
| | | ||
| LL | #![feature(capture_disjoint_fields)] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: `#[warn(incomplete_features)]` on by default | ||
| = note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information | ||
|
|
||
| error[E0594]: cannot assign to `z`, as it is not declared as mutable | ||
| --> $DIR/cant-mutate-imm.rs:13:9 | ||
| | | ||
| LL | let z = (y, 10); | ||
| | - help: consider changing this to be mutable: `mut z` | ||
| ... | ||
| LL | z.0.0.0 = 20; | ||
| | ^^^^^^^^^^^^ cannot assign | ||
|
|
||
| error[E0594]: cannot assign to `bx`, as it is not declared as mutable | ||
| --> $DIR/cant-mutate-imm.rs:25:9 | ||
| | | ||
| LL | let bx = Box::new(x); | ||
| | -- help: consider changing this to be mutable: `mut bx` | ||
| ... | ||
| LL | bx.0 = 20; | ||
| | ^^^^^^^^^ cannot assign | ||
|
|
||
| error: aborting due to 2 previous errors; 1 warning emitted | ||
|
|
||
| For more information about this error, try `rustc --explain E0594`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a comment here, something like
/// Returns the hir-id of the root variable for the captured place. e.g., if
a.b.cwas captured, would return the hir-id fora.