Skip to content

Commit 905e64b

Browse files
skinnyBatmati865
authored andcommitted
Added lazy_normalization_consts feature, and removed the -Z flag.
1 parent 40887eb commit 905e64b

28 files changed

+171
-65
lines changed

src/librustc_feature/active.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ declare_features! (
558558

559559
/// Allow negative trait implementations.
560560
(active, negative_impls, "1.44.0", Some(68318), None),
561+
562+
/// Lazily evaluate constants. Which allows constants to depend on type parameters.
563+
(active, lazy_normalization_consts, "1.44.0", Some(60471), None),
561564

562565
// -------------------------------------------------------------------------
563566
// feature-group-end: actual feature gates
@@ -575,4 +578,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
575578
sym::raw_dylib,
576579
sym::const_trait_impl,
577580
sym::const_trait_bound_opt_out,
581+
sym::lazy_normalization_consts,
578582
];

src/librustc_infer/infer/combine.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
165165
return self.unify_const_variable(!a_is_expected, vid, a);
166166
}
167167
(ty::ConstKind::Unevaluated(..), _)
168-
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
168+
if self.tcx.features().lazy_normalization_consts =>
169169
{
170170
relation.const_equate_obligation(a, b);
171171
return Ok(b);
172172
}
173173
(_, ty::ConstKind::Unevaluated(..))
174-
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
174+
if self.tcx.features().lazy_normalization_consts =>
175175
{
176176
relation.const_equate_obligation(a, b);
177177
return Ok(a);
@@ -660,9 +660,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
660660
}
661661
}
662662
}
663-
ty::ConstKind::Unevaluated(..)
664-
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
665-
{
663+
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
666664
Ok(c)
667665
}
668666
_ => relate::super_relate_consts(self, c, c),
@@ -671,7 +669,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
671669
}
672670

673671
pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
674-
/// Register am obligation that both constants must be equal to each other.
672+
/// Register an obligation that both constants must be equal to each other.
675673
///
676674
/// If they aren't equal then the relation doesn't hold.
677675
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>);

src/librustc_infer/infer/equate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::combine::{CombineFields, RelationDir, ConstEquateRelation};
1+
use super::combine::{CombineFields, ConstEquateRelation, RelationDir};
22
use super::Subtype;
33

44
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};

src/librustc_infer/infer/nll_relate/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,7 @@ where
997997
}
998998
}
999999
}
1000-
ty::ConstKind::Unevaluated(..)
1001-
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
1002-
{
1000+
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
10031001
Ok(a)
10041002
}
10051003
_ => relate::super_relate_consts(self, a, a),

src/librustc_middle/ty/relate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
431431
let t = relation.relate(&a_t, &b_t)?;
432432
match relation.relate(&sz_a, &sz_b) {
433433
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
434-
// FIXME(lazy-normalization) Implement improved diagnostics for mismatched array
434+
// FIXME(lazy_normalization_consts) Implement improved diagnostics for mismatched array
435435
// length?
436-
Err(err) if relation.tcx().sess.opts.debugging_opts.lazy_normalization => Err(err),
436+
Err(err) if relation.tcx().features().lazy_normalization_consts => Err(err),
437437
Err(err) => {
438438
// Check whether the lengths are both concrete/known values,
439439
// but are unequal, for better diagnostics.

src/librustc_session/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,4 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
982982
"Link native libraries in the linker invocation."),
983983
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
984984
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),
985-
lazy_normalization: bool = (false, parse_bool, [UNTRACKED],
986-
"lazily evaluate constants (experimental)"),
987985
}

src/librustc_span/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ symbols! {
408408
label_break_value,
409409
lang,
410410
lang_items,
411+
lazy_normalization_consts,
411412
let_chains,
412413
lhs,
413414
lib,

src/librustc_trait_selection/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
387387
}
388388

389389
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
390-
if self.selcx.tcx().sess.opts.debugging_opts.lazy_normalization {
390+
if self.selcx.tcx().features().lazy_normalization_consts {
391391
constant
392392
} else {
393393
constant.eval(self.selcx.tcx(), self.param_env)

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,12 +1181,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
11811181
Some(tcx.hir().local_def_id(parent_id))
11821182
}
11831183
Node::AnonConst(_) => {
1184-
// HACK(skinny121) Provide correct generics if `feature(const_generics)` is enabled, in
1185-
// addition to when the '-Z lazy-normalization' flag is used, so that trait
1186-
// implementations that have const generic parameters within the standard library still
1187-
// work. The feature check won't be necessary when lazy normalization is enabled by
1188-
// default.
1189-
if tcx.sess.opts.debugging_opts.lazy_normalization || tcx.features().const_generics {
1184+
if tcx.features().lazy_normalization_consts {
11901185
let parent_id = tcx.hir().get_parent_item(hir_id);
11911186
Some(tcx.hir().local_def_id(parent_id))
11921187
} else {

src/test/ui/const-generics/array-size-in-generic-struct-param.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(const_generics)]
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
35

46
#[allow(dead_code)]
57
struct ArithArrayLen<const N: usize>([u32; 0 + N]);

src/test/ui/const-generics/array-size-in-generic-struct-param.stderr

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/array-size-in-generic-struct-param.rs:3:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
915
error: constant expression depends on a generic parameter
10-
--> $DIR/array-size-in-generic-struct-param.rs:5:38
16+
--> $DIR/array-size-in-generic-struct-param.rs:7:38
1117
|
1218
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
1319
| ^^^^^^^^^^^^
1420
|
1521
= note: this may fail depending on what value the parameter takes
1622

1723
error: constant expression depends on a generic parameter
18-
--> $DIR/array-size-in-generic-struct-param.rs:14:5
24+
--> $DIR/array-size-in-generic-struct-param.rs:16:5
1925
|
2026
LL | arr: [u8; CFG.arr_size],
2127
| ^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/const-generics/issues/issue-61336-1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(const_generics)]
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
35

46
// build-pass
57

src/test/ui/const-generics/issues/issue-61336-1.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-61336-1.rs:3:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/const-generics/issues/issue-61336-2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(const_generics)]
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
35

46
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
57
[x; { N }]

src/test/ui/const-generics/issues/issue-61336-2.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-61336-2.rs:3:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
915
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
1016
--> $DIR/issue-61336-2.rs:9:5
1117
|

src/test/ui/const-generics/issues/issue-61336.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(const_generics)]
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
35

46
fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
57
[x; N]

src/test/ui/const-generics/issues/issue-61336.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-61336.rs:3:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
915
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
1016
--> $DIR/issue-61336.rs:9:5
1117
|

src/test/ui/const-generics/issues/issue-61747.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#![feature(const_generics)]
44
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
#![feature(lazy_normalization_consts)]
6+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
57

68
struct Const<const N: usize>;
79

src/test/ui/const-generics/issues/issue-61747.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ LL | #![feature(const_generics)]
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-61747.rs:5:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+

src/test/ui/const-generics/issues/issue-61935.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// check-pass
2-
// compile-flags: -Z lazy-normalization
32

43
#![feature(const_generics)]
54
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
#![feature(lazy_normalization_consts)]
6+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
67

78
trait Foo {}
89

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/issue-61935.rs:4:12
2+
--> $DIR/issue-61935.rs:3:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-61935.rs:5:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+

src/test/ui/const-generics/issues/issue-66205.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#![allow(incomplete_features, dead_code, unconditional_recursion)]
44
#![feature(const_generics)]
5+
#![feature(lazy_normalization_consts)]
56

67
fn fact<const N: usize>() {
78
fact::<{ N - 1 }>();

src/test/ui/const-generics/issues/issue-67185-1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// check-pass
2-
// compile-flags: -Z lazy-normalization
32

43
#![feature(const_generics)]
54
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
5+
#![feature(lazy_normalization_consts)]
6+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
67

78
trait Baz {
89
type Quaks;
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/issue-67185-1.rs:4:12
2+
--> $DIR/issue-67185-1.rs:3:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(incomplete_features)]` on by default
88

9+
warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
10+
--> $DIR/issue-67185-1.rs:5:12
11+
|
12+
LL | #![feature(lazy_normalization_consts)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+

src/test/ui/const-generics/issues/issue-67185-2.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// compile-flags: -Z lazy-normalization
2-
31
#![feature(const_generics)]
42
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
55

66
trait Baz {
77
type Quaks;
@@ -14,7 +14,8 @@ trait Bar {}
1414
impl Bar for [u16; 4] {}
1515
impl Bar for [[u16; 3]; 3] {}
1616

17-
trait Foo //~ ERROR mismatched types
17+
trait Foo //~ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
18+
//~^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]
1819
where
1920
[<u8 as Baz>::Quaks; 2]: Bar,
2021
<u8 as Baz>::Quaks: Bar,
@@ -24,12 +25,12 @@ trait Foo //~ ERROR mismatched types
2425
struct FooImpl;
2526

2627
impl Foo for FooImpl {}
27-
//~^ ERROR mismatched types
28-
//~^^ ERROR mismatched types
28+
//~^ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
29+
//~^^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]
2930

3031
fn f(_: impl Foo) {}
31-
//~^ ERROR mismatched types
32-
//~^^ ERROR mismatched types
32+
//~^ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
33+
//~^^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]
3334

3435
fn main() {
3536
f(FooImpl)

0 commit comments

Comments
 (0)