@@ -44,20 +44,6 @@ use std::mem::transmute;
44
44
use std:: { i8, i16, i32, i64, u8, u16, u32, u64} ;
45
45
use std:: rc:: Rc ;
46
46
47
- fn lookup_const < ' a > ( tcx : & ' a ty:: ctxt , e : & Expr ) -> Option < & ' a Expr > {
48
- let opt_def = tcx. def_map . borrow ( ) . get ( & e. id ) . map ( |d| d. full_def ( ) ) ;
49
- match opt_def {
50
- Some ( def:: DefConst ( def_id) ) |
51
- Some ( def:: DefAssociatedConst ( def_id) ) => {
52
- lookup_const_by_id ( tcx, def_id, Some ( e. id ) , None )
53
- }
54
- Some ( def:: DefVariant ( enum_def, variant_def, _) ) => {
55
- lookup_variant_by_id ( tcx, enum_def, variant_def)
56
- }
57
- _ => None
58
- }
59
- }
60
-
61
47
fn lookup_variant_by_id < ' a > ( tcx : & ' a ty:: ctxt ,
62
48
enum_def : DefId ,
63
49
variant_def : DefId )
@@ -382,12 +368,12 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
382
368
hir:: PatStruct ( path. clone ( ) , hir:: HirVec :: new ( ) , false ) ,
383
369
Some ( def:: DefVariant ( ..) ) =>
384
370
hir:: PatEnum ( path. clone ( ) , None ) ,
385
- _ => {
386
- match lookup_const ( tcx , expr ) {
387
- Some ( actual ) => return const_expr_to_pat ( tcx, actual , span ) ,
388
- _ => unreachable ! ( )
389
- }
390
- }
371
+ Some ( def :: DefConst ( def_id ) ) |
372
+ Some ( def :: DefAssociatedConst ( def_id ) ) => {
373
+ let expr = lookup_const_by_id ( tcx, def_id , Some ( expr . id ) , None ) . unwrap ( ) ;
374
+ return const_expr_to_pat ( tcx , expr , span ) ;
375
+ } ,
376
+ _ => unreachable ! ( ) ,
391
377
}
392
378
}
393
379
0 commit comments