-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
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.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsT-langRelevant to the language teamRelevant to the language team
Description
What is this lint about
Consider the following code:
extern {
static S: T;
}
S
here is a static variable accessible to Rust but defined and initialized elsewhere.
External static variables cannot be accessed safely from Rust code for several reasons:
S
can contain an arbitrary bit pattern not necessarily being a valid value of typeT
.- even if all bit patterns are valid values of
T
,S
is still not controlled by Rust ownership system and can be accessed from other threads potentially creating data races.
See #35112 for more details as well as examples of how this can lead to crashes.
Previously safe accesses to extern statics were erroneously permitted outside of unsafe blocks. #36173 fixed this oversight.
How to fix this warning/error
Surround accesses to extern statics with unsafe
blocks and make sure these accesses are actually valid.
Current status
- Issue deprecation warnings for safe accesses to extern statics #36173 introduces the
safe_extern_statics
lint as warn-by-default - Make sufficiently old or low-impact compatibility lints deny-by-default #42894 makes the
safe_extern_statics
lint deny-by-default - PR ? makes the
safe_extern_statics
lint a hard error
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.B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-future-incompatibilityCategory: Future-incompatibility lintsCategory: Future-incompatibility lintsT-langRelevant to the language teamRelevant to the language team