@@ -689,6 +689,13 @@ struct DiagMetadata<'ast> {
689
689
current_elision_failures : Vec < MissingLifetime > ,
690
690
}
691
691
692
+ #[ derive( Debug ) ]
693
+ struct ResolvedNestedElisionTarget {
694
+ segment_id : NodeId ,
695
+ elided_lifetime_span : Span ,
696
+ diagnostic : lint:: BuiltinLintDiag ,
697
+ }
698
+
692
699
struct LateResolutionVisitor < ' a , ' ast , ' ra , ' tcx > {
693
700
r : & ' a mut Resolver < ' ra , ' tcx > ,
694
701
@@ -729,6 +736,9 @@ struct LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
729
736
730
737
/// Count the number of places a lifetime is used.
731
738
lifetime_uses : FxHashMap < LocalDefId , LifetimeUseSet > ,
739
+
740
+ /// Track which types participated in lifetime elision
741
+ resolved_lifetime_elisions : Vec < ResolvedNestedElisionTarget > ,
732
742
}
733
743
734
744
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1433,6 +1443,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1433
1443
// errors at module scope should always be reported
1434
1444
in_func_body : false ,
1435
1445
lifetime_uses : Default :: default ( ) ,
1446
+ resolved_lifetime_elisions : Vec :: new ( ) ,
1436
1447
}
1437
1448
}
1438
1449
@@ -2116,17 +2127,16 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2116
2127
}
2117
2128
2118
2129
if should_lint {
2119
- self . r . lint_buffer . buffer_lint (
2120
- lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
2130
+ self . resolved_lifetime_elisions . push ( ResolvedNestedElisionTarget {
2121
2131
segment_id,
2122
2132
elided_lifetime_span,
2123
- lint:: BuiltinLintDiag :: ElidedLifetimesInPaths (
2133
+ diagnostic : lint:: BuiltinLintDiag :: ElidedLifetimesInPaths (
2124
2134
expected_lifetimes,
2125
2135
path_span,
2126
2136
!segment. has_generic_args ,
2127
2137
elided_lifetime_span,
2128
2138
) ,
2129
- ) ;
2139
+ } ) ;
2130
2140
}
2131
2141
}
2132
2142
}
@@ -2211,24 +2221,46 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2211
2221
inputs : impl Iterator < Item = ( Option < & ' ast Pat > , & ' ast Ty ) > + Clone ,
2212
2222
output_ty : & ' ast FnRetTy ,
2213
2223
) {
2224
+ let outer_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2225
+
2214
2226
// Add each argument to the rib.
2215
2227
let elision_lifetime = self . resolve_fn_params ( has_self, inputs) ;
2216
2228
debug ! ( ?elision_lifetime) ;
2229
+ let param_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2217
2230
2218
2231
let outer_failures = take ( & mut self . diag_metadata . current_elision_failures ) ;
2232
+
2219
2233
let output_rib = if let Ok ( res) = elision_lifetime. as_ref ( ) {
2220
2234
self . r . lifetime_elision_allowed . insert ( fn_id) ;
2221
2235
LifetimeRibKind :: Elided ( * res)
2222
2236
} else {
2223
2237
LifetimeRibKind :: ElisionFailure
2224
2238
} ;
2225
2239
self . with_lifetime_rib ( output_rib, |this| visit:: walk_fn_ret_ty ( this, output_ty) ) ;
2240
+
2226
2241
let elision_failures =
2227
2242
replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
2228
2243
if !elision_failures. is_empty ( ) {
2229
2244
let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
2230
2245
self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
2231
2246
}
2247
+
2248
+ let output_resolved_lifetime_elisions =
2249
+ replace ( & mut self . resolved_lifetime_elisions , outer_resolved_lifetime_elisions) ;
2250
+
2251
+ let resolved_lifetime_elisions =
2252
+ param_resolved_lifetime_elisions. into_iter ( ) . chain ( output_resolved_lifetime_elisions) ;
2253
+
2254
+ for re in resolved_lifetime_elisions {
2255
+ let ResolvedNestedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = re;
2256
+
2257
+ self . r . lint_buffer . buffer_lint (
2258
+ lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
2259
+ segment_id,
2260
+ elided_lifetime_span,
2261
+ diagnostic,
2262
+ ) ;
2263
+ }
2232
2264
}
2233
2265
2234
2266
/// Resolve inside function parameters and parameter types.
0 commit comments