-
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
Incorrect function deduced with same name as correct function #16444
Comments
Here's a quite absurd example that illustrates how it makes it hard to work with: The code above boils down to: let skippable = solution.history.iter().position(|h| [...]).unwrap_or(1); where In the middle of this lambda, I'd originally written |
Probably another instance of rust-lang/chalk#727 or rust-lang/chalk#750; it will probably get fixed with the new trait solver (and not before). |
@flodiebold is there a tracking issue or something that we can follow for progress on the new trait solver? |
Another quirk of this issue: when I call a trait function that is being incorrectly deduced and giving the error about wrong number of arguments, changing the name of the trait function being called without changing the callsite will result in a rustc compiler error while simultaneously claiming it's the other function. I realized after a moment or two that these are errors from separate tools so it's not quite one part of rust-analyzer being right wile the other is wrong. |
This seems to be a regression of #11048, and honestly, it's been a problem on and off for all of 2023.
In code like:
where
scores
is aVec<Option<u32>>
, rust-analyzer may assume that.min
refers to a trait function defined incore::cmp::Ord
(pub fn min(self, other: Self) -> Self
) while the actual function in question is theIterator
trait function, which takes 0 additional arguments. The result is that VSCode complains that my code will not compile, but there is no problem with it.The code is annotated like this:
which is incorrect in the last line (but at least consistent with the assumption that the appropriate min is a comparison to another Iterator).
This also occurs with traits defined in the current crate.
https://github.com/Zannick/logic-graph/blob/0cb411f89d36507e1f459599044725f43ca4669d/analyzer/src/condense.rs#L303
Changing
Exit::dest(e)
here toe.dest()
results in rust-analyzer believing that this function isAction::dest
. These trait functions have the same name but different arguments; Action is the first trait alphabetically in the same file as Exit that has adest
function.After a rustup update and a restart of VSCode, the problem went away for these two examples but appeared elsewhere:
warp.dest(ctx.get(), world)
reports an error because rust-analyzer believes this refers toExit::dest
. rust-analyzer describes the type ofwarp.dest(ctx.get(), world)
when I highlight it as<<W as World>::Warp as Exit>::SpotId
. It annotateswarp
correctly as&<W as World>::Warp
; the function has a type restriction on that associated type pointing to the correct trait with adest
function:W::Warp: Warp
, so I'm not sure where this analysis can conclude thatExit
trait functions can be invoked onwarp
.rust-analyzer version:
rust-analyzer version: 0.3.1823-standalone (7219414e8 2024-01-27)
rustc version: (as run from the VSCode terminal)
rustc 1.74.0 (79e9716c9 2023-11-13)
, after rustup updaterustc 1.75.0 (82e1608df 2023-12-21)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTC
,RUSTUP_HOME
orCARGO_HOME
)The text was updated successfully, but these errors were encountered: