Improve wording of static_mut_ref
Rename `static_mut_ref` lint to `static_mut_refs`.
This commit is contained in:
parent
eeeb021954
commit
408eeae59d
73 changed files with 783 additions and 460 deletions
|
@ -112,8 +112,8 @@ fn start<T: Termination + 'static>(
|
||||||
|
|
||||||
static mut NUM: u8 = 6 * 7;
|
static mut NUM: u8 = 6 * 7;
|
||||||
|
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[allow(static_mut_refs)]
|
||||||
static NUM_REF: &'static u8 = unsafe { &NUM };
|
static NUM_REF: &'static u8 = unsafe { &NUM };
|
||||||
|
|
||||||
unsafe fn zeroed<T>() -> T {
|
unsafe fn zeroed<T>() -> T {
|
||||||
|
|
|
@ -99,8 +99,8 @@ fn start<T: Termination + 'static>(
|
||||||
|
|
||||||
static mut NUM: u8 = 6 * 7;
|
static mut NUM: u8 = 6 * 7;
|
||||||
|
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[allow(static_mut_refs)]
|
||||||
static NUM_REF: &'static u8 = unsafe { &NUM };
|
static NUM_REF: &'static u8 = unsafe { &NUM };
|
||||||
|
|
||||||
macro_rules! assert {
|
macro_rules! assert {
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
Reference of mutable static.
|
You have created a reference to a mutable static.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,edition2024,E0796
|
```compile_fail,edition2024,E0796
|
||||||
static mut X: i32 = 23;
|
static mut X: i32 = 23;
|
||||||
static mut Y: i32 = 24;
|
|
||||||
|
|
||||||
unsafe {
|
fn work() {
|
||||||
let y = &X;
|
let _val = unsafe { X };
|
||||||
let ref x = X;
|
|
||||||
let (x, y) = (&X, &Y);
|
|
||||||
foo(&X);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo<'a>(_x: &'a i32) {}
|
let x_ref = unsafe { &mut X };
|
||||||
|
work();
|
||||||
|
// The next line has Undefined Behavior!
|
||||||
|
// `x_ref` is a mutable reference and allows no aliases,
|
||||||
|
// but `work` has been reading the reference between
|
||||||
|
// the moment `x_ref` was created and when it was used.
|
||||||
|
// This violates the uniqueness of `x_ref`.
|
||||||
|
*x_ref = 42;
|
||||||
```
|
```
|
||||||
|
|
||||||
Mutable statics can be written to by multiple threads: aliasing violations or
|
A reference to a mutable static has lifetime `'static`. This is very dangerous
|
||||||
data races will cause undefined behavior.
|
as it is easy to accidentally overlap the lifetime of that reference with
|
||||||
|
other, conflicting accesses to the same static.
|
||||||
|
|
||||||
Reference of mutable static is a hard error from 2024 edition.
|
References to mutable statics are a hard error in the 2024 edition.
|
||||||
|
|
|
@ -373,19 +373,24 @@ hir_analysis_start_not_target_feature = `#[start]` function is not allowed to ha
|
||||||
hir_analysis_start_not_track_caller = `#[start]` function is not allowed to be `#[track_caller]`
|
hir_analysis_start_not_track_caller = `#[start]` function is not allowed to be `#[track_caller]`
|
||||||
.label = `#[start]` function is not allowed to be `#[track_caller]`
|
.label = `#[start]` function is not allowed to be `#[track_caller]`
|
||||||
|
|
||||||
hir_analysis_static_mut_ref = reference of mutable static is disallowed
|
hir_analysis_static_mut_ref = creating a {$shared} reference to a mutable static
|
||||||
.label = reference of mutable static
|
.label = {$shared} reference to mutable static
|
||||||
.note = mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
.note = {$shared ->
|
||||||
.suggestion = shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
[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
|
||||||
.suggestion_mut = mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
*[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
|
||||||
|
}
|
||||||
|
.suggestion = use `addr_of!` instead to create a raw pointer
|
||||||
|
.suggestion_mut = use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
||||||
hir_analysis_static_mut_ref_lint = {$shared}reference of mutable static is discouraged
|
hir_analysis_static_mut_refs_lint = creating a {$shared} reference to mutable static is discouraged
|
||||||
.label = shared reference of mutable static
|
.label = {$shared} reference to mutable static
|
||||||
.label_mut = mutable reference of mutable static
|
.suggestion = use `addr_of!` instead to create a raw pointer
|
||||||
.suggestion = shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
.suggestion_mut = use `addr_of_mut!` instead to create a raw pointer
|
||||||
.suggestion_mut = mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
.note = this will be a hard error in the 2024 edition
|
||||||
.note = reference of mutable static is a hard error from 2024 edition
|
.why_note = {$shared ->
|
||||||
.why_note = mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
[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
|
||||||
|
*[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
|
||||||
|
}
|
||||||
|
|
||||||
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
|
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir_pretty::qpath_to_string;
|
use rustc_hir_pretty::qpath_to_string;
|
||||||
use rustc_lint_defs::builtin::STATIC_MUT_REF;
|
use rustc_lint_defs::builtin::STATIC_MUT_REFS;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
use rustc_type_ir::Mutability;
|
use rustc_type_ir::Mutability;
|
||||||
|
@ -66,32 +66,24 @@ fn handle_static_mut_ref(
|
||||||
hir_id: hir::HirId,
|
hir_id: hir::HirId,
|
||||||
) {
|
) {
|
||||||
if e2024 {
|
if e2024 {
|
||||||
let sugg = if mutable {
|
let (sugg, shared) = if mutable {
|
||||||
errors::StaticMutRefSugg::Mut { span, var }
|
(errors::StaticMutRefSugg::Mut { span, var }, "mutable")
|
||||||
} else {
|
} else {
|
||||||
errors::StaticMutRefSugg::Shared { span, var }
|
(errors::StaticMutRefSugg::Shared { span, var }, "shared")
|
||||||
};
|
};
|
||||||
tcx.sess.parse_sess.dcx.emit_err(errors::StaticMutRef { span, sugg });
|
tcx.sess.parse_sess.dcx.emit_err(errors::StaticMutRef { span, sugg, shared });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (label, sugg, shared) = if mutable {
|
let (sugg, shared) = if mutable {
|
||||||
(
|
(errors::RefOfMutStaticSugg::Mut { span, var }, "mutable")
|
||||||
errors::RefOfMutStaticLabel::Mut { span },
|
|
||||||
errors::RefOfMutStaticSugg::Mut { span, var },
|
|
||||||
"mutable ",
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
(
|
(errors::RefOfMutStaticSugg::Shared { span, var }, "shared")
|
||||||
errors::RefOfMutStaticLabel::Shared { span },
|
|
||||||
errors::RefOfMutStaticSugg::Shared { span, var },
|
|
||||||
"shared ",
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
tcx.emit_node_span_lint(
|
tcx.emit_node_span_lint(
|
||||||
STATIC_MUT_REF,
|
STATIC_MUT_REFS,
|
||||||
hir_id,
|
hir_id,
|
||||||
span,
|
span,
|
||||||
errors::RefOfMutStatic { shared, why_note: (), label, sugg },
|
errors::RefOfMutStatic { span, sugg, shared },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1455,12 +1455,13 @@ pub struct OnlyCurrentTraitsPointerSugg<'a> {
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(hir_analysis_static_mut_ref, code = E0796)]
|
#[diag(hir_analysis_static_mut_ref, code = E0796)]
|
||||||
#[note]
|
#[note]
|
||||||
pub struct StaticMutRef {
|
pub struct StaticMutRef<'a> {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub sugg: StaticMutRefSugg,
|
pub sugg: StaticMutRefSugg,
|
||||||
|
pub shared: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
@ -1491,30 +1492,15 @@ pub enum StaticMutRefSugg {
|
||||||
|
|
||||||
// STATIC_MUT_REF lint
|
// STATIC_MUT_REF lint
|
||||||
#[derive(LintDiagnostic)]
|
#[derive(LintDiagnostic)]
|
||||||
#[diag(hir_analysis_static_mut_ref_lint)]
|
#[diag(hir_analysis_static_mut_refs_lint)]
|
||||||
#[note]
|
#[note]
|
||||||
|
#[note(hir_analysis_why_note)]
|
||||||
pub struct RefOfMutStatic<'a> {
|
pub struct RefOfMutStatic<'a> {
|
||||||
pub shared: &'a str,
|
#[label]
|
||||||
#[note(hir_analysis_why_note)]
|
pub span: Span,
|
||||||
pub why_note: (),
|
|
||||||
#[subdiagnostic]
|
|
||||||
pub label: RefOfMutStaticLabel,
|
|
||||||
#[subdiagnostic]
|
#[subdiagnostic]
|
||||||
pub sugg: RefOfMutStaticSugg,
|
pub sugg: RefOfMutStaticSugg,
|
||||||
}
|
pub shared: &'a str,
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
|
||||||
pub enum RefOfMutStaticLabel {
|
|
||||||
#[label(hir_analysis_label)]
|
|
||||||
Shared {
|
|
||||||
#[primary_span]
|
|
||||||
span: Span,
|
|
||||||
},
|
|
||||||
#[label(hir_analysis_label_mut)]
|
|
||||||
Mut {
|
|
||||||
#[primary_span]
|
|
||||||
span: Span,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
|
|
|
@ -325,6 +325,7 @@ fn register_builtins(store: &mut LintStore) {
|
||||||
store.register_renamed("or_patterns_back_compat", "rust_2021_incompatible_or_patterns");
|
store.register_renamed("or_patterns_back_compat", "rust_2021_incompatible_or_patterns");
|
||||||
store.register_renamed("non_fmt_panic", "non_fmt_panics");
|
store.register_renamed("non_fmt_panic", "non_fmt_panics");
|
||||||
store.register_renamed("unused_tuple_struct_fields", "dead_code");
|
store.register_renamed("unused_tuple_struct_fields", "dead_code");
|
||||||
|
store.register_renamed("static_mut_ref", "static_mut_refs");
|
||||||
|
|
||||||
// These were moved to tool lints, but rustc still sees them when compiling normally, before
|
// These were moved to tool lints, but rustc still sees them when compiling normally, before
|
||||||
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
|
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
|
||||||
|
|
|
@ -89,7 +89,7 @@ declare_lint_pass! {
|
||||||
SINGLE_USE_LIFETIMES,
|
SINGLE_USE_LIFETIMES,
|
||||||
SOFT_UNSTABLE,
|
SOFT_UNSTABLE,
|
||||||
STABLE_FEATURES,
|
STABLE_FEATURES,
|
||||||
STATIC_MUT_REF,
|
STATIC_MUT_REFS,
|
||||||
SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
SUSPICIOUS_AUTO_TRAIT_IMPLS,
|
||||||
TEST_UNSTABLE_LINT,
|
TEST_UNSTABLE_LINT,
|
||||||
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
|
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
|
||||||
|
@ -1769,7 +1769,7 @@ declare_lint! {
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
/// The `static_mut_ref` lint checks for shared or mutable references
|
/// The `static_mut_refs` lint checks for shared or mutable references
|
||||||
/// of mutable static inside `unsafe` blocks and `unsafe` functions.
|
/// of mutable static inside `unsafe` blocks and `unsafe` functions.
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
|
@ -1807,9 +1807,9 @@ declare_lint! {
|
||||||
/// Shared or mutable references of mutable static are almost always a mistake and
|
/// Shared or mutable references of mutable static are almost always a mistake and
|
||||||
/// can lead to undefined behavior and various other problems in your code.
|
/// can lead to undefined behavior and various other problems in your code.
|
||||||
///
|
///
|
||||||
/// This lint is "warn" by default on editions up to 2021, from 2024 there is
|
/// This lint is "warn" by default on editions up to 2021, in 2024 there is
|
||||||
/// a hard error instead.
|
/// a hard error instead.
|
||||||
pub STATIC_MUT_REF,
|
pub STATIC_MUT_REFS,
|
||||||
Warn,
|
Warn,
|
||||||
"shared references or mutable references of mutable static is discouraged",
|
"shared references or mutable references of mutable static is discouraged",
|
||||||
@future_incompatible = FutureIncompatibleInfo {
|
@future_incompatible = FutureIncompatibleInfo {
|
||||||
|
|
|
@ -261,8 +261,9 @@ cfg_if::cfg_if! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(bootstrap, allow(static_mut_ref))]
|
||||||
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
|
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
|
||||||
use core::intrinsics::atomic_store_seqcst;
|
use core::intrinsics::atomic_store_seqcst;
|
||||||
|
|
||||||
|
@ -324,8 +325,9 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
|
||||||
_CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
|
_CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(bootstrap, allow(static_mut_ref))]
|
||||||
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
pub unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send> {
|
pub unsafe fn cleanup(payload: *mut u8) -> Box<dyn Any + Send> {
|
||||||
// A null payload here means that we got here from the catch (...) of
|
// A null payload here means that we got here from the catch (...) of
|
||||||
// __rust_try. This happens when a non-Rust foreign exception is caught.
|
// __rust_try. This happens when a non-Rust foreign exception is caught.
|
||||||
|
|
|
@ -337,8 +337,9 @@ pub mod panic_count {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[cfg(not(feature = "panic_immediate_abort"))]
|
#[cfg(not(feature = "panic_immediate_abort"))]
|
||||||
#[unstable(feature = "update_panic_count", issue = "none")]
|
#[unstable(feature = "update_panic_count", issue = "none")]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(bootstrap, allow(static_mut_ref))]
|
||||||
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
pub mod panic_count {
|
pub mod panic_count {
|
||||||
use crate::cell::Cell;
|
use crate::cell::Cell;
|
||||||
use crate::sync::atomic::{AtomicUsize, Ordering};
|
use crate::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
|
@ -13,8 +13,9 @@ pub macro thread_local_inner {
|
||||||
(@key $t:ty, const $init:expr) => {{
|
(@key $t:ty, const $init:expr) => {{
|
||||||
#[inline]
|
#[inline]
|
||||||
#[deny(unsafe_op_in_unsafe_fn)]
|
#[deny(unsafe_op_in_unsafe_fn)]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(bootstrap, allow(static_mut_ref))]
|
||||||
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
unsafe fn __getit(
|
unsafe fn __getit(
|
||||||
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
|
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
|
||||||
) -> $crate::option::Option<&'static $t> {
|
) -> $crate::option::Option<&'static $t> {
|
||||||
|
|
|
@ -11,8 +11,9 @@ pub macro thread_local_inner {
|
||||||
(@key $t:ty, const $init:expr) => {{
|
(@key $t:ty, const $init:expr) => {{
|
||||||
#[inline] // see comments below
|
#[inline] // see comments below
|
||||||
#[deny(unsafe_op_in_unsafe_fn)]
|
#[deny(unsafe_op_in_unsafe_fn)]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(bootstrap, allow(static_mut_ref))]
|
||||||
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
unsafe fn __getit(
|
unsafe fn __getit(
|
||||||
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
|
_init: $crate::option::Option<&mut $crate::option::Option<$t>>,
|
||||||
) -> $crate::option::Option<&'static $t> {
|
) -> $crate::option::Option<&'static $t> {
|
||||||
|
|
|
@ -180,8 +180,8 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[cfg_attr(not(test), rustc_diagnostic_item = "thread_local_macro")]
|
#[cfg_attr(not(test), rustc_diagnostic_item = "thread_local_macro")]
|
||||||
#[allow_internal_unstable(thread_local_internals)]
|
#[allow_internal_unstable(thread_local_internals)]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
|
||||||
macro_rules! thread_local {
|
macro_rules! thread_local {
|
||||||
// empty (base case for the recursion)
|
// empty (base case for the recursion)
|
||||||
() => {};
|
() => {};
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
//! Ensure that thread-local statics get deallocated when the thread dies.
|
//! Ensure that thread-local statics get deallocated when the thread dies.
|
||||||
|
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
#[thread_local]
|
#[thread_local]
|
||||||
static mut TLS: u8 = 0;
|
static mut TLS: u8 = 0;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
static mut FOO: i32 = 42;
|
static mut FOO: i32 = 42;
|
||||||
|
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#[allow(static_mut_ref)]
|
#[allow(static_mut_refs)]
|
||||||
static BAR: Foo = Foo(unsafe { &FOO as *const _ });
|
static BAR: Foo = Foo(unsafe { &FOO as *const _ });
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
//! test, we also check that thread-locals act as per-thread statics.
|
//! test, we also check that thread-locals act as per-thread statics.
|
||||||
|
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
|
// FIXME: Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,9 @@ unsafe fn run() {
|
||||||
rust_dbg_static_mut = -3;
|
rust_dbg_static_mut = -3;
|
||||||
assert_eq!(rust_dbg_static_mut, -3);
|
assert_eq!(rust_dbg_static_mut, -3);
|
||||||
static_bound(&rust_dbg_static_mut);
|
static_bound(&rust_dbg_static_mut);
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
static_bound_set(&mut rust_dbg_static_mut);
|
static_bound_set(&mut rust_dbg_static_mut);
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/static-mut-foreign.rs:35:18
|
--> $DIR/static-mut-foreign.rs:35:18
|
||||||
|
|
|
|
||||||
LL | static_bound(&rust_dbg_static_mut);
|
LL | static_bound(&rust_dbg_static_mut);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ shared reference of mutable static
|
| ^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static_bound(addr_of!(rust_dbg_static_mut));
|
LL | static_bound(addr_of!(rust_dbg_static_mut));
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/static-mut-foreign.rs:37:22
|
--> $DIR/static-mut-foreign.rs:37:22
|
||||||
|
|
|
|
||||||
LL | static_bound_set(&mut rust_dbg_static_mut);
|
LL | static_bound_set(&mut rust_dbg_static_mut);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static_bound_set(addr_of_mut!(rust_dbg_static_mut));
|
LL | static_bound_set(addr_of_mut!(rust_dbg_static_mut));
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn main() {
|
||||||
let _y1 = &mut static_x; //~ ERROR [E0596]
|
let _y1 = &mut static_x; //~ ERROR [E0596]
|
||||||
unsafe {
|
unsafe {
|
||||||
let _y2 = &mut static_x_mut;
|
let _y2 = &mut static_x_mut;
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/borrowck-access-permissions.rs:18:23
|
--> $DIR/borrowck-access-permissions.rs:18:23
|
||||||
|
|
|
|
||||||
LL | let _y2 = &mut static_x_mut;
|
LL | let _y2 = &mut static_x_mut;
|
||||||
| ^^^^^^^^^^^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y2 = addr_of_mut!(static_x_mut);
|
LL | let _y2 = addr_of_mut!(static_x_mut);
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl Foo {
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let sfoo: *mut Foo = &mut SFOO;
|
let sfoo: *mut Foo = &mut SFOO;
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
let x = (*sfoo).x();
|
let x = (*sfoo).x();
|
||||||
(*sfoo).x[1] += 1;
|
(*sfoo).x[1] += 1;
|
||||||
*x += 1;
|
*x += 1;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30
|
--> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30
|
||||||
|
|
|
|
||||||
LL | let sfoo: *mut Foo = &mut SFOO;
|
LL | let sfoo: *mut Foo = &mut SFOO;
|
||||||
| ^^^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let sfoo: *mut Foo = addr_of_mut!(SFOO);
|
LL | let sfoo: *mut Foo = addr_of_mut!(SFOO);
|
||||||
| ~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -12,7 +12,7 @@ fn imm_ref() -> &'static T {
|
||||||
|
|
||||||
fn mut_ref() -> &'static mut T {
|
fn mut_ref() -> &'static mut T {
|
||||||
unsafe { &mut GLOBAL_MUT_T }
|
unsafe { &mut GLOBAL_MUT_T }
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mut_ptr() -> *mut T {
|
fn mut_ptr() -> *mut T {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/issue-20801.rs:14:14
|
--> $DIR/issue-20801.rs:14:14
|
||||||
|
|
|
|
||||||
LL | unsafe { &mut GLOBAL_MUT_T }
|
LL | unsafe { &mut GLOBAL_MUT_T }
|
||||||
| ^^^^^^^^^^^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | unsafe { addr_of_mut!(GLOBAL_MUT_T) }
|
LL | unsafe { addr_of_mut!(GLOBAL_MUT_T) }
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -10,7 +10,7 @@ mod borrowck_closures_unique {
|
||||||
//~^ ERROR is not declared as mutable
|
//~^ ERROR is not declared as mutable
|
||||||
unsafe {
|
unsafe {
|
||||||
c1(&mut Y);
|
c1(&mut Y);
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ mod borrowck_closures_unique_grandparent {
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
c1(&mut Z);
|
c1(&mut Z);
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ fn main() {
|
||||||
static mut X: isize = 2;
|
static mut X: isize = 2;
|
||||||
unsafe {
|
unsafe {
|
||||||
borrowck_closures_unique::e(&mut X);
|
borrowck_closures_unique::e(&mut X);
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
||||||
mutability_errors::capture_assign_whole((1000,));
|
mutability_errors::capture_assign_whole((1000,));
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:12:16
|
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:12:16
|
||||||
|
|
|
|
||||||
LL | c1(&mut Y);
|
LL | c1(&mut Y);
|
||||||
| ^^^^^^ mutable reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | c1(addr_of_mut!(Y));
|
LL | c1(addr_of_mut!(Y));
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16
|
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:27:16
|
||||||
|
|
|
|
||||||
LL | c1(&mut Z);
|
LL | c1(&mut Z);
|
||||||
| ^^^^^^ mutable reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | c1(addr_of_mut!(Z));
|
LL | c1(addr_of_mut!(Z));
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
|
--> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:64:37
|
||||||
|
|
|
|
||||||
LL | borrowck_closures_unique::e(&mut X);
|
LL | borrowck_closures_unique::e(&mut X);
|
||||||
| ^^^^^^ mutable reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | borrowck_closures_unique::e(addr_of_mut!(X));
|
LL | borrowck_closures_unique::e(addr_of_mut!(X));
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -16,7 +16,7 @@ static mut BB: AA = AA::new();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let ptr = unsafe { &mut BB };
|
let ptr = unsafe { &mut BB };
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
for a in ptr.data.iter() {
|
for a in ptr.data.iter() {
|
||||||
println!("{}", a);
|
println!("{}", a);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/const_let_assign2.rs:18:24
|
--> $DIR/const_let_assign2.rs:18:24
|
||||||
|
|
|
|
||||||
LL | let ptr = unsafe { &mut BB };
|
LL | let ptr = unsafe { &mut BB };
|
||||||
| ^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let ptr = unsafe { addr_of_mut!(BB) };
|
LL | let ptr = unsafe { addr_of_mut!(BB) };
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
|
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
|
||||||
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
|
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
|
||||||
#![feature(const_refs_to_static)]
|
#![feature(const_refs_to_static)]
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
fn invalid() {
|
fn invalid() {
|
||||||
static S: i8 = 10;
|
static S: i8 = 10;
|
||||||
|
@ -43,8 +43,8 @@ fn mutable() {
|
||||||
// This *must not build*, the constant we are matching against
|
// This *must not build*, the constant we are matching against
|
||||||
// could change its value!
|
// could change its value!
|
||||||
match &42 {
|
match &42 {
|
||||||
C => {}, //~ERROR: could not evaluate constant pattern
|
C => {} //~ERROR: could not evaluate constant pattern
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ LL | const C: &i32 = unsafe { &S_MUT };
|
||||||
error: could not evaluate constant pattern
|
error: could not evaluate constant pattern
|
||||||
--> $DIR/const_refs_to_static_fail_invalid.rs:46:9
|
--> $DIR/const_refs_to_static_fail_invalid.rs:46:9
|
||||||
|
|
|
|
||||||
LL | C => {},
|
LL | C => {}
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
const C1: &'static mut [usize] = &mut [];
|
const C1: &'static mut [usize] = &mut [];
|
||||||
//~^ ERROR: mutable references are not allowed
|
//~^ ERROR: mutable references are not allowed
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
|
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
|
||||||
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
|
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
|
||||||
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
|
#![feature(exclusive_range_pattern, half_open_range_patterns_in_slices)]
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
extern crate static_cross_crate;
|
extern crate static_cross_crate;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
static mut DATA: u8;
|
static mut DATA: u8;
|
||||||
|
|
|
@ -5,13 +5,13 @@ LL | const MUH: Meh = Meh {
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:27:1
|
--> $DIR/mutable_references_err.rs:28:1
|
||||||
|
|
|
|
||||||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:32:1
|
--> $DIR/mutable_references_err.rs:33:1
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
|
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
|
||||||
|
@ -22,13 +22,13 @@ LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
}
|
}
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:35:1
|
--> $DIR/mutable_references_err.rs:36:1
|
||||||
|
|
|
|
||||||
LL | const BLUNT: &mut i32 = &mut 42;
|
LL | const BLUNT: &mut i32 = &mut 42;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:40:1
|
--> $DIR/mutable_references_err.rs:41:1
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
|
||||||
|
@ -39,7 +39,7 @@ LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const
|
||||||
}
|
}
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:47:1
|
--> $DIR/mutable_references_err.rs:48:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
|
||||||
|
@ -50,49 +50,49 @@ LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
}
|
}
|
||||||
|
|
||||||
note: erroneous constant encountered
|
note: erroneous constant encountered
|
||||||
--> $DIR/mutable_references_err.rs:49:34
|
--> $DIR/mutable_references_err.rs:50:34
|
||||||
|
|
|
|
||||||
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1;
|
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1;
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/mutable_references_err.rs:51:43
|
--> $DIR/mutable_references_err.rs:52:43
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
||||||
| ^^^^^^^^^^^^^ constant accesses mutable global memory
|
| ^^^^^^^^^^^^^ constant accesses mutable global memory
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:55:1
|
--> $DIR/mutable_references_err.rs:56:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:57:1
|
--> $DIR/mutable_references_err.rs:58:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:59:1
|
--> $DIR/mutable_references_err.rs:60:1
|
||||||
|
|
|
|
||||||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:69:1
|
--> $DIR/mutable_references_err.rs:72:1
|
||||||
|
|
|
|
||||||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:71:1
|
--> $DIR/mutable_references_err.rs:74:1
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:73:1
|
--> $DIR/mutable_references_err.rs:76:1
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -100,77 +100,77 @@ LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
warning: skipping const checks
|
warning: skipping const checks
|
||||||
|
|
|
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:18:8
|
--> $DIR/mutable_references_err.rs:19:8
|
||||||
|
|
|
|
||||||
LL | x: &UnsafeCell::new(42),
|
LL | x: &UnsafeCell::new(42),
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:27:27
|
--> $DIR/mutable_references_err.rs:28:27
|
||||||
|
|
|
|
||||||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:32:40
|
--> $DIR/mutable_references_err.rs:33:40
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^
|
| ^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:32:35
|
--> $DIR/mutable_references_err.rs:33:35
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:35:25
|
--> $DIR/mutable_references_err.rs:36:25
|
||||||
|
|
|
|
||||||
LL | const BLUNT: &mut i32 = &mut 42;
|
LL | const BLUNT: &mut i32 = &mut 42;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:40:49
|
--> $DIR/mutable_references_err.rs:41:49
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:40:49
|
--> $DIR/mutable_references_err.rs:41:49
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:47:44
|
--> $DIR/mutable_references_err.rs:48:44
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:51:45
|
--> $DIR/mutable_references_err.rs:52:45
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:55:45
|
--> $DIR/mutable_references_err.rs:56:45
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:57:46
|
--> $DIR/mutable_references_err.rs:58:46
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:59:47
|
--> $DIR/mutable_references_err.rs:60:47
|
||||||
|
|
|
|
||||||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:69:51
|
--> $DIR/mutable_references_err.rs:72:51
|
||||||
|
|
|
|
||||||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:71:50
|
--> $DIR/mutable_references_err.rs:74:49
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:73:51
|
--> $DIR/mutable_references_err.rs:76:51
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
@ -5,13 +5,13 @@ LL | const MUH: Meh = Meh {
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:27:1
|
--> $DIR/mutable_references_err.rs:28:1
|
||||||
|
|
|
|
||||||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:32:1
|
--> $DIR/mutable_references_err.rs:33:1
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
|
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference in a `const` or `static`
|
||||||
|
@ -22,13 +22,13 @@ LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
}
|
}
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:35:1
|
--> $DIR/mutable_references_err.rs:36:1
|
||||||
|
|
|
|
||||||
LL | const BLUNT: &mut i32 = &mut 42;
|
LL | const BLUNT: &mut i32 = &mut 42;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:40:1
|
--> $DIR/mutable_references_err.rs:41:1
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory
|
||||||
|
@ -39,7 +39,7 @@ LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const
|
||||||
}
|
}
|
||||||
|
|
||||||
error[E0080]: it is undefined behavior to use this value
|
error[E0080]: it is undefined behavior to use this value
|
||||||
--> $DIR/mutable_references_err.rs:47:1
|
--> $DIR/mutable_references_err.rs:48:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const`
|
||||||
|
@ -50,49 +50,49 @@ LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
}
|
}
|
||||||
|
|
||||||
note: erroneous constant encountered
|
note: erroneous constant encountered
|
||||||
--> $DIR/mutable_references_err.rs:49:34
|
--> $DIR/mutable_references_err.rs:50:34
|
||||||
|
|
|
|
||||||
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1;
|
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1;
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0080]: evaluation of constant value failed
|
error[E0080]: evaluation of constant value failed
|
||||||
--> $DIR/mutable_references_err.rs:51:43
|
--> $DIR/mutable_references_err.rs:52:43
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
||||||
| ^^^^^^^^^^^^^ constant accesses mutable global memory
|
| ^^^^^^^^^^^^^ constant accesses mutable global memory
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:55:1
|
--> $DIR/mutable_references_err.rs:56:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:57:1
|
--> $DIR/mutable_references_err.rs:58:1
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:59:1
|
--> $DIR/mutable_references_err.rs:60:1
|
||||||
|
|
|
|
||||||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:69:1
|
--> $DIR/mutable_references_err.rs:72:1
|
||||||
|
|
|
|
||||||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:71:1
|
--> $DIR/mutable_references_err.rs:74:1
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: encountered mutable pointer in final value of constant
|
error: encountered mutable pointer in final value of constant
|
||||||
--> $DIR/mutable_references_err.rs:73:1
|
--> $DIR/mutable_references_err.rs:76:1
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -100,77 +100,77 @@ LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
warning: skipping const checks
|
warning: skipping const checks
|
||||||
|
|
|
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:18:8
|
--> $DIR/mutable_references_err.rs:19:8
|
||||||
|
|
|
|
||||||
LL | x: &UnsafeCell::new(42),
|
LL | x: &UnsafeCell::new(42),
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:27:27
|
--> $DIR/mutable_references_err.rs:28:27
|
||||||
|
|
|
|
||||||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:32:40
|
--> $DIR/mutable_references_err.rs:33:40
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^
|
| ^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:32:35
|
--> $DIR/mutable_references_err.rs:33:35
|
||||||
|
|
|
|
||||||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO };
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:35:25
|
--> $DIR/mutable_references_err.rs:36:25
|
||||||
|
|
|
|
||||||
LL | const BLUNT: &mut i32 = &mut 42;
|
LL | const BLUNT: &mut i32 = &mut 42;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:40:49
|
--> $DIR/mutable_references_err.rs:41:49
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_mut_refs` feature
|
help: skipping check for `const_mut_refs` feature
|
||||||
--> $DIR/mutable_references_err.rs:40:49
|
--> $DIR/mutable_references_err.rs:41:49
|
||||||
|
|
|
|
||||||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:47:44
|
--> $DIR/mutable_references_err.rs:48:44
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE };
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check for `const_refs_to_static` feature
|
help: skipping check for `const_refs_to_static` feature
|
||||||
--> $DIR/mutable_references_err.rs:51:45
|
--> $DIR/mutable_references_err.rs:52:45
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF };
|
||||||
| ^^^^^^^^^^^
|
| ^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:55:45
|
--> $DIR/mutable_references_err.rs:56:45
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:57:46
|
--> $DIR/mutable_references_err.rs:58:46
|
||||||
|
|
|
|
||||||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:59:47
|
--> $DIR/mutable_references_err.rs:60:47
|
||||||
|
|
|
|
||||||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:69:51
|
--> $DIR/mutable_references_err.rs:72:51
|
||||||
|
|
|
|
||||||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:71:50
|
--> $DIR/mutable_references_err.rs:74:49
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
|
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
help: skipping check that does not even have a feature gate
|
help: skipping check that does not even have a feature gate
|
||||||
--> $DIR/mutable_references_err.rs:73:51
|
--> $DIR/mutable_references_err.rs:76:51
|
||||||
|
|
|
|
||||||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
//@ stderr-per-bitwidth
|
//@ stderr-per-bitwidth
|
||||||
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
#![allow(invalid_reference_casting, static_mut_ref)]
|
#![allow(invalid_reference_casting, static_mut_refs)]
|
||||||
|
|
||||||
use std::sync::atomic::*;
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
|
use std::sync::atomic::*;
|
||||||
|
|
||||||
// this test ensures that our mutability story is sound
|
// this test ensures that our mutability story is sound
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ unsafe impl Sync for Meh {}
|
||||||
|
|
||||||
// the following will never be ok! no interior mut behind consts, because
|
// the following will never be ok! no interior mut behind consts, because
|
||||||
// all allocs interned here will be marked immutable.
|
// all allocs interned here will be marked immutable.
|
||||||
const MUH: Meh = Meh { //~ ERROR: mutable pointer in final value
|
const MUH: Meh = Meh {
|
||||||
|
//~^ ERROR encountered mutable pointer in final value of constant
|
||||||
x: &UnsafeCell::new(42),
|
x: &UnsafeCell::new(42),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -59,7 +60,9 @@ const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _;
|
||||||
const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
//~^ ERROR: mutable pointer in final value
|
//~^ ERROR: mutable pointer in final value
|
||||||
|
|
||||||
struct SyncPtr<T> { x : *const T }
|
struct SyncPtr<T> {
|
||||||
|
x: *const T,
|
||||||
|
}
|
||||||
unsafe impl<T> Sync for SyncPtr<T> {}
|
unsafe impl<T> Sync for SyncPtr<T> {}
|
||||||
|
|
||||||
// These pass the lifetime checks because of the "tail expression" / "outer scope" rule.
|
// These pass the lifetime checks because of the "tail expression" / "outer scope" rule.
|
||||||
|
@ -68,7 +71,7 @@ unsafe impl<T> Sync for SyncPtr<T> {}
|
||||||
// (Also see `static-no-inner-mut` for similar tests on `static`.)
|
// (Also see `static-no-inner-mut` for similar tests on `static`.)
|
||||||
const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) };
|
||||||
//~^ ERROR mutable pointer in final value
|
//~^ ERROR mutable pointer in final value
|
||||||
const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
|
const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ };
|
||||||
//~^ ERROR mutable pointer in final value
|
//~^ ERROR mutable pointer in final value
|
||||||
const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 };
|
||||||
//~^ ERROR mutable pointer in final value
|
//~^ ERROR mutable pointer in final value
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//@ check-pass
|
//@ check-pass
|
||||||
#![allow(non_camel_case_types, non_upper_case_globals, static_mut_ref)]
|
|
||||||
|
#![allow(non_camel_case_types, non_upper_case_globals, static_mut_refs)]
|
||||||
|
|
||||||
pub struct wl_interface {
|
pub struct wl_interface {
|
||||||
pub version: i32
|
pub version: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Interface {
|
pub struct Interface {
|
||||||
|
@ -10,20 +11,14 @@ pub struct Interface {
|
||||||
pub c_ptr: Option<&'static wl_interface>,
|
pub c_ptr: Option<&'static wl_interface>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static mut wl_callback_interface: wl_interface = wl_interface {
|
pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };
|
||||||
version: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub static WL_CALLBACK_INTERFACE: Interface = Interface {
|
pub static WL_CALLBACK_INTERFACE: Interface =
|
||||||
other_interfaces: &[],
|
Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) };
|
||||||
c_ptr: Some(unsafe { &wl_callback_interface }),
|
|
||||||
};
|
|
||||||
|
|
||||||
// This static contains a promoted that points to a static that points to a mutable static.
|
// This static contains a promoted that points to a static that points to a mutable static.
|
||||||
pub static WL_SURFACE_INTERFACE: Interface = Interface {
|
pub static WL_SURFACE_INTERFACE: Interface =
|
||||||
other_interfaces: &[&WL_CALLBACK_INTERFACE],
|
Interface { other_interfaces: &[&WL_CALLBACK_INTERFACE], c_ptr: None };
|
||||||
c_ptr: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
// And another variant of the same thing, this time with interior mutability.
|
// And another variant of the same thing, this time with interior mutability.
|
||||||
use std::sync::OnceLock;
|
use std::sync::OnceLock;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//@ build-pass (FIXME(62277): could be check-pass?)
|
//@ build-pass (FIXME(62277): could be check-pass?)
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
static mut STDERR_BUFFER_SPACE: [u8; 42] = [0u8; 42];
|
static mut STDERR_BUFFER_SPACE: [u8; 42] = [0u8; 42];
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//@ revisions: stock mut_refs
|
//@ revisions: stock mut_refs
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||||
|
|
||||||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||||
|
|
|
@ -91,7 +91,7 @@ pub mod d {
|
||||||
pub fn max_width() -> u32 {
|
pub fn max_width() -> u32 {
|
||||||
unsafe {
|
unsafe {
|
||||||
(mem::size_of_val(&trails) * 8) as u32
|
(mem::size_of_val(&trails) * 8) as u32
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/issue-23338-ensure-param-drop-order.rs:93:31
|
--> $DIR/issue-23338-ensure-param-drop-order.rs:93:31
|
||||||
|
|
|
|
||||||
LL | (mem::size_of_val(&trails) * 8) as u32
|
LL | (mem::size_of_val(&trails) * 8) as u32
|
||||||
| ^^^^^^^ shared reference of mutable static
|
| ^^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
|
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -13,6 +13,6 @@ static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are no
|
||||||
//~| WARN taking a mutable
|
//~| WARN taking a mutable
|
||||||
|
|
||||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/E0017.rs:15:52
|
--> $DIR/E0017.rs:15:52
|
||||||
|
|
|
|
||||||
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
||||||
| ^^^^^^ mutable reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { addr_of_mut!(M) };
|
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { addr_of_mut!(M) };
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -187,7 +187,7 @@ pub mod d {
|
||||||
pub fn max_width() -> u32 {
|
pub fn max_width() -> u32 {
|
||||||
unsafe {
|
unsafe {
|
||||||
(mem::size_of_val(&trails) * 8) as u32
|
(mem::size_of_val(&trails) * 8) as u32
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/issue-23611-enum-swap-in-drop.rs:189:31
|
--> $DIR/issue-23611-enum-swap-in-drop.rs:189:31
|
||||||
|
|
|
|
||||||
LL | (mem::size_of_val(&trails) * 8) as u32
|
LL | (mem::size_of_val(&trails) * 8) as u32
|
||||||
| ^^^^^^^ shared reference of mutable static
|
| ^^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
|
LL | (mem::size_of_val(addr_of!(trails)) * 8) as u32
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -5,5 +5,5 @@ extern "C" {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{:p}", unsafe { &symbol });
|
println!("{:p}", unsafe { &symbol });
|
||||||
//~^ WARN: shared reference of mutable static is discouraged
|
//~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,17 @@ LL | pub static mut symbol: [i8];
|
||||||
|
|
|
|
||||||
= help: the trait `Sized` is not implemented for `[i8]`
|
= help: the trait `Sized` is not implemented for `[i8]`
|
||||||
|
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/issue-54410.rs:7:31
|
--> $DIR/issue-54410.rs:7:31
|
||||||
|
|
|
|
||||||
LL | println!("{:p}", unsafe { &symbol });
|
LL | println!("{:p}", unsafe { &symbol });
|
||||||
| ^^^^^^^ shared reference of mutable static
|
| ^^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | println!("{:p}", unsafe { addr_of!(symbol) });
|
LL | println!("{:p}", unsafe { addr_of!(symbol) });
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct S1 {
|
||||||
impl S1 {
|
impl S1 {
|
||||||
fn new(_x: u64) -> S1 {
|
fn new(_x: u64) -> S1 {
|
||||||
S1 { a: unsafe { &mut X1 } }
|
S1 { a: unsafe { &mut X1 } }
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/borrowck-thread-local-static-mut-borrow-outlives-fn.rs:17:26
|
--> $DIR/borrowck-thread-local-static-mut-borrow-outlives-fn.rs:17:26
|
||||||
|
|
|
|
||||||
LL | S1 { a: unsafe { &mut X1 } }
|
LL | S1 { a: unsafe { &mut X1 } }
|
||||||
| ^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | S1 { a: unsafe { addr_of_mut!(X1) } }
|
LL | S1 { a: unsafe { addr_of_mut!(X1) } }
|
||||||
| ~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
|
||||||
--> $DIR/reference-of-mut-static-safe.rs:9:14
|
|
||||||
|
|
|
||||||
LL | let _x = &X;
|
|
||||||
| ^^ shared reference of mutable static
|
|
||||||
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
|
||||||
|
|
|
||||||
LL | let _x = addr_of!(X);
|
|
||||||
| ~~~~~~~~~~~
|
|
||||||
|
|
||||||
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
|
|
||||||
--> $DIR/reference-of-mut-static-safe.rs:9:15
|
|
||||||
|
|
|
||||||
LL | let _x = &X;
|
|
||||||
| ^ use of mutable static
|
|
||||||
|
|
|
||||||
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error; 1 warning emitted
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0133`.
|
|
|
@ -1,15 +0,0 @@
|
||||||
error[E0796]: reference of mutable static is disallowed
|
|
||||||
--> $DIR/reference-of-mut-static-safe.rs:9:14
|
|
||||||
|
|
|
||||||
LL | let _x = &X;
|
|
||||||
| ^^ reference of mutable static
|
|
||||||
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
|
||||||
|
|
|
||||||
LL | let _x = addr_of!(X);
|
|
||||||
| ~~~~~~~~~~~
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0796`.
|
|
|
@ -7,17 +7,20 @@ unsafe fn _foo() {
|
||||||
static mut Y: i32 = 1;
|
static mut Y: i32 = 1;
|
||||||
|
|
||||||
let _y = &X;
|
let _y = &X;
|
||||||
//~^ ERROR reference of mutable static is disallowed
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
|
||||||
let ref _a = X;
|
let ref _a = X;
|
||||||
//~^ ERROR reference of mutable static is disallowed
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
|
||||||
let (_b, _c) = (&X, &Y);
|
let ref mut _a = X;
|
||||||
//~^ ERROR reference of mutable static is disallowed
|
//~^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
//~^^ ERROR reference of mutable static is disallowed
|
|
||||||
|
let (_b, _c) = (&X, &mut Y);
|
||||||
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//~^^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
|
|
||||||
foo(&X);
|
foo(&X);
|
||||||
//~^ ERROR reference of mutable static is disallowed
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo<'a>(_x: &'a i32) {}
|
fn foo<'a>(_x: &'a i32) {}
|
||||||
|
|
|
@ -1,63 +1,75 @@
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static-unsafe-fn.rs:9:14
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:9:14
|
||||||
|
|
|
|
||||||
LL | let _y = &X;
|
LL | let _y = &X;
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y = addr_of!(X);
|
LL | let _y = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static-unsafe-fn.rs:12:18
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:12:18
|
||||||
|
|
|
|
||||||
LL | let ref _a = X;
|
LL | let ref _a = X;
|
||||||
| ^ reference of mutable static
|
| ^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let ref _a = addr_of!(X);
|
LL | let ref _a = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static-unsafe-fn.rs:15:21
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:15:22
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let ref mut _a = X;
|
||||||
| ^^ reference of mutable static
|
| ^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (addr_of!(X), &Y);
|
LL | let ref mut _a = addr_of_mut!(X);
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:18:21
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &mut Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (addr_of!(X), &mut Y);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static-unsafe-fn.rs:15:25
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:18:25
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let (_b, _c) = (&X, &mut Y);
|
||||||
| ^^ reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, addr_of!(Y));
|
LL | let (_b, _c) = (&X, addr_of_mut!(Y));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static-unsafe-fn.rs:19:9
|
--> $DIR/reference-of-mut-static-unsafe-fn.rs:22:9
|
||||||
|
|
|
|
||||||
LL | foo(&X);
|
LL | foo(&X);
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | foo(addr_of!(X));
|
LL | foo(addr_of!(X));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0796`.
|
For more information about this error, try `rustc --explain E0796`.
|
||||||
|
|
|
@ -1,88 +1,88 @@
|
||||||
error: shared reference of mutable static is discouraged
|
error: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:16:18
|
--> $DIR/reference-of-mut-static.rs:16:18
|
||||||
|
|
|
|
||||||
LL | let _y = &X;
|
LL | let _y = &X;
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/reference-of-mut-static.rs:6:9
|
--> $DIR/reference-of-mut-static.rs:6:9
|
||||||
|
|
|
|
||||||
LL | #![deny(static_mut_ref)]
|
LL | #![deny(static_mut_refs)]
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y = addr_of!(X);
|
LL | let _y = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: mutable reference of mutable static is discouraged
|
error: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:20:18
|
--> $DIR/reference-of-mut-static.rs:20:18
|
||||||
|
|
|
|
||||||
LL | let _y = &mut X;
|
LL | let _y = &mut X;
|
||||||
| ^^^^^^ mutable reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y = addr_of_mut!(X);
|
LL | let _y = addr_of_mut!(X);
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: shared reference of mutable static is discouraged
|
error: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:28:22
|
--> $DIR/reference-of-mut-static.rs:28:22
|
||||||
|
|
|
|
||||||
LL | let ref _a = X;
|
LL | let ref _a = X;
|
||||||
| ^ shared reference of mutable static
|
| ^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let ref _a = addr_of!(X);
|
LL | let ref _a = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: shared reference of mutable static is discouraged
|
error: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:32:25
|
--> $DIR/reference-of-mut-static.rs:32:25
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (addr_of!(X), &Y);
|
LL | let (_b, _c) = (addr_of!(X), &Y);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: shared reference of mutable static is discouraged
|
error: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:32:29
|
--> $DIR/reference-of-mut-static.rs:32:29
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, addr_of!(Y));
|
LL | let (_b, _c) = (&X, addr_of!(Y));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: shared reference of mutable static is discouraged
|
error: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/reference-of-mut-static.rs:38:13
|
--> $DIR/reference-of-mut-static.rs:38:13
|
||||||
|
|
|
|
||||||
LL | foo(&X);
|
LL | foo(&X);
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | foo(addr_of!(X));
|
LL | foo(addr_of!(X));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
|
@ -1,71 +1,71 @@
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:16:18
|
--> $DIR/reference-of-mut-static.rs:16:18
|
||||||
|
|
|
|
||||||
LL | let _y = &X;
|
LL | let _y = &X;
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y = addr_of!(X);
|
LL | let _y = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:20:18
|
--> $DIR/reference-of-mut-static.rs:20:18
|
||||||
|
|
|
|
||||||
LL | let _y = &mut X;
|
LL | let _y = &mut X;
|
||||||
| ^^^^^^ reference of mutable static
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let _y = addr_of_mut!(X);
|
LL | let _y = addr_of_mut!(X);
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:28:22
|
--> $DIR/reference-of-mut-static.rs:28:22
|
||||||
|
|
|
|
||||||
LL | let ref _a = X;
|
LL | let ref _a = X;
|
||||||
| ^ reference of mutable static
|
| ^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let ref _a = addr_of!(X);
|
LL | let ref _a = addr_of!(X);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:32:25
|
--> $DIR/reference-of-mut-static.rs:32:25
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (addr_of!(X), &Y);
|
LL | let (_b, _c) = (addr_of!(X), &Y);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:32:29
|
--> $DIR/reference-of-mut-static.rs:32:29
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, &Y);
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let (_b, _c) = (&X, addr_of!(Y));
|
LL | let (_b, _c) = (&X, addr_of!(Y));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0796]: reference of mutable static is disallowed
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
--> $DIR/reference-of-mut-static.rs:38:13
|
--> $DIR/reference-of-mut-static.rs:38:13
|
||||||
|
|
|
|
||||||
LL | foo(&X);
|
LL | foo(&X);
|
||||||
| ^^ reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | foo(addr_of!(X));
|
LL | foo(addr_of!(X));
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//@ [e2021] edition:2021
|
//@ [e2021] edition:2021
|
||||||
//@ [e2024] compile-flags: --edition 2024 -Z unstable-options
|
//@ [e2024] compile-flags: --edition 2024 -Z unstable-options
|
||||||
|
|
||||||
#![deny(static_mut_ref)]
|
#![deny(static_mut_refs)]
|
||||||
|
|
||||||
use std::ptr::{addr_of, addr_of_mut};
|
use std::ptr::{addr_of, addr_of_mut};
|
||||||
|
|
||||||
|
@ -14,30 +14,30 @@ fn main() {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let _y = &X;
|
let _y = &X;
|
||||||
//[e2024]~^ ERROR reference of mutable static is disallowed
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
let _y = &mut X;
|
let _y = &mut X;
|
||||||
//[e2024]~^ ERROR reference of mutable static is disallowed
|
//[e2024]~^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ ERROR mutable reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
let _z = addr_of_mut!(X);
|
let _z = addr_of_mut!(X);
|
||||||
|
|
||||||
let _p = addr_of!(X);
|
let _p = addr_of!(X);
|
||||||
|
|
||||||
let ref _a = X;
|
let ref _a = X;
|
||||||
//[e2024]~^ ERROR reference of mutable static is disallowed
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
let (_b, _c) = (&X, &Y);
|
let (_b, _c) = (&X, &Y);
|
||||||
//[e2024]~^ ERROR reference of mutable static is disallowed
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
//[e2024]~^^^ ERROR reference of mutable static is disallowed
|
//[e2024]~^^^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
foo(&X);
|
foo(&X);
|
||||||
//[e2024]~^ ERROR reference of mutable static is disallowed
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
static mut Z: &[i32; 3] = &[0, 1, 2];
|
static mut Z: &[i32; 3] = &[0, 1, 2];
|
||||||
|
|
||||||
|
|
26
tests/ui/static/reference-to-mut-static-safe.e2021.stderr
Normal file
26
tests/ui/static/reference-to-mut-static-safe.e2021.stderr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static-safe.rs:9:14
|
||||||
|
|
|
||||||
|
LL | let _x = &X;
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _x = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
|
||||||
|
--> $DIR/reference-to-mut-static-safe.rs:9:15
|
||||||
|
|
|
||||||
|
LL | let _x = &X;
|
||||||
|
| ^ use of mutable static
|
||||||
|
|
|
||||||
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error; 1 warning emitted
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0133`.
|
15
tests/ui/static/reference-to-mut-static-safe.e2024.stderr
Normal file
15
tests/ui/static/reference-to-mut-static-safe.e2024.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-safe.rs:9:14
|
||||||
|
|
|
||||||
|
LL | let _x = &X;
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _x = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0796`.
|
|
@ -7,7 +7,7 @@ fn main() {
|
||||||
static mut X: i32 = 1;
|
static mut X: i32 = 1;
|
||||||
|
|
||||||
let _x = &X;
|
let _x = &X;
|
||||||
//[e2024]~^ reference of mutable static is disallowed [E0796]
|
//[e2024]~^ creating a shared reference to a mutable static [E0796]
|
||||||
//[e2021]~^^ use of mutable static is unsafe and requires unsafe function or block [E0133]
|
//[e2021]~^^ use of mutable static is unsafe and requires unsafe function or block [E0133]
|
||||||
//[e2021]~^^^ shared reference of mutable static is discouraged [static_mut_ref]
|
//[e2021]~^^^ shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
26
tests/ui/static/reference-to-mut-static-unsafe-fn.rs
Normal file
26
tests/ui/static/reference-to-mut-static-unsafe-fn.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
//@ compile-flags: --edition 2024 -Z unstable-options
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
|
|
||||||
|
unsafe fn _foo() {
|
||||||
|
static mut X: i32 = 1;
|
||||||
|
static mut Y: i32 = 1;
|
||||||
|
|
||||||
|
let _y = &X;
|
||||||
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
|
||||||
|
let ref _a = X;
|
||||||
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
|
||||||
|
let ref mut _a = X;
|
||||||
|
//~^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
|
|
||||||
|
let (_b, _c) = (&X, &mut Y);
|
||||||
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//~^^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
|
|
||||||
|
foo(&X);
|
||||||
|
//~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo<'a>(_x: &'a i32) {}
|
75
tests/ui/static/reference-to-mut-static-unsafe-fn.stderr
Normal file
75
tests/ui/static/reference-to-mut-static-unsafe-fn.stderr
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:9:14
|
||||||
|
|
|
||||||
|
LL | let _y = &X;
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _y = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:12:18
|
||||||
|
|
|
||||||
|
LL | let ref _a = X;
|
||||||
|
| ^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let ref _a = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:15:22
|
||||||
|
|
|
||||||
|
LL | let ref mut _a = X;
|
||||||
|
| ^ mutable reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let ref mut _a = addr_of_mut!(X);
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:18:21
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &mut Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (addr_of!(X), &mut Y);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:18:25
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &mut Y);
|
||||||
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, addr_of_mut!(Y));
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static-unsafe-fn.rs:22:9
|
||||||
|
|
|
||||||
|
LL | foo(&X);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | foo(addr_of!(X));
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0796`.
|
91
tests/ui/static/reference-to-mut-static.e2021.stderr
Normal file
91
tests/ui/static/reference-to-mut-static.e2021.stderr
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
error: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:16:18
|
||||||
|
|
|
||||||
|
LL | let _y = &X;
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/reference-to-mut-static.rs:6:9
|
||||||
|
|
|
||||||
|
LL | #![deny(static_mut_refs)]
|
||||||
|
| ^^^^^^^^^^^^^^^
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _y = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: creating a mutable reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:20:18
|
||||||
|
|
|
||||||
|
LL | let _y = &mut X;
|
||||||
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _y = addr_of_mut!(X);
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:28:22
|
||||||
|
|
|
||||||
|
LL | let ref _a = X;
|
||||||
|
| ^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let ref _a = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:32:25
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (addr_of!(X), &Y);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:32:29
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, addr_of!(Y));
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: creating a shared reference to mutable static is discouraged
|
||||||
|
--> $DIR/reference-to-mut-static.rs:38:13
|
||||||
|
|
|
||||||
|
LL | foo(&X);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
|
= note: this will be a hard error in the 2024 edition
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | foo(addr_of!(X));
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
75
tests/ui/static/reference-to-mut-static.e2024.stderr
Normal file
75
tests/ui/static/reference-to-mut-static.e2024.stderr
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:16:18
|
||||||
|
|
|
||||||
|
LL | let _y = &X;
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _y = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a mutable reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:20:18
|
||||||
|
|
|
||||||
|
LL | let _y = &mut X;
|
||||||
|
| ^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let _y = addr_of_mut!(X);
|
||||||
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:28:22
|
||||||
|
|
|
||||||
|
LL | let ref _a = X;
|
||||||
|
| ^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let ref _a = addr_of!(X);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:32:25
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (addr_of!(X), &Y);
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:32:29
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, &Y);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | let (_b, _c) = (&X, addr_of!(Y));
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0796]: creating a shared reference to a mutable static
|
||||||
|
--> $DIR/reference-to-mut-static.rs:38:13
|
||||||
|
|
|
||||||
|
LL | foo(&X);
|
||||||
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
||||||
|
= note: 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
|
||||||
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
||||||
|
LL | foo(addr_of!(X));
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0796`.
|
50
tests/ui/static/reference-to-mut-static.rs
Normal file
50
tests/ui/static/reference-to-mut-static.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
//@ revisions: e2021 e2024
|
||||||
|
|
||||||
|
//@ [e2021] edition:2021
|
||||||
|
//@ [e2024] compile-flags: --edition 2024 -Z unstable-options
|
||||||
|
|
||||||
|
#![deny(static_mut_refs)]
|
||||||
|
|
||||||
|
use std::ptr::{addr_of, addr_of_mut};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
static mut X: i32 = 1;
|
||||||
|
|
||||||
|
static mut Y: i32 = 1;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let _y = &X;
|
||||||
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
|
let _y = &mut X;
|
||||||
|
//[e2024]~^ ERROR creating a mutable reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
|
let _z = addr_of_mut!(X);
|
||||||
|
|
||||||
|
let _p = addr_of!(X);
|
||||||
|
|
||||||
|
let ref _a = X;
|
||||||
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
|
let (_b, _c) = (&X, &Y);
|
||||||
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
//[e2024]~^^^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
|
foo(&X);
|
||||||
|
//[e2024]~^ ERROR creating a shared reference to a mutable static [E0796]
|
||||||
|
//[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
|
static mut Z: &[i32; 3] = &[0, 1, 2];
|
||||||
|
|
||||||
|
let _ = Z.len();
|
||||||
|
let _ = Z[0];
|
||||||
|
let _ = format!("{:?}", Z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo<'a>(_x: &'a i32) {}
|
|
@ -10,8 +10,8 @@ extern "C" {
|
||||||
fn main() {
|
fn main() {
|
||||||
let b = B; //~ ERROR use of mutable static is unsafe
|
let b = B; //~ ERROR use of mutable static is unsafe
|
||||||
let rb = &B; //~ ERROR use of mutable static is unsafe
|
let rb = &B; //~ ERROR use of mutable static is unsafe
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
let xb = XB; //~ ERROR use of mutable static is unsafe
|
let xb = XB; //~ ERROR use of mutable static is unsafe
|
||||||
let xrb = &XB; //~ ERROR use of mutable static is unsafe
|
let xrb = &XB; //~ ERROR use of mutable static is unsafe
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/safe-extern-statics-mut.rs:12:14
|
--> $DIR/safe-extern-statics-mut.rs:12:14
|
||||||
|
|
|
|
||||||
LL | let rb = &B;
|
LL | let rb = &B;
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let rb = addr_of!(B);
|
LL | let rb = addr_of!(B);
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/safe-extern-statics-mut.rs:15:15
|
--> $DIR/safe-extern-statics-mut.rs:15:15
|
||||||
|
|
|
|
||||||
LL | let xrb = &XB;
|
LL | let xrb = &XB;
|
||||||
| ^^^ shared reference of mutable static
|
| ^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | let xrb = addr_of!(XB);
|
LL | let xrb = addr_of!(XB);
|
||||||
| ~~~~~~~~~~~~
|
| ~~~~~~~~~~~~
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
static mut n_mut: usize = 0;
|
static mut n_mut: usize = 0;
|
||||||
|
|
||||||
static n: &'static usize = unsafe { &n_mut };
|
static n: &'static usize = unsafe { &n_mut };
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/issue-15261.rs:9:37
|
--> $DIR/issue-15261.rs:9:37
|
||||||
|
|
|
|
||||||
LL | static n: &'static usize = unsafe { &n_mut };
|
LL | static n: &'static usize = unsafe { &n_mut };
|
||||||
| ^^^^^^ shared reference of mutable static
|
| ^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static n: &'static usize = unsafe { addr_of!(n_mut) };
|
LL | static n: &'static usize = unsafe { addr_of!(n_mut) };
|
||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -26,9 +26,9 @@ unsafe fn run() {
|
||||||
static_mut_xc::a = -3;
|
static_mut_xc::a = -3;
|
||||||
assert_eq!(static_mut_xc::a, -3);
|
assert_eq!(static_mut_xc::a, -3);
|
||||||
static_bound(&static_mut_xc::a);
|
static_bound(&static_mut_xc::a);
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
static_bound_set(&mut static_mut_xc::a);
|
static_bound_set(&mut static_mut_xc::a);
|
||||||
//~^ WARN mutable reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN mutable reference to mutable static is discouraged [static_mut_refs]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/static-mut-xc.rs:28:18
|
--> $DIR/static-mut-xc.rs:28:18
|
||||||
|
|
|
|
||||||
LL | static_bound(&static_mut_xc::a);
|
LL | static_bound(&static_mut_xc::a);
|
||||||
| ^^^^^^^^^^^^^^^^^ shared reference of mutable static
|
| ^^^^^^^^^^^^^^^^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static_bound(addr_of!(static_mut_xc::a));
|
LL | static_bound(addr_of!(static_mut_xc::a));
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
warning: mutable reference of mutable static is discouraged
|
warning: creating a mutable reference to mutable static is discouraged
|
||||||
--> $DIR/static-mut-xc.rs:30:22
|
--> $DIR/static-mut-xc.rs:30:22
|
||||||
|
|
|
|
||||||
LL | static_bound_set(&mut static_mut_xc::a);
|
LL | static_bound_set(&mut static_mut_xc::a);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ mutable reference of mutable static
|
| ^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
help: use `addr_of_mut!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static_bound_set(addr_of_mut!(static_mut_xc::a));
|
LL | static_bound_set(addr_of_mut!(static_mut_xc::a));
|
||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//@ run-pass
|
//@ run-pass
|
||||||
|
|
||||||
static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
||||||
//~^ WARN shared reference of mutable static is discouraged [static_mut_ref]
|
//~^ WARN shared reference to mutable static is discouraged [static_mut_refs]
|
||||||
|
|
||||||
struct StaticDoubleLinked {
|
struct StaticDoubleLinked {
|
||||||
prev: &'static StaticDoubleLinked,
|
prev: &'static StaticDoubleLinked,
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
warning: shared reference of mutable static is discouraged
|
warning: creating a shared reference to mutable static is discouraged
|
||||||
--> $DIR/static-recursive.rs:3:36
|
--> $DIR/static-recursive.rs:3:36
|
||||||
|
|
|
|
||||||
LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
LL | static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };
|
||||||
| ^^ shared reference of mutable static
|
| ^^ shared reference to mutable static
|
||||||
|
|
|
|
||||||
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
|
||||||
= note: reference of mutable static is a hard error from 2024 edition
|
= note: this will be a hard error in the 2024 edition
|
||||||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
|
= note: 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
|
||||||
= note: `#[warn(static_mut_ref)]` on by default
|
= note: `#[warn(static_mut_refs)]` on by default
|
||||||
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
help: use `addr_of!` instead to create a raw pointer
|
||||||
|
|
|
|
||||||
LL | static mut S: *const u8 = unsafe { addr_of!(S) as *const *const u8 as *const u8 };
|
LL | static mut S: *const u8 = unsafe { addr_of!(S) as *const *const u8 as *const u8 };
|
||||||
| ~~~~~~~~~~~
|
| ~~~~~~~~~~~
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
#![feature(const_swap)]
|
#![feature(const_swap)]
|
||||||
#![allow(static_mut_ref)]
|
#![allow(static_mut_refs)]
|
||||||
|
|
||||||
#[thread_local]
|
#[thread_local]
|
||||||
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
|
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue