]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/check/closure.rs
Refactor away `inferred_obligations` from the trait selector
[rust.git] / src / librustc_typeck / check / closure.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Code for type-checking closure expressions.
12
13 use super::{check_fn, Expectation, FnCtxt, GeneratorTypes};
14
15 use astconv::AstConv;
16 use rustc::hir::def_id::DefId;
17 use rustc::infer::{InferOk, InferResult};
18 use rustc::infer::LateBoundRegionConversionTime;
19 use rustc::infer::type_variable::TypeVariableOrigin;
20 use rustc::traits::error_reporting::ArgKind;
21 use rustc::ty::{self, ToPolyTraitRef, Ty};
22 use rustc::ty::subst::Substs;
23 use rustc::ty::TypeFoldable;
24 use std::cmp;
25 use std::iter;
26 use syntax::abi::Abi;
27 use syntax::codemap::Span;
28 use rustc::hir;
29
30 /// What signature do we *expect* the closure to have from context?
31 #[derive(Debug)]
32 struct ExpectedSig<'tcx> {
33     /// Span that gave us this expectation, if we know that.
34     cause_span: Option<Span>,
35     sig: ty::FnSig<'tcx>,
36 }
37
38 struct ClosureSignatures<'tcx> {
39     bound_sig: ty::PolyFnSig<'tcx>,
40     liberated_sig: ty::FnSig<'tcx>,
41 }
42
43 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44     pub fn check_expr_closure(
45         &self,
46         expr: &hir::Expr,
47         _capture: hir::CaptureClause,
48         decl: &'gcx hir::FnDecl,
49         body_id: hir::BodyId,
50         gen: Option<hir::GeneratorMovability>,
51         expected: Expectation<'tcx>,
52     ) -> Ty<'tcx> {
53         debug!(
54             "check_expr_closure(expr={:?},expected={:?})",
55             expr, expected
56         );
57
58         // It's always helpful for inference if we know the kind of
59         // closure sooner rather than later, so first examine the expected
60         // type, and see if can glean a closure kind from there.
61         let (expected_sig, expected_kind) = match expected.to_option(self) {
62             Some(ty) => self.deduce_expectations_from_expected_type(ty),
63             None => (None, None),
64         };
65         let body = self.tcx.hir.body(body_id);
66         self.check_closure(expr, expected_kind, decl, body, gen, expected_sig)
67     }
68
69     fn check_closure(
70         &self,
71         expr: &hir::Expr,
72         opt_kind: Option<ty::ClosureKind>,
73         decl: &'gcx hir::FnDecl,
74         body: &'gcx hir::Body,
75         gen: Option<hir::GeneratorMovability>,
76         expected_sig: Option<ExpectedSig<'tcx>>,
77     ) -> Ty<'tcx> {
78         debug!(
79             "check_closure(opt_kind={:?}, expected_sig={:?})",
80             opt_kind, expected_sig
81         );
82
83         let expr_def_id = self.tcx.hir.local_def_id(expr.id);
84
85         let ClosureSignatures {
86             bound_sig,
87             liberated_sig,
88         } = self.sig_of_closure(expr_def_id, decl, body, expected_sig);
89
90         debug!("check_closure: ty_of_closure returns {:?}", liberated_sig);
91
92         let generator_types = check_fn(
93             self,
94             self.param_env,
95             liberated_sig,
96             decl,
97             expr.id,
98             body,
99             gen,
100         ).1;
101
102         // Create type variables (for now) to represent the transformed
103         // types of upvars. These will be unified during the upvar
104         // inference phase (`upvar.rs`).
105         let base_substs =
106             Substs::identity_for_item(self.tcx, self.tcx.closure_base_def_id(expr_def_id));
107         let substs = base_substs.extend_to(
108             self.tcx,
109             expr_def_id,
110             |_, _| span_bug!(expr.span, "closure has region param"),
111             |_, _| {
112                 self.infcx
113                     .next_ty_var(ty::UniverseIndex::ROOT,
114                                  TypeVariableOrigin::ClosureSynthetic(expr.span))
115             },
116         );
117         let substs = ty::ClosureSubsts { substs };
118         let closure_type = self.tcx.mk_closure(expr_def_id, substs);
119
120         if let Some(GeneratorTypes { yield_ty, interior }) = generator_types {
121             self.demand_eqtype(
122                 expr.span,
123                 yield_ty,
124                 substs.generator_yield_ty(expr_def_id, self.tcx),
125             );
126             self.demand_eqtype(
127                 expr.span,
128                 liberated_sig.output(),
129                 substs.generator_return_ty(expr_def_id, self.tcx),
130             );
131             return self.tcx.mk_generator(expr_def_id, substs, interior);
132         }
133
134         debug!(
135             "check_closure: expr.id={:?} closure_type={:?}",
136             expr.id, closure_type
137         );
138
139         // Tuple up the arguments and insert the resulting function type into
140         // the `closures` table.
141         let sig = bound_sig.map_bound(|sig| {
142             self.tcx.mk_fn_sig(
143                 iter::once(self.tcx.intern_tup(sig.inputs(), false)),
144                 sig.output(),
145                 sig.variadic,
146                 sig.unsafety,
147                 sig.abi,
148             )
149         });
150
151         debug!(
152             "check_closure: expr_def_id={:?}, sig={:?}, opt_kind={:?}",
153             expr_def_id, sig, opt_kind
154         );
155
156         let sig_fn_ptr_ty = self.tcx.mk_fn_ptr(sig);
157         self.demand_eqtype(
158             expr.span,
159             sig_fn_ptr_ty,
160             substs.closure_sig_ty(expr_def_id, self.tcx),
161         );
162
163         if let Some(kind) = opt_kind {
164             self.demand_eqtype(
165                 expr.span,
166                 kind.to_ty(self.tcx),
167                 substs.closure_kind_ty(expr_def_id, self.tcx),
168             );
169         }
170
171         closure_type
172     }
173
174     /// Given the expected type, figures out what it can about this closure we
175     /// are about to type check:
176     fn deduce_expectations_from_expected_type(
177         &self,
178         expected_ty: Ty<'tcx>,
179     ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
180         debug!(
181             "deduce_expectations_from_expected_type(expected_ty={:?})",
182             expected_ty
183         );
184
185         match expected_ty.sty {
186             ty::TyDynamic(ref object_type, ..) => {
187                 let sig = object_type
188                     .projection_bounds()
189                     .filter_map(|pb| {
190                         let pb = pb.with_self_ty(self.tcx, self.tcx.types.err);
191                         self.deduce_sig_from_projection(None, &pb)
192                     })
193                     .next();
194                 let kind = object_type
195                     .principal()
196                     .and_then(|p| self.tcx.lang_items().fn_trait_kind(p.def_id()));
197                 (sig, kind)
198             }
199             ty::TyInfer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
200             ty::TyFnPtr(sig) => {
201                 let expected_sig = ExpectedSig {
202                     cause_span: None,
203                     sig: sig.skip_binder().clone(),
204                 };
205                 (Some(expected_sig), Some(ty::ClosureKind::Fn))
206             }
207             _ => (None, None),
208         }
209     }
210
211     fn deduce_expectations_from_obligations(
212         &self,
213         expected_vid: ty::TyVid,
214     ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
215         let fulfillment_cx = self.fulfillment_cx.borrow();
216         // Here `expected_ty` is known to be a type inference variable.
217
218         let expected_sig = fulfillment_cx
219             .pending_obligations()
220             .iter()
221             .map(|obligation| &obligation.obligation)
222             .filter_map(|obligation| {
223                 debug!(
224                     "deduce_expectations_from_obligations: obligation.predicate={:?}",
225                     obligation.predicate
226                 );
227
228                 match obligation.predicate {
229                     // Given a Projection predicate, we can potentially infer
230                     // the complete signature.
231                     ty::Predicate::Projection(ref proj_predicate) => {
232                         let trait_ref = proj_predicate.to_poly_trait_ref(self.tcx);
233                         self.self_type_matches_expected_vid(trait_ref, expected_vid)
234                             .and_then(|_| {
235                                 self.deduce_sig_from_projection(
236                                     Some(obligation.cause.span),
237                                     proj_predicate,
238                                 )
239                             })
240                     }
241                     _ => None,
242                 }
243             })
244             .next();
245
246         // Even if we can't infer the full signature, we may be able to
247         // infer the kind. This can occur if there is a trait-reference
248         // like `F : Fn<A>`. Note that due to subtyping we could encounter
249         // many viable options, so pick the most restrictive.
250         let expected_kind = fulfillment_cx
251             .pending_obligations()
252             .iter()
253             .map(|obligation| &obligation.obligation)
254             .filter_map(|obligation| {
255                 let opt_trait_ref = match obligation.predicate {
256                     ty::Predicate::Projection(ref data) => Some(data.to_poly_trait_ref(self.tcx)),
257                     ty::Predicate::Trait(ref data) => Some(data.to_poly_trait_ref()),
258                     ty::Predicate::Equate(..) => None,
259                     ty::Predicate::Subtype(..) => None,
260                     ty::Predicate::RegionOutlives(..) => None,
261                     ty::Predicate::TypeOutlives(..) => None,
262                     ty::Predicate::WellFormed(..) => None,
263                     ty::Predicate::ObjectSafe(..) => None,
264                     ty::Predicate::ConstEvaluatable(..) => None,
265
266                     // NB: This predicate is created by breaking down a
267                     // `ClosureType: FnFoo()` predicate, where
268                     // `ClosureType` represents some `TyClosure`. It can't
269                     // possibly be referring to the current closure,
270                     // because we haven't produced the `TyClosure` for
271                     // this closure yet; this is exactly why the other
272                     // code is looking for a self type of a unresolved
273                     // inference variable.
274                     ty::Predicate::ClosureKind(..) => None,
275                 };
276                 opt_trait_ref
277                     .and_then(|tr| self.self_type_matches_expected_vid(tr, expected_vid))
278                     .and_then(|tr| self.tcx.lang_items().fn_trait_kind(tr.def_id()))
279             })
280             .fold(None, |best, cur| {
281                 Some(best.map_or(cur, |best| cmp::min(best, cur)))
282             });
283
284         (expected_sig, expected_kind)
285     }
286
287     /// Given a projection like "<F as Fn(X)>::Result == Y", we can deduce
288     /// everything we need to know about a closure.
289     ///
290     /// The `cause_span` should be the span that caused us to
291     /// have this expected signature, or `None` if we can't readily
292     /// know that.
293     fn deduce_sig_from_projection(
294         &self,
295         cause_span: Option<Span>,
296         projection: &ty::PolyProjectionPredicate<'tcx>,
297     ) -> Option<ExpectedSig<'tcx>> {
298         let tcx = self.tcx;
299
300         debug!("deduce_sig_from_projection({:?})", projection);
301
302         let trait_ref = projection.to_poly_trait_ref(tcx);
303
304         if tcx.lang_items().fn_trait_kind(trait_ref.def_id()).is_none() {
305             return None;
306         }
307
308         let arg_param_ty = trait_ref.substs().type_at(1);
309         let arg_param_ty = self.resolve_type_vars_if_possible(&arg_param_ty);
310         debug!(
311             "deduce_sig_from_projection: arg_param_ty {:?}",
312             arg_param_ty
313         );
314
315         let input_tys = match arg_param_ty.sty {
316             ty::TyTuple(tys, _) => tys.into_iter(),
317             _ => {
318                 return None;
319             }
320         };
321
322         let ret_param_ty = projection.0.ty;
323         let ret_param_ty = self.resolve_type_vars_if_possible(&ret_param_ty);
324         debug!(
325             "deduce_sig_from_projection: ret_param_ty {:?}",
326             ret_param_ty
327         );
328
329         let sig = self.tcx.mk_fn_sig(
330             input_tys.cloned(),
331             ret_param_ty,
332             false,
333             hir::Unsafety::Normal,
334             Abi::Rust,
335         );
336         debug!("deduce_sig_from_projection: sig {:?}", sig);
337
338         Some(ExpectedSig { cause_span, sig })
339     }
340
341     fn self_type_matches_expected_vid(
342         &self,
343         trait_ref: ty::PolyTraitRef<'tcx>,
344         expected_vid: ty::TyVid,
345     ) -> Option<ty::PolyTraitRef<'tcx>> {
346         let self_ty = self.shallow_resolve(trait_ref.self_ty());
347         debug!(
348             "self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?})",
349             trait_ref, self_ty
350         );
351         match self_ty.sty {
352             ty::TyInfer(ty::TyVar(v)) if expected_vid == v => Some(trait_ref),
353             _ => None,
354         }
355     }
356
357     fn sig_of_closure(
358         &self,
359         expr_def_id: DefId,
360         decl: &hir::FnDecl,
361         body: &hir::Body,
362         expected_sig: Option<ExpectedSig<'tcx>>,
363     ) -> ClosureSignatures<'tcx> {
364         if let Some(e) = expected_sig {
365             self.sig_of_closure_with_expectation(expr_def_id, decl, body, e)
366         } else {
367             self.sig_of_closure_no_expectation(expr_def_id, decl, body)
368         }
369     }
370
371     /// If there is no expected signature, then we will convert the
372     /// types that the user gave into a signature.
373     fn sig_of_closure_no_expectation(
374         &self,
375         expr_def_id: DefId,
376         decl: &hir::FnDecl,
377         body: &hir::Body,
378     ) -> ClosureSignatures<'tcx> {
379         debug!("sig_of_closure_no_expectation()");
380
381         let bound_sig = self.supplied_sig_of_closure(decl);
382
383         self.closure_sigs(expr_def_id, body, bound_sig)
384     }
385
386     /// Invoked to compute the signature of a closure expression. This
387     /// combines any user-provided type annotations (e.g., `|x: u32|
388     /// -> u32 { .. }`) with the expected signature.
389     ///
390     /// The approach is as follows:
391     ///
392     /// - Let `S` be the (higher-ranked) signature that we derive from the user's annotations.
393     /// - Let `E` be the (higher-ranked) signature that we derive from the expectations, if any.
394     ///   - If we have no expectation `E`, then the signature of the closure is `S`.
395     ///   - Otherwise, the signature of the closure is E. Moreover:
396     ///     - Skolemize the late-bound regions in `E`, yielding `E'`.
397     ///     - Instantiate all the late-bound regions bound in the closure within `S`
398     ///       with fresh (existential) variables, yielding `S'`
399     ///     - Require that `E' = S'`
400     ///       - We could use some kind of subtyping relationship here,
401     ///         I imagine, but equality is easier and works fine for
402     ///         our purposes.
403     ///
404     /// The key intuition here is that the user's types must be valid
405     /// from "the inside" of the closure, but the expectation
406     /// ultimately drives the overall signature.
407     ///
408     /// # Examples
409     ///
410     /// ```
411     /// fn with_closure<F>(_: F)
412     ///   where F: Fn(&u32) -> &u32 { .. }
413     ///
414     /// with_closure(|x: &u32| { ... })
415     /// ```
416     ///
417     /// Here:
418     /// - E would be `fn(&u32) -> &u32`.
419     /// - S would be `fn(&u32) ->
420     /// - E' is `&'!0 u32 -> &'!0 u32`
421     /// - S' is `&'?0 u32 -> ?T`
422     ///
423     /// S' can be unified with E' with `['?0 = '!0, ?T = &'!10 u32]`.
424     ///
425     /// # Arguments
426     ///
427     /// - `expr_def_id`: the def-id of the closure expression
428     /// - `decl`: the HIR declaration of the closure
429     /// - `body`: the body of the closure
430     /// - `expected_sig`: the expected signature (if any). Note that
431     ///   this is missing a binder: that is, there may be late-bound
432     ///   regions with depth 1, which are bound then by the closure.
433     fn sig_of_closure_with_expectation(
434         &self,
435         expr_def_id: DefId,
436         decl: &hir::FnDecl,
437         body: &hir::Body,
438         expected_sig: ExpectedSig<'tcx>,
439     ) -> ClosureSignatures<'tcx> {
440         debug!(
441             "sig_of_closure_with_expectation(expected_sig={:?})",
442             expected_sig
443         );
444
445         // Watch out for some surprises and just ignore the
446         // expectation if things don't see to match up with what we
447         // expect.
448         if expected_sig.sig.variadic != decl.variadic {
449             return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
450         } else if expected_sig.sig.inputs_and_output.len() != decl.inputs.len() + 1 {
451             return self.sig_of_closure_with_mismatched_number_of_arguments(
452                 expr_def_id,
453                 decl,
454                 body,
455                 expected_sig,
456             );
457         }
458
459         // Create a `PolyFnSig`. Note the oddity that late bound
460         // regions appearing free in `expected_sig` are now bound up
461         // in this binder we are creating.
462         assert!(!expected_sig.sig.has_regions_escaping_depth(1));
463         let bound_sig = ty::Binder(self.tcx.mk_fn_sig(
464             expected_sig.sig.inputs().iter().cloned(),
465             expected_sig.sig.output(),
466             decl.variadic,
467             hir::Unsafety::Normal,
468             Abi::RustCall,
469         ));
470
471         // `deduce_expectations_from_expected_type` introduces
472         // late-bound lifetimes defined elsewhere, which we now
473         // anonymize away, so as not to confuse the user.
474         let bound_sig = self.tcx.anonymize_late_bound_regions(&bound_sig);
475
476         let closure_sigs = self.closure_sigs(expr_def_id, body, bound_sig);
477
478         // Up till this point, we have ignored the annotations that the user
479         // gave. This function will check that they unify successfully.
480         // Along the way, it also writes out entries for types that the user
481         // wrote into our tables, which are then later used by the privacy
482         // check.
483         match self.check_supplied_sig_against_expectation(decl, &closure_sigs) {
484             Ok(infer_ok) => self.register_infer_ok_obligations(infer_ok),
485             Err(_) => return self.sig_of_closure_no_expectation(expr_def_id, decl, body),
486         }
487
488         closure_sigs
489     }
490
491     fn sig_of_closure_with_mismatched_number_of_arguments(
492         &self,
493         expr_def_id: DefId,
494         decl: &hir::FnDecl,
495         body: &hir::Body,
496         expected_sig: ExpectedSig<'tcx>,
497     ) -> ClosureSignatures<'tcx> {
498         let expr_map_node = self.tcx.hir.get_if_local(expr_def_id).unwrap();
499         let expected_args: Vec<_> = expected_sig
500             .sig
501             .inputs()
502             .iter()
503             .map(|ty| ArgKind::from_expected_ty(ty))
504             .collect();
505         let (closure_span, found_args) = self.get_fn_like_arguments(expr_map_node);
506         let expected_span = expected_sig.cause_span.unwrap_or(closure_span);
507         self.report_arg_count_mismatch(
508             expected_span,
509             Some(closure_span),
510             expected_args,
511             found_args,
512             true,
513         ).emit();
514
515         let error_sig = self.error_sig_of_closure(decl);
516
517         self.closure_sigs(expr_def_id, body, error_sig)
518     }
519
520     /// Enforce the user's types against the expectation.  See
521     /// `sig_of_closure_with_expectation` for details on the overall
522     /// strategy.
523     fn check_supplied_sig_against_expectation(
524         &self,
525         decl: &hir::FnDecl,
526         expected_sigs: &ClosureSignatures<'tcx>,
527     ) -> InferResult<'tcx, ()> {
528         // Get the signature S that the user gave.
529         //
530         // (See comment on `sig_of_closure_with_expectation` for the
531         // meaning of these letters.)
532         let supplied_sig = self.supplied_sig_of_closure(decl);
533
534         debug!(
535             "check_supplied_sig_against_expectation: supplied_sig={:?}",
536             supplied_sig
537         );
538
539         // FIXME(#45727): As discussed in [this comment][c1], naively
540         // forcing equality here actually results in suboptimal error
541         // messages in some cases.  For now, if there would have been
542         // an obvious error, we fallback to declaring the type of the
543         // closure to be the one the user gave, which allows other
544         // error message code to trigger.
545         //
546         // However, I think [there is potential to do even better
547         // here][c2], since in *this* code we have the precise span of
548         // the type parameter in question in hand when we report the
549         // error.
550         //
551         // [c1]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341089706
552         // [c2]: https://github.com/rust-lang/rust/pull/45072#issuecomment-341096796
553         self.infcx.commit_if_ok(|_| {
554             let mut all_obligations = vec![];
555
556             // The liberated version of this signature should be be a subtype
557             // of the liberated form of the expectation.
558             for ((hir_ty, &supplied_ty), expected_ty) in decl.inputs.iter()
559                            .zip(*supplied_sig.inputs().skip_binder()) // binder moved to (*) below
560                            .zip(expected_sigs.liberated_sig.inputs())
561             // `liberated_sig` is E'.
562             {
563                 // Instantiate (this part of..) S to S', i.e., with fresh variables.
564                 let (supplied_ty, _) = self.infcx.replace_late_bound_regions_with_fresh_var(
565                     hir_ty.span,
566                     LateBoundRegionConversionTime::FnCall,
567                     &ty::Binder(supplied_ty),
568                 ); // recreated from (*) above
569
570                 // Check that E' = S'.
571                 let cause = &self.misc(hir_ty.span);
572                 let InferOk {
573                     value: (),
574                     obligations,
575                 } = self.at(cause, self.param_env)
576                     .eq(*expected_ty, supplied_ty)?;
577                 all_obligations.extend(obligations);
578             }
579
580             let (supplied_output_ty, _) = self.infcx.replace_late_bound_regions_with_fresh_var(
581                 decl.output.span(),
582                 LateBoundRegionConversionTime::FnCall,
583                 &supplied_sig.output(),
584             );
585             let cause = &self.misc(decl.output.span());
586             let InferOk {
587                 value: (),
588                 obligations,
589             } = self.at(cause, self.param_env)
590                 .eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
591             all_obligations.extend(obligations);
592
593             Ok(InferOk {
594                 value: (),
595                 obligations: all_obligations,
596             })
597         })
598     }
599
600     /// If there is no expected signature, then we will convert the
601     /// types that the user gave into a signature.
602     fn supplied_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
603         let astconv: &AstConv = self;
604
605         // First, convert the types that the user supplied (if any).
606         let supplied_arguments = decl.inputs.iter().map(|a| astconv.ast_ty_to_ty(a));
607         let supplied_return = match decl.output {
608             hir::Return(ref output) => astconv.ast_ty_to_ty(&output),
609             hir::DefaultReturn(_) => astconv.ty_infer(decl.output.span()),
610         };
611
612         let result = ty::Binder(self.tcx.mk_fn_sig(
613             supplied_arguments,
614             supplied_return,
615             decl.variadic,
616             hir::Unsafety::Normal,
617             Abi::RustCall,
618         ));
619
620         debug!("supplied_sig_of_closure: result={:?}", result);
621
622         result
623     }
624
625     /// Converts the types that the user supplied, in case that doing
626     /// so should yield an error, but returns back a signature where
627     /// all parameters are of type `TyErr`.
628     fn error_sig_of_closure(&self, decl: &hir::FnDecl) -> ty::PolyFnSig<'tcx> {
629         let astconv: &AstConv = self;
630
631         let supplied_arguments = decl.inputs.iter().map(|a| {
632             // Convert the types that the user supplied (if any), but ignore them.
633             astconv.ast_ty_to_ty(a);
634             self.tcx.types.err
635         });
636
637         match decl.output {
638             hir::Return(ref output) => {
639                 astconv.ast_ty_to_ty(&output);
640             }
641             hir::DefaultReturn(_) => {}
642         }
643
644         let result = ty::Binder(self.tcx.mk_fn_sig(
645             supplied_arguments,
646             self.tcx.types.err,
647             decl.variadic,
648             hir::Unsafety::Normal,
649             Abi::RustCall,
650         ));
651
652         debug!("supplied_sig_of_closure: result={:?}", result);
653
654         result
655     }
656
657     fn closure_sigs(
658         &self,
659         expr_def_id: DefId,
660         body: &hir::Body,
661         bound_sig: ty::PolyFnSig<'tcx>,
662     ) -> ClosureSignatures<'tcx> {
663         let liberated_sig = self.tcx()
664             .liberate_late_bound_regions(expr_def_id, &bound_sig);
665         let liberated_sig = self.inh.normalize_associated_types_in(
666             body.value.span,
667             body.value.id,
668             self.param_env,
669             &liberated_sig,
670         );
671         ClosureSignatures {
672             bound_sig,
673             liberated_sig,
674         }
675     }
676 }