]> git.lizzy.rs Git - rust.git/commitdiff
Fix ICE in MIR pretty printing
authorDan Robertson <dan@dlrobertson.com>
Sat, 9 Mar 2019 03:39:23 +0000 (03:39 +0000)
committerDan Robertson <dan@dlrobertson.com>
Sun, 10 Mar 2019 00:19:00 +0000 (00:19 +0000)
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:

```
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;
```

src/librustc_mir/util/pretty.rs
src/test/mir-opt/unusual-item-types.rs

index c3fbee3a2a6e5747e31f804dd053a9a5ceb9f3fa..af49f61ae86c78a5e3f94ba2ada8a0a6558c4dd3 100644 (file)
@@ -1,4 +1,5 @@
 use rustc::hir::def_id::{DefId, LOCAL_CRATE};
+use rustc::hir::def::CtorKind;
 use rustc::mir::*;
 use rustc::mir::visit::Visitor;
 use rustc::ty::{self, TyCtxt};
@@ -597,7 +598,8 @@ fn write_mir_sig(
     trace!("write_mir_sig: {:?}", src.instance);
     let descr = tcx.describe_def(src.def_id());
     let is_function = match descr {
-        Some(Def::Fn(_)) | Some(Def::Method(_)) | Some(Def::StructCtor(..)) => true,
+        Some(Def::Fn(_)) | Some(Def::Method(_)) | Some(Def::Variant(..)) |
+        Some(Def::StructCtor(_, CtorKind::Fn)) => true,
         _ => tcx.is_closure(src.def_id()),
     };
     match (descr, src.promoted) {
index fe85baa048e3903046c895c8012d444895b210ec..ced30381fda68cb0f81a16151a9f3005297456bb 100644 (file)
@@ -7,11 +7,18 @@ impl A {
     const ASSOCIATED_CONSTANT: i32 = 2;
 }
 
+// See #59021
+enum Test {
+    X(usize),
+    Y { a: usize },
+}
+
 enum E {
     V = 5,
 }
 
 fn main() {
+    let f = Test::X as fn(usize) -> Test;
     let v = Vec::<i32>::new();
 }
 
@@ -64,3 +71,14 @@ fn main() {
 //     _3 = const std::ops::Drop::drop(move _2) -> [return: bb6, unwind: bb5];
 // }
 // END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
+
+// START rustc.Test-X.mir_map.0.mir
+// fn Test::X(_1: usize) -> Test {
+//     let mut _0: Test;
+//
+//     bb0: {
+//         _0 = Test::X(move _1,);
+//         return;
+//     }
+// }
+// END rustc.Test-X.mir_map.0.mir