11use hir:: GenericParamKind ;
22use rustc_errors:: {
33 fluent, AddToDiagnostic , Applicability , Diagnostic , DiagnosticMessage , DiagnosticStyledString ,
4- MultiSpan , SubdiagnosticMessage ,
4+ IntoDiagnosticArg , MultiSpan , SubdiagnosticMessage ,
55} ;
66use rustc_hir as hir;
77use rustc_hir:: FnRetTy ;
88use 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 } ;
1011use rustc_span:: symbol:: kw;
1112use rustc_span:: Symbol ;
1213use rustc_span:: { symbol:: Ident , BytePos , Span } ;
1314
15+ use crate :: infer:: error_reporting:: nice_region_error:: placeholder_error:: Highlighted ;
1416use crate :: infer:: error_reporting:: {
1517 need_type_info:: { GeneratorKindAsDiagArg , UnderspecifiedArgKind } ,
1618 ObligationCauseAsDiagArg ,
@@ -557,91 +559,126 @@ pub enum ExplicitLifetimeRequired<'a> {
557559 } ,
558560}
559561
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+
560576#[ derive( Subdiagnostic ) ]
561- pub enum ActualImplExplNotes {
577+ pub enum ActualImplExplNotes < ' tcx > {
562578 #[ note( infer_actual_impl_expl_expected_signature_two) ]
563579 ExpectedSignatureTwo {
564580 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 > > ,
567583 lifetime_1 : usize ,
568584 lifetime_2 : usize ,
569585 } ,
570586 #[ note( infer_actual_impl_expl_expected_signature_any) ]
571587 ExpectedSignatureAny {
572588 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 > > ,
575591 lifetime_1 : usize ,
576592 } ,
577593 #[ note( infer_actual_impl_expl_expected_signature_some) ]
578594 ExpectedSignatureSome {
579595 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 > > ,
582598 lifetime_1 : usize ,
583599 } ,
584600 #[ 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+ } ,
586606 #[ note( infer_actual_impl_expl_expected_passive_two) ]
587607 ExpectedPassiveTwo {
588608 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 > > ,
591611 lifetime_1 : usize ,
592612 lifetime_2 : usize ,
593613 } ,
594614 #[ note( infer_actual_impl_expl_expected_passive_any) ]
595615 ExpectedPassiveAny {
596616 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 > > ,
599619 lifetime_1 : usize ,
600620 } ,
601621 #[ note( infer_actual_impl_expl_expected_passive_some) ]
602622 ExpectedPassiveSome {
603623 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 > > ,
606626 lifetime_1 : usize ,
607627 } ,
608628 #[ 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+ } ,
610634 #[ note( infer_actual_impl_expl_expected_other_two) ]
611635 ExpectedOtherTwo {
612636 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 > > ,
615639 lifetime_1 : usize ,
616640 lifetime_2 : usize ,
617641 } ,
618642 #[ note( infer_actual_impl_expl_expected_other_any) ]
619643 ExpectedOtherAny {
620644 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 > > ,
623647 lifetime_1 : usize ,
624648 } ,
625649 #[ note( infer_actual_impl_expl_expected_other_some) ]
626650 ExpectedOtherSome {
627651 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 > > ,
630654 lifetime_1 : usize ,
631655 } ,
632656 #[ 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+ } ,
634662 #[ 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+ } ,
636668 #[ note( infer_actual_impl_expl_but_actually_implemented_for_ty) ]
637669 ButActuallyImplementedForTy {
638- trait_path : String ,
670+ trait_path : Highlighted < ' tcx , TraitRefPrintOnlyTraitPath < ' tcx > > ,
639671 has_lifetime : bool ,
640672 lifetime : usize ,
641673 ty : String ,
642674 } ,
643675 #[ 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+ } ,
645682}
646683
647684pub enum ActualImplExpectedKind {
@@ -657,13 +694,13 @@ pub enum ActualImplExpectedLifetimeKind {
657694 Nothing ,
658695}
659696
660- impl ActualImplExplNotes {
697+ impl < ' tcx > ActualImplExplNotes < ' tcx > {
661698 pub fn new_expected (
662699 kind : ActualImplExpectedKind ,
663700 lt_kind : ActualImplExpectedLifetimeKind ,
664701 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 > > ,
667704 lifetime_1 : usize ,
668705 lifetime_2 : usize ,
669706 ) -> Self {
@@ -728,7 +765,7 @@ impl ActualImplExplNotes {
728765
729766#[ derive( Diagnostic ) ]
730767#[ diag( infer_trait_placeholder_mismatch) ]
731- pub struct TraitPlaceholderMismatch {
768+ pub struct TraitPlaceholderMismatch < ' tcx > {
732769 #[ primary_span]
733770 pub span : Span ,
734771 #[ label( label_satisfy) ]
@@ -741,7 +778,7 @@ pub struct TraitPlaceholderMismatch {
741778 pub trait_def_id : String ,
742779
743780 #[ subdiagnostic( eager) ]
744- pub actual_impl_expl_notes : Vec < ActualImplExplNotes > ,
781+ pub actual_impl_expl_notes : Vec < ActualImplExplNotes < ' tcx > > ,
745782}
746783
747784pub struct ConsiderBorrowingParamHelp {
0 commit comments