@@ -645,6 +645,13 @@ struct DiagnosticMetadata<'ast> {
645645 current_elision_failures : Vec < MissingLifetime > ,
646646}
647647
648+ #[ derive( Debug ) ]
649+ struct ResolvedNestedElisionTarget {
650+ segment_id : NodeId ,
651+ elided_lifetime_span : Span ,
652+ diagnostic : lint:: BuiltinLintDiagnostics ,
653+ }
654+
648655struct LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
649656 r : & ' b mut Resolver < ' a , ' tcx > ,
650657
@@ -685,6 +692,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
685692
686693 /// Count the number of places a lifetime is used.
687694 lifetime_uses : FxHashMap < LocalDefId , LifetimeUseSet > ,
695+
696+ /// Track which types participated in lifetime elision
697+ resolved_lifetime_elisions : Vec < ResolvedNestedElisionTarget > ,
688698}
689699
690700/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1301,6 +1311,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13011311 // errors at module scope should always be reported
13021312 in_func_body : false ,
13031313 lifetime_uses : Default :: default ( ) ,
1314+ resolved_lifetime_elisions : Vec :: new ( ) ,
13041315 }
13051316 }
13061317
@@ -1946,18 +1957,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19461957 }
19471958
19481959 if should_lint {
1949- self . r . lint_buffer . buffer_lint_with_diagnostic (
1950- lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
1960+ self . resolved_lifetime_elisions . push ( ResolvedNestedElisionTarget {
19511961 segment_id,
19521962 elided_lifetime_span,
1953- "hidden lifetime parameters in types are deprecated" ,
1954- lint:: BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
1963+ diagnostic : lint:: BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
19551964 expected_lifetimes,
19561965 path_span,
19571966 !segment. has_generic_args ,
19581967 elided_lifetime_span,
19591968 ) ,
1960- ) ;
1969+ } ) ;
19611970 }
19621971 }
19631972 }
@@ -2000,24 +2009,47 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20002009 inputs : impl Iterator < Item = ( Option < & ' ast Pat > , & ' ast Ty ) > + Clone ,
20012010 output_ty : & ' ast FnRetTy ,
20022011 ) {
2012+ let outer_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2013+
20032014 // Add each argument to the rib.
20042015 let elision_lifetime = self . resolve_fn_params ( has_self, inputs) ;
20052016 debug ! ( ?elision_lifetime) ;
2017+ let param_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
20062018
20072019 let outer_failures = take ( & mut self . diagnostic_metadata . current_elision_failures ) ;
2020+
20082021 let output_rib = if let Ok ( res) = elision_lifetime. as_ref ( ) {
20092022 self . r . lifetime_elision_allowed . insert ( fn_id) ;
20102023 LifetimeRibKind :: Elided ( * res)
20112024 } else {
20122025 LifetimeRibKind :: ElisionFailure
20132026 } ;
20142027 self . with_lifetime_rib ( output_rib, |this| visit:: walk_fn_ret_ty ( this, output_ty) ) ;
2028+
20152029 let elision_failures =
20162030 replace ( & mut self . diagnostic_metadata . current_elision_failures , outer_failures) ;
20172031 if !elision_failures. is_empty ( ) {
20182032 let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
20192033 self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
20202034 }
2035+
2036+ let output_resolved_lifetime_elisions =
2037+ replace ( & mut self . resolved_lifetime_elisions , outer_resolved_lifetime_elisions) ;
2038+
2039+ let resolved_lifetime_elisions =
2040+ param_resolved_lifetime_elisions. into_iter ( ) . chain ( output_resolved_lifetime_elisions) ;
2041+
2042+ for re in resolved_lifetime_elisions {
2043+ let ResolvedNestedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = re;
2044+
2045+ self . r . lint_buffer . buffer_lint_with_diagnostic (
2046+ lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
2047+ segment_id,
2048+ elided_lifetime_span,
2049+ "hidden lifetime parameters in types are deprecated" ,
2050+ diagnostic,
2051+ ) ;
2052+ }
20212053 }
20222054
20232055 /// Resolve inside function parameters and parameter types.
0 commit comments