@@ -1423,6 +1423,21 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1423
1423
//
1424
1424
// then just use the normal error. The closure isn't escaping
1425
1425
// and `move` will not help here.
1426
+ (
1427
+ Some ( name) ,
1428
+ BorrowExplanation :: UsedLater ( LaterUseKind :: ClosureCapture , var_or_use_span, _) ,
1429
+ ) => self . report_escaping_closure_capture (
1430
+ borrow_spans,
1431
+ borrow_span,
1432
+ & RegionName {
1433
+ name : self . synthesize_region_name ( ) ,
1434
+ source : RegionNameSource :: Static ,
1435
+ } ,
1436
+ ConstraintCategory :: CallArgument ( None ) ,
1437
+ var_or_use_span,
1438
+ & format ! ( "`{}`" , name) ,
1439
+ "block" ,
1440
+ ) ,
1426
1441
(
1427
1442
Some ( name) ,
1428
1443
BorrowExplanation :: MustBeValidFor {
@@ -1443,6 +1458,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1443
1458
category,
1444
1459
span,
1445
1460
& format ! ( "`{}`" , name) ,
1461
+ "function" ,
1446
1462
) ,
1447
1463
(
1448
1464
name,
@@ -1895,6 +1911,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1895
1911
Some ( err)
1896
1912
}
1897
1913
1914
+ #[ instrument( level = "debug" , skip( self ) ) ]
1898
1915
fn report_escaping_closure_capture (
1899
1916
& mut self ,
1900
1917
use_span : UseSpans < ' tcx > ,
@@ -1903,6 +1920,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1903
1920
category : ConstraintCategory < ' tcx > ,
1904
1921
constraint_span : Span ,
1905
1922
captured_var : & str ,
1923
+ scope : & str ,
1906
1924
) -> DiagnosticBuilder < ' cx , ErrorGuaranteed > {
1907
1925
let tcx = self . infcx . tcx ;
1908
1926
let args_span = use_span. args_or_use ( ) ;
@@ -1933,8 +1951,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1933
1951
None => "closure" ,
1934
1952
} ;
1935
1953
1936
- let mut err =
1937
- self . cannot_capture_in_long_lived_closure ( args_span, kind, captured_var, var_span) ;
1954
+ let mut err = self . cannot_capture_in_long_lived_closure (
1955
+ args_span,
1956
+ kind,
1957
+ captured_var,
1958
+ var_span,
1959
+ scope,
1960
+ ) ;
1938
1961
err. span_suggestion_verbose (
1939
1962
sugg_span,
1940
1963
& format ! (
@@ -1956,10 +1979,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1956
1979
if matches ! ( use_span. generator_kind( ) , Some ( GeneratorKind :: Async ( _) ) ) {
1957
1980
err. note (
1958
1981
"async blocks are not executed immediately and must either take a \
1959
- reference or ownership of outside variables they use",
1982
+ reference or ownership of outside variables they use",
1960
1983
) ;
1961
1984
} else {
1962
- let msg = format ! ( "function requires argument type to outlive `{}`" , fr_name ) ;
1985
+ let msg = format ! ( "{scope} requires argument type to outlive `{fr_name }`" ) ;
1963
1986
err. span_note ( constraint_span, & msg) ;
1964
1987
}
1965
1988
}
0 commit comments