-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
This ICEs on stable, probably since March 2018, but it requires the user to do UB in constants, so...
I think a possible fix would be to enable validation in const eval (cc @RalfJung ), though we should benchmark the perf considerations around that first. Alternatively we can just not ICE here and instead emit an error.
#[derive(Copy, Clone)]
pub struct ChildStdin {
inner: AnonPipe,
}
#[derive(Copy, Clone)]
enum AnonPipe {}
const FOO: () = {
union Foo {
a: ChildStdin,
b: (),
}
let x = unsafe { Foo { b: () }.a };
let x = &x.inner;
};
fn main() {}
Errors:
Compiling playground v0.0.1 (/playground)
warning: field is never used: `inner`
--> src/main.rs:3:5
|
3 | inner: AnonPipe,
| ^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
warning: constant item is never used: `FOO`
--> src/main.rs:9:1
|
9 | / const FOO: () = {
10 | | union Foo {
11 | | a: ChildStdin,
12 | | b: (),
... |
15 | | let x = &x.inner;
16 | | };
| |__^
thread 'rustc' panicked at 'Tried to access field 0 of union with 0 fields', src/librustc_mir/interpret/place.rs:360:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.37.0 (eae3437df 2019-08-13) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `playground`.
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.