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
INT: Support "Create associated function" for path Self::func()
#9335
Conversation
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.
Could it also work with <this struct>::Foo
? For example:
struct Foo;
impl Foo {
fn foo() {
Foo::bar();
}
// create fn bar() {}
}
Maybe we could just always detect/find an existing impl block and use it if it's available? That seems like it could unify the "OtherType::foo()", "::foo()" and "Self::foo()" use-cases.
|
||
is RsStructOrEnumItemElement -> { | ||
text = "Create associated function `${target.name}::$name`" | ||
Context.AssociatedFunction(functionCall, name, target.containingMod, target, existingImpl = null) |
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.
It looks like in the current usage, existingImpl
and item
are exclusive? It could be modeled by some enum, but it's probably overkill.
It already works but creates new impl. As you said, it would be nice to find an existing impl, and I plan to do it next. Btw for |
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.
Ok, in that case LGTM :)
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.
LGTM. Regarding this intention in general, I noticed that it does not reuse existing impl
blocks when generating new associated functions or methods, e.g.:
struct S;
impl S {
fn foo() {}
}
// new `impl S` block for `bar` will be added instead of reusing the previous one
fn foo() {
S::bar/*caret*/(1, 2);
}
IMO it would be nice if the intention could avoid generating unnecessary impl
blocks in such cases, for example when there is only one existing impl
block located in the same file. @dima74 WDYT?
Yeah I plan to do this next |
bors r=ortem |
Build succeeded: |
Judging by the tests, this is the expected behavior, but I opened the issue before looking at the tests :D |
changelog: Support
Create associated function
intention for pathSelf::func()