-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Add information about group a lint belongs to #140794
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
base: master
Are you sure you want to change the base?
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
I'm not satisfied with tests for this change, I tried to add clippy ui test, but I wasn't able to do so, because they use |
I gathered my thoughts about possible approaches Possible ApproachesOption 1: Status Quo (No Change)Current behavior:
Pros:
Cons:
Option 2: Group Annotation (Current PR)Example:
Alternatives:
Pros:
Cons:
Option 3: Group Override LintBehavior: #[allow(unused_variables)]
#[allow(unused_imports)] Could trigger a suggestion like: #[allow(unused)] Pros:
Cons:
Option 4: Link to DocumentationExample:
Pros:
Cons:
Questions for Discussion
|
cc @hkBst |
We already have a few tests that are full workspaces/crates (thus have access to A better option, if possible, is to have |
So, about the topic at hand. This current PR feels like it adds a ton of noise for not much benefit tbh, raising awareness for lint groups is -fine- but they aren't really all that commonly needed. Extra noise and confusion just so the user knows about I was going to suggest the alternative of only doing this when the user specifies All that said, clippy adding links to documentation everywhere is quite a bit of noise too.
This will have huge issues in Clippy, whose categories are just for lint levels and aren't really related lints at all. So we do definitely need that opt-out behavior. This should probably be special cased to
This is already done for clippy lints and is pretty standard. These are auto-generated and the same can probably be done in rustc as well. Seems reasonable to me considering prior art. It would be nice if there was something like rustc's error codes index to make this a bit more concise, that is perhaps something to look into if you go down this route. |
sup dawg, I heard you like your linters, so I added a linter for your linter so you can lint your lints while you lint |
// | ||
// Ideally, we'd like to use lints that are part of `unused` group as shown in the issue. | ||
// This is not possible in an ui test, because `unused` lints are enabled with `-A unused` | ||
// in such tests, and the we're testing a scenario with no modification to the default settings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// in such tests, and the we're testing a scenario with no modification to the default settings. | |
// in such tests, and we want to test a scenario with no modification of the default settings. |
Do we want that, or are the default settings the only option here? To be honest, I wonder if this test is necessary at all, given the coverage provided by all the existing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm you may be right, the test in current state doesn't actually test anything better than rest of the tests that capture lint output.
Hi @karolzwolak, I really like your work, and the current PR seems like the most natural option of the proposed alternatives. I think this is a very good way of teaching users about the existence of various lint groups and adds a lot of value to the compiler messages. Let's consider the following program, which contains all three case of individual lint specified, lint group specified, default lint: pub fn unused_var() {
#[warn(unused_variables)]
let x = 5;
}
pub fn unused() {
#[warn(unused)]
let x = 5;
}
pub fn default_() {
let x = 5;
} My proposed change from current (stable) output would be:
This last case with "default", assumes that defaults are lint groups instead of individual lints. I'm not sure that is (always) the case. If this is wrong, then perhaps instead just add this line (like for the first function):
|
In my understanding, individual lints are set on default, and the groups are a way to refer to bunch of lints at the same time, but I could be wrong. However I really like the your suggestions for the messages, and perhaps this slight inaccuracy (if I'm right) is okay here, because it makes the messages consistent. |
I think these messages look great, and might be the way to go, since as @Centri3 pointed out, lint wouldn't work too well in this example. @Centri3 thanks for providing feedback, what do you thing about these messages? EDIT:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as resolved.
This comment was marked as resolved.
bd18376
to
71d486a
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Apologies for my delay in getting back to this, it's looking pretty good, could you rebase and I'll do one last pass? |
71d486a
to
5cce81b
Compare
@GuillaumeGomez the try build succeeded, can we proceed with merging this? It touches a lot of ui tests, so it stales quickly. |
@bors r=davidtwco rollup=iffy |
…, r=davidtwco Add information about group a lint belongs to # Description Fixes: rust-lang#65464 ## Changes Made - Extended the default lint settings message to include the lint group they belong to - Modified the proposed fix message wording from "part of" to "implied by" for better accuracy - Old message: `` `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default `` - New message: `` `#[warn(unused_variables)]` (implied by `#[warn(unused)]`) on by default `` ## Rationale 1. The new wording ("implied by") better reflects the actual relationship between lint groups and their members 2. It maintains consistency with messages shown when manually setting lint levels 3. The change helps users understand the hierarchy of lint settings ## Implementation Notes - Only affects messages for default lint levels (not shown when levels are overridden) - External lints remain unchanged (potential discussion point for future changes) ## Examples ### Case 1: Unchanged behavior when lint level is overridden ```rust #[deny(unused)] fn main() { let x = 5; } ``` Result: ``` note: the lint level is defined here --> src/main.rs:1:8 | 1 | #[deny(unused)] | ^^^^^^ = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` ``` ### Case 2: Changed behavior for default lint levels ```rust fn main() { let x = 5; } ``` New output: ``` = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default ``` Previous output: ``` = note: `#[warn(unused_variables)]` on by default ``` ## Discussion Points - Should we extend this change to external lints as well? - Is "part of" the most accurate terminology? - Doesn't this additional info bloat the message? Perhaps a clippy lint suggesting overriding a whole group instead of a few lints manually would be better
Rollup of 10 pull requests Successful merges: - #140794 (Add information about group a lint belongs to) - #144476 (rustdoc-search: search backend with partitioned suffix tree) - #144838 (Fix outdated doc comment) - #145206 (Port `#[custom_mir(..)]` to the new attribute system) - #145208 (Implement declarative (`macro_rules!`) derive macros (RFC 3698)) - #145420 (cg_llvm: Use LLVM-C bindings for `LLVMSetTailCallKind`, `LLVMGetTypeKind`) - #145451 (Add static glibc to the nix dev shell) - #145460 (Speedup `copy_src_dirs` in bootstrap) - #145476 (Fix typo in doc for library/std/src/fs.rs#set_permissions) - #145485 (Fix deprecation attributes on foreign statics) r? `@ghost` `@rustbot` modify labels: rollup
Failed in rollup: #145517 (comment) @bors r- |
@bors try jobs=x86_64-gnu-aux |
This comment has been minimized.
This comment has been minimized.
Add information about group a lint belongs to try-job: x86_64-gnu-aux
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test for 0478750 failed: CI. Failed jobs:
|
It looks like the cargo tests are only run for the x86_64-gnu-aux target. |
I added a PR that fixes the failing tests in cargo. How do we proceed @davidtwco? |
Yes, we'll need to merge the Cargo PR, and I'll include that in #145478, and wait for the submodule update PR merge, and then this merges. |
…#15849) Needed for [rust-lang/rust#140794](rust-lang/rust#140794) (not merged yet).
Update cargo 28 commits in 840b83a10fb0e039a83f4d70ad032892c287570a..71eb84f21aef43c07580c6aed6f806a6299f5042 2025-07-30 13:59:19 +0000 to 2025-08-17 17:18:56 +0000 - update tests to match lint message changes from #140794 (rust-lang/cargo#15849) - chore: downgrade to [email protected] (rust-lang/cargo#15851) - Reorder `lto` options in profiles.md (rust-lang/cargo#15841) - feat(unstable): add -Zbuild-analysis unstable feature (rust-lang/cargo#15845) - refactor(unstable): group stabilized features (rust-lang/cargo#15846) - Fixes error while running the cargo clippy --all-targets -- -D warning (rust-lang/cargo#15843) - Clarify that `cargo doc --no-deps` is cumulative and won’t delete prev (rust-lang/cargo#15800) - docs: Formatting and cross-linking to build-dir/target-dir docs (rust-lang/cargo#15840) - Stabilize `build.build-dir` (rust-lang/cargo#15833) - make resolve features public for cargo-as-a-library (rust-lang/cargo#15835) - chore(deps): bump slab from 0.4.10 to 0.4.11 (rust-lang/cargo#15832) - chore: remove x86_64-apple-darwin from CI and tests (rust-lang/cargo#15831) - chore(deps): update msrv (3 versions) to v1.87 (rust-lang/cargo#15819) - perf(package): Always reuse the workspace's target-dir (rust-lang/cargo#15783) - More helpful error for invalid cargo-features = [] (rust-lang/cargo#15781) - Add initial integration for `--json=timings` behing `-Zsection-timings` (rust-lang/cargo#15780) - add is_inherited methods to InheritableDependency and InheritableField (rust-lang/cargo#15828) - chore(deps): update compatible (rust-lang/cargo#15804) - docs(unstable): Link out to the Plumbing commands effort (rust-lang/cargo#15821) - chore(deps): update cargo-semver-checks to v0.43.0 (rust-lang/cargo#15825) - test(build-std): relax the thread name assertion (rust-lang/cargo#15822) - chore(deps): update msrv (1 version) to v1.89 (rust-lang/cargo#15815) - Update semver tests for 1.89 (rust-lang/cargo#15816) - Accessing each build script's `OUT_DIR` and in the correct order (rust-lang/cargo#15776) - chore: bump to 0.92.0; update changelog (rust-lang/cargo#15807) - docs: `-Zpackage-workspace` has been stabilized (rust-lang/cargo#15808) - chore(deps): update rust crate cargo_metadata to 0.21.0 (rust-lang/cargo#15795) - docs(build-rs): Fix broken intra-doc links (rust-lang/cargo#15810)
Update cargo 28 commits in 840b83a10fb0e039a83f4d70ad032892c287570a..71eb84f21aef43c07580c6aed6f806a6299f5042 2025-07-30 13:59:19 +0000 to 2025-08-17 17:18:56 +0000 - update tests to match lint message changes from #140794 (rust-lang/cargo#15849) - chore: downgrade to [email protected] (rust-lang/cargo#15851) - Reorder `lto` options in profiles.md (rust-lang/cargo#15841) - feat(unstable): add -Zbuild-analysis unstable feature (rust-lang/cargo#15845) - refactor(unstable): group stabilized features (rust-lang/cargo#15846) - Fixes error while running the cargo clippy --all-targets -- -D warning (rust-lang/cargo#15843) - Clarify that `cargo doc --no-deps` is cumulative and won’t delete prev (rust-lang/cargo#15800) - docs: Formatting and cross-linking to build-dir/target-dir docs (rust-lang/cargo#15840) - Stabilize `build.build-dir` (rust-lang/cargo#15833) - make resolve features public for cargo-as-a-library (rust-lang/cargo#15835) - chore(deps): bump slab from 0.4.10 to 0.4.11 (rust-lang/cargo#15832) - chore: remove x86_64-apple-darwin from CI and tests (rust-lang/cargo#15831) - chore(deps): update msrv (3 versions) to v1.87 (rust-lang/cargo#15819) - perf(package): Always reuse the workspace's target-dir (rust-lang/cargo#15783) - More helpful error for invalid cargo-features = [] (rust-lang/cargo#15781) - Add initial integration for `--json=timings` behing `-Zsection-timings` (rust-lang/cargo#15780) - add is_inherited methods to InheritableDependency and InheritableField (rust-lang/cargo#15828) - chore(deps): update compatible (rust-lang/cargo#15804) - docs(unstable): Link out to the Plumbing commands effort (rust-lang/cargo#15821) - chore(deps): update cargo-semver-checks to v0.43.0 (rust-lang/cargo#15825) - test(build-std): relax the thread name assertion (rust-lang/cargo#15822) - chore(deps): update msrv (1 version) to v1.89 (rust-lang/cargo#15815) - Update semver tests for 1.89 (rust-lang/cargo#15816) - Accessing each build script's `OUT_DIR` and in the correct order (rust-lang/cargo#15776) - chore: bump to 0.92.0; update changelog (rust-lang/cargo#15807) - docs: `-Zpackage-workspace` has been stabilized (rust-lang/cargo#15808) - chore(deps): update rust crate cargo_metadata to 0.21.0 (rust-lang/cargo#15795) - docs(build-rs): Fix broken intra-doc links (rust-lang/cargo#15810)
Description
Fixes: #65464
Changes Made
`#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
`#[warn(unused_variables)]` (implied by `#[warn(unused)]`) on by default
Rationale
Implementation Notes
Examples
Case 1: Unchanged behavior when lint level is overridden
Result:
Case 2: Changed behavior for default lint levels
New output:
Previous output:
Discussion Points