about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-03-19 23:01:42 +0100
committerGitHub <noreply@github.com>2021-03-19 23:01:42 +0100
commit51a29cbb23d2146322350fbfde53fe9523e554fb (patch)
tree147f1b291abe9114184d93bff95adb94b78fa522 /src
parent767b094d1e638c38725f449778bf6759349353f8 (diff)
parent957705802ee2f255ec57e42fe60a59a60e56a425 (diff)
downloadrust-51a29cbb23d2146322350fbfde53fe9523e554fb.tar.gz
rust-51a29cbb23d2146322350fbfde53fe9523e554fb.zip
Rollup merge of #83297 - oli-obk:why_bug_today_if_you_can_delay_to_tomorrow, r=petrochenkov
Do not ICE on ty::Error as an error must already have been reported

fixes #83253
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/const-generics/type_mismatch.rs9
-rw-r--r--src/test/ui/const-generics/type_mismatch.stderr23
-rw-r--r--src/test/ui/const-generics/type_not_in_scope.rs11
-rw-r--r--src/test/ui/const-generics/type_not_in_scope.stderr24
4 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/type_mismatch.rs b/src/test/ui/const-generics/type_mismatch.rs
new file mode 100644
index 00000000000..4a7534e3713
--- /dev/null
+++ b/src/test/ui/const-generics/type_mismatch.rs
@@ -0,0 +1,9 @@
+fn foo<const N: usize>() -> [u8; N] {
+    bar::<N>() //~ ERROR mismatched types
+}
+
+fn bar<const N: u8>() -> [u8; N] {}
+//~^ ERROR mismatched types
+//~| ERROR mismatched types
+
+fn main() {}
diff --git a/src/test/ui/const-generics/type_mismatch.stderr b/src/test/ui/const-generics/type_mismatch.stderr
new file mode 100644
index 00000000000..f5053e4c8c8
--- /dev/null
+++ b/src/test/ui/const-generics/type_mismatch.stderr
@@ -0,0 +1,23 @@
+error[E0308]: mismatched types
+  --> $DIR/type_mismatch.rs:2:11
+   |
+LL |     bar::<N>()
+   |           ^ expected `u8`, found `usize`
+
+error[E0308]: mismatched types
+  --> $DIR/type_mismatch.rs:5:31
+   |
+LL | fn bar<const N: u8>() -> [u8; N] {}
+   |                               ^ expected `usize`, found `u8`
+
+error[E0308]: mismatched types
+  --> $DIR/type_mismatch.rs:5:26
+   |
+LL | fn bar<const N: u8>() -> [u8; N] {}
+   |    ---                   ^^^^^^^ expected array `[u8; N]`, found `()`
+   |    |
+   |    implicitly returns `()` as its body has no tail or `return` expression
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/type_not_in_scope.rs b/src/test/ui/const-generics/type_not_in_scope.rs
new file mode 100644
index 00000000000..5933701808b
--- /dev/null
+++ b/src/test/ui/const-generics/type_not_in_scope.rs
@@ -0,0 +1,11 @@
+impl X {
+    //~^ ERROR cannot find type
+    fn getn<const N: usize>() -> [u8; N] {
+        getn::<N>()
+    }
+}
+fn getn<const N: cfg_attr>() -> [u8; N] {}
+//~^ ERROR expected type, found built-in attribute `cfg_attr`
+//~| ERROR mismatched types
+
+fn main() {}
diff --git a/src/test/ui/const-generics/type_not_in_scope.stderr b/src/test/ui/const-generics/type_not_in_scope.stderr
new file mode 100644
index 00000000000..16796acb3d2
--- /dev/null
+++ b/src/test/ui/const-generics/type_not_in_scope.stderr
@@ -0,0 +1,24 @@
+error[E0412]: cannot find type `X` in this scope
+  --> $DIR/type_not_in_scope.rs:1:6
+   |
+LL | impl X {
+   |      ^ not found in this scope
+
+error[E0573]: expected type, found built-in attribute `cfg_attr`
+  --> $DIR/type_not_in_scope.rs:7:18
+   |
+LL | fn getn<const N: cfg_attr>() -> [u8; N] {}
+   |                  ^^^^^^^^ not a type
+
+error[E0308]: mismatched types
+  --> $DIR/type_not_in_scope.rs:7:33
+   |
+LL | fn getn<const N: cfg_attr>() -> [u8; N] {}
+   |    ----                         ^^^^^^^ expected array `[u8; N]`, found `()`
+   |    |
+   |    implicitly returns `()` as its body has no tail or `return` expression
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0308, E0412, E0573.
+For more information about an error, try `rustc --explain E0308`.