@@ -158,6 +158,10 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
158
158
ty:: Adt ( adt, _) if self . tcx . is_diagnostic_item ( sym:: Arguments , adt. did ) => {
159
159
return self . fmt_arguments ( arg, f) ;
160
160
}
161
+ ty:: Adt ( adt, _) if self . tcx . is_diagnostic_item ( sym:: String , adt. did ) => {
162
+ // NOTE(nbdd0121): const `String` can only be empty.
163
+ dispatch_fmt ! ( "" , Display ) ;
164
+ }
161
165
162
166
// FIXME(nbdd0121): ty::Adt(..) => (),
163
167
_ => {
@@ -241,4 +245,18 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
241
245
self . fmt_arguments ( arguments, & mut formatter) ?;
242
246
Ok ( msg)
243
247
}
248
+
249
+ pub ( super ) fn eval_const_panic_any ( & mut self , arg : OpTy < ' tcx > ) -> InterpResult < ' tcx , String > {
250
+ match arg. layout . ty . kind ( ) {
251
+ ty:: Ref ( _, ty, _) if ty. is_str ( ) => {
252
+ let place = self . deref_operand ( & arg) ?;
253
+ Ok ( self . read_str ( & place) ?. to_string ( ) )
254
+ }
255
+ ty:: Adt ( adt, _) if self . tcx . is_diagnostic_item ( sym:: String , adt. did ) => {
256
+ // NOTE(nbdd0121): const `String` can only be empty.
257
+ Ok ( String :: new ( ) )
258
+ }
259
+ _ => Ok ( "Box<dyn Any>" . to_string ( ) ) ,
260
+ }
261
+ }
244
262
}
0 commit comments