Tweak dyn compatibility error when pointing at receiver - #163049
Conversation
|
rustbot has assigned @ShoyuVanilla. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
||
| /// the method's receiver (`self` argument) can't be dispatched on | ||
| UndispatchableReceiver(Option<Span>), | ||
| UndispatchableReceiver(Option<(Span, Symbol)>), |
There was a problem hiding this comment.
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>>
|
```
61c8226 to
41fede0
Compare
|
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. |
|
@bors r=ShoyuVanilla |
|
⌛ Testing commit 41fede0 with merge 317826f... Workflow: https://github.com/rust-lang/rust/actions/runs/35677613574 |
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>>
|
```
|
@bors yield (enclosing rollup) |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #163139. |
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>> | ```
Account for receivers with arbitrary self types to suggest idiomatic code.
Instead of