Skip to content

Commit 035372b

Browse files
authored
Rollup merge of rust-lang#59036 - dlrobertson:fix_59021, r=estebank
Fix ICE in MIR pretty printing A `Def::Variant` should be considered as a function in mir pretty printing. Each variant has a constructor that we must print. Given the following enum definition: ```rust pub enum TestMe { X(usize), } ``` We will need to generate a constructor for the variant `X` with a signature that looks something like the following: ``` fn TestMe::X(_1: usize) -> TestMe; ``` Fixes: rust-lang#59021
2 parents 91cbb53 + 3a83cb2 commit 035372b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/librustc_mir/util/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
2+
use rustc::hir::def::CtorKind;
23
use rustc::mir::*;
34
use rustc::mir::visit::Visitor;
45
use rustc::ty::{self, TyCtxt};
@@ -597,7 +598,8 @@ fn write_mir_sig(
597598
trace!("write_mir_sig: {:?}", src.instance);
598599
let descr = tcx.describe_def(src.def_id());
599600
let is_function = match descr {
600-
Some(Def::Fn(_)) | Some(Def::Method(_)) | Some(Def::StructCtor(..)) => true,
601+
Some(Def::Fn(_)) | Some(Def::Method(_)) | Some(Def::Variant(..)) |
602+
Some(Def::StructCtor(_, CtorKind::Fn)) => true,
601603
_ => tcx.is_closure(src.def_id()),
602604
};
603605
match (descr, src.promoted) {

src/test/mir-opt/unusual-item-types.rs

+18
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ impl A {
77
const ASSOCIATED_CONSTANT: i32 = 2;
88
}
99

10+
// See #59021
11+
enum Test {
12+
X(usize),
13+
Y { a: usize },
14+
}
15+
1016
enum E {
1117
V = 5,
1218
}
1319

1420
fn main() {
21+
let f = Test::X as fn(usize) -> Test;
1522
let v = Vec::<i32>::new();
1623
}
1724

@@ -64,3 +71,14 @@ fn main() {
6471
// _3 = const std::ops::Drop::drop(move _2) -> [return: bb6, unwind: bb5];
6572
// }
6673
// END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
74+
75+
// START rustc.Test-X.mir_map.0.mir
76+
// fn Test::X(_1: usize) -> Test {
77+
// let mut _0: Test;
78+
//
79+
// bb0: {
80+
// _0 = Test::X(move _1,);
81+
// return;
82+
// }
83+
// }
84+
// END rustc.Test-X.mir_map.0.mir

0 commit comments

Comments
 (0)