Skip to content

Commit aabed93

Browse files
committed
mir: pretty-print Rvalue::Aggregate correctly.
1 parent 2472e04 commit aabed93

16 files changed

+44
-42
lines changed

src/librustc_middle/mir/mod.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -2242,39 +2242,41 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22422242
}
22432243

22442244
Aggregate(ref kind, ref places) => {
2245-
fn fmt_tuple(fmt: &mut Formatter<'_>, places: &[Operand<'_>]) -> fmt::Result {
2246-
let mut tuple_fmt = fmt.debug_tuple("");
2245+
let fmt_tuple = |fmt: &mut Formatter<'_>, name: &str| {
2246+
let mut tuple_fmt = fmt.debug_tuple(name);
22472247
for place in places {
22482248
tuple_fmt.field(place);
22492249
}
22502250
tuple_fmt.finish()
2251-
}
2251+
};
22522252

22532253
match **kind {
22542254
AggregateKind::Array(_) => write!(fmt, "{:?}", places),
22552255

2256-
AggregateKind::Tuple => match places.len() {
2257-
0 => write!(fmt, "()"),
2258-
1 => write!(fmt, "({:?},)", places[0]),
2259-
_ => fmt_tuple(fmt, places),
2260-
},
2256+
AggregateKind::Tuple => {
2257+
if places.is_empty() {
2258+
write!(fmt, "()")
2259+
} else {
2260+
fmt_tuple(fmt, "")
2261+
}
2262+
}
22612263

22622264
AggregateKind::Adt(adt_def, variant, substs, _user_ty, _) => {
22632265
let variant_def = &adt_def.variants[variant];
22642266

2265-
let f = &mut *fmt;
2266-
ty::tls::with(|tcx| {
2267+
let name = ty::tls::with(|tcx| {
2268+
let mut name = String::new();
22672269
let substs = tcx.lift(&substs).expect("could not lift for printing");
2268-
FmtPrinter::new(tcx, f, Namespace::ValueNS)
2270+
FmtPrinter::new(tcx, &mut name, Namespace::ValueNS)
22692271
.print_def_path(variant_def.def_id, substs)?;
2270-
Ok(())
2272+
Ok(name)
22712273
})?;
22722274

22732275
match variant_def.ctor_kind {
2274-
CtorKind::Const => Ok(()),
2275-
CtorKind::Fn => fmt_tuple(fmt, places),
2276+
CtorKind::Const => fmt.write_str(&name),
2277+
CtorKind::Fn => fmt_tuple(fmt, &name),
22762278
CtorKind::Fictive => {
2277-
let mut struct_fmt = fmt.debug_struct("");
2279+
let mut struct_fmt = fmt.debug_struct(&name);
22782280
for (field, place) in variant_def.fields.iter().zip(places) {
22792281
struct_fmt.field(&field.ident.as_str(), place);
22802282
}

src/test/mir-opt/const_prop/discriminant/32bit/rustc.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
StorageLive(_1); // bb0[0]: scope 0 at $DIR/discriminant.rs:6:9: 6:10
1616
StorageLive(_2); // bb0[1]: scope 0 at $DIR/discriminant.rs:6:13: 6:64
1717
StorageLive(_3); // bb0[2]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
18-
- _3 = std::option::Option::<bool>::Some(const true,); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
18+
- _3 = std::option::Option::<bool>::Some(const true); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
1919
+ _3 = const {transmute(0x01): std::option::Option<bool>}; // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
2020
// ty::Const
2121
- // + ty: bool

src/test/mir-opt/const_prop/discriminant/64bit/rustc.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
StorageLive(_1); // bb0[0]: scope 0 at $DIR/discriminant.rs:6:9: 6:10
1616
StorageLive(_2); // bb0[1]: scope 0 at $DIR/discriminant.rs:6:13: 6:64
1717
StorageLive(_3); // bb0[2]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
18-
- _3 = std::option::Option::<bool>::Some(const true,); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
18+
- _3 = std::option::Option::<bool>::Some(const true); // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
1919
+ _3 = const {transmute(0x01): std::option::Option<bool>}; // bb0[3]: scope 0 at $DIR/discriminant.rs:6:34: 6:44
2020
// ty::Const
2121
- // + ty: bool

src/test/mir-opt/deaggregator_test_enum_2/rustc.test1.Deaggregator.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
bb1: {
1919
StorageLive(_5); // bb1[0]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:16: 13:17
2020
_5 = _2; // bb1[1]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:16: 13:17
21-
- _0 = Foo::B(move _5,); // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
21+
- _0 = Foo::B(move _5); // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
2222
- StorageDead(_5); // bb1[3]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:17: 13:18
2323
- goto -> bb3; // bb1[4]: scope 0 at $DIR/deaggregator_test_enum_2.rs:10:5: 14:6
2424
+ ((_0 as B).0: i32) = move _5; // bb1[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:13:9: 13:18
@@ -30,7 +30,7 @@
3030
bb2: {
3131
StorageLive(_4); // bb2[0]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:16: 11:17
3232
_4 = _2; // bb2[1]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:16: 11:17
33-
- _0 = Foo::A(move _4,); // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18
33+
- _0 = Foo::A(move _4); // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18
3434
- StorageDead(_4); // bb2[3]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:17: 11:18
3535
- goto -> bb3; // bb2[4]: scope 0 at $DIR/deaggregator_test_enum_2.rs:10:5: 14:6
3636
+ ((_0 as A).0: i32) = move _4; // bb2[2]: scope 0 at $DIR/deaggregator_test_enum_2.rs:11:9: 11:18

src/test/mir-opt/deaggregator_test_multiple/rustc.test.Deaggregator.diff

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
StorageLive(_2); // bb0[0]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
1414
StorageLive(_3); // bb0[1]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:13: 10:14
1515
_3 = _1; // bb0[2]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:13: 10:14
16-
- _2 = Foo::A(move _3,); // bb0[3]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
16+
- _2 = Foo::A(move _3); // bb0[3]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:6: 10:15
1717
- StorageDead(_3); // bb0[4]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:14: 10:15
1818
- StorageLive(_4); // bb0[5]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
1919
- StorageLive(_5); // bb0[6]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:24: 10:25
2020
- _5 = _1; // bb0[7]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:24: 10:25
21-
- _4 = Foo::A(move _5,); // bb0[8]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
21+
- _4 = Foo::A(move _5); // bb0[8]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:17: 10:26
2222
- StorageDead(_5); // bb0[9]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:25: 10:26
2323
- _0 = [move _2, move _4]; // bb0[10]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:5: 10:27
2424
- StorageDead(_4); // bb0[11]: scope 0 at $DIR/deaggregator_test_multiple.rs:10:26: 10:27

src/test/mir-opt/generator-storage-dead-unwind/rustc.main-{{closure}}.StateTransform.before.mir

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ yields ()
2121

2222
bb0: {
2323
StorageLive(_3); // bb0[0]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:13: 23:14
24-
_3 = Foo(const 5i32,); // bb0[1]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23
24+
_3 = Foo(const 5i32); // bb0[1]: scope 0 at $DIR/generator-storage-dead-unwind.rs:23:17: 23:23
2525
// ty::Const
2626
// + ty: i32
2727
// + val: Value(Scalar(0x00000005))
2828
// mir::Constant
2929
// + span: $DIR/generator-storage-dead-unwind.rs:23:21: 23:22
3030
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) }
3131
StorageLive(_4); // bb0[2]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:13: 24:14
32-
_4 = Bar(const 6i32,); // bb0[3]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23
32+
_4 = Bar(const 6i32); // bb0[3]: scope 1 at $DIR/generator-storage-dead-unwind.rs:24:17: 24:23
3333
// ty::Const
3434
// + ty: i32
3535
// + val: Value(Scalar(0x00000006))

src/test/mir-opt/generator-tiny/rustc.main-{{closure}}.generator_resume.0.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main::{{closure}}#0(_1: std::pin::Pin<&mut [generator@$DIR/generator-tiny.rs:
3434
StorageLive(_6); // bb2[0]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
3535
StorageLive(_7); // bb2[1]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
3636
_7 = (); // bb2[2]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
37-
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7,); // bb2[3]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
37+
_0 = std::ops::GeneratorState::<(), ()>::Yielded(move _7); // bb2[3]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
3838
discriminant((*(_1.0: &mut [generator@$DIR/generator-tiny.rs:18:16: 24:6 {u8, HasDrop, ()}]))) = 3; // bb2[4]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
3939
return; // bb2[5]: scope 1 at $DIR/generator-tiny.rs:21:13: 21:18
4040
}

src/test/mir-opt/issue-41888/rustc.main.ElaborateDrops.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() -> () {
8080
StorageLive(_3); // bb5[0]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
8181
StorageLive(_4); // bb5[1]: scope 1 at $DIR/issue-41888.rs:9:18: 9:19
8282
_4 = K; // bb5[2]: scope 1 at $DIR/issue-41888.rs:9:18: 9:19
83-
_3 = E::F(move _4,); // bb5[3]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
83+
_3 = E::F(move _4); // bb5[3]: scope 1 at $DIR/issue-41888.rs:9:13: 9:20
8484
StorageDead(_4); // bb5[4]: scope 1 at $DIR/issue-41888.rs:9:19: 9:20
8585
goto -> bb14; // bb5[5]: scope 1 at $DIR/issue-41888.rs:9:9: 9:10
8686
}

src/test/mir-opt/issue-62289/rustc.test.ElaborateDrops.before.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn test() -> std::option::Option<std::boxed::Box<u32>> {
115115

116116
bb12: {
117117
StorageDead(_2); // bb12[0]: scope 0 at $DIR/issue-62289.rs:9:20: 9:21
118-
_0 = std::option::Option::<std::boxed::Box<u32>>::Some(move _1,); // bb12[1]: scope 0 at $DIR/issue-62289.rs:9:5: 9:22
118+
_0 = std::option::Option::<std::boxed::Box<u32>>::Some(move _1); // bb12[1]: scope 0 at $DIR/issue-62289.rs:9:5: 9:22
119119
drop(_1) -> bb13; // bb12[2]: scope 0 at $DIR/issue-62289.rs:9:21: 9:22
120120
}
121121

src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn full_tested_match() -> () {
2626
bb0: {
2727
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:15:13: 19:6
2828
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
29-
_2 = std::option::Option::<i32>::Some(const 42i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
29+
_2 = std::option::Option::<i32>::Some(const 42i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:15:19: 15:27
3030
// ty::Const
3131
// + ty: i32
3232
// + val: Value(Scalar(0x0000002a))

src/test/mir-opt/match_false_edges/rustc.full_tested_match2.PromoteTemps.before.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn full_tested_match2() -> () {
2525
bb0: {
2626
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:26:13: 30:6
2727
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
28-
_2 = std::option::Option::<i32>::Some(const 42i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
28+
_2 = std::option::Option::<i32>::Some(const 42i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:26:19: 26:27
2929
// ty::Const
3030
// + ty: i32
3131
// + val: Value(Scalar(0x0000002a))

src/test/mir-opt/match_false_edges/rustc.main.PromoteTemps.before.mir

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() -> () {
3636
bb0: {
3737
StorageLive(_1); // bb0[0]: scope 0 at $DIR/match_false_edges.rs:35:13: 40:6
3838
StorageLive(_2); // bb0[1]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
39-
_2 = std::option::Option::<i32>::Some(const 1i32,); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
39+
_2 = std::option::Option::<i32>::Some(const 1i32); // bb0[2]: scope 0 at $DIR/match_false_edges.rs:35:19: 35:26
4040
// ty::Const
4141
// + ty: i32
4242
// + val: Value(Scalar(0x00000001))

src/test/mir-opt/packed-struct-drop-aligned/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ fn main() -> () {
1616
StorageLive(_1); // bb0[0]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14
1717
StorageLive(_2); // bb0[1]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
1818
StorageLive(_3); // bb0[2]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
19-
_3 = Droppy(const 0usize,); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
19+
_3 = Droppy(const 0usize); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
2020
// ty::Const
2121
// + ty: usize
2222
// + val: Value(Scalar(0x00000000))
2323
// mir::Constant
2424
// + span: $DIR/packed-struct-drop-aligned.rs:6:39: 6:40
2525
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
26-
_2 = Aligned(move _3,); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
26+
_2 = Aligned(move _3); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
2727
StorageDead(_3); // bb0[5]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:41: 6:42
28-
_1 = Packed(move _2,); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
28+
_1 = Packed(move _2); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
2929
StorageDead(_2); // bb0[7]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43
3030
StorageLive(_4); // bb0[8]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
3131
StorageLive(_5); // bb0[9]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
32-
_5 = Droppy(const 0usize,); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
32+
_5 = Droppy(const 0usize); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
3333
// ty::Const
3434
// + ty: usize
3535
// + val: Value(Scalar(0x00000000))
3636
// mir::Constant
3737
// + span: $DIR/packed-struct-drop-aligned.rs:7:26: 7:27
3838
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
39-
_4 = Aligned(move _5,); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
39+
_4 = Aligned(move _5); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
4040
StorageDead(_5); // bb0[12]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:28: 7:29
4141
StorageLive(_6); // bb0[13]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
4242
_6 = move (_1.0: Aligned); // bb0[14]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8

src/test/mir-opt/packed-struct-drop-aligned/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ fn main() -> () {
1616
StorageLive(_1); // bb0[0]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:9: 6:14
1717
StorageLive(_2); // bb0[1]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
1818
StorageLive(_3); // bb0[2]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
19-
_3 = Droppy(const 0usize,); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
19+
_3 = Droppy(const 0usize); // bb0[3]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:32: 6:41
2020
// ty::Const
2121
// + ty: usize
2222
// + val: Value(Scalar(0x0000000000000000))
2323
// mir::Constant
2424
// + span: $DIR/packed-struct-drop-aligned.rs:6:39: 6:40
2525
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
26-
_2 = Aligned(move _3,); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
26+
_2 = Aligned(move _3); // bb0[4]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:24: 6:42
2727
StorageDead(_3); // bb0[5]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:41: 6:42
28-
_1 = Packed(move _2,); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
28+
_1 = Packed(move _2); // bb0[6]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:17: 6:43
2929
StorageDead(_2); // bb0[7]: scope 0 at $DIR/packed-struct-drop-aligned.rs:6:42: 6:43
3030
StorageLive(_4); // bb0[8]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
3131
StorageLive(_5); // bb0[9]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
32-
_5 = Droppy(const 0usize,); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
32+
_5 = Droppy(const 0usize); // bb0[10]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:19: 7:28
3333
// ty::Const
3434
// + ty: usize
3535
// + val: Value(Scalar(0x0000000000000000))
3636
// mir::Constant
3737
// + span: $DIR/packed-struct-drop-aligned.rs:7:26: 7:27
3838
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
39-
_4 = Aligned(move _5,); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
39+
_4 = Aligned(move _5); // bb0[11]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:11: 7:29
4040
StorageDead(_5); // bb0[12]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:28: 7:29
4141
StorageLive(_6); // bb0[13]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8
4242
_6 = move (_1.0: Aligned); // bb0[14]: scope 1 at $DIR/packed-struct-drop-aligned.rs:7:5: 7:8

0 commit comments

Comments
 (0)