Skip to content

Commit

Permalink
Fix optional trait parsing
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Check for ?Trait in visitor

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2725.rs: New test.

Signed-off-by: Dave Evans <dave@dmetwo.org>
  • Loading branch information
dme2 authored and P-E-P committed Jun 17, 2024
1 parent 7fa14d4 commit 89c056b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions gcc/rust/typecheck/rust-hir-type-check-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,24 @@ TypeCheckItem::visit (HIR::Module &module)
void
TypeCheckItem::visit (HIR::Trait &trait)
{
if (trait.has_type_param_bounds ())
{
for (auto &tp_bound : trait.get_type_param_bounds ())
{
if (tp_bound.get ()->get_bound_type ()
== HIR::TypeParamBound::BoundType::TRAITBOUND)
{
HIR::TraitBound &tb
= static_cast<HIR::TraitBound &> (*tp_bound.get ());
if (tb.get_polarity () == BoundPolarity::AntiBound)
{
rust_error_at (tb.get_locus (),
"%<?Trait%> is not permitted in supertraits");
}
}
}
}

TraitReference *trait_ref = TraitResolver::Resolve (trait);
if (trait_ref->is_error ())
{
Expand Down
3 changes: 3 additions & 0 deletions gcc/testsuite/rust/compile/issue-2725.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#[lang = "sized"]
pub trait Sized {}
trait Trait: ?Sized {} // { dg-error ".?Trait. is not permitted in supertraits" }

0 comments on commit 89c056b

Please sign in to comment.