]> git.proxmox.com Git - rustc.git/blobdiff - compiler/rustc_typeck/src/check/closure.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / compiler / rustc_typeck / src / check / closure.rs
index 2ba05071c05000f5e046c10014c1fc356dd66a6f..7470c1a76a94316a910164c188e28618ae5be30f 100644 (file)
@@ -24,7 +24,7 @@ use std::iter;
 struct ExpectedSig<'tcx> {
     /// Span that gave us this expectation, if we know that.
     cause_span: Option<Span>,
-    sig: ty::FnSig<'tcx>,
+    sig: ty::PolyFnSig<'tcx>,
 }
 
 struct ClosureSignatures<'tcx> {
@@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             }
             ty::Infer(ty::TyVar(vid)) => self.deduce_expectations_from_obligations(vid),
             ty::FnPtr(sig) => {
-                let expected_sig = ExpectedSig { cause_span: None, sig: sig.skip_binder() };
+                let expected_sig = ExpectedSig { cause_span: None, sig };
                 (Some(expected_sig), Some(ty::ClosureKind::Fn))
             }
             _ => (None, None),
@@ -257,7 +257,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
         let input_tys = if is_fn {
             let arg_param_ty = trait_ref.skip_binder().substs.type_at(1);
-            let arg_param_ty = self.resolve_vars_if_possible(&arg_param_ty);
+            let arg_param_ty = self.resolve_vars_if_possible(arg_param_ty);
             debug!("deduce_sig_from_projection: arg_param_ty={:?}", arg_param_ty);
 
             match arg_param_ty.kind() {
@@ -271,16 +271,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         };
 
         let ret_param_ty = projection.skip_binder().ty;
-        let ret_param_ty = self.resolve_vars_if_possible(&ret_param_ty);
+        let ret_param_ty = self.resolve_vars_if_possible(ret_param_ty);
         debug!("deduce_sig_from_projection: ret_param_ty={:?}", ret_param_ty);
 
-        let sig = self.tcx.mk_fn_sig(
+        let sig = projection.rebind(self.tcx.mk_fn_sig(
             input_tys.iter(),
             &ret_param_ty,
             false,
             hir::Unsafety::Normal,
             Abi::Rust,
-        );
+        ));
         debug!("deduce_sig_from_projection: sig={:?}", sig);
 
         Some(ExpectedSig { cause_span, sig })
@@ -374,9 +374,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // Watch out for some surprises and just ignore the
         // expectation if things don't see to match up with what we
         // expect.
-        if expected_sig.sig.c_variadic != decl.c_variadic {
+        if expected_sig.sig.c_variadic() != decl.c_variadic {
             return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
-        } else if expected_sig.sig.inputs_and_output.len() != decl.inputs.len() + 1 {
+        } else if expected_sig.sig.skip_binder().inputs_and_output.len() != decl.inputs.len() + 1 {
             return self.sig_of_closure_with_mismatched_number_of_arguments(
                 expr_def_id,
                 decl,
@@ -388,19 +388,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // Create a `PolyFnSig`. Note the oddity that late bound
         // regions appearing free in `expected_sig` are now bound up
         // in this binder we are creating.
-        assert!(!expected_sig.sig.has_vars_bound_above(ty::INNERMOST));
-        let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig(
-            expected_sig.sig.inputs().iter().cloned(),
-            expected_sig.sig.output(),
-            decl.c_variadic,
-            hir::Unsafety::Normal,
-            Abi::RustCall,
-        ));
+        assert!(!expected_sig.sig.skip_binder().has_vars_bound_above(ty::INNERMOST));
+        let bound_sig = expected_sig.sig.map_bound(|sig| {
+            self.tcx.mk_fn_sig(
+                sig.inputs().iter().cloned(),
+                sig.output(),
+                sig.c_variadic,
+                hir::Unsafety::Normal,
+                Abi::RustCall,
+            )
+        });
 
         // `deduce_expectations_from_expected_type` introduces
         // late-bound lifetimes defined elsewhere, which we now
         // anonymize away, so as not to confuse the user.
-        let bound_sig = self.tcx.anonymize_late_bound_regions(&bound_sig);
+        let bound_sig = self.tcx.anonymize_late_bound_regions(bound_sig);
 
         let closure_sigs = self.closure_sigs(expr_def_id, body, bound_sig);
 
@@ -428,6 +430,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         let expr_map_node = hir.get_if_local(expr_def_id).unwrap();
         let expected_args: Vec<_> = expected_sig
             .sig
+            .skip_binder()
             .inputs()
             .iter()
             .map(|ty| ArgKind::from_expected_ty(ty, None))
@@ -500,7 +503,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 let (supplied_ty, _) = self.infcx.replace_bound_vars_with_fresh_vars(
                     hir_ty.span,
                     LateBoundRegionConversionTime::FnCall,
-                    &ty::Binder::bind(supplied_ty),
+                    supplied_sig.inputs().rebind(supplied_ty),
                 ); // recreated from (*) above
 
                 // Check that E' = S'.
@@ -513,7 +516,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             let (supplied_output_ty, _) = self.infcx.replace_bound_vars_with_fresh_vars(
                 decl.output.span(),
                 LateBoundRegionConversionTime::FnCall,
-                &supplied_sig.output(),
+                supplied_sig.output(),
             );
             let cause = &self.misc(decl.output.span());
             let InferOk { value: (), obligations } = self
@@ -578,7 +581,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
 
         debug!("supplied_sig_of_closure: result={:?}", result);
 
-        let c_result = self.inh.infcx.canonicalize_response(&result);
+        let c_result = self.inh.infcx.canonicalize_response(result);
         self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
 
         result
@@ -619,12 +622,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // where R is the return type we are expecting. This type `T`
         // will be our output.
         let output_ty = self.obligations_for_self_ty(ret_vid).find_map(|(_, obligation)| {
-            if let ty::PredicateAtom::Projection(proj_predicate) =
-                obligation.predicate.skip_binders()
-            {
+            let bound_predicate = obligation.predicate.bound_atom();
+            if let ty::PredicateAtom::Projection(proj_predicate) = bound_predicate.skip_binder() {
                 self.deduce_future_output_from_projection(
                     obligation.cause.span,
-                    ty::Binder::bind(proj_predicate),
+                    bound_predicate.rebind(proj_predicate),
                 )
             } else {
                 None
@@ -683,7 +685,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         // Extract the type from the projection. Note that there can
         // be no bound variables in this type because the "self type"
         // does not have any regions in it.
-        let output_ty = self.resolve_vars_if_possible(&predicate.ty);
+        let output_ty = self.resolve_vars_if_possible(predicate.ty);
         debug!("deduce_future_output_from_projection: output_ty={:?}", output_ty);
         Some(output_ty)
     }
@@ -704,7 +706,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             astconv.ast_ty_to_ty(&output);
         }
 
-        let result = ty::Binder::bind(self.tcx.mk_fn_sig(
+        let result = ty::Binder::dummy(self.tcx.mk_fn_sig(
             supplied_arguments,
             self.tcx.ty_error(),
             decl.c_variadic,
@@ -723,12 +725,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         body: &hir::Body<'_>,
         bound_sig: ty::PolyFnSig<'tcx>,
     ) -> ClosureSignatures<'tcx> {
-        let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, &bound_sig);
+        let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, bound_sig);
         let liberated_sig = self.inh.normalize_associated_types_in(
             body.value.span,
             body.value.hir_id,
             self.param_env,
-            &liberated_sig,
+            liberated_sig,
         );
         ClosureSignatures { bound_sig, liberated_sig }
     }