about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYI <uuuuuu@protonmail.com>2020-03-10 01:51:08 +0800
committerYI <uuuuuu@protonmail.com>2020-03-10 09:30:24 +0800
commit906bb8d0e8bbd026fc933fe3f5b829be5e4ac69e (patch)
treec444760e076eb79ef74f2aed82afea77669aec3c /src
parent3dbade652ed8ebac70f903e01f51cd92c4e4302c (diff)
downloadrust-906bb8d0e8bbd026fc933fe3f5b829be5e4ac69e.tar.gz
rust-906bb8d0e8bbd026fc933fe3f5b829be5e4ac69e.zip
fix #62456
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/expr.rs18
-rw-r--r--src/test/ui/const-generics/issues/issue-62456.rs9
-rw-r--r--src/test/ui/const-generics/issues/issue-62456.stderr16
3 files changed, 38 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs
index 7570d9d4b28..859a219c95a 100644
--- a/src/librustc_typeck/check/expr.rs
+++ b/src/librustc_typeck/check/expr.rs
@@ -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;
@@ -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,
         }
     }
 
diff --git a/src/test/ui/const-generics/issues/issue-62456.rs b/src/test/ui/const-generics/issues/issue-62456.rs
new file mode 100644
index 00000000000..c5e6fe9104b
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-62456.rs
@@ -0,0 +1,9 @@
+#![feature(const_generics)]
+//~^ 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() {}
diff --git a/src/test/ui/const-generics/issues/issue-62456.stderr b/src/test/ui/const-generics/issues/issue-62456.stderr
new file mode 100644
index 00000000000..9cdccf8407c
--- /dev/null
+++ b/src/test/ui/const-generics/issues/issue-62456.stderr
@@ -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
+