@@ -10,7 +10,7 @@ use rustc_hir as hir;
1010use rustc_hir:: def:: DefKind ;
1111use rustc_hir:: def_id:: DefId ;
1212use rustc_hir:: intravisit:: Visitor ;
13- use rustc_hir:: { GeneratorKind , AsyncGeneratorKind , Node } ;
13+ use rustc_hir:: { AsyncGeneratorKind , GeneratorKind , Node } ;
1414use rustc_middle:: ty:: TypeckTables ;
1515use rustc_middle:: ty:: {
1616 self , AdtKind , DefIdTree , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness ,
@@ -1089,7 +1089,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10891089 }
10901090 } ;
10911091
1092- let generator_body = self . tcx
1092+ let generator_body = self
1093+ . tcx
10931094 . hir ( )
10941095 . as_local_hir_id ( generator_did)
10951096 . 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> {
11311132 } )
11321133 . map ( |cause| {
11331134 // 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 ( )
11351138 . map ( |id| self . tcx . hir ( ) . expect_expr ( id) )
11361139 . find ( |expr| {
11371140 let ty = tables. expr_ty_adjusted ( & expr) ;
@@ -1220,29 +1223,32 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12201223 err. clear_code ( ) ;
12211224 err. set_primary_message ( format ! (
12221225 "{} cannot be {} between threads safely" ,
1223- future_or_generator,
1224- trait_verb
1226+ future_or_generator, trait_verb
12251227 ) ) ;
12261228
12271229 let original_span = err. span . primary_span ( ) . unwrap ( ) ;
12281230 let mut span = MultiSpan :: from_span ( original_span) ;
12291231
12301232 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 ( ) {
12331235 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+ } )
12461252 . unwrap_or_else ( || format ! ( "{} is not {}" , future_or_generator, trait_name) ) ;
12471253
12481254 span. push_span_label ( original_span, message) ;
@@ -1269,10 +1275,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12691275 if let Some ( await_span) = from_awaited_ty {
12701276 // The type causing this obligation is one being awaited at await_span.
12711277 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 ( ) ) ;
12761279
12771280 if target_span != await_span {
12781281 push_target_span ( & mut span) ;
@@ -1307,7 +1310,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13071310
13081311 err. span_note (
13091312 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+ ) ,
13111317 ) ;
13121318 }
13131319
@@ -1662,8 +1668,9 @@ impl<'v> Visitor<'v> for AwaitsVisitor {
16621668
16631669 fn visit_expr ( & mut self , ex : & ' v hir:: Expr < ' v > ) {
16641670 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+ }
16671674 _ => ( ) ,
16681675 }
16691676 hir:: intravisit:: walk_expr ( self , ex)
0 commit comments