1
Fork 0

unimplement PointerLike for trait objects

This commit is contained in:
Lukas Markeffsky 2024-12-20 17:35:29 +01:00
parent 42c00cb647
commit 971a4f2d3b
3 changed files with 63 additions and 0 deletions

View file

@ -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))]

View file

@ -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;
}

View file

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