diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index f3ad72c72374..cb07b26d5d64 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -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 (impl_type), diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index 669a48263ef8..c1e8107774c0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -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> diff --git a/gcc/testsuite/rust/compile/issue-3030.rs b/gcc/testsuite/rust/compile/issue-3030.rs new file mode 100644 index 000000000000..0a1866d9a6b2 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3030.rs @@ -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 !DerefMut for &T {} diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index ca07ed6ecd2b..3251921acd45 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -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