Skip to main content

rust_spec/
layout.rs

1//! Representation stability and trap/robustness classification.
2//!
3//! This module provides the marker types used by [`crate::RustSpec::Layout`].
4//! Stability describes whether Rust guarantees the representation shape.
5//! Robustness describes whether the represented value space has trap values that
6//! require validity care.
7use core::ops::Add;
8
9use crate::{Stable, Unstable};
10
11/// Closed family of representation-stability classifications.
12#[sealed::sealed]
13pub trait LayoutKind {}
14
15/// Marker for a robust type that does not require validity conversion.
16pub enum Robust {}
17
18/// Marker for a non-robust type that is still transmuted by the ABI layer.
19pub enum NonRobust {}
20
21#[sealed::sealed]
22impl LayoutKind for Stable {}
23
24#[sealed::sealed]
25impl LayoutKind for Unstable {}
26
27impl<K> Add<K> for NonRobust {
28    type Output = Self;
29
30    fn add(self, _: K) -> Self::Output {
31        unreachable!()
32    }
33}
34
35impl<K> Add<K> for Robust {
36    type Output = K;
37
38    fn add(self, _: K) -> Self::Output {
39        unreachable!()
40    }
41}
42
43impl<K> Add<K> for Unstable {
44    type Output = Self;
45
46    fn add(self, _: K) -> Self::Output {
47        unreachable!()
48    }
49}
50
51impl Add<Unstable> for Stable {
52    type Output = Unstable;
53
54    fn add(self, _: Unstable) -> Self::Output {
55        unreachable!()
56    }
57}
58
59impl Add for Stable {
60    type Output = Self;
61
62    fn add(self, _: Self) -> Self::Output {
63        unreachable!()
64    }
65}