@@ -13,6 +13,7 @@ use rustc_data_structures::indexed_vec::Idx;
13
13
use hair:: cx:: Cx ;
14
14
use hair:: cx:: block;
15
15
use hair:: cx:: to_ref:: ToRef ;
16
+ use hair:: util:: UserAnnotatedTyHelpers ;
16
17
use rustc:: hir:: def:: { Def , CtorKind } ;
17
18
use rustc:: mir:: interpret:: GlobalId ;
18
19
use rustc:: ty:: { self , AdtKind , Ty } ;
@@ -475,7 +476,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
475
476
adt_def : adt,
476
477
variant_index : 0 ,
477
478
substs,
478
- user_ty : user_annotated_ty_for_adt ( cx , expr. hir_id , adt) ,
479
+ user_ty : cx . user_substs_applied_to_adt ( expr. hir_id , adt) ,
479
480
fields : field_refs ( cx, fields) ,
480
481
base : base. as_ref ( ) . map ( |base| {
481
482
FruInfo {
@@ -501,7 +502,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
501
502
adt_def : adt,
502
503
variant_index : index,
503
504
substs,
504
- user_ty : user_annotated_ty_for_adt ( cx , expr. hir_id , adt) ,
505
+ user_ty : cx . user_substs_applied_to_adt ( expr. hir_id , adt) ,
505
506
fields : field_refs ( cx, fields) ,
506
507
base : None ,
507
508
}
@@ -787,48 +788,17 @@ fn user_annotated_ty_for_def(
787
788
// user.
788
789
Def :: StructCtor ( _def_id, CtorKind :: Const ) |
789
790
Def :: VariantCtor ( _def_id, CtorKind :: Const ) =>
790
- match & cx. tables ( ) . node_id_to_type ( hir_id) . sty {
791
- ty:: Adt ( adt_def, _) => user_annotated_ty_for_adt ( cx, hir_id, adt_def) ,
792
- sty => bug ! ( "unexpected sty: {:?}" , sty) ,
793
- } ,
791
+ cx. user_substs_applied_to_ty_of_hir_id ( hir_id) ,
794
792
795
793
// `Self` is used in expression as a tuple struct constructor or an unit struct constructor
796
- Def :: SelfCtor ( _) => {
797
- let sty = & cx. tables ( ) . node_id_to_type ( hir_id) . sty ;
798
- match sty {
799
- ty:: FnDef ( ref def_id, _) => {
800
- Some ( cx. tables ( ) . user_substs ( hir_id) ?. unchecked_map ( |user_substs| {
801
- // Here, we just pair a `DefId` with the
802
- // `user_substs`, so no new types etc are introduced.
803
- cx. tcx ( ) . mk_fn_def ( * def_id, user_substs)
804
- } ) )
805
- }
806
- ty:: Adt ( ref adt_def, _) => {
807
- user_annotated_ty_for_adt ( cx, hir_id, adt_def)
808
- }
809
- _ => {
810
- bug ! ( "unexpected sty: {:?}" , sty)
811
- }
812
- }
813
- }
794
+ Def :: SelfCtor ( _) =>
795
+ cx. user_substs_applied_to_ty_of_hir_id ( hir_id) ,
796
+
814
797
_ =>
815
798
bug ! ( "user_annotated_ty_for_def: unexpected def {:?} at {:?}" , def, hir_id)
816
799
}
817
800
}
818
801
819
- fn user_annotated_ty_for_adt (
820
- cx : & mut Cx < ' a , ' gcx , ' tcx > ,
821
- hir_id : hir:: HirId ,
822
- adt_def : & ' tcx AdtDef ,
823
- ) -> Option < CanonicalTy < ' tcx > > {
824
- let user_substs = cx. tables ( ) . user_substs ( hir_id) ?;
825
- Some ( user_substs. unchecked_map ( |user_substs| {
826
- // Here, we just pair an `AdtDef` with the
827
- // `user_substs`, so no new types etc are introduced.
828
- cx. tcx ( ) . mk_adt ( adt_def, user_substs)
829
- } ) )
830
- }
831
-
832
802
fn method_callee < ' a , ' gcx , ' tcx > (
833
803
cx : & mut Cx < ' a , ' gcx , ' tcx > ,
834
804
expr : & hir:: Expr ,
@@ -943,7 +913,7 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
943
913
adt_def,
944
914
variant_index : adt_def. variant_index_with_id ( def_id) ,
945
915
substs,
946
- user_ty : user_annotated_ty_for_adt ( cx , expr. hir_id , adt_def) ,
916
+ user_ty : cx . user_substs_applied_to_adt ( expr. hir_id , adt_def) ,
947
917
fields : vec ! [ ] ,
948
918
base : None ,
949
919
}
0 commit comments