Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #62456 #69859

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::type_error_struct;
use crate::util::common::ErrorReported;

use rustc::middle::lang_items;
use rustc::mir::interpret::ErrorHandled;
use rustc::ty;
use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
use rustc::ty::Ty;
Expand Down Expand Up @@ -1039,11 +1040,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

if element_ty.references_error() {
tcx.types.err
} else if let Ok(count) = count {
tcx.mk_ty(ty::Array(t, count))
} else {
tcx.types.err
return tcx.types.err;
}
match count {
Ok(count) => tcx.mk_ty(ty::Array(t, count)),
Err(ErrorHandled::TooGeneric) => {
self.tcx.sess.span_err(
tcx.def_span(count_def_id),
"array lengths can't depend on generic parameters",
);
tcx.types.err
}
Err(ErrorHandled::Reported) => tcx.types.err,
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/const-generics/issues/issue-62456.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(const_generics)]
contrun marked this conversation as resolved.
Show resolved Hide resolved
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

fn foo<const N: usize>() {
let _ = [0u64; N + 1];
//~^ ERROR array lengths can't depend on generic parameters
}

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/const-generics/issues/issue-62456.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-62456.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: array lengths can't depend on generic parameters
--> $DIR/issue-62456.rs:5:20
|
LL | let _ = [0u64; N + 1];
| ^^^^^

error: aborting due to previous error

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

fn main() {
let _ = [0; B::VALUE];
//~^ ERROR array lengths can't depend on generic parameters
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ LL | type MyA: TraitA;
LL | impl TraitB for B {
| ^^^^^^^^^^^^^^^^^ missing `MyA` in implementation

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

error: aborting due to 3 previous errors

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