]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix optional trait parsing
authordave <dave@dmetwo.org>
Wed, 15 Nov 2023 18:28:27 +0000 (12:28 -0600)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:48 +0000 (16:35 +0100)
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>
gcc/rust/typecheck/rust-hir-type-check-item.cc
gcc/testsuite/rust/compile/issue-2725.rs [new file with mode: 0644]

index 317d16700aae1fdc1b36f2e6faa9642981e2475f..68e206924bbddc50523312cc2a10ea5dacbf2b1e 100644 (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 ())
     {
diff --git a/gcc/testsuite/rust/compile/issue-2725.rs b/gcc/testsuite/rust/compile/issue-2725.rs
new file mode 100644 (file)
index 0000000..a344bc8
--- /dev/null
@@ -0,0 +1,3 @@
+#[lang = "sized"]
+pub trait Sized {}
+trait Trait: ?Sized {} // { dg-error ".?Trait. is not permitted in supertraits" }