Fix a recently introduces regression
This commit is contained in:
parent
6d34ec18c7
commit
f8e508cde4
6 changed files with 44 additions and 6 deletions
|
@ -518,7 +518,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
|
||||
// Only allow statics (not consts) to refer to other statics.
|
||||
if self.mode == Mode::Static || self.mode == Mode::StaticMut {
|
||||
if context.is_mutating_use() {
|
||||
if self.mode == Mode::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
|
||||
|
|
7
src/test/ui/consts/static_mut_containing_mut_ref.rs
Normal file
7
src/test/ui/consts/static_mut_containing_mut_ref.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
// compile-pass
|
||||
|
||||
static mut STDERR_BUFFER_SPACE: [u8; 42] = [0u8; 42];
|
||||
|
||||
pub static mut STDERR_BUFFER: *mut [u8] = unsafe { &mut STDERR_BUFFER_SPACE };
|
||||
|
||||
fn main() {}
|
8
src/test/ui/consts/static_mut_containing_mut_ref2.rs
Normal file
8
src/test/ui/consts/static_mut_containing_mut_ref2.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
#![feature(const_let)]
|
||||
|
||||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||
|
||||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
//~^ references in statics may only refer to immutable values
|
||||
|
||||
fn main() {}
|
9
src/test/ui/consts/static_mut_containing_mut_ref2.stderr
Normal file
9
src/test/ui/consts/static_mut_containing_mut_ref2.stderr
Normal file
|
@ -0,0 +1,9 @@
|
|||
error[E0017]: references in statics may only refer to immutable values
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:5:46
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0017`.
|
|
@ -12,10 +12,10 @@
|
|||
|
||||
pub static mut A: u32 = 0;
|
||||
pub static mut B: () = unsafe { A = 1; };
|
||||
//~^ ERROR cannot mutate statics in the initializer of another static
|
||||
//~^ ERROR could not evaluate static initializer
|
||||
|
||||
pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
//~^ ERROR cannot mutate statics in the initializer of another static
|
||||
//~^ ERROR cycle detected
|
||||
|
||||
pub static D: u32 = D;
|
||||
|
||||
|
|
|
@ -1,14 +1,28 @@
|
|||
error: cannot mutate statics in the initializer of another static
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/write-to-static-mut-in-static.rs:14:33
|
||||
|
|
||||
LL | pub static mut B: () = unsafe { A = 1; };
|
||||
| ^^^^^
|
||||
| ^^^^^ tried to modify a static's initial value from another static's initializer
|
||||
|
||||
error: cannot mutate statics in the initializer of another static
|
||||
error[E0391]: cycle detected when const-evaluating `C`
|
||||
--> $DIR/write-to-static-mut-in-static.rs:17:34
|
||||
|
|
||||
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
| ^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating `C`...
|
||||
--> $DIR/write-to-static-mut-in-static.rs:17:1
|
||||
|
|
||||
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which again requires const-evaluating `C`, completing the cycle
|
||||
note: cycle used when const-evaluating + checking `C`
|
||||
--> $DIR/write-to-static-mut-in-static.rs:17:1
|
||||
|
|
||||
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors occurred: E0080, E0391.
|
||||
For more information about an error, try `rustc --explain E0080`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue