forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#71665 - RalfJung:miri-intern-no-ice, r=oli-obk
Miri interning: replace ICEs by proper errors Fixes rust-lang#71316 I also did some refactoring, as I kept being confused by all the parameters to `intern_shallow`, some of which have invalid combinations (such as a mutable const). So instead `InternMode` now contains all the information that is needed and invalid combinations are ruled out by the type system. Also I removed interpreter errors from interning. We already ignored almost all errors, and the `ValidationFailure` errors that we handled separately actually cannot ever happen here. The only interpreter failure that was actually reachable was the UB on dangling pointers -- and arguably, a dangling raw pointer is not UB, so the error was not even correct. It's just that the rest of the compiler does not like "dangling" `AllocId`. It should be possible to review the 3 commits separately. r? @oli-obk Cc @rust-lang/wg-const-eval
- Loading branch information
Showing
23 changed files
with
331 additions
and
336 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 +1,25 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/dangling-alloc-id-ice.rs:8:1 | ||
error: encountered dangling pointer in final constant | ||
--> $DIR/dangling-alloc-id-ice.rs:9:1 | ||
| | ||
LL | / const FOO: &() = { | ||
LL | | | ||
LL | | let y = (); | ||
LL | | unsafe { Foo { y: &y }.long_live_the_unit } | ||
LL | | }; | ||
| |__^ encountered dangling pointer in final constant | ||
| |__^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/dangling-alloc-id-ice.rs:9:1 | ||
| | ||
LL | / const FOO: &() = { | ||
LL | | | ||
LL | | let y = (); | ||
LL | | unsafe { Foo { y: &y }.long_live_the_unit } | ||
LL | | }; | ||
| |__^ type validation failed: encountered a dangling reference (use-after-free) | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= 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. | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
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
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,13 +1,11 @@ | ||
error: any use of this value will cause an error | ||
error: encountered dangling pointer in final constant | ||
--> $DIR/dangling_raw_ptr.rs:1:1 | ||
| | ||
LL | / const FOO: *const u32 = { | ||
LL | | let x = 42; | ||
LL | | &x | ||
LL | | }; | ||
| |__^ encountered dangling pointer in final constant | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
| |__^ | ||
|
||
error: aborting due to previous error | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
src/test/ui/consts/miri_unleashed/mutable_references_err.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,37 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
|
||
#![allow(const_err)] | ||
|
||
use std::cell::UnsafeCell; | ||
|
||
// this test ensures that our mutability story is sound | ||
|
||
struct Meh { | ||
x: &'static UnsafeCell<i32>, | ||
} | ||
unsafe impl Sync for Meh {} | ||
|
||
// the following will never be ok! no interior mut behind consts, because | ||
// all allocs interned here will be marked immutable. | ||
const MUH: Meh = Meh { //~ ERROR: mutable memory (`UnsafeCell`) is not allowed in constant | ||
x: &UnsafeCell::new(42), | ||
}; | ||
|
||
struct Synced { | ||
x: UnsafeCell<i32>, | ||
} | ||
unsafe impl Sync for Synced {} | ||
|
||
// Make sure we also catch this behind a type-erased `dyn Trait` reference. | ||
const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
//~^ ERROR: mutable memory (`UnsafeCell`) is not allowed in constant | ||
|
||
// Make sure we also catch mutable references. | ||
const BLUNT: &mut i32 = &mut 42; | ||
//~^ ERROR: mutable memory (`&mut`) is not allowed in constant | ||
|
||
fn main() { | ||
unsafe { | ||
*MUH.x.get() = 99; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/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,40 @@ | ||
error: mutable memory (`UnsafeCell`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:16:1 | ||
| | ||
LL | / const MUH: Meh = Meh { | ||
LL | | x: &UnsafeCell::new(42), | ||
LL | | }; | ||
| |__^ | ||
|
||
error: mutable memory (`UnsafeCell`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:26:1 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable memory (`&mut`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:30:1 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: skipping const checks | ||
| | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:17:8 | ||
| | ||
LL | x: &UnsafeCell::new(42), | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:26:27 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check for `const_mut_refs` feature | ||
--> $DIR/mutable_references_err.rs:30:25 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
29 changes: 0 additions & 29 deletions
29
src/test/ui/consts/miri_unleashed/mutable_references_ice.rs
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.