about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2025-05-23 12:41:18 +0000
committerMichael Goulet <michael@errs.io>2025-06-08 22:41:23 -0400
commit87141e37f32b31de0cc1e9559319ea408c794fb1 (patch)
tree7afc76d279afa8f094facbe3cd99ad5566166dc5
parentc31cccb7b5cc098b1a8c1794ed38d7fdbec0ccb0 (diff)
downloadrust-87141e37f32b31de0cc1e9559319ea408c794fb1.tar.gz
rust-87141e37f32b31de0cc1e9559319ea408c794fb1.zip
move `canonicalize_param_env` into sub-fn
-rw-r--r--compiler/rustc_next_trait_solver/src/canonicalizer.rs55
1 files changed, 30 insertions, 25 deletions
diff --git a/compiler/rustc_next_trait_solver/src/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonicalizer.rs
index a87ae5284b1..4b48ae7c417 100644
--- a/compiler/rustc_next_trait_solver/src/canonicalizer.rs
+++ b/compiler/rustc_next_trait_solver/src/canonicalizer.rs
@@ -100,20 +100,15 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
         Canonical { max_universe, variables, value }
     }
 
-    /// When canonicalizing query inputs, we keep `'static` in the `param_env`
-    /// but erase it everywhere else. We generally don't want to depend on region
-    /// identity, so while it should not matter whether `'static` is kept in the
-    /// value or opaque type storage as well, this prevents us from accidentally
-    /// relying on it in the future.
-    ///
-    /// We want to keep the option of canonicalizing `'static` to an existential
-    /// variable in the future by changing the way we detect global where-bounds.
-    pub fn canonicalize_input<P: TypeFoldable<I>>(
+    fn canonicalize_param_env(
         delegate: &'a D,
         variables: &'a mut Vec<I::GenericArg>,
-        input: QueryInput<I, P>,
-    ) -> ty::Canonical<I, QueryInput<I, P>> {
-        // First canonicalize the `param_env` while keeping `'static`
+        param_env: I::ParamEnv,
+    ) -> (I::ParamEnv, HashMap<I::GenericArg, usize>, Vec<CanonicalVarKind<I>>) {
+        if !param_env.has_type_flags(NEEDS_CANONICAL) {
+            return (param_env, Default::default(), Vec::new());
+        }
+
         let mut env_canonicalizer = Canonicalizer {
             delegate,
             canonicalize_mode: CanonicalizeMode::Input { keep_static: true },
@@ -125,26 +120,36 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
 
             cache: Default::default(),
         };
-
-        let param_env = input.goal.param_env;
-        let param_env = if param_env.has_type_flags(NEEDS_CANONICAL) {
-            param_env.fold_with(&mut env_canonicalizer)
-        } else {
-            param_env
-        };
-
+        let param_env = param_env.fold_with(&mut env_canonicalizer);
         debug_assert_eq!(env_canonicalizer.binder_index, ty::INNERMOST);
+        (param_env, env_canonicalizer.variable_lookup_table, env_canonicalizer.var_kinds)
+    }
+
+    /// When canonicalizing query inputs, we keep `'static` in the `param_env`
+    /// but erase it everywhere else. We generally don't want to depend on region
+    /// identity, so while it should not matter whether `'static` is kept in the
+    /// value or opaque type storage as well, this prevents us from accidentally
+    /// relying on it in the future.
+    ///
+    /// We want to keep the option of canonicalizing `'static` to an existential
+    /// variable in the future by changing the way we detect global where-bounds.
+    pub fn canonicalize_input<P: TypeFoldable<I>>(
+        delegate: &'a D,
+        variables: &'a mut Vec<I::GenericArg>,
+        input: QueryInput<I, P>,
+    ) -> ty::Canonical<I, QueryInput<I, P>> {
+        // First canonicalize the `param_env` while keeping `'static`
+        let (param_env, variable_lookup_table, var_kinds) =
+            Canonicalizer::canonicalize_param_env(delegate, variables, input.goal.param_env);
         // Then canonicalize the rest of the input without keeping `'static`
         // while *mostly* reusing the canonicalizer from above.
         let mut rest_canonicalizer = Canonicalizer {
             delegate,
             canonicalize_mode: CanonicalizeMode::Input { keep_static: false },
 
-            variables: env_canonicalizer.variables,
-            // We're able to reuse the `variable_lookup_table` as whether or not
-            // it already contains an entry for `'static` does not matter.
-            variable_lookup_table: env_canonicalizer.variable_lookup_table,
-            var_kinds: env_canonicalizer.var_kinds,
+            variables,
+            variable_lookup_table,
+            var_kinds,
             binder_index: ty::INNERMOST,
 
             // We do not reuse the cache as it may contain entries whose canonicalized