Skip to content

Commit ddacb2d

Browse files
committed
omit count
1 parent d8f91e8 commit ddacb2d

6 files changed

+85
-3
lines changed

library/std/src/sys_common/backtrace.rs

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
5959
let mut bt_fmt = BacktraceFmt::new(fmt, print_fmt, &mut print_path);
6060
bt_fmt.add_context()?;
6161
let mut idx = 0;
62+
let mut emitted_count: usize = 0;
6263
let mut res = Ok(());
6364
// Start immediately if we're not using a short backtrace.
6465
let mut start = print_fmt != PrintFmt::Short;
@@ -85,10 +86,17 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
8586
start = true;
8687
return;
8788
}
89+
if !start {
90+
emitted_count += 1;
91+
}
8892
}
8993
}
9094

9195
if start {
96+
if emitted_count > 0 {
97+
let _ = bt_fmt.print_omitted_count(emitted_count);
98+
emitted_count = 0;
99+
}
92100
res = bt_fmt.frame().symbol(frame, symbol);
93101
}
94102
});

tests/ui/consts/const-eval/const-eval-query-stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const-eval-query-stack.rs:16:16
2+
--> $DIR/const-eval-query-stack.rs:17:16
33
|
44
LL | const X: i32 = 1 / 0;
55
| ^^^^^ attempt to divide `1_i32` by zero
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// compile-flags:-Cstrip=none
2+
// run-fail
3+
// check-run-results
4+
// exec-env:RUST_BACKTRACE=1
5+
// ignore-android FIXME #17520
6+
// ignore-wasm no panic support
7+
// ignore-openbsd no support for libbacktrace without filename
8+
// ignore-emscripten no panic or subprocess support
9+
// ignore-sgx no subprocess support
10+
// ignore-fuchsia Backtraces not symbolized
11+
// ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable.
12+
13+
14+
#[inline(never)]
15+
fn __rust_begin_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T {
16+
let result = f();
17+
std::hint::black_box(result)
18+
}
19+
20+
#[inline(never)]
21+
fn __rust_end_short_backtrace<T, F: FnOnce() -> T>(f: F) -> T {
22+
let result = f();
23+
std::hint::black_box(result)
24+
}
25+
26+
fn first() {
27+
__rust_end_short_backtrace(|| second());
28+
}
29+
30+
fn second() {
31+
third(); // won't show up
32+
}
33+
34+
fn third() {
35+
fourth(); // won't show up
36+
}
37+
38+
fn fourth() {
39+
__rust_begin_short_backtrace(|| fifth());
40+
}
41+
42+
fn fifth() {
43+
__rust_end_short_backtrace(|| sixth());
44+
}
45+
46+
fn sixth() {
47+
seven(); // won't show up
48+
}
49+
50+
fn seven() {
51+
__rust_begin_short_backtrace(|| eight());
52+
}
53+
54+
fn eight() {
55+
panic!("debug!!!");
56+
}
57+
58+
fn main() {
59+
first();
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
thread 'main' panicked at 'debug!!!', $DIR/short-ice-remove-middle-frames-2.rs:55:5
2+
stack backtrace:
3+
0: std::panicking::begin_panic
4+
1: short_ice_remove_middle_frames_2::eight
5+
2: short_ice_remove_middle_frames_2::seven::{{closure}}
6+
... omitted 3 frames ...
7+
3: short_ice_remove_middle_frames_2::fifth
8+
4: short_ice_remove_middle_frames_2::fourth::{{closure}}
9+
... omitted 4 frames ...
10+
5: short_ice_remove_middle_frames_2::first
11+
6: short_ice_remove_middle_frames_2::main
12+
7: core::ops::function::FnOnce::call_once
13+
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

tests/ui/panics/short-ice-remove-middle-frames.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// ignore-android FIXME #17520
66
// ignore-wasm no panic support
77
// ignore-openbsd no support for libbacktrace without filename
8-
// ignore-emscripten no panic or subprocess support
9-
// ignore-sgx no subprocess support
8+
// ignore-emscripten no panic
9+
// ignore-sgx Backtraces not symbolized
1010
// ignore-fuchsia Backtraces not symbolized
1111
// ignore-msvc the `__rust_{begin,end}_short_backtrace` symbols aren't reliable.
1212

tests/ui/panics/short-ice-remove-middle-frames.run.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ stack backtrace:
44
1: short_ice_remove_middle_frames::seven
55
2: short_ice_remove_middle_frames::sixth
66
3: short_ice_remove_middle_frames::fifth::{{closure}}
7+
... omitted 4 frames ...
78
4: short_ice_remove_middle_frames::second
89
5: short_ice_remove_middle_frames::first::{{closure}}
910
6: short_ice_remove_middle_frames::first

0 commit comments

Comments
 (0)