-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Auto completion should use fully qualified syntax in case of ambiguity #18895
Comments
The code completed is correct, why should we prefer UFCS? |
I think the point is that we should use UFCS if the user picks a trait method that's shadowed by an inherent one? |
Ah yes sorry, I thought there wasn't ambiguity. |
This issue can also be observed from methods with fn main() {
trait Pilot {
fn fly(&self);
}
trait Wizard {
fn fly(&self);
}
struct Human;
impl Pilot for Human {
fn fly(&self) {
println!("This is your captain speaking.");
}
}
impl Wizard for Human {
fn fly(&self) {
println!("Up!");
}
}
let person = Human;
// Try typing: `person.f`, and RA will suggest: `fly()` (as `Wizard`)
// Note that it doesn't provide suggestion for (as `Pilot`)
// When I accept the auto-completion, it gave me:
person.fly(); // `rustc` would complain: multiple applicable items in scope
// The expected behavior should be suggesting all applicable items:
// 1. `fly()` (as `Wizard`)
// 2. `fly()` (as `Pilot`)
// And use the following syntax to avoid ambiguity:
Pilot::fly(&person);
Wizard::fly(&person);
} |
Note that we have some construction logic for this in the qualify assist (so there should be possibility of code sharing for the completions) |
@rustbot claim |
rust-analyzer version:
0.3.2257-standalone
rustc version:
1.83.0
(90b35a623
2024-11-26)editor or extension: VSCode, with
[email protected]
relevant settings: N/A
repository link (if public, optional): N/A
code snippet to reproduce:
The text was updated successfully, but these errors were encountered: