diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6cb8f0e6579..c8d7c6c6d19 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9642,15 +9642,23 @@ Parser::parse_bare_function_type ( if (!skip_token (FN_KW)) return nullptr; - if (!skip_token (LEFT_PAREN)) - return nullptr; + auto t = lexer.peek_token (); + if (t->get_id () != LEFT_PAREN) + { + Error error (t->get_locus (), + "unexpected token %qs - expected bare function", + t->get_token_description ()); + add_error (std::move (error)); + + return nullptr; + } // parse function params, if they exist std::vector params; bool is_variadic = false; AST::AttrVec variadic_attrs; - const_TokenPtr t = lexer.peek_token (); + t = lexer.peek_token (); while (t->get_id () != RIGHT_PAREN) { AST::AttrVec temp_attrs = parse_outer_attributes (); diff --git a/gcc/testsuite/rust/compile/invalid_impl_for.rs b/gcc/testsuite/rust/compile/invalid_impl_for.rs new file mode 100644 index 00000000000..069c5356f6e --- /dev/null +++ b/gcc/testsuite/rust/compile/invalid_impl_for.rs @@ -0,0 +1,4 @@ +impl Foo for +fn main() {// { dg-error "unexpected token .* - expected bare function" } +// { dg-error "could not parse type in trait impl" "" { target *-*-* } .-1 } +} \ No newline at end of file