@@ -8,6 +8,7 @@ use rustc_hir::{FnRetTy, Ty};
88use rustc_macros:: { Diagnostic , Subdiagnostic } ;
99use rustc_middle:: ty:: { Region , TyCtxt } ;
1010use rustc_span:: symbol:: kw;
11+ use rustc_span:: Symbol ;
1112use rustc_span:: { symbol:: Ident , BytePos , Span } ;
1213
1314use crate :: infer:: error_reporting:: {
@@ -619,3 +620,99 @@ pub struct TraitImplDiff {
619620 pub expected : String ,
620621 pub found : String ,
621622}
623+
624+ pub struct DynTraitConstraintSuggestion {
625+ pub span : Span ,
626+ pub ident : Ident ,
627+ }
628+
629+ impl AddSubdiagnostic for DynTraitConstraintSuggestion {
630+ fn add_to_diagnostic ( self , diag : & mut rustc_errors:: Diagnostic ) {
631+ let mut multi_span: MultiSpan = vec ! [ self . span] . into ( ) ;
632+ multi_span. push_span_label ( self . span , fluent:: infer:: dtcs_has_lifetime_req_label) ;
633+ multi_span. push_span_label ( self . ident . span , fluent:: infer:: dtcs_introduces_requirement) ;
634+ diag. span_note ( multi_span, fluent:: infer:: dtcs_has_req_note) ;
635+ diag. span_suggestion_verbose (
636+ self . span . shrink_to_hi ( ) ,
637+ fluent:: infer:: dtcs_suggestion,
638+ " + '_" ,
639+ Applicability :: MaybeIncorrect ,
640+ ) ;
641+ }
642+ }
643+
644+ #[ derive( SessionDiagnostic ) ]
645+ #[ diag( infer:: but_calling_introduces, code = "E0772" ) ]
646+ pub struct ButCallingIntroduces {
647+ #[ label( infer:: label1) ]
648+ pub param_ty_span : Span ,
649+ #[ primary_span]
650+ #[ label( infer:: label2) ]
651+ pub cause_span : Span ,
652+
653+ pub has_param_name : bool ,
654+ pub param_name : String ,
655+ pub has_lifetime : bool ,
656+ pub lifetime : String ,
657+ pub assoc_item : Symbol ,
658+ pub has_impl_path : bool ,
659+ pub impl_path : String ,
660+ }
661+
662+ pub struct ReqIntroducedLocations {
663+ pub span : MultiSpan ,
664+ pub spans : Vec < Span > ,
665+ pub fn_decl_span : Span ,
666+ pub cause_span : Span ,
667+ pub add_label : bool ,
668+ }
669+
670+ impl AddSubdiagnostic for ReqIntroducedLocations {
671+ fn add_to_diagnostic ( mut self , diag : & mut rustc_errors:: Diagnostic ) {
672+ for sp in self . spans {
673+ self . span . push_span_label ( sp, fluent:: infer:: ril_introduced_here) ;
674+ }
675+
676+ if self . add_label {
677+ self . span . push_span_label ( self . fn_decl_span , fluent:: infer:: ril_introduced_by) ;
678+ }
679+ self . span . push_span_label ( self . cause_span , fluent:: infer:: ril_because_of) ;
680+ diag. span_note ( self . span , fluent:: infer:: ril_static_introduced_by) ;
681+ }
682+ }
683+
684+ pub struct MoreTargeted {
685+ pub ident : Symbol ,
686+ }
687+
688+ impl AddSubdiagnostic for MoreTargeted {
689+ fn add_to_diagnostic ( self , diag : & mut rustc_errors:: Diagnostic ) {
690+ diag. code ( rustc_errors:: error_code!( E0772 ) ) ;
691+ diag. set_primary_message ( fluent:: infer:: more_targeted) ;
692+ diag. set_arg ( "ident" , self . ident ) ;
693+ }
694+ }
695+
696+ #[ derive( SessionDiagnostic ) ]
697+ #[ diag( infer:: but_needs_to_satisfy, code = "E0759" ) ]
698+ pub struct ButNeedsToSatisfy {
699+ #[ primary_span]
700+ pub sp : Span ,
701+ #[ label( infer:: influencer) ]
702+ pub influencer_point : Span ,
703+ #[ label( infer:: used_here) ]
704+ pub spans : Vec < Span > ,
705+ #[ label( infer:: require) ]
706+ pub require_span_as_label : Option < Span > ,
707+ #[ note( infer:: require) ]
708+ pub require_span_as_note : Option < Span > ,
709+ #[ note( infer:: introduced_by_bound) ]
710+ pub bound : Option < Span > ,
711+
712+ #[ subdiagnostic]
713+ pub req_introduces_loc : Option < ReqIntroducedLocations > ,
714+
715+ pub spans_empty : bool ,
716+ pub has_lifetime : bool ,
717+ pub lifetime : String ,
718+ }
0 commit comments