From 6c519f6189e9673f53f8d61e1ade916f063da6b9 Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 14 Jul 2024 16:12:32 +0100 Subject: [PATCH] Introduce some tests --- .../const_param_ty_object_safety.rs | 9 +++++++++ .../const_param_ty_object_safety.stderr | 18 ++++++++++++++++++ .../reference_pointee_is_const_param-1.rs | 11 +++++++++++ .../reference_pointee_is_const_param-1.stderr | 9 +++++++++ .../reference_pointee_is_const_param-2.rs} | 6 ++++-- .../reference_pointee_is_const_param-2.stderr | 9 +++++++++ .../trait_objects_as_a_const_generic.rs | 13 +++++++++++++ .../trait_objects_as_a_const_generic.stderr | 8 ++++++++ 8 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs create mode 100644 tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr rename tests/{crashes/119299.rs => ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs} (74%) create mode 100644 tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr create mode 100644 tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs create mode 100644 tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs new file mode 100644 index 000000000000..a2629640b250 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.rs @@ -0,0 +1,9 @@ +#![feature(adt_const_params, unsized_const_parameters)] +#![allow(incomplete_features)] + +use std::marker::ConstParamTy_; + +fn foo(a: &dyn ConstParamTy_) {} +//~^ ERROR: the trait `ConstParamTy_` + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr new file mode 100644 index 000000000000..a415c704aa8b --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/const_param_ty_object_safety.stderr @@ -0,0 +1,18 @@ +error[E0038]: the trait `ConstParamTy_` cannot be made into an object + --> $DIR/const_param_ty_object_safety.rs:6:12 + | +LL | fn foo(a: &dyn ConstParamTy_) {} + | ^^^^^^^^^^^^^^^^^ `ConstParamTy_` cannot be made into an object + | +note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: the trait cannot be made into an object because it uses `Self` as a type parameter +help: consider using an opaque type instead + | +LL | fn foo(a: &impl ConstParamTy_) {} + | ~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0038`. diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs new file mode 100644 index 000000000000..9f62f7655e58 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.rs @@ -0,0 +1,11 @@ +#![feature(adt_const_params, unsized_const_parameters)] +#![allow(incomplete_features)] + +use std::marker::ConstParamTy_; + +struct Foo; + +impl ConstParamTy_ for &'static Foo {} +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr new file mode 100644 index 000000000000..b977cf5d44e0 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-1.stderr @@ -0,0 +1,9 @@ +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/reference_pointee_is_const_param-1.rs:8:24 + | +LL | impl ConstParamTy_ for &'static Foo {} + | ^^^^^^^^^^^^ this field does not implement `ConstParamTy_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/crashes/119299.rs b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs similarity index 74% rename from tests/crashes/119299.rs rename to tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs index 0b54af7b3e1e..66a05ab537f8 100644 --- a/tests/crashes/119299.rs +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.rs @@ -1,13 +1,15 @@ -//@ known-bug: #119299 -#![feature(adt_const_params)] +#![feature(adt_const_params, unsized_const_parameters)] #![allow(incomplete_features)] +// Regression test for #119299 + use std::marker::ConstParamTy_; #[derive(Eq, PartialEq)] struct ConstStrU(*const u8, usize); impl ConstParamTy_ for &'static ConstStrU {} +//~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type impl ConstStrU { const fn from_bytes(bytes: &'static [u8]) -> Self { diff --git a/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr new file mode 100644 index 000000000000..0fe92f253a05 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/reference_pointee_is_const_param-2.stderr @@ -0,0 +1,9 @@ +error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type + --> $DIR/reference_pointee_is_const_param-2.rs:11:24 + | +LL | impl ConstParamTy_ for &'static ConstStrU {} + | ^^^^^^^^^^^^^^^^^^ this field does not implement `ConstParamTy_` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0204`. diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs new file mode 100644 index 000000000000..4bae31e219c8 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.rs @@ -0,0 +1,13 @@ +#![feature(adt_const_params, unsized_const_parameters)] +#![allow(incomplete_features)] + +use std::marker::ConstParamTy_; + +trait Trait {} + +impl ConstParamTy_ for dyn Trait {} +//~^ ERROR: the trait `ConstParamTy` may not be implemented for this type + +fn foo() {} + +fn main() {} diff --git a/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr new file mode 100644 index 000000000000..67c6314e2975 --- /dev/null +++ b/tests/ui/const-generics/adt_const_params/trait_objects_as_a_const_generic.stderr @@ -0,0 +1,8 @@ +error: the trait `ConstParamTy` may not be implemented for this type + --> $DIR/trait_objects_as_a_const_generic.rs:8:24 + | +LL | impl ConstParamTy_ for dyn Trait {} + | ^^^^^^^^^ type is not a structure or enumeration + +error: aborting due to 1 previous error +