@@ -265,6 +265,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
265
265
}
266
266
} )
267
267
. collect ( ) ;
268
+ // FIXME(#47184) -- user given type annot on ADTs
268
269
ExprKind :: Adt {
269
270
adt_def,
270
271
substs,
@@ -423,6 +424,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
423
424
ty:: Adt ( adt, substs) => {
424
425
match adt. adt_kind ( ) {
425
426
AdtKind :: Struct | AdtKind :: Union => {
427
+ // FIXME(#47184) -- user given type annot on ADTs
426
428
ExprKind :: Adt {
427
429
adt_def : adt,
428
430
variant_index : 0 ,
@@ -448,6 +450,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
448
450
assert ! ( base. is_none( ) ) ;
449
451
450
452
let index = adt. variant_index_with_id ( variant_id) ;
453
+ // FIXME(#47184) -- user given type annot on ADTs
451
454
ExprKind :: Adt {
452
455
adt_def : adt,
453
456
variant_index : index,
@@ -686,26 +689,78 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
686
689
}
687
690
}
688
691
689
- fn method_callee < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
690
- expr : & hir:: Expr ,
691
- custom_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > )
692
- -> Expr < ' tcx > {
692
+ fn user_annotated_ty_for_def (
693
+ cx : & mut Cx < ' a , ' gcx , ' tcx > ,
694
+ hir_id : hir:: HirId ,
695
+ def : & Def ,
696
+ ) -> Option < CanonicalTy < ' tcx > > {
697
+ let user_substs = cx. tables ( ) . user_substs ( hir_id) ?;
698
+ Some ( match def {
699
+ // A reference to something callable -- e.g., a fn, method, or
700
+ // a tuple-struct or tuple-variant. This has the type of a
701
+ // `Fn` but with the user-given substitutions.
702
+ Def :: Fn ( _) |
703
+ Def :: Method ( _) |
704
+ Def :: StructCtor ( _, CtorKind :: Fn ) |
705
+ Def :: VariantCtor ( _, CtorKind :: Fn ) =>
706
+ user_substs. unchecked_map ( |user_substs| {
707
+ // Here, we just pair a `DefId` with the
708
+ // `user_substs`, so no new types etc are introduced.
709
+ cx. tcx ( ) . mk_fn_def ( def. def_id ( ) , user_substs)
710
+ } ) ,
711
+
712
+ Def :: Const ( _def_id) |
713
+ Def :: AssociatedConst ( _def_id) =>
714
+ bug ! ( "unimplemented" ) ,
715
+
716
+ // A unit struct/variant which is used as a value (e.g.,
717
+ // `None`). This has the type of the enum/struct that defines
718
+ // this variant -- but with the substitutions given by the
719
+ // user.
720
+ Def :: StructCtor ( _def_id, CtorKind :: Const ) |
721
+ Def :: VariantCtor ( _def_id, CtorKind :: Const ) =>
722
+ match & cx. tables ( ) . node_id_to_type ( hir_id) . sty {
723
+ ty:: TyAdt ( adt_def, _) =>
724
+ user_substs. unchecked_map ( |user_substs| {
725
+ // Here, we just pair an `AdtDef` with the
726
+ // `user_substs`, so no new types etc are introduced.
727
+ cx. tcx ( ) . mk_adt ( adt_def, user_substs)
728
+ } ) ,
729
+ sty => bug ! ( "unexpected sty: {:?}" , sty) ,
730
+ } ,
731
+
732
+ _ =>
733
+ bug ! ( "user_annotated_ty_for_def: unexpected def {:?} at {:?}" , def, hir_id)
734
+ } )
735
+ }
736
+
737
+ fn method_callee < ' a , ' gcx , ' tcx > (
738
+ cx : & mut Cx < ' a , ' gcx , ' tcx > ,
739
+ expr : & hir:: Expr ,
740
+ overloaded_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > ,
741
+ ) -> Expr < ' tcx > {
693
742
let temp_lifetime = cx. region_scope_tree . temporary_scope ( expr. hir_id . local_id ) ;
694
- let ( def_id, substs) = custom_callee. unwrap_or_else ( || {
695
- if let Some ( def) = cx. tables ( ) . type_dependent_defs ( ) . get ( expr. hir_id ) {
696
- ( def. def_id ( ) , cx. tables ( ) . node_substs ( expr. hir_id ) )
697
- } else {
698
- span_bug ! ( expr. span, "no type-dependent def for method callee" )
743
+ let ( def_id, substs, user_ty) = match overloaded_callee {
744
+ Some ( ( def_id, substs) ) => ( def_id, substs, None ) ,
745
+ None => {
746
+ let type_dependent_defs = cx. tables ( ) . type_dependent_defs ( ) ;
747
+ let def = type_dependent_defs
748
+ . get ( expr. hir_id )
749
+ . unwrap_or_else ( || {
750
+ span_bug ! ( expr. span, "no type-dependent def for method callee" )
751
+ } ) ;
752
+ let user_ty = user_annotated_ty_for_def ( cx, expr. hir_id , def) ;
753
+ ( def. def_id ( ) , cx. tables ( ) . node_substs ( expr. hir_id ) , user_ty)
699
754
}
700
- } ) ;
755
+ } ;
701
756
let ty = cx. tcx ( ) . mk_fn_def ( def_id, substs) ;
702
757
Expr {
703
758
temp_lifetime,
704
759
ty,
705
760
span : expr. span ,
706
761
kind : ExprKind :: Literal {
707
762
literal : ty:: Const :: zero_sized ( cx. tcx ( ) , ty) ,
708
- user_ty : None , // TODO
763
+ user_ty,
709
764
} ,
710
765
}
711
766
}
@@ -756,12 +811,15 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
756
811
Def :: Fn ( _) |
757
812
Def :: Method ( _) |
758
813
Def :: StructCtor ( _, CtorKind :: Fn ) |
759
- Def :: VariantCtor ( _, CtorKind :: Fn ) => ExprKind :: Literal {
760
- literal : ty:: Const :: zero_sized (
761
- cx. tcx ,
762
- cx. tables ( ) . node_id_to_type ( expr. hir_id ) ,
763
- ) ,
764
- user_ty : None , // TODO
814
+ Def :: VariantCtor ( _, CtorKind :: Fn ) => {
815
+ let user_ty = user_annotated_ty_for_def ( cx, expr. hir_id , & def) ;
816
+ ExprKind :: Literal {
817
+ literal : ty:: Const :: zero_sized (
818
+ cx. tcx ,
819
+ cx. tables ( ) . node_id_to_type ( expr. hir_id ) ,
820
+ ) ,
821
+ user_ty,
822
+ }
765
823
} ,
766
824
767
825
Def :: Const ( def_id) |
@@ -772,11 +830,12 @@ fn convert_path_expr<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
772
830
substs,
773
831
cx. tables ( ) . node_id_to_type ( expr. hir_id ) ,
774
832
) ,
775
- user_ty : None , // TODO?
833
+ user_ty : None , // FIXME(#47184) -- user given type annot on constants
776
834
} ,
777
835
778
836
Def :: StructCtor ( def_id, CtorKind :: Const ) |
779
837
Def :: VariantCtor ( def_id, CtorKind :: Const ) => {
838
+ // FIXME(#47184) -- user given type annot on ADTs
780
839
match cx. tables ( ) . node_id_to_type ( expr. hir_id ) . sty {
781
840
// A unit struct/variant which is used as a value.
782
841
// We return a completely different ExprKind here to account for this special case.
@@ -963,12 +1022,13 @@ fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
963
1022
}
964
1023
}
965
1024
966
- fn overloaded_place < ' a , ' gcx , ' tcx > ( cx : & mut Cx < ' a , ' gcx , ' tcx > ,
967
- expr : & ' tcx hir:: Expr ,
968
- place_ty : Ty < ' tcx > ,
969
- custom_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > ,
970
- args : Vec < ExprRef < ' tcx > > )
971
- -> ExprKind < ' tcx > {
1025
+ fn overloaded_place < ' a , ' gcx , ' tcx > (
1026
+ cx : & mut Cx < ' a , ' gcx , ' tcx > ,
1027
+ expr : & ' tcx hir:: Expr ,
1028
+ place_ty : Ty < ' tcx > ,
1029
+ overloaded_callee : Option < ( DefId , & ' tcx Substs < ' tcx > ) > ,
1030
+ args : Vec < ExprRef < ' tcx > > ,
1031
+ ) -> ExprKind < ' tcx > {
972
1032
// For an overloaded *x or x[y] expression of type T, the method
973
1033
// call returns an &T and we must add the deref so that the types
974
1034
// line up (this is because `*x` and `x[y]` represent places):
@@ -993,7 +1053,7 @@ fn overloaded_place<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
993
1053
// construct the complete expression `foo()` for the overloaded call,
994
1054
// which will yield the &T type
995
1055
let temp_lifetime = cx. region_scope_tree . temporary_scope ( expr. hir_id . local_id ) ;
996
- let fun = method_callee ( cx, expr, custom_callee ) ;
1056
+ let fun = method_callee ( cx, expr, overloaded_callee ) ;
997
1057
let ref_expr = Expr {
998
1058
temp_lifetime,
999
1059
ty : ref_ty,
0 commit comments