]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust: negative polarity removes restrictions on validation of impl blocks
authorPhilip Herron <herron.philip@googlemail.com>
Fri, 20 Sep 2024 16:49:36 +0000 (17:49 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:11 +0000 (15:32 +0100)
Negative polarity means we can just ignore if any trait items are not
implemented.

Fxies #3030

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): the polarity was reversed
* typecheck/rust-hir-type-check-item.cc: check the polarity

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3030.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/hir/rust-ast-lower-item.cc
gcc/rust/typecheck/rust-hir-type-check-item.cc
gcc/testsuite/rust/compile/issue-3030.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude

index 0ef4f357c8ed0a12fac4cca0f9884c4726837f85..171737ab0293001eba863c25cd1758930e175fb5 100644 (file)
@@ -690,8 +690,8 @@ ASTLoweringItem::visit (AST::TraitImpl &impl_block)
     }
 
   BoundPolarity polarity = impl_block.is_exclam ()
-                            ? BoundPolarity::RegularBound
-                            : BoundPolarity::NegativeBound;
+                            ? BoundPolarity::NegativeBound
+                            : BoundPolarity::RegularBound;
   HIR::ImplBlock *hir_impl_block = new HIR::ImplBlock (
     mapping, std::move (impl_items), std::move (generic_params),
     std::unique_ptr<HIR::Type> (impl_type),
index 68e206924bbddc50523312cc2a10ea5dacbf2b1e..d707e3458f1d297a096e64fdeed4f8de916b3a68 100644 (file)
@@ -734,7 +734,8 @@ TypeCheckItem::validate_trait_impl_block (
   bool impl_block_missing_trait_items
     = !specified_bound.is_error ()
       && trait_reference->size () != trait_item_refs.size ();
-  if (impl_block_missing_trait_items)
+  if (impl_block_missing_trait_items
+      && impl_block.get_polarity () == BoundPolarity::RegularBound)
     {
       // filter the missing impl_items
       std::vector<std::reference_wrapper<const TraitItemReference>>
diff --git a/gcc/testsuite/rust/compile/issue-3030.rs b/gcc/testsuite/rust/compile/issue-3030.rs
new file mode 100644 (file)
index 0000000..0a1866d
--- /dev/null
@@ -0,0 +1,16 @@
+#![feature(negative_impls)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+pub trait Deref {}
+
+pub trait DerefMut: Deref {
+    type Target;
+
+    /// Mutably dereferences the value.
+    #[stable(feature = "rust1", since = "1.0.0")]
+    fn deref_mut(&mut self) -> &mut Self::Target;
+}
+
+impl<T: ?Sized> !DerefMut for &T {}
index ca07ed6ecd2bb624496949663b7215006d69761d..3251921acd453b6cb7677f089dca924ce6925588 100644 (file)
@@ -291,3 +291,4 @@ unknown-associated-item.rs
 box_syntax_feature_gate.rs
 dropck_eyepatch_feature_gate.rs
 inline_asm_parse_output_operand.rs
+issue-3030.rs
\ No newline at end of file