about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/dyn-star/dyn-pointer-like.rs23
-rw-r--r--tests/ui/dyn-star/dyn-pointer-like.stderr39
-rw-r--r--tests/ui/traits/deny-builtin-object-impl.current.stderr50
-rw-r--r--tests/ui/traits/deny-builtin-object-impl.next.stderr50
-rw-r--r--tests/ui/traits/deny-builtin-object-impl.rs41
5 files changed, 168 insertions, 35 deletions
diff --git a/tests/ui/dyn-star/dyn-pointer-like.rs b/tests/ui/dyn-star/dyn-pointer-like.rs
new file mode 100644
index 00000000000..f26fa90505c
--- /dev/null
+++ b/tests/ui/dyn-star/dyn-pointer-like.rs
@@ -0,0 +1,23 @@
+// Test that `dyn PointerLike` and `dyn* PointerLike` do not implement `PointerLike`.
+// This used to ICE during codegen.
+
+#![crate_type = "lib"]
+
+#![feature(pointer_like_trait, dyn_star)]
+#![feature(unsized_fn_params)]
+#![expect(incomplete_features)]
+#![expect(internal_features)]
+
+use std::marker::PointerLike;
+
+pub fn lol(x: dyn* PointerLike) {
+    foo(x); //~ ERROR `dyn* PointerLike` needs to have the same ABI as a pointer
+}
+
+pub fn uwu(x: dyn PointerLike) {
+    foo(x); //~ ERROR `dyn PointerLike` needs to have the same ABI as a pointer
+}
+
+fn foo<T: PointerLike + ?Sized>(x: T) {
+    let _: dyn* PointerLike = x;
+}
diff --git a/tests/ui/dyn-star/dyn-pointer-like.stderr b/tests/ui/dyn-star/dyn-pointer-like.stderr
new file mode 100644
index 00000000000..4c558e92d3f
--- /dev/null
+++ b/tests/ui/dyn-star/dyn-pointer-like.stderr
@@ -0,0 +1,39 @@
+error[E0277]: `dyn* PointerLike` needs to have the same ABI as a pointer
+  --> $DIR/dyn-pointer-like.rs:14:9
+   |
+LL |     foo(x);
+   |     --- ^ the trait `PointerLike` is not implemented for `dyn* PointerLike`
+   |     |
+   |     required by a bound introduced by this call
+   |
+   = note: the trait bound `dyn* PointerLike: PointerLike` is not satisfied
+note: required by a bound in `foo`
+  --> $DIR/dyn-pointer-like.rs:21:11
+   |
+LL | fn foo<T: PointerLike + ?Sized>(x: T) {
+   |           ^^^^^^^^^^^ required by this bound in `foo`
+help: consider borrowing here
+   |
+LL |     foo(&x);
+   |         +
+LL |     foo(&mut x);
+   |         ++++
+
+error[E0277]: `dyn PointerLike` needs to have the same ABI as a pointer
+  --> $DIR/dyn-pointer-like.rs:18:9
+   |
+LL |     foo(x);
+   |     --- ^ `dyn PointerLike` needs to be a pointer-like type
+   |     |
+   |     required by a bound introduced by this call
+   |
+   = help: the trait `PointerLike` is not implemented for `dyn PointerLike`
+note: required by a bound in `foo`
+  --> $DIR/dyn-pointer-like.rs:21:11
+   |
+LL | fn foo<T: PointerLike + ?Sized>(x: T) {
+   |           ^^^^^^^^^^^ required by this bound in `foo`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/deny-builtin-object-impl.current.stderr b/tests/ui/traits/deny-builtin-object-impl.current.stderr
index 8423a2519b2..d6f4762d099 100644
--- a/tests/ui/traits/deny-builtin-object-impl.current.stderr
+++ b/tests/ui/traits/deny-builtin-object-impl.current.stderr
@@ -1,20 +1,44 @@
-error[E0277]: the trait bound `dyn NotObject: NotObject` is not satisfied
-  --> $DIR/deny-builtin-object-impl.rs:19:23
+error[E0322]: explicit impls for the `NotImplYesObject` trait are not permitted
+  --> $DIR/deny-builtin-object-impl.rs:20:1
    |
-LL |     test_not_object::<dyn NotObject>();
-   |                       ^^^^^^^^^^^^^ the trait `NotObject` is not implemented for `dyn NotObject`
+LL | impl NotImplYesObject for () {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `NotImplYesObject` not allowed
+
+error[E0277]: the trait bound `dyn NotImplNotObject: NotImplNotObject` is not satisfied
+  --> $DIR/deny-builtin-object-impl.rs:37:32
+   |
+LL |     test_not_impl_not_object::<dyn NotImplNotObject>();
+   |                                ^^^^^^^^^^^^^^^^^^^^ the trait `NotImplNotObject` is not implemented for `dyn NotImplNotObject`
+   |
+help: this trait has no implementations, consider adding one
+  --> $DIR/deny-builtin-object-impl.rs:12:1
+   |
+LL | trait NotImplNotObject {}
+   | ^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `test_not_impl_not_object`
+  --> $DIR/deny-builtin-object-impl.rs:28:32
+   |
+LL | fn test_not_impl_not_object<T: NotImplNotObject + ?Sized>() {}
+   |                                ^^^^^^^^^^^^^^^^ required by this bound in `test_not_impl_not_object`
+
+error[E0277]: the trait bound `dyn YesImplNotObject: YesImplNotObject` is not satisfied
+  --> $DIR/deny-builtin-object-impl.rs:40:32
+   |
+LL |     test_yes_impl_not_object::<dyn YesImplNotObject>();
+   |                                ^^^^^^^^^^^^^^^^^^^^ the trait `YesImplNotObject` is not implemented for `dyn YesImplNotObject`
    |
 help: this trait has no implementations, consider adding one
-  --> $DIR/deny-builtin-object-impl.rs:11:1
+  --> $DIR/deny-builtin-object-impl.rs:15:1
    |
-LL | trait NotObject {}
-   | ^^^^^^^^^^^^^^^
-note: required by a bound in `test_not_object`
-  --> $DIR/deny-builtin-object-impl.rs:15:23
+LL | trait YesImplNotObject {}
+   | ^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `test_yes_impl_not_object`
+  --> $DIR/deny-builtin-object-impl.rs:30:32
    |
-LL | fn test_not_object<T: NotObject + ?Sized>() {}
-   |                       ^^^^^^^^^ required by this bound in `test_not_object`
+LL | fn test_yes_impl_not_object<T: YesImplNotObject + ?Sized>() {}
+   |                                ^^^^^^^^^^^^^^^^ required by this bound in `test_yes_impl_not_object`
 
-error: aborting due to 1 previous error
+error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0277`.
+Some errors have detailed explanations: E0277, E0322.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/deny-builtin-object-impl.next.stderr b/tests/ui/traits/deny-builtin-object-impl.next.stderr
index 8423a2519b2..d6f4762d099 100644
--- a/tests/ui/traits/deny-builtin-object-impl.next.stderr
+++ b/tests/ui/traits/deny-builtin-object-impl.next.stderr
@@ -1,20 +1,44 @@
-error[E0277]: the trait bound `dyn NotObject: NotObject` is not satisfied
-  --> $DIR/deny-builtin-object-impl.rs:19:23
+error[E0322]: explicit impls for the `NotImplYesObject` trait are not permitted
+  --> $DIR/deny-builtin-object-impl.rs:20:1
    |
-LL |     test_not_object::<dyn NotObject>();
-   |                       ^^^^^^^^^^^^^ the trait `NotObject` is not implemented for `dyn NotObject`
+LL | impl NotImplYesObject for () {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `NotImplYesObject` not allowed
+
+error[E0277]: the trait bound `dyn NotImplNotObject: NotImplNotObject` is not satisfied
+  --> $DIR/deny-builtin-object-impl.rs:37:32
+   |
+LL |     test_not_impl_not_object::<dyn NotImplNotObject>();
+   |                                ^^^^^^^^^^^^^^^^^^^^ the trait `NotImplNotObject` is not implemented for `dyn NotImplNotObject`
+   |
+help: this trait has no implementations, consider adding one
+  --> $DIR/deny-builtin-object-impl.rs:12:1
+   |
+LL | trait NotImplNotObject {}
+   | ^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `test_not_impl_not_object`
+  --> $DIR/deny-builtin-object-impl.rs:28:32
+   |
+LL | fn test_not_impl_not_object<T: NotImplNotObject + ?Sized>() {}
+   |                                ^^^^^^^^^^^^^^^^ required by this bound in `test_not_impl_not_object`
+
+error[E0277]: the trait bound `dyn YesImplNotObject: YesImplNotObject` is not satisfied
+  --> $DIR/deny-builtin-object-impl.rs:40:32
+   |
+LL |     test_yes_impl_not_object::<dyn YesImplNotObject>();
+   |                                ^^^^^^^^^^^^^^^^^^^^ the trait `YesImplNotObject` is not implemented for `dyn YesImplNotObject`
    |
 help: this trait has no implementations, consider adding one
-  --> $DIR/deny-builtin-object-impl.rs:11:1
+  --> $DIR/deny-builtin-object-impl.rs:15:1
    |
-LL | trait NotObject {}
-   | ^^^^^^^^^^^^^^^
-note: required by a bound in `test_not_object`
-  --> $DIR/deny-builtin-object-impl.rs:15:23
+LL | trait YesImplNotObject {}
+   | ^^^^^^^^^^^^^^^^^^^^^^
+note: required by a bound in `test_yes_impl_not_object`
+  --> $DIR/deny-builtin-object-impl.rs:30:32
    |
-LL | fn test_not_object<T: NotObject + ?Sized>() {}
-   |                       ^^^^^^^^^ required by this bound in `test_not_object`
+LL | fn test_yes_impl_not_object<T: YesImplNotObject + ?Sized>() {}
+   |                                ^^^^^^^^^^^^^^^^ required by this bound in `test_yes_impl_not_object`
 
-error: aborting due to 1 previous error
+error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0277`.
+Some errors have detailed explanations: E0277, E0322.
+For more information about an error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/deny-builtin-object-impl.rs b/tests/ui/traits/deny-builtin-object-impl.rs
index c16dcca8fbc..9d02ab7bd46 100644
--- a/tests/ui/traits/deny-builtin-object-impl.rs
+++ b/tests/ui/traits/deny-builtin-object-impl.rs
@@ -4,18 +4,41 @@
 
 #![feature(rustc_attrs)]
 
-#[rustc_deny_explicit_impl(implement_via_object = true)]
-trait YesObject {}
+#[rustc_deny_explicit_impl]
+trait NotImplYesObject {}
 
-#[rustc_deny_explicit_impl(implement_via_object = false)]
-trait NotObject {}
+#[rustc_deny_explicit_impl]
+#[rustc_do_not_implement_via_object]
+trait NotImplNotObject {}
 
-fn test_yes_object<T: YesObject + ?Sized>() {}
+#[rustc_do_not_implement_via_object]
+trait YesImplNotObject {}
 
-fn test_not_object<T: NotObject + ?Sized>() {}
+#[rustc_do_not_implement_via_object]
+trait YesImplNotObject2 {}
+
+impl NotImplYesObject for () {}
+//~^ ERROR explicit impls for the `NotImplYesObject` trait are not permitted
+
+// If there is no automatic impl then we can add a manual impl:
+impl YesImplNotObject2 for dyn YesImplNotObject2 {}
+
+fn test_not_impl_yes_object<T: NotImplYesObject + ?Sized>() {}
+
+fn test_not_impl_not_object<T: NotImplNotObject + ?Sized>() {}
+
+fn test_yes_impl_not_object<T: YesImplNotObject + ?Sized>() {}
+
+fn test_yes_impl_not_object2<T: YesImplNotObject2 + ?Sized>() {}
 
 fn main() {
-    test_yes_object::<dyn YesObject>();
-    test_not_object::<dyn NotObject>();
-    //~^ ERROR the trait bound `dyn NotObject: NotObject` is not satisfied
+    test_not_impl_yes_object::<dyn NotImplYesObject>();
+
+    test_not_impl_not_object::<dyn NotImplNotObject>();
+    //~^ ERROR the trait bound `dyn NotImplNotObject: NotImplNotObject` is not satisfied
+
+    test_yes_impl_not_object::<dyn YesImplNotObject>();
+    //~^ ERROR the trait bound `dyn YesImplNotObject: YesImplNotObject` is not satisfied
+
+    test_yes_impl_not_object2::<dyn YesImplNotObject2>();
 }