Skip to content

ManuallyDrop can't be used as a constant in match since 1.94 #154890

@WaffleLapkin

Description

@WaffleLapkin

Code

I tried this code:

use std::mem::ManuallyDrop;
fn main() {
    const X: ManuallyDrop<u32> = ManuallyDrop::new(1);
    
    match ManuallyDrop::new(1) {
        X => println!("blah"),
        _ => println!("bleh"),
    }
}

I expected to see this happen: it compiles.

Instead, this happened: it fails:

error: constant of non-structural type `MaybeDangling<u32>` in a pattern
  --> src/main.rs:6:9
   |
 3 |     const X: ManuallyDrop<u32> = ManuallyDrop::new(1);
   |     -------------------------- constant defined here
...
 6 |         X => println!("blah"),
   |         ^ constant of non-structural type
   |
  ::: /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/maybe_dangling.rs:76:1
   |
76 | pub struct MaybeDangling<P: ?Sized>(P);
   | ----------------------------------- `MaybeDangling<u32>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
   |
   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details

Version it worked on

It most recently worked on: 1.93.0

Version with regression

1.94.0, introduced by #149775

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions