-
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
rust-analyzer seems to be getting confused between trait methods and inherent methods #17233
Comments
This seems like a problem with chalk, I traced it to this
Which here should return EDIT: The goal that's sent to chalk: |
Probably rust-lang/chalk#750 or rust-lang/chalk#727. |
…uments, found 1 Also fixes rust-lang#17233 The issue occurs because in some configurations of traits where one of them has Deref as a supertrait, RA's type inference algorithm fails to fully resolve a trait's self type, and instead uses a TyKind::BoundVar. This then erroneously matches with types that do not implement the trait. In other words, unconnected types appear to inherit the trait's methods. The fix is to insert a heuristic when invoking lookup_method() that allows the caller to determine if the returned method is a good match. If the returned method would result in diagnostic errors, the caller instructs the algorithm to continue iterating the possible methods to see if a better one exists (i.e. one that won't result in diagnostic errors). Includes a unit test that only passes after applying the fixes in this commit.
…uments, found 1 Also fixes rust-lang#17233 The issue occurs because in some configurations of traits where one of them has Deref as a supertrait, RA's type inference algorithm fails to fully resolve a trait's self type, and instead uses a TyKind::BoundVar. This then erroneously matches with types that do not implement the trait. In other words, unconnected types appear to inherit the trait's methods. The fix is to insert a heuristic when invoking lookup_method() that allows the caller to determine if the returned method is a good match. If the returned method would result in diagnostic errors, the caller instructs the algorithm to continue iterating the possible methods to see if a better one exists (i.e. one that won't result in diagnostic errors). Includes a unit test that only passes after applying the fixes in this commit.
…uments, found 1 Also fixes rust-lang#17233 The issue occurs because in some configurations of traits where one of them has Deref as a supertrait, RA's type inference algorithm fails to fully resolve a trait's self type, and instead uses a TyKind::BoundVar. This then erroneously matches with types that do not implement the trait. In other words, unconnected types appear to inherit the trait's methods. The fix is to insert a heuristic when invoking lookup_method() that allows the caller to determine if the returned method is a good match. If the returned method would result in diagnostic errors, the caller instructs the algorithm to continue iterating the possible methods to see if a better one exists (i.e. one that won't result in diagnostic errors). Includes a unit test that only passes after applying the fixes in this commit.
rust-analyzer version: rust-analyzer 1.78.0 (9b00956 2024-04-29)
Can also reproduce with rust-analyzer 1.80.0-nightly (ab14f94 2024-05-13)
rustc version: rustc 1.78.0 (9b00956e5 2024-04-29)
editor or extension: Neovim 0.9.5
relevant settings:
CARGO_HOME
is set to$HOME/.local/share/cargo
RUSTUP_HOME
is set to$HOME/.local/share/rustup
code snippet to reproduce:
Note that the above code does compile.
The text was updated successfully, but these errors were encountered: