Skip to content
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

Show warnings for unused variables #125

Closed
aochagavia opened this issue Oct 11, 2018 · 6 comments
Closed

Show warnings for unused variables #125

aochagavia opened this issue Oct 11, 2018 · 6 comments
Labels

Comments

@aochagavia
Copy link
Contributor

Right now Rust Analyzer doesn't give much feedback while writing code. There is no autocompletion and you get only syntax errors. I was thinking about a good first step toward giving more feedback and came to the idea of showing warnings for unused variables. This should be doable by reusing resolve_local_name, which was defined in #98

In the future we will probably want to extend this to detect unused struct fields, types and other stuff. But we need to begin with something.

@aochagavia
Copy link
Contributor Author

@matklad is it a problem to keep adding things while you are migrating everything to salsa?

@aochagavia
Copy link
Contributor Author

@matklad I would like to pick up this issue, but I am having trouble finding the right place to implement it. Do you have any suggestions? Tackling this means working at #27 as well, so a bit of mentoring would be greatly appreciated.

@matklad
Copy link
Member

matklad commented Oct 30, 2018

Oups, sorry, I've somehow missed all three comments on the issue :(

I think that we already can detect unused fields, yeah. There might be false-positives due to macros, but they should be rate, and we can hack around them (var is used in a macro if macro's text contains var name), for example.

The migration to salsa is mostly complete.

Do you have any suggestions?

So, #27 is an unrelated issue: validators are purely for checking syntax (in general, we try to remove checks for the parser per se to make it more tolerant to the errors).

I think the right place for this is near the resolve_local_name. So, something like

fn collect_unused_variables(
    fn_def: ast::FnDef
    scopes: &FnScopes
) -> Vec<ast::Name> {
}

should work.

@skade
Copy link
Contributor

skade commented Apr 14, 2020

Is this issue still current?

Peek 2020-04-14 17-38

Highlighting unused variables exists.

@lnicola
Copy link
Member

lnicola commented Apr 14, 2020

It works by running cargo check and displaying its diagnostics, but it's not implemented natively in rust-analyzer. That might still happen, but probably not in the near future.

@matklad matklad added the E-hard label Apr 15, 2020
@matklad
Copy link
Member

matklad commented Jul 15, 2020

Ok, so this is handled by cargo check. Native handling is desirable, but then this issue is indistinguishable from "implement the rest of the owl compiler", so it's not useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants