]> git.lizzy.rs Git - rust.git/commitdiff
Logically seperate lazy norm from `const_generics`
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Sun, 17 May 2020 08:36:56 +0000 (10:36 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Sun, 17 May 2020 09:06:35 +0000 (11:06 +0200)
src/librustc_infer/infer/combine.rs
src/librustc_infer/infer/nll_relate/mod.rs
src/librustc_middle/ty/context.rs
src/librustc_middle/ty/relate.rs
src/librustc_trait_selection/traits/project.rs
src/librustc_typeck/collect.rs

index e3e8e88993ea7df6fea5057542400c7f927ace27..3467457b44997a0d21a8440684f899b86592b00e 100644 (file)
@@ -164,7 +164,7 @@ pub fn super_combine_consts<R>(
             (_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
                 return self.unify_const_variable(!a_is_expected, vid, a);
             }
-            (ty::ConstKind::Unevaluated(..), _) if self.tcx.features().const_generics => {
+            (ty::ConstKind::Unevaluated(..), _) if self.tcx.lazy_normalization() => {
                 // FIXME(#59490): Need to remove the leak check to accomodate
                 // escaping bound variables here.
                 if !a.has_escaping_bound_vars() && !b.has_escaping_bound_vars() {
@@ -172,7 +172,7 @@ pub fn super_combine_consts<R>(
                 }
                 return Ok(b);
             }
-            (_, ty::ConstKind::Unevaluated(..)) if self.tcx.features().const_generics => {
+            (_, ty::ConstKind::Unevaluated(..)) if self.tcx.lazy_normalization() => {
                 // FIXME(#59490): Need to remove the leak check to accomodate
                 // escaping bound variables here.
                 if !a.has_escaping_bound_vars() && !b.has_escaping_bound_vars() {
@@ -666,7 +666,7 @@ fn consts(
                     }
                 }
             }
-            ty::ConstKind::Unevaluated(..) if self.tcx().features().const_generics => Ok(c),
+            ty::ConstKind::Unevaluated(..) if self.tcx().lazy_normalization() => Ok(c),
             _ => relate::super_relate_consts(self, c, c),
         }
     }
index e5687db4ff13fceae950b00e3c6b79f8e3f6ba09..8de892510060828e12c6ddc238a8650794178660 100644 (file)
@@ -988,7 +988,7 @@ fn consts(
                     }
                 }
             }
-            ty::ConstKind::Unevaluated(..) if self.tcx().features().const_generics => Ok(a),
+            ty::ConstKind::Unevaluated(..) if self.tcx().lazy_normalization() => Ok(a),
             _ => relate::super_relate_consts(self, a, a),
         }
     }
index 7feb080d4b8d421d844090ae8eb8e8f754e727b0..da413f19eff234e5d1326560e391f33d85a1f34d 100644 (file)
@@ -1339,7 +1339,7 @@ pub fn migrate_borrowck(self) -> bool {
 
     /// What mode(s) of borrowck should we run? AST? MIR? both?
     /// (Also considers the `#![feature(nll)]` setting.)
-    pub fn borrowck_mode(&self) -> BorrowckMode {
+    pub fn borrowck_mode(self) -> BorrowckMode {
         // Here are the main constraints we need to deal with:
         //
         // 1. An opts.borrowck_mode of `BorrowckMode::Migrate` is
@@ -1369,6 +1369,13 @@ pub fn borrowck_mode(&self) -> BorrowckMode {
         self.sess.opts.borrowck_mode
     }
 
+    /// If `true`, we should use lazy normalization for constants, otherwise
+    /// we still evaluate them eagerly.
+    #[inline]
+    pub fn lazy_normalization(self) -> bool {
+        self.features().const_generics
+    }
+
     #[inline]
     pub fn local_crate_exports_generics(self) -> bool {
         debug_assert!(self.sess.opts.share_generics());
index 0ae62b0e813aff42580f266964a517b1887f7457..594ffbcd83613ef888bff691ca8f74e9c04008ea 100644 (file)
@@ -433,7 +433,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
                 Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
                 // FIXME(#72219) Implement improved diagnostics for mismatched array
                 // length?
-                Err(err) if relation.tcx().features().const_generics => Err(err),
+                Err(err) if relation.tcx().lazy_normalization() => Err(err),
                 Err(err) => {
                     // Check whether the lengths are both concrete/known values,
                     // but are unequal, for better diagnostics.
index 983e11622f9d56322b4d08487561a1c610efc6e6..c4cb72fa08c08c1c4806c7743919c4282b341fd6 100644 (file)
@@ -388,7 +388,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
     }
 
     fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
-        if self.selcx.tcx().features().const_generics {
+        if self.selcx.tcx().lazy_normalization() {
             constant
         } else {
             let constant = constant.super_fold_with(self);
index 80740651230defc254c8689ab3ffcd9fc3209a30..7cfb89f3ff048eeb29d6c744ea6064663ecc44a8 100644 (file)
@@ -1173,7 +1173,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
             // HACK(eddyb) this provides the correct generics when
             // `feature(const_generics)` is enabled, so that const expressions
             // used with const generics, e.g. `Foo<{N+1}>`, can work at all.
-            if tcx.features().const_generics {
+            if tcx.lazy_normalization() {
                 Some(parent_def_id.to_def_id())
             } else {
                 let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));