-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also catch static mutation at evaluation time
- Loading branch information
Showing
15 changed files
with
82 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// New test for #53818: modifying static memory at compile-time is not allowed. | ||
// The test should never compile successfully | ||
|
||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_let)] | ||
|
||
use std::cell::UnsafeCell; | ||
|
||
struct Foo(UnsafeCell<u32>); | ||
|
||
unsafe impl Send for Foo {} | ||
unsafe impl Sync for Foo {} | ||
|
||
static FOO: Foo = Foo(UnsafeCell::new(42)); | ||
|
||
static BAR: () = unsafe { | ||
*FOO.0.get() = 5; //~ ERROR could not evaluate static initializer | ||
}; | ||
|
||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/consts/const-eval/assign-to-static-within-other-static-2.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0080]: could not evaluate static initializer | ||
--> $DIR/assign-to-static-within-other-static-2.rs:27:5 | ||
| | ||
LL | *FOO.0.get() = 5; //~ ERROR could not evaluate static initializer | ||
| ^^^^^^^^^^^^^^^^ 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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/test/ui/consts/const-eval/assign-to-static-within-other-static.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
error: cannot mutate statics in the initializer of another static | ||
--> $DIR/assign-to-static-within-other-static.rs:32:5 | ||
--> $DIR/assign-to-static-within-other-static.rs:21:5 | ||
| | ||
LL | FOO2 = 5; | ||
| ^^^^^^^^ | ||
LL | FOO = 5; //~ ERROR cannot mutate statics in the initializer of another static | ||
| ^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
error[E0658]: statements in statics are unstable (see issue #48821) | ||
error: cannot mutate statics in the initializer of another static | ||
--> $DIR/write-to-static-mut-in-static.rs:14:33 | ||
| | ||
LL | pub static mut B: () = unsafe { A = 1; }; | ||
| ^^^^^ | ||
| | ||
= help: add #![feature(const_let)] to the crate attributes to enable | ||
|
||
error[E0658]: statements in statics are unstable (see issue #48821) | ||
error: cannot mutate statics in the initializer of another static | ||
--> $DIR/write-to-static-mut-in-static.rs:17:34 | ||
| | ||
LL | pub static mut C: u32 = unsafe { C = 1; 0 }; | ||
| ^^^^^ | ||
| | ||
= help: add #![feature(const_let)] to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |