-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cleanup linting system #13797
Cleanup linting system #13797
Conversation
r? @weihanglo rustbot has assigned @weihanglo. Use |
gctx: &GlobalContext, | ||
) -> CargoResult<()> { | ||
let manifest = pkg.manifest(); | ||
let lint_level = IM_A_TEAPOT.level(lints, manifest.edition()); |
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.
IM_A_TEAPOT
should be an unstable lint that we hide (when it comes to that)
let edition_level = self | ||
.edition_lint_opts | ||
.filter(|(e, _)| edition >= *e) | ||
.map(|(_, l)| l); | ||
|
||
if self.default_level == LintLevel::Forbid || edition_level == Some(LintLevel::Forbid) { | ||
return LintLevel::Forbid; | ||
} | ||
|
||
let level = self | ||
.groups | ||
.iter() | ||
.map(|g| g.name) | ||
.chain(std::iter::once(self.name)) | ||
.filter_map(|n| lints.get(n).map(|l| (n, l))) | ||
.max_by_key(|(n, l)| (l.priority(), std::cmp::Reverse(*n))); | ||
.max_by_key(|(n, l)| { | ||
( | ||
l.level() == TomlLintLevel::Forbid, | ||
l.priority(), | ||
std::cmp::Reverse(*n), | ||
) | ||
}); | ||
|
||
match level { | ||
Some((_, toml_lint)) => toml_lint.level().into(), | ||
None => { | ||
if let Some((lint_edition, lint_level)) = self.edition_lint_opts { | ||
if edition >= lint_edition { | ||
return lint_level; | ||
} | ||
if let Some(level) = edition_level { | ||
level | ||
} else { | ||
self.default_level | ||
} | ||
self.default_level | ||
} |
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.
The implementation for default and edition exists in two places. We should do this in one place.
☀️ Test successful - checks-actions |
Update cargo 9 commits in c9392675917adc2edab269eea27c222b5359c637..b60a1555155111e962018007a6d0ef85207db463 2024-04-23 19:35:19 +0000 to 2024-04-26 16:37:29 +0000 - fix(toml): Remove underscore field support in 2024 (rust-lang/cargo#13804) - fix: emit 1.77 syntax error only when msrv is incompatible (rust-lang/cargo#13808) - docs(ref): Index differences between virtual / real manifests (rust-lang/cargo#13794) - refactor(toml): extract dependency-to-source-id to function (rust-lang/cargo#13802) - Add where lint was set (rust-lang/cargo#13801) - fix(toml): Don't double-warn when underscore is used in workspace dep (rust-lang/cargo#13800) - fix(toml): Be more forceful with underscore/dash redundancy (rust-lang/cargo#13798) - Fix warning suppression for config.toml vs config compat symlinks (rust-lang/cargo#13793) - Cleanup linting system (rust-lang/cargo#13797) r? ghost
Update cargo 9 commits in c9392675917adc2edab269eea27c222b5359c637..b60a1555155111e962018007a6d0ef85207db463 2024-04-23 19:35:19 +0000 to 2024-04-26 16:37:29 +0000 - fix(toml): Remove underscore field support in 2024 (rust-lang/cargo#13804) - fix: emit 1.77 syntax error only when msrv is incompatible (rust-lang/cargo#13808) - docs(ref): Index differences between virtual / real manifests (rust-lang/cargo#13794) - refactor(toml): extract dependency-to-source-id to function (rust-lang/cargo#13802) - Add where lint was set (rust-lang/cargo#13801) - fix(toml): Don't double-warn when underscore is used in workspace dep (rust-lang/cargo#13800) - fix(toml): Be more forceful with underscore/dash redundancy (rust-lang/cargo#13798) - Fix warning suppression for config.toml vs config compat symlinks (rust-lang/cargo#13793) - Cleanup linting system (rust-lang/cargo#13797) r? ghost
Error when unstable lints are specified but not enabled In [#13797, it was noted that](#13797 (comment)) the `im-a-teapot` lint should always be unstable. This PR makes it so that `im-a-teapot` is unstable, and it is an error to specify it without the `test-dummy-unstable` cargo feature. It does this by adding a `feature-gate` field to `Lint` and `LintGroup` that optionally puts the lint/lint group behind a feature. The `feature-gate` is then checked during the new `analyze_cargo_lints_table` step that runs across all lints (and groups) specified in `[lints.cargo]` or `[workspace.lints]` if the package is inheriting its lints from a workspace. The error looks like the following: No inherit ![No inherit](https://github.com/rust-lang/cargo/assets/23045215/c245af87-8623-42dc-9652-be461809bb30) Inherited ![Inhrtited](https://github.com/rust-lang/cargo/assets/23045215/5a90b7c9-0e9e-4a07-ab0e-e2e43cca8991)
There are a number of problems with the current linting system, most notably that lints could run without
-Zcargo-lints
being set. This PR fixes that issue and a few others that are low-hanging fruit.