Skip to content

Commit

Permalink
Rollup merge of rust-lang#71021 - robojumper:71000-mir-assert-syntax,…
Browse files Browse the repository at this point in the history
… r=jonas-schievink

Use write!-style syntax for MIR assert terminator

Fixes rust-lang#71000.

r? @jonas-schievink
  • Loading branch information
Dylan-DPC authored Apr 11, 2020
2 parents b794cb2 + b78ff99 commit d8dcdec
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 25 deletions.
19 changes: 18 additions & 1 deletion src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,21 @@ impl<O> AssertKind<O> {
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> {
Expand Down Expand Up @@ -1480,7 +1495,9 @@ impl<'tcx> TerminatorKind<'tcx> {
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
// + 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
+ // + val: Value(Scalar(0x01))
+ // 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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): {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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): {
Expand Down

0 comments on commit d8dcdec

Please sign in to comment.