Do not cast parenthesised types to TraitBound types.
Fixes Rust-GCC#4148
gcc/rust/ChangeLog:
* ast/rust-path.cc (TypePath::to_trait_bound): Check if in
parenthesis.
* hir/tree/rust-hir-type.cc (ParenthesisedType::to_trait_bound):
Likewise.
* hir/tree/rust-hir.cc (TypePath::to_trait_bound): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/issue-4148.rs: Test should produce errors.
Signed-off-by: lenny.chiadmi-delage <lenny.chiadmi-delage@epita.fr>
TraitBound *
TypePath::to_trait_bound (bool in_parens) const
{
+ // If already in parentheses, don't convert to trait bound
+ // This ensures (TypePath) stays as ParenthesisedType in the parser
+ if (in_parens)
+ return nullptr;
+
return new TraitBound (TypePath (*this), get_locus (), in_parens);
}
}
std::unique_ptr<TraitBound>
-ParenthesisedType::to_trait_bound (bool in_parens ATTRIBUTE_UNUSED) const
+ParenthesisedType::to_trait_bound (bool in_parens) const
{
+ /* If already in parentheses, don't convert - should stay as
+ * ParenthesisedType */
+ if (in_parens)
+ return nullptr;
+
/* NOTE: obviously it is unknown whether the internal type is a trait bound
* due to polymorphism, so just let the internal type handle it. As
* parenthesised type, it must be in parentheses. */
std::unique_ptr<TraitBound>
TypePath::to_trait_bound (bool in_parens) const
{
+ // If already in parentheses, don't convert to trait bound
+ // This ensures (TypePath) stays as ParenthesisedType in the parser
+ if (in_parens)
+ return nullptr;
+
// create clone FIXME is this required? or is copy constructor automatically
// called?
TypePath copy (*this);
-// { 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 {