Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive for uninit lint #10551

Closed
zesterer opened this issue Mar 26, 2023 · 3 comments · Fixed by #10553
Closed

False positive for uninit lint #10551

zesterer opened this issue Mar 26, 2023 · 3 comments · Fixed by #10553
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@zesterer
Copy link

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

@zesterer zesterer added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 26, 2023
@zesterer
Copy link
Author

cc @Nilstrieb

@Nilstrieb
Copy link
Member

See #10520 (comment) for why this happens

@Alexendoo
Copy link
Member

Using the old logic as the fallback sounds good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants