rust/tests/ui/static/reference-to-mut-static-unsafe-fn.stderr
Obei Sideg 408eeae59d Improve wording of static_mut_ref
Rename `static_mut_ref` lint to `static_mut_refs`.
2024-02-18 06:01:40 +03:00

75 lines
3.4 KiB
Text

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`.