From a5215b2dc54046745093b092c748086fae13bfcc Mon Sep 17 00:00:00 2001 From: "lenny.chiadmi-delage" Date: Wed, 15 Oct 2025 13:44:12 +0000 Subject: [PATCH] gccrs: fix parser error on parenthesised types Do not cast parenthesised types to TraitBound types Fixes #4148 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_paren_prefixed_type): remove cast to TraitBound gcc/testsuite/ChangeLog: * rust/compile/issue-4148.rs: test should not produce errors Signed-off-by: lenny.chiadmi-delage --- gcc/rust/parse/rust-parse-impl.h | 47 +++++++++++++++--------- gcc/testsuite/rust/compile/issue-4148.rs | 2 - 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index ec4c1c1d6c7..404f3b7d8cb 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -9460,28 +9460,39 @@ Parser::parse_paren_prefixed_type () { // release vector pointer std::unique_ptr released_ptr = std::move (types[0]); + + // We don't want to convert it to TraitBound as it could be a + // ParenthesisedType + + return std::unique_ptr ( + new AST::ParenthesisedType (std::move (released_ptr), + left_delim_locus)); + /* HACK: attempt to convert to trait bound. if fails, parenthesised * type */ - std::unique_ptr converted_bound ( - released_ptr->to_trait_bound (true)); - if (converted_bound == nullptr) - { - // parenthesised type - return std::unique_ptr ( - new AST::ParenthesisedType (std::move (released_ptr), - left_delim_locus)); - } - else - { - // trait object type (one bound) - // get value semantics trait bound - AST::TraitBound value_bound (*converted_bound); + /* + std::unique_ptr converted_bound ( + released_ptr->to_trait_bound (true)); + if (converted_bound == nullptr) + { + // parenthesised type + return std::unique_ptr ( + new AST::ParenthesisedType (std::move (released_ptr), + left_delim_locus)); + } + else + { + // trait object type (one bound) - return std::unique_ptr ( - new AST::TraitObjectTypeOneBound (value_bound, - left_delim_locus)); - } + // get value semantics trait bound + AST::TraitBound value_bound (*converted_bound); + + return std::unique_ptr ( + new AST::TraitObjectTypeOneBound (value_bound, + left_delim_locus)); + } + */ } } else diff --git a/gcc/testsuite/rust/compile/issue-4148.rs b/gcc/testsuite/rust/compile/issue-4148.rs index 599d73955ac..f46c5ca3e8e 100644 --- a/gcc/testsuite/rust/compile/issue-4148.rs +++ b/gcc/testsuite/rust/compile/issue-4148.rs @@ -1,5 +1,3 @@ -// { dg-excess-errors "warnings" } - // TODO: all `xfail` conditions should be changed to `target` once the ICE in #4148 is resolved pub fn ret_parens(x: i32) -> i32 {