@@ -6,15 +6,14 @@ use crate::astconv::{
6
6
use crate :: errors:: AssocTypeBindingNotAllowed ;
7
7
use crate :: structured_errors:: { GenericArgsInfo , StructuredDiagnostic , WrongNumberOfGenericArgs } ;
8
8
use 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 } ;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: { DefKind , Res } ;
12
12
use rustc_hir:: def_id:: DefId ;
13
13
use rustc_hir:: GenericArg ;
14
14
use rustc_middle:: ty:: {
15
15
self , subst, subst:: SubstsRef , GenericParamDef , GenericParamDefKind , IsSuggestable , Ty , TyCtxt ,
16
16
} ;
17
- use rustc_session:: lint:: builtin:: LATE_BOUND_LIFETIME_ARGUMENTS ;
18
17
use rustc_span:: { symbol:: kw, Span } ;
19
18
use smallvec:: SmallVec ;
20
19
@@ -602,7 +601,6 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
602
601
args : & hir:: GenericArgs < ' _ > ,
603
602
position : GenericArgPosition ,
604
603
) -> ExplicitLateBound {
605
- let param_counts = def. own_counts ( ) ;
606
604
let infer_lifetimes = position != GenericArgPosition :: Type && !args. has_lifetime_params ( ) ;
607
605
608
606
if infer_lifetimes {
@@ -611,27 +609,22 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
611
609
612
610
if let Some ( span_late) = def. has_late_bound_regions {
613
611
let msg = "cannot specify lifetime arguments explicitly \
614
- if late bound lifetime parameters are present";
612
+ if late bound lifetime parameters are present";
615
613
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 ( ) ;
635
628
636
629
ExplicitLateBound :: Yes
637
630
} else {
0 commit comments