@@ -74,6 +74,8 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
74
74
bt_fmt. add_context ( ) ?;
75
75
let mut idx = 0 ;
76
76
let mut res = Ok ( ( ) ) ;
77
+ // Start immediately if we're not using a short backtrace.
78
+ let mut start = print_fmt != PrintFmt :: Short ;
77
79
backtrace_rs:: trace_unsynchronized ( |frame| {
78
80
if print_fmt == PrintFmt :: Short && idx > MAX_NB_FRAMES {
79
81
return false ;
@@ -89,16 +91,24 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
89
91
stop = true ;
90
92
return ;
91
93
}
94
+ if sym. contains ( "__rust_end_short_backtrace" ) {
95
+ start = true ;
96
+ return ;
97
+ }
92
98
}
93
99
}
94
100
95
- res = bt_fmt. frame ( ) . symbol ( frame, symbol) ;
101
+ if start {
102
+ res = bt_fmt. frame ( ) . symbol ( frame, symbol) ;
103
+ }
96
104
} ) ;
97
105
if stop {
98
106
return false ;
99
107
}
100
108
if !hit {
101
- res = bt_fmt. frame ( ) . print_raw ( frame. ip ( ) , None , None , None ) ;
109
+ if start {
110
+ res = bt_fmt. frame ( ) . print_raw ( frame. ip ( ) , None , None , None ) ;
111
+ }
102
112
}
103
113
104
114
idx += 1 ;
@@ -123,10 +133,29 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
123
133
pub fn __rust_begin_short_backtrace < F , T > ( f : F ) -> T
124
134
where
125
135
F : FnOnce ( ) -> T ,
126
- F : Send ,
127
- T : Send ,
128
136
{
129
- f ( )
137
+ let result = f ( ) ;
138
+
139
+ // prevent this frame from being tail-call optimised away
140
+ crate :: hint:: black_box ( ( ) ) ;
141
+
142
+ result
143
+ }
144
+
145
+ /// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`. Note that
146
+ /// this is only inline(never) when backtraces in libstd are enabled, otherwise
147
+ /// it's fine to optimize away.
148
+ #[ cfg_attr( feature = "backtrace" , inline( never) ) ]
149
+ pub fn __rust_end_short_backtrace < F , T > ( f : F ) -> T
150
+ where
151
+ F : FnOnce ( ) -> T ,
152
+ {
153
+ let result = f ( ) ;
154
+
155
+ // prevent this frame from being tail-call optimised away
156
+ crate :: hint:: black_box ( ( ) ) ;
157
+
158
+ result
130
159
}
131
160
132
161
pub enum RustBacktrace {
0 commit comments