]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #63153 - varkor:remove-resolve_const_var, r=cramertj
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 2 Aug 2019 10:14:17 +0000 (12:14 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2019 10:14:17 +0000 (12:14 +0200)
Remove redundant method with const variable resolution

I've also removed a `bug!()` in const value relation code and replaced it with a `FIXME`. Now `ConstValue::Slice` and `ConstValue::ByRef` will simply fail to unify rather than ICEing, which seems more user-friendly for testers.

src/librustc/infer/canonical/canonicalizer.rs
src/librustc/infer/mod.rs
src/librustc/ty/relate.rs

index 3d57a89493e1ea7aaf0c09d7e186c6e82ac647fb..db724875b8aa390b16aaf4b3fe7ef722a1818054 100644 (file)
@@ -693,7 +693,7 @@ fn canonicalize_const_var(
         const_var: &'tcx ty::Const<'tcx>
     ) -> &'tcx ty::Const<'tcx> {
         let infcx = self.infcx.expect("encountered const-var without infcx");
-        let bound_to = infcx.resolve_const_var(const_var);
+        let bound_to = infcx.shallow_resolve(const_var);
         if bound_to != const_var {
             self.fold_const(bound_to)
         } else {
index 663acd67dcd839b147f5e4b3a7fc263a70e0a0af..e1d77a97c116068fd0c26828d486c03e40b47dc9 100644 (file)
@@ -1351,23 +1351,6 @@ pub fn probe_const_var(
         }
     }
 
-    pub fn resolve_const_var(
-        &self,
-        ct: &'tcx ty::Const<'tcx>
-    ) -> &'tcx ty::Const<'tcx> {
-        if let ty::Const { val: ConstValue::Infer(InferConst::Var(v)), .. } = ct {
-            self.const_unification_table
-                .borrow_mut()
-                .probe_value(*v)
-                .val
-                .known()
-                .map(|c| self.resolve_const_var(c))
-                .unwrap_or(ct)
-        } else {
-            ct
-        }
-    }
-
     pub fn fully_resolve<T: TypeFoldable<'tcx>>(&self, value: &T) -> FixupResult<'tcx, T> {
         /*!
          * Attempts to resolve all type/region/const variables in
@@ -1586,7 +1569,7 @@ pub fn inlined_shallow_resolve(&mut self, typ: Ty<'tcx>) -> Ty<'tcx> {
                 // it can be resolved to an int/float variable, which
                 // can then be recursively resolved, hence the
                 // recursion. Note though that we prevent type
-                // variables from unifyxing to other type variables
+                // variables from unifying to other type variables
                 // directly (though they may be embedded
                 // structurally), and we prevent cycles in any case,
                 // so this recursion should always be of very limited
@@ -1626,17 +1609,15 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
     }
 
     fn fold_const(&mut self, ct: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
-        match ct {
-            ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } => {
+        if let ty::Const { val: ConstValue::Infer(InferConst::Var(vid)), .. } = ct {
                 self.infcx.const_unification_table
                     .borrow_mut()
                     .probe_value(*vid)
                     .val
                     .known()
-                    .map(|c| self.fold_const(c))
                     .unwrap_or(ct)
-            }
-            _ => ct,
+        } else {
+            ct
         }
     }
 }
index a6bfc2dee613b0ce04bb8e997f1cd4550cd390ff..ca54f63b83afe0c2acc30e6f38162a9cbf7dedb8 100644 (file)
@@ -594,13 +594,11 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
                 ty: a.ty,
             }))
         }
-        (ConstValue::ByRef { .. }, _) => {
-            bug!(
-                "non-Scalar ConstValue encountered in super_relate_consts {:?} {:?}",
-                a,
-                b,
-            );
-        }
+
+        // FIXME(const_generics): we should either handle `Scalar::Ptr` or add a comment
+        // saying that we're not handling it intentionally.
+
+        // FIXME(const_generics): handle `ConstValue::ByRef` and `ConstValue::Slice`.
 
         // FIXME(const_generics): this is wrong, as it is a projection
         (ConstValue::Unevaluated(a_def_id, a_substs),