@@ -1117,6 +1117,18 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
1117
1117
1118
1118
fn visit_precise_capturing_arg ( & mut self , arg : & ' ast PreciseCapturingArg ) {
1119
1119
match arg {
1120
+ PreciseCapturingArg :: Lifetime ( lt) if lt. ident . name == kw:: UnderscoreLifetime => {
1121
+ // We account for `+ use<'_>` explicitly to avoid providing an invalid suggestion
1122
+ // for `+ use<'static>`.
1123
+ let outer_failures = take ( & mut self . diag_metadata . current_elision_failures ) ;
1124
+ visit:: walk_precise_capturing_arg ( self , arg) ;
1125
+ let elision_failures =
1126
+ replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
1127
+ if !elision_failures. is_empty ( ) {
1128
+ self . report_missing_lifetime_specifiers ( elision_failures, None , true ) ;
1129
+ }
1130
+ return ;
1131
+ }
1120
1132
// Lower the lifetime regularly; we'll resolve the lifetime and check
1121
1133
// it's a parameter later on in HIR lowering.
1122
1134
PreciseCapturingArg :: Lifetime ( _) => { }
@@ -1877,7 +1889,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
1877
1889
}
1878
1890
}
1879
1891
self . record_lifetime_res ( lifetime. id , LifetimeRes :: Error , elision_candidate) ;
1880
- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
1892
+ self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None , false ) ;
1881
1893
}
1882
1894
1883
1895
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -2097,7 +2109,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2097
2109
LifetimeElisionCandidate :: Ignore ,
2098
2110
) ;
2099
2111
}
2100
- self . report_missing_lifetime_specifiers ( vec ! [ missing_lifetime] , None ) ;
2112
+ self . report_missing_lifetime_specifiers (
2113
+ vec ! [ missing_lifetime] ,
2114
+ None ,
2115
+ false ,
2116
+ ) ;
2101
2117
break ;
2102
2118
}
2103
2119
LifetimeRibKind :: Generics { .. } | LifetimeRibKind :: ConstParamTy => { }
@@ -2220,7 +2236,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
2220
2236
replace ( & mut self . diag_metadata . current_elision_failures , outer_failures) ;
2221
2237
if !elision_failures. is_empty ( ) {
2222
2238
let Err ( failure_info) = elision_lifetime else { bug ! ( ) } ;
2223
- self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) ) ;
2239
+ self . report_missing_lifetime_specifiers ( elision_failures, Some ( failure_info) , false ) ;
2224
2240
}
2225
2241
}
2226
2242
0 commit comments