1
Fork 0

Rollup merge of #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 https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/issues/134545
fixes https://github.com/rust-lang/rust/issues/134543

r? `@compiler-errors`
This commit is contained in:
Matthias Krüger 2024-12-20 21:32:33 +01:00 committed by GitHub
commit 0b1834d66b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 217 additions and 93 deletions

View file

@ -70,12 +70,12 @@ pub struct TraitDef {
/// Whether to add a builtin `dyn Trait: Trait` implementation.
/// This is enabled for all traits except ones marked with
/// `#[rustc_deny_explicit_impl(implement_via_object = false)]`.
/// `#[rustc_do_not_implement_via_object]`.
pub implement_via_object: bool,
/// Whether a trait is fully built-in, and any implementation is disallowed.
/// This only applies to built-in traits, and is marked via
/// `#[rustc_deny_explicit_impl(implement_via_object = ...)]`.
/// `#[rustc_deny_explicit_impl]`.
pub deny_explicit_impl: bool,
}