diff --git a/src/attributes/type_system.md b/src/attributes/type_system.md index f8691b30d..d91b96f1e 100644 --- a/src/attributes/type_system.md +++ b/src/attributes/type_system.md @@ -166,7 +166,7 @@ match message { It's also not allowed to use numeric casts (`as`) on enums that contain any non-exhaustive variants. For example, the following enum can be cast because it doesn't contain any non-exhaustive variants: -```rust, ignore +```rust #[non_exhaustive] pub enum Example { First, @@ -176,20 +176,21 @@ pub enum Example { However, if the enum contains even a single non-exhaustive variant, casting will result in an error. Consider this modified version of the same enum: -```rust, ignore +```rust #[non_exhaustive] -pub enum Example { +pub enum EnumWithNonExhaustiveVariants { First, #[non_exhaustive] Second } ``` -```rust, ignore -use othercrate::EnumWithNonExhaustiveEnumVariants; + +```rust,ignore +use othercrate::EnumWithNonExhaustiveVariants; // Error: cannot cast an enum with a non-exhaustive variant when it's defined in another crate -let _ = EnumWithNonExhaustiveEnumVariants::default() as u8; +let _ = EnumWithNonExhaustiveVariants::First as u8; ``` Non-exhaustive types are always considered inhabited in downstream crates.