@@ -44,20 +44,6 @@ use std::mem::transmute;
4444use std:: { i8, i16, i32, i64, u8, u16, u32, u64} ;
4545use std:: rc:: Rc ;
4646
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-
6147fn lookup_variant_by_id < ' a > ( tcx : & ' a ty:: ctxt ,
6248 enum_def : DefId ,
6349 variant_def : DefId )
@@ -382,12 +368,12 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr, span: Span) -> P<hir::Pat>
382368 hir:: PatStruct ( path. clone ( ) , hir:: HirVec :: new ( ) , false ) ,
383369 Some ( def:: DefVariant ( ..) ) =>
384370 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 ! ( ) ,
391377 }
392378 }
393379
0 commit comments