@@ -65,6 +65,7 @@ use hir;
65
65
66
66
use std:: collections:: BTreeMap ;
67
67
use std:: collections:: HashMap ;
68
+ use std:: iter;
68
69
use syntax:: ast:: * ;
69
70
use syntax:: attr:: { ThinAttributes , ThinAttributesExt } ;
70
71
use syntax:: ext:: mtwt;
@@ -1213,9 +1214,74 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
1213
1214
ExprKind :: Index ( ref el, ref er) => {
1214
1215
hir:: ExprIndex ( lower_expr ( lctx, el) , lower_expr ( lctx, er) )
1215
1216
}
1216
- ExprKind :: Range ( ref e1, ref e2) => {
1217
- hir:: ExprRange ( e1. as_ref ( ) . map ( |x| lower_expr ( lctx, x) ) ,
1218
- e2. as_ref ( ) . map ( |x| lower_expr ( lctx, x) ) )
1217
+ ExprKind :: Range ( ref e1, ref e2, lims) => {
1218
+ fn make_struct ( lctx : & LoweringContext ,
1219
+ ast_expr : & Expr ,
1220
+ path : & [ & str ] ,
1221
+ fields : & [ ( & str , & P < Expr > ) ] ) -> P < hir:: Expr > {
1222
+ let strs = std_path ( lctx, & iter:: once ( & "ops" )
1223
+ . chain ( path)
1224
+ . map ( |s| * s)
1225
+ . collect :: < Vec < _ > > ( ) ) ;
1226
+
1227
+ let structpath = path_global ( ast_expr. span , strs) ;
1228
+
1229
+ let hir_expr = if fields. len ( ) == 0 {
1230
+ expr_path ( lctx,
1231
+ structpath,
1232
+ ast_expr. attrs . clone ( ) )
1233
+ } else {
1234
+ expr_struct ( lctx,
1235
+ ast_expr. span ,
1236
+ structpath,
1237
+ fields. into_iter ( ) . map ( |& ( s, e) | {
1238
+ field ( token:: intern ( s) ,
1239
+ lower_expr ( lctx, & * * e) ,
1240
+ ast_expr. span )
1241
+ } ) . collect ( ) ,
1242
+ None ,
1243
+ ast_expr. attrs . clone ( ) )
1244
+ } ;
1245
+
1246
+ signal_block_expr ( lctx,
1247
+ hir_vec ! [ ] ,
1248
+ hir_expr,
1249
+ ast_expr. span ,
1250
+ hir:: PushUnstableBlock ,
1251
+ None )
1252
+ }
1253
+
1254
+ return cache_ids ( lctx, e. id , |lctx| {
1255
+ use syntax:: ast:: RangeLimits :: * ;
1256
+
1257
+ match ( e1, e2, lims) {
1258
+ ( & None , & None , HalfOpen ) =>
1259
+ make_struct ( lctx, e, & [ "RangeFull" ] ,
1260
+ & [ ] ) ,
1261
+
1262
+ ( & Some ( ref e1) , & None , HalfOpen ) =>
1263
+ make_struct ( lctx, e, & [ "RangeFrom" ] ,
1264
+ & [ ( "start" , e1) ] ) ,
1265
+
1266
+ ( & None , & Some ( ref e2) , HalfOpen ) =>
1267
+ make_struct ( lctx, e, & [ "RangeTo" ] ,
1268
+ & [ ( "end" , e2) ] ) ,
1269
+
1270
+ ( & Some ( ref e1) , & Some ( ref e2) , HalfOpen ) =>
1271
+ make_struct ( lctx, e, & [ "Range" ] ,
1272
+ & [ ( "start" , e1) , ( "end" , e2) ] ) ,
1273
+
1274
+ ( & None , & Some ( ref e2) , Closed ) =>
1275
+ make_struct ( lctx, e, & [ "RangeToInclusive" ] ,
1276
+ & [ ( "end" , e2) ] ) ,
1277
+
1278
+ ( & Some ( ref e1) , & Some ( ref e2) , Closed ) =>
1279
+ make_struct ( lctx, e, & [ "RangeInclusive" , "NonEmpty" ] ,
1280
+ & [ ( "start" , e1) , ( "end" , e2) ] ) ,
1281
+
1282
+ _ => panic ! ( "impossible range in AST" ) ,
1283
+ }
1284
+ } ) ;
1219
1285
}
1220
1286
ExprKind :: Path ( ref qself, ref path) => {
1221
1287
let hir_qself = qself. as_ref ( ) . map ( |& QSelf { ref ty, position } | {
@@ -1632,6 +1698,17 @@ fn arm(pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
1632
1698
}
1633
1699
}
1634
1700
1701
+ fn field ( name : Name , expr : P < hir:: Expr > , span : Span ) -> hir:: Field {
1702
+ hir:: Field {
1703
+ name : Spanned {
1704
+ node : name,
1705
+ span : span,
1706
+ } ,
1707
+ span : span,
1708
+ expr : expr,
1709
+ }
1710
+ }
1711
+
1635
1712
fn expr_break ( lctx : & LoweringContext , span : Span ,
1636
1713
attrs : ThinAttributes ) -> P < hir:: Expr > {
1637
1714
expr ( lctx, span, hir:: ExprBreak ( None ) , attrs)
@@ -1681,6 +1758,15 @@ fn expr_tuple(lctx: &LoweringContext, sp: Span, exprs: hir::HirVec<P<hir::Expr>>
1681
1758
expr ( lctx, sp, hir:: ExprTup ( exprs) , attrs)
1682
1759
}
1683
1760
1761
+ fn expr_struct ( lctx : & LoweringContext ,
1762
+ sp : Span ,
1763
+ path : hir:: Path ,
1764
+ fields : hir:: HirVec < hir:: Field > ,
1765
+ e : Option < P < hir:: Expr > > ,
1766
+ attrs : ThinAttributes ) -> P < hir:: Expr > {
1767
+ expr ( lctx, sp, hir:: ExprStruct ( path, fields, e) , attrs)
1768
+ }
1769
+
1684
1770
fn expr ( lctx : & LoweringContext , span : Span , node : hir:: Expr_ ,
1685
1771
attrs : ThinAttributes ) -> P < hir:: Expr > {
1686
1772
P ( hir:: Expr {
0 commit comments