@@ -746,52 +746,53 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
746
746
tcx. calculate_dtor ( def_id, & mut dropck:: check_drop_impl)
747
747
}
748
748
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,
751
752
/// returns `None`.
752
753
///
753
- /// If this function returns "some" , then `typeck_tables(def_id)` will
754
+ /// If this function returns `Some` , then `typeck_tables(def_id)` will
754
755
/// succeed; if it returns `None`, then `typeck_tables(def_id)` may or
755
756
/// may not succeed. In some cases where this function returns `None`
756
757
/// (notably closures), `typeck_tables(def_id)` would wind up
757
758
/// redirecting to the owning function.
758
759
fn primary_body_of (
759
760
tcx : TyCtxt < ' _ > ,
760
761
id : hir:: HirId ,
761
- ) -> Option < ( hir:: BodyId , Option < & hir:: FnDecl > ) > {
762
+ ) -> Option < ( hir:: BodyId , Option < & hir:: FnHeader > , Option < & hir :: FnDecl > ) > {
762
763
match tcx. hir ( ) . get ( id) {
763
764
Node :: Item ( item) => {
764
765
match item. node {
765
766
hir:: ItemKind :: Const ( _, body) |
766
767
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) ) ) ,
770
771
_ =>
771
772
None ,
772
773
}
773
774
}
774
775
Node :: TraitItem ( item) => {
775
776
match item. node {
776
777
hir:: TraitItemKind :: Const ( _, Some ( body) ) =>
777
- Some ( ( body, None ) ) ,
778
+ Some ( ( body, None , None ) ) ,
778
779
hir:: TraitItemKind :: Method ( ref sig, hir:: TraitMethod :: Provided ( body) ) =>
779
- Some ( ( body, Some ( & sig. decl ) ) ) ,
780
+ Some ( ( body, Some ( & sig. header ) , Some ( & sig . decl ) ) ) ,
780
781
_ =>
781
782
None ,
782
783
}
783
784
}
784
785
Node :: ImplItem ( item) => {
785
786
match item. node {
786
787
hir:: ImplItemKind :: Const ( _, body) =>
787
- Some ( ( body, None ) ) ,
788
+ Some ( ( body, None , None ) ) ,
788
789
hir:: ImplItemKind :: Method ( ref sig, body) =>
789
- Some ( ( body, Some ( & sig. decl ) ) ) ,
790
+ Some ( ( body, Some ( & sig. header ) , Some ( & sig . decl ) ) ) ,
790
791
_ =>
791
792
None ,
792
793
}
793
794
}
794
- Node :: AnonConst ( constant) => Some ( ( constant. body , None ) ) ,
795
+ Node :: AnonConst ( constant) => Some ( ( constant. body , None , None ) ) ,
795
796
_ => None ,
796
797
}
797
798
}
@@ -824,15 +825,21 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
824
825
let span = tcx. hir ( ) . span ( id) ;
825
826
826
827
// 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
+ } ) ;
830
832
let body = tcx. hir ( ) . body ( body_id) ;
831
833
832
834
let tables = Inherited :: build ( tcx, def_id) . enter ( |inh| {
833
835
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
+ } ;
836
843
837
844
check_abi ( tcx, span, fn_sig. abi ( ) ) ;
838
845
0 commit comments