Skip to content

Tweak dyn compatibility error when pointing at receiver - #163049

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
estebank:dyn-compat-receiver
Sep 22, 2026
Merged

rust-bors[bot] merged 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>>
   |

@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?

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 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@estebank

Copy link
Copy Markdown
Contributor Author

@bors r=ShoyuVanilla

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 41fede0 has been approved by ShoyuVanilla

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2026
@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

⌛ Testing commit 41fede0 with merge 317826f...

Workflow: https://github.com/rust-lang/rust/actions/runs/35677613574

rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
Tweak dyn compatibility error when pointing at receiver

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>>
   |
```
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 22, 2026
@Zalathar

Copy link
Copy Markdown
Member

@bors yield (enclosing rollup)

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #163139.

rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
Rollup of 4 pull requests

Successful merges:

 - #163049 (Tweak dyn compatibility error when pointing at receiver)
 - #163051 (Make CovariantUnsafeCell actually covariant)
 - #163080 (`rustc_builtin_macros` cleanup, part 5)
 - #163100 (normalize normalizes, avoid next-solver hack)
@rust-bors
rust-bors Bot merged commit b420a66 into rust-lang:main Sep 22, 2026
13 of 14 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
Rollup merge of #163049 - estebank:dyn-compat-receiver, r=ShoyuVanilla

Tweak dyn compatibility error when pointing at receiver

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 this to the 1.100.0 milestone Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

4 participants