Skip to content

CoercePointee doesn't support trait bounds on the smart pointer #138172

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Darksonn opened this issue Mar 7, 2025 · 1 comment · Fixed by #138174
Closed

CoercePointee doesn't support trait bounds on the smart pointer #138172

Darksonn opened this issue Mar 7, 2025 · 1 comment · Fixed by #138174
Assignees
Labels
C-bug Category: This is a bug. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Darksonn
Copy link
Contributor

Darksonn commented Mar 7, 2025

I tried this code:

#![feature(derive_coerce_pointee)]
#![feature(arbitrary_self_types)]
use std::ops::Deref;
use std::marker::CoercePointee;
use std::sync::Arc;

trait MyTrait {}

#[derive(CoercePointee)]
#[repr(transparent)]
struct MyArc<T>
where
    T: MyTrait + ?Sized,
{
    inner: Arc<T>
}

impl<T: MyTrait + ?Sized> Deref for MyArc<T> {
    type Target = T;
    fn deref(&self) -> &T {
        &self.inner
    }
}

trait MyOtherTrait: MyTrait {
    fn foo(self: MyArc<Self>);
}

fn test(_: MyArc<dyn MyOtherTrait>) {}

I expected to see this happen: It compiles.
Instead, this happened:

error[E0038]: the trait `MyOtherTrait` is not dyn compatible
  --> src/lib.rs:29:18
   |
26 |     fn foo(self: MyArc<Self>);
   |                  ----------- help: consider changing method `foo`'s `self` parameter to be `&self`: `&Self`
...
29 | fn test(_: MyArc<dyn MyOtherTrait>) {}
   |                  ^^^^^^^^^^^^^^^^ `MyOtherTrait` is not dyn compatible
   |
note: for a trait to be dyn compatible it needs to allow building a vtable
      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
  --> src/lib.rs:26:18
   |
25 | trait MyOtherTrait: MyTrait {
   |       ------------ this trait is not dyn compatible...
26 |     fn foo(self: MyArc<Self>);
   |                  ^^^^^^^^^^^ ...because method `foo`'s `self` parameter cannot be dispatched on
@Darksonn Darksonn added the C-bug Category: This is a bug. label Mar 7, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 7, 2025
@Darksonn
Copy link
Contributor Author

Darksonn commented Mar 7, 2025

@rustbot label F-derive_coerce_pointee

@rustbot rustbot added the F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation label Mar 7, 2025
@compiler-errors compiler-errors self-assigned this Mar 7, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 12, 2025
…elf-pred, r=BoxyUwU

Elaborate trait assumption in `receiver_is_dispatchable`

Fixes rust-lang#138172. See comment on the linked test.

Probably not a fix for the general problem, bc I think this may still be incomplete for other weird `where` clauses on the receiver. But 🤷, supertraits seems like an obvious one to fix.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 12, 2025
…elf-pred, r=BoxyUwU

Elaborate trait assumption in `receiver_is_dispatchable`

Fixes rust-lang#138172. See comment on the linked test.

Probably not a fix for the general problem, bc I think this may still be incomplete for other weird `where` clauses on the receiver. But 🤷, supertraits seems like an obvious one to fix.
@bors bors closed this as completed in 143eb4f Mar 12, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 12, 2025
Rollup merge of rust-lang#138174 - compiler-errors:elaborate-unsize-self-pred, r=BoxyUwU

Elaborate trait assumption in `receiver_is_dispatchable`

Fixes rust-lang#138172. See comment on the linked test.

Probably not a fix for the general problem, bc I think this may still be incomplete for other weird `where` clauses on the receiver. But 🤷, supertraits seems like an obvious one to fix.
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 12, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-derive_coerce_pointee Feature: RFC 3621's oft-renamed implementation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants