-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow statics pointing to mutable statics
- Loading branch information
Showing
11 changed files
with
207 additions
and
91 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
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
180 changes: 180 additions & 0 deletions
180
tests/ui/consts/miri_unleashed/mutable_references_err.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,180 @@ | ||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:18:1 | ||
| | ||
LL | const MUH: Meh = Meh { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:29:1 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/mutable_references_err.rs:34:1 | ||
| | ||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { | ||
HEX_DUMP | ||
} | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:37:1 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/mutable_references_err.rs:42:1 | ||
| | ||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered mutable reference or box pointing to read-only memory | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { | ||
HEX_DUMP | ||
} | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/mutable_references_err.rs:49:1 | ||
| | ||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered reference to mutable memory in `const` | ||
| | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) { | ||
HEX_DUMP | ||
} | ||
|
||
note: erroneous constant encountered | ||
--> $DIR/mutable_references_err.rs:51:34 | ||
| | ||
LL | const READS_FROM_MUTABLE: i32 = *POINTS_TO_MUTABLE1; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/mutable_references_err.rs:53:43 | ||
| | ||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF }; | ||
| ^^^^^^^^^^^^^ constant accesses mutable global memory | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:57:1 | ||
| | ||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:59:1 | ||
| | ||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:61:1 | ||
| | ||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:73:1 | ||
| | ||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:75:1 | ||
| | ||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: encountered mutable pointer in final value of constant | ||
--> $DIR/mutable_references_err.rs:77:1 | ||
| | ||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: skipping const checks | ||
| | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:20:8 | ||
| | ||
LL | x: &UnsafeCell::new(42), | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:29:27 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check for `const_refs_to_static` feature | ||
--> $DIR/mutable_references_err.rs:34:40 | ||
| | ||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO }; | ||
| ^^^ | ||
help: skipping check for `const_mut_refs` feature | ||
--> $DIR/mutable_references_err.rs:34:35 | ||
| | ||
LL | const SUBTLE: &mut i32 = unsafe { &mut FOO }; | ||
| ^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:37:25 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^ | ||
help: skipping check for `const_mut_refs` feature | ||
--> $DIR/mutable_references_err.rs:42:49 | ||
| | ||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check for `const_mut_refs` feature | ||
--> $DIR/mutable_references_err.rs:42:49 | ||
| | ||
LL | static mut MUT_TO_READONLY: &mut i32 = unsafe { &mut *(&READONLY as *const _ as *mut _) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check for `const_refs_to_static` feature | ||
--> $DIR/mutable_references_err.rs:49:44 | ||
| | ||
LL | const POINTS_TO_MUTABLE1: &i32 = unsafe { &MUTABLE }; | ||
| ^^^^^^^ | ||
help: skipping check for `const_refs_to_static` feature | ||
--> $DIR/mutable_references_err.rs:53:45 | ||
| | ||
LL | const POINTS_TO_MUTABLE2: &i32 = unsafe { &*MUTABLE_REF }; | ||
| ^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:57:45 | ||
| | ||
LL | const POINTS_TO_MUTABLE_INNER: *const i32 = &mut 42 as *mut _ as *const _; | ||
| ^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:59:46 | ||
| | ||
LL | const POINTS_TO_MUTABLE_INNER2: *const i32 = &mut 42 as *const _; | ||
| ^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:61:47 | ||
| | ||
LL | const INTERIOR_MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _; | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:73:51 | ||
| | ||
LL | const RAW_SYNC: SyncPtr<AtomicI32> = SyncPtr { x: &AtomicI32::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:75:49 | ||
| | ||
LL | const RAW_MUT_CAST: SyncPtr<i32> = SyncPtr { x: &mut 42 as *mut _ as *const _ }; | ||
| ^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:77:51 | ||
| | ||
LL | const RAW_MUT_COERCE: SyncPtr<i32> = SyncPtr { x: &mut 0 }; | ||
| ^^^^^^ | ||
|
||
error: aborting due to 13 previous errors; 1 warning emitted | ||
|
||
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
Oops, something went wrong.