-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Tracking issue for future-incompatibility lint mem_uninitialized #101570
Copy link
Copy link
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.Status: The feature has not been implemented.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
Status
Idea
Important
This lint has not been implemented yet! See #100342.
This is the summary issue for the
mem_uninitializedfuture-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::uninitializedis used, unless the type returned consists of only raw pointers, integers, and floats.As an example,
uninitialized::<[char; 64]>will trigger the warning, butuninitialized::<[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 onlyassume_initonce 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::uninitializedin their dependency tree.