Skip to content

Commit 4573c92

Browse files
committed
add guard_patterns unstable feature, without unstable book chapter or tracking issue for now
1 parent 5ad98b4 commit 4573c92

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
@@ -488,6 +488,8 @@ declare_features! (
488488
(incomplete, generic_const_items, "1.73.0", Some(113521)),
489489
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
490490
(unstable, global_registration, "1.80.0", Some(125119)),
491+
/// Allows using guards in patterns.
492+
(unstable, guard_patterns, "CURRENT_RUSTC_VERSION", None),
491493
/// Allows using `..=X` as a patterns in slices.
492494
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
493495
/// 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
@@ -961,6 +961,7 @@ symbols! {
961961
global_registration,
962962
globs,
963963
gt,
964+
guard_patterns,
964965
half_open_range_patterns,
965966
half_open_range_patterns_in_slices,
966967
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)