@@ -746,52 +746,53 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
746746 tcx. calculate_dtor ( def_id, & mut dropck:: check_drop_impl)
747747}
748748
749- /// If this `DefId` is a "primary tables entry", returns `Some((body_id, decl))`
750- /// with information about it's body-id and fn-decl (if any). Otherwise,
749+ /// If this `DefId` is a "primary tables entry", returns
750+ /// `Some((body_id, header, decl))` with information about
751+ /// it's body-id, fn-header and fn-decl (if any). Otherwise,
751752/// returns `None`.
752753///
753- /// If this function returns "some" , then `typeck_tables(def_id)` will
754+ /// If this function returns `Some` , then `typeck_tables(def_id)` will
754755/// succeed; if it returns `None`, then `typeck_tables(def_id)` may or
755756/// may not succeed. In some cases where this function returns `None`
756757/// (notably closures), `typeck_tables(def_id)` would wind up
757758/// redirecting to the owning function.
758759fn primary_body_of (
759760 tcx : TyCtxt < ' _ > ,
760761 id : hir:: HirId ,
761- ) -> Option < ( hir:: BodyId , Option < & hir:: FnDecl > ) > {
762+ ) -> Option < ( hir:: BodyId , Option < & hir:: FnHeader > , Option < & hir :: FnDecl > ) > {
762763 match tcx. hir ( ) . get ( id) {
763764 Node :: Item ( item) => {
764765 match item. node {
765766 hir:: ItemKind :: Const ( _, body) |
766767 hir:: ItemKind :: Static ( _, _, body) =>
767- Some ( ( body, None ) ) ,
768- hir:: ItemKind :: Fn ( ref decl, .., body) =>
769- Some ( ( body, Some ( decl) ) ) ,
768+ Some ( ( body, None , None ) ) ,
769+ hir:: ItemKind :: Fn ( ref decl, ref header , .., body) =>
770+ Some ( ( body, Some ( header ) , Some ( decl) ) ) ,
770771 _ =>
771772 None ,
772773 }
773774 }
774775 Node :: TraitItem ( item) => {
775776 match item. node {
776777 hir:: TraitItemKind :: Const ( _, Some ( body) ) =>
777- Some ( ( body, None ) ) ,
778+ Some ( ( body, None , None ) ) ,
778779 hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Provided ( body) ) =>
779- Some ( ( body, Some ( & sig. decl ) ) ) ,
780+ Some ( ( body, Some ( & sig. header ) , Some ( & sig . decl ) ) ) ,
780781 _ =>
781782 None ,
782783 }
783784 }
784785 Node :: ImplItem ( item) => {
785786 match item. node {
786787 hir:: ImplItemKind :: Const ( _, body) =>
787- Some ( ( body, None ) ) ,
788+ Some ( ( body, None , None ) ) ,
788789 hir:: ImplItemKind :: Method ( ref sig, body) =>
789- Some ( ( body, Some ( & sig. decl ) ) ) ,
790+ Some ( ( body, Some ( & sig. header ) , Some ( & sig . decl ) ) ) ,
790791 _ =>
791792 None ,
792793 }
793794 }
794- Node :: AnonConst ( constant) => Some ( ( constant. body , None ) ) ,
795+ Node :: AnonConst ( constant) => Some ( ( constant. body , None , None ) ) ,
795796 _ => None ,
796797 }
797798}
@@ -824,15 +825,21 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
824825 let span = tcx. hir ( ) . span ( id) ;
825826
826827 // Figure out what primary body this item has.
827- let ( body_id, fn_decl) = primary_body_of ( tcx, id) . unwrap_or_else ( || {
828- span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
829- } ) ;
828+ let ( body_id, fn_header, fn_decl) = primary_body_of ( tcx, id)
829+ . unwrap_or_else ( || {
830+ span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
831+ } ) ;
830832 let body = tcx. hir ( ) . body ( body_id) ;
831833
832834 let tables = Inherited :: build ( tcx, def_id) . enter ( |inh| {
833835 let param_env = tcx. param_env ( def_id) ;
834- let fcx = if let Some ( decl) = fn_decl {
835- let fn_sig = tcx. fn_sig ( def_id) ;
836+ let fcx = if let ( Some ( header) , Some ( decl) ) = ( fn_header, fn_decl) {
837+ let fn_sig = if crate :: collect:: get_infer_ret_ty ( & decl. output ) . is_some ( ) {
838+ let fcx = FnCtxt :: new ( & inh, param_env, body. value . hir_id ) ;
839+ AstConv :: ty_of_fn ( & fcx, header. unsafety , header. abi , decl)
840+ } else {
841+ tcx. fn_sig ( def_id)
842+ } ;
836843
837844 check_abi ( tcx, span, fn_sig. abi ( ) ) ;
838845
0 commit comments