@@ -223,7 +223,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
223
223
self . hir ( ) . span_by_hir_id ( node) ,
224
224
) ,
225
225
_ => (
226
- format ! ( "the lifetime {} as defined on" , fr . bound_region ) ,
226
+ format ! ( "the lifetime {} as defined on" , region ) ,
227
227
cm. def_span ( self . hir ( ) . span_by_hir_id ( node) ) ,
228
228
) ,
229
229
} ,
@@ -444,17 +444,109 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
444
444
terr : & TypeError < ' tcx > ,
445
445
sp : Span ,
446
446
) {
447
+ use hir:: def_id:: CrateNum ;
448
+ use hir:: map:: DisambiguatedDefPathData ;
449
+ use ty:: print:: Printer ;
450
+ use ty:: subst:: Kind ;
451
+
452
+ struct AbsolutePathPrinter < ' a , ' gcx , ' tcx > {
453
+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
454
+ }
455
+
456
+ struct NonTrivialPath ;
457
+
458
+ impl < ' gcx , ' tcx > Printer < ' gcx , ' tcx > for AbsolutePathPrinter < ' _ , ' gcx , ' tcx > {
459
+ type Error = NonTrivialPath ;
460
+
461
+ type Path = Vec < String > ;
462
+ type Region = !;
463
+ type Type = !;
464
+ type DynExistential = !;
465
+
466
+ fn tcx < ' a > ( & ' a self ) -> TyCtxt < ' a , ' gcx , ' tcx > {
467
+ self . tcx
468
+ }
469
+
470
+ fn print_region (
471
+ self ,
472
+ _region : ty:: Region < ' _ > ,
473
+ ) -> Result < Self :: Region , Self :: Error > {
474
+ Err ( NonTrivialPath )
475
+ }
476
+
477
+ fn print_type (
478
+ self ,
479
+ _ty : Ty < ' tcx > ,
480
+ ) -> Result < Self :: Type , Self :: Error > {
481
+ Err ( NonTrivialPath )
482
+ }
483
+
484
+ fn print_dyn_existential (
485
+ self ,
486
+ _predicates : & ' tcx ty:: List < ty:: ExistentialPredicate < ' tcx > > ,
487
+ ) -> Result < Self :: DynExistential , Self :: Error > {
488
+ Err ( NonTrivialPath )
489
+ }
490
+
491
+ fn path_crate (
492
+ self ,
493
+ cnum : CrateNum ,
494
+ ) -> Result < Self :: Path , Self :: Error > {
495
+ Ok ( vec ! [ self . tcx. original_crate_name( cnum) . to_string( ) ] )
496
+ }
497
+ fn path_qualified (
498
+ self ,
499
+ _self_ty : Ty < ' tcx > ,
500
+ _trait_ref : Option < ty:: TraitRef < ' tcx > > ,
501
+ ) -> Result < Self :: Path , Self :: Error > {
502
+ Err ( NonTrivialPath )
503
+ }
504
+
505
+ fn path_append_impl (
506
+ self ,
507
+ _print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
508
+ _disambiguated_data : & DisambiguatedDefPathData ,
509
+ _self_ty : Ty < ' tcx > ,
510
+ _trait_ref : Option < ty:: TraitRef < ' tcx > > ,
511
+ ) -> Result < Self :: Path , Self :: Error > {
512
+ Err ( NonTrivialPath )
513
+ }
514
+ fn path_append (
515
+ self ,
516
+ print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
517
+ disambiguated_data : & DisambiguatedDefPathData ,
518
+ ) -> Result < Self :: Path , Self :: Error > {
519
+ let mut path = print_prefix ( self ) ?;
520
+ path. push ( disambiguated_data. data . as_interned_str ( ) . to_string ( ) ) ;
521
+ Ok ( path)
522
+ }
523
+ fn path_generic_args (
524
+ self ,
525
+ print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
526
+ _args : & [ Kind < ' tcx > ] ,
527
+ ) -> Result < Self :: Path , Self :: Error > {
528
+ print_prefix ( self )
529
+ }
530
+ }
531
+
447
532
let report_path_match = |err : & mut DiagnosticBuilder < ' _ > , did1 : DefId , did2 : DefId | {
448
533
// Only external crates, if either is from a local
449
534
// module we could have false positives
450
535
if !( did1. is_local ( ) || did2. is_local ( ) ) && did1. krate != did2. krate {
451
- let exp_path = self . tcx . item_path_str ( did1) ;
452
- let found_path = self . tcx . item_path_str ( did2) ;
453
- let exp_abs_path = self . tcx . absolute_item_path_str ( did1) ;
454
- let found_abs_path = self . tcx . absolute_item_path_str ( did2) ;
536
+ let abs_path = |def_id| {
537
+ AbsolutePathPrinter { tcx : self . tcx }
538
+ . print_def_path ( def_id, & [ ] )
539
+ } ;
540
+
455
541
// We compare strings because DefPath can be different
456
542
// for imported and non-imported crates
457
- if exp_path == found_path || exp_abs_path == found_abs_path {
543
+ let same_path = || -> Result < _ , NonTrivialPath > {
544
+ Ok (
545
+ self . tcx . def_path_str ( did1) == self . tcx . def_path_str ( did2) ||
546
+ abs_path ( did1) ? == abs_path ( did2) ?
547
+ )
548
+ } ;
549
+ if same_path ( ) . unwrap_or ( false ) {
458
550
let crate_name = self . tcx . crate_name ( did1. krate ) ;
459
551
err. span_note (
460
552
sp,
@@ -658,7 +750,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
658
750
return Some ( ( ) ) ;
659
751
}
660
752
if let & ty:: Adt ( def, _) = & ta. sty {
661
- let path_ = self . tcx . item_path_str ( def. did . clone ( ) ) ;
753
+ let path_ = self . tcx . def_path_str ( def. did . clone ( ) ) ;
662
754
if path_ == other_path {
663
755
self . highlight_outer ( & mut t1_out, & mut t2_out, path, sub, i, & other_ty) ;
664
756
return Some ( ( ) ) ;
@@ -683,7 +775,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
683
775
}
684
776
685
777
/// For generic types with parameters with defaults, remove the parameters corresponding to
686
- /// the defaults. This repeats a lot of the logic found in `PrintContext::parameterized `.
778
+ /// the defaults. This repeats a lot of the logic found in `ty::print::pretty `.
687
779
fn strip_generic_default_params (
688
780
& self ,
689
781
def_id : DefId ,
@@ -742,11 +834,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
742
834
mutbl : hir:: Mutability ,
743
835
s : & mut DiagnosticStyledString ,
744
836
) {
745
- let r = & r. to_string ( ) ;
837
+ let mut r = r. to_string ( ) ;
838
+ if r == "'_" {
839
+ r. clear ( ) ;
840
+ } else {
841
+ r. push ( ' ' ) ;
842
+ }
746
843
s. push_highlighted ( format ! (
747
- "&{}{}{} " ,
844
+ "&{}{}" ,
748
845
r,
749
- if r == "" { "" } else { " " } ,
750
846
if mutbl == hir:: MutMutable { "mut " } else { "" }
751
847
) ) ;
752
848
s. push_normal ( ty. to_string ( ) ) ;
@@ -757,8 +853,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
757
853
let sub_no_defaults_1 = self . strip_generic_default_params ( def1. did , sub1) ;
758
854
let sub_no_defaults_2 = self . strip_generic_default_params ( def2. did , sub2) ;
759
855
let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
760
- let path1 = self . tcx . item_path_str ( def1. did . clone ( ) ) ;
761
- let path2 = self . tcx . item_path_str ( def2. did . clone ( ) ) ;
856
+ let path1 = self . tcx . def_path_str ( def1. did . clone ( ) ) ;
857
+ let path2 = self . tcx . def_path_str ( def2. did . clone ( ) ) ;
762
858
if def1. did == def2. did {
763
859
// Easy case. Replace same types with `_` to shorten the output and highlight
764
860
// the differing ones.
@@ -1013,7 +1109,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1013
1109
if exp_is_struct && & exp_found. expected == ret_ty. skip_binder ( ) {
1014
1110
let message = format ! (
1015
1111
"did you mean `{}(/* fields */)`?" ,
1016
- self . tcx. item_path_str ( def_id)
1112
+ self . tcx. def_path_str ( def_id)
1017
1113
) ;
1018
1114
diag. span_label ( span, message) ;
1019
1115
}
@@ -1425,7 +1521,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1425
1521
var_origin : RegionVariableOrigin ,
1426
1522
) -> DiagnosticBuilder < ' tcx > {
1427
1523
let br_string = |br : ty:: BoundRegion | {
1428
- let mut s = br. to_string ( ) ;
1524
+ let mut s = match br {
1525
+ ty:: BrNamed ( _, name) => name. to_string ( ) ,
1526
+ _ => String :: new ( ) ,
1527
+ } ;
1429
1528
if !s. is_empty ( ) {
1430
1529
s. push_str ( " " ) ;
1431
1530
}
0 commit comments