about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2024-12-20 17:35:29 +0100
committerLukas Markeffsky <@>2024-12-20 17:35:29 +0100
commit971a4f2d3b0c44fae115b39e4fa9607a911ed59c (patch)
treee4a9b5cdfe069237b2f7252808c878e099e294da
parent42c00cb6479d6e03742968e06c6d280a272acd53 (diff)
unimplement `PointerLike` for trait objects
-rw-r--r--library/core/src/marker.rs1
-rw-r--r--tests/ui/dyn-star/dyn-pointer-like.rs23
-rw-r--r--tests/ui/dyn-star/dyn-pointer-like.stderr39
3 files changed, 63 insertions, 0 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs
index 31b27b7ef26..bdfa162919f 100644
--- a/library/core/src/marker.rs
+++ b/library/core/src/marker.rs
@@ -990,6 +990,7 @@ pub trait Tuple {}
     message = "`{Self}` needs to have the same ABI as a pointer",
     label = "`{Self}` needs to be a pointer-like type"
 )]
+#[cfg_attr(not(bootstrap), rustc_do_not_implement_via_object)]
 pub trait PointerLike {}
 
 #[cfg(not(bootstrap))]
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`.