@@ -1173,6 +1173,13 @@ impl<'a> LoweringContext<'a> {
1173
1173
) )
1174
1174
}
1175
1175
1176
+ fn lower_fn_body_block ( & mut self , decl : & FnDecl , body : & Block ) -> hir:: BodyId {
1177
+ self . lower_fn_body ( decl, |this| {
1178
+ let body = this. lower_block ( body, false ) ;
1179
+ this. expr_block ( body, ThinVec :: new ( ) )
1180
+ } )
1181
+ }
1182
+
1176
1183
fn lower_const_body ( & mut self , expr : & Expr ) -> hir:: BodyId {
1177
1184
self . lower_body ( |this| ( hir_vec ! [ ] , this. lower_expr ( expr) ) )
1178
1185
}
@@ -3181,10 +3188,7 @@ impl<'a> LoweringContext<'a> {
3181
3188
) -> hir:: BodyId {
3182
3189
let closure_id = match asyncness {
3183
3190
IsAsync :: Async { closure_id, .. } => closure_id,
3184
- IsAsync :: NotAsync => return self . lower_fn_body ( & decl, |this| {
3185
- let body = this. lower_block ( body, false ) ;
3186
- this. expr_block ( body, ThinVec :: new ( ) )
3187
- } ) ,
3191
+ IsAsync :: NotAsync => return self . lower_fn_body_block ( decl, body) ,
3188
3192
} ;
3189
3193
3190
3194
self . lower_body ( |this| {
@@ -3786,10 +3790,7 @@ impl<'a> LoweringContext<'a> {
3786
3790
( generics, hir:: TraitItemKind :: Method ( sig, hir:: TraitMethod :: Required ( names) ) )
3787
3791
}
3788
3792
TraitItemKind :: Method ( ref sig, Some ( ref body) ) => {
3789
- let body_id = self . lower_fn_body ( & sig. decl , |this| {
3790
- let body = this. lower_block ( body, false ) ;
3791
- this. expr_block ( body, ThinVec :: new ( ) )
3792
- } ) ;
3793
+ let body_id = self . lower_fn_body_block ( & sig. decl , body) ;
3793
3794
let ( generics, sig) = self . lower_method_sig (
3794
3795
& i. generics ,
3795
3796
sig,
@@ -4566,144 +4567,6 @@ impl<'a> LoweringContext<'a> {
4566
4567
}
4567
4568
}
4568
4569
4569
- fn expr_break ( & mut self , span : Span , attrs : ThinVec < Attribute > ) -> P < hir:: Expr > {
4570
- let expr_break = hir:: ExprKind :: Break ( self . lower_loop_destination ( None ) , None ) ;
4571
- P ( self . expr ( span, expr_break, attrs) )
4572
- }
4573
-
4574
- fn expr_call (
4575
- & mut self ,
4576
- span : Span ,
4577
- e : P < hir:: Expr > ,
4578
- args : hir:: HirVec < hir:: Expr > ,
4579
- ) -> hir:: Expr {
4580
- self . expr ( span, hir:: ExprKind :: Call ( e, args) , ThinVec :: new ( ) )
4581
- }
4582
-
4583
- // Note: associated functions must use `expr_call_std_path`.
4584
- fn expr_call_std_path (
4585
- & mut self ,
4586
- span : Span ,
4587
- path_components : & [ Symbol ] ,
4588
- args : hir:: HirVec < hir:: Expr > ,
4589
- ) -> hir:: Expr {
4590
- let path = P ( self . expr_std_path ( span, path_components, None , ThinVec :: new ( ) ) ) ;
4591
- self . expr_call ( span, path, args)
4592
- }
4593
-
4594
- // Create an expression calling an associated function of an std type.
4595
- //
4596
- // Associated functions cannot be resolved through the normal `std_path` function,
4597
- // as they are resolved differently and so cannot use `expr_call_std_path`.
4598
- //
4599
- // This function accepts the path component (`ty_path_components`) separately from
4600
- // the name of the associated function (`assoc_fn_name`) in order to facilitate
4601
- // separate resolution of the type and creation of a path referring to its associated
4602
- // function.
4603
- fn expr_call_std_assoc_fn (
4604
- & mut self ,
4605
- ty_path_id : hir:: HirId ,
4606
- span : Span ,
4607
- ty_path_components : & [ Symbol ] ,
4608
- assoc_fn_name : & str ,
4609
- args : hir:: HirVec < hir:: Expr > ,
4610
- ) -> hir:: ExprKind {
4611
- let ty_path = P ( self . std_path ( span, ty_path_components, None , false ) ) ;
4612
- let ty = P ( self . ty_path ( ty_path_id, span, hir:: QPath :: Resolved ( None , ty_path) ) ) ;
4613
- let fn_seg = P ( hir:: PathSegment :: from_ident ( Ident :: from_str ( assoc_fn_name) ) ) ;
4614
- let fn_path = hir:: QPath :: TypeRelative ( ty, fn_seg) ;
4615
- let fn_expr = P ( self . expr ( span, hir:: ExprKind :: Path ( fn_path) , ThinVec :: new ( ) ) ) ;
4616
- hir:: ExprKind :: Call ( fn_expr, args)
4617
- }
4618
-
4619
- fn expr_ident ( & mut self , span : Span , ident : Ident , binding : hir:: HirId ) -> hir:: Expr {
4620
- self . expr_ident_with_attrs ( span, ident, binding, ThinVec :: new ( ) )
4621
- }
4622
-
4623
- fn expr_ident_with_attrs (
4624
- & mut self ,
4625
- span : Span ,
4626
- ident : Ident ,
4627
- binding : hir:: HirId ,
4628
- attrs : ThinVec < Attribute > ,
4629
- ) -> hir:: Expr {
4630
- let expr_path = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
4631
- None ,
4632
- P ( hir:: Path {
4633
- span,
4634
- res : Res :: Local ( binding) ,
4635
- segments : hir_vec ! [ hir:: PathSegment :: from_ident( ident) ] ,
4636
- } ) ,
4637
- ) ) ;
4638
-
4639
- self . expr ( span, expr_path, attrs)
4640
- }
4641
-
4642
- fn expr_mut_addr_of ( & mut self , span : Span , e : P < hir:: Expr > ) -> hir:: Expr {
4643
- self . expr ( span, hir:: ExprKind :: AddrOf ( hir:: MutMutable , e) , ThinVec :: new ( ) )
4644
- }
4645
-
4646
- fn expr_std_path (
4647
- & mut self ,
4648
- span : Span ,
4649
- components : & [ Symbol ] ,
4650
- params : Option < P < hir:: GenericArgs > > ,
4651
- attrs : ThinVec < Attribute > ,
4652
- ) -> hir:: Expr {
4653
- let path = self . std_path ( span, components, params, true ) ;
4654
- self . expr (
4655
- span,
4656
- hir:: ExprKind :: Path ( hir:: QPath :: Resolved ( None , P ( path) ) ) ,
4657
- attrs,
4658
- )
4659
- }
4660
-
4661
- /// Wrap the given `expr` in a terminating scope using `hir::ExprKind::DropTemps`.
4662
- ///
4663
- /// In terms of drop order, it has the same effect as wrapping `expr` in
4664
- /// `{ let _t = $expr; _t }` but should provide better compile-time performance.
4665
- ///
4666
- /// The drop order can be important in e.g. `if expr { .. }`.
4667
- fn expr_drop_temps (
4668
- & mut self ,
4669
- span : Span ,
4670
- expr : P < hir:: Expr > ,
4671
- attrs : ThinVec < Attribute >
4672
- ) -> hir:: Expr {
4673
- self . expr ( span, hir:: ExprKind :: DropTemps ( expr) , attrs)
4674
- }
4675
-
4676
- fn expr_match (
4677
- & mut self ,
4678
- span : Span ,
4679
- arg : P < hir:: Expr > ,
4680
- arms : hir:: HirVec < hir:: Arm > ,
4681
- source : hir:: MatchSource ,
4682
- ) -> hir:: Expr {
4683
- self . expr ( span, hir:: ExprKind :: Match ( arg, arms, source) , ThinVec :: new ( ) )
4684
- }
4685
-
4686
- fn expr_block ( & mut self , b : P < hir:: Block > , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4687
- self . expr ( b. span , hir:: ExprKind :: Block ( b, None ) , attrs)
4688
- }
4689
-
4690
- fn expr_unit ( & mut self , sp : Span ) -> hir:: Expr {
4691
- self . expr_tuple ( sp, hir_vec ! [ ] )
4692
- }
4693
-
4694
- fn expr_tuple ( & mut self , sp : Span , exprs : hir:: HirVec < hir:: Expr > ) -> hir:: Expr {
4695
- self . expr ( sp, hir:: ExprKind :: Tup ( exprs) , ThinVec :: new ( ) )
4696
- }
4697
-
4698
- fn expr ( & mut self , span : Span , node : hir:: ExprKind , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4699
- hir:: Expr {
4700
- hir_id : self . next_id ( ) ,
4701
- node,
4702
- span,
4703
- attrs,
4704
- }
4705
- }
4706
-
4707
4570
fn stmt ( & mut self , span : Span , node : hir:: StmtKind ) -> hir:: Stmt {
4708
4571
hir:: Stmt { span, node, hir_id : self . next_id ( ) }
4709
4572
}
@@ -4732,11 +4595,6 @@ impl<'a> LoweringContext<'a> {
4732
4595
self . stmt ( span, hir:: StmtKind :: Local ( P ( local) ) )
4733
4596
}
4734
4597
4735
- fn expr_block_empty ( & mut self , span : Span ) -> hir:: Expr {
4736
- let blk = self . block_all ( span, hir_vec ! [ ] , None ) ;
4737
- self . expr_block ( P ( blk) , ThinVec :: new ( ) )
4738
- }
4739
-
4740
4598
fn block_expr ( & mut self , expr : P < hir:: Expr > ) -> hir:: Block {
4741
4599
self . block_all ( expr. span , hir:: HirVec :: new ( ) , Some ( expr) )
4742
4600
}
@@ -4757,29 +4615,6 @@ impl<'a> LoweringContext<'a> {
4757
4615
}
4758
4616
}
4759
4617
4760
- fn expr_unsafe ( & mut self , expr : P < hir:: Expr > ) -> hir:: Expr {
4761
- let hir_id = self . next_id ( ) ;
4762
- let span = expr. span ;
4763
- self . expr (
4764
- span,
4765
- hir:: ExprKind :: Block ( P ( hir:: Block {
4766
- stmts : hir_vec ! [ ] ,
4767
- expr : Some ( expr) ,
4768
- hir_id,
4769
- rules : hir:: UnsafeBlock ( hir:: CompilerGenerated ) ,
4770
- span,
4771
- targeted_by_break : false ,
4772
- } ) , None ) ,
4773
- ThinVec :: new ( ) ,
4774
- )
4775
- }
4776
-
4777
- /// Constructs a `true` or `false` literal expression.
4778
- fn expr_bool ( & mut self , span : Span , val : bool ) -> hir:: Expr {
4779
- let lit = Spanned { span, node : LitKind :: Bool ( val) } ;
4780
- self . expr ( span, hir:: ExprKind :: Lit ( lit) , ThinVec :: new ( ) )
4781
- }
4782
-
4783
4618
/// Constructs a `true` or `false` literal pattern.
4784
4619
fn pat_bool ( & mut self , span : Span , val : bool ) -> P < hir:: Pat > {
4785
4620
let expr = self . expr_bool ( span, val) ;
0 commit comments