Skip to content

Tweak dyn compatibility error when pointing at receiver - #163049

Open
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:dyn-compat-receiver
Open

estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:dyn-compat-receiver

Conversation

@estebank

Copy link
Copy Markdown
Contributor

Account for receivers with arbitrary self types to suggest idiomatic code.

error[E0038]: the trait `Fetcher` is not dyn compatible
  --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:19:21
   |
LL | fn fetcher() -> Box<dyn Fetcher> {
   |                     ^^^^^^^^^^^ `Fetcher` 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>
  --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:16
   |
LL | pub trait Fetcher: Send + Sync {
   |           ------- this trait is not dyn compatible...
LL |     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |                ^^^^^^^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on
help: consider changing method `get`'s `self` parameter to be `&self`
   |
LL -     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
LL +     fn get<'a>(&'a self) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |

Instead of

help: consider changing method `get`'s `self` parameter to be `&self`
   |
LL -     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
LL +     fn get<'a>(self: &Self) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |

Account for receivers with arbitrary self types to suggest idiomatic code.

```
error[E0038]: the trait `Fetcher` is not dyn compatible
  --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:19:21
   |
LL | fn fetcher() -> Box<dyn Fetcher> {
   |                     ^^^^^^^^^^^ `Fetcher` 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>
  --> $DIR/undispatchable-receiver-and-wc-references-Self.rs:11:16
   |
LL | pub trait Fetcher: Send + Sync {
   |           ------- this trait is not dyn compatible...
LL |     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |                ^^^^^^^^^^^^^^^^^^^ ...because method `get`'s `self` parameter cannot be dispatched on
help: consider changing method `get`'s `self` parameter to be `&self`
   |
LL -     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
LL +     fn get<'a>(&'a self) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |
```

Instead of

```
help: consider changing method `get`'s `self` parameter to be `&self`
   |
LL -     fn get<'a>(self: &'a Box<Self>) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
LL +     fn get<'a>(self: &Self) -> Pin<Box<dyn Future<Output = Vec<u8>> + 'a>>
   |
```
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 20, 2026
@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

r? @ShoyuVanilla

rustbot has assigned @ShoyuVanilla.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 18 candidates

@ShoyuVanilla ShoyuVanilla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a nit but feel free to r=me with or without it 😄

View changes since this review


/// the method's receiver (`self` argument) can't be dispatched on
UndispatchableReceiver(Option<Span>),
UndispatchableReceiver(Option<(Span, Symbol)>),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second field Symbol is little bit confusing. It feels like a symbol for the receiver's type or self kw itself, rather than its (maybe empty) lifetime to me 😅. How would you feel about making it as a named field or add a doc comment for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants