-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the borrowck behavior of if-let guards
- Loading branch information
1 parent
1d12c3c
commit 56aaf74
Showing
27 changed files
with
645 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
error[E0510]: cannot assign `x` in match guard | ||
--> $DIR/borrowck-mutate-in-guard.rs:10:25 | ||
--> $DIR/borrowck-mutate-in-guard.rs:12:25 | ||
| | ||
LL | match x { | ||
| - value is immutable in match guard | ||
LL | Enum::A(_) if { x = Enum::B(false); false } => 1, | ||
| ^^^^^^^^^^^^^^^^^^ cannot assign | ||
|
||
error[E0510]: cannot mutably borrow `x` in match guard | ||
--> $DIR/borrowck-mutate-in-guard.rs:12:33 | ||
--> $DIR/borrowck-mutate-in-guard.rs:14:33 | ||
| | ||
LL | match x { | ||
| - value is immutable in match guard | ||
... | ||
LL | Enum::A(_) if { let y = &mut x; *y = Enum::B(false); false } => 1, | ||
| ^^^^^^ cannot mutably borrow | ||
|
||
error: aborting due to 2 previous errors | ||
error[E0510]: cannot assign `x` in match guard | ||
--> $DIR/borrowck-mutate-in-guard.rs:25:40 | ||
| | ||
LL | match x { | ||
| - value is immutable in match guard | ||
LL | Enum::A(_) if let Some(()) = { x = Enum::B(false); None } => 1, | ||
| ^^^^^^^^^^^^^^^^^^ cannot assign | ||
|
||
error[E0510]: cannot mutably borrow `x` in match guard | ||
--> $DIR/borrowck-mutate-in-guard.rs:27:48 | ||
| | ||
LL | match x { | ||
| - value is immutable in match guard | ||
... | ||
LL | Enum::A(_) if let Some(()) = { let y = &mut x; *y = Enum::B(false); None } => 1, | ||
| ^^^^^^ cannot mutably borrow | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0510`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
#![feature(if_let_guard)] | ||
|
||
fn main() { | ||
let a = Some("...".to_owned()); | ||
let b = match a { | ||
Some(_) if { drop(a); false } => None, | ||
x => x, //~ ERROR use of moved value: `a` | ||
}; | ||
println!("{:?}", b); | ||
|
||
let a = Some("...".to_owned()); | ||
let b = match a { | ||
Some(_) if let Some(()) = { drop(a); None } => None, | ||
x => x, //~ ERROR use of moved value: `a` | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.