Skip to content

Commit 1d56b8a

Browse files
committed
Make unevaluated DefId rendering deterministic
1 parent 5582b19 commit 1d56b8a

20 files changed

+37
-23
lines changed

compiler/rustc_mir/src/util/pretty.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,21 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
465465
if use_verbose(ty) {
466466
self.push("ty::Const");
467467
self.push(&format!("+ ty: {:?}", ty));
468-
self.push(&format!("+ val: {:?}", val));
468+
let val = match val {
469+
ty::ConstKind::Param(p) => format!("Param({})", p),
470+
ty::ConstKind::Infer(infer) => format!("Infer({:?})", infer),
471+
ty::ConstKind::Bound(idx, var) => format!("Bound({:?}, {:?})", idx, var),
472+
ty::ConstKind::Placeholder(ph) => format!("PlaceHolder({:?})", ph),
473+
ty::ConstKind::Unevaluated(uv) => format!(
474+
"Unevaluated({}, {:?}, {:?})",
475+
self.tcx.def_path_str(uv.def.did),
476+
uv.substs,
477+
uv.promoted
478+
),
479+
ty::ConstKind::Value(val) => format!("Value({:?})", val),
480+
ty::ConstKind::Error(_) => format!("Error"),
481+
};
482+
self.push(&format!("+ val: {}", val));
469483
}
470484
}
471485

src/test/mir-opt/const_promotion_extern_static.BAR.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
- // + ty: &i32
2323
- // + val: Value(Scalar(alloc0))
2424
+ // + ty: &[&i32; 1]
25-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
25+
+ // + val: Unevaluated(BAR, [], Some(promoted[0]))
2626
// mir::Constant
2727
- // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34
2828
- // + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) }

src/test/mir-opt/const_promotion_extern_static.FOO.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- // + ty: *const i32
2525
- // + val: Value(Scalar(alloc2))
2626
+ // + ty: &[&i32; 1]
27-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
27+
+ // + val: Unevaluated(FOO, [], Some(promoted[0]))
2828
// mir::Constant
2929
- // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43
3030
- // + literal: Const { ty: *const i32, val: Value(Scalar(alloc2)) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2929
// ty::Const
3030
// + ty: &[i32; 3]
31-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
31+
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3434
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
2929
// ty::Const
3030
// + ty: &[i32; 3]
31-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
31+
// + val: Unevaluated(main, [], Some(promoted[0]))
3232
// mir::Constant
3333
// + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35
3434
// + literal: Const { ty: &[i32; 3], val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/const_prop_fails_gracefully.main.ConstProp.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_3 = const FOO; // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
2020
// ty::Const
2121
// + ty: &i32
22-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main::FOO), const_param_did: None }, substs: [], promoted: None })
22+
// + val: Unevaluated(FOO, [], None)
2323
// mir::Constant
2424
// + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16
2525
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main::FOO), const_param_did: None }, substs: [], promoted: None }) }

src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
1515
// ty::Const
1616
// + ty: &i32
17-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
17+
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref.rs:5:6: 5:10
2020
// + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/ref_deref.main.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
1818
+ // ty::Const
1919
+ // + ty: &i32
20-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
20+
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref.rs:5:6: 5:10
2323
+ // + literal: Const { ty: &i32, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
1515
// ty::Const
1616
// + ty: &(i32, i32)
17-
// + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
17+
// + val: Unevaluated(main, [], Some(promoted[0]))
1818
// mir::Constant
1919
// + span: $DIR/ref_deref_project.rs:5:6: 5:17
2020
// + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

src/test/mir-opt/const_prop/ref_deref_project.main.PromoteTemps.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
+ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
1818
+ // ty::Const
1919
+ // + ty: &(i32, i32)
20-
+ // + val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) })
20+
+ // + val: Unevaluated(main, [], Some(promoted[0]))
2121
+ // mir::Constant
2222
+ // + span: $DIR/ref_deref_project.rs:5:6: 5:17
2323
+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, substs: [], promoted: Some(promoted[0]) }) }

0 commit comments

Comments
 (0)