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

Default lints should correspond to rustc #16628

Open
dhardy opened this issue Feb 21, 2024 · 8 comments
Open

Default lints should correspond to rustc #16628

dhardy opened this issue Feb 21, 2024 · 8 comments
Labels
A-diagnostics diagnostics / error reporting C-support Category: support questions

Comments

@dhardy
Copy link

dhardy commented Feb 21, 2024

Summary

I would expect that rust-analyzer, with default settings, would report the same lints (warnings, errors, etc.) as rustc

Details

Currently this is not the case; for example I also see messages about these:

  • inactive-code — this may have a special purpose in some editors? In Kate it's more annoying than useful, but that may be just Kate.
  • remove-unnecessary-else — nearest equivalent is Clippy's redundant_else?

The default enabled lints also do not correspond to Clippy's default lints (there is a note in the manual about enabling Clippy by default).

Motivation

I would (naively) expect that a project which is clean (reports no lints) under cargo check is also clean under rust-analyzer, and vice-versa. This makes it easier for developers using different tools to collaborate on a project.

Further motivation: the rust-analyzer project should probably not be responsible for choosing which lints are enabled by default (especially when both rustc and clippy already do this).

@dhardy dhardy added the C-support Category: support questions label Feb 21, 2024
@flodiebold
Copy link
Member

These lints are all "WeakWarning" level, which VSCode shows in a very inconspicuous way, just some dots to give a hint you can do something there; the inactive-code is also marked as unused, which makes it be shown still differently, just darkening the code a bit:
2024-02-22-110848_379x393_scrot
In general I agree that for warnings/errors we emit that emulate corresponding rustc/clippy ones we should honor their lint settings, and we aren't quite there yet. These hints are a different category though.

@dhardy
Copy link
Author

dhardy commented Feb 22, 2024

The specification doesn't list a "WeakWarning" level. I think non-standard extensions should be either disabled by default or gated to editors known to support them?

Or is the LSP standard too dated to be useful now (but surely it should also correspond to what VSCode supports since they're both MS products)?

(This should probably be forked to a new issue.)


That very inconspicuous hint sounds fine for inactive-code. Given that this is not a critique of the code but merely a notification of the current configuration, it does make sense that this is part of rust-analyzer and not rustc or Clippy.

The remove-unnecessary-else lint though, I still don't think should be here: it's a pedantic style lint, and thus falls into Clippy's remit.

@flodiebold
Copy link
Member

Sorry, we apparently call "WeakWarning" what's called "Hint" on the LSP level. It's not a non-standard extension.

@flodiebold
Copy link
Member

I don't know. I think these hints are more intended as "there's a useful thing to do here", not necessarily that there's something wrong. And you might not be using Clippy at all, so I don't think we should only go by what's enabled for Clippy. OTOH we should probably honor if a similar lint is explicitly disabled for Clippy.

@dhardy
Copy link
Author

dhardy commented Feb 22, 2024

"there's a useful thing to do here"

This is very opinionated (the "useful" part). Your example above (where the else block is empty) is suspicious, and Clippy reports needless_else. cargo check doesn't report this, presumably because it ignores comments and there could be a comment there (which is enough to suppress the Clippy warning). My motivating example had code in the else block, at which point removal of the else is a stylistic change:
image

More generally,

  • rustc mostly tries not to be opinionated beyond concerns of correctness and safety (with some exceptions, e.g. CamelCase names).
  • Clippy is intentionally an opinionated tool (concerning style, potentially-confusing patterns and more). Some projects use it, some use it with customized lints, some don't use it at all.
  • rust-analyzer, as a tool intended for usage everywhere, should (in my opinion) be minimally opinionated to minimize the difference in experience between those who use it and those who don't.

There is a counter-argument that certain things should be hinted by rustc if there were a minimally-conspicious way of doing so, and thus rust-analyzer can pick up these missing hints. If that is what you are going for, then these hints should be minimally opinionated.

@flodiebold
Copy link
Member

Why would we want to "minimize the difference in experience between those who use [rust-analyzer] and those who don't"? You can always turn off any of these diagnostics using the rust-analyzer.diagnostics.disabled setting, so you can configure the experience to your personal liking.

@dhardy
Copy link
Author

dhardy commented Feb 23, 2024

Sorry, I mean to minimize the difference in reported lints, so that usage of rust-analyzer is an individual decision, not a project-level decision.

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Feb 28, 2024
bors added a commit that referenced this issue Mar 4, 2024
minor: Mark remove_unnecessary_else as experimental

cc #16566 (comment) #16628

There seem to be some leftover issues with this, additionally its a style lint so it's not too nice to see for some people. We should flesh out our diagnostics stuff before adding more style lints I think
bors added a commit that referenced this issue Mar 5, 2024
fix: Put style lints behind disabled-by-default config

Fixes #16542
Fixes #16725
cc #16628

Our diagnostic infra is not yet setup for those kinds of diagnostics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

3 participants