-
Notifications
You must be signed in to change notification settings - Fork 1.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
Assist/Quickfix for converting method call to function call syntax #13247
Comments
This is somewhat similar to #12497. So I think this issue should track the diagnostic side of things? |
seems there has a diagnostic and quickfix from rustc side
|
after apply the quickfix, I think there isn't necessary to make a same diagnostic in rust-analyzer side, maybe this issue can be close? cc @jonas-schievink, @Veykril |
No, ultimately we want to have every rustc diagnostic in r-a as well, as relying on cargo check is slow and cumbersome. |
Is there any feature else that r-a rely on Same feature in r-a and rustc have their respective implementation, seems a maintenance pressure. It would be nice if these feature could be extract into a crate and be use in different project (there maybe some historical reasons which I don't know quite well, like different AST, parser or something else, causing this phenomenon) |
In an ideal world we could plug rustc's diagnostics into r-a / share them with r-a, but that is unlikely to ever be feasible, so we'll try to implement the most useful ones ourselves at least. In case of this issue, note that we already have an assist for this https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/qualify_method_call.rs, so diagnosing this error we could re-use the assist functionality for the diagnostic quickfix (as the assist itself does not trigger on these incorrect method calls). |
|
Oh ye sorry, I meant adjusting the common functionality to be able to figure this invalid case out as well (via a toggle). Then the assist should stick to keep working only on valid ones, while the diagnostic will expose a quickfix for the invalid case. |
Sorry, I don't quite understand, via a toggle? Could you be more specific?
struct A {}
impl A {
fn hello() {}
}
fn main() {
let a = A{};
a.hello$0();
}
|
Right, its not the simple. I see two options here:
Regarding the latter option, you'd need to "retry" resolution in the diagnostic branch here rust-analyzer/crates/hir-ty/src/infer/expr.rs Lines 1484 to 1507 in 2ee17bc
method_resolution::iterate_method_candidates with method_resolution::LookupMode::Path similar to how its done in rust-analyzer/crates/hir-ty/src/infer/path.rs Lines 314 to 332 in 2ee17bc
|
@rustbot claim |
It's not uncommon to accidentally write code like this:
But
Box::into_raw
is an associated function, not a method. It would be nice to detect this and offer an assist. A diagnostic + quickfix would also be possible (though maybe there's some use case in converting this, even if it is a method, in which case it should probably be a normal assist?)The text was updated successfully, but these errors were encountered: