summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-05-16 19:40:02 +0200
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-05-16 20:09:25 +0200
commit0336dd132b50af57389aa222793aff3c38b88daf (patch)
tree4f01af97cfcd8d8e402c7bdcce5c3bcf2a94b13c /tests
parentcba14074bb4cc12bfe918eabd0d52a3999b2a461 (diff)
downloadrust-0336dd132b50af57389aa222793aff3c38b88daf.tar.gz
Add derive for `core::marker::ConstParamTy`
This makes it easier to implement it for a type, just like `Copy`.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_good.rs10
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs4
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr13
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs4
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr12
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs33
-rw-r--r--tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr8
7 files changed, 82 insertions, 2 deletions
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
index a1b711a3024..87ae83dd966 100644
--- 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
@@ -11,6 +11,13 @@ struct S<T> {
impl<T: ConstParamTy> ConstParamTy for S<T> {}
+#[derive(PartialEq, Eq, ConstParamTy)]
+struct D<T> {
+ field: u8,
+ gen: T,
+}
+
+
fn check<T: ConstParamTy + ?Sized>() {}
fn main() {
@@ -39,5 +46,8 @@ fn main() {
check::<S<u8>>();
check::<S<[&[bool]; 8]>>();
+ check::<D<u8>>();
+ check::<D<[&[bool]; 8]>>();
+
// FIXME: test tuples
}
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs
index 07fd243737e..74283a37afc 100644
--- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.rs
@@ -10,4 +10,8 @@ struct CantParam(NotParam);
impl std::marker::ConstParamTy for CantParam {}
//~^ error: the trait `ConstParamTy` cannot be implemented for this type
+#[derive(std::marker::ConstParamTy, Eq, PartialEq)]
+//~^ error: the trait `ConstParamTy` cannot be implemented for this type
+struct CantParamDerive(NotParam);
+
fn main() {}
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr
index c8e065848b1..52b65d6061a 100644
--- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_bad_field.stderr
@@ -7,6 +7,17 @@ LL |
LL | impl std::marker::ConstParamTy for CantParam {}
| ^^^^^^^^^
-error: aborting due to previous error
+error[E0204]: the trait `ConstParamTy` cannot be implemented for this type
+ --> $DIR/const_param_ty_impl_bad_field.rs:13:10
+ |
+LL | #[derive(std::marker::ConstParamTy, Eq, PartialEq)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |
+LL | struct CantParamDerive(NotParam);
+ | -------- this field does not implement `ConstParamTy`
+ |
+ = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0204`.
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs
index 17ef396164e..37986de481f 100644
--- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.rs
@@ -10,6 +10,10 @@ struct CantParam(ImplementsConstParamTy);
impl std::marker::ConstParamTy for CantParam {}
//~^ error: the type `CantParam` does not `#[derive(Eq)]`
+#[derive(std::marker::ConstParamTy)]
+//~^ error: the type `CantParamDerive` does not `#[derive(Eq)]`
+struct CantParamDerive(ImplementsConstParamTy);
+
fn check<T: std::marker::ConstParamTy>() {}
fn main() {
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr
index ca5abf5e254..52701d55914 100644
--- a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_no_structural_eq.stderr
@@ -7,6 +7,16 @@ LL | impl std::marker::ConstParamTy for CantParam {}
note: required by a bound in `ConstParamTy`
--> $SRC_DIR/core/src/marker.rs:LL:COL
-error: aborting due to previous error
+error[E0277]: the type `CantParamDerive` does not `#[derive(Eq)]`
+ --> $DIR/const_param_ty_impl_no_structural_eq.rs:13:10
+ |
+LL | #[derive(std::marker::ConstParamTy)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `StructuralEq` is not implemented for `CantParamDerive`
+ |
+note: required by a bound in `ConstParamTy`
+ --> $SRC_DIR/core/src/marker.rs:LL:COL
+ = note: this error originates in the derive macro `std::marker::ConstParamTy` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 2 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_impl_union.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs
new file mode 100644
index 00000000000..d70377a20c1
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.rs
@@ -0,0 +1,33 @@
+#![allow(incomplete_features)]
+#![feature(adt_const_params, structural_match)]
+
+union Union {
+ a: u8,
+}
+
+impl PartialEq for Union {
+ fn eq(&self, other: &Union) -> bool {
+ true
+ }
+}
+impl Eq for Union {}
+impl std::marker::StructuralEq for Union {}
+
+impl std::marker::ConstParamTy for Union {}
+
+#[derive(std::marker::ConstParamTy)]
+//~^ ERROR this trait cannot be derived for unions
+union UnionDerive {
+ a: u8,
+}
+
+impl PartialEq for UnionDerive {
+ fn eq(&self, other: &UnionDerive) -> bool {
+ true
+ }
+}
+impl Eq for UnionDerive {}
+impl std::marker::StructuralEq for UnionDerive {}
+
+
+fn main() {}
diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr
new file mode 100644
index 00000000000..29370304605
--- /dev/null
+++ b/tests/ui/const-generics/adt_const_params/const_param_ty_impl_union.stderr
@@ -0,0 +1,8 @@
+error: this trait cannot be derived for unions
+ --> $DIR/const_param_ty_impl_union.rs:18:10
+ |
+LL | #[derive(std::marker::ConstParamTy)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+