Skip to content

Commit

Permalink
Auto merge of #116548 - nnethercote:assert-long-condition, r=matthewj…
Browse files Browse the repository at this point in the history
…asper

Improve handling of assertion failures with very long conditions

It's not perfectly clear what the best behaviour is here, but I think this is an improvement.

r? `@matthewjasper`
cc `@m-ou-se`
  • Loading branch information
bors committed Oct 10, 2023
2 parents 84d44dd + 7528fdc commit 091bb74
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn expand_assert<'cx>(
DUMMY_SP,
Symbol::intern(&format!(
"assertion failed: {}",
pprust::expr_to_string(&cond_expr).escape_debug()
pprust::expr_to_string(&cond_expr)
)),
)],
);
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/macros/assert-long-condition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-fail
// check-run-results
// exec-env:RUST_BACKTRACE=0
// ignore-emscripten no processes
// ignore-tidy-linelength

fn main() {
assert!(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0);
}
4 changes: 4 additions & 0 deletions tests/ui/macros/assert-long-condition.run.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
thread 'main' panicked at $DIR/assert-long-condition.rs:8:5:
assertion failed: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18
+ 19 + 20 + 21 + 22 + 23 + 24 + 25 == 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

0 comments on commit 091bb74

Please sign in to comment.