implement StructuralPartialEq for MaybeDangling

This fixes a stable-to-stable regression where constants of type
`ManuallyDrop<T>` would not be allowed to be used as a pattern due to
`MaybeDangling<T>` in `ManuallyDrop<T>` not implementing
`StructuralPartialEq`.
This commit is contained in:
Waffle Lapkin
2026-04-06 17:01:55 +02:00
parent 906ca7ff5e
commit d5f98fbb27
2 changed files with 19 additions and 0 deletions
+3
View File
@@ -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 @@ pub const fn into_inner(self) -> P
x
}
}
impl<T: ?Sized> StructuralPartialEq for MaybeDangling<T> {}
@@ -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 <https://github.com/rust-lang/rust/issues/154890>.
//
//@ check-pass
use std::mem::ManuallyDrop;
fn main() {
const X: ManuallyDrop<u32> = ManuallyDrop::new(1);
match ManuallyDrop::new(1) {
X => println!("blah"),
_ => println!("bleh"),
}
}