@@ -83,20 +83,6 @@ macro_rules! type_error_struct {
83
83
} )
84
84
}
85
85
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
-
100
86
fn has_typeck_results ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
101
87
// Closures' typeck results come from their outermost function,
102
88
// as they are part of the same "inference environment".
@@ -163,7 +149,7 @@ fn typeck_with_fallback<'tcx>(
163
149
let span = tcx. hir ( ) . span ( id) ;
164
150
165
151
// 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 ( || {
167
153
span_bug ! ( span, "can't type-check body of {:?}" , def_id) ;
168
154
} ) ;
169
155
let body = tcx. hir ( ) . body ( body_id) ;
@@ -176,7 +162,7 @@ fn typeck_with_fallback<'tcx>(
176
162
}
177
163
let mut fcx = FnCtxt :: new ( & inh, param_env, def_id) ;
178
164
179
- if let Some ( hir:: FnSig { header, decl, .. } ) = fn_sig {
165
+ if let Some ( hir:: FnSig { header, decl, .. } ) = node . fn_sig ( ) {
180
166
let fn_sig = if decl. output . get_infer_ret_ty ( ) . is_some ( ) {
181
167
fcx. lowerer ( ) . lower_fn_ty ( id, header. unsafety , header. abi , decl, None , None )
182
168
} else {
@@ -191,7 +177,7 @@ fn typeck_with_fallback<'tcx>(
191
177
192
178
check_fn ( & mut fcx, fn_sig, None , decl, def_id, body, tcx. features ( ) . unsized_fn_params ) ;
193
179
} else {
194
- let expected_type = infer_type_if_missing ( body_ty , & fcx, node) ;
180
+ let expected_type = infer_type_if_missing ( & fcx, node) ;
195
181
let expected_type = expected_type. unwrap_or_else ( fallback) ;
196
182
197
183
let expected_type = fcx. normalize ( body. value . span , expected_type) ;
@@ -261,14 +247,10 @@ fn typeck_with_fallback<'tcx>(
261
247
typeck_results
262
248
}
263
249
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 > > {
269
251
let tcx = fcx. tcx ;
270
252
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 ( ) {
272
254
if let Some ( item) = tcx. opt_associated_item ( def_id. into ( ) )
273
255
&& let ty:: AssocKind :: Const = item. kind
274
256
&& let ty:: ImplContainer = item. container
0 commit comments