@@ -224,7 +224,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
224
224
self . hir ( ) . span ( node) ,
225
225
) ,
226
226
_ => (
227
- format ! ( "the lifetime {} as defined on" , fr . bound_region ) ,
227
+ format ! ( "the lifetime {} as defined on" , region ) ,
228
228
cm. def_span ( self . hir ( ) . span ( node) ) ,
229
229
) ,
230
230
} ,
@@ -445,17 +445,109 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
445
445
terr : & TypeError < ' tcx > ,
446
446
sp : Span ,
447
447
) {
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
+
448
533
let report_path_match = |err : & mut DiagnosticBuilder < ' _ > , did1 : DefId , did2 : DefId | {
449
534
// Only external crates, if either is from a local
450
535
// module we could have false positives
451
536
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
+
456
542
// We compare strings because DefPath can be different
457
543
// 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 ) {
459
551
let crate_name = self . tcx . crate_name ( did1. krate ) ;
460
552
err. span_note (
461
553
sp,
@@ -650,7 +742,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
650
742
return Some ( ( ) ) ;
651
743
}
652
744
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 ( ) ) ;
654
746
if path_ == other_path {
655
747
self . highlight_outer ( & mut t1_out, & mut t2_out, path, sub, i, & other_ty) ;
656
748
return Some ( ( ) ) ;
@@ -675,7 +767,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
675
767
}
676
768
677
769
/// 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 `.
679
771
fn strip_generic_default_params (
680
772
& self ,
681
773
def_id : DefId ,
@@ -740,11 +832,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
740
832
mutbl : hir:: Mutability ,
741
833
s : & mut DiagnosticStyledString ,
742
834
) {
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
+ }
744
841
s. push_highlighted ( format ! (
745
- "&{}{}{} " ,
842
+ "&{}{}" ,
746
843
r,
747
- if r == "" { "" } else { " " } ,
748
844
if mutbl == hir:: MutMutable { "mut " } else { "" }
749
845
) ) ;
750
846
s. push_normal ( ty. to_string ( ) ) ;
@@ -755,8 +851,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
755
851
let sub_no_defaults_1 = self . strip_generic_default_params ( def1. did , sub1) ;
756
852
let sub_no_defaults_2 = self . strip_generic_default_params ( def2. did , sub2) ;
757
853
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 ( ) ) ;
760
856
if def1. did == def2. did {
761
857
// Easy case. Replace same types with `_` to shorten the output and highlight
762
858
// the differing ones.
@@ -1011,7 +1107,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1011
1107
if exp_is_struct && & exp_found. expected == ret_ty. skip_binder ( ) {
1012
1108
let message = format ! (
1013
1109
"did you mean `{}(/* fields */)`?" ,
1014
- self . tcx. item_path_str ( def_id)
1110
+ self . tcx. def_path_str ( def_id)
1015
1111
) ;
1016
1112
diag. span_label ( span, message) ;
1017
1113
}
@@ -1423,7 +1519,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1423
1519
var_origin : RegionVariableOrigin ,
1424
1520
) -> DiagnosticBuilder < ' tcx > {
1425
1521
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
+ } ;
1427
1526
if !s. is_empty ( ) {
1428
1527
s. push_str ( " " ) ;
1429
1528
}
0 commit comments