gccrs: Fix optional trait parsing

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>
This commit is contained in:
dave
2023-11-15 12:28:27 -06:00
committed by Arthur Cohen
parent 2658b0642b
commit a3e002aa61
2 changed files with 21 additions and 0 deletions

View File

@@ -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 ())
{

View File

@@ -0,0 +1,3 @@
#[lang = "sized"]
pub trait Sized {}
trait Trait: ?Sized {} // { dg-error ".?Trait. is not permitted in supertraits" }