Skip to content

Commit 760f529

Browse files
00ARCohenArthur
authored andcommitted
gccrs: fixed compiler error message on wildcard pattern within expression
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>
1 parent d6cb04b commit 760f529

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

gcc/rust/parse/rust-parse-impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13021,6 +13021,12 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
1302113021
case UNSAFE:
1302213022
return parse_unsafe_block_expr (std::move (outer_attrs),
1302313023
tok->get_locus ());
13024+
case UNDERSCORE:
13025+
add_error (
13026+
Error (tok->get_locus (),
13027+
"use of %qs is not allowed on the right-side of an assignment",
13028+
tok->get_token_description ()));
13029+
return nullptr;
1302413030
default:
1302513031
if (!restrictions.expr_can_be_null)
1302613032
add_error (Error (tok->get_locus (),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {
2+
let _ = 42;
3+
let a = _ + 123; // { dg-error "use of '_' is not allowed on the right-side of an assignment" }
4+
// { dg-error {failed to parse expression in let statement} "" { target *-*-* } .-1 }
5+
// { dg-error {failed to parse statement or expression without block in block expression} "" { target *-*-* } .-2 }
6+
// { dg-error {unrecognised token '\}' for start of item} "" { target *-*-* } .+2 }
7+
// { dg-error {failed to parse item in crate} "" { target *-*-* } .+1 }
8+
}

0 commit comments

Comments
 (0)