Closed
Description
Given the following struct:
#[rustc_layout_scalar_valid_range_start(2)]
struct NonZeroAndOneU8(u8);
trying to initialise it directly with NonZeroAndOneU8(1)
(rightfully) results in the error:
error[[E0133]](https://doc.rust-lang.org/nightly/error_codes/E0133.html): initializing type with `rustc_layout_scalar_valid_range` attr is unsafe and requires unsafe function or block
--> src/main.rs:9:5
|
9 | NonZeroAndOneU8(1);
| ^^^^^^^^^^^^^^^^^^ initializing type with `rustc_layout_scalar_valid_range` attr
|
= note: initializing a layout restricted type's field with a value outside the valid range is undefined behavior
For more information about this error, try `rustc --explain E0133`.
error: could not compile `playground` (bin "playground") due to previous error
But Some(1).map(NonZeroAndOneU8).unwrap()
compiles just fine returning NonZeroAndOneU8(1)
which is an invalid state (link to the playground).