Content-Length: 13132 | pFad | https://doc.rust-lang.org/reference/../../std/../error_codes/./E0796.html

E0796 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0796

Note: this error code is no longer emitted by the compiler.

You have created a reference to a mutable static.

Erroneous code example:

#![allow(unused)]
fn main() {
static mut X: i32 = 23;
fn work() {
  let _val = unsafe { X };
}
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;
}

A reference to a mutable static has lifetime 'static. This is very dangerous as it is easy to accidentally overlap the lifetime of that reference with other, conflicting accesses to the same static.

References to mutable statics are a hard error in the 2024 edition.









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/reference/../../std/../error_codes/./E0796.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy