Skip to content

Commit ca8b7cc

Browse files
committed
add guard_patterns unstable feature, without unstable book chapter or tracking issue for now
1 parent 1d68e6d commit ca8b7cc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ declare_features! (
485485
(incomplete, generic_const_items, "1.73.0", Some(113521)),
486486
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
487487
(unstable, global_registration, "1.80.0", Some(125119)),
488+
/// Allows using guards in patterns.
489+
(unstable, guard_patterns, "CURRENT_RUSTC_VERSION", None),
488490
/// Allows using `..=X` as a patterns in slices.
489491
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
490492
/// Allows `if let` guard in match arms.

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ symbols! {
979979
global_registration,
980980
globs,
981981
gt,
982+
guard_patterns,
982983
half_open_range_patterns,
983984
half_open_range_patterns_in_slices,
984985
hash,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
fn match_guards_still_work() {
2+
match 0 {
3+
0 if guard(0) => {},
4+
_ => {},
5+
}
6+
}
7+
8+
fn other_guards_dont() {
9+
match 0 {
10+
(0 if guard(0)) | 1 => {},
11+
//~^ ERROR: guard patterns are unstable
12+
_ => {},
13+
}
14+
15+
let ((x if guard(x)) | x) = 0;
16+
//~^ ERROR: guard patterns are unstable
17+
18+
if let (x if guard(x)) = 0 {}
19+
//~^ ERROR: guard patterns are unstable
20+
while let (x if guard(x)) = 0 {}
21+
//~^ ERROR: guard patterns are unstable
22+
}
23+
24+
fn even_as_function_parameters(((x if guard(x), _) | (_, x)): (i32, i32)) {}
25+
//~^ ERROR: guard patterns are unstable
26+
27+
fn guard<T>(x: T) -> bool {
28+
unimplemented!()
29+
}

0 commit comments

Comments
 (0)