[][src]Trait core::marker::StructuralEq

#[lang = "structural_teq"]
pub trait StructuralEq { }
🔬 This is a nightly-only experimental API. (structural_match #31434)

Required trait for constants used in pattern matches.

Any type that derives Eq automatically implements this trait, regardless of whether its type-parameters implement Eq.

This is a hack to workaround a limitation in our type-system.

Background:

We want to require that types of consts used in pattern matches have the attribute #[derive(PartialEq, Eq)].

In a more ideal world, we could check that requirement by just checking that the given type implements both (1.) the StructuralPartialEq trait and (2.) the Eq trait. However, you can have ADTs that do derive(PartialEq, Eq), and be a case that we want the compiler to accept, and yet the constant's type fails to implement Eq.

Namely, a case like this:

#[derive(PartialEq, Eq)]
struct Wrap<X>(X);
fn higher_order(_: &()) { }
const CFN: Wrap<fn(&())> = Wrap(higher_order);
fn main() {
    match CFN {
        CFN => {}
        _ => {}
    }
}Run

(The problem in the above code is that Wrap<fn(&())> does not implement PartialEq, nor Eq, because for<'a> fn(&'a _) does not implement those traits.)

Therefore, we cannot rely on naive check for StructuralPartialEq and mere Eq.

As a hack to work around this, we use two separate traits injected by each of the two derives (#[derive(PartialEq)] and #[derive(Eq)]) and check that both of them are present as part of structural-match checking.

Implementors

impl StructuralEq for FpCategory[src]

impl StructuralEq for IntErrorKind[src]

impl StructuralEq for SearchStep[src]

impl StructuralEq for Ordering[src]

impl StructuralEq for AllocErr[src]

impl StructuralEq for CannotReallocInPlace[src]

impl StructuralEq for Layout[src]

impl StructuralEq for LayoutErr[src]

impl StructuralEq for TypeId[src]

impl StructuralEq for CpuidResult[src]

impl StructuralEq for CharTryFromError[src]

impl StructuralEq for DecodeUtf16Error[src]

impl StructuralEq for ParseCharError[src]

impl StructuralEq for UnicodeVersion[src]

impl StructuralEq for Error[src]

impl StructuralEq for PhantomPinned[src]

impl StructuralEq for NonZeroI128[src]

impl StructuralEq for NonZeroI16[src]

impl StructuralEq for NonZeroI32[src]

impl StructuralEq for NonZeroI64[src]

impl StructuralEq for NonZeroI8[src]

impl StructuralEq for NonZeroIsize[src]

impl StructuralEq for NonZeroU128[src]

impl StructuralEq for NonZeroU16[src]

impl StructuralEq for NonZeroU32[src]

impl StructuralEq for NonZeroU64[src]

impl StructuralEq for NonZeroU8[src]

impl StructuralEq for NonZeroUsize[src]

impl StructuralEq for ParseFloatError[src]

impl StructuralEq for ParseIntError[src]

impl StructuralEq for TryFromIntError[src]

impl StructuralEq for RangeFull[src]

impl StructuralEq for NoneError[src]

impl StructuralEq for ParseBoolError[src]

impl StructuralEq for Utf8Error[src]

impl StructuralEq for Duration[src]

impl<'a> StructuralEq for Utf8LossyChunk<'a>[src]

impl<Idx> StructuralEq for Range<Idx>[src]

impl<Idx> StructuralEq for RangeFrom<Idx>[src]

impl<Idx> StructuralEq for RangeTo<Idx>[src]

impl<Idx> StructuralEq for RangeToInclusive<Idx>[src]

impl<P> StructuralEq for Pin<P>[src]

impl<T> StructuralEq for Bound<T>[src]

impl<T> StructuralEq for Option<T>[src]

impl<T> StructuralEq for Poll<T>[src]

impl<T> StructuralEq for Reverse<T>[src]

impl<T> StructuralEq for Wrapping<T>[src]

impl<T, E> StructuralEq for Result<T, E>[src]

impl<T: ?Sized> StructuralEq for PhantomData<T>[src]

impl<T: ?Sized> StructuralEq for ManuallyDrop<T>[src]

impl<Y, R> StructuralEq for GeneratorState<Y, R>[src]

Loading content...