Add a fix that inserts a missing method#19950
Add a fix that inserts a missing method#19950MatrixFrog wants to merge 8 commits intorust-lang:masterfrom
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
| } | ||
|
|
||
| #[test] | ||
| fn test_add_method_fix_ref_self() { |
There was a problem hiding this comment.
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.
Haven't yet tested cases with &mut SomeType but probably need to handle that too.
Veykril
left a comment
There was a problem hiding this comment.
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)
7f05496 to
6f77fd3
Compare
…d that this only works on T's not &T's
d98b4ab to
b59a82d
Compare
| .enumerate() | ||
| .map(|(i, ty)| { | ||
| let name = format!("arg{}", i + 1); | ||
| let ty = ty.display_source_code(db, module_id.into(), true).unwrap(); |
There was a problem hiding this comment.
this unwrap panicked on some real code. if there's an error just put in '()' or something for the type
|
☔ The latest upstream changes (possibly #21804) made this pull request unmergeable. Please resolve the merge conflicts. |
|
We've temporarily suspended acceptance of new assists due to lack of bandwidth. They may be accepted in the future, perhaps even without code changes. |
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_deadmethod.&selfbut maybe we can figure out whether it should beselfor&mut selfinstead?let lhs: SomeType = dog.play_dead()todo!()orunimplemented!()or something else? What is the most consistent with how r-a does things elsewhere?