@@ -759,40 +759,40 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
759759fn primary_body_of (
760760 tcx : TyCtxt < ' _ > ,
761761 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 > ) > {
763763 match tcx. hir ( ) . get ( id) {
764764 Node :: Item ( item) => {
765765 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 ) ) ,
769769 hir:: ItemKind :: Fn ( ref decl, ref header, .., body) =>
770- Some ( ( body, Some ( header) , Some ( decl) ) ) ,
770+ Some ( ( body, None , Some ( header) , Some ( decl) ) ) ,
771771 _ =>
772772 None ,
773773 }
774774 }
775775 Node :: TraitItem ( item) => {
776776 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 ) ) ,
779779 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 ) ) ) ,
781781 _ =>
782782 None ,
783783 }
784784 }
785785 Node :: ImplItem ( item) => {
786786 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 ) ) ,
789789 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 ) ) ) ,
791791 _ =>
792792 None ,
793793 }
794794 }
795- Node :: AnonConst ( constant) => Some ( ( constant. body , None , None ) ) ,
795+ Node :: AnonConst ( constant) => Some ( ( constant. body , None , None , None ) ) ,
796796 _ => None ,
797797 }
798798}
@@ -825,7 +825,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
825825 let span = tcx. hir ( ) . span ( id) ;
826826
827827 // 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)
829829 . unwrap_or_else ( || {
830830 span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
831831 } ) ;
@@ -856,7 +856,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
856856 fcx
857857 } else {
858858 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) ) ;
860863 let expected_type = fcx. normalize_associated_types_in ( body. value . span , & expected_type) ;
861864 fcx. require_type_is_sized ( expected_type, body. value . span , traits:: ConstSized ) ;
862865
0 commit comments