Skip to content

Commit

Permalink
allow irrefutable let patterns in feature gate test
Browse files Browse the repository at this point in the history
  • Loading branch information
max-niederman committed Jan 1, 2025
1 parent 087b872 commit c3132e7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
4 changes: 2 additions & 2 deletions tests/ui/feature-gates/feature-gate-guard-patterns.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(irrefutable_let_patterns)]

fn match_guards_still_work() {
match 0 {
0 if guard(0) => {},
Expand All @@ -24,11 +26,9 @@ fn other_guards_dont() {

if let (x if guard(x)) = 0 {}
//~^ ERROR: guard patterns are experimental
//~| WARN: irrefutable

while let (x if guard(x)) = 0 {}
//~^ ERROR: guard patterns are experimental
//~| WARN: irrefutable

#[cfg(FALSE)]
while let (x if guard(x)) = 0 {}
Expand Down
35 changes: 8 additions & 27 deletions tests/ui/feature-gates/feature-gate-guard-patterns.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: unexpected parentheses surrounding `match` arm pattern
--> $DIR/feature-gate-guard-patterns.rs:10:9
--> $DIR/feature-gate-guard-patterns.rs:12:9
|
LL | (0 if guard(0)) => {},
| ^ ^
Expand All @@ -11,7 +11,7 @@ LL + 0 if guard(0) => {},
|

error[E0425]: cannot find value `x` in this scope
--> $DIR/feature-gate-guard-patterns.rs:21:22
--> $DIR/feature-gate-guard-patterns.rs:23:22
|
LL | let ((x if guard(x)) | x) = 0;
| ^ not found in this scope
Expand All @@ -23,13 +23,13 @@ LL | fn even_as_function_parameters(((x if guard(x), _) | (_, x)): (i32, i32)) {
| ^
|
help: the binding `x` is available in a different scope in the same function
--> $DIR/feature-gate-guard-patterns.rs:21:11
--> $DIR/feature-gate-guard-patterns.rs:23:11
|
LL | let ((x if guard(x)) | x) = 0;
| ^

error[E0658]: guard patterns are experimental
--> $DIR/feature-gate-guard-patterns.rs:16:15
--> $DIR/feature-gate-guard-patterns.rs:18:15
|
LL | (0 if guard(0)) | 1 => {},
| ^^^^^^^^
Expand All @@ -40,7 +40,7 @@ LL | (0 if guard(0)) | 1 => {},
= help: consider using match arm guards

error[E0658]: guard patterns are experimental
--> $DIR/feature-gate-guard-patterns.rs:21:16
--> $DIR/feature-gate-guard-patterns.rs:23:16
|
LL | let ((x if guard(x)) | x) = 0;
| ^^^^^^^^
Expand All @@ -51,7 +51,7 @@ LL | let ((x if guard(x)) | x) = 0;
= help: consider using match arm guards

error[E0658]: guard patterns are experimental
--> $DIR/feature-gate-guard-patterns.rs:25:18
--> $DIR/feature-gate-guard-patterns.rs:27:18
|
LL | if let (x if guard(x)) = 0 {}
| ^^^^^^^^
Expand All @@ -62,7 +62,7 @@ LL | if let (x if guard(x)) = 0 {}
= help: consider using match arm guards

error[E0658]: guard patterns are experimental
--> $DIR/feature-gate-guard-patterns.rs:29:21
--> $DIR/feature-gate-guard-patterns.rs:30:21
|
LL | while let (x if guard(x)) = 0 {}
| ^^^^^^^^
Expand Down Expand Up @@ -94,26 +94,7 @@ LL | fn even_as_function_parameters(((x if guard(x), _) | (_, x)): (i32, i32)) {
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= help: consider using match arm guards

warning: irrefutable `if let` pattern
--> $DIR/feature-gate-guard-patterns.rs:25:8
|
LL | if let (x if guard(x)) = 0 {}
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
= note: `#[warn(irrefutable_let_patterns)]` on by default

warning: irrefutable `while let` pattern
--> $DIR/feature-gate-guard-patterns.rs:29:11
|
LL | while let (x if guard(x)) = 0 {}
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this pattern will always match, so the loop will never exit
= help: consider instead using a `loop { ... }` with a `let` inside it

error: aborting due to 9 previous errors; 2 warnings emitted
error: aborting due to 9 previous errors

Some errors have detailed explanations: E0425, E0658.
For more information about an error, try `rustc --explain E0425`.

0 comments on commit c3132e7

Please sign in to comment.