@@ -21,6 +21,7 @@ use rustc_span::symbol::{Ident, sym};
21
21
use rustc_span:: { BytePos , DUMMY_SP , FileName , Span } ;
22
22
use tracing:: { debug, instrument, warn} ;
23
23
24
+ use super :: nice_region_error:: placeholder_error:: Highlighted ;
24
25
use crate :: error_reporting:: TypeErrCtxt ;
25
26
use crate :: errors:: {
26
27
AmbiguousImpl , AmbiguousReturn , AnnotationRequired , InferenceBadError ,
@@ -281,6 +282,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
281
282
arg : GenericArg < ' tcx > ,
282
283
highlight : ty:: print:: RegionHighlightMode < ' tcx > ,
283
284
) -> InferenceDiagnosticsData {
285
+ let tcx = self . tcx ;
284
286
match arg. unpack ( ) {
285
287
GenericArgKind :: Type ( ty) => {
286
288
if let ty:: Infer ( ty:: TyVar ( ty_vid) ) = * ty. kind ( ) {
@@ -300,12 +302,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
300
302
}
301
303
}
302
304
303
- let mut printer = ty:: print:: FmtPrinter :: new ( self . tcx , Namespace :: TypeNS ) ;
304
- printer. region_highlight_mode = highlight;
305
-
306
- ty. print ( & mut printer) . unwrap ( ) ;
307
305
InferenceDiagnosticsData {
308
- name : printer. into_buffer ( ) ,
306
+ name : Highlighted { highlight, ns : Namespace :: TypeNS , tcx, value : ty }
307
+ . to_string ( ) ,
309
308
span : None ,
310
309
kind : UnderspecifiedArgKind :: Type { prefix : ty. prefix_string ( self . tcx ) } ,
311
310
parent : None ,
@@ -324,12 +323,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
324
323
}
325
324
326
325
debug_assert ! ( !origin. span. is_dummy( ) ) ;
327
- let mut printer = ty:: print:: FmtPrinter :: new ( self . tcx , Namespace :: ValueNS ) ;
328
- printer. region_highlight_mode = highlight;
329
-
330
- ct. print ( & mut printer) . unwrap ( ) ;
331
326
InferenceDiagnosticsData {
332
- name : printer. into_buffer ( ) ,
327
+ name : Highlighted { highlight, ns : Namespace :: ValueNS , tcx, value : ct }
328
+ . to_string ( ) ,
333
329
span : Some ( origin. span ) ,
334
330
kind : UnderspecifiedArgKind :: Const { is_parameter : false } ,
335
331
parent : None ,
@@ -341,12 +337,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
341
337
// FIXME: Ideally we should look into the generic constant
342
338
// to figure out which inference var is actually unresolved so that
343
339
// this path is unreachable.
344
- let mut printer = ty:: print:: FmtPrinter :: new ( self . tcx , Namespace :: ValueNS ) ;
345
- printer. region_highlight_mode = highlight;
346
-
347
- ct. print ( & mut printer) . unwrap ( ) ;
348
340
InferenceDiagnosticsData {
349
- name : printer. into_buffer ( ) ,
341
+ name : Highlighted { highlight, ns : Namespace :: ValueNS , tcx, value : ct }
342
+ . to_string ( ) ,
350
343
span : None ,
351
344
kind : UnderspecifiedArgKind :: Const { is_parameter : false } ,
352
345
parent : None ,
0 commit comments