Skip to content

Commit 6a72ba4

Browse files
committed
Logically seperate lazy norm from const_generics
1 parent 752d8a2 commit 6a72ba4

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/librustc_infer/infer/combine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
164164
(_, ty::ConstKind::Infer(InferConst::Var(vid))) => {
165165
return self.unify_const_variable(!a_is_expected, vid, a);
166166
}
167-
(ty::ConstKind::Unevaluated(..), _) if self.tcx.features().const_generics => {
167+
(ty::ConstKind::Unevaluated(..), _) if self.tcx.lazy_normalization() => {
168168
// FIXME(#59490): Need to remove the leak check to accomodate
169169
// escaping bound variables here.
170170
if !a.has_escaping_bound_vars() && !b.has_escaping_bound_vars() {
171171
relation.const_equate_obligation(a, b);
172172
}
173173
return Ok(b);
174174
}
175-
(_, ty::ConstKind::Unevaluated(..)) if self.tcx.features().const_generics => {
175+
(_, ty::ConstKind::Unevaluated(..)) if self.tcx.lazy_normalization() => {
176176
// FIXME(#59490): Need to remove the leak check to accomodate
177177
// escaping bound variables here.
178178
if !a.has_escaping_bound_vars() && !b.has_escaping_bound_vars() {
@@ -666,7 +666,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
666666
}
667667
}
668668
}
669-
ty::ConstKind::Unevaluated(..) if self.tcx().features().const_generics => Ok(c),
669+
ty::ConstKind::Unevaluated(..) if self.tcx().lazy_normalization() => Ok(c),
670670
_ => relate::super_relate_consts(self, c, c),
671671
}
672672
}

src/librustc_infer/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ where
988988
}
989989
}
990990
}
991-
ty::ConstKind::Unevaluated(..) if self.tcx().features().const_generics => Ok(a),
991+
ty::ConstKind::Unevaluated(..) if self.tcx().lazy_normalization() => Ok(a),
992992
_ => relate::super_relate_consts(self, a, a),
993993
}
994994
}

src/librustc_middle/ty/context.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,7 @@ impl<'tcx> TyCtxt<'tcx> {
13391339

13401340
/// What mode(s) of borrowck should we run? AST? MIR? both?
13411341
/// (Also considers the `#![feature(nll)]` setting.)
1342-
pub fn borrowck_mode(&self) -> BorrowckMode {
1342+
pub fn borrowck_mode(self) -> BorrowckMode {
13431343
// Here are the main constraints we need to deal with:
13441344
//
13451345
// 1. An opts.borrowck_mode of `BorrowckMode::Migrate` is
@@ -1369,6 +1369,13 @@ impl<'tcx> TyCtxt<'tcx> {
13691369
self.sess.opts.borrowck_mode
13701370
}
13711371

1372+
/// If `true`, we should use lazy normalization for constants, otherwise
1373+
/// we still evaluate them eagerly.
1374+
#[inline]
1375+
pub fn lazy_normalization(self) -> bool {
1376+
self.features().const_generics
1377+
}
1378+
13721379
#[inline]
13731380
pub fn local_crate_exports_generics(self) -> bool {
13741381
debug_assert!(self.sess.opts.share_generics());

src/librustc_middle/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
433433
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
434434
// FIXME(#72219) Implement improved diagnostics for mismatched array
435435
// length?
436-
Err(err) if relation.tcx().features().const_generics => Err(err),
436+
Err(err) if relation.tcx().lazy_normalization() => Err(err),
437437
Err(err) => {
438438
// Check whether the lengths are both concrete/known values,
439439
// but are unequal, for better diagnostics.

src/librustc_trait_selection/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
388388
}
389389

390390
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
391-
if self.selcx.tcx().features().const_generics {
391+
if self.selcx.tcx().lazy_normalization() {
392392
constant
393393
} else {
394394
let constant = constant.super_fold_with(self);

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
11731173
// HACK(eddyb) this provides the correct generics when
11741174
// `feature(const_generics)` is enabled, so that const expressions
11751175
// used with const generics, e.g. `Foo<{N+1}>`, can work at all.
1176-
if tcx.features().const_generics {
1176+
if tcx.lazy_normalization() {
11771177
Some(parent_def_id.to_def_id())
11781178
} else {
11791179
let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id));

0 commit comments

Comments
 (0)