@@ -83,20 +83,6 @@ macro_rules! type_error_struct {
8383 } )
8484}
8585
86- /// If this `DefId` is a "primary tables entry", returns
87- /// `Some((body_id, body_ty, fn_sig))`. Otherwise, returns `None`.
88- ///
89- /// If this function returns `Some`, then `typeck_results(def_id)` will
90- /// succeed; if it returns `None`, then `typeck_results(def_id)` may or
91- /// may not succeed. In some cases where this function returns `None`
92- /// (notably closures), `typeck_results(def_id)` would wind up
93- /// redirecting to the owning function.
94- fn primary_body_of (
95- node : Node < ' _ > ,
96- ) -> Option < ( hir:: BodyId , Option < & hir:: Ty < ' _ > > , Option < & hir:: FnSig < ' _ > > ) > {
97- Some ( ( node. body_id ( ) ?, node. ty ( ) , node. fn_sig ( ) ) )
98- }
99-
10086fn has_typeck_results ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
10187 // Closures' typeck results come from their outermost function,
10288 // as they are part of the same "inference environment".
@@ -163,7 +149,7 @@ fn typeck_with_fallback<'tcx>(
163149 let span = tcx. hir ( ) . span ( id) ;
164150
165151 // Figure out what primary body this item has.
166- let ( body_id, body_ty , fn_sig ) = primary_body_of ( node) . unwrap_or_else ( || {
152+ let body_id = node. body_id ( ) . unwrap_or_else ( || {
167153 span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
168154 } ) ;
169155 let body = tcx. hir ( ) . body ( body_id) ;
@@ -176,7 +162,7 @@ fn typeck_with_fallback<'tcx>(
176162 }
177163 let mut fcx = FnCtxt :: new ( & inh, param_env, def_id) ;
178164
179- if let Some ( hir:: FnSig { header, decl, .. } ) = fn_sig {
165+ if let Some ( hir:: FnSig { header, decl, .. } ) = node . fn_sig ( ) {
180166 let fn_sig = if decl. output . get_infer_ret_ty ( ) . is_some ( ) {
181167 fcx. lowerer ( ) . lower_fn_ty ( id, header. unsafety , header. abi , decl, None , None )
182168 } else {
@@ -191,7 +177,7 @@ fn typeck_with_fallback<'tcx>(
191177
192178 check_fn ( & mut fcx, fn_sig, None , decl, def_id, body, tcx. features ( ) . unsized_fn_params ) ;
193179 } else {
194- let expected_type = infer_type_if_missing ( body_ty , & fcx, node) ;
180+ let expected_type = infer_type_if_missing ( & fcx, node) ;
195181 let expected_type = expected_type. unwrap_or_else ( fallback) ;
196182
197183 let expected_type = fcx. normalize ( body. value . span , expected_type) ;
@@ -261,14 +247,10 @@ fn typeck_with_fallback<'tcx>(
261247 typeck_results
262248}
263249
264- fn infer_type_if_missing < ' tcx > (
265- body_ty : Option < & hir:: Ty < ' tcx > > ,
266- fcx : & FnCtxt < ' _ , ' tcx > ,
267- node : Node < ' tcx > ,
268- ) -> Option < Ty < ' tcx > > {
250+ fn infer_type_if_missing < ' tcx > ( fcx : & FnCtxt < ' _ , ' tcx > , node : Node < ' tcx > ) -> Option < Ty < ' tcx > > {
269251 let tcx = fcx. tcx ;
270252 let def_id = fcx. body_id ;
271- let expected_type = if let Some ( & hir:: Ty { kind : hir:: TyKind :: Infer , span, .. } ) = body_ty {
253+ let expected_type = if let Some ( & hir:: Ty { kind : hir:: TyKind :: Infer , span, .. } ) = node . ty ( ) {
272254 if let Some ( item) = tcx. opt_associated_item ( def_id. into ( ) )
273255 && let ty:: AssocKind :: Const = item. kind
274256 && let ty:: ImplContainer = item. container
0 commit comments