From 6a72ba4c33472060a96b17378be58d45570eb4a8 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Sun, 17 May 2020 10:36:56 +0200 Subject: [PATCH] Logically seperate lazy norm from `const_generics` --- src/librustc_infer/infer/combine.rs | 6 +++--- src/librustc_infer/infer/nll_relate/mod.rs | 2 +- src/librustc_middle/ty/context.rs | 9 ++++++++- src/librustc_middle/ty/relate.rs | 2 +- src/librustc_trait_selection/traits/project.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/librustc_infer/infer/combine.rs b/src/librustc_infer/infer/combine.rs index e3e8e88993e..3467457b449 100644 --- a/src/librustc_infer/infer/combine.rs +++ b/src/librustc_infer/infer/combine.rs @@ -164,7 +164,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { (_, 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 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> { } 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 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { } } } - 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), } } diff --git a/src/librustc_infer/infer/nll_relate/mod.rs b/src/librustc_infer/infer/nll_relate/mod.rs index e5687db4ff1..8de89251006 100644 --- a/src/librustc_infer/infer/nll_relate/mod.rs +++ b/src/librustc_infer/infer/nll_relate/mod.rs @@ -988,7 +988,7 @@ where } } } - 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), } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 7feb080d4b8..da413f19eff 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -1339,7 +1339,7 @@ impl<'tcx> TyCtxt<'tcx> { /// 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 @@ impl<'tcx> TyCtxt<'tcx> { 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()); diff --git a/src/librustc_middle/ty/relate.rs b/src/librustc_middle/ty/relate.rs index 0ae62b0e813..594ffbcd836 100644 --- a/src/librustc_middle/ty/relate.rs +++ b/src/librustc_middle/ty/relate.rs @@ -433,7 +433,7 @@ pub fn super_relate_tys>( 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. diff --git a/src/librustc_trait_selection/traits/project.rs b/src/librustc_trait_selection/traits/project.rs index 983e11622f9..c4cb72fa08c 100644 --- a/src/librustc_trait_selection/traits/project.rs +++ b/src/librustc_trait_selection/traits/project.rs @@ -388,7 +388,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, '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); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 80740651230..7cfb89f3ff0 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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));