-
Notifications
You must be signed in to change notification settings - Fork 181
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
Prefer clauses from the environment #584
Comments
Yeah, the plan for chalk was to try and push a "more pure" approach, where we would consider it ambiguous, but return "guidance", and leave it up to the rust-analyzer to decide when to apply that guidance. |
I would definitely prefer to try this approach (guidance) before anything else, it's great that we can use rust-analyzer to see how well it works. |
So, would this be something like |
Hello @nikomatsakis, I've done a little investigation on the interation of Rust Analyzer with Chalk to infer types. But it would be great to have a confirmation if I'm following the right way. Rust Analyzer utilizes the unification via |
@nikomatsakis I disagree with the "more pure"/"guidance" approach. IMHO chalk should try its best to match what ructc would do in this situation. In this case, that would be to eagerly infer that For example, this same principle applies to my use case: mod some_lib {
pub fn a_to_b(b_compat: &(impl Into<String> + Clone)) -> impl Into<String> {
b_compat.clone()
}
}
fn main() {
let a = "8";
let b = some_lib::a_to_b(&a).into(); // this is type String but rust-analyzer says the type is {unknown}
let c = b.replace("8", "9");
println!("b = {}, c = {}", b, c);
}
|
The following code compiles in rustc:
This works even though there are other (blanket) impls that could apply for the
into()
call. rust-analyzer on the other hand can't resolve the type ofx
because theT: Into<?>
goal is ambiguous. Note that if we have a structS
that implsInto<String>
instead of the type parameterT
, we get an ambiguity error (see this playground).This works because rustc eagerly selects clauses from the environment, before looking at other impls. I think the old recursive solver actually handled this, but we removed the code because we didn't have / come up with a test case for it.
(CC rust-lang/rust-analyzer#5514)
The text was updated successfully, but these errors were encountered: