about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/uninhabited/missing-if-let-or-let-else.rs24
-rw-r--r--tests/ui/uninhabited/missing-if-let-or-let-else.stderr39
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/ui/uninhabited/missing-if-let-or-let-else.rs b/tests/ui/uninhabited/missing-if-let-or-let-else.rs
new file mode 100644
index 00000000000..51fedb79756
--- /dev/null
+++ b/tests/ui/uninhabited/missing-if-let-or-let-else.rs
@@ -0,0 +1,24 @@
+fn a() {
+    let Some(x) = foo() { //~ ERROR expected one of
+        //~^ HELP you might have meant to use `if let`
+        let y = x;
+    }
+}
+fn b() {
+    let Some(x) = foo() { //~ ERROR expected one of
+        //~^ HELP you might have meant to use `let else`
+        return;
+    }
+}
+fn c() {
+    let Some(x) = foo() { //~ ERROR expected one of
+        //~^ HELP you might have meant to use `if let`
+        //~| HELP alternatively, you might have meant to use `let else`
+        // The parser check happens pre-macro-expansion, so we don't know for sure.
+        println!("{x}");
+    }
+}
+fn foo() -> Option<i32> {
+    Some(42)
+}
+fn main() {}
diff --git a/tests/ui/uninhabited/missing-if-let-or-let-else.stderr b/tests/ui/uninhabited/missing-if-let-or-let-else.stderr
new file mode 100644
index 00000000000..4b78a0fa16e
--- /dev/null
+++ b/tests/ui/uninhabited/missing-if-let-or-let-else.stderr
@@ -0,0 +1,39 @@
+error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
+  --> $DIR/missing-if-let-or-let-else.rs:2:25
+   |
+LL |     let Some(x) = foo() {
+   |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator
+   |
+help: you might have meant to use `if let`
+   |
+LL |     if let Some(x) = foo() {
+   |     ++
+
+error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
+  --> $DIR/missing-if-let-or-let-else.rs:8:25
+   |
+LL |     let Some(x) = foo() {
+   |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator
+   |
+help: you might have meant to use `let else`
+   |
+LL |     let Some(x) = foo() else {
+   |                         ++++
+
+error: expected one of `.`, `;`, `?`, `else`, or an operator, found `{`
+  --> $DIR/missing-if-let-or-let-else.rs:14:25
+   |
+LL |     let Some(x) = foo() {
+   |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator
+   |
+help: you might have meant to use `if let`
+   |
+LL |     if let Some(x) = foo() {
+   |     ++
+help: alternatively, you might have meant to use `let else`
+   |
+LL |     let Some(x) = foo() else {
+   |                         ++++
+
+error: aborting due to 3 previous errors
+