-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add a fix that inserts a missing method #19950
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
base: master
Are you sure you want to change the base?
Conversation
There is a config for what to insert in e.g. fill match arms, I think it's appropriate to use it here as well. |
6e541ae
to
4d54aab
Compare
…d that this only works on T's not &T's
@@ -289,6 +333,117 @@ fn main() { | |||
); | |||
} | |||
|
|||
#[test] | |||
fn test_add_method_fix_ref_self() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test currently fails. we're calling a non-existent method on &Dolphin
(not Dolphin
) so no fix is generated. In such a case we should look for an impl Dolphin
block and add a method that takes &self
, or look for an impl &Dolphin
block and add a method that takes self
. What if both exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't yet tested cases with &mut SomeType
but probably need to handle that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an assist that can create functions from unresolved ones,
// ``` |
Naturally, that should turn into a diagnostic in the long run (when we have more confident diagnostics for this).
Would be good to deduplicate code here, especially as the assist already supports this use case better (being signature aware)
Work in progress! Not ready for review yet.
Often I will call a method even though I know it doesn't exist yet, because I'm planning to add that method.
This PR adds a fix that inserts a stub for the
play_dead
method.&self
but maybe we can figure out whether it should beself
or&mut self
instead?let lhs: SomeType = dog.play_dead()
todo!()
orunimplemented!()
or something else? What is the most consistent with how r-a does things elsewhere?