Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c10072f

Browse files
committedJul 24, 2024·
Auto merge of rust-lang#124895 - obeis:static-mut-hidden-ref, r=michaelwoerister
Disallow hidden references to mutable static Closes rust-lang#123060 Tracking: - rust-lang#123758
2 parents 2ccafed + fa621b7 commit c10072f

File tree

103 files changed

+1333
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1333
-538
lines changed
 

‎compiler/rustc_driver_impl/src/signal_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ macro raw_errln($tokens:tt) {
3434
}
3535

3636
/// Signal handler installed for SIGSEGV
37+
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
38+
#[allow(static_mut_refs)]
3739
extern "C" fn print_stack_trace(_: libc::c_int) {
3840
const MAX_FRAMES: usize = 256;
3941
// Reserve data segment so we don't have to malloc in a signal handler, which might fail

‎compiler/rustc_hir_analysis/messages.ftl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,24 +463,20 @@ hir_analysis_start_not_target_feature = `#[start]` function is not allowed to ha
463463
hir_analysis_start_not_track_caller = `#[start]` function is not allowed to be `#[track_caller]`
464464
.label = `#[start]` function is not allowed to be `#[track_caller]`
465465
466-
hir_analysis_static_mut_ref = creating a {$shared} reference to a mutable static
467-
.label = {$shared} reference to mutable static
468-
.note = {$shared ->
469-
[shared] this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
470-
*[mutable] this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
471-
}
466+
hir_analysis_static_mut_ref = creating a {$shared_label}reference to a mutable static
467+
.label = {$shared_label}reference to mutable static
468+
.shared_note = shared references to mutable statics are dangerous since if there's any kind of mutation of, or mutable reference created for, that static while the reference lives, that's undefined behavior
469+
.mut_note = mutable references to mutable statics are dangerous since if there's any other pointer used or reference created for that static while the reference lives, that's undefined behavior
472470
.suggestion = use `addr_of!` instead to create a raw pointer
473471
.suggestion_mut = use `addr_of_mut!` instead to create a raw pointer
474472
475-
hir_analysis_static_mut_refs_lint = creating a {$shared} reference to mutable static is discouraged
476-
.label = {$shared} reference to mutable static
473+
hir_analysis_static_mut_refs_lint = creating a {$shared_label}reference to mutable static is discouraged
474+
.label = {$shared_label}reference to mutable static
477475
.suggestion = use `addr_of!` instead to create a raw pointer
478476
.suggestion_mut = use `addr_of_mut!` instead to create a raw pointer
479477
.note = this will be a hard error in the 2024 edition
480-
.why_note = {$shared ->
481-
[shared] this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
482-
*[mutable] this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior
483-
}
478+
.shared_note = shared references to mutable statics are dangerous since if there's any kind of mutation of, or mutable reference created for, that static while the reference lives, that's undefined behavior
479+
.mut_note = mutable references to mutable statics are dangerous since if there's any other pointer used or reference created for that static while the reference lives, that's undefined behavior
484480
485481
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
486482

0 commit comments

Comments
 (0)
This repository has been archived.