Skip to content

Commit 4717cf2

Browse files
committed
Auto merge of #75566 - alasher:master, r=oli-obk
Suppress verbose MIR comments for trivial types Addresses #74508 This is my first contribution to the Rust project! Please let me know if anything needs revising, I'm happy to make changes.
2 parents 515c9fa + 28ac141 commit 4717cf2

File tree

132 files changed

+48
-3687
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+48
-3687
lines changed

src/librustc_mir/util/pretty.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,30 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
387387
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
388388
self.super_constant(constant, location);
389389
let Constant { span, user_ty, literal } = constant;
390-
self.push("mir::Constant");
391-
self.push(&format!("+ span: {}", self.tcx.sess.source_map().span_to_string(*span)));
392-
if let Some(user_ty) = user_ty {
393-
self.push(&format!("+ user_ty: {:?}", user_ty));
390+
match literal.ty.kind {
391+
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char => {}
392+
_ => {
393+
self.push("mir::Constant");
394+
self.push(&format!("+ span: {}", self.tcx.sess.source_map().span_to_string(*span)));
395+
if let Some(user_ty) = user_ty {
396+
self.push(&format!("+ user_ty: {:?}", user_ty));
397+
}
398+
self.push(&format!("+ literal: {:?}", literal));
399+
}
394400
}
395-
self.push(&format!("+ literal: {:?}", literal));
396401
}
397402

398403
fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, _: Location) {
399404
self.super_const(constant);
400405
let ty::Const { ty, val, .. } = constant;
401-
self.push("ty::Const");
402-
self.push(&format!("+ ty: {:?}", ty));
403-
self.push(&format!("+ val: {:?}", val));
406+
match ty.kind {
407+
ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char => {}
408+
_ => {
409+
self.push("ty::Const");
410+
self.push(&format!("+ ty: {:?}", ty));
411+
self.push(&format!("+ val: {:?}", val));
412+
}
413+
}
404414
}
405415

406416
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {

src/test/mir-opt/address_of.address_of_reborrow.SimplifyCfg-initial.after.mir

-12
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,11 @@ fn address_of_reborrow() -> () {
129129
StorageLive(_1); // scope 0 at $DIR/address-of.rs:4:9: 4:10
130130
StorageLive(_2); // scope 0 at $DIR/address-of.rs:4:14: 4:21
131131
_2 = [const 0_i32; 10]; // scope 0 at $DIR/address-of.rs:4:14: 4:21
132-
// ty::Const
133-
// + ty: i32
134-
// + val: Value(Scalar(0x00000000))
135-
// mir::Constant
136-
// + span: $DIR/address-of.rs:4:15: 4:16
137-
// + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) }
138132
_1 = &_2; // scope 0 at $DIR/address-of.rs:4:13: 4:21
139133
FakeRead(ForLet, _1); // scope 0 at $DIR/address-of.rs:4:9: 4:10
140134
StorageLive(_3); // scope 1 at $DIR/address-of.rs:5:9: 5:14
141135
StorageLive(_4); // scope 1 at $DIR/address-of.rs:5:22: 5:29
142136
_4 = [const 0_i32; 10]; // scope 1 at $DIR/address-of.rs:5:22: 5:29
143-
// ty::Const
144-
// + ty: i32
145-
// + val: Value(Scalar(0x00000000))
146-
// mir::Constant
147-
// + span: $DIR/address-of.rs:5:23: 5:24
148-
// + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) }
149137
_3 = &mut _4; // scope 1 at $DIR/address-of.rs:5:17: 5:29
150138
FakeRead(ForLet, _3); // scope 1 at $DIR/address-of.rs:5:9: 5:14
151139
StorageLive(_5); // scope 2 at $DIR/address-of.rs:7:5: 7:18

src/test/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir.32bit

-24
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,8 @@ fn main() -> () {
2626
bb0: {
2727
StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14
2828
_1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29
29-
// ty::Const
30-
// + ty: u32
31-
// + val: Value(Scalar(0x0000002a))
32-
// mir::Constant
33-
// + span: $DIR/array-index-is-temporary.rs:13:18: 13:20
34-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) }
35-
// ty::Const
36-
// + ty: u32
37-
// + val: Value(Scalar(0x0000002b))
38-
// mir::Constant
39-
// + span: $DIR/array-index-is-temporary.rs:13:22: 13:24
40-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002b)) }
41-
// ty::Const
42-
// + ty: u32
43-
// + val: Value(Scalar(0x0000002c))
44-
// mir::Constant
45-
// + span: $DIR/array-index-is-temporary.rs:13:26: 13:28
46-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002c)) }
4729
StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14
4830
_2 = const 1_usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18
49-
// ty::Const
50-
// + ty: usize
51-
// + val: Value(Scalar(0x00000001))
52-
// mir::Constant
53-
// + span: $DIR/array-index-is-temporary.rs:14:17: 14:18
54-
// + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) }
5531
StorageLive(_3); // scope 2 at $DIR/array-index-is-temporary.rs:15:9: 15:10
5632
StorageLive(_4); // scope 2 at $DIR/array-index-is-temporary.rs:15:25: 15:31
5733
_4 = &mut _2; // scope 2 at $DIR/array-index-is-temporary.rs:15:25: 15:31

src/test/mir-opt/array_index_is_temporary.main.SimplifyCfg-elaborate-drops.after.mir.64bit

-24
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,8 @@ fn main() -> () {
2626
bb0: {
2727
StorageLive(_1); // scope 0 at $DIR/array-index-is-temporary.rs:13:9: 13:14
2828
_1 = [const 42_u32, const 43_u32, const 44_u32]; // scope 0 at $DIR/array-index-is-temporary.rs:13:17: 13:29
29-
// ty::Const
30-
// + ty: u32
31-
// + val: Value(Scalar(0x0000002a))
32-
// mir::Constant
33-
// + span: $DIR/array-index-is-temporary.rs:13:18: 13:20
34-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002a)) }
35-
// ty::Const
36-
// + ty: u32
37-
// + val: Value(Scalar(0x0000002b))
38-
// mir::Constant
39-
// + span: $DIR/array-index-is-temporary.rs:13:22: 13:24
40-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002b)) }
41-
// ty::Const
42-
// + ty: u32
43-
// + val: Value(Scalar(0x0000002c))
44-
// mir::Constant
45-
// + span: $DIR/array-index-is-temporary.rs:13:26: 13:28
46-
// + literal: Const { ty: u32, val: Value(Scalar(0x0000002c)) }
4729
StorageLive(_2); // scope 1 at $DIR/array-index-is-temporary.rs:14:9: 14:14
4830
_2 = const 1_usize; // scope 1 at $DIR/array-index-is-temporary.rs:14:17: 14:18
49-
// ty::Const
50-
// + ty: usize
51-
// + val: Value(Scalar(0x0000000000000001))
52-
// mir::Constant
53-
// + span: $DIR/array-index-is-temporary.rs:14:17: 14:18
54-
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) }
5531
StorageLive(_3); // scope 2 at $DIR/array-index-is-temporary.rs:15:9: 15:10
5632
StorageLive(_4); // scope 2 at $DIR/array-index-is-temporary.rs:15:25: 15:31
5733
_4 = &mut _2; // scope 2 at $DIR/array-index-is-temporary.rs:15:25: 15:31

src/test/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ fn main() -> () {
2828
bb0: {
2929
StorageLive(_1); // scope 0 at $DIR/basic_assignment.rs:11:9: 11:17
3030
_1 = const false; // scope 0 at $DIR/basic_assignment.rs:11:20: 11:25
31-
// ty::Const
32-
// + ty: bool
33-
// + val: Value(Scalar(0x00))
34-
// mir::Constant
35-
// + span: $DIR/basic_assignment.rs:11:20: 11:25
36-
// + literal: Const { ty: bool, val: Value(Scalar(0x00)) }
3731
FakeRead(ForLet, _1); // scope 0 at $DIR/basic_assignment.rs:11:9: 11:17
3832
StorageLive(_2); // scope 1 at $DIR/basic_assignment.rs:12:9: 12:17
3933
StorageLive(_3); // scope 2 at $DIR/basic_assignment.rs:16:16: 16:24

src/test/mir-opt/byte_slice.main.SimplifyCfg-elaborate-drops.after.mir

-12
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ fn main() -> () {
2222
// + literal: Const { ty: &[u8; 3], val: Value(Scalar(alloc0)) }
2323
StorageLive(_2); // scope 1 at $DIR/byte_slice.rs:6:9: 6:10
2424
_2 = [const 5_u8, const 120_u8]; // scope 1 at $DIR/byte_slice.rs:6:13: 6:24
25-
// ty::Const
26-
// + ty: u8
27-
// + val: Value(Scalar(0x05))
28-
// mir::Constant
29-
// + span: $DIR/byte_slice.rs:6:14: 6:17
30-
// + literal: Const { ty: u8, val: Value(Scalar(0x05)) }
31-
// ty::Const
32-
// + ty: u8
33-
// + val: Value(Scalar(0x78))
34-
// mir::Constant
35-
// + span: $DIR/byte_slice.rs:6:19: 6:23
36-
// + literal: Const { ty: u8, val: Value(Scalar(0x78)) }
3725
_0 = const (); // scope 0 at $DIR/byte_slice.rs:4:11: 7:2
3826
// ty::Const
3927
// + ty: ()

src/test/mir-opt/combine_array_len.norm2.InstCombine.diff.32bit

-24
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,8 @@
2929
StorageLive(_2); // scope 0 at $DIR/combine_array_len.rs:5:9: 5:10
3030
StorageLive(_3); // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
3131
_3 = const 0_usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
32-
// ty::Const
33-
// + ty: usize
34-
// + val: Value(Scalar(0x00000000))
35-
// mir::Constant
36-
// + span: $DIR/combine_array_len.rs:5:15: 5:16
37-
// + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
3832
- _4 = Len(_1); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
3933
+ _4 = const 2_usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
40-
+ // ty::Const
41-
+ // + ty: usize
42-
+ // + val: Value(Scalar(0x00000002))
43-
+ // mir::Constant
44-
+ // + span: $DIR/combine_array_len.rs:5:13: 5:17
45-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
4634
_5 = Lt(_3, _4); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
4735
assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
4836
}
@@ -53,20 +41,8 @@
5341
StorageLive(_6); // scope 1 at $DIR/combine_array_len.rs:6:9: 6:10
5442
StorageLive(_7); // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16
5543
_7 = const 1_usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16
56-
// ty::Const
57-
// + ty: usize
58-
// + val: Value(Scalar(0x00000001))
59-
// mir::Constant
60-
// + span: $DIR/combine_array_len.rs:6:15: 6:16
61-
// + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) }
6244
- _8 = Len(_1); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
6345
+ _8 = const 2_usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
64-
+ // ty::Const
65-
+ // + ty: usize
66-
+ // + val: Value(Scalar(0x00000002))
67-
+ // mir::Constant
68-
+ // + span: $DIR/combine_array_len.rs:6:13: 6:17
69-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
7046
_9 = Lt(_7, _8); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
7147
assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
7248
}

src/test/mir-opt/combine_array_len.norm2.InstCombine.diff.64bit

-24
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,8 @@
2929
StorageLive(_2); // scope 0 at $DIR/combine_array_len.rs:5:9: 5:10
3030
StorageLive(_3); // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
3131
_3 = const 0_usize; // scope 0 at $DIR/combine_array_len.rs:5:15: 5:16
32-
// ty::Const
33-
// + ty: usize
34-
// + val: Value(Scalar(0x0000000000000000))
35-
// mir::Constant
36-
// + span: $DIR/combine_array_len.rs:5:15: 5:16
37-
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
3832
- _4 = Len(_1); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
3933
+ _4 = const 2_usize; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
40-
+ // ty::Const
41-
+ // + ty: usize
42-
+ // + val: Value(Scalar(0x0000000000000002))
43-
+ // mir::Constant
44-
+ // + span: $DIR/combine_array_len.rs:5:13: 5:17
45-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
4634
_5 = Lt(_3, _4); // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
4735
assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
4836
}
@@ -53,20 +41,8 @@
5341
StorageLive(_6); // scope 1 at $DIR/combine_array_len.rs:6:9: 6:10
5442
StorageLive(_7); // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16
5543
_7 = const 1_usize; // scope 1 at $DIR/combine_array_len.rs:6:15: 6:16
56-
// ty::Const
57-
// + ty: usize
58-
// + val: Value(Scalar(0x0000000000000001))
59-
// mir::Constant
60-
// + span: $DIR/combine_array_len.rs:6:15: 6:16
61-
// + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) }
6244
- _8 = Len(_1); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
6345
+ _8 = const 2_usize; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
64-
+ // ty::Const
65-
+ // + ty: usize
66-
+ // + val: Value(Scalar(0x0000000000000002))
67-
+ // mir::Constant
68-
+ // + span: $DIR/combine_array_len.rs:6:13: 6:17
69-
+ // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
7046
_9 = Lt(_7, _8); // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
7147
assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
7248
}

0 commit comments

Comments
 (0)