Skip to content

Commit 62e3dae

Browse files
authored
Rollup merge of #69859 - contrun:fix-62456, r=matthewjasper
fix #62456 closes #62456
2 parents dfbbd5d + 0a0c850 commit 62e3dae

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

src/librustc_typeck/check/expr.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::type_error_struct;
1818
use crate::util::common::ErrorReported;
1919

2020
use rustc::middle::lang_items;
21+
use rustc::mir::interpret::ErrorHandled;
2122
use rustc::ty;
2223
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
2324
use rustc::ty::Ty;
@@ -1039,11 +1040,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10391040
};
10401041

10411042
if element_ty.references_error() {
1042-
tcx.types.err
1043-
} else if let Ok(count) = count {
1044-
tcx.mk_ty(ty::Array(t, count))
1045-
} else {
1046-
tcx.types.err
1043+
return tcx.types.err;
1044+
}
1045+
match count {
1046+
Ok(count) => tcx.mk_ty(ty::Array(t, count)),
1047+
Err(ErrorHandled::TooGeneric) => {
1048+
self.tcx.sess.span_err(
1049+
tcx.def_span(count_def_id),
1050+
"array lengths can't depend on generic parameters",
1051+
);
1052+
tcx.types.err
1053+
}
1054+
Err(ErrorHandled::Reported) => tcx.types.err,
10471055
}
10481056
}
10491057

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
fn foo<const N: usize>() {
5+
let _ = [0u64; N + 1];
6+
//~^ ERROR array lengths can't depend on generic parameters
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/issue-62456.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error: array lengths can't depend on generic parameters
10+
--> $DIR/issue-62456.rs:5:20
11+
|
12+
LL | let _ = [0u64; N + 1];
13+
| ^^^^^
14+
15+
error: aborting due to previous error
16+

src/test/ui/issues/issue-69602-type-err-during-codegen-ice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ impl TraitB for B { //~ ERROR not all trait items implemented, missing: `MyA`
1919

2020
fn main() {
2121
let _ = [0; B::VALUE];
22+
//~^ ERROR array lengths can't depend on generic parameters
2223
}

src/test/ui/issues/issue-69602-type-err-during-codegen-ice.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ LL | type MyA: TraitA;
1313
LL | impl TraitB for B {
1414
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation
1515

16-
error: aborting due to 2 previous errors
16+
error: array lengths can't depend on generic parameters
17+
--> $DIR/issue-69602-type-err-during-codegen-ice.rs:21:17
18+
|
19+
LL | let _ = [0; B::VALUE];
20+
| ^^^^^^^^
21+
22+
error: aborting due to 3 previous errors
1723

1824
Some errors have detailed explanations: E0046, E0437.
1925
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)