@@ -192,6 +192,10 @@ impl<'a> LoweringContext<'a> {
192
192
}
193
193
}
194
194
195
+ fn lower_opt_sp_ident ( & mut self , o_id : Option < Spanned < Ident > > ) -> Option < Spanned < Name > > {
196
+ o_id. map ( |sp_ident| respan ( sp_ident. span , self . lower_ident ( sp_ident. node ) ) )
197
+ }
198
+
195
199
fn lower_attrs ( & mut self , attrs : & Vec < Attribute > ) -> hir:: HirVec < Attribute > {
196
200
attrs. clone ( ) . into ( )
197
201
}
@@ -269,7 +273,7 @@ impl<'a> LoweringContext<'a> {
269
273
P ( hir:: Ty {
270
274
id : t. id ,
271
275
node : match t. node {
272
- Infer => hir:: TyInfer ,
276
+ Infer | ImplicitSelf => hir:: TyInfer ,
273
277
Vec ( ref ty) => hir:: TyVec ( self . lower_ty ( ty) ) ,
274
278
Ptr ( ref mt) => hir:: TyPtr ( self . lower_mt ( mt) ) ,
275
279
Rptr ( ref region, ref mt) => {
@@ -787,23 +791,24 @@ impl<'a> LoweringContext<'a> {
787
791
}
788
792
789
793
fn lower_method_sig ( & mut self , sig : & MethodSig ) -> hir:: MethodSig {
790
- // Check for `self: _` and `self: &_`
791
- if let SelfKind :: Explicit ( ref ty, _) = sig. explicit_self . node {
792
- match sig. decl . inputs . get ( 0 ) . and_then ( Arg :: to_self) . map ( |eself| eself. node ) {
793
- Some ( SelfKind :: Value ( ..) ) | Some ( SelfKind :: Region ( ..) ) => {
794
- self . id_assigner . diagnostic ( ) . span_err ( ty. span ,
795
- "the type placeholder `_` is not allowed within types on item signatures" ) ;
796
- }
797
- _ => { }
798
- }
799
- }
800
- hir:: MethodSig {
794
+ let hir_sig = hir:: MethodSig {
801
795
generics : self . lower_generics ( & sig. generics ) ,
802
796
abi : sig. abi ,
803
797
unsafety : self . lower_unsafety ( sig. unsafety ) ,
804
798
constness : self . lower_constness ( sig. constness ) ,
805
799
decl : self . lower_fn_decl ( & sig. decl ) ,
800
+ } ;
801
+ // Check for `self: _` and `self: &_`
802
+ if let Some ( SelfKind :: Explicit ( ..) ) = sig. decl . get_self ( ) . map ( |eself| eself. node ) {
803
+ match hir_sig. decl . get_self ( ) . map ( |eself| eself. node ) {
804
+ Some ( hir:: SelfKind :: Value ( ..) ) | Some ( hir:: SelfKind :: Region ( ..) ) => {
805
+ self . id_assigner . diagnostic ( ) . span_err ( sig. decl . inputs [ 0 ] . ty . span ,
806
+ "the type placeholder `_` is not allowed within types on item signatures" ) ;
807
+ }
808
+ _ => { }
809
+ }
806
810
}
811
+ hir_sig
807
812
}
808
813
809
814
fn lower_unsafety ( & mut self , u : Unsafety ) -> hir:: Unsafety {
@@ -872,10 +877,10 @@ impl<'a> LoweringContext<'a> {
872
877
} )
873
878
}
874
879
PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( self . lower_expr ( e) ) ,
875
- PatKind :: TupleStruct ( ref pth, ref pats) => {
880
+ PatKind :: TupleStruct ( ref pth, ref pats, ddpos ) => {
876
881
hir:: PatKind :: TupleStruct ( self . lower_path ( pth) ,
877
- pats. as_ref ( )
878
- . map ( |pats| pats . iter ( ) . map ( |x| self . lower_pat ( x ) ) . collect ( ) ) )
882
+ pats. iter ( ) . map ( |x| self . lower_pat ( x ) ) . collect ( ) ,
883
+ ddpos )
879
884
}
880
885
PatKind :: Path ( ref pth) => {
881
886
hir:: PatKind :: Path ( self . lower_path ( pth) )
@@ -903,8 +908,8 @@ impl<'a> LoweringContext<'a> {
903
908
. collect ( ) ;
904
909
hir:: PatKind :: Struct ( pth, fs, etc)
905
910
}
906
- PatKind :: Tup ( ref elts) => {
907
- hir:: PatKind :: Tup ( elts. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) )
911
+ PatKind :: Tuple ( ref elts, ddpos ) => {
912
+ hir:: PatKind :: Tuple ( elts. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) , ddpos )
908
913
}
909
914
PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
910
915
PatKind :: Ref ( ref inner, mutbl) => {
@@ -1122,11 +1127,10 @@ impl<'a> LoweringContext<'a> {
1122
1127
}
1123
1128
ExprKind :: While ( ref cond, ref body, opt_ident) => {
1124
1129
hir:: ExprWhile ( self . lower_expr ( cond) , self . lower_block ( body) ,
1125
- opt_ident . map ( |ident| self . lower_ident ( ident ) ) )
1130
+ self . lower_opt_sp_ident ( opt_ident ) )
1126
1131
}
1127
1132
ExprKind :: Loop ( ref body, opt_ident) => {
1128
- hir:: ExprLoop ( self . lower_block ( body) ,
1129
- opt_ident. map ( |ident| self . lower_ident ( ident) ) )
1133
+ hir:: ExprLoop ( self . lower_block ( body) , self . lower_opt_sp_ident ( opt_ident) )
1130
1134
}
1131
1135
ExprKind :: Match ( ref expr, ref arms) => {
1132
1136
hir:: ExprMatch ( self . lower_expr ( expr) ,
@@ -1243,12 +1247,8 @@ impl<'a> LoweringContext<'a> {
1243
1247
} ;
1244
1248
hir:: ExprPath ( hir_qself, self . lower_path_full ( path, rename) )
1245
1249
}
1246
- ExprKind :: Break ( opt_ident) => hir:: ExprBreak ( opt_ident. map ( |sp_ident| {
1247
- respan ( sp_ident. span , self . lower_ident ( sp_ident. node ) )
1248
- } ) ) ,
1249
- ExprKind :: Again ( opt_ident) => hir:: ExprAgain ( opt_ident. map ( |sp_ident| {
1250
- respan ( sp_ident. span , self . lower_ident ( sp_ident. node ) )
1251
- } ) ) ,
1250
+ ExprKind :: Break ( opt_ident) => hir:: ExprBreak ( self . lower_opt_sp_ident ( opt_ident) ) ,
1251
+ ExprKind :: Again ( opt_ident) => hir:: ExprAgain ( self . lower_opt_sp_ident ( opt_ident) ) ,
1252
1252
ExprKind :: Ret ( ref e) => hir:: ExprRet ( e. as_ref ( ) . map ( |x| self . lower_expr ( x) ) ) ,
1253
1253
ExprKind :: InlineAsm ( InlineAsm {
1254
1254
ref inputs,
@@ -1422,8 +1422,7 @@ impl<'a> LoweringContext<'a> {
1422
1422
1423
1423
// `[opt_ident]: loop { ... }`
1424
1424
let loop_block = self . block_expr ( match_expr) ;
1425
- let loop_expr = hir:: ExprLoop ( loop_block,
1426
- opt_ident. map ( |ident| self . lower_ident ( ident) ) ) ;
1425
+ let loop_expr = hir:: ExprLoop ( loop_block, self . lower_opt_sp_ident ( opt_ident) ) ;
1427
1426
// add attributes to the outer returned expr node
1428
1427
let attrs = e. attrs . clone ( ) ;
1429
1428
return P ( hir:: Expr { id : e. id , node : loop_expr, span : e. span , attrs : attrs } ) ;
@@ -1503,8 +1502,7 @@ impl<'a> LoweringContext<'a> {
1503
1502
1504
1503
// `[opt_ident]: loop { ... }`
1505
1504
let loop_block = self . block_expr ( match_expr) ;
1506
- let loop_expr = hir:: ExprLoop ( loop_block,
1507
- opt_ident. map ( |ident| self . lower_ident ( ident) ) ) ;
1505
+ let loop_expr = hir:: ExprLoop ( loop_block, self . lower_opt_sp_ident ( opt_ident) ) ;
1508
1506
let loop_expr =
1509
1507
P ( hir:: Expr { id : e. id , node : loop_expr, span : e. span , attrs : None } ) ;
1510
1508
@@ -1857,7 +1855,7 @@ impl<'a> LoweringContext<'a> {
1857
1855
let pt = if subpats. is_empty ( ) {
1858
1856
hir:: PatKind :: Path ( path)
1859
1857
} else {
1860
- hir:: PatKind :: TupleStruct ( path, Some ( subpats) )
1858
+ hir:: PatKind :: TupleStruct ( path, subpats, None )
1861
1859
} ;
1862
1860
let pat = self . pat ( span, pt) ;
1863
1861
self . resolver . record_resolution ( pat. id , def) ;
0 commit comments