Skip to content

Commit e35e9ee

Browse files
authored
Rollup merge of rust-lang#58354 - matthewjasper:mir-dump-fixes, r=wesleywiser
Fix ICE and invalid filenames in MIR printing code * Don't panic when printing MIR for associated constants * Don't use `<` and `>` in filenames, since they aren't allowed on Windows. r? @eddyb cc @RalfJung
2 parents d18e4f0 + d7afd3e commit e35e9ee

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/librustc_mir/util/pretty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn dump_path(
197197
.chars()
198198
.filter_map(|c| match c {
199199
' ' => None,
200-
':' => Some('_'),
200+
':' | '<' | '>' => Some('_'),
201201
c => Some(c)
202202
}));
203203
s
@@ -603,7 +603,8 @@ fn write_mir_sig(
603603
match (descr, src.promoted) {
604604
(_, Some(i)) => write!(w, "{:?} in ", i)?,
605605
(Some(Def::StructCtor(..)), _) => write!(w, "struct ")?,
606-
(Some(Def::Const(_)), _) => write!(w, "const ")?,
606+
(Some(Def::Const(_)), _)
607+
| (Some(Def::AssociatedConst(_)), _) => write!(w, "const ")?,
607608
(Some(Def::Static(_, /*is_mutbl*/false)), _) => write!(w, "static ")?,
608609
(Some(Def::Static(_, /*is_mutbl*/true)), _) => write!(w, "static mut ")?,
609610
(_, _) if is_function => write!(w, "fn ")?,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Test that we don't ICE when trying to dump MIR for unusual item types and
2+
// that we don't create filenames containing `<` and `>`
3+
4+
struct A;
5+
6+
impl A {
7+
const ASSOCIATED_CONSTANT: i32 = 2;
8+
}
9+
10+
enum E {
11+
V = 5,
12+
}
13+
14+
fn main() {
15+
let v = Vec::<i32>::new();
16+
}
17+
18+
// END RUST SOURCE
19+
20+
// START rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir
21+
// bb0: {
22+
// _0 = const 2i32;
23+
// return;
24+
// }
25+
// bb1: {
26+
// resume;
27+
// }
28+
// END rustc.{{impl}}-ASSOCIATED_CONSTANT.mir_map.0.mir
29+
30+
// START rustc.E-V-{{constant}}.mir_map.0.mir
31+
// bb0: {
32+
// _0 = const 5isize;
33+
// return;
34+
// }
35+
// bb1: {
36+
// resume;
37+
// }
38+
// END rustc.E-V-{{constant}}.mir_map.0.mir
39+
40+
// START rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir
41+
// bb0: {
42+
// goto -> bb7;
43+
// }
44+
// bb1: {
45+
// return;
46+
// }
47+
// bb2: {
48+
// resume;
49+
// }
50+
// bb3: {
51+
// goto -> bb1;
52+
// }
53+
// bb4: {
54+
// goto -> bb2;
55+
// }
56+
// bb5: {
57+
// drop(((*_1).0: alloc::raw_vec::RawVec<i32>)) -> bb4;
58+
// }
59+
// bb6: {
60+
// drop(((*_1).0: alloc::raw_vec::RawVec<i32>)) -> [return: bb3, unwind: bb4];
61+
// }
62+
// bb7: {
63+
// _2 = &mut (*_1);
64+
// _3 = const std::ops::Drop::drop(move _2) -> [return: bb6, unwind: bb5];
65+
// }
66+
// END rustc.ptr-real_drop_in_place.std__vec__Vec_i32_.AddMovesForPackedDrops.before.mir

0 commit comments

Comments
 (0)