Code
use std::marker::PhantomData;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StructuralType<T: PartialEq> {
ty: PhantomData<T>,
var: u32,
}
impl<T: PartialEq> StructuralType<T> {
const A: Self = StructuralType {
ty: PhantomData,
var: 0,
};
const B: Self = StructuralType {
ty: PhantomData,
var: 0,
};
fn broken(self) {
match self {
Self::A => {}
Self::B => {}
_ => {}
}
}
}
Current output
error: constant of non-structural type `StructuralType<T>` in a pattern
--> src/lib.rs:22:13
|
4 | pub struct StructuralType<T: PartialEq> {
| --------------------------------------- `StructuralType<T>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
...
9 | impl<T: PartialEq> StructuralType<T> {
| ------------------------------------
10 | const A: Self = StructuralType {
| ------------- constant defined here
...
22 | Self::A => {}
| ^^^^^^^ constant of non-structural type
error: constant of non-structural type `StructuralType<T>` in a pattern
--> src/lib.rs:23:13
|
4 | pub struct StructuralType<T: PartialEq> {
| --------------------------------------- `StructuralType<T>` must be annotated with `#[derive(PartialEq)]` to be usable in patterns
...
9 | impl<T: PartialEq> StructuralType<T> {
| ------------------------------------
...
15 | const B: Self = StructuralType {
| ------------- constant defined here
...
23 | Self::B => {}
| ^^^^^^^ constant of non-structural type
error: could not compile `test_structural_ty` (lib) due to 2 previous errors
Desired output
Undecided, however the suggestion to annotate #[derive(PartialEq)] is incorrect.
Rust Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
Additional Information
Code
Current output
Desired output
Undecided, however the suggestion to annotate
#[derive(PartialEq)]is incorrect.Rust Version
Additional Information
StructuralPartialEqcomputation error #150296.