Skip to content

Commit d5f98fb

Browse files
committed
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`.
1 parent 906ca7f commit d5f98fb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

library/core/src/mem/maybe_dangling.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![unstable(feature = "maybe_dangling", issue = "118166")]
22

3+
use crate::marker::StructuralPartialEq;
34
use crate::{mem, ptr};
45

56
/// Allows wrapped [references] and [boxes] to dangle.
@@ -109,3 +110,5 @@ impl<P: ?Sized> MaybeDangling<P> {
109110
x
110111
}
111112
}
113+
114+
impl<T: ?Sized> StructuralPartialEq for MaybeDangling<T> {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Check that `ManuallyDrop` types can be used as a constant when matching.
2+
// I.e. that `ManuallyDrop` implements `StructuralPartialEq`.
3+
//
4+
// Regression test for <https://github.com/rust-lang/rust/issues/154890>.
5+
//
6+
//@ check-pass
7+
use std::mem::ManuallyDrop;
8+
9+
fn main() {
10+
const X: ManuallyDrop<u32> = ManuallyDrop::new(1);
11+
12+
match ManuallyDrop::new(1) {
13+
X => println!("blah"),
14+
_ => println!("bleh"),
15+
}
16+
}

0 commit comments

Comments
 (0)