From ce445bab795890f0d1d3b9fe77e1ff3f581e70d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAcio=20Boari=20Fleury?= Date: Fri, 28 Nov 2025 08:57:33 -0300 Subject: [PATCH 1/5] Handle IDENTIFIER at parse_bare_function_type( MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/rust/ChangeLog: * parse/rust-parse-impl.h: new error Signed-off-by: Lúcio Boari Fleury --- gcc/rust/parse/rust-parse-impl.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6cb8f0e6579..b2eeae1cf16 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9642,6 +9642,17 @@ Parser::parse_bare_function_type ( if (!skip_token (FN_KW)) return nullptr; + auto t = lexer.peek_token (); + if (t->get_id () == IDENTIFIER) + { + Error error (t->get_locus (), + "unexpected token %qs - expected bare function", + t->get_token_description ()); + add_error (std::move (error)); + + return nullptr; + } + if (!skip_token (LEFT_PAREN)) return nullptr; @@ -9650,7 +9661,7 @@ Parser::parse_bare_function_type ( 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 (); From ab1dec9f05b0f0cf4df711aac9182096d515b2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAcio=20Boari=20Fleury?= Date: Fri, 28 Nov 2025 10:12:53 -0300 Subject: [PATCH 2/5] Previously this test emmited expected '(' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/testsuite/ChangeLog: * rust/compile/invalid_impl_for.rs: triggers check for identifier Signed-off-by: Lúcio Boari Fleury --- gcc/testsuite/rust/compile/invalid_impl_for.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/invalid_impl_for.rs 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..6b7ad7edd2c --- /dev/null +++ b/gcc/testsuite/rust/compile/invalid_impl_for.rs @@ -0,0 +1,4 @@ +impl Foo for +fn main() {// { dg-error "unexpected token .identifier. - expected bare function" } +// { dg-error "could not parse type in trait impl" "" { target *-*-* } .-1 } +} \ No newline at end of file From f658684ece44e573318c4ed5b264580b91cea8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAcio=20Boari=20Fleury?= Date: Fri, 28 Nov 2025 16:35:31 -0300 Subject: [PATCH 3/5] Catch tokens different from IDENTIFIER MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/rust/ChangeLog: * parse/rust-parse-impl.h: (parse_bare_function_type) broadens check gcc/testsuite/ChangeLog: * rust/compile/invalid_impl_for.rs: broadens regex Signed-off-by: Lúcio Boari Fleury --- gcc/rust/parse/rust-parse-impl.h | 2 +- gcc/testsuite/rust/compile/invalid_impl_for.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index b2eeae1cf16..97ff71fa6f1 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9643,7 +9643,7 @@ Parser::parse_bare_function_type ( return nullptr; auto t = lexer.peek_token (); - if (t->get_id () == IDENTIFIER) + if (t->get_id () != LEFT_PAREN) { Error error (t->get_locus (), "unexpected token %qs - expected bare function", diff --git a/gcc/testsuite/rust/compile/invalid_impl_for.rs b/gcc/testsuite/rust/compile/invalid_impl_for.rs index 6b7ad7edd2c..e9b4d2767f0 100644 --- a/gcc/testsuite/rust/compile/invalid_impl_for.rs +++ b/gcc/testsuite/rust/compile/invalid_impl_for.rs @@ -1,4 +1,4 @@ impl Foo for -fn main() {// { dg-error "unexpected token .identifier. - expected bare function" } +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 From 8376309eebd849d5fe58ac1006ec96e8cef8a24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAcio=20Boari=20Fleury?= Date: Fri, 28 Nov 2025 16:42:27 -0300 Subject: [PATCH 4/5] Improve regex for test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/testsuite/ChangeLog: * rust/compile/invalid_impl_for.rs: nothing should change in principle Signed-off-by: Lúcio Boari Fleury --- gcc/testsuite/rust/compile/invalid_impl_for.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/rust/compile/invalid_impl_for.rs b/gcc/testsuite/rust/compile/invalid_impl_for.rs index e9b4d2767f0..069c5356f6e 100644 --- a/gcc/testsuite/rust/compile/invalid_impl_for.rs +++ b/gcc/testsuite/rust/compile/invalid_impl_for.rs @@ -1,4 +1,4 @@ impl Foo for -fn main() {// { dg-error "unexpected token ..*. - expected bare function" } +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 From d6b6ba21ce5a232fd0b9f001cf7044e4ab123602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=BAcio=20Boari=20Fleury?= Date: Mon, 1 Dec 2025 16:16:28 -0300 Subject: [PATCH 5/5] Check for LEFT_PAREN is now redundant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/rust/ChangeLog: * parse/rust-parse-impl.h: (parse_bare_function_type) remove redundancy Signed-off-by: Lúcio Boari Fleury --- gcc/rust/parse/rust-parse-impl.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 97ff71fa6f1..c8d7c6c6d19 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9653,9 +9653,6 @@ Parser::parse_bare_function_type ( return nullptr; } - if (!skip_token (LEFT_PAREN)) - return nullptr; - // parse function params, if they exist std::vector params; bool is_variadic = false;