about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-12-07 20:40:06 +0800
committerDeadbeef <ent3rm4n@gmail.com>2021-12-12 12:35:00 +0800
commit17b53b964567b948c08cf04b9571d62146597ae3 (patch)
tree6ceeb131cbcc71d69b79ade32f0a8bb2252c3602
parent2bea3b3aa3fd943aee09b5ef3ef85d449d986422 (diff)
downloadrust-17b53b964567b948c08cf04b9571d62146597ae3.tar.gz
rust-17b53b964567b948c08cf04b9571d62146597ae3.zip
Remap more env constness for queries
-rw-r--r--compiler/rustc_middle/src/infer/canonical.rs8
-rw-r--r--compiler/rustc_middle/src/query/mod.rs11
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs4
-rw-r--r--compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs27
-rw-r--r--compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs8
5 files changed, 40 insertions, 18 deletions
diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs
index d764d45ba7e..14cff60475a 100644
--- a/compiler/rustc_middle/src/infer/canonical.rs
+++ b/compiler/rustc_middle/src/infer/canonical.rs
@@ -246,6 +246,14 @@ impl<'tcx, R> Canonical<'tcx, QueryResponse<'tcx, R>> {
     }
 }
 
+impl<'tcx, R> Canonical<'tcx, ty::ParamEnvAnd<'tcx, R>> {
+    #[inline]
+    pub fn without_const(mut self) -> Self {
+        self.value = self.value.without_const();
+        self
+    }
+}
+
 impl<'tcx, V> Canonical<'tcx, V> {
     /// Allows you to map the `value` of a canonical while keeping the
     /// same set of bound variables.
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 61cbb79602c..58f584d65d5 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -1655,6 +1655,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "normalizing `{:?}`", goal }
+        remap_env_constness
     }
 
     // FIXME: Implement `normalize_generic_arg_after_erasing_regions` and
@@ -1701,6 +1702,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "computing implied outlives bounds for `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
@@ -1711,6 +1713,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "computing dropck types for `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
@@ -1738,6 +1741,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "evaluating `type_op_ascribe_user_type` `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `Eq` type-op
@@ -1748,6 +1752,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "evaluating `type_op_eq` `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `Subtype` type-op
@@ -1758,6 +1763,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "evaluating `type_op_subtype` `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `ProvePredicate` type-op
@@ -1778,6 +1784,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "normalizing `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `Normalize` type-op
@@ -1788,6 +1795,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "normalizing `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `Normalize` type-op
@@ -1798,6 +1806,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "normalizing `{:?}`", goal }
+        remap_env_constness
     }
 
     /// Do not call this query directly: part of the `Normalize` type-op
@@ -1808,6 +1817,7 @@ rustc_queries! {
         NoSolution,
     > {
         desc { "normalizing `{:?}`", goal }
+        remap_env_constness
     }
 
     query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
@@ -1821,6 +1831,7 @@ rustc_queries! {
         goal: CanonicalTyGoal<'tcx>
     ) -> MethodAutoderefStepsResult<'tcx> {
         desc { "computing autoderef types for `{:?}`", goal }
+        remap_env_constness
     }
 
     query supported_target_features(_: CrateNum) -> FxHashMap<String, Option<Symbol>> {
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index a6d083101a0..8a768558668 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -1354,6 +1354,10 @@ impl<'tcx> ParamEnv<'tcx> {
         self
     }
 
+    pub fn remap_constness_with(&mut self, mut constness: ty::BoundConstness) {
+        *self = self.with_constness(constness.and(self.constness()))
+    }
+
     /// Returns a new parameter environment with the same clauses, but
     /// which "reveals" the true results of projections in all cases
     /// (even for associated types that are specializable). This is
diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
index 2c1f604b033..4874ba6f58c 100644
--- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
+++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs
@@ -67,27 +67,20 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
     ) -> Result<EvaluationResult, OverflowError> {
         let mut _orig_values = OriginalQueryValues::default();
 
-        let (param_env, predicate) = match obligation.predicate.kind().skip_binder() {
-            ty::PredicateKind::Trait(mut pred) => {
-                let orig_pred_constness = pred.constness;
-                let env_constness = pred.constness.and(obligation.param_env.constness());
-
-                let predicate = if orig_pred_constness != pred.constness {
-                    self.tcx.mk_predicate(
-                        obligation.predicate.kind().rebind(ty::PredicateKind::Trait(pred)),
-                    )
-                } else {
-                    obligation.predicate
-                };
-
-                (obligation.param_env.with_constness(env_constness), predicate)
+        let param_env = match obligation.predicate.kind().skip_binder() {
+            ty::PredicateKind::Trait(pred) => {
+                // we ignore the value set to it.
+                let mut _constness = pred.constness;
+                obligation
+                    .param_env
+                    .with_constness(_constness.and(obligation.param_env.constness()))
             }
             // constness has no effect on the given predicate.
-            _ => (obligation.param_env.without_const(), obligation.predicate),
+            _ => obligation.param_env.without_const(),
         };
 
-        let c_pred =
-            self.canonicalize_query_keep_static(param_env.and(predicate), &mut _orig_values);
+        let c_pred = self
+            .canonicalize_query_keep_static(param_env.and(obligation.predicate), &mut _orig_values);
         // Run canonical query. If overflow occurs, rerun from scratch but this time
         // in standard trait query mode so that overflow is handled appropriately
         // within `SelectionContext`.
diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs
index 02e9b4d0f0e..081308ac73e 100644
--- a/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs
+++ b/compiler/rustc_trait_selection/src/traits/query/type_op/prove_predicate.rs
@@ -30,8 +30,14 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
 
     fn perform_query(
         tcx: TyCtxt<'tcx>,
-        canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
+        mut canonicalized: Canonicalized<'tcx, ParamEnvAnd<'tcx, Self>>,
     ) -> Fallible<CanonicalizedQueryResponse<'tcx, ()>> {
+        match canonicalized.value.value.predicate.kind().skip_binder() {
+            ty::PredicateKind::Trait(pred) => {
+                canonicalized.value.param_env.remap_constness_with(pred.constness);
+            }
+            _ => canonicalized.value.param_env = canonicalized.value.param_env.without_const(),
+        }
         tcx.type_op_prove_predicate(canonicalized)
     }
 }