@@ -759,40 +759,40 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
759
759
fn primary_body_of (
760
760
tcx : TyCtxt < ' _ > ,
761
761
id : hir:: HirId ,
762
- ) -> Option < ( hir:: BodyId , Option < & hir:: FnHeader > , Option < & hir:: FnDecl > ) > {
762
+ ) -> Option < ( hir:: BodyId , Option < & hir:: Ty > , Option < & hir :: FnHeader > , Option < & hir:: FnDecl > ) > {
763
763
match tcx. hir ( ) . get ( id) {
764
764
Node :: Item ( item) => {
765
765
match item. node {
766
- hir:: ItemKind :: Const ( _ , body) |
767
- hir:: ItemKind :: Static ( _ , _, body) =>
768
- Some ( ( body, None , None ) ) ,
766
+ hir:: ItemKind :: Const ( ref ty , body) |
767
+ hir:: ItemKind :: Static ( ref ty , _, body) =>
768
+ Some ( ( body, Some ( ty ) , None , None ) ) ,
769
769
hir:: ItemKind :: Fn ( ref decl, ref header, .., body) =>
770
- Some ( ( body, Some ( header) , Some ( decl) ) ) ,
770
+ Some ( ( body, None , Some ( header) , Some ( decl) ) ) ,
771
771
_ =>
772
772
None ,
773
773
}
774
774
}
775
775
Node :: TraitItem ( item) => {
776
776
match item. node {
777
- hir:: TraitItemKind :: Const ( _ , Some ( body) ) =>
778
- Some ( ( body, None , None ) ) ,
777
+ hir:: TraitItemKind :: Const ( ref ty , Some ( body) ) =>
778
+ Some ( ( body, Some ( ty ) , None , None ) ) ,
779
779
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Provided ( body) ) =>
780
- Some ( ( body, Some ( & sig. header ) , Some ( & sig. decl ) ) ) ,
780
+ Some ( ( body, None , Some ( & sig. header ) , Some ( & sig. decl ) ) ) ,
781
781
_ =>
782
782
None ,
783
783
}
784
784
}
785
785
Node :: ImplItem ( item) => {
786
786
match item. node {
787
- hir:: ImplItemKind :: Const ( _ , body) =>
788
- Some ( ( body, None , None ) ) ,
787
+ hir:: ImplItemKind :: Const ( ref ty , body) =>
788
+ Some ( ( body, Some ( ty ) , None , None ) ) ,
789
789
hir:: ImplItemKind :: Method ( ref sig, body) =>
790
- Some ( ( body, Some ( & sig. header ) , Some ( & sig. decl ) ) ) ,
790
+ Some ( ( body, None , Some ( & sig. header ) , Some ( & sig. decl ) ) ) ,
791
791
_ =>
792
792
None ,
793
793
}
794
794
}
795
- Node :: AnonConst ( constant) => Some ( ( constant. body , None , None ) ) ,
795
+ Node :: AnonConst ( constant) => Some ( ( constant. body , None , None , None ) ) ,
796
796
_ => None ,
797
797
}
798
798
}
@@ -825,7 +825,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
825
825
let span = tcx. hir ( ) . span ( id) ;
826
826
827
827
// Figure out what primary body this item has.
828
- let ( body_id, fn_header, fn_decl) = primary_body_of ( tcx, id)
828
+ let ( body_id, body_ty , fn_header, fn_decl) = primary_body_of ( tcx, id)
829
829
. unwrap_or_else ( || {
830
830
span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
831
831
} ) ;
@@ -856,7 +856,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
856
856
fcx
857
857
} else {
858
858
let fcx = FnCtxt :: new ( & inh, param_env, body. value . hir_id ) ;
859
- let expected_type = tcx. type_of ( def_id) ;
859
+ let expected_type = body_ty. and_then ( |ty| match ty. node {
860
+ hir:: TyKind :: Infer => Some ( AstConv :: ast_ty_to_ty ( & fcx, ty) ) ,
861
+ _ => None
862
+ } ) . unwrap_or_else ( || tcx. type_of ( def_id) ) ;
860
863
let expected_type = fcx. normalize_associated_types_in ( body. value . span , & expected_type) ;
861
864
fcx. require_type_is_sized ( expected_type, body. value . span , traits:: ConstSized ) ;
862
865
0 commit comments