@@ -12,6 +12,7 @@ use rustc_abi::BackendRepr;
1212use rustc_data_structures:: fx:: FxHashSet ;
1313use rustc_middle:: ty:: Ty ;
1414use rustc_middle:: ty:: layout:: LayoutOf ;
15+ use rustc_span:: def_id:: DefId ;
1516use smallvec:: SmallVec ;
1617use std:: borrow:: Cow ;
1718use std:: cell:: Cell ;
@@ -56,6 +57,7 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
5657 pub fn try_decode_and_remove_format_args < ' a > (
5758 builder : & mut Builder < ' a , ' tcx > ,
5859 args : & [ SpirvValue ] ,
60+ panic_def_id : Option < DefId > ,
5961 ) -> FormatArgsResult < ' tcx > {
6062 let mut decoded_format_args = DecodedFormatArgs :: default ( ) ;
6163
@@ -187,11 +189,59 @@ impl<'tcx> DecodedFormatArgs<'tcx> {
187189 Some ( ( pieces, placeholder_count, placeholders_map_1_to_1) )
188190 } ;
189191
192+ let panic_const_message = || {
193+ let def_id = panic_def_id?;
194+ let def_path = cx. tcx . def_path_str ( def_id) ;
195+ let name = def_path. strip_prefix ( "core::panicking::panic_const::" ) ?;
196+ match name {
197+ "panic_const_add_overflow" => Some ( "attempt to add with overflow" ) ,
198+ "panic_const_sub_overflow" => Some ( "attempt to subtract with overflow" ) ,
199+ "panic_const_mul_overflow" => Some ( "attempt to multiply with overflow" ) ,
200+ "panic_const_div_overflow" => Some ( "attempt to divide with overflow" ) ,
201+ "panic_const_rem_overflow" => {
202+ Some ( "attempt to calculate the remainder with overflow" )
203+ }
204+ "panic_const_neg_overflow" => Some ( "attempt to negate with overflow" ) ,
205+ "panic_const_shr_overflow" => Some ( "attempt to shift right with overflow" ) ,
206+ "panic_const_shl_overflow" => Some ( "attempt to shift left with overflow" ) ,
207+ "panic_const_div_by_zero" => Some ( "attempt to divide by zero" ) ,
208+ "panic_const_rem_by_zero" => {
209+ Some ( "attempt to calculate the remainder with a divisor of zero" )
210+ }
211+ "panic_const_coroutine_resumed" => Some ( "coroutine resumed after completion" ) ,
212+ "panic_const_async_fn_resumed" => Some ( "`async fn` resumed after completion" ) ,
213+ "panic_const_async_gen_fn_resumed" => {
214+ Some ( "`async gen fn` resumed after completion" )
215+ }
216+ "panic_const_gen_fn_none" => {
217+ Some ( "`gen fn` should just keep returning `None` after completion" )
218+ }
219+ "panic_const_coroutine_resumed_panic" => Some ( "coroutine resumed after panicking" ) ,
220+ "panic_const_async_fn_resumed_panic" => Some ( "`async fn` resumed after panicking" ) ,
221+ "panic_const_async_gen_fn_resumed_panic" => {
222+ Some ( "`async gen fn` resumed after panicking" )
223+ }
224+ "panic_const_gen_fn_none_panic" => {
225+ Some ( "`gen fn` should just keep returning `None` after panicking" )
226+ }
227+ "panic_const_coroutine_resumed_drop" => Some ( "coroutine resumed after async drop" ) ,
228+ "panic_const_async_fn_resumed_drop" => Some ( "`async fn` resumed after async drop" ) ,
229+ "panic_const_async_gen_fn_resumed_drop" => {
230+ Some ( "`async gen fn` resumed after async drop" )
231+ }
232+ "panic_const_gen_fn_none_drop" => Some ( "`gen fn` resumed after async drop" ) ,
233+ _ => None ,
234+ }
235+ } ;
236+
190237 // HACK(eddyb) `panic_explicit` doesn't take any regular arguments,
191238 // only an (implicit) `&'static panic::Location<'static>`.
192239 if args. len ( ) == 1 {
193- decoded_format_args. const_pieces =
194- Some ( [ "explicit panic" . into ( ) ] . into_iter ( ) . collect ( ) ) ;
240+ decoded_format_args. const_pieces = Some (
241+ [ panic_const_message ( ) . unwrap_or ( "explicit panic" ) . into ( ) ]
242+ . into_iter ( )
243+ . collect ( ) ,
244+ ) ;
195245 return Ok ( decoded_format_args) ;
196246 }
197247
0 commit comments