From d5f98fbb27f6f31a7d211353b016941fa45f699d Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Mon, 6 Apr 2026 17:01:55 +0200 Subject: [PATCH] implement `StructuralPartialEq` for `MaybeDangling` This fixes a stable-to-stable regression where constants of type `ManuallyDrop` would not be allowed to be used as a pattern due to `MaybeDangling` in `ManuallyDrop` not implementing `StructuralPartialEq`. --- library/core/src/mem/maybe_dangling.rs | 3 +++ tests/ui/consts/manually_drop_structural_eq.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/ui/consts/manually_drop_structural_eq.rs diff --git a/library/core/src/mem/maybe_dangling.rs b/library/core/src/mem/maybe_dangling.rs index c85576b5778cc..2c9c435c24085 100644 --- a/library/core/src/mem/maybe_dangling.rs +++ b/library/core/src/mem/maybe_dangling.rs @@ -1,5 +1,6 @@ #![unstable(feature = "maybe_dangling", issue = "118166")] +use crate::marker::StructuralPartialEq; use crate::{mem, ptr}; /// Allows wrapped [references] and [boxes] to dangle. @@ -109,3 +110,5 @@ impl MaybeDangling

{ x } } + +impl StructuralPartialEq for MaybeDangling {} diff --git a/tests/ui/consts/manually_drop_structural_eq.rs b/tests/ui/consts/manually_drop_structural_eq.rs new file mode 100644 index 0000000000000..1768ebd5f9c4e --- /dev/null +++ b/tests/ui/consts/manually_drop_structural_eq.rs @@ -0,0 +1,16 @@ +// Check that `ManuallyDrop` types can be used as a constant when matching. +// I.e. that `ManuallyDrop` implements `StructuralPartialEq`. +// +// Regression test for . +// +//@ check-pass +use std::mem::ManuallyDrop; + +fn main() { + const X: ManuallyDrop = ManuallyDrop::new(1); + + match ManuallyDrop::new(1) { + X => println!("blah"), + _ => println!("bleh"), + } +}