Skip to content

Prefer clauses from the environment #584

@flodiebold

Description

@flodiebold

The following code compiles in rustc:

fn f<T: Into<String>>(u: T) {
    let x = u.into();
    x.as_str();
}

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 of x because the T: Into<?> goal is ambiguous. Note that if we have a struct S that impls Into<String> instead of the type parameter T, 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions