@@ -10,7 +10,7 @@ use rustc_hir as hir;
10
10
use rustc_hir:: def:: DefKind ;
11
11
use rustc_hir:: def_id:: DefId ;
12
12
use rustc_hir:: intravisit:: Visitor ;
13
- use rustc_hir:: { GeneratorKind , AsyncGeneratorKind , Node } ;
13
+ use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
14
14
use rustc_middle:: ty:: TypeckTables ;
15
15
use rustc_middle:: ty:: {
16
16
self , AdtKind , DefIdTree , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness ,
@@ -1204,7 +1204,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1204
1204
}
1205
1205
} ;
1206
1206
1207
- let generator_body = self . tcx
1207
+ let generator_body = self
1208
+ . tcx
1208
1209
. hir ( )
1209
1210
. as_local_hir_id ( generator_did)
1210
1211
. and_then ( |hir_id| self . tcx . hir ( ) . maybe_body_owned_by ( hir_id) )
@@ -1246,7 +1247,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1246
1247
} )
1247
1248
. map ( |cause| {
1248
1249
// Check to see if any awaited expressions have the target type.
1249
- let from_awaited_ty = visitor. awaits . into_iter ( )
1250
+ let from_awaited_ty = visitor
1251
+ . awaits
1252
+ . into_iter ( )
1250
1253
. map ( |id| self . tcx . hir ( ) . expect_expr ( id) )
1251
1254
. find ( |expr| {
1252
1255
let ty = tables. expr_ty_adjusted ( & expr) ;
@@ -1335,29 +1338,32 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1335
1338
err. clear_code ( ) ;
1336
1339
err. set_primary_message ( format ! (
1337
1340
"{} cannot be {} between threads safely" ,
1338
- future_or_generator,
1339
- trait_verb
1341
+ future_or_generator, trait_verb
1340
1342
) ) ;
1341
1343
1342
1344
let original_span = err. span . primary_span ( ) . unwrap ( ) ;
1343
1345
let mut span = MultiSpan :: from_span ( original_span) ;
1344
1346
1345
1347
let message = outer_generator
1346
- . and_then ( |generator_did| Some (
1347
- match self . tcx . generator_kind ( generator_did) . unwrap ( ) {
1348
+ . and_then ( |generator_did| {
1349
+ Some ( match self . tcx . generator_kind ( generator_did) . unwrap ( ) {
1348
1350
GeneratorKind :: Gen => format ! ( "generator is not {}" , trait_name) ,
1349
- GeneratorKind :: Async ( AsyncGeneratorKind :: Fn ) =>
1350
- self . tcx . parent ( generator_did)
1351
- . and_then ( |parent_did| hir. as_local_hir_id ( parent_did) )
1352
- . and_then ( |parent_hir_id| hir. opt_name ( parent_hir_id) )
1353
- . map ( |name| format ! ( "future returned by `{}` is not {}" ,
1354
- name, trait_name) ) ?,
1355
- GeneratorKind :: Async ( AsyncGeneratorKind :: Block ) =>
1356
- format ! ( "future created by async block is not {}" , trait_name) ,
1357
- GeneratorKind :: Async ( AsyncGeneratorKind :: Closure ) =>
1358
- format ! ( "future created by async closure is not {}" , trait_name) ,
1359
- }
1360
- ) )
1351
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Fn ) => self
1352
+ . tcx
1353
+ . parent ( generator_did)
1354
+ . and_then ( |parent_did| hir. as_local_hir_id ( parent_did) )
1355
+ . and_then ( |parent_hir_id| hir. opt_name ( parent_hir_id) )
1356
+ . map ( |name| {
1357
+ format ! ( "future returned by `{}` is not {}" , name, trait_name)
1358
+ } ) ?,
1359
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Block ) => {
1360
+ format ! ( "future created by async block is not {}" , trait_name)
1361
+ }
1362
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Closure ) => {
1363
+ format ! ( "future created by async closure is not {}" , trait_name)
1364
+ }
1365
+ } )
1366
+ } )
1361
1367
. unwrap_or_else ( || format ! ( "{} is not {}" , future_or_generator, trait_name) ) ;
1362
1368
1363
1369
span. push_span_label ( original_span, message) ;
@@ -1384,10 +1390,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1384
1390
if let Some ( await_span) = from_awaited_ty {
1385
1391
// The type causing this obligation is one being awaited at await_span.
1386
1392
let mut span = MultiSpan :: from_span ( await_span) ;
1387
- span. push_span_label (
1388
- await_span,
1389
- "await occurs here" . to_string ( ) ,
1390
- ) ;
1393
+ span. push_span_label ( await_span, "await occurs here" . to_string ( ) ) ;
1391
1394
1392
1395
if target_span != await_span {
1393
1396
push_target_span ( & mut span) ;
@@ -1422,7 +1425,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1422
1425
1423
1426
err. span_note (
1424
1427
span,
1425
- & format ! ( "{} as this value is used across an {}" , trait_explanation, await_or_yield) ,
1428
+ & format ! (
1429
+ "{} as this value is used across an {}" ,
1430
+ trait_explanation, await_or_yield
1431
+ ) ,
1426
1432
) ;
1427
1433
}
1428
1434
@@ -1784,8 +1790,9 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
1784
1790
1785
1791
fn visit_expr ( & mut self , ex : & ' v hir:: Expr < ' v > ) {
1786
1792
match ex. kind {
1787
- hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) =>
1788
- self . awaits . push ( id) ,
1793
+ hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) => {
1794
+ self . awaits . push ( id)
1795
+ }
1789
1796
_ => ( ) ,
1790
1797
}
1791
1798
hir:: intravisit:: walk_expr ( self , ex)
0 commit comments