-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Failed Type Annotations in For Loops #13395
Comments
Are these functions annotated with an attribute by any chance? |
What type is |
dataset is a |
Does this occur for any for loop? Does it work for |
I tried It does not work in existing one, which prompted this post. It does work in other projects. Its just the one. |
@RylanYancey Are you able to narrow this down to a minimal project that you can share? |
I'm seeing the same thing. It uses whatever type it can infer from how the variable is used inside the loop body. For this example, hovering over name will show the type as {unknown}.
By passing it to a function, it's given the type of the function argument. In this example, hovering now shows name as a String.
In this last example, hovering shows name as a usize. Along with a compiler error saying that's incorrect.
|
We can't do anything here unless we get a proper reproduction + server logs that may help us here. |
Apparently it's caused by having my own "core" library in my workspace. My top level Cargo.toml looks like,
in runner/Cargo.toml I have core as a dependency,
If I rename that library, or remove the dependency, then the behavior goes away. |
using core as the name for a library is bad choice in general, as it clashes with the standard libraries core (r-a is particularly bad at handling this, but other tools aren't too fond of it either) |
Replace SmolStr usage with lang item enum for lang items Fixes #13395
** Rust-Analyzer Version:** 0.3.1238-standalone
** Rustc Version:** rustc 1.64.1 (a55dd71d5 2022-09-19)
Rust-Analyzer fails to provide type annotations for variables in loops, giving them the
{unknown}
type.Example 1:
Example 2:
Issue persists after reinstalling rust-analyzer, restarting VSCode, and restarting my computer. RA successfully identifies the types of other variables.
The text was updated successfully, but these errors were encountered: