-
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.
Auto merge of #115995 - matthiaskrgr:rollup-jukbrvq, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #115965 (Add more if let guard tests) - #115978 (Copy 1.72.1 release notes to master) - #115983 (fix confusing let chain indentation in rustc_resolve) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
13 changed files
with
310 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Ensure if let guards can be used in constant expressions. | ||
// build-pass | ||
|
||
#![feature(if_let_guard)] | ||
|
||
const fn match_if_let(x: Option<i32>, y: Option<i32>) -> i32 { | ||
match x { | ||
None if let Some(a @ 5) = y => a, | ||
Some(z) if let (Some(_), 12) = (y, z) => 2, | ||
_ => 3, | ||
} | ||
} | ||
|
||
const ASSERTS: usize = { | ||
assert!(match_if_let(None, Some(5)) == 5); | ||
assert!(match_if_let(Some(12), Some(3)) == 2); | ||
assert!(match_if_let(None, Some(4)) == 3); | ||
assert!(match_if_let(Some(11), Some(3)) == 3); | ||
assert!(match_if_let(Some(12), None) == 3); | ||
assert!(match_if_let(None, None) == 3); | ||
0 | ||
}; | ||
|
||
fn main() { | ||
let _: [(); ASSERTS]; | ||
} |
97 changes: 97 additions & 0 deletions
97
tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#![feature(if_let_guard)] | ||
#![feature(let_chains)] | ||
#![allow(irrefutable_let_patterns)] | ||
|
||
fn same_pattern(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if let y = x && c => (), | ||
(1, 2) if let z = x => (), //~ ERROR use of moved value: `x` | ||
_ => (), | ||
} | ||
} | ||
|
||
fn same_pattern_ok(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if c && let y = x => (), | ||
(1, 2) if let z = x => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn different_patterns(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, _) if let y = x && c => (), | ||
(_, 2) if let z = x => (), //~ ERROR use of moved value: `x` | ||
_ => (), | ||
} | ||
} | ||
|
||
fn different_patterns_ok(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, _) if c && let y = x => (), | ||
(_, 2) if let z = x => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn or_pattern(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, _) | (_, 2) if let y = x && c => (), //~ ERROR use of moved value: `x` | ||
_ => (), | ||
} | ||
} | ||
|
||
fn or_pattern_ok(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, _) | (_, 2) if c && let y = x => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn use_in_arm(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if let y = x && c => false, | ||
_ => { *x == 1 }, //~ ERROR use of moved value: `x` | ||
}; | ||
} | ||
|
||
fn use_in_arm_ok(c: bool) { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if c && let y = x => false, | ||
_ => { *x == 1 }, | ||
}; | ||
} | ||
|
||
fn main() {} |
67 changes: 67 additions & 0 deletions
67
tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
error[E0382]: use of moved value: `x` | ||
--> $DIR/move-guard-if-let-chain.rs:12:27 | ||
| | ||
LL | let x: Box<_> = Box::new(1); | ||
| - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait | ||
... | ||
LL | (1, 2) if let y = x && c => (), | ||
| - value moved here | ||
LL | (1, 2) if let z = x => (), | ||
| ^ value used here after move | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | (1, 2) if let ref y = x && c => (), | ||
| +++ | ||
|
||
error[E0382]: use of moved value: `x` | ||
--> $DIR/move-guard-if-let-chain.rs:36:27 | ||
| | ||
LL | let x: Box<_> = Box::new(1); | ||
| - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait | ||
... | ||
LL | (1, _) if let y = x && c => (), | ||
| - value moved here | ||
LL | (_, 2) if let z = x => (), | ||
| ^ value used here after move | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | (1, _) if let ref y = x && c => (), | ||
| +++ | ||
|
||
error[E0382]: use of moved value: `x` | ||
--> $DIR/move-guard-if-let-chain.rs:59:36 | ||
| | ||
LL | let x: Box<_> = Box::new(1); | ||
| - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait | ||
... | ||
LL | (1, _) | (_, 2) if let y = x && c => (), | ||
| - ^ value used here after move | ||
| | | ||
| value moved here | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | (1, _) | (_, 2) if let ref y = x && c => (), | ||
| +++ | ||
|
||
error[E0382]: use of moved value: `x` | ||
--> $DIR/move-guard-if-let-chain.rs:82:16 | ||
| | ||
LL | let x: Box<_> = Box::new(1); | ||
| - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait | ||
... | ||
LL | (1, 2) if let y = x && c => false, | ||
| - value moved here | ||
LL | _ => { *x == 1 }, | ||
| ^^ value used here after move | ||
| | ||
help: borrow this binding in the pattern to avoid moving the value | ||
| | ||
LL | (1, 2) if let ref y = x && c => false, | ||
| +++ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0382`. |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Check that borrowck knows that moves in the pattern for if-let guards | ||
// only happen when the pattern is matched. | ||
|
||
// build-pass | ||
|
||
#![feature(if_let_guard)] | ||
#![allow(irrefutable_let_patterns)] | ||
|
||
fn same_pattern() { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if let y = x => (), | ||
(1, 2) if let z = x => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn or_pattern() { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, _) | (_, 2) if let y = x => (), | ||
_ => (), | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: Box<_> = Box::new(1); | ||
|
||
let v = (1, 2); | ||
|
||
match v { | ||
(1, 2) if let y = x => false, | ||
_ => { *x == 1 }, | ||
}; | ||
} |
Oops, something went wrong.