forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#106005 - LeSeulArtichaut:if-let-guard-borro…
…wck-test, r=Nilstrieb Test the borrowck behavior of if-let guards Add some tests to make sure that if-let guards behave the same as if guards with respect to borrow-checking. Most of them are a naive adaptation, replacing an `if` guard with `if let Some(())`. This includes regression tests for notable issues that arose for if guards (rust-lang#24535, rust-lang#27282, rust-lang#29723, rust-lang#31287) as suggested in rust-lang#51114 (comment). cc `@pnkfelix` are there any other tests that you would want to see? cc tracking issue rust-lang#51114
- Loading branch information
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.