let is_thread_local = self.tcx.has_attr(*def_id, sym::thread_local);
if is_thread_local {
self.check_op(ops::ThreadLocalAccess);
- } else if self.const_kind() == ConstKind::Static && context.is_mutating_use() {
- // this is not strictly necessary as miri will also bail out
- // For interior mutability we can't really catch this statically as that
- // goes through raw pointers and intermediate temporaries, so miri has
- // to catch this anyway
-
- self.tcx.sess.span_err(
- self.span,
- "cannot mutate statics in the initializer of another static",
- );
- } else {
+ } else if self.const_kind() != ConstKind::Static || !context.is_mutating_use() {
self.check_op(ops::StaticAccess);
}
}
static mut FOO: u32 = 42;
static BOO: () = unsafe {
- FOO = 5; //~ ERROR cannot mutate statics in the initializer of another static
+ FOO = 5;
+ //~^ could not evaluate static initializer [E0080]
};
fn main() {}
-error: cannot mutate statics in the initializer of another static
+error[E0080]: could not evaluate static initializer
--> $DIR/assign-to-static-within-other-static.rs:10:5
|
LL | FOO = 5;
- | ^^^^^^^
+ | ^^^^^^^ tried to modify a static's initial value from another static's initializer
error: aborting due to previous error
+For more information about this error, try `rustc --explain E0080`.
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
//~| ERROR cannot borrow
- //~| ERROR cannot mutate statics
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
fn main() {}
LL | static STATIC_REF: &'static mut i32 = &mut X;
| ^^^^^^ statics require immutable values
-error: cannot mutate statics in the initializer of another static
- --> $DIR/E0017.rs:5:39
- |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
- | ^^^^^^
-
error[E0596]: cannot borrow immutable static item `X` as mutable
--> $DIR/E0017.rs:5:39
|
| ^^^^^^ cannot borrow as mutable
error[E0017]: references in statics may only refer to immutable values
- --> $DIR/E0017.rs:8:38
+ --> $DIR/E0017.rs:7:38
|
LL | static CONST_REF: &'static mut i32 = &mut C;
| ^^^^^^ statics require immutable values
-error: aborting due to 5 previous errors
+error: aborting due to 4 previous errors
Some errors have detailed explanations: E0017, E0596.
For more information about an error, try `rustc --explain E0017`.
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
//~| ERROR cannot borrow
- //~| ERROR cannot mutate statics
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
fn main() {}
LL | static STATIC_REF: &'static mut i32 = &mut X;
| ^^^^^^ statics require immutable values
-error: cannot mutate statics in the initializer of another static
- --> $DIR/E0388.rs:5:39
- |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
- | ^^^^^^
-
error[E0596]: cannot borrow immutable static item `X` as mutable
--> $DIR/E0388.rs:5:39
|
| ^^^^^^ cannot borrow as mutable
error[E0017]: references in statics may only refer to immutable values
- --> $DIR/E0388.rs:8:38
+ --> $DIR/E0388.rs:7:38
|
LL | static CONST_REF: &'static mut i32 = &mut C;
| ^^^^^^ statics require immutable values
-error: aborting due to 5 previous errors
+error: aborting due to 4 previous errors
Some errors have detailed explanations: E0017, E0596.
For more information about an error, try `rustc --explain E0017`.