@@ -224,7 +224,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
224224 self . hir ( ) . span ( node) ,
225225 ) ,
226226 _ => (
227- format ! ( "the lifetime {} as defined on" , fr . bound_region ) ,
227+ format ! ( "the lifetime {} as defined on" , region ) ,
228228 cm. def_span ( self . hir ( ) . span ( node) ) ,
229229 ) ,
230230 } ,
@@ -445,17 +445,109 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445445 terr : & TypeError < ' tcx > ,
446446 sp : Span ,
447447 ) {
448+ use hir:: def_id:: CrateNum ;
449+ use hir:: map:: DisambiguatedDefPathData ;
450+ use ty:: print:: Printer ;
451+ use ty:: subst:: Kind ;
452+
453+ struct AbsolutePathPrinter < ' a , ' gcx , ' tcx > {
454+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
455+ }
456+
457+ struct NonTrivialPath ;
458+
459+ impl < ' gcx , ' tcx > Printer < ' gcx , ' tcx > for AbsolutePathPrinter < ' _ , ' gcx , ' tcx > {
460+ type Error = NonTrivialPath ;
461+
462+ type Path = Vec < String > ;
463+ type Region = !;
464+ type Type = !;
465+ type DynExistential = !;
466+
467+ fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' a , ' gcx , ' tcx > {
468+ self . tcx
469+ }
470+
471+ fn print_region (
472+ self ,
473+ _region : ty:: Region < ' _ > ,
474+ ) -> Result < Self :: Region , Self :: Error > {
475+ Err ( NonTrivialPath )
476+ }
477+
478+ fn print_type (
479+ self ,
480+ _ty : Ty < ' tcx > ,
481+ ) -> Result < Self :: Type , Self :: Error > {
482+ Err ( NonTrivialPath )
483+ }
484+
485+ fn print_dyn_existential (
486+ self ,
487+ _predicates : & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > ,
488+ ) -> Result < Self :: DynExistential , Self :: Error > {
489+ Err ( NonTrivialPath )
490+ }
491+
492+ fn path_crate (
493+ self ,
494+ cnum : CrateNum ,
495+ ) -> Result < Self :: Path , Self :: Error > {
496+ Ok ( vec ! [ self . tcx. original_crate_name( cnum) . to_string( ) ] )
497+ }
498+ fn path_qualified (
499+ self ,
500+ _self_ty : Ty < ' tcx > ,
501+ _trait_ref : Option < ty:: TraitRef < ' tcx > > ,
502+ ) -> Result < Self :: Path , Self :: Error > {
503+ Err ( NonTrivialPath )
504+ }
505+
506+ fn path_append_impl (
507+ self ,
508+ _print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
509+ _disambiguated_data : & DisambiguatedDefPathData ,
510+ _self_ty : Ty < ' tcx > ,
511+ _trait_ref : Option < ty:: TraitRef < ' tcx > > ,
512+ ) -> Result < Self :: Path , Self :: Error > {
513+ Err ( NonTrivialPath )
514+ }
515+ fn path_append (
516+ self ,
517+ print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
518+ disambiguated_data : & DisambiguatedDefPathData ,
519+ ) -> Result < Self :: Path , Self :: Error > {
520+ let mut path = print_prefix ( self ) ?;
521+ path. push ( disambiguated_data. data . as_interned_str ( ) . to_string ( ) ) ;
522+ Ok ( path)
523+ }
524+ fn path_generic_args (
525+ self ,
526+ print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
527+ _args : & [ Kind < ' tcx > ] ,
528+ ) -> Result < Self :: Path , Self :: Error > {
529+ print_prefix ( self )
530+ }
531+ }
532+
448533 let report_path_match = |err : & mut DiagnosticBuilder < ' _ > , did1 : DefId , did2 : DefId | {
449534 // Only external crates, if either is from a local
450535 // module we could have false positives
451536 if !( did1. is_local ( ) || did2. is_local ( ) ) && did1. krate != did2. krate {
452- let exp_path = self . tcx . item_path_str ( did1) ;
453- let found_path = self . tcx . item_path_str ( did2) ;
454- let exp_abs_path = self . tcx . absolute_item_path_str ( did1) ;
455- let found_abs_path = self . tcx . absolute_item_path_str ( did2) ;
537+ let abs_path = |def_id| {
538+ AbsolutePathPrinter { tcx : self . tcx }
539+ . print_def_path ( def_id, & [ ] )
540+ } ;
541+
456542 // We compare strings because DefPath can be different
457543 // for imported and non-imported crates
458- if exp_path == found_path || exp_abs_path == found_abs_path {
544+ let same_path = || -> Result < _ , NonTrivialPath > {
545+ Ok (
546+ self . tcx . def_path_str ( did1) == self . tcx . def_path_str ( did2) ||
547+ abs_path ( did1) ? == abs_path ( did2) ?
548+ )
549+ } ;
550+ if same_path ( ) . unwrap_or ( false ) {
459551 let crate_name = self . tcx . crate_name ( did1. krate ) ;
460552 err. span_note (
461553 sp,
@@ -650,7 +742,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
650742 return Some ( ( ) ) ;
651743 }
652744 if let & ty:: Adt ( def, _) = & ta. sty {
653- let path_ = self . tcx . item_path_str ( def. did . clone ( ) ) ;
745+ let path_ = self . tcx . def_path_str ( def. did . clone ( ) ) ;
654746 if path_ == other_path {
655747 self . highlight_outer ( & mut t1_out, & mut t2_out, path, sub, i, & other_ty) ;
656748 return Some ( ( ) ) ;
@@ -675,7 +767,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
675767 }
676768
677769 /// For generic types with parameters with defaults, remove the parameters corresponding to
678- /// the defaults. This repeats a lot of the logic found in `PrintContext::parameterized `.
770+ /// the defaults. This repeats a lot of the logic found in `ty::print::pretty `.
679771 fn strip_generic_default_params (
680772 & self ,
681773 def_id : DefId ,
@@ -740,11 +832,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
740832 mutbl : hir:: Mutability ,
741833 s : & mut DiagnosticStyledString ,
742834 ) {
743- let r = & r. to_string ( ) ;
835+ let mut r = r. to_string ( ) ;
836+ if r == "'_" {
837+ r. clear ( ) ;
838+ } else {
839+ r. push ( ' ' ) ;
840+ }
744841 s. push_highlighted ( format ! (
745- "&{}{}{} " ,
842+ "&{}{}" ,
746843 r,
747- if r == "" { "" } else { " " } ,
748844 if mutbl == hir:: MutMutable { "mut " } else { "" }
749845 ) ) ;
750846 s. push_normal ( ty. to_string ( ) ) ;
@@ -755,8 +851,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
755851 let sub_no_defaults_1 = self . strip_generic_default_params ( def1. did , sub1) ;
756852 let sub_no_defaults_2 = self . strip_generic_default_params ( def2. did , sub2) ;
757853 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
758- let path1 = self . tcx . item_path_str ( def1. did . clone ( ) ) ;
759- let path2 = self . tcx . item_path_str ( def2. did . clone ( ) ) ;
854+ let path1 = self . tcx . def_path_str ( def1. did . clone ( ) ) ;
855+ let path2 = self . tcx . def_path_str ( def2. did . clone ( ) ) ;
760856 if def1. did == def2. did {
761857 // Easy case. Replace same types with `_` to shorten the output and highlight
762858 // the differing ones.
@@ -1011,7 +1107,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10111107 if exp_is_struct && & exp_found. expected == ret_ty. skip_binder ( ) {
10121108 let message = format ! (
10131109 "did you mean `{}(/* fields */)`?" ,
1014- self . tcx. item_path_str ( def_id)
1110+ self . tcx. def_path_str ( def_id)
10151111 ) ;
10161112 diag. span_label ( span, message) ;
10171113 }
@@ -1423,7 +1519,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14231519 var_origin : RegionVariableOrigin ,
14241520 ) -> DiagnosticBuilder < ' tcx > {
14251521 let br_string = |br : ty:: BoundRegion | {
1426- let mut s = br. to_string ( ) ;
1522+ let mut s = match br {
1523+ ty:: BrNamed ( _, name) => name. to_string ( ) ,
1524+ _ => String :: new ( ) ,
1525+ } ;
14271526 if !s. is_empty ( ) {
14281527 s. push_str ( " " ) ;
14291528 }
0 commit comments