Skip to content

Commit 40887eb

Browse files
skinnyBatmati865
authored andcommitted
Fix tests and lazy normalization gating. Also adds -Z lazy-normalization to some tests that require
lazy normalization to pass.
1 parent 70ec3b5 commit 40887eb

File tree

13 files changed

+49
-15
lines changed

13 files changed

+49
-15
lines changed

src/librustc_infer/infer/combine.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +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.sess.opts.debugging_opts.lazy_normalization => {
167+
(ty::ConstKind::Unevaluated(..), _)
168+
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
169+
{
168170
relation.const_equate_obligation(a, b);
169171
return Ok(b);
170172
}
171-
(_, ty::ConstKind::Unevaluated(..)) if self.tcx.sess.opts.debugging_opts.lazy_normalization => {
173+
(_, ty::ConstKind::Unevaluated(..))
174+
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
175+
{
172176
relation.const_equate_obligation(a, b);
173177
return Ok(a);
174178
}
@@ -656,7 +660,11 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
656660
}
657661
}
658662
}
659-
ty::ConstKind::Unevaluated(..) if self.tcx().sess.opts.debugging_opts.lazy_normalization => Ok(c),
663+
ty::ConstKind::Unevaluated(..)
664+
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
665+
{
666+
Ok(c)
667+
}
660668
_ => relate::super_relate_consts(self, c, c),
661669
}
662670
}

src/librustc_infer/infer/nll_relate/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,11 @@ where
997997
}
998998
}
999999
}
1000-
ty::ConstKind::Unevaluated(..) if self.tcx().sess.opts.debugging_opts.lazy_normalization=> Ok(a),
1000+
ty::ConstKind::Unevaluated(..)
1001+
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
1002+
{
1003+
Ok(a)
1004+
}
10011005
_ => relate::super_relate_consts(self, a, a),
10021006
}
10031007
}

src/librustc_trait_selection/traits/project.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
385385
_ => ty,
386386
}
387387
}
388+
389+
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 {
391+
constant
392+
} else {
393+
constant.eval(self.selcx.tcx(), self.param_env)
394+
}
395+
}
388396
}
389397

390398
/// The guts of `normalize`: normalize a specific projection like `<T

src/librustc_trait_selection/traits/query/normalize.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,8 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
189189
_ => ty,
190190
}
191191
}
192+
193+
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
194+
constant.eval(self.infcx.tcx, self.param_env)
195+
}
192196
}

src/librustc_typeck/collect.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,12 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
11811181
Some(tcx.hir().local_def_id(parent_id))
11821182
}
11831183
Node::AnonConst(_) => {
1184-
if tcx.sess.opts.debugging_opts.lazy_normalization {
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 {
11851190
let parent_id = tcx.hir().get_parent_item(hir_id);
11861191
Some(tcx.hir().local_def_id(parent_id))
11871192
} else {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// check-pass
2+
// compile-flags: -Z lazy-normalization
23

34
#![feature(const_generics)]
45
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/issue-61935.rs:3:12
2+
--> $DIR/issue-61935.rs:4:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// check-pass
2+
// compile-flags: -Z lazy-normalization
23

34
#![feature(const_generics)]
45
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/issue-67185-1.rs:3:12
2+
--> $DIR/issue-67185-1.rs:4:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Z lazy-normalization
2+
13
#![feature(const_generics)]
24
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
35

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

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

99
error[E0308]: mismatched types
10-
--> $DIR/issue-67185-2.rs:15:1
10+
--> $DIR/issue-67185-2.rs:17:1
1111
|
1212
LL | / trait Foo
1313
LL | | where
@@ -21,7 +21,7 @@ LL | | }
2121
found type `4usize`
2222

2323
error[E0308]: mismatched types
24-
--> $DIR/issue-67185-2.rs:24:6
24+
--> $DIR/issue-67185-2.rs:26:6
2525
|
2626
LL | impl Foo for FooImpl {}
2727
| ^^^ expected `3usize`, found `4usize`
@@ -30,7 +30,7 @@ LL | impl Foo for FooImpl {}
3030
found type `4usize`
3131

3232
error[E0308]: mismatched types
33-
--> $DIR/issue-67185-2.rs:24:6
33+
--> $DIR/issue-67185-2.rs:26:6
3434
|
3535
LL | impl Foo for FooImpl {}
3636
| ^^^ expected `2usize`, found `3usize`
@@ -39,7 +39,7 @@ LL | impl Foo for FooImpl {}
3939
found type `3usize`
4040

4141
error[E0308]: mismatched types
42-
--> $DIR/issue-67185-2.rs:28:1
42+
--> $DIR/issue-67185-2.rs:30:1
4343
|
4444
LL | fn f(_: impl Foo) {}
4545
| ^^^^^^^^^^^^^^^^^^^^ expected `2usize`, found `3usize`
@@ -48,7 +48,7 @@ LL | fn f(_: impl Foo) {}
4848
found type `3usize`
4949

5050
error[E0308]: mismatched types
51-
--> $DIR/issue-67185-2.rs:28:1
51+
--> $DIR/issue-67185-2.rs:30:1
5252
|
5353
LL | fn f(_: impl Foo) {}
5454
| ^^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `4usize`

src/test/ui/const-generics/trait-const-args.rs

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

34
#![feature(const_generics)]
45
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
@@ -26,4 +27,4 @@ fn main() {
2627
// FIXME this causes a stack overflow in rustc
2728
// foo_where(Const);
2829
foo_where(Const::<3>);
29-
}
30+
}

src/test/ui/const-generics/trait-const-args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/trait-const-args.rs:3:12
2+
--> $DIR/trait-const-args.rs:4:12
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)