-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhelpful error message when using bad receiver type #57994
Comments
Re-posting from #63966 since it was closed in favor of this thread. playground mod First {
trait Foo { fn m(self: Box<Self>); }
fn foo<T: Foo>(a: T) {
a.m();
}
}
mod Second {
trait Bar { fn m(self: std::sync::Arc<Self>); }
fn bar(b: impl Bar) {
b.m();
}
}
The above suggests a trait from another module with a different name
and the next suggestion isn't syntactically correct. |
Current output:
|
@rustbot modify labels to +AsyncAwait-OnDeck This error message comes up a lot when users attempt to manually implement |
Triage: we no longer emit the incorrect suggestions. |
Is the following output acceptable?
|
That wording does indicates the actual problem (hooray!), but it also doesn't feel very newcomer-friendly to me because of the phrase "arbitrary self type". IMO something like " |
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
@estebank Currently this code use core::pin::Pin;
struct S;
impl S {
fn x(self: Pin<&mut Self>) {
}
}
fn main() {
S.x();
} Outputs
Without any hint about there being a method by that name with an unusual receiver type. Not sure whether I should file a new issue or ask for this one to be reopened. |
Also fails to provide a hint on opaque use std::future::Future; //would be necessary to call `poll` if the receiver type was correct
async fn f() {
}
fn foo(cx: &mut std::task::Context) {
f().poll(cx);
} Outputs
|
Triage: no change. Yet another error that needs to be accounted for:
|
Current output for the first comment:
Current output for my comment above (it should suggest
Current output for the previous comment (it doesn't fix the issue because
Current output for the comment prior to that, which I considered solved:
|
Fixed:
Needs to further refine mutability suggested, when using
Gives a suggestion but it doesn't lead to working code:
Fixed
|
``` error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scope --> $DIR/arbitrary_self_type_mut_difference.rs:11:18 | LL | Pin::new(&S).x(); | ^ help: there is a method with a similar name: `y` | note: method is available for `Pin<&mut S>` --> $DIR/arbitrary_self_type_mut_difference.rs:6:5 | LL | fn x(self: Pin<&mut Self>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Related to rust-lang#57994, as one of the presented cases can lead to code like this.
Only outstanding issue is for the |
The code it currently suggests does not even build, so that should definitely be fixed. Here's how fn foo(cx: &mut std::task::Context) {
let mut f = std::pin::pin!(f());
f.as_mut().poll(cx);
} |
@RalfJung I noticed that we already provide an appropriate note on the E0277 to use the
Having said that, between #114654:
and #114469:
I think we can consider this ticket addressed. |
…diff, r=davidtwco Detect method not found on arbitrary self type with different mutability ``` error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scope --> $DIR/arbitrary_self_type_mut_difference.rs:11:18 | LL | Pin::new(&S).x(); | ^ help: there is a method with a similar name: `y` | note: method is available for `Pin<&mut S>` --> $DIR/arbitrary_self_type_mut_difference.rs:6:5 | LL | fn x(self: Pin<&mut Self>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Related to rust-lang#57994, as one of the presented cases can lead to code like this.
…dtwco Suggest `pin!()` instead of `Pin::new()` when appropriate When encountering a type that needs to be pinned but that is `!Unpin`, suggest using the `pin!()` macro. Fix rust-lang#57994.
Rollup merge of rust-lang#114654 - estebank:suggest-pin-macro, r=davidtwco Suggest `pin!()` instead of `Pin::new()` when appropriate When encountering a type that needs to be pinned but that is `!Unpin`, suggest using the `pin!()` macro. Fix rust-lang#57994.
Consider the following piece of code:
The error here is that
test
can only be called onPin<&mut Self>
, sot.test
does not work. But the error message is less than helpful:It suggests I import a trait that is already in scope. This leads down the totally wrong path -- not showing the "help" and "note" at all would be better than this. Ideally it could point out the receiver type mismatch.
The text was updated successfully, but these errors were encountered: