Skip to content

Commit 971a4f2

Browse files
author
Lukas Markeffsky
committed
unimplement PointerLike for trait objects
1 parent 42c00cb commit 971a4f2

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

library/core/src/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ pub trait Tuple {}
990990
message = "`{Self}` needs to have the same ABI as a pointer",
991991
label = "`{Self}` needs to be a pointer-like type"
992992
)]
993+
#[cfg_attr(not(bootstrap), rustc_do_not_implement_via_object)]
993994
pub trait PointerLike {}
994995

995996
#[cfg(not(bootstrap))]

tests/ui/dyn-star/dyn-pointer-like.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test that `dyn PointerLike` and `dyn* PointerLike` do not implement `PointerLike`.
2+
// This used to ICE during codegen.
3+
4+
#![crate_type = "lib"]
5+
6+
#![feature(pointer_like_trait, dyn_star)]
7+
#![feature(unsized_fn_params)]
8+
#![expect(incomplete_features)]
9+
#![expect(internal_features)]
10+
11+
use std::marker::PointerLike;
12+
13+
pub fn lol(x: dyn* PointerLike) {
14+
foo(x); //~ ERROR `dyn* PointerLike` needs to have the same ABI as a pointer
15+
}
16+
17+
pub fn uwu(x: dyn PointerLike) {
18+
foo(x); //~ ERROR `dyn PointerLike` needs to have the same ABI as a pointer
19+
}
20+
21+
fn foo<T: PointerLike + ?Sized>(x: T) {
22+
let _: dyn* PointerLike = x;
23+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0277]: `dyn* PointerLike` needs to have the same ABI as a pointer
2+
--> $DIR/dyn-pointer-like.rs:14:9
3+
|
4+
LL | foo(x);
5+
| --- ^ the trait `PointerLike` is not implemented for `dyn* PointerLike`
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= note: the trait bound `dyn* PointerLike: PointerLike` is not satisfied
10+
note: required by a bound in `foo`
11+
--> $DIR/dyn-pointer-like.rs:21:11
12+
|
13+
LL | fn foo<T: PointerLike + ?Sized>(x: T) {
14+
| ^^^^^^^^^^^ required by this bound in `foo`
15+
help: consider borrowing here
16+
|
17+
LL | foo(&x);
18+
| +
19+
LL | foo(&mut x);
20+
| ++++
21+
22+
error[E0277]: `dyn PointerLike` needs to have the same ABI as a pointer
23+
--> $DIR/dyn-pointer-like.rs:18:9
24+
|
25+
LL | foo(x);
26+
| --- ^ `dyn PointerLike` needs to be a pointer-like type
27+
| |
28+
| required by a bound introduced by this call
29+
|
30+
= help: the trait `PointerLike` is not implemented for `dyn PointerLike`
31+
note: required by a bound in `foo`
32+
--> $DIR/dyn-pointer-like.rs:21:11
33+
|
34+
LL | fn foo<T: PointerLike + ?Sized>(x: T) {
35+
| ^^^^^^^^^^^ required by this bound in `foo`
36+
37+
error: aborting due to 2 previous errors
38+
39+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)