Closed
Description
openedon Mar 26, 2023
Summary
Code like this produces an erroneous lint emission despite the code being safe (MaybeUninit<T>
has no inhabitants).
Lint Name
uninit_assumed_init
Reproducer
I tried this code:
trait MaybeUninitExt<T>: Sized {
/// Identical to the unstable [`MaybeUninit::uninit_array`]
fn uninit_array<const N: usize>() -> [Self; N];
}
impl<T> MaybeUninitExt<T> for MaybeUninit<T> {
fn uninit_array<const N: usize>() -> [Self; N] {
// SAFETY: Output type is entirely uninhabited - IE, it's made up entirely of `MaybeUninit`
unsafe { MaybeUninit::uninit().assume_init() }
}
}
I saw this happen:
error: this call for this type may be undefined behavior
--> src/private.rs:280:18
|
280 | unsafe { MaybeUninit::uninit().assume_init() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
I expected to see this happen:
nothing
Version
No response
Additional Labels
No response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment