Skip to content

Commit 49bf48a

Browse files
authored
Rollup merge of #81309 - lcnr:lazy-norm-err-msgh, r=nikomatsakis
always eagerly eval consts in Relate r? ```@nikomatsakis``` cc ```@varkor```
2 parents 5fe790e + 2beea2c commit 49bf48a

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

compiler/rustc_middle/src/ty/relate.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,14 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
421421
let t = relation.relate(a_t, b_t)?;
422422
match relation.relate(sz_a, sz_b) {
423423
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
424-
// FIXME(#72219) Implement improved diagnostics for mismatched array
425-
// length?
426-
Err(err) if relation.tcx().lazy_normalization() => Err(err),
427424
Err(err) => {
428425
// Check whether the lengths are both concrete/known values,
429426
// but are unequal, for better diagnostics.
427+
//
428+
// It might seem dubious to eagerly evaluate these constants here,
429+
// we however cannot end up with errors in `Relate` during both
430+
// `type_of` and `predicates_of`. This means that evaluating the
431+
// constants should not cause cycle errors here.
430432
let sz_a = sz_a.try_eval_usize(tcx, relation.param_env());
431433
let sz_b = sz_b.try_eval_usize(tcx, relation.param_env());
432434
match (sz_a, sz_b) {

src/test/ui/const-generics/const-argument-cross-crate-mismatch.full.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0308]: mismatched types
2-
--> $DIR/const-argument-cross-crate-mismatch.rs:7:67
2+
--> $DIR/const-argument-cross-crate-mismatch.rs:9:67
33
|
44
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
55
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
66

77
error[E0308]: mismatched types
8-
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
8+
--> $DIR/const-argument-cross-crate-mismatch.rs:11:65
99
|
1010
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
1111
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements

src/test/ui/const-generics/const-argument-cross-crate-mismatch.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0308]: mismatched types
2-
--> $DIR/const-argument-cross-crate-mismatch.rs:7:67
2+
--> $DIR/const-argument-cross-crate-mismatch.rs:9:67
33
|
44
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
55
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
66

77
error[E0308]: mismatched types
8-
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
8+
--> $DIR/const-argument-cross-crate-mismatch.rs:11:65
99
|
1010
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
1111
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements

src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// aux-build:const_generic_lib.rs
22
// revisions: full min
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(full, allow(incomplete_features))]
35

46
extern crate const_generic_lib;
57

0 commit comments

Comments
 (0)