]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fixed compiler error message on wildcard pattern within expression
authorAbdul Rafey <abdulrafeyq@gmail.com>
Sun, 29 Jan 2023 11:35:23 +0000 (17:05 +0530)
committerAbdul Rafey <abdulrafeyq@gmail.com>
Mon, 30 Jan 2023 10:45:50 +0000 (16:15 +0530)
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/issue-867.rs [new file with mode: 0644]

index c19fe9b6ec4f6ef3788c521a4ccf18b7fcf339b7..17ca6bb49d7b1c72dc69bf039730e31cb7be5209 100644 (file)
@@ -13021,6 +13021,12 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
     case UNSAFE:
       return parse_unsafe_block_expr (std::move (outer_attrs),
                                      tok->get_locus ());
+    case UNDERSCORE:
+      add_error (
+       Error (tok->get_locus (),
+              "use of %qs is not allowed on the right-side of an assignment",
+              tok->get_token_description ()));
+      return nullptr;
     default:
       if (!restrictions.expr_can_be_null)
        add_error (Error (tok->get_locus (),
diff --git a/gcc/testsuite/rust/compile/issue-867.rs b/gcc/testsuite/rust/compile/issue-867.rs
new file mode 100644 (file)
index 0000000..8e12068
--- /dev/null
@@ -0,0 +1,8 @@
+fn main() {
+    let _ = 42;
+    let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" }
+                     // { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1  }
+                     // { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 }
+                     // { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+2 }
+                     // { dg-error {failed to parse item in crate} "" { target *-*-* } .+1 }
+}