]> git.proxmox.com Git - rustc.git/blobdiff - compiler/rustc_trait_selection/src/traits/project.rs
New upstream version 1.50.0+dfsg1
[rustc.git] / compiler / rustc_trait_selection / src / traits / project.rs
index 170110a54aea6b2fa596ef095e455068b0f2c766..f22b5b96616990febaa2bc078edc937382686608 100644 (file)
@@ -168,7 +168,7 @@ pub(super) fn poly_project_and_unify_type<'cx, 'tcx>(
     let infcx = selcx.infcx();
     infcx.commit_if_ok(|_snapshot| {
         let placeholder_predicate =
-            infcx.replace_bound_vars_with_placeholders(&obligation.predicate);
+            infcx.replace_bound_vars_with_placeholders(obligation.predicate);
 
         let placeholder_obligation = obligation.with(placeholder_predicate);
         let result = project_and_unify_type(selcx, &placeholder_obligation)?;
@@ -232,7 +232,7 @@ pub fn normalize<'a, 'b, 'tcx, T>(
     selcx: &'a mut SelectionContext<'b, 'tcx>,
     param_env: ty::ParamEnv<'tcx>,
     cause: ObligationCause<'tcx>,
-    value: &T,
+    value: T,
 ) -> Normalized<'tcx, T>
 where
     T: TypeFoldable<'tcx>,
@@ -246,7 +246,7 @@ pub fn normalize_to<'a, 'b, 'tcx, T>(
     selcx: &'a mut SelectionContext<'b, 'tcx>,
     param_env: ty::ParamEnv<'tcx>,
     cause: ObligationCause<'tcx>,
-    value: &T,
+    value: T,
     obligations: &mut Vec<PredicateObligation<'tcx>>,
 ) -> T
 where
@@ -261,7 +261,7 @@ pub fn normalize_with_depth<'a, 'b, 'tcx, T>(
     param_env: ty::ParamEnv<'tcx>,
     cause: ObligationCause<'tcx>,
     depth: usize,
-    value: &T,
+    value: T,
 ) -> Normalized<'tcx, T>
 where
     T: TypeFoldable<'tcx>,
@@ -277,7 +277,7 @@ pub fn normalize_with_depth_to<'a, 'b, 'tcx, T>(
     param_env: ty::ParamEnv<'tcx>,
     cause: ObligationCause<'tcx>,
     depth: usize,
-    value: &T,
+    value: T,
     obligations: &mut Vec<PredicateObligation<'tcx>>,
 ) -> T
 where
@@ -309,7 +309,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
         AssocTypeNormalizer { selcx, param_env, cause, obligations, depth }
     }
 
-    fn fold<T: TypeFoldable<'tcx>>(&mut self, value: &T) -> T {
+    fn fold<T: TypeFoldable<'tcx>>(&mut self, value: T) -> T {
         let value = self.selcx.infcx().resolve_vars_if_possible(value);
 
         if !value.has_projections() { value } else { value.fold_with(self) }
@@ -365,7 +365,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
                 }
             }
 
-            ty::Projection(ref data) if !data.has_escaping_bound_vars() => {
+            ty::Projection(data) if !data.has_escaping_bound_vars() => {
                 // This is kind of hacky -- we need to be able to
                 // handle normalization within binders because
                 // otherwise we wind up a need to normalize when doing
@@ -381,7 +381,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
                 let normalized_ty = normalize_projection_type(
                     self.selcx,
                     self.param_env,
-                    *data,
+                    data,
                     self.cause.clone(),
                     self.depth,
                     &mut self.obligations,
@@ -474,7 +474,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
 ) -> Result<Option<Ty<'tcx>>, InProgress> {
     let infcx = selcx.infcx();
 
-    let projection_ty = infcx.resolve_vars_if_possible(&projection_ty);
+    let projection_ty = infcx.resolve_vars_if_possible(projection_ty);
     let cache_key = ProjectionCacheKey::new(projection_ty);
 
     // FIXME(#20304) For now, I am caching here, which is good, but it
@@ -569,7 +569,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
                     depth + 1,
                     &mut projected_obligations,
                 );
-                let normalized_ty = normalizer.fold(&projected_ty);
+                let normalized_ty = normalizer.fold(projected_ty);
 
                 debug!(?normalized_ty, ?depth);
 
@@ -736,14 +736,9 @@ fn project_type<'cx, 'tcx>(
 
     if !selcx.tcx().sess.recursion_limit().value_within_limit(obligation.recursion_depth) {
         debug!("project: overflow!");
-        match selcx.query_mode() {
-            super::TraitQueryMode::Standard => {
-                selcx.infcx().report_overflow_error(&obligation, true);
-            }
-            super::TraitQueryMode::Canonical => {
-                return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow));
-            }
-        }
+        // This should really be an immediate error, but some existing code
+        // relies on being able to recover from this.
+        return Err(ProjectionTyError::TraitSelectionError(SelectionError::Overflow));
     }
 
     let obligation_trait_ref = &obligation.predicate.trait_ref(selcx.tcx());
@@ -960,7 +955,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
 
     // If we are resolving `<T as TraitRef<...>>::Item == Type`,
     // start out by selecting the predicate `T as TraitRef<...>`:
-    let poly_trait_ref = obligation_trait_ref.to_poly_trait_ref();
+    let poly_trait_ref = ty::Binder::dummy(*obligation_trait_ref);
     let trait_obligation = obligation.with(poly_trait_ref.to_poly_trait_predicate());
     let _ = selcx.infcx().commit_if_ok(|_| {
         let impl_source = match selcx.select(&trait_obligation) {
@@ -1006,7 +1001,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
                 // type.
                 //
                 // NOTE: This should be kept in sync with the similar code in
-                // `rustc_ty::instance::resolve_associated_item()`.
+                // `rustc_ty_utils::instance::resolve_associated_item()`.
                 let node_item =
                     assoc_ty_def(selcx, impl_data.impl_def_id, obligation.predicate.item_def_id)
                         .map_err(|ErrorReported| ())?;
@@ -1022,8 +1017,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
                     if obligation.param_env.reveal() == Reveal::All {
                         // NOTE(eddyb) inference variables can resolve to parameters, so
                         // assume `poly_trait_ref` isn't monomorphic, if it contains any.
-                        let poly_trait_ref =
-                            selcx.infcx().resolve_vars_if_possible(&poly_trait_ref);
+                        let poly_trait_ref = selcx.infcx().resolve_vars_if_possible(poly_trait_ref);
                         !poly_trait_ref.still_further_specializable()
                     } else {
                         debug!(
@@ -1201,7 +1195,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
         obligation.param_env,
         obligation.cause.clone(),
         obligation.recursion_depth + 1,
-        &gen_sig,
+        gen_sig,
     );
 
     debug!(?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate");
@@ -1257,7 +1251,9 @@ fn confirm_discriminant_kind_candidate<'cx, 'tcx>(
         ty: self_ty.discriminant_ty(tcx),
     };
 
-    confirm_param_env_candidate(selcx, obligation, ty::Binder::bind(predicate), false)
+    // We get here from `poly_project_and_unify_type` which replaces bound vars
+    // with placeholders, so dummy is okay here.
+    confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
 }
 
 fn confirm_fn_pointer_candidate<'cx, 'tcx>(
@@ -1272,7 +1268,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>(
         obligation.param_env,
         obligation.cause.clone(),
         obligation.recursion_depth + 1,
-        &sig,
+        sig,
     );
 
     confirm_callable_candidate(selcx, obligation, sig, util::TupleArgumentsFlag::Yes)
@@ -1291,7 +1287,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
         obligation.param_env,
         obligation.cause.clone(),
         obligation.recursion_depth + 1,
-        &closure_sig,
+        closure_sig,
     );
 
     debug!(?obligation, ?closure_sig, ?obligations, "confirm_closure_candidate");
@@ -1345,7 +1341,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
     let (cache_entry, _) = infcx.replace_bound_vars_with_fresh_vars(
         cause.span,
         LateBoundRegionConversionTime::HigherRankedType,
-        &poly_cache_entry,
+        poly_cache_entry,
     );
 
     let cache_trait_ref = cache_entry.projection_ty.trait_ref(infcx.tcx);
@@ -1358,7 +1354,7 @@ fn confirm_param_env_candidate<'cx, 'tcx>(
                 obligation.param_env,
                 obligation.cause.clone(),
                 obligation.recursion_depth + 1,
-                &cache_trait_ref,
+                cache_trait_ref,
                 &mut nested_obligations,
             )
         })
@@ -1454,7 +1450,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
             obligation.param_env,
             obligation.cause.clone(),
             obligation.recursion_depth + 1,
-            &predicate,
+            predicate,
             nested,
         );
         nested.push(Obligation::with_depth(
@@ -1535,7 +1531,7 @@ impl<'tcx> ProjectionCacheKeyExt<'tcx> for ProjectionCacheKey<'tcx> {
                 // from a specific call to `opt_normalize_projection_type` - if
                 // there's no precise match, the original cache entry is "stranded"
                 // anyway.
-                infcx.resolve_vars_if_possible(&predicate.projection_ty),
+                infcx.resolve_vars_if_possible(predicate.projection_ty),
             )
         })
     }