@@ -645,6 +645,13 @@ struct DiagnosticMetadata<'ast> {
645
645
current_elision_failures : Vec < MissingLifetime > ,
646
646
}
647
647
648
+ #[ derive( Debug ) ]
649
+ struct ResolvedNestedElisionTarget {
650
+ segment_id : NodeId ,
651
+ elided_lifetime_span : Span ,
652
+ diagnostic : lint:: BuiltinLintDiagnostics ,
653
+ }
654
+
648
655
struct LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
649
656
r : & ' b mut Resolver < ' a , ' tcx > ,
650
657
@@ -685,6 +692,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
685
692
686
693
/// Count the number of places a lifetime is used.
687
694
lifetime_uses : FxHashMap < LocalDefId , LifetimeUseSet > ,
695
+
696
+ /// Track which types participated in lifetime elision
697
+ resolved_lifetime_elisions : Vec < ResolvedNestedElisionTarget > ,
688
698
}
689
699
690
700
/// 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> {
1301
1311
// errors at module scope should always be reported
1302
1312
in_func_body : false ,
1303
1313
lifetime_uses : Default :: default ( ) ,
1314
+ resolved_lifetime_elisions : Vec :: new ( ) ,
1304
1315
}
1305
1316
}
1306
1317
@@ -1946,18 +1957,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1946
1957
}
1947
1958
1948
1959
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 {
1951
1961
segment_id,
1952
1962
elided_lifetime_span,
1953
- "hidden lifetime parameters in types are deprecated" ,
1954
- lint:: BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
1963
+ diagnostic : lint:: BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
1955
1964
expected_lifetimes,
1956
1965
path_span,
1957
1966
!segment. has_generic_args ,
1958
1967
elided_lifetime_span,
1959
1968
) ,
1960
- ) ;
1969
+ } ) ;
1961
1970
}
1962
1971
}
1963
1972
}
@@ -2000,24 +2009,47 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2000
2009
inputs : impl Iterator < Item = ( Option < & ' ast Pat > , & ' ast Ty ) > + Clone ,
2001
2010
output_ty : & ' ast FnRetTy ,
2002
2011
) {
2012
+ let outer_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2013
+
2003
2014
// Add each argument to the rib.
2004
2015
let elision_lifetime = self . resolve_fn_params ( has_self, inputs) ;
2005
2016
debug ! ( ?elision_lifetime) ;
2017
+ let param_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2006
2018
2007
2019
let outer_failures = take ( & mut self . diagnostic_metadata . current_elision_failures ) ;
2020
+
2008
2021
let output_rib = if let Ok ( res) = elision_lifetime. as_ref ( ) {
2009
2022
self . r . lifetime_elision_allowed . insert ( fn_id) ;
2010
2023
LifetimeRibKind :: Elided ( * res)
2011
2024
} else {
2012
2025
LifetimeRibKind :: ElisionFailure
2013
2026
} ;
2014
2027
self . with_lifetime_rib ( output_rib, |this| visit:: walk_fn_ret_ty ( this, output_ty) ) ;
2028
+
2015
2029
let elision_failures =
2016
2030
replace ( & mut self . diagnostic_metadata . current_elision_failures , outer_failures) ;
2017
2031
if !elision_failures. is_empty ( ) {
2018
2032
let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
2019
2033
self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
2020
2034
}
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
+ }
2021
2053
}
2022
2054
2023
2055
/// Resolve inside function parameters and parameter types.
0 commit comments