Skip to content
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

Fix ICE in MIR pretty printing #59036

Merged
merged 1 commit into from Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_mir/util/pretty.rs
@@ -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};
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/mir-opt/unusual-item-types.rs
Expand Up @@ -7,11 +7,18 @@ impl A {
const ASSOCIATED_CONSTANT: i32 = 2;
}

// See #59021
enum Test {
X(usize),
Y { a: usize },
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the output mir below? It should be in a file with a name like build/x86_64-unknown-linux-gnu/test/mir-opt/unusual-item-types/rustc/Test-X.mir_map.0.mir

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the following to verify that we won't ICE with struct-like variants.

pub enum Test2 {
    X { a: usize },
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Added the tests


enum E {
V = 5,
}

fn main() {
let f = Test::X as fn(usize) -> Test;
let v = Vec::<i32>::new();
}

Expand Down Expand Up @@ -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