Skip to content

Commit 45874ae

Browse files
committed
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 <lenny.chiadmi-delage@epita.fr>
1 parent dbf131a commit 45874ae

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

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

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9488,28 +9488,39 @@ Parser<ManagedTokenSource>::parse_paren_prefixed_type ()
94889488
{
94899489
// release vector pointer
94909490
std::unique_ptr<AST::Type> released_ptr = std::move (types[0]);
9491+
9492+
// We don't want to convert it to TraitBound as it could be a
9493+
// ParenthesisedType
9494+
9495+
return std::unique_ptr<AST::ParenthesisedType> (
9496+
new AST::ParenthesisedType (std::move (released_ptr),
9497+
left_delim_locus));
9498+
94919499
/* HACK: attempt to convert to trait bound. if fails, parenthesised
94929500
* type */
9493-
std::unique_ptr<AST::TraitBound> converted_bound (
9494-
released_ptr->to_trait_bound (true));
9495-
if (converted_bound == nullptr)
9496-
{
9497-
// parenthesised type
9498-
return std::unique_ptr<AST::ParenthesisedType> (
9499-
new AST::ParenthesisedType (std::move (released_ptr),
9500-
left_delim_locus));
9501-
}
9502-
else
9503-
{
9504-
// trait object type (one bound)
95059501

9506-
// get value semantics trait bound
9507-
AST::TraitBound value_bound (*converted_bound);
9502+
/*
9503+
std::unique_ptr<AST::TraitBound> converted_bound (
9504+
released_ptr->to_trait_bound (true));
9505+
if (converted_bound == nullptr)
9506+
{
9507+
// parenthesised type
9508+
return std::unique_ptr<AST::ParenthesisedType> (
9509+
new AST::ParenthesisedType (std::move (released_ptr),
9510+
left_delim_locus));
9511+
}
9512+
else
9513+
{
9514+
// trait object type (one bound)
95089515
9509-
return std::unique_ptr<AST::TraitObjectTypeOneBound> (
9510-
new AST::TraitObjectTypeOneBound (value_bound,
9511-
left_delim_locus));
9512-
}
9516+
// get value semantics trait bound
9517+
AST::TraitBound value_bound (*converted_bound);
9518+
9519+
return std::unique_ptr<AST::TraitObjectTypeOneBound> (
9520+
new AST::TraitObjectTypeOneBound (value_bound,
9521+
left_delim_locus));
9522+
}
9523+
*/
95139524
}
95149525
}
95159526
else

gcc/testsuite/rust/compile/issue-4148.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// { dg-excess-errors "warnings" }
2-
31
// TODO: all `xfail` conditions should be changed to `target` once the ICE in #4148 is resolved
42

53
pub fn ret_parens(x: i32) -> i32 {

0 commit comments

Comments
 (0)