@@ -21,6 +21,7 @@ use rustc_span::symbol::{Ident, sym};
2121use rustc_span:: { BytePos , DUMMY_SP , FileName , Span } ;
2222use tracing:: { debug, instrument, warn} ;
2323
24+ use super :: nice_region_error:: placeholder_error:: Highlighted ;
2425use crate :: error_reporting:: TypeErrCtxt ;
2526use crate :: errors:: {
2627 AmbiguousImpl , AmbiguousReturn , AnnotationRequired , InferenceBadError ,
@@ -281,6 +282,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
281282 arg : GenericArg < ' tcx > ,
282283 highlight : ty:: print:: RegionHighlightMode < ' tcx > ,
283284 ) -> InferenceDiagnosticsData {
285+ let tcx = self . tcx ;
284286 match arg. unpack ( ) {
285287 GenericArgKind :: Type ( ty) => {
286288 if let ty:: Infer ( ty:: TyVar ( ty_vid) ) = * ty. kind ( ) {
@@ -300,12 +302,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
300302 }
301303 }
302304
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 ( ) ;
307305 InferenceDiagnosticsData {
308- name : printer. into_buffer ( ) ,
306+ name : Highlighted { highlight, ns : Namespace :: TypeNS , tcx, value : ty }
307+ . to_string ( ) ,
309308 span : None ,
310309 kind : UnderspecifiedArgKind :: Type { prefix : ty. prefix_string ( self . tcx ) } ,
311310 parent : None ,
@@ -324,12 +323,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
324323 }
325324
326325 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 ( ) ;
331326 InferenceDiagnosticsData {
332- name : printer. into_buffer ( ) ,
327+ name : Highlighted { highlight, ns : Namespace :: ValueNS , tcx, value : ct }
328+ . to_string ( ) ,
333329 span : Some ( origin. span ) ,
334330 kind : UnderspecifiedArgKind :: Const { is_parameter : false } ,
335331 parent : None ,
@@ -341,12 +337,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
341337 // FIXME: Ideally we should look into the generic constant
342338 // to figure out which inference var is actually unresolved so that
343339 // 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 ( ) ;
348340 InferenceDiagnosticsData {
349- name : printer. into_buffer ( ) ,
341+ name : Highlighted { highlight, ns : Namespace :: ValueNS , tcx, value : ct }
342+ . to_string ( ) ,
350343 span : None ,
351344 kind : UnderspecifiedArgKind :: Const { is_parameter : false } ,
352345 parent : None ,
0 commit comments