summaryrefslogtreecommitdiffstats
path: root/tests/ui/const-generics
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/ui/const-generics
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/const-generics')
-rw-r--r--tests/ui/const-generics/bad-generic-in-copy-impl.rs9
-rw-r--r--tests/ui/const-generics/bad-generic-in-copy-impl.stderr9
-rw-r--r--tests/ui/const-generics/bad-subst-const-kind.rs13
-rw-r--r--tests/ui/const-generics/bad-subst-const-kind.stderr9
-rw-r--r--tests/ui/const-generics/const-arg-in-const-arg.full.stderr17
-rw-r--r--tests/ui/const-generics/const-arg-in-const-arg.min.stderr18
-rw-r--r--tests/ui/const-generics/defaults/doesnt_infer.stderr2
-rw-r--r--tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr8
-rw-r--r--tests/ui/const-generics/generic_const_exprs/issue-94287.stderr2
-rw-r--r--tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.rs11
-rw-r--r--tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.stderr18
-rw-r--r--tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs52
-rw-r--r--tests/ui/const-generics/issue-93647.rs1
-rw-r--r--tests/ui/const-generics/issue-93647.stderr19
-rw-r--r--tests/ui/const-generics/issues/issue-82956.stderr8
-rw-r--r--tests/ui/const-generics/transmute-fail.rs35
-rw-r--r--tests/ui/const-generics/transmute-fail.stderr52
-rw-r--r--tests/ui/const-generics/transmute.rs83
-rw-r--r--tests/ui/const-generics/transmute_no_gate.rs91
-rw-r--r--tests/ui/const-generics/transmute_no_gate.stderr84
-rw-r--r--tests/ui/const-generics/type_mismatch.rs1
-rw-r--r--tests/ui/const-generics/type_mismatch.stderr18
-rw-r--r--tests/ui/const-generics/type_not_in_scope.rs1
-rw-r--r--tests/ui/const-generics/type_not_in_scope.stderr14
24 files changed, 531 insertions, 44 deletions
diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.rs b/tests/ui/const-generics/bad-generic-in-copy-impl.rs
new file mode 100644
index 000000000..b5663464c
--- /dev/null
+++ b/tests/ui/const-generics/bad-generic-in-copy-impl.rs
@@ -0,0 +1,9 @@
+#[derive(Copy, Clone)]
+pub struct Foo {
+ x: [u8; SIZE],
+ //~^ ERROR mismatched types
+}
+
+const SIZE: u32 = 1;
+
+fn main() {}
diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr
new file mode 100644
index 000000000..25701ce68
--- /dev/null
+++ b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+ --> $DIR/bad-generic-in-copy-impl.rs:3:13
+ |
+LL | x: [u8; SIZE],
+ | ^^^^ expected `usize`, found `u32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/const-generics/bad-subst-const-kind.rs b/tests/ui/const-generics/bad-subst-const-kind.rs
new file mode 100644
index 000000000..e13dfbacd
--- /dev/null
+++ b/tests/ui/const-generics/bad-subst-const-kind.rs
@@ -0,0 +1,13 @@
+// incremental
+#![crate_type = "lib"]
+
+trait Q {
+ const ASSOC: usize;
+}
+
+impl<const N: u64> Q for [u8; N] {
+ //~^ ERROR mismatched types
+ const ASSOC: usize = 1;
+}
+
+pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] { todo!() }
diff --git a/tests/ui/const-generics/bad-subst-const-kind.stderr b/tests/ui/const-generics/bad-subst-const-kind.stderr
new file mode 100644
index 000000000..bd24f9140
--- /dev/null
+++ b/tests/ui/const-generics/bad-subst-const-kind.stderr
@@ -0,0 +1,9 @@
+error[E0308]: mismatched types
+ --> $DIR/bad-subst-const-kind.rs:8:31
+ |
+LL | impl<const N: u64> Q for [u8; N] {
+ | ^ expected `usize`, found `u64`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/const-generics/const-arg-in-const-arg.full.stderr b/tests/ui/const-generics/const-arg-in-const-arg.full.stderr
index 8672e79b3..463a37d7e 100644
--- a/tests/ui/const-generics/const-arg-in-const-arg.full.stderr
+++ b/tests/ui/const-generics/const-arg-in-const-arg.full.stderr
@@ -1,4 +1,4 @@
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:18:23
|
LL | let _: [u8; faz::<'a>(&())];
@@ -10,7 +10,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:21:23
|
LL | let _: [u8; faz::<'b>(&())];
@@ -22,7 +22,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:41:24
|
LL | let _: Foo<{ faz::<'a>(&()) }>;
@@ -34,7 +34,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:44:24
|
LL | let _: Foo<{ faz::<'b>(&()) }>;
@@ -94,7 +94,7 @@ LL | let _ = [0; bar::<N>()];
|
= help: try adding a `where` bound using this expression: `where [(); bar::<N>()]:`
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:30:23
|
LL | let _ = [0; faz::<'a>(&())];
@@ -106,7 +106,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:33:23
|
LL | let _ = [0; faz::<'b>(&())];
@@ -134,7 +134,7 @@ LL | let _ = Foo::<{ bar::<N>() }>;
|
= help: try adding a `where` bound using this expression: `where [(); { bar::<N>() }]:`
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:52:27
|
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
@@ -146,7 +146,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:55:27
|
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
@@ -160,3 +160,4 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
error: aborting due to 16 previous errors
+For more information about this error, try `rustc --explain E0794`.
diff --git a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr
index f1353aa99..a7bd9c62b 100644
--- a/tests/ui/const-generics/const-arg-in-const-arg.min.stderr
+++ b/tests/ui/const-generics/const-arg-in-const-arg.min.stderr
@@ -216,7 +216,7 @@ help: if this generic argument was intended as a const parameter, surround it wi
LL | let _: [u8; bar::<{ N }>()];
| + +
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:18:23
|
LL | let _: [u8; faz::<'a>(&())];
@@ -228,7 +228,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:21:23
|
LL | let _: [u8; faz::<'b>(&())];
@@ -251,7 +251,7 @@ help: if this generic argument was intended as a const parameter, surround it wi
LL | let _: Foo<{ bar::<{ N }>() }>;
| + +
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:41:24
|
LL | let _: Foo<{ faz::<'a>(&()) }>;
@@ -263,7 +263,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:44:24
|
LL | let _: Foo<{ faz::<'b>(&()) }>;
@@ -294,7 +294,7 @@ help: if this generic argument was intended as a const parameter, surround it wi
LL | let _ = [0; bar::<{ N }>()];
| + +
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:30:23
|
LL | let _ = [0; faz::<'a>(&())];
@@ -306,7 +306,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:33:23
|
LL | let _ = [0; faz::<'b>(&())];
@@ -329,7 +329,7 @@ help: if this generic argument was intended as a const parameter, surround it wi
LL | let _ = Foo::<{ bar::<{ N }>() }>;
| + +
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:52:27
|
LL | let _ = Foo::<{ faz::<'a>(&()) }>;
@@ -341,7 +341,7 @@ note: the late bound lifetime parameter is introduced here
LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
| ^^
-error: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+error[E0794]: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
--> $DIR/const-arg-in-const-arg.rs:55:27
|
LL | let _ = Foo::<{ faz::<'b>(&()) }>;
@@ -355,5 +355,5 @@ LL | const fn faz<'a>(_: &'a ()) -> usize { 13 }
error: aborting due to 36 previous errors
-Some errors have detailed explanations: E0658, E0747.
+Some errors have detailed explanations: E0658, E0747, E0794.
For more information about an error, try `rustc --explain E0658`.
diff --git a/tests/ui/const-generics/defaults/doesnt_infer.stderr b/tests/ui/const-generics/defaults/doesnt_infer.stderr
index 227b2f402..a61411d6e 100644
--- a/tests/ui/const-generics/defaults/doesnt_infer.stderr
+++ b/tests/ui/const-generics/defaults/doesnt_infer.stderr
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed for `Foo<N>`
LL | let foo = Foo::foo();
| ^^^
|
-help: consider giving `foo` an explicit type, where the the value of const parameter `N` is specified
+help: consider giving `foo` an explicit type, where the value of const parameter `N` is specified
|
LL | let foo: Foo<N> = Foo::foo();
| ++++++++
diff --git a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr
index 7b4d46b82..6b3396a25 100644
--- a/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/cross_crate_predicate.stderr
@@ -1,8 +1,8 @@
error: unconstrained generic constant
- --> $DIR/cross_crate_predicate.rs:7:13
+ --> $DIR/cross_crate_predicate.rs:7:44
|
LL | let _ = const_evaluatable_lib::test1::<T>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^
|
= help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<T>() - 1]:`
note: required by a bound in `test1`
@@ -12,10 +12,10 @@ LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test1`
error: unconstrained generic constant
- --> $DIR/cross_crate_predicate.rs:7:13
+ --> $DIR/cross_crate_predicate.rs:7:44
|
LL | let _ = const_evaluatable_lib::test1::<T>();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ | ^
|
= help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<T>() - 1]:`
note: required by a bound in `test1`
diff --git a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
index 7390a0077..dc7d0c54f 100644
--- a/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
+++ b/tests/ui/const-generics/generic_const_exprs/issue-94287.stderr
@@ -8,7 +8,7 @@ LL | If<{ FRAC <= 32 }>: True,
help: consider enabling this feature
--> $DIR/issue-94287.rs:1:1
|
-LL | #![feature(generic_const_exprs)]
+LL + #![feature(generic_const_exprs)]
|
error: aborting due to previous error
diff --git a/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.rs b/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.rs
new file mode 100644
index 000000000..734a37862
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.rs
@@ -0,0 +1,11 @@
+#![feature(generic_const_exprs)]
+//~^ WARN the feature `generic_const_exprs` is incomplete
+
+trait B {
+ type U<T>;
+}
+
+fn f<T: B<U<1i32> = ()>>() {}
+//~^ ERROR constant provided when a type was expected
+
+fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.stderr b/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.stderr
new file mode 100644
index 000000000..8b6eb5b75
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/mismatched-gat-subst-kind.stderr
@@ -0,0 +1,18 @@
+warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
+ --> $DIR/mismatched-gat-subst-kind.rs:1:12
+ |
+LL | #![feature(generic_const_exprs)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
+ = note: `#[warn(incomplete_features)]` on by default
+
+error[E0747]: constant provided when a type was expected
+ --> $DIR/mismatched-gat-subst-kind.rs:8:13
+ |
+LL | fn f<T: B<U<1i32> = ()>>() {}
+ | ^^^^
+
+error: aborting due to previous error; 1 warning emitted
+
+For more information about this error, try `rustc --explain E0747`.
diff --git a/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs b/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs
new file mode 100644
index 000000000..85345d65c
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs
@@ -0,0 +1,52 @@
+// check-pass
+// known-bug: #97156
+
+#![feature(const_type_id, generic_const_exprs)]
+#![allow(incomplete_features)]
+
+use std::any::TypeId;
+// `One` and `Two` are currently considered equal types, as both
+// `One <: Two` and `One :> Two` holds.
+type One = for<'a> fn(&'a (), &'a ());
+type Two = for<'a, 'b> fn(&'a (), &'b ());
+trait AssocCt {
+ const ASSOC: usize;
+}
+const fn to_usize<T: 'static>() -> usize {
+ const WHAT_A_TYPE: TypeId = TypeId::of::<One>();
+ match TypeId::of::<T>() {
+ WHAT_A_TYPE => 0,
+ _ => 1000,
+ }
+}
+impl<T: 'static> AssocCt for T {
+ const ASSOC: usize = to_usize::<T>();
+}
+
+trait WithAssoc<U> {
+ type Assoc;
+}
+impl<T: 'static> WithAssoc<()> for T where [(); <T as AssocCt>::ASSOC]: {
+ type Assoc = [u8; <T as AssocCt>::ASSOC];
+}
+
+fn generic<T: 'static, U>(x: <T as WithAssoc<U>>::Assoc) -> <T as WithAssoc<U>>::Assoc
+where
+ [(); <T as AssocCt>::ASSOC]:,
+ T: WithAssoc<U>,
+{
+ x
+}
+
+
+fn unsound<T>(x: <One as WithAssoc<T>>::Assoc) -> <Two as WithAssoc<T>>::Assoc
+where
+ One: WithAssoc<T>,
+{
+ let x: <Two as WithAssoc<T>>::Assoc = generic::<One, T>(x);
+ x
+}
+
+fn main() {
+ println!("{:?}", unsound::<()>([]));
+}
diff --git a/tests/ui/const-generics/issue-93647.rs b/tests/ui/const-generics/issue-93647.rs
index 806540e17..a0083a0c6 100644
--- a/tests/ui/const-generics/issue-93647.rs
+++ b/tests/ui/const-generics/issue-93647.rs
@@ -1,6 +1,7 @@
struct X<const N: usize = {
(||1usize)()
//~^ ERROR cannot call non-const closure
+ //~| ERROR the trait bound
}>;
fn main() {}
diff --git a/tests/ui/const-generics/issue-93647.stderr b/tests/ui/const-generics/issue-93647.stderr
index 18370eea5..20a6af5c5 100644
--- a/tests/ui/const-generics/issue-93647.stderr
+++ b/tests/ui/const-generics/issue-93647.stderr
@@ -1,3 +1,17 @@
+error[E0277]: the trait bound `[closure@$DIR/issue-93647.rs:2:6: 2:8]: Fn<()>` is not satisfied
+ --> $DIR/issue-93647.rs:2:5
+ |
+LL | (||1usize)()
+ | ^^^^^^^^^^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-93647.rs:2:6: 2:8]`
+ |
+ = help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-93647.rs:2:6: 2:8]`
+note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-93647.rs:2:6: 2:8]`, but that implementation is not `const`
+ --> $DIR/issue-93647.rs:2:5
+ |
+LL | (||1usize)()
+ | ^^^^^^^^^^^^
+ = note: wrap the `[closure@$DIR/issue-93647.rs:2:6: 2:8]` in a closure with no arguments: `|| { /* code */ }`
+
error[E0015]: cannot call non-const closure in constants
--> $DIR/issue-93647.rs:2:5
|
@@ -8,6 +22,7 @@ LL | (||1usize)()
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
= help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
-error: aborting due to previous error
+error: aborting due to 2 previous errors
-For more information about this error, try `rustc --explain E0015`.
+Some errors have detailed explanations: E0015, E0277.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/tests/ui/const-generics/issues/issue-82956.stderr b/tests/ui/const-generics/issues/issue-82956.stderr
index d2320293e..d70c8d0bf 100644
--- a/tests/ui/const-generics/issues/issue-82956.stderr
+++ b/tests/ui/const-generics/issues/issue-82956.stderr
@@ -6,13 +6,13 @@ LL | let mut iter = IntoIter::new(self);
|
help: consider importing one of these items
|
-LL | use std::array::IntoIter;
+LL + use std::array::IntoIter;
|
-LL | use std::collections::binary_heap::IntoIter;
+LL + use std::collections::binary_heap::IntoIter;
|
-LL | use std::collections::btree_map::IntoIter;
+LL + use std::collections::btree_map::IntoIter;
|
-LL | use std::collections::btree_set::IntoIter;
+LL + use std::collections::btree_set::IntoIter;
|
and 8 other candidates
diff --git a/tests/ui/const-generics/transmute-fail.rs b/tests/ui/const-generics/transmute-fail.rs
new file mode 100644
index 000000000..d7bf1b47f
--- /dev/null
+++ b/tests/ui/const-generics/transmute-fail.rs
@@ -0,0 +1,35 @@
+#![feature(transmute_generic_consts)]
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+fn foo<const W: usize, const H: usize>(v: [[u32;H+1]; W]) -> [[u32; W+1]; H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute between types
+ }
+}
+
+fn baz<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H * H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn overflow(v: [[[u32; 8888888]; 9999999]; 777777777]) -> [[[u32; 9999999]; 777777777]; 8888888] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/const-generics/transmute-fail.stderr b/tests/ui/const-generics/transmute-fail.stderr
new file mode 100644
index 000000000..41b098135
--- /dev/null
+++ b/tests/ui/const-generics/transmute-fail.stderr
@@ -0,0 +1,52 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute-fail.rs:7:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; H+1]; W]` (generic size [const expr])
+ = note: target type: `[[u32; W+1]; H]` (generic size [const expr])
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute-fail.rs:16:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; H]; W]` (this type does not have a fixed size)
+ = note: target type: `[[u32; W]; H]` (size can vary because of [u32; W])
+
+error[E0308]: mismatched types
+ --> $DIR/transmute-fail.rs:12:53
+ |
+LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
+ | ^ expected `usize`, found `bool`
+
+error[E0308]: mismatched types
+ --> $DIR/transmute-fail.rs:12:67
+ |
+LL | fn bar<const W: bool, const H: usize>(v: [[u32; H]; W]) -> [[u32; W]; H] {
+ | ^ expected `usize`, found `bool`
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute-fail.rs:23:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; H]; W]` (generic size [const expr])
+ = note: target type: `[u32; W * H * H]` (generic size [const expr])
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute-fail.rs:30:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[[u32; 8888888]; 9999999]; 777777777]` (values of the type `[[[u32; 8888888]; 9999999]; 777777777]` are too big for the current architecture)
+ = note: target type: `[[[u32; 9999999]; 777777777]; 8888888]` (values of the type `[[[u32; 9999999]; 777777777]; 8888888]` are too big for the current architecture)
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0308, E0512.
+For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/const-generics/transmute.rs b/tests/ui/const-generics/transmute.rs
new file mode 100644
index 000000000..30560a95b
--- /dev/null
+++ b/tests/ui/const-generics/transmute.rs
@@ -0,0 +1,83 @@
+// run-pass
+#![feature(generic_const_exprs)]
+#![feature(transmute_generic_consts)]
+#![allow(incomplete_features)]
+
+fn transpose<const W: usize, const H: usize>(v: [[u32;H]; W]) -> [[u32; W]; H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn coagulate<const W: usize, const H: usize>(v: [u32; H*W]) -> [[u32; W];H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn flatten_3d<const W: usize, const H: usize, const D: usize>(
+ v: [[[u32; D]; H]; W]
+) -> [u32; D * W * H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn flatten_somewhat<const W: usize, const H: usize, const D: usize>(
+ v: [[[u32; D]; H]; W]
+) -> [[u32; D * W]; H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8;1]; L] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn transpose_with_const<const W: usize, const H: usize>(
+ v: [[u32; 2 * H]; W + W]
+) -> [[u32; W + W]; 2 * H] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn main() {
+ let _ = transpose([[0; 8]; 16]);
+ let _ = transpose_with_const::<8,4>([[0; 8]; 16]);
+ let _ = ident([[0; 8]; 16]);
+ let _ = flatten([[0; 13]; 5]);
+ let _: [[_; 5]; 13] = coagulate([0; 65]);
+ let _ = flatten_3d([[[0; 3]; 13]; 5]);
+ let _ = flatten_somewhat([[[0; 3]; 13]; 5]);
+ let _ = known_size([16; 13]);
+ let _: [u16; 5] = condense_bytes([16u8; 10]);
+ let _ = singleton_each([16; 10]);
+}
diff --git a/tests/ui/const-generics/transmute_no_gate.rs b/tests/ui/const-generics/transmute_no_gate.rs
new file mode 100644
index 000000000..e1ac44390
--- /dev/null
+++ b/tests/ui/const-generics/transmute_no_gate.rs
@@ -0,0 +1,91 @@
+// gate-test-transmute_generic_consts
+#![feature(generic_const_exprs)]
+#![allow(incomplete_features)]
+
+fn transpose<const W: usize, const H: usize>(v: [[u32;H]; W]) -> [[u32; W]; H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn ident<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [[u32; H]; W] {
+ unsafe {
+ std::mem::transmute(v)
+ }
+}
+
+fn flatten<const W: usize, const H: usize>(v: [[u32; H]; W]) -> [u32; W * H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn coagulate<const W: usize, const H: usize>(v: [u32; H*W]) -> [[u32; W];H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn flatten_3d<const W: usize, const H: usize, const D: usize>(
+ v: [[[u32; D]; H]; W]
+) -> [u32; D * W * H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn flatten_somewhat<const W: usize, const H: usize, const D: usize>(
+ v: [[[u32; D]; H]; W]
+) -> [[u32; D * W]; H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn known_size<const L: usize>(v: [u16; L]) -> [u8; L * 2] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn condense_bytes<const L: usize>(v: [u8; L * 2]) -> [u16; L] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn singleton_each<const L: usize>(v: [u8; L]) -> [[u8;1]; L] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn transpose_with_const<const W: usize, const H: usize>(
+ v: [[u32; 2 * H]; W + W]
+) -> [[u32; W + W]; 2 * H] {
+ unsafe {
+ std::mem::transmute(v)
+ //~^ ERROR cannot transmute
+ }
+}
+
+fn main() {
+ let _ = transpose([[0; 8]; 16]);
+ let _ = transpose_with_const::<8,4>([[0; 8]; 16]);
+ let _ = ident([[0; 8]; 16]);
+ let _ = flatten([[0; 13]; 5]);
+ let _: [[_; 5]; 13] = coagulate([0; 65]);
+ let _ = flatten_3d([[[0; 3]; 13]; 5]);
+ let _ = flatten_somewhat([[[0; 3]; 13]; 5]);
+ let _ = known_size([16; 13]);
+ let _: [u16; 5] = condense_bytes([16u8; 10]);
+ let _ = singleton_each([16; 10]);
+}
diff --git a/tests/ui/const-generics/transmute_no_gate.stderr b/tests/ui/const-generics/transmute_no_gate.stderr
new file mode 100644
index 000000000..9c271b348
--- /dev/null
+++ b/tests/ui/const-generics/transmute_no_gate.stderr
@@ -0,0 +1,84 @@
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:7:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; H]; W]` (this type does not have a fixed size)
+ = note: target type: `[[u32; W]; H]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:20:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; H]; W]` (this type does not have a fixed size)
+ = note: target type: `[u32; W * H]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:27:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u32; H*W]` (this type does not have a fixed size)
+ = note: target type: `[[u32; W]; H]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:36:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[[u32; D]; H]; W]` (this type does not have a fixed size)
+ = note: target type: `[u32; D * W * H]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:45:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[[u32; D]; H]; W]` (this type does not have a fixed size)
+ = note: target type: `[[u32; D * W]; H]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:52:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u16; L]` (this type does not have a fixed size)
+ = note: target type: `[u8; L * 2]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:59:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; L * 2]` (this type does not have a fixed size)
+ = note: target type: `[u16; L]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:66:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[u8; L]` (this type does not have a fixed size)
+ = note: target type: `[[u8; 1]; L]` (this type does not have a fixed size)
+
+error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
+ --> $DIR/transmute_no_gate.rs:75:5
+ |
+LL | std::mem::transmute(v)
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: source type: `[[u32; 2 * H]; W + W]` (this type does not have a fixed size)
+ = note: target type: `[[u32; W + W]; 2 * H]` (this type does not have a fixed size)
+
+error: aborting due to 9 previous errors
+
+For more information about this error, try `rustc --explain E0512`.
diff --git a/tests/ui/const-generics/type_mismatch.rs b/tests/ui/const-generics/type_mismatch.rs
index 4a7534e37..daa13277b 100644
--- a/tests/ui/const-generics/type_mismatch.rs
+++ b/tests/ui/const-generics/type_mismatch.rs
@@ -1,5 +1,6 @@
fn foo<const N: usize>() -> [u8; N] {
bar::<N>() //~ ERROR mismatched types
+ //~^ ERROR the constant `N` is not of type `u8`
}
fn bar<const N: u8>() -> [u8; N] {}
diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr
index b28ae8f7e..394dd44d4 100644
--- a/tests/ui/const-generics/type_mismatch.stderr
+++ b/tests/ui/const-generics/type_mismatch.stderr
@@ -1,3 +1,15 @@
+error: the constant `N` is not of type `u8`
+ --> $DIR/type_mismatch.rs:2:11
+ |
+LL | bar::<N>()
+ | ^ expected `u8`, found `usize`
+ |
+note: required by a bound in `bar`
+ --> $DIR/type_mismatch.rs:6:8
+ |
+LL | fn bar<const N: u8>() -> [u8; N] {}
+ | ^^^^^^^^^^^ required by this bound in `bar`
+
error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:2:11
|
@@ -5,7 +17,7 @@ LL | bar::<N>()
| ^ expected `u8`, found `usize`
error[E0308]: mismatched types
- --> $DIR/type_mismatch.rs:5:26
+ --> $DIR/type_mismatch.rs:6:26
|
LL | fn bar<const N: u8>() -> [u8; N] {}
| --- ^^^^^^^ expected `[u8; N]`, found `()`
@@ -13,11 +25,11 @@ LL | fn bar<const N: u8>() -> [u8; N] {}
| implicitly returns `()` as its body has no tail or `return` expression
error[E0308]: mismatched types
- --> $DIR/type_mismatch.rs:5:31
+ --> $DIR/type_mismatch.rs:6:31
|
LL | fn bar<const N: u8>() -> [u8; N] {}
| ^ expected `usize`, found `u8`
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/const-generics/type_not_in_scope.rs b/tests/ui/const-generics/type_not_in_scope.rs
index 593370180..917abaed1 100644
--- a/tests/ui/const-generics/type_not_in_scope.rs
+++ b/tests/ui/const-generics/type_not_in_scope.rs
@@ -6,6 +6,5 @@ impl X {
}
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/tests/ui/const-generics/type_not_in_scope.stderr b/tests/ui/const-generics/type_not_in_scope.stderr
index 5f45550a6..5eb81ca05 100644
--- a/tests/ui/const-generics/type_not_in_scope.stderr
+++ b/tests/ui/const-generics/type_not_in_scope.stderr
@@ -10,15 +10,7 @@ error[E0573]: expected type, found built-in attribute `cfg_attr`
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 `[u8; N]`, found `()`
- | |
- | implicitly returns `()` as its body has no tail or `return` expression
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
-Some errors have detailed explanations: E0308, E0412, E0573.
-For more information about an error, try `rustc --explain E0308`.
+Some errors have detailed explanations: E0412, E0573.
+For more information about an error, try `rustc --explain E0412`.