forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#134573 - lukas-code:unimpl-dyn-pointerlike, r=compiler-errors unimplement `PointerLike` for trait objects Values of type `dyn* PointerLike` or `dyn PointerLike` are not pointer-like so these types should not implement `PointerLike`. After rust-lang#133226, `PointerLike` allows user implementations, so we can't just mark it with `#[rustc_deny_explicit_impl(implement_via_object = false)]`. Instead, this PR splits the `#[rustc_deny_explicit_impl(implement_via_object = ...)]` attribute into two separate attributes `#[rustc_deny_explicit_impl]` and `#[rustc_do_not_implement_via_object]` so that we opt out of the automatic `impl PointerLike for dyn PointerLike` and still allow user implementations. For traits that are marked with `#[do_not_implement_via_object]` but not `#[rustc_deny_explicit_impl]` I've also made it possible to add a manual `impl Trait for dyn Trait`. There is no immediate need for this, but it was one line to implement and seems nice to have. fixes rust-lang#134545 fixes rust-lang#134543 r? `@compiler-errors`
- Loading branch information
Showing
15 changed files
with
217 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
Oops, something went wrong.