You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/3926-custom-lint-profiles.md
+14-2Lines changed: 14 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,13 +47,13 @@ There are multiple ways that lint levels can be toggled in modern Rust. For the
47
47
- This **can** be easily tweaked at runtime
48
48
- This **is always** shared between crates
49
49
- Changing this invalidates the entire build
50
-
- In the CLI, by means of `RUSTFLAGS=-Dwarnings` or `CARGO_BUILD_WARNINGS=deny`
50
+
- In the CLI, by means of `RUSTFLAGS=-Dwarnings`, `build.warnings`, or `CARGO_BUILD_WARNINGS=deny`
51
51
- This **does not** support use with `cfg`
52
52
- This **does not** allow fine grained control over code sections
53
53
- This **does not** allow fine grained control over individual lints
54
54
- This **can** be easily tweaked at runtime
55
55
- This **is always** shared between crates
56
-
- Changing RUSTFLAGS invalidates the entire build, but `CARGO_BUILD_WARNINGS`does not invalidate anything.
56
+
- Changing RUSTFLAGS invalidates the entire build, but `CARGO_BUILD_WARNINGS`and `build.warnings` do not invalidate anything.
57
57
- In the CLI, by choosing to call `cargo clippy`
58
58
- (This is technically a modality too)
59
59
- This usually rebuilds the workspace.
@@ -83,10 +83,13 @@ In essence, lints can have different effects in different contexts.
83
83
## Lint modalities and their use cases
84
84
85
85
Overall, it's quite common in codebases to want to have different "modes" for lints for the different contexts a linter might be run in.
86
+
86
87
### Deny in CI
87
88
88
89
The most common use case is wanting to have the codebase be lint-free but not hinder development while hacking on something, but have the lints gate landing on `main`. Workflows around this typically involve running CI with `-Dwarnings` (or the new `CARGO_BUILD_WARNINGS=deny`), with contributors often running `cargo check` / `cargo clippy` locally and ensuring they are warnings-clean before opening a PR.
89
90
91
+
Note that while this is very common, a downside of this approach is that it's not always clear what the "severity" of a check is: warnings showing errors may make a newer contributor think they *have* to do the steps mentioned in the warning, rather than potentially silencing the lint or choosing another approach.
92
+
90
93
### Noisier PR-integrated linters or IDEs
91
94
92
95
If using a PR-integrated CI linter, your bar for non-blocking noisy informative lints can be lower since the linter will only flag things in code touched by the current PR. One may wish to enable far more pedantic lints in such CI.
This creates a profile that inherits from the default profile, but with all warnings replaced with hard errors, and further tweaks to some other lints.
248
251
252
+
Note that profiles cannot inherit from profiles defined in the workspace without first inheriting the to-be-inherited profile from the workspace with `lints.profile.foo.workspace = true`.
253
+
249
254
This has no impact on lint levels specified in the source code, or warnings that come from places other than the warning system (in other words, this does not apply `-Dwarnings`)
250
255
251
256
@@ -507,6 +512,7 @@ Should using this feature require an MSRV bump? Technically crates consuming you
507
512
# Future work
508
513
509
514
515
+
510
516
## Custom lint groups
511
517
512
518
@@ -519,6 +525,12 @@ A thing this feature does *not* let one do is toggle multiple lints at once in c
519
525
It's not yet clear to me how feasible this is, or if we should have such a feature, but it's worth listing.
520
526
521
527
528
+
## Better diagnostics for warn-to-deny lints
529
+
530
+
The inheritance model proposed here, when inheriting a profile as warn-to-deny, does not retain memory of the lint originally being "warn".
531
+
532
+
In theory, rustc could choose to display `deny` and `warn`-but-`-Dwarnings` lints differently. If it wishes to do that, `inherits = {profile = "default", warn = "deny"}` may also need a way to retain memory of the original lint level. This is an interesting avenue to investigate but somewhat out of scope for this RFC.
533
+
522
534
## Teaching lints
523
535
524
536
In the past people wished for tooling that produces lints that potentially tell new users about subtleties in their code, subtleties that are not really *problems* to be fixed, but interesting things to be noted. These would be opted in to by individual users and as they get used to a concept, disabled globally one by one. Lint profiles allow one to better handle toggles like this, but it is not in an of itself a major step in this direction.
0 commit comments