@@ -14,11 +14,11 @@ use rustc_data_structures::fnv::FnvHashMap;
1414use  rustc:: middle:: const_eval; 
1515use  rustc:: middle:: def; 
1616use  rustc:: middle:: pat_util:: { pat_is_resolved_const,  pat_is_binding} ; 
17- use  rustc:: middle:: subst:: Substs ; 
1817use  rustc:: middle:: ty:: { self ,  Ty } ; 
1918use  rustc:: mir:: repr:: * ; 
2019use  rustc_front:: hir; 
2120use  syntax:: ast; 
21+ use  syntax:: codemap:: Span ; 
2222use  syntax:: ptr:: P ; 
2323
2424/// When there are multiple patterns in a single arm, each one has its 
@@ -40,15 +40,15 @@ struct PatCx<'patcx, 'cx: 'patcx, 'tcx: 'cx> {
4040} 
4141
4242impl < ' cx ,  ' tcx >  Cx < ' cx ,  ' tcx >  { 
43-     pub  fn  irrefutable_pat ( & mut  self ,  pat :  & ' tcx   hir:: Pat )  -> Pattern < ' tcx >  { 
44-         PatCx :: new ( self ,  None ) . to_pat ( pat) 
43+     pub  fn  irrefutable_pat ( & mut  self ,  pat :  & hir:: Pat )  -> Pattern < ' tcx >  { 
44+         PatCx :: new ( self ,  None ) . to_pattern ( pat) 
4545    } 
4646
4747    pub  fn  refutable_pat ( & mut  self , 
4848                         binding_map :  Option < & FnvHashMap < ast:: Name ,  ast:: NodeId > > , 
49-                          pat :  & ' tcx   hir:: Pat ) 
49+                          pat :  & hir:: Pat ) 
5050                         -> Pattern < ' tcx >  { 
51-         PatCx :: new ( self ,  binding_map) . to_pat ( pat) 
51+         PatCx :: new ( self ,  binding_map) . to_pattern ( pat) 
5252    } 
5353} 
5454
@@ -62,13 +62,12 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
6262        } 
6363    } 
6464
65-     fn  to_pat ( & mut  self ,  pat :  & ' tcx   hir:: Pat )  -> Pattern < ' tcx >  { 
65+     fn  to_pattern ( & mut  self ,  pat :  & hir:: Pat )  -> Pattern < ' tcx >  { 
6666        let  kind = match  pat. node  { 
6767            hir:: PatWild  => PatternKind :: Wild , 
6868
6969            hir:: PatLit ( ref  value)  => { 
7070                let  value = const_eval:: eval_const_expr ( self . cx . tcx ,  value) ; 
71-                 let  value = Literal :: Value  {  value :  value } ; 
7271                PatternKind :: Constant  {  value :  value } 
7372            } 
7473
@@ -88,22 +87,9 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
8887                    def:: DefConst ( def_id)  | def:: DefAssociatedConst ( def_id)  =>
8988                        match  const_eval:: lookup_const_by_id ( self . cx . tcx ,  def_id,  Some ( pat. id ) )  { 
9089                            Some ( const_expr)  => { 
91-                                 let  opt_value =
92-                                     const_eval:: eval_const_expr_partial ( 
93-                                         self . cx . tcx ,  const_expr, 
94-                                         const_eval:: EvalHint :: ExprTypeChecked , 
95-                                         None ) ; 
96-                                 let  literal = if  let  Ok ( value)  = opt_value { 
97-                                     Literal :: Value  {  value :  value } 
98-                                 }  else  { 
99-                                     let  substs = self . cx . tcx . mk_substs ( Substs :: empty ( ) ) ; 
100-                                     Literal :: Item  { 
101-                                         def_id :  def_id, 
102-                                         kind :  ItemKind :: Constant , 
103-                                         substs :  substs
104-                                     } 
105-                                 } ; 
106-                                 PatternKind :: Constant  {  value :  literal } 
90+                                 let  pat = const_eval:: const_expr_to_pat ( self . cx . tcx ,  const_expr, 
91+                                                                         pat. span ) ; 
92+                                 return  self . to_pattern ( & * pat) ; 
10793                            } 
10894                            None  => { 
10995                                self . cx . tcx . sess . span_bug ( 
@@ -120,7 +106,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
120106
121107            hir:: PatRegion ( ref  subpattern,  _)  |
122108            hir:: PatBox ( ref  subpattern)  => { 
123-                 PatternKind :: Deref  {  subpattern :  self . to_pat ( subpattern)  } 
109+                 PatternKind :: Deref  {  subpattern :  self . to_pattern ( subpattern)  } 
124110            } 
125111
126112            hir:: PatVec ( ref  prefix,  ref  slice,  ref  suffix)  => { 
@@ -131,14 +117,14 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
131117                            subpattern :  Pattern  { 
132118                                ty :  mt. ty , 
133119                                span :  pat. span , 
134-                                 kind :  Box :: new ( self . slice_or_array_pattern ( pat,  mt. ty ,  prefix, 
120+                                 kind :  Box :: new ( self . slice_or_array_pattern ( pat. span ,  mt. ty ,  prefix, 
135121                                                                           slice,  suffix) ) , 
136122                            } , 
137123                        } , 
138124
139125                    ty:: TySlice ( ..)  |
140126                    ty:: TyArray ( ..)  =>
141-                         self . slice_or_array_pattern ( pat,  ty,  prefix,  slice,  suffix) , 
127+                         self . slice_or_array_pattern ( pat. span ,  ty,  prefix,  slice,  suffix) , 
142128
143129                    ref  sty =>
144130                        self . cx . tcx . sess . span_bug ( 
@@ -153,7 +139,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
153139                               . enumerate ( ) 
154140                               . map ( |( i,  subpattern) | FieldPattern  { 
155141                                   field :  Field :: new ( i) , 
156-                                    pattern :  self . to_pat ( subpattern) , 
142+                                    pattern :  self . to_pattern ( subpattern) , 
157143                               } ) 
158144                               . collect ( ) ; 
159145
@@ -188,7 +174,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
188174                    name :  ident. node . name , 
189175                    var :  id, 
190176                    ty :  var_ty, 
191-                     subpattern :  self . to_opt_pat ( sub) , 
177+                     subpattern :  self . to_opt_pattern ( sub) , 
192178                } 
193179            } 
194180
@@ -203,7 +189,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
203189                                   . enumerate ( ) 
204190                                   . map ( |( i,  field) | FieldPattern  { 
205191                                       field :  Field :: new ( i) , 
206-                                        pattern :  self . to_pat ( field) , 
192+                                        pattern :  self . to_pattern ( field) , 
207193                                   } ) 
208194                                   . collect ( ) ; 
209195                self . variant_or_leaf ( pat,  subpatterns) 
@@ -234,7 +220,7 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
234220                              } ) ; 
235221                              FieldPattern  { 
236222                                  field :  Field :: new ( index) , 
237-                                   pattern :  self . to_pat ( & field. node . pat ) , 
223+                                   pattern :  self . to_pattern ( & field. node . pat ) , 
238224                              } 
239225                          } ) 
240226                          . collect ( ) ; 
@@ -256,49 +242,49 @@ impl<'patcx, 'cx, 'tcx> PatCx<'patcx, 'cx, 'tcx> {
256242        } 
257243    } 
258244
259-     fn  to_pats ( & mut  self ,  pats :  & ' tcx   [ P < hir:: Pat > ] )  -> Vec < Pattern < ' tcx > >  { 
260-         pats. iter ( ) . map ( |p| self . to_pat ( p) ) . collect ( ) 
245+     fn  to_patterns ( & mut  self ,  pats :  & [ P < hir:: Pat > ] )  -> Vec < Pattern < ' tcx > >  { 
246+         pats. iter ( ) . map ( |p| self . to_pattern ( p) ) . collect ( ) 
261247    } 
262248
263-     fn  to_opt_pat ( & mut  self ,  pat :  & ' tcx   Option < P < hir:: Pat > > )  -> Option < Pattern < ' tcx > >  { 
264-         pat. as_ref ( ) . map ( |p| self . to_pat ( p) ) 
249+     fn  to_opt_pattern ( & mut  self ,  pat :  & Option < P < hir:: Pat > > )  -> Option < Pattern < ' tcx > >  { 
250+         pat. as_ref ( ) . map ( |p| self . to_pattern ( p) ) 
265251    } 
266252
267253    fn  slice_or_array_pattern ( & mut  self , 
268-                               pat :   & ' tcx  hir :: Pat , 
254+                               span :   Span , 
269255                              ty :  Ty < ' tcx > , 
270-                               prefix :  & ' tcx   [ P < hir:: Pat > ] , 
271-                               slice :  & ' tcx   Option < P < hir:: Pat > > , 
272-                               suffix :  & ' tcx   [ P < hir:: Pat > ] ) 
256+                               prefix :  & [ P < hir:: Pat > ] , 
257+                               slice :  & Option < P < hir:: Pat > > , 
258+                               suffix :  & [ P < hir:: Pat > ] ) 
273259                              -> PatternKind < ' tcx >  { 
274260        match  ty. sty  { 
275261            ty:: TySlice ( ..)  => { 
276262                // matching a slice or fixed-length array 
277263                PatternKind :: Slice  { 
278-                     prefix :  self . to_pats ( prefix) , 
279-                     slice :  self . to_opt_pat ( slice) , 
280-                     suffix :  self . to_pats ( suffix) , 
264+                     prefix :  self . to_patterns ( prefix) , 
265+                     slice :  self . to_opt_pattern ( slice) , 
266+                     suffix :  self . to_patterns ( suffix) , 
281267                } 
282268            } 
283269
284270            ty:: TyArray ( _,  len)  => { 
285271                // fixed-length array 
286272                assert ! ( len >= prefix. len( )  + suffix. len( ) ) ; 
287273                PatternKind :: Array  { 
288-                     prefix :  self . to_pats ( prefix) , 
289-                     slice :  self . to_opt_pat ( slice) , 
290-                     suffix :  self . to_pats ( suffix) , 
274+                     prefix :  self . to_patterns ( prefix) , 
275+                     slice :  self . to_opt_pattern ( slice) , 
276+                     suffix :  self . to_patterns ( suffix) , 
291277                } 
292278            } 
293279
294280            _ => { 
295-                 self . cx . tcx . sess . span_bug ( pat . span ,  "unexpanded macro or bad constant etc" ) ; 
281+                 self . cx . tcx . sess . span_bug ( span,  "unexpanded macro or bad constant etc" ) ; 
296282            } 
297283        } 
298284    } 
299285
300286    fn  variant_or_leaf ( & mut  self , 
301-                        pat :  & ' tcx   hir:: Pat , 
287+                        pat :  & hir:: Pat , 
302288                       subpatterns :  Vec < FieldPattern < ' tcx > > ) 
303289                       -> PatternKind < ' tcx >  { 
304290        let  def = self . cx . tcx . def_map . borrow ( ) . get ( & pat. id ) . unwrap ( ) . full_def ( ) ; 
0 commit comments