mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
408eeae59d
Rename `static_mut_ref` lint to `static_mut_refs`.
80 lines
3.1 KiB
Plaintext
80 lines
3.1 KiB
Plaintext
warning: creating a mutable reference to mutable static is discouraged
|
|
--> $DIR/borrowck-access-permissions.rs:18:23
|
|
|
|
|
LL | let _y2 = &mut static_x_mut;
|
|
| ^^^^^^^^^^^^^^^^^ 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
|
|
= note: `#[warn(static_mut_refs)]` on by default
|
|
help: use `addr_of_mut!` instead to create a raw pointer
|
|
|
|
|
LL | let _y2 = addr_of_mut!(static_x_mut);
|
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
|
|
--> $DIR/borrowck-access-permissions.rs:10:19
|
|
|
|
|
LL | let _y1 = &mut x;
|
|
| ^^^^^^ cannot borrow as mutable
|
|
|
|
|
help: consider changing this to be mutable
|
|
|
|
|
LL | let mut x = 1;
|
|
| +++
|
|
|
|
error[E0596]: cannot borrow immutable static item `static_x` as mutable
|
|
--> $DIR/borrowck-access-permissions.rs:16:19
|
|
|
|
|
LL | let _y1 = &mut static_x;
|
|
| ^^^^^^^^^^^^^ cannot borrow as mutable
|
|
|
|
error[E0596]: cannot borrow `*box_x` as mutable, as `box_x` is not declared as mutable
|
|
--> $DIR/borrowck-access-permissions.rs:28:19
|
|
|
|
|
LL | let _y1 = &mut *box_x;
|
|
| ^^^^^^^^^^^ cannot borrow as mutable
|
|
|
|
|
help: consider changing this to be mutable
|
|
|
|
|
LL | let mut box_x = Box::new(1);
|
|
| +++
|
|
|
|
error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
|
|
--> $DIR/borrowck-access-permissions.rs:37:19
|
|
|
|
|
LL | let _y1 = &mut *ref_x;
|
|
| ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
|
|
|
|
help: consider changing this to be a mutable reference
|
|
|
|
|
LL | let ref_x = &mut x;
|
|
| +++
|
|
|
|
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
|
|
--> $DIR/borrowck-access-permissions.rs:47:23
|
|
|
|
|
LL | let _y1 = &mut *ptr_x;
|
|
| ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
|
|
|
|
|
help: consider changing this to be a mutable pointer
|
|
|
|
|
LL | let ptr_x: *const _ = &mut x;
|
|
| +++
|
|
|
|
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
|
|
--> $DIR/borrowck-access-permissions.rs:60:18
|
|
|
|
|
LL | let _y = &mut *foo_ref.f;
|
|
| ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
|
|
|
|
help: consider changing this to be a mutable reference
|
|
|
|
|
LL | let foo_ref = &mut foo;
|
|
| +++
|
|
|
|
error: aborting due to 6 previous errors; 1 warning emitted
|
|
|
|
For more information about this error, try `rustc --explain E0596`.
|