From 1429964a9cb2f9c3be3ca1fc903fcda4ff9f74f3 Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 15 Nov 2023 12:28:27 -0600 Subject: [PATCH] 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 --- gcc/rust/typecheck/rust-hir-type-check-item.cc | 18 ++++++++++++++++++ gcc/testsuite/rust/compile/issue-2725.rs | 3 +++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2725.rs diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 87313af9a587..802d5845e171 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -518,6 +518,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 (*tp_bound.get ()); + if (tb.get_polarity () == BoundPolarity::AntiBound) + { + rust_error_at (tb.get_locus (), + "% is not permitted in supertraits"); + } + } + } + } + TraitReference *trait_ref = TraitResolver::Resolve (trait); if (trait_ref->is_error ()) { diff --git a/gcc/testsuite/rust/compile/issue-2725.rs b/gcc/testsuite/rust/compile/issue-2725.rs new file mode 100644 index 000000000000..a344bc8d4641 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2725.rs @@ -0,0 +1,3 @@ +#[lang = "sized"] +pub trait Sized {} +trait Trait: ?Sized {} // { dg-error ".?Trait. is not permitted in supertraits" }