@@ -1132,6 +1132,18 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
1132
1132
1133
1133
fn visit_precise_capturing_arg ( & mut self , arg : & ' ast PreciseCapturingArg ) {
1134
1134
match arg {
1135
+ PreciseCapturingArg :: Lifetime ( lt) if lt. ident . name == kw:: UnderscoreLifetime => {
1136
+ // We account for `+ use<'_>` explicitly to avoid providing an invalid suggestion
1137
+ // for `+ use<'static>`.
1138
+ let outer_failures = take ( & mut self . diag_metadata . current_elision_failures ) ;
1139
+ visit:: walk_precise_capturing_arg ( self , arg) ;
1140
+ let elision_failures =
1141
+ replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
1142
+ if !elision_failures. is_empty ( ) {
1143
+ self . report_missing_lifetime_specifiers ( elision_failures, None , true ) ;
1144
+ }
1145
+ return ;
1146
+ }
1135
1147
// Lower the lifetime regularly; we'll resolve the lifetime and check
1136
1148
// it's a parameter later on in HIR lowering.
1137
1149
PreciseCapturingArg :: Lifetime ( _) => { }
@@ -1884,7 +1896,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1884
1896
}
1885
1897
}
1886
1898
self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
1887
- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
1899
+ self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None , false ) ;
1888
1900
}
1889
1901
1890
1902
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -2104,7 +2116,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2104
2116
LifetimeElisionCandidate :: Ignore ,
2105
2117
) ;
2106
2118
}
2107
- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
2119
+ self . report_missing_lifetime_specifiers (
2120
+ vec ! [ missing_lifetime] ,
2121
+ None ,
2122
+ false ,
2123
+ ) ;
2108
2124
break ;
2109
2125
}
2110
2126
LifetimeRibKind :: Generics { .. } | LifetimeRibKind :: ConstParamTy => { }
@@ -2227,7 +2243,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2227
2243
replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
2228
2244
if !elision_failures. is_empty ( ) {
2229
2245
let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
2230
- self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
2246
+ self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) , false ) ;
2231
2247
}
2232
2248
}
2233
2249
0 commit comments