@@ -637,12 +637,25 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
637
637
name : Field :: new ( cx. tcx . field_index ( expr. id , cx. tables ) ) ,
638
638
}
639
639
}
640
- hir:: ExprKind :: Cast ( ref source, ref ty) => {
640
+ hir:: ExprKind :: Cast ( ref source, ref cast_ty) => {
641
+ // Check for a user-given type annotation on this `cast`
642
+ let user_ty = cx. tables . user_provided_tys ( ) . get ( cast_ty. hir_id )
643
+ . map ( |& t| UserTypeAnnotation :: Ty ( t) ) ;
644
+
645
+ debug ! (
646
+ "cast({:?}) has ty w/ hir_id {:?} and user provided ty {:?}" ,
647
+ expr,
648
+ cast_ty. hir_id,
649
+ user_ty,
650
+ ) ;
651
+
641
652
// Check to see if this cast is a "coercion cast", where the cast is actually done
642
653
// using a coercion (or is a no-op).
643
- if let Some ( & TyCastKind :: CoercionCast ) = cx. tables ( )
644
- . cast_kinds ( )
645
- . get ( source. hir_id ) {
654
+ let cast = if let Some ( & TyCastKind :: CoercionCast ) =
655
+ cx. tables ( )
656
+ . cast_kinds ( )
657
+ . get ( source. hir_id )
658
+ {
646
659
// Convert the lexpr to a vexpr.
647
660
ExprKind :: Use { source : source. to_ref ( ) }
648
661
} else {
@@ -679,32 +692,33 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
679
692
} else {
680
693
None
681
694
} ;
682
- let source = if let Some ( ( did, offset, ty) ) = var {
695
+
696
+ let source = if let Some ( ( did, offset, var_ty) ) = var {
683
697
let mk_const = |literal| Expr {
684
698
temp_lifetime,
685
- ty,
699
+ ty : var_ty ,
686
700
span : expr. span ,
687
701
kind : ExprKind :: Literal { literal, user_ty : None } ,
688
702
} . to_ref ( ) ;
689
703
let offset = mk_const ( ty:: Const :: from_bits (
690
704
cx. tcx ,
691
705
offset as u128 ,
692
- cx. param_env . and ( ty ) ,
706
+ cx. param_env . and ( var_ty ) ,
693
707
) ) ;
694
708
match did {
695
709
Some ( did) => {
696
710
// in case we are offsetting from a computed discriminant
697
711
// and not the beginning of discriminants (which is always `0`)
698
712
let substs = Substs :: identity_for_item ( cx. tcx ( ) , did) ;
699
- let lhs = mk_const ( ty:: Const :: unevaluated ( cx. tcx ( ) , did, substs, ty ) ) ;
713
+ let lhs = mk_const ( ty:: Const :: unevaluated ( cx. tcx ( ) , did, substs, var_ty ) ) ;
700
714
let bin = ExprKind :: Binary {
701
715
op : BinOp :: Add ,
702
716
lhs,
703
717
rhs : offset,
704
718
} ;
705
719
Expr {
706
720
temp_lifetime,
707
- ty,
721
+ ty : var_ty ,
708
722
span : expr. span ,
709
723
kind : bin,
710
724
} . to_ref ( )
@@ -715,25 +729,25 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
715
729
source. to_ref ( )
716
730
} ;
717
731
718
- let cast = ExprKind :: Cast { source } ;
732
+ ExprKind :: Cast { source }
733
+ } ;
719
734
720
- if let Some ( user_ty) = cx . tables . user_provided_tys ( ) . get ( ty . hir_id ) {
721
- // NOTE: Creating a new Expr and wrapping a Cast inside of it may be
722
- // inefficient, revisit this when performance becomes an issue.
723
- let cast_expr = Expr {
724
- temp_lifetime,
725
- ty : expr_ty,
726
- span : expr. span ,
727
- kind : cast,
728
- } ;
735
+ if let Some ( user_ty) = user_ty {
736
+ // NOTE: Creating a new Expr and wrapping a Cast inside of it may be
737
+ // inefficient, revisit this when performance becomes an issue.
738
+ let cast_expr = Expr {
739
+ temp_lifetime,
740
+ ty : expr_ty,
741
+ span : expr. span ,
742
+ kind : cast,
743
+ } ;
729
744
730
- ExprKind :: ValueTypeAscription {
731
- source : cast_expr. to_ref ( ) ,
732
- user_ty : UserTypeAnnotation :: Ty ( * user_ty) ,
733
- }
734
- } else {
735
- cast
745
+ ExprKind :: ValueTypeAscription {
746
+ source : cast_expr. to_ref ( ) ,
747
+ user_ty : user_ty,
736
748
}
749
+ } else {
750
+ cast
737
751
}
738
752
}
739
753
hir:: ExprKind :: Type ( ref source, ref ty) => {
0 commit comments