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

Tracking issue for future-incompatibility lint mem_uninitialized #101570

Open
5225225 opened this issue Sep 8, 2022 · 1 comment
Open

Tracking issue for future-incompatibility lint mem_uninitialized #101570

5225225 opened this issue Sep 8, 2022 · 1 comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-unimplemented Status: The feature has not been implemented. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@5225225
Copy link
Contributor

5225225 commented Sep 8, 2022

Important

This lint has not been implemented yet! See #100342.

This is the summary issue for the mem_uninitialized
future-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.

What is the warning for?

This warning will trigger whenever std::mem::uninitialized is used, unless the type returned consists of only raw pointers, integers, and floats.

As an example, uninitialized::<[char; 64]> will trigger the warning, but uninitialized::<[u8; 64]> will not. Additionally, in generic methods, uninitialized::<T> will trigger the warning, even though T might be a [u8; 64] when it is used.

To fix the warning, use std::mem::MaybeUninit, and only assume_init once the value is fully initialized. Note that even though we do not warn for uninitialized integers here, it is still undefined behavior to create uninitialized integers.

The change to warn here was made in order to get notified when their dependencies inappropriately use mem::uninitialized, which can lead to runtime panics depending on the type (as tracked in #66151). Using a lint here is less surprising than a runtime panic, and allows people to get notification of code that may break at runtime, earlier.

When will this warning become a hard error?

Unlike other future-compat warnings, this is never intended to be a hard error, it is purely to warn users about dangerous uses of mem::uninitialized in their dependency tree.

@5225225 5225225 changed the title mem_uninitialized future-compatibility warning Tracking issue for mem_uninitialized future-compatibility warning Sep 8, 2022
@5225225
Copy link
Contributor Author

5225225 commented Sep 8, 2022

Note: I'm making this now to register the number so I can add it to the implementation PR (#100342), the exact places where this will lint on is not finalized, but what's described here is what's currently implemented.

Also, I diverged from the template at the end, I suppose the wording here is okay? This is the only FCW that will never actually become a hard error (So I suppose it will exist forever?).

@rustbot label +C-future-compatibility +C-tracking-issue

@rustbot rustbot added C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. labels Sep 8, 2022
@fmease fmease added the S-tracking-unimplemented Status: The feature has not been implemented. label Sep 14, 2024
@fmease fmease changed the title Tracking issue for mem_uninitialized future-compatibility warning Tracking issue for future-incompatibility lint mem_uninitialized Sep 14, 2024
@fmease fmease added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. labels Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-future-incompatibility Category: Future-incompatibility lints C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-unimplemented Status: The feature has not been implemented. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
Archived in project
Development

No branches or pull requests

3 participants