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(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(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(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`.