1
1
use hir:: GenericParamKind ;
2
2
use rustc_errors:: {
3
3
fluent, AddToDiagnostic , Applicability , Diagnostic , DiagnosticMessage , DiagnosticStyledString ,
4
- MultiSpan , SubdiagnosticMessage ,
4
+ IntoDiagnosticArg , MultiSpan , SubdiagnosticMessage ,
5
5
} ;
6
6
use rustc_hir as hir;
7
7
use rustc_hir:: FnRetTy ;
8
8
use rustc_macros:: { Diagnostic , Subdiagnostic } ;
9
- use rustc_middle:: ty:: { Region , Ty , TyCtxt } ;
9
+ use rustc_middle:: ty:: print:: TraitRefPrintOnlyTraitPath ;
10
+ use rustc_middle:: ty:: { Binder , FnSig , Region , Ty , TyCtxt } ;
10
11
use rustc_span:: symbol:: kw;
11
12
use rustc_span:: Symbol ;
12
13
use rustc_span:: { symbol:: Ident , BytePos , Span } ;
13
14
15
+ use crate :: infer:: error_reporting:: nice_region_error:: placeholder_error:: Highlighted ;
14
16
use crate :: infer:: error_reporting:: {
15
17
need_type_info:: { GeneratorKindAsDiagArg , UnderspecifiedArgKind } ,
16
18
ObligationCauseAsDiagArg ,
@@ -557,91 +559,126 @@ pub enum ExplicitLifetimeRequired<'a> {
557
559
} ,
558
560
}
559
561
562
+ pub enum TyOrSig < ' tcx > {
563
+ Ty ( Highlighted < ' tcx , Ty < ' tcx > > ) ,
564
+ ClosureSig ( Highlighted < ' tcx , Binder < ' tcx , FnSig < ' tcx > > > ) ,
565
+ }
566
+
567
+ impl IntoDiagnosticArg for TyOrSig < ' _ > {
568
+ fn into_diagnostic_arg ( self ) -> rustc_errors:: DiagnosticArgValue < ' static > {
569
+ match self {
570
+ TyOrSig :: Ty ( ty) => ty. into_diagnostic_arg ( ) ,
571
+ TyOrSig :: ClosureSig ( sig) => sig. into_diagnostic_arg ( ) ,
572
+ }
573
+ }
574
+ }
575
+
560
576
#[ derive( Subdiagnostic ) ]
561
- pub enum ActualImplExplNotes {
577
+ pub enum ActualImplExplNotes < ' tcx > {
562
578
#[ note( infer_actual_impl_expl_expected_signature_two) ]
563
579
ExpectedSignatureTwo {
564
580
leading_ellipsis : bool ,
565
- ty_or_sig : String ,
566
- trait_path : String ,
581
+ ty_or_sig : TyOrSig < ' tcx > ,
582
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
567
583
lifetime_1 : usize ,
568
584
lifetime_2 : usize ,
569
585
} ,
570
586
#[ note( infer_actual_impl_expl_expected_signature_any) ]
571
587
ExpectedSignatureAny {
572
588
leading_ellipsis : bool ,
573
- ty_or_sig : String ,
574
- trait_path : String ,
589
+ ty_or_sig : TyOrSig < ' tcx > ,
590
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
575
591
lifetime_1 : usize ,
576
592
} ,
577
593
#[ note( infer_actual_impl_expl_expected_signature_some) ]
578
594
ExpectedSignatureSome {
579
595
leading_ellipsis : bool ,
580
- ty_or_sig : String ,
581
- trait_path : String ,
596
+ ty_or_sig : TyOrSig < ' tcx > ,
597
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
582
598
lifetime_1 : usize ,
583
599
} ,
584
600
#[ note( infer_actual_impl_expl_expected_signature_nothing) ]
585
- ExpectedSignatureNothing { leading_ellipsis : bool , ty_or_sig : String , trait_path : String } ,
601
+ ExpectedSignatureNothing {
602
+ leading_ellipsis : bool ,
603
+ ty_or_sig : TyOrSig < ' tcx > ,
604
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
605
+ } ,
586
606
#[ note( infer_actual_impl_expl_expected_passive_two) ]
587
607
ExpectedPassiveTwo {
588
608
leading_ellipsis : bool ,
589
- ty_or_sig : String ,
590
- trait_path : String ,
609
+ ty_or_sig : TyOrSig < ' tcx > ,
610
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
591
611
lifetime_1 : usize ,
592
612
lifetime_2 : usize ,
593
613
} ,
594
614
#[ note( infer_actual_impl_expl_expected_passive_any) ]
595
615
ExpectedPassiveAny {
596
616
leading_ellipsis : bool ,
597
- ty_or_sig : String ,
598
- trait_path : String ,
617
+ ty_or_sig : TyOrSig < ' tcx > ,
618
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
599
619
lifetime_1 : usize ,
600
620
} ,
601
621
#[ note( infer_actual_impl_expl_expected_passive_some) ]
602
622
ExpectedPassiveSome {
603
623
leading_ellipsis : bool ,
604
- ty_or_sig : String ,
605
- trait_path : String ,
624
+ ty_or_sig : TyOrSig < ' tcx > ,
625
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
606
626
lifetime_1 : usize ,
607
627
} ,
608
628
#[ note( infer_actual_impl_expl_expected_passive_nothing) ]
609
- ExpectedPassiveNothing { leading_ellipsis : bool , ty_or_sig : String , trait_path : String } ,
629
+ ExpectedPassiveNothing {
630
+ leading_ellipsis : bool ,
631
+ ty_or_sig : TyOrSig < ' tcx > ,
632
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
633
+ } ,
610
634
#[ note( infer_actual_impl_expl_expected_other_two) ]
611
635
ExpectedOtherTwo {
612
636
leading_ellipsis : bool ,
613
- ty_or_sig : String ,
614
- trait_path : String ,
637
+ ty_or_sig : TyOrSig < ' tcx > ,
638
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
615
639
lifetime_1 : usize ,
616
640
lifetime_2 : usize ,
617
641
} ,
618
642
#[ note( infer_actual_impl_expl_expected_other_any) ]
619
643
ExpectedOtherAny {
620
644
leading_ellipsis : bool ,
621
- ty_or_sig : String ,
622
- trait_path : String ,
645
+ ty_or_sig : TyOrSig < ' tcx > ,
646
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
623
647
lifetime_1 : usize ,
624
648
} ,
625
649
#[ note( infer_actual_impl_expl_expected_other_some) ]
626
650
ExpectedOtherSome {
627
651
leading_ellipsis : bool ,
628
- ty_or_sig : String ,
629
- trait_path : String ,
652
+ ty_or_sig : TyOrSig < ' tcx > ,
653
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
630
654
lifetime_1 : usize ,
631
655
} ,
632
656
#[ note( infer_actual_impl_expl_expected_other_nothing) ]
633
- ExpectedOtherNothing { leading_ellipsis : bool , ty_or_sig : String , trait_path : String } ,
657
+ ExpectedOtherNothing {
658
+ leading_ellipsis : bool ,
659
+ ty_or_sig : TyOrSig < ' tcx > ,
660
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
661
+ } ,
634
662
#[ note( infer_actual_impl_expl_but_actually_implements_trait) ]
635
- ButActuallyImplementsTrait { trait_path : String , has_lifetime : bool , lifetime : usize } ,
663
+ ButActuallyImplementsTrait {
664
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
665
+ has_lifetime : bool ,
666
+ lifetime : usize ,
667
+ } ,
636
668
#[ note( infer_actual_impl_expl_but_actually_implemented_for_ty) ]
637
669
ButActuallyImplementedForTy {
638
- trait_path : String ,
670
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
639
671
has_lifetime : bool ,
640
672
lifetime : usize ,
641
673
ty : String ,
642
674
} ,
643
675
#[ note( infer_actual_impl_expl_but_actually_ty_implements) ]
644
- ButActuallyTyImplements { trait_path : String , has_lifetime : bool , lifetime : usize , ty : String } ,
676
+ ButActuallyTyImplements {
677
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
678
+ has_lifetime : bool ,
679
+ lifetime : usize ,
680
+ ty : String ,
681
+ } ,
645
682
}
646
683
647
684
pub enum ActualImplExpectedKind {
@@ -657,13 +694,13 @@ pub enum ActualImplExpectedLifetimeKind {
657
694
Nothing ,
658
695
}
659
696
660
- impl ActualImplExplNotes {
697
+ impl < ' tcx > ActualImplExplNotes < ' tcx > {
661
698
pub fn new_expected (
662
699
kind : ActualImplExpectedKind ,
663
700
lt_kind : ActualImplExpectedLifetimeKind ,
664
701
leading_ellipsis : bool ,
665
- ty_or_sig : String ,
666
- trait_path : String ,
702
+ ty_or_sig : TyOrSig < ' tcx > ,
703
+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
667
704
lifetime_1 : usize ,
668
705
lifetime_2 : usize ,
669
706
) -> Self {
@@ -728,7 +765,7 @@ impl ActualImplExplNotes {
728
765
729
766
#[ derive( Diagnostic ) ]
730
767
#[ diag( infer_trait_placeholder_mismatch) ]
731
- pub struct TraitPlaceholderMismatch {
768
+ pub struct TraitPlaceholderMismatch < ' tcx > {
732
769
#[ primary_span]
733
770
pub span : Span ,
734
771
#[ label( label_satisfy) ]
@@ -741,7 +778,7 @@ pub struct TraitPlaceholderMismatch {
741
778
pub trait_def_id : String ,
742
779
743
780
#[ subdiagnostic( eager) ]
744
- pub actual_impl_expl_notes : Vec < ActualImplExplNotes > ,
781
+ pub actual_impl_expl_notes : Vec < ActualImplExplNotes < ' tcx > > ,
745
782
}
746
783
747
784
pub struct ConsiderBorrowingParamHelp {
0 commit comments