Skip to content

Commit f3b1c2a

Browse files
committed
gccrs: fix parser error on parenthesised types
Do not cast parenthesised types to TraitBound types gcc/rust/ChangeLog: * ast/rust-path.cc (TypePath::to_trait_bound): * hir/tree/rust-hir-type.cc (ParenthesisedType::to_trait_bound): * hir/tree/rust-hir.cc (TypePath::to_trait_bound): * parse/rust-parse-impl.h (Parser::parse_paren_prefixed_type): * parse/rust-parse-impl.h (Parser::parse_paren_prefixed_type): Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
1 parent 177b601 commit f3b1c2a

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

gcc/rust/ast/rust-path.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ TypePath::make_debug_string () const
290290
TraitBound *
291291
TypePath::to_trait_bound (bool in_parens) const
292292
{
293+
// If already in parentheses, don't convert to trait bound
294+
// This ensures (TypePath) stays as ParenthesisedType in the parser
295+
if (in_parens)
296+
return nullptr;
297+
293298
return new TraitBound (TypePath (*this), get_locus (), in_parens);
294299
}
295300

gcc/rust/hir/tree/rust-hir-type.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ ParenthesisedType::operator= (ParenthesisedType const &other)
101101
}
102102

103103
std::unique_ptr<TraitBound>
104-
ParenthesisedType::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
104+
ParenthesisedType::to_trait_bound (bool in_parens) const
105105
{
106+
/* If already in parentheses, don't convert - should stay as
107+
* ParenthesisedType */
108+
if (in_parens)
109+
return nullptr;
110+
106111
/* NOTE: obviously it is unknown whether the internal type is a trait bound
107112
* due to polymorphism, so just let the internal type handle it. As
108113
* parenthesised type, it must be in parentheses. */

gcc/rust/hir/tree/rust-hir.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2798,6 +2798,11 @@ Expr::as_string () const
27982798
std::unique_ptr<TraitBound>
27992799
TypePath::to_trait_bound (bool in_parens) const
28002800
{
2801+
// If already in parentheses, don't convert to trait bound
2802+
// This ensures (TypePath) stays as ParenthesisedType in the parser
2803+
if (in_parens)
2804+
return nullptr;
2805+
28012806
// create clone FIXME is this required? or is copy constructor automatically
28022807
// called?
28032808
TypePath copy (*this);

0 commit comments

Comments
 (0)