@@ -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 ,
@@ -1089,7 +1089,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1089
1089
}
1090
1090
} ;
1091
1091
1092
- let generator_body = self . tcx
1092
+ let generator_body = self
1093
+ . tcx
1093
1094
. hir ( )
1094
1095
. as_local_hir_id ( generator_did)
1095
1096
. and_then ( |hir_id| self . tcx . hir ( ) . maybe_body_owned_by ( hir_id) )
@@ -1131,7 +1132,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1131
1132
} )
1132
1133
. map ( |cause| {
1133
1134
// Check to see if any awaited expressions have the target type.
1134
- let from_awaited_ty = visitor. awaits . into_iter ( )
1135
+ let from_awaited_ty = visitor
1136
+ . awaits
1137
+ . into_iter ( )
1135
1138
. map ( |id| self . tcx . hir ( ) . expect_expr ( id) )
1136
1139
. find ( |expr| {
1137
1140
let ty = tables. expr_ty_adjusted ( & expr) ;
@@ -1220,29 +1223,32 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1220
1223
err. clear_code ( ) ;
1221
1224
err. set_primary_message ( format ! (
1222
1225
"{} cannot be {} between threads safely" ,
1223
- future_or_generator,
1224
- trait_verb
1226
+ future_or_generator, trait_verb
1225
1227
) ) ;
1226
1228
1227
1229
let original_span = err. span . primary_span ( ) . unwrap ( ) ;
1228
1230
let mut span = MultiSpan :: from_span ( original_span) ;
1229
1231
1230
1232
let message = outer_generator
1231
- . and_then ( |generator_did| Some (
1232
- match self . tcx . generator_kind ( generator_did) . unwrap ( ) {
1233
+ . and_then ( |generator_did| {
1234
+ Some ( match self . tcx . generator_kind ( generator_did) . unwrap ( ) {
1233
1235
GeneratorKind :: Gen => format ! ( "generator is not {}" , trait_name) ,
1234
- GeneratorKind :: Async ( AsyncGeneratorKind :: Fn ) =>
1235
- self . tcx . parent ( generator_did)
1236
- . and_then ( |parent_did| hir. as_local_hir_id ( parent_did) )
1237
- . and_then ( |parent_hir_id| hir. opt_name ( parent_hir_id) )
1238
- . map ( |name| format ! ( "future returned by `{}` is not {}" ,
1239
- name, trait_name) ) ?,
1240
- GeneratorKind :: Async ( AsyncGeneratorKind :: Block ) =>
1241
- format ! ( "future created by async block is not {}" , trait_name) ,
1242
- GeneratorKind :: Async ( AsyncGeneratorKind :: Closure ) =>
1243
- format ! ( "future created by async closure is not {}" , trait_name) ,
1244
- }
1245
- ) )
1236
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Fn ) => self
1237
+ . tcx
1238
+ . parent ( generator_did)
1239
+ . and_then ( |parent_did| hir. as_local_hir_id ( parent_did) )
1240
+ . and_then ( |parent_hir_id| hir. opt_name ( parent_hir_id) )
1241
+ . map ( |name| {
1242
+ format ! ( "future returned by `{}` is not {}" , name, trait_name)
1243
+ } ) ?,
1244
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Block ) => {
1245
+ format ! ( "future created by async block is not {}" , trait_name)
1246
+ }
1247
+ GeneratorKind :: Async ( AsyncGeneratorKind :: Closure ) => {
1248
+ format ! ( "future created by async closure is not {}" , trait_name)
1249
+ }
1250
+ } )
1251
+ } )
1246
1252
. unwrap_or_else ( || format ! ( "{} is not {}" , future_or_generator, trait_name) ) ;
1247
1253
1248
1254
span. push_span_label ( original_span, message) ;
@@ -1269,10 +1275,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1269
1275
if let Some ( await_span) = from_awaited_ty {
1270
1276
// The type causing this obligation is one being awaited at await_span.
1271
1277
let mut span = MultiSpan :: from_span ( await_span) ;
1272
- span. push_span_label (
1273
- await_span,
1274
- "await occurs here" . to_string ( ) ,
1275
- ) ;
1278
+ span. push_span_label ( await_span, "await occurs here" . to_string ( ) ) ;
1276
1279
1277
1280
if target_span != await_span {
1278
1281
push_target_span ( & mut span) ;
@@ -1307,7 +1310,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1307
1310
1308
1311
err. span_note (
1309
1312
span,
1310
- & format ! ( "{} as this value is used across an {}" , trait_explanation, await_or_yield) ,
1313
+ & format ! (
1314
+ "{} as this value is used across an {}" ,
1315
+ trait_explanation, await_or_yield
1316
+ ) ,
1311
1317
) ;
1312
1318
}
1313
1319
@@ -1662,8 +1668,9 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
1662
1668
1663
1669
fn visit_expr ( & mut self , ex : & ' v hir:: Expr < ' v > ) {
1664
1670
match ex. kind {
1665
- hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) =>
1666
- self . awaits . push ( id) ,
1671
+ hir:: ExprKind :: Yield ( _, hir:: YieldSource :: Await { expr : Some ( id) } ) => {
1672
+ self . awaits . push ( id)
1673
+ }
1667
1674
_ => ( ) ,
1668
1675
}
1669
1676
hir:: intravisit:: walk_expr ( self , ex)
0 commit comments