Rust errors / Everything else
Rust compiler error · checked with rustc 1.99.0
Rust error E0796: #### Note: this error code is no longer emitted by the compiler
What it means#### Note: this error code is no longer emitted by the compiler.
Retired: rustc no longer emits this error code. You may still see it in old answers, books and CI logs from older toolchains; the explanation below is kept for reference.
The compiler team's explanation
Note: this error code is no longer emitted by the compiler.
You have created a reference to a mutable static.
Erroneous code example:
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.
From rustc --explain E0796 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0061this function takes N arguments but M were supplied
- E0412cannot find type in this scope
- E0515cannot return reference to local variable
- E0728await is only allowed inside async functions and blocks
- E0787naked functions must contain a single `naked_asm!` invocation
- E0793reference to field of packed struct is unaligned
- E0797base expression required after `..`
- E0798arguments for `"cmse-nonsecure-call"` function too large to pass via registers
Up next
Often hit nextE0061: this function takes N arguments but M were suppliedA related error from the same family.Read it next →Did this answer your question?