@@ -1700,57 +1700,45 @@ impl<'a> LoweringContext<'a> {
1700
1700
hir:: ExprIndex ( P ( self . lower_expr ( el) ) , P ( self . lower_expr ( er) ) )
1701
1701
}
1702
1702
ExprKind :: Range ( ref e1, ref e2, lims) => {
1703
- fn make_struct ( this : & mut LoweringContext ,
1704
- ast_expr : & Expr ,
1705
- path : & [ & str ] ,
1706
- fields : & [ ( & str , & P < Expr > ) ] ) -> hir:: Expr {
1707
- let struct_path = & iter:: once ( & "ops" ) . chain ( path) . map ( |s| * s)
1708
- . collect :: < Vec < _ > > ( ) ;
1709
- let unstable_span = this. allow_internal_unstable ( "..." , ast_expr. span ) ;
1710
-
1711
- if fields. len ( ) == 0 {
1712
- this. expr_std_path ( unstable_span, struct_path,
1713
- ast_expr. attrs . clone ( ) )
1714
- } else {
1715
- let fields = fields. into_iter ( ) . map ( |& ( s, e) | {
1716
- let expr = P ( this. lower_expr ( & e) ) ;
1717
- let unstable_span = this. allow_internal_unstable ( "..." , e. span ) ;
1718
- this. field ( Symbol :: intern ( s) , expr, unstable_span)
1719
- } ) . collect ( ) ;
1720
- let attrs = ast_expr. attrs . clone ( ) ;
1721
-
1722
- this. expr_std_struct ( unstable_span, struct_path, fields, None , attrs)
1723
- }
1724
- }
1725
-
1726
1703
use syntax:: ast:: RangeLimits :: * ;
1727
1704
1728
- return match ( e1, e2, lims) {
1729
- ( & None , & None , HalfOpen ) =>
1730
- make_struct ( self , e, & [ "RangeFull" ] , & [ ] ) ,
1731
-
1732
- ( & Some ( ref e1) , & None , HalfOpen ) =>
1733
- make_struct ( self , e, & [ "RangeFrom" ] ,
1734
- & [ ( "start" , e1) ] ) ,
1735
-
1736
- ( & None , & Some ( ref e2) , HalfOpen ) =>
1737
- make_struct ( self , e, & [ "RangeTo" ] ,
1738
- & [ ( "end" , e2) ] ) ,
1739
-
1740
- ( & Some ( ref e1) , & Some ( ref e2) , HalfOpen ) =>
1741
- make_struct ( self , e, & [ "Range" ] ,
1742
- & [ ( "start" , e1) , ( "end" , e2) ] ) ,
1743
-
1744
- ( & None , & Some ( ref e2) , Closed ) =>
1745
- make_struct ( self , e, & [ "RangeToInclusive" ] ,
1746
- & [ ( "end" , e2) ] ) ,
1747
-
1748
- ( & Some ( ref e1) , & Some ( ref e2) , Closed ) =>
1749
- make_struct ( self , e, & [ "RangeInclusive" , "NonEmpty" ] ,
1750
- & [ ( "start" , e1) , ( "end" , e2) ] ) ,
1705
+ let ( path, variant) = match ( e1, e2, lims) {
1706
+ ( & None , & None , HalfOpen ) => ( "RangeFull" , None ) ,
1707
+ ( & Some ( ..) , & None , HalfOpen ) => ( "RangeFrom" , None ) ,
1708
+ ( & None , & Some ( ..) , HalfOpen ) => ( "RangeTo" , None ) ,
1709
+ ( & Some ( ..) , & Some ( ..) , HalfOpen ) => ( "Range" , None ) ,
1710
+ ( & None , & Some ( ..) , Closed ) => ( "RangeToInclusive" , None ) ,
1711
+ ( & Some ( ..) , & Some ( ..) , Closed ) => ( "RangeInclusive" , Some ( "NonEmpty" ) ) ,
1712
+ ( _, & None , Closed ) =>
1713
+ panic ! ( self . diagnostic( ) . span_fatal(
1714
+ e. span, "inclusive range with no end" ) ) ,
1715
+ } ;
1751
1716
1752
- _ => panic ! ( self . diagnostic( )
1753
- . span_fatal( e. span, "inclusive range with no end" ) ) ,
1717
+ let fields =
1718
+ e1. iter ( ) . map ( |e| ( "start" , e) ) . chain ( e2. iter ( ) . map ( |e| ( "end" , e) ) )
1719
+ . map ( |( s, e) | {
1720
+ let expr = P ( self . lower_expr ( & e) ) ;
1721
+ let unstable_span = self . allow_internal_unstable ( "..." , e. span ) ;
1722
+ self . field ( Symbol :: intern ( s) , expr, unstable_span)
1723
+ } ) . collect :: < P < [ hir:: Field ] > > ( ) ;
1724
+
1725
+ let is_unit = fields. is_empty ( ) ;
1726
+ let unstable_span = self . allow_internal_unstable ( "..." , e. span ) ;
1727
+ let struct_path =
1728
+ iter:: once ( "ops" ) . chain ( iter:: once ( path) ) . chain ( variant)
1729
+ . collect :: < Vec < _ > > ( ) ;
1730
+ let struct_path = self . std_path ( unstable_span, & struct_path, is_unit) ;
1731
+ let struct_path = hir:: QPath :: Resolved ( None , P ( struct_path) ) ;
1732
+
1733
+ return hir:: Expr {
1734
+ id : e. id ,
1735
+ node : if is_unit {
1736
+ hir:: ExprPath ( struct_path)
1737
+ } else {
1738
+ hir:: ExprStruct ( struct_path, fields, None )
1739
+ } ,
1740
+ span : unstable_span,
1741
+ attrs : e. attrs . clone ( ) ,
1754
1742
} ;
1755
1743
}
1756
1744
ExprKind :: Path ( ref qself, ref path) => {
@@ -2334,17 +2322,6 @@ impl<'a> LoweringContext<'a> {
2334
2322
P ( self . expr ( sp, hir:: ExprTup ( exprs) , ThinVec :: new ( ) ) )
2335
2323
}
2336
2324
2337
- fn expr_std_struct ( & mut self ,
2338
- span : Span ,
2339
- components : & [ & str ] ,
2340
- fields : hir:: HirVec < hir:: Field > ,
2341
- e : Option < P < hir:: Expr > > ,
2342
- attrs : ThinVec < Attribute > ) -> hir:: Expr {
2343
- let path = self . std_path ( span, components, false ) ;
2344
- let qpath = hir:: QPath :: Resolved ( None , P ( path) ) ;
2345
- self . expr ( span, hir:: ExprStruct ( qpath, fields, e) , attrs)
2346
- }
2347
-
2348
2325
fn expr ( & mut self , span : Span , node : hir:: Expr_ , attrs : ThinVec < Attribute > ) -> hir:: Expr {
2349
2326
hir:: Expr {
2350
2327
id : self . next_id ( ) ,
0 commit comments