Skip to content

Commit 906bb8d

Browse files
committed
fix #62456
1 parent 3dbade6 commit 906bb8d

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
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+

0 commit comments

Comments
 (0)