Skip to main content

assert_stable_kinds

Macro assert_stable_kinds 

Source
macro_rules! assert_stable_kinds {
    ($enum:ty, $test_name:ident, $($variant:ident = $value:expr),+ $(,)?) => { ... };
}
Expand description

Assert that an error-kind enum’s discriminants are what they were.

The discriminants are a public ABI contract, so a reordering that a compiler is happy with is a breaking change for every consumer. This turns that into a test failure.

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum ErrorKind {
    Other = 1,
    Io = 2,
}

unparser_shared::assert_stable_kinds! {
    ErrorKind, discriminants_are_stable,
    Other = 1,
    Io = 2,
}