[committed 21/88] gccrs: fixed compiler error message on wildcard pattern within expression
arthur.cohen@embecosm.com
arthur.cohen@embecosm.com
Wed Apr 5 14:03:05 GMT 2023
From: Abdul Rafey <abdulrafeyq@gmail.com>
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::null_denotation): Add proper error
when seeing wildcard var on right side of assignment.
gcc/testsuite/ChangeLog:
* rust/compile/issue-867.rs: New test.
Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
---
gcc/rust/parse/rust-parse-impl.h | 6 ++++++
gcc/testsuite/rust/compile/issue-867.rs | 8 ++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-867.rs
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index d71bafded63..af749ca9200 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -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
index 00000000000..8e120685c1a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-867.rs
@@ -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 }
+}
--
2.40.0
More information about the Gcc-rust
mailing list