rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.62k stars 1.49k forks source link

Borrow<T> leads to T being unknown in a generic blanket impl #17170

Closed sunrosa closed 3 days ago

sunrosa commented 2 weeks ago

I am using rust-analyzer VScode extension v0.3.1940 and rustc 1.77.2. I am having this issue with borrow(). With the impl below: image

It is resolving to unknown and not linting, but has no compiler errors: image

And of course, there is no linting when trying to access fields of the unknown type.

Kohei316 commented 1 week ago

@rustbot claim

DavidArchibald commented 3 days ago

I believe I've run into this issue as well. Here's my own reproduction:

fn broken_into_inference(into_string: impl Into<String>) {
    let should_be_string = into_string.into();

    should_be_string.len();
}

should_be_string is displayed with a type of {unknown} and the documentation for stuff like len won't show up. Using the wrong methods still shows up as an error but I think that's because of a rustc pass or something.

I'm going to assume the root cause is the same, hence why this isn't its own issue. I just want to make sure it gets looked at alongside this reproduction, just in case the root causes are different.

flodiebold commented 3 days ago

Both of these are cases of #5514.