Skip to content

Commit a5215b2

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 <[email protected]>
1 parent b92a684 commit a5215b2

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
@@ -9460,28 +9460,39 @@ Parser<ManagedTokenSource>::parse_paren_prefixed_type ()
94609460
{
94619461
// release vector pointer
94629462
std::unique_ptr<AST::Type> released_ptr = std::move (types[0]);
9463+
9464+
// We don't want to convert it to TraitBound as it could be a
9465+
// ParenthesisedType
9466+
9467+
return std::unique_ptr<AST::ParenthesisedType> (
9468+
new AST::ParenthesisedType (std::move (released_ptr),
9469+
left_delim_locus));
9470+
94639471
/* HACK: attempt to convert to trait bound. if fails, parenthesised
94649472
* type */
9465-
std::unique_ptr<AST::TraitBound> converted_bound (
9466-
released_ptr->to_trait_bound (true));
9467-
if (converted_bound == nullptr)
9468-
{
9469-
// parenthesised type
9470-
return std::unique_ptr<AST::ParenthesisedType> (
9471-
new AST::ParenthesisedType (std::move (released_ptr),
9472-
left_delim_locus));
9473-
}
9474-
else
9475-
{
9476-
// trait object type (one bound)
94779473

9478-
// get value semantics trait bound
9479-
AST::TraitBound value_bound (*converted_bound);
9474+
/*
9475+
std::unique_ptr<AST::TraitBound> converted_bound (
9476+
released_ptr->to_trait_bound (true));
9477+
if (converted_bound == nullptr)
9478+
{
9479+
// parenthesised type
9480+
return std::unique_ptr<AST::ParenthesisedType> (
9481+
new AST::ParenthesisedType (std::move (released_ptr),
9482+
left_delim_locus));
9483+
}
9484+
else
9485+
{
9486+
// trait object type (one bound)
94809487
9481-
return std::unique_ptr<AST::TraitObjectTypeOneBound> (
9482-
new AST::TraitObjectTypeOneBound (value_bound,
9483-
left_delim_locus));
9484-
}
9488+
// get value semantics trait bound
9489+
AST::TraitBound value_bound (*converted_bound);
9490+
9491+
return std::unique_ptr<AST::TraitObjectTypeOneBound> (
9492+
new AST::TraitObjectTypeOneBound (value_bound,
9493+
left_delim_locus));
9494+
}
9495+
*/
94859496
}
94869497
}
94879498
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)