]> git.lizzy.rs Git - rust.git/commitdiff
Use write!-style syntax for MIR assert terminator
authorrobojumper <robojumper@gmail.com>
Sat, 11 Apr 2020 10:59:19 +0000 (12:59 +0200)
committerrobojumper <robojumper@gmail.com>
Sat, 11 Apr 2020 11:27:51 +0000 (13:27 +0200)
15 files changed:
src/librustc_middle/mir/mod.rs
src/test/mir-opt/array-index-is-temporary/32bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir
src/test/mir-opt/array-index-is-temporary/64bit/rustc.main.SimplifyCfg-elaborate-drops.after.mir
src/test/mir-opt/combine_array_len/32bit/rustc.norm2.InstCombine.diff
src/test/mir-opt/combine_array_len/64bit/rustc.norm2.InstCombine.diff
src/test/mir-opt/const_prop/array_index/32bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/array_index/64bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/optimizes_into_variable/32bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/optimizes_into_variable/64bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/repeat/32bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/repeat/64bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff
src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff
src/test/mir-opt/nll/region-subtyping-basic/32bit/rustc.main.nll.0.mir
src/test/mir-opt/nll/region-subtyping-basic/64bit/rustc.main.nll.0.mir

index b82008f429fa4a37e32010e23b28d94bcc81f267..212061cfd824f9c365b61e6feb59f54c4068140f 100644 (file)
@@ -1403,6 +1403,21 @@ pub fn description(&self) -> &'static str {
             BoundsCheck { .. } => bug!("Unexpected AssertKind"),
         }
     }
+
+    /// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing.
+    fn fmt_assert_args<W: Write>(&self, f: &mut W) -> fmt::Result
+    where
+        O: Debug,
+    {
+        match self {
+            AssertKind::BoundsCheck { ref len, ref index } => write!(
+                f,
+                "\"index out of bounds: the len is {{}} but the index is {{}}\", {:?}, {:?}",
+                len, index
+            ),
+            _ => write!(f, "\"{}\"", self.description()),
+        }
+    }
 }
 
 impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
@@ -1480,7 +1495,9 @@ pub fn fmt_head<W: Write>(&self, fmt: &mut W) -> fmt::Result {
                 if !expected {
                     write!(fmt, "!")?;
                 }
-                write!(fmt, "{:?}, \"{:?}\")", cond, msg)
+                write!(fmt, "{:?}, ", cond)?;
+                msg.fmt_assert_args(fmt)?;
+                write!(fmt, ")")
             }
             FalseEdges { .. } => write!(fmt, "falseEdges"),
             FalseUnwind { .. } => write!(fmt, "falseUnwind"),
index 052a335d00be683305616313e4909243385d1870..0016cebbb4c064341ffe657d44a060d75ae864b7 100644 (file)
@@ -75,7 +75,7 @@ fn main() -> () {
         _7 = _2;                         // bb1[2]: scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
         _8 = Len(_1);                    // bb1[3]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
         _9 = Lt(_7, _8);                 // bb1[4]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
-        assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2; // bb1[5]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
+        assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // bb1[5]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
     }
 
     bb2: {
index e180f4496954826796623f43dbb1ba3d697b9184..a004ab4a06aed524401b46f9b6869822892984e7 100644 (file)
@@ -75,7 +75,7 @@ fn main() -> () {
         _7 = _2;                         // bb1[2]: scope 3 at $DIR/array-index-is-temporary.rs:16:7: 16:8
         _8 = Len(_1);                    // bb1[3]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
         _9 = Lt(_7, _8);                 // bb1[4]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
-        assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2; // bb1[5]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
+        assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // bb1[5]: scope 3 at $DIR/array-index-is-temporary.rs:16:5: 16:9
     }
 
     bb2: {
index 7ec1c9ac637b35c6d71ded5b565bfa41e5043002..1deeee0f61239e5431d03f72d122b3be3bf4c872 100644 (file)
@@ -44,7 +44,7 @@
 +                                          // + span: $DIR/combine_array_len.rs:5:13: 5:17
 +                                          // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
           _5 = Lt(_3, _4);                 // bb0[4]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
-          assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[5]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
+          assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[5]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
       }
   
       bb1: {
@@ -68,7 +68,7 @@
 +                                          // + span: $DIR/combine_array_len.rs:6:13: 6:17
 +                                          // + literal: Const { ty: usize, val: Value(Scalar(0x00000002)) }
           _9 = Lt(_7, _8);                 // bb1[6]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
-          assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2; // bb1[7]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
+          assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // bb1[7]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
       }
   
       bb2: {
index 0bab28738d8acbc4acc0e9dde3aef9d92fba1510..7120829e2b54a0bf0db53a307947767ed40b98e9 100644 (file)
@@ -44,7 +44,7 @@
 +                                          // + span: $DIR/combine_array_len.rs:5:13: 5:17
 +                                          // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
           _5 = Lt(_3, _4);                 // bb0[4]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
-          assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[5]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
+          assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[5]: scope 0 at $DIR/combine_array_len.rs:5:13: 5:17
       }
   
       bb1: {
@@ -68,7 +68,7 @@
 +                                          // + span: $DIR/combine_array_len.rs:6:13: 6:17
 +                                          // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000002)) }
           _9 = Lt(_7, _8);                 // bb1[6]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
-          assert(move _9, "index out of bounds: the len is move _8 but the index is _7") -> bb2; // bb1[7]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
+          assert(move _9, "index out of bounds: the len is {} but the index is {}", move _8, _7) -> bb2; // bb1[7]: scope 1 at $DIR/combine_array_len.rs:6:13: 6:17
       }
   
       bb2: {
index f956ef82707bc0a776165769ba02158195d9e1f5..99d79b23e9e60f438291fc623c2b5b0ba175f993 100644 (file)
@@ -56,7 +56,7 @@
                                            // + span: $DIR/array_index.rs:5:18: 5:33
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x00000004)) }
 -         _5 = Lt(_3, _4);                 // bb0[6]: scope 0 at $DIR/array_index.rs:5:18: 5:33
--         assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
+-         assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +         _5 = const true;                 // bb0[6]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
@@ -64,7 +64,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/array_index.rs:5:18: 5:33
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index c336d6e66ae4d80111da4d909339d79a8a8cbbb6..629ca226f2ad60645af2ea66f06f3d0df4eab013 100644 (file)
@@ -56,7 +56,7 @@
                                            // + span: $DIR/array_index.rs:5:18: 5:33
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000004)) }
 -         _5 = Lt(_3, _4);                 // bb0[6]: scope 0 at $DIR/array_index.rs:5:18: 5:33
--         assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
+-         assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +         _5 = const true;                 // bb0[6]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
@@ -64,7 +64,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/array_index.rs:5:18: 5:33
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _4 but the index is _3") -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> bb1; // bb0[7]: scope 0 at $DIR/array_index.rs:5:18: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index d8bd397d74a6569665fe9b839451aa6ba9c644ce..41ffedf06bc980c711526dbde6fa10a512855377 100644 (file)
                                            // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x00000006)) }
 -         _7 = Lt(_5, _6);                 // bb1[7]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
--         assert(move _7, "index out of bounds: the len is move _6 but the index is _5") -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
+-         assert(move _7, "index out of bounds: the len is {} but the index is {}", move _6, _5) -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +         _7 = const true;                 // bb1[7]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // mir::Constant
 +                                          // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _6 but the index is _5") -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _6, _5) -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index 9e646e7336d8014a7a6921a84f5bcf1b195b1592..fd3281f527372a4e7cfa2d25a437d926aa87071e 100644 (file)
                                            // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000006)) }
 -         _7 = Lt(_5, _6);                 // bb1[7]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
--         assert(move _7, "index out of bounds: the len is move _6 but the index is _5") -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
+-         assert(move _7, "index out of bounds: the len is {} but the index is {}", move _6, _5) -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +         _7 = const true;                 // bb1[7]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // mir::Constant
 +                                          // + span: $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _6 but the index is _5") -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _6, _5) -> bb2; // bb1[8]: scope 1 at $DIR/optimizes_into_variable.rs:13:13: 13:34
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index dce98d88e3d9211d542d1285d499d0e0aea4e9d5..9d62fa31a4565d4b811edc0aea219b20a8489ed6 100644 (file)
@@ -40,7 +40,7 @@
                                            // + span: $DIR/repeat.rs:6:18: 6:28
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x00000008)) }
 -         _6 = Lt(_4, _5);                 // bb0[7]: scope 0 at $DIR/repeat.rs:6:18: 6:28
--         assert(move _6, "index out of bounds: the len is move _5 but the index is _4") -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
+-         assert(move _6, "index out of bounds: the len is {} but the index is {}", move _5, _4) -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +         _6 = const true;                 // bb0[7]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +                                          // ty::Const
 +                                          // + ty: bool
@@ -48,7 +48,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/repeat.rs:6:18: 6:28
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _5 but the index is _4") -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _5, _4) -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index c9e640291f2f5c85fc60c2bba03a9d1ac503c0bf..cb84ee82cfea8bf92339b16e0d0c888e0841f21b 100644 (file)
@@ -40,7 +40,7 @@
                                            // + span: $DIR/repeat.rs:6:18: 6:28
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000008)) }
 -         _6 = Lt(_4, _5);                 // bb0[7]: scope 0 at $DIR/repeat.rs:6:18: 6:28
--         assert(move _6, "index out of bounds: the len is move _5 but the index is _4") -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
+-         assert(move _6, "index out of bounds: the len is {} but the index is {}", move _5, _4) -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +         _6 = const true;                 // bb0[7]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +                                          // ty::Const
 +                                          // + ty: bool
@@ -48,7 +48,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/repeat.rs:6:18: 6:28
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _5 but the index is _4") -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _5, _4) -> bb1; // bb0[8]: scope 0 at $DIR/repeat.rs:6:18: 6:28
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index 5f821078b75fdd72d15cfd4384712a0702980faf..dbb4171e7f0ed90e255f3cdf099cac76c60799c4 100644 (file)
@@ -39,7 +39,7 @@
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x00000001)) }
 -         _7 = Len((*_2));                 // bb0[11]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 -         _8 = Lt(_6, _7);                 // bb0[12]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
--         assert(move _8, "index out of bounds: the len is move _7 but the index is _6") -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
+-         assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +         _7 = const 3usize;               // bb0[11]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +                                          // ty::Const
 +                                          // + ty: usize
@@ -54,7 +54,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/slice_len.rs:5:5: 5:33
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _7 but the index is _6") -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index 46f98b7f0aef836912adf95f1e81157dd98254a6..3c4415e05583867c16c5d1b08c620d36408f2357 100644 (file)
@@ -39,7 +39,7 @@
                                            // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000001)) }
 -         _7 = Len((*_2));                 // bb0[11]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 -         _8 = Lt(_6, _7);                 // bb0[12]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
--         assert(move _8, "index out of bounds: the len is move _7 but the index is _6") -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
+-         assert(move _8, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +         _7 = const 3usize;               // bb0[11]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +                                          // ty::Const
 +                                          // + ty: usize
@@ -54,7 +54,7 @@
 +                                          // mir::Constant
 +                                          // + span: $DIR/slice_len.rs:5:5: 5:33
 +                                          // + literal: Const { ty: bool, val: Value(Scalar(0x01)) }
-+         assert(const true, "index out of bounds: the len is move _7 but the index is _6") -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
++         assert(const true, "index out of bounds: the len is {} but the index is {}", move _7, _6) -> bb1; // bb0[13]: scope 0 at $DIR/slice_len.rs:5:5: 5:33
 +                                          // ty::Const
 +                                          // + ty: bool
 +                                          // + val: Value(Scalar(0x01))
index f6ec2d925021e4f289a4d5ee51187af17dde898d..1f75658aa265ae7feb2f24da7e83c723c3a5f316 100644 (file)
@@ -75,7 +75,7 @@ fn main() -> () {
                                          // + literal: Const { ty: usize, val: Value(Scalar(0x00000000)) }
         _4 = Len(_1);                    // bb0[6]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
         _5 = Lt(_3, _4);                 // bb0[7]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
-        assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> [success: bb2, unwind: bb1]; // bb0[8]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
+        assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> [success: bb2, unwind: bb1]; // bb0[8]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
     }
 
     bb1 (cleanup): {
index fa3a9a0e1222ab1faa412ad9360f10acfca15840..8305c3fe7c493ecbf1aac45f831958be3614fa6f 100644 (file)
@@ -75,7 +75,7 @@ fn main() -> () {
                                          // + literal: Const { ty: usize, val: Value(Scalar(0x0000000000000000)) }
         _4 = Len(_1);                    // bb0[6]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
         _5 = Lt(_3, _4);                 // bb0[7]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
-        assert(move _5, "index out of bounds: the len is move _4 but the index is _3") -> [success: bb2, unwind: bb1]; // bb0[8]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
+        assert(move _5, "index out of bounds: the len is {} but the index is {}", move _4, _3) -> [success: bb2, unwind: bb1]; // bb0[8]: scope 1 at $DIR/region-subtyping-basic.rs:16:14: 16:18
     }
 
     bb1 (cleanup): {