@@ -645,6 +645,13 @@ struct DiagMetadata<'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:: BuiltinLintDiag ,
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.
@@ -1298,6 +1308,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1298
1308
// errors at module scope should always be reported
1299
1309
in_func_body : false ,
1300
1310
lifetime_uses : Default :: default ( ) ,
1311
+ resolved_lifetime_elisions : Vec :: new ( ) ,
1301
1312
}
1302
1313
}
1303
1314
@@ -1942,18 +1953,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1942
1953
}
1943
1954
1944
1955
if should_lint {
1945
- self . r . lint_buffer . buffer_lint_with_diagnostic (
1946
- lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
1956
+ self . resolved_lifetime_elisions . push ( ResolvedNestedElisionTarget {
1947
1957
segment_id,
1948
1958
elided_lifetime_span,
1949
- "hidden lifetime parameters in types are deprecated" ,
1950
- lint:: BuiltinLintDiag :: ElidedLifetimesInPaths (
1959
+ diagnostic : lint:: BuiltinLintDiag :: ElidedLifetimesInPaths (
1951
1960
expected_lifetimes,
1952
1961
path_span,
1953
1962
!segment. has_generic_args ,
1954
1963
elided_lifetime_span,
1955
1964
) ,
1956
- ) ;
1965
+ } ) ;
1957
1966
}
1958
1967
}
1959
1968
}
@@ -1996,24 +2005,47 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1996
2005
inputs : impl Iterator < Item = ( Option < & ' ast Pat > , & ' ast Ty ) > + Clone ,
1997
2006
output_ty : & ' ast FnRetTy ,
1998
2007
) {
2008
+ let outer_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2009
+
1999
2010
// Add each argument to the rib.
2000
2011
let elision_lifetime = self . resolve_fn_params ( has_self, inputs) ;
2001
2012
debug ! ( ?elision_lifetime) ;
2013
+ let param_resolved_lifetime_elisions = take ( & mut self . resolved_lifetime_elisions ) ;
2002
2014
2003
2015
let outer_failures = take ( & mut self . diag_metadata . current_elision_failures ) ;
2016
+
2004
2017
let output_rib = if let Ok ( res) = elision_lifetime. as_ref ( ) {
2005
2018
self . r . lifetime_elision_allowed . insert ( fn_id) ;
2006
2019
LifetimeRibKind :: Elided ( * res)
2007
2020
} else {
2008
2021
LifetimeRibKind :: ElisionFailure
2009
2022
} ;
2010
2023
self . with_lifetime_rib ( output_rib, |this| visit:: walk_fn_ret_ty ( this, output_ty) ) ;
2024
+
2011
2025
let elision_failures =
2012
2026
replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
2013
2027
if !elision_failures. is_empty ( ) {
2014
2028
let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
2015
2029
self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
2016
2030
}
2031
+
2032
+ let output_resolved_lifetime_elisions =
2033
+ replace ( & mut self . resolved_lifetime_elisions , outer_resolved_lifetime_elisions) ;
2034
+
2035
+ let resolved_lifetime_elisions =
2036
+ param_resolved_lifetime_elisions. into_iter ( ) . chain ( output_resolved_lifetime_elisions) ;
2037
+
2038
+ for re in resolved_lifetime_elisions {
2039
+ let ResolvedNestedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = re;
2040
+
2041
+ self . r . lint_buffer . buffer_lint_with_diagnostic (
2042
+ lint:: builtin:: ELIDED_LIFETIMES_IN_PATHS ,
2043
+ segment_id,
2044
+ elided_lifetime_span,
2045
+ "hidden lifetime parameters in types are deprecated" ,
2046
+ diagnostic,
2047
+ ) ;
2048
+ }
2017
2049
}
2018
2050
2019
2051
/// Resolve inside function parameters and parameter types.
0 commit comments