-
Notifications
You must be signed in to change notification settings - Fork 13.4k
pretty/mir: const value enums with no variants #73442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1177,8 +1177,13 @@ pub trait PrettyPrinter<'tcx>: | |
} | ||
p!(write(")")); | ||
} | ||
ty::Adt(def, substs) if def.variants.is_empty() => { | ||
p!(print_value_path(def.did, substs)); | ||
} | ||
Comment on lines
+1180
to
+1182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this should ever be reached? This sort of thing should be an evaluation error, surely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t know about an evaluation error, but this definitely gets reached. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we use the pretty printer from within the miri engine and the const evaluator does not validate that every local is always valid, only miri does this. |
||
ty::Adt(def, substs) => { | ||
let variant_def = &def.variants[contents.variant]; | ||
let variant_id = | ||
contents.variant.expect("destructed const of adt without variant id"); | ||
let variant_def = &def.variants[variant_id]; | ||
p!(print_value_path(variant_def.def_id, substs)); | ||
|
||
match variant_def.ctor_kind { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// compile-flags: -Z mir-opt-level=1 | ||
// Regression test for #72181, this ICE requires `-Z mir-opt-level=1` flags. | ||
|
||
#![feature(never_type)] | ||
#![allow(unused, invalid_value)] | ||
|
||
enum Void {} | ||
|
||
// EMIT_MIR rustc.f.mir_map.0.mir | ||
fn f(v: Void) -> ! { | ||
match v {} | ||
} | ||
|
||
// EMIT_MIR rustc.main.mir_map.0.mir | ||
fn main() { | ||
let v: Void = unsafe { | ||
std::mem::transmute::<(), Void>(()) | ||
}; | ||
|
||
f(v); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// MIR for `f` 0 mir_map | ||
|
||
fn f(_1: Void) -> ! { | ||
debug v => _1; // in scope 0 at $DIR/issue-72181-1.rs:10:6: 10:7 | ||
let mut _0: !; // return place in scope 0 at $DIR/issue-72181-1.rs:10:18: 10:19 | ||
let mut _2: !; // in scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
let mut _3: !; // in scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
StorageLive(_3); // scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
FakeRead(ForMatchedPlace, _1); // scope 0 at $DIR/issue-72181-1.rs:11:11: 11:12 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:11:11: 11:12 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181-1.rs:10:1: 12:2 | ||
} | ||
|
||
bb2: { | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:11:5: 11:15 | ||
} | ||
|
||
bb3: { | ||
StorageDead(_3); // scope 0 at $DIR/issue-72181-1.rs:11:14: 11:15 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:10:20: 12:2 | ||
} | ||
|
||
bb4: { | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181-1.rs:12:1: 12:2 | ||
goto -> bb5; // scope 0 at $DIR/issue-72181-1.rs:12:2: 12:2 | ||
} | ||
|
||
bb5: { | ||
return; // scope 0 at $DIR/issue-72181-1.rs:12:2: 12:2 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// MIR for `main` 0 mir_map | ||
|
||
| User Type Annotations | ||
| 0: Canonical { max_universe: U0, variables: [], value: Ty(Void) } at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
| 1: Canonical { max_universe: U0, variables: [], value: Ty(Void) } at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
| | ||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/issue-72181-1.rs:15:11: 15:11 | ||
let mut _1: !; // in scope 0 at $DIR/issue-72181-1.rs:15:11: 21:2 | ||
let _2: Void as UserTypeProjection { base: UserType(0), projs: [] }; // in scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
let mut _3: (); // in scope 0 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
let _4: !; // in scope 0 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
let mut _5: Void; // in scope 0 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
scope 1 { | ||
debug v => _2; // in scope 1 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
} | ||
scope 2 { | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
StorageLive(_3); // scope 2 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
_3 = (); // scope 2 at $DIR/issue-72181-1.rs:17:41: 17:43 | ||
_2 = const std::intrinsics::transmute::<(), Void>(move _3) -> [return: bb2, unwind: bb1]; // scope 2 at $DIR/issue-72181-1.rs:17:9: 17:44 | ||
// ty::Const | ||
// + ty: unsafe extern "rust-intrinsic" fn(()) -> Void {std::intrinsics::transmute::<(), Void>} | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181-1.rs:17:9: 17:40 | ||
// + literal: Const { ty: unsafe extern "rust-intrinsic" fn(()) -> Void {std::intrinsics::transmute::<(), Void>}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181-1.rs:15:1: 21:2 | ||
} | ||
|
||
bb2: { | ||
StorageDead(_3); // scope 2 at $DIR/issue-72181-1.rs:17:43: 17:44 | ||
FakeRead(ForLet, _2); // scope 0 at $DIR/issue-72181-1.rs:16:9: 16:10 | ||
AscribeUserType(_2, o, UserTypeProjection { base: UserType(1), projs: [] }); // scope 0 at $DIR/issue-72181-1.rs:16:12: 16:16 | ||
StorageLive(_4); // scope 1 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
StorageLive(_5); // scope 1 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
_5 = move _2; // scope 1 at $DIR/issue-72181-1.rs:20:7: 20:8 | ||
const f(move _5) -> bb1; // scope 1 at $DIR/issue-72181-1.rs:20:5: 20:9 | ||
// ty::Const | ||
// + ty: fn(Void) -> ! {f} | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181-1.rs:20:5: 20:6 | ||
// + literal: Const { ty: fn(Void) -> ! {f}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb3: { | ||
StorageDead(_5); // scope 1 at $DIR/issue-72181-1.rs:20:8: 20:9 | ||
StorageDead(_4); // scope 1 at $DIR/issue-72181-1.rs:20:9: 20:10 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181-1.rs:21:1: 21:2 | ||
unreachable; // scope 0 at $DIR/issue-72181-1.rs:15:11: 21:2 | ||
} | ||
|
||
bb4: { | ||
goto -> bb5; // scope 0 at $DIR/issue-72181-1.rs:21:2: 21:2 | ||
} | ||
|
||
bb5: { | ||
return; // scope 0 at $DIR/issue-72181-1.rs:21:2: 21:2 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// compile-flags: -Z mir-opt-level=1 | ||
// Regression test for #72181, this ICE requires `-Z mir-opt-level=1` flags. | ||
|
||
use std::mem; | ||
|
||
#[derive(Copy, Clone)] | ||
enum Never {} | ||
|
||
union Foo { | ||
a: u64, | ||
b: Never | ||
} | ||
|
||
// EMIT_MIR_FOR_EACH_BIT_WIDTH | ||
// EMIT_MIR rustc.foo.mir_map.0.mir | ||
fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 } | ||
|
||
// EMIT_MIR rustc.bar.mir_map.0.mir | ||
fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x } | ||
|
||
// EMIT_MIR_FOR_EACH_BIT_WIDTH | ||
// EMIT_MIR rustc.main.mir_map.0.mir | ||
fn main() { | ||
let _ = mem::size_of::<Foo>(); | ||
|
||
let f = [Foo { a: 42 }, Foo { a: 10 }]; | ||
let _ = unsafe { f[0].a }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// MIR for `bar` 0 mir_map | ||
|
||
fn bar(_1: [(Never, u32); 1]) -> u32 { | ||
let mut _0: u32; // return place in scope 0 at $DIR/issue-72181.rs:19:40: 19:43 | ||
let _2: u32; // in scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
scope 1 { | ||
debug x => _2; // in scope 1 at $DIR/issue-72181.rs:19:13: 19:14 | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
_2 = (_1[0 of 1].1: u32); // scope 0 at $DIR/issue-72181.rs:19:13: 19:14 | ||
_0 = _2; // scope 1 at $DIR/issue-72181.rs:19:46: 19:47 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181.rs:19:48: 19:49 | ||
goto -> bb2; // scope 0 at $DIR/issue-72181.rs:19:49: 19:49 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181.rs:19:1: 19:49 | ||
} | ||
|
||
bb2: { | ||
return; // scope 0 at $DIR/issue-72181.rs:19:49: 19:49 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// MIR for `foo` 0 mir_map | ||
|
||
fn foo(_1: [(Never, u32); 1]) -> u32 { | ||
debug xs => _1; // in scope 0 at $DIR/issue-72181.rs:16:8: 16:10 | ||
let mut _0: u32; // return place in scope 0 at $DIR/issue-72181.rs:16:34: 16:37 | ||
let _2: usize; // in scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
let mut _3: usize; // in scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
let mut _4: bool; // in scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
_2 = const 0usize; // scope 0 at $DIR/issue-72181.rs:16:43: 16:44 | ||
// ty::Const | ||
// + ty: usize | ||
// + val: Value(Scalar(0x00000000)) | ||
// mir::Constant | ||
// + span: $DIR/issue-72181.rs:16:43: 16:44 | ||
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) } | ||
_3 = Len(_1); // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
_4 = Lt(_2, _3); // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
assert(move _4, "index out of bounds: the len is {} but the index is {}", move _3, _2) -> [success: bb2, unwind: bb1]; // scope 0 at $DIR/issue-72181.rs:16:40: 16:45 | ||
} | ||
|
||
bb1 (cleanup): { | ||
resume; // scope 0 at $DIR/issue-72181.rs:16:1: 16:49 | ||
} | ||
|
||
bb2: { | ||
_0 = (_1[_2].1: u32); // scope 0 at $DIR/issue-72181.rs:16:40: 16:47 | ||
StorageDead(_2); // scope 0 at $DIR/issue-72181.rs:16:48: 16:49 | ||
goto -> bb3; // scope 0 at $DIR/issue-72181.rs:16:49: 16:49 | ||
} | ||
|
||
bb3: { | ||
return; // scope 0 at $DIR/issue-72181.rs:16:49: 16:49 | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.