Skip to content

Commit c886490

Browse files
committed
add guard_patterns unstable feature, without unstable book chapter or tracking issue for now
1 parent 16422db commit c886490

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
@@ -501,6 +501,8 @@ declare_features! (
501501
(incomplete, generic_const_items, "1.73.0", Some(113521)),
502502
/// Allows registering static items globally, possibly across crates, to iterate over at runtime.
503503
(unstable, global_registration, "1.80.0", Some(125119)),
504+
/// Allows using guards in patterns.
505+
(unstable, guard_patterns, "CURRENT_RUSTC_VERSION", None),
504506
/// Allows using `..=X` as a patterns in slices.
505507
(unstable, half_open_range_patterns_in_slices, "1.66.0", Some(67264)),
506508
/// 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
@@ -984,6 +984,7 @@ symbols! {
984984
global_registration,
985985
globs,
986986
gt,
987+
guard_patterns,
987988
half_open_range_patterns,
988989
half_open_range_patterns_in_slices,
989990
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)