summaryrefslogtreecommitdiffstats
path: root/src/test/ui/rfc-2497-if-let-chains
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr52
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs2
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr26
-rw-r--r--src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs15
4 files changed, 43 insertions, 52 deletions
diff --git a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
index fce0cdfe0..91c001151 100644
--- a/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
+++ b/src/test/ui/rfc-2497-if-let-chains/disallowed-positions.stderr
@@ -1493,17 +1493,11 @@ LL | if (let 0 = 0)? {}
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> $DIR/disallowed-positions.rs:132:19
|
-LL | / fn nested_within_if_expr() {
-LL | | if &let 0 = 0 {}
-LL | |
-LL | |
-... |
-LL | | if (let 0 = 0)? {}
- | | ^ cannot use the `?` operator in a function that returns `()`
-... |
-LL | |
-LL | | }
- | |_- this function should return `Result` or `Option` to accept `?`
+LL | fn nested_within_if_expr() {
+ | -------------------------- this function should return `Result` or `Option` to accept `?`
+...
+LL | if (let 0 = 0)? {}
+ | ^ cannot use the `?` operator in a function that returns `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
@@ -1516,7 +1510,7 @@ LL | if x = let 0 = 0 {}
help: you might have meant to compare for equality
|
LL | if x == let 0 = 0 {}
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:157:8
@@ -1693,17 +1687,11 @@ LL | while (let 0 = 0)? {}
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> $DIR/disallowed-positions.rs:224:22
|
-LL | / fn nested_within_while_expr() {
-LL | | while &let 0 = 0 {}
-LL | |
-LL | |
-... |
-LL | | while (let 0 = 0)? {}
- | | ^ cannot use the `?` operator in a function that returns `()`
-... |
-LL | |
-LL | | }
- | |_- this function should return `Result` or `Option` to accept `?`
+LL | fn nested_within_while_expr() {
+ | ----------------------------- this function should return `Result` or `Option` to accept `?`
+...
+LL | while (let 0 = 0)? {}
+ | ^ cannot use the `?` operator in a function that returns `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
@@ -1716,7 +1704,7 @@ LL | while x = let 0 = 0 {}
help: you might have meant to compare for equality
|
LL | while x == let 0 = 0 {}
- | ~~
+ | +
error[E0308]: mismatched types
--> $DIR/disallowed-positions.rs:249:11
@@ -1881,17 +1869,11 @@ LL | (let 0 = 0)?;
error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`)
--> $DIR/disallowed-positions.rs:325:16
|
-LL | / fn outside_if_and_while_expr() {
-LL | | &let 0 = 0;
-LL | |
-LL | |
-... |
-LL | | (let 0 = 0)?;
- | | ^ cannot use the `?` operator in a function that returns `()`
-... |
-LL | |
-LL | | }
- | |_- this function should return `Result` or `Option` to accept `?`
+LL | fn outside_if_and_while_expr() {
+ | ------------------------------ this function should return `Result` or `Option` to accept `?`
+...
+LL | (let 0 = 0)?;
+ | ^ cannot use the `?` operator in a function that returns `()`
|
= help: the trait `FromResidual<_>` is not implemented for `()`
diff --git a/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs b/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs
index 12befc637..2a6c14435 100644
--- a/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs
+++ b/src/test/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.rs
@@ -1,4 +1,4 @@
-#![feature(let_chains, let_else)]
+#![feature(let_chains)]
fn main() {
let opt = Some(1i32);
diff --git a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
index d1d5288ae..be4a52315 100644
--- a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
+++ b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.disallowed.stderr
@@ -4,13 +4,13 @@ error: leading irrefutable pattern in let chain
LL | if let first = &opt && let Some(ref second) = first && let None = second.start {}
| ^^^^^^^^^^^^^^^^
|
+ = note: this pattern will always match
+ = help: consider moving it outside of the construct
note: the lint level is defined here
--> $DIR/irrefutable-lets.rs:6:30
|
LL | #![cfg_attr(disallowed, deny(irrefutable_let_patterns))]
| ^^^^^^^^^^^^^^^^^^^^^^^^
- = note: this pattern will always match
- = help: consider moving it outside of the construct
error: irrefutable `if let` patterns
--> $DIR/irrefutable-lets.rs:19:8
@@ -75,26 +75,26 @@ LL | if let first = &opt && let None = Some(1) {}
= note: this pattern will always match
= help: consider moving it outside of the construct
-error: irrefutable `let` patterns
+error: irrefutable `if let` guard patterns
--> $DIR/irrefutable-lets.rs:44:28
|
LL | Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: these patterns will always match, so the `let` is useless
- = help: consider removing `let`
+ = note: these patterns will always match, so the guard is useless
+ = help: consider removing the guard and adding a `let` inside the match arm
-error: leading irrefutable pattern in let chain
- --> $DIR/irrefutable-lets.rs:50:28
+error: trailing irrefutable patterns in let chain
+ --> $DIR/irrefutable-lets.rs:59:16
|
-LL | Some(ref first) if let Range { start: local_start, end: _ } = first
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | && let v = local_end && let w = v => {},
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
- = note: this pattern will always match
- = help: consider moving it outside of the construct
+ = note: these patterns will always match
+ = help: consider moving them into the body
error: irrefutable `while let` patterns
- --> $DIR/irrefutable-lets.rs:59:11
+ --> $DIR/irrefutable-lets.rs:68:11
|
LL | while let first = &opt && let (a, b) = (1, 2) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -103,7 +103,7 @@ LL | while let first = &opt && let (a, b) = (1, 2) {}
= help: consider instead using a `loop { ... }` with a `let` inside it
error: trailing irrefutable patterns in let chain
- --> $DIR/irrefutable-lets.rs:62:40
+ --> $DIR/irrefutable-lets.rs:71:40
|
LL | while let Some(ref first) = opt && let second = first && let _third = second {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
index 3d1626e8f..9afb6853b 100644
--- a/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
+++ b/src/test/ui/rfc-2497-if-let-chains/irrefutable-lets.rs
@@ -42,18 +42,27 @@ fn main() {
match opt {
Some(ref first) if let second = first && let _third = second && let v = 4 + 4 => {},
- //[disallowed]~^ ERROR irrefutable `let` patterns
+ //[disallowed]~^ ERROR irrefutable `if let` guard patterns
_ => {}
}
+ // No error about leading irrefutable patterns: the expr on the rhs might
+ // use the bindings created by the match.
match opt {
Some(ref first) if let Range { start: local_start, end: _ } = first
- //[disallowed]~^ ERROR leading irrefutable pattern in let chain
&& let None = local_start => {},
_ => {}
}
- // No error, despite the prefix being irrefutable
+ match opt {
+ Some(ref first) if let Range { start: Some(_), end: local_end } = first
+ && let v = local_end && let w = v => {},
+ //[disallowed]~^ ERROR trailing irrefutable patterns in let chain
+ _ => {}
+ }
+
+ // No error, despite the prefix being irrefutable: moving out could change the behaviour,
+ // due to possible side effects of the operation.
while let first = &opt && let Some(ref second) = first && let None = second.start {}
while let first = &opt && let (a, b) = (1, 2) {}