@@ -518,24 +518,13 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
518
518
}
519
519
520
520
pub fn get_expr_data ( & self , expr : & hir:: Expr < ' _ > ) -> Option < Data > {
521
- let hir_node = self . tcx . hir ( ) . expect_expr ( expr. hir_id ) ;
522
- let ty = self . tables . expr_ty_adjusted_opt ( & hir_node) ;
523
- if ty. is_none ( ) || matches ! ( ty. unwrap( ) . kind, ty:: Error ( _) ) {
521
+ let ty = self . tables . expr_ty_adjusted_opt ( expr) ?;
522
+ if matches ! ( ty. kind, ty:: Error ( _) ) {
524
523
return None ;
525
524
}
526
525
match expr. kind {
527
526
hir:: ExprKind :: Field ( ref sub_ex, ident) => {
528
- let hir_node = match self . tcx . hir ( ) . find ( sub_ex. hir_id ) {
529
- Some ( Node :: Expr ( expr) ) => expr,
530
- _ => {
531
- debug ! (
532
- "Missing or weird node for sub-expression {} in {:?}" ,
533
- sub_ex. hir_id, expr
534
- ) ;
535
- return None ;
536
- }
537
- } ;
538
- match self . tables . expr_ty_adjusted ( & hir_node) . kind {
527
+ match self . tables . expr_ty_adjusted ( & sub_ex) . kind {
539
528
ty:: Adt ( def, _) if !def. is_enum ( ) => {
540
529
let variant = & def. non_enum_variant ( ) ;
541
530
filter ! ( self . span_utils, ident. span) ;
@@ -562,8 +551,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
562
551
hir:: QPath :: Resolved ( _, path) => path. segments . last ( ) . unwrap ( ) ,
563
552
hir:: QPath :: TypeRelative ( _, segment) => segment,
564
553
} ;
565
- match self . tables . expr_ty_adjusted ( & hir_node ) . kind {
566
- ty:: Adt ( def, _) if !def . is_enum ( ) => {
554
+ match ty . kind {
555
+ ty:: Adt ( def, _) => {
567
556
let sub_span = segment. ident . span ;
568
557
filter ! ( self . span_utils, sub_span) ;
569
558
let span = self . span_from_span ( sub_span) ;
@@ -574,9 +563,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
574
563
} ) )
575
564
}
576
565
_ => {
577
- // FIXME ty could legitimately be an enum, but then we will fail
578
- // later if we try to look up the fields.
579
- debug ! ( "expected struct or union, found {:?}" , ty) ;
566
+ debug ! ( "expected adt, found {:?}" , ty) ;
580
567
None
581
568
}
582
569
}
0 commit comments