Skip to content

False positive for uninit lint #10551

Closed
@zesterer

Description

@zesterer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions