about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-03-03 18:52:49 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-27 15:59:07 +0000
commit26417a85e7551115146f98c64ea4e433453b9b4b (patch)
treecea8f3fbdddcbd82da560f63767fabe77056fb65
parentbdb5502aa862e22cec579eb845df4bfe42612cfd (diff)
downloadrust-26417a85e7551115146f98c64ea4e433453b9b4b.tar.gz
rust-26417a85e7551115146f98c64ea4e433453b9b4b.zip
Add `ConstParamTy` tests
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs13
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr87
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs13
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr42
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_good.rs43
5 files changed, 198 insertions, 0 deletions
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs
new file mode 100644
index 00000000000..a9ade9d838c
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.rs
@@ -0,0 +1,13 @@
+#![allow(incomplete_features)]
+#![feature(adt_const_params)]
+
+fn check(_: impl std::marker::ConstParamTy) {}
+
+fn main() {
+    check(main);               //~ error: `fn() {main}` can't be used as a const parameter type
+    check(|| {});              //~ error: `[closure@fake-test-src-base/const-generics/adt_const_params/const_param_ty_bad.rs:8:11: 8:13]` can't be used as a const parameter type
+    check(main as fn());       //~ error: `fn()` can't be used as a const parameter type
+    check(&mut ());            //~ error: `&mut ()` can't be used as a const parameter type
+    check(&mut () as *mut ()); //~ error: `*mut ()` can't be used as a const parameter type
+    check(&() as *const ());   //~ error: `*const ()` can't be used as a const parameter type
+}
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
new file mode 100644
index 00000000000..de5704ee429
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_bad.stderr
@@ -0,0 +1,87 @@
+error[E0277]: `fn() {main}` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:7:11
+   |
+LL |     check(main);
+   |     ----- ^^^^ the trait `ConstParamTy` is not implemented for fn item `fn() {main}`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:8:11
+   |
+LL |     check(|| {});
+   |     ----- ^^^^^ the trait `ConstParamTy` is not implemented for closure `[closure@$DIR/const_param_ty_bad.rs:8:11: 8:13]`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `fn()` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:9:11
+   |
+LL |     check(main as fn());
+   |     ----- ^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `fn()`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `&mut ()` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:10:11
+   |
+LL |     check(&mut ());
+   |     ----- ^^^^^^^ the trait `ConstParamTy` is not implemented for `&mut ()`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `*mut ()` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:11:11
+   |
+LL |     check(&mut () as *mut ());
+   |     ----- ^^^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*mut ()`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `*const ()` can't be used as a const parameter type
+  --> $DIR/const_param_ty_bad.rs:12:11
+   |
+LL |     check(&() as *const ());
+   |     ----- ^^^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `*const ()`
+   |     |
+   |     required by a bound introduced by this call
+   |
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_bad.rs:4:18
+   |
+LL | fn check(_: impl std::marker::ConstParamTy) {}
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs
new file mode 100644
index 00000000000..e4dc76703a2
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.rs
@@ -0,0 +1,13 @@
+#![allow(incomplete_features)]
+#![feature(adt_const_params)]
+
+#[derive(PartialEq, Eq)]
+struct NotParam;
+
+fn check<T: std::marker::ConstParamTy + ?Sized>() {}
+
+fn main() {
+    check::<&NotParam>();      //~ error: `NotParam` can't be used as a const parameter type
+    check::<[NotParam]>();     //~ error: `NotParam` can't be used as a const parameter type
+    check::<[NotParam; 17]>(); //~ error: `NotParam` can't be used as a const parameter type
+}
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr
new file mode 100644
index 00000000000..86d1c94e87f
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_generic_bounds_do_not_hold.stderr
@@ -0,0 +1,42 @@
+error[E0277]: `NotParam` can't be used as a const parameter type
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:10:13
+   |
+LL |     check::<&NotParam>();
+   |             ^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
+   |
+   = note: required for `&NotParam` to implement `ConstParamTy`
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
+   |
+LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `NotParam` can't be used as a const parameter type
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:11:13
+   |
+LL |     check::<[NotParam]>();
+   |             ^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
+   |
+   = note: required for `[NotParam]` to implement `ConstParamTy`
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
+   |
+LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error[E0277]: `NotParam` can't be used as a const parameter type
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:12:13
+   |
+LL |     check::<[NotParam; 17]>();
+   |             ^^^^^^^^^^^^^^ the trait `ConstParamTy` is not implemented for `NotParam`
+   |
+   = note: required for `[NotParam; 17]` to implement `ConstParamTy`
+note: required by a bound in `check`
+  --> $DIR/const_param_ty_generic_bounds_do_not_hold.rs:7:13
+   |
+LL | fn check<T: std::marker::ConstParamTy + ?Sized>() {}
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `check`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs
new file mode 100644
index 00000000000..a1b711a3024
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_good.rs
@@ -0,0 +1,43 @@
+// check-pass
+#![allow(incomplete_features)]
+#![feature(adt_const_params)]
+use std::marker::ConstParamTy;
+
+#[derive(PartialEq, Eq)]
+struct S<T> {
+    field: u8,
+    gen: T,
+}
+
+impl<T: ConstParamTy> ConstParamTy for S<T> {}
+
+fn check<T: ConstParamTy + ?Sized>() {}
+
+fn main() {
+    check::<u8>();
+    check::<u16>();
+    check::<u32>();
+    check::<u64>();
+    check::<u128>();
+
+    check::<i8>();
+    check::<i16>();
+    check::<i32>();
+    check::<i64>();
+    check::<i128>();
+
+    check::<char>();
+    check::<bool>();
+    check::<str>();
+
+    check::<&u8>();
+    check::<&str>();
+    check::<[usize]>();
+    check::<[u16; 0]>();
+    check::<[u8; 42]>();
+
+    check::<S<u8>>();
+    check::<S<[&[bool]; 8]>>();
+
+    // FIXME: test tuples
+}