@@ -6,15 +6,14 @@ use crate::astconv::{
66use crate :: errors:: AssocTypeBindingNotAllowed ;
77use crate :: structured_errors:: { GenericArgsInfo , StructuredDiagnostic , WrongNumberOfGenericArgs } ;
88use rustc_ast:: ast:: ParamKindOrd ;
9- use rustc_errors:: { struct_span_err, Applicability , Diagnostic , ErrorGuaranteed , MultiSpan } ;
9+ use rustc_errors:: { struct_span_err, Applicability , Diagnostic , ErrorGuaranteed } ;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: { DefKind , Res } ;
1212use rustc_hir:: def_id:: DefId ;
1313use rustc_hir:: GenericArg ;
1414use rustc_middle:: ty:: {
1515 self , subst, subst:: SubstsRef , GenericParamDef , GenericParamDefKind , IsSuggestable , Ty , TyCtxt ,
1616} ;
17- use rustc_session:: lint:: builtin:: LATE_BOUND_LIFETIME_ARGUMENTS ;
1817use rustc_span:: { symbol:: kw, Span } ;
1918use smallvec:: SmallVec ;
2019
@@ -602,7 +601,6 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
602601 args : & hir:: GenericArgs < ' _ > ,
603602 position : GenericArgPosition ,
604603) -> ExplicitLateBound {
605- let param_counts = def. own_counts ( ) ;
606604 let infer_lifetimes = position != GenericArgPosition :: Type && !args. has_lifetime_params ( ) ;
607605
608606 if infer_lifetimes {
@@ -611,27 +609,22 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
611609
612610 if let Some ( span_late) = def. has_late_bound_regions {
613611 let msg = "cannot specify lifetime arguments explicitly \
614- if late bound lifetime parameters are present";
612+ if late bound lifetime parameters are present";
615613 let note = "the late bound lifetime parameter is introduced here" ;
616- let span = args. args [ 0 ] . span ( ) ;
617-
618- if position == GenericArgPosition :: Value
619- && args. num_lifetime_params ( ) != param_counts. lifetimes
620- {
621- let mut err = tcx. sess . struct_span_err ( span, msg) ;
622- err. span_note ( span_late, note) ;
623- err. emit ( ) ;
624- } else {
625- let mut multispan = MultiSpan :: from_span ( span) ;
626- multispan. push_span_label ( span_late, note) ;
627- tcx. struct_span_lint_hir (
628- LATE_BOUND_LIFETIME_ARGUMENTS ,
629- args. args [ 0 ] . hir_id ( ) ,
630- multispan,
631- msg,
632- |lint| lint,
633- ) ;
634- }
614+ let help = format ! (
615+ "remove the explicit lifetime argument{}" ,
616+ rustc_errors:: pluralize!( args. num_lifetime_params( ) )
617+ ) ;
618+ let spans: Vec < _ > = args
619+ . args
620+ . iter ( )
621+ . filter_map ( |arg| match arg {
622+ hir:: GenericArg :: Lifetime ( l) => Some ( l. ident . span ) ,
623+ _ => None ,
624+ } )
625+ . collect ( ) ;
626+
627+ tcx. sess . struct_span_err ( spans, msg) . span_note ( span_late, note) . help ( help) . emit ( ) ;
635628
636629 ExplicitLateBound :: Yes
637630 } else {
0 commit comments