Skip to content

Commit 426df5f

Browse files
committed
feat(diag): Stabilize cargo-lints
Fixes #12235
1 parent ebd28ed commit 426df5f

99 files changed

Lines changed: 1831 additions & 480 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/xtask-lint-docs/src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ fn main() -> anyhow::Result<()> {
4545
>
4646
> See [the lints section in the Manifest Format
4747
> chapter](manifest.md#the-lints-section) to configure lint levels for tools
48-
> such as `rustc` or `clippy`.
49-
50-
> [!WARNING]
51-
> [Cargo's linting system is unstable](unstable.md#lintscargo) and can only be used on nightly
52-
> toolchains."
48+
> such as `rustc` or `clippy`."
5349
)?;
5450
writeln!(buf)?;
5551

doc/book/src/guide/build-performance.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,11 @@ Trade-offs:
151151

152152
### Removing unused dependencies
153153

154-
Recommendation: periodically review unused dependencies for removal using:
155-
```console
156-
$ cargo +nightly check -Zcargo-lints --workspace --all-targets
157-
```
158-
This may have false positives from:
159-
- when a dependency's use is dynamically controlled by a `build.rs` or `RUSTFLAGS`
154+
The [`cargo::unused_dependencies`](../reference/lints.md#unused_dependencies) will identify most unused dependencies with few false positives.
160155

161-
Also, periodically review hidden [`cargo::unused_dependencies`] results:
156+
For everything else, periodically review hidden [`cargo::unused_dependencies`] results:
162157
```console
163-
$ CARGO_LOG=cargo::diagnostics::rules::unused_dependencies=debug cargo +nightly check -Zcargo-lints --workspace --all-targets
158+
$ CARGO_LOG=cargo::diagnostics::rules::unused_dependencies=debug cargo check --workspace --all-targets
164159
```
165160
This will show potential unused dependencies for
166161
- registry and git dependencies
@@ -174,10 +169,8 @@ it can be easy to miss that a dependency is no longer used and can be removed.
174169

175170
Trade-offs:
176171
- ✅ Faster full build and link times
177-
-**Requires using nightly Rust and an [unstable Cargo feature][cargo-lints] when reviewing unused dependencies**
178172
- ❌ It takes effort to identify unused dependencies from among the false positives
179173

180-
[cargo-lints]: ../reference/unstable.md#lintscargo
181174
[`cargo::unused_dependencies`]: ../reference/lints.md#unused_dependencies
182175
[`package.rust-version`]: ../reference/rust-version.md
183176

doc/book/src/reference/lints.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
> chapter](manifest.md#the-lints-section) to configure lint levels for tools
88
> such as `rustc` or `clippy`.
99
10-
> [!WARNING]
11-
> [Cargo's linting system is unstable](unstable.md#lintscargo) and can only be used on nightly
12-
> toolchains.
13-
1410

1511

1612
| Group | Description | Default level |

doc/book/src/reference/unstable.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ Each new feature described below should explain how to use it.
116116
* [per-package-target](#per-package-target) --- Sets the `--target` to use for each individual package.
117117
* [artifact dependencies](#artifact-dependencies) --- Allow build artifacts to be included into other build artifacts and build them for different targets.
118118
* [Profile `trim-paths` option](#profile-trim-paths-option) --- Control the sanitization of file paths in build outputs.
119-
* [`[lints.cargo]`](#lintscargo) --- Allows configuring lints for Cargo.
120119
* [path bases](#path-bases) --- Named base directories for path dependencies.
121120
* [`unstable-editions`](#unstable-editions) --- Allows use of editions that are not yet stable.
122121
* Information and metadata
@@ -1756,27 +1755,6 @@ Use fine grain locking instead of locking the entire build cache.
17561755

17571756
Note: Fine grain locking implicitly enables [build-dir-new-layout](#build-dir-new-layout) as fine grain locking builds on that directory reoganization.
17581757

1759-
## `[lints.cargo]`
1760-
1761-
* Tracking Issue: [#12235](https://github.com/rust-lang/cargo/issues/12235)
1762-
1763-
A new `lints` tool table for `cargo` that can be used to configure lints emitted
1764-
by `cargo` itself when `-Zcargo-lints` is used
1765-
```toml
1766-
[lints.cargo]
1767-
implicit-features = "warn"
1768-
```
1769-
1770-
This will work with
1771-
[RFC 2906 `workspace-deduplicate`](https://rust-lang.github.io/rfcs/2906-cargo-workspace-deduplicate.html):
1772-
```toml
1773-
[workspace.lints.cargo]
1774-
implicit-features = "warn"
1775-
1776-
[lints]
1777-
workspace = true
1778-
```
1779-
17801758
## Path Bases
17811759

17821760
* Tracking Issue: [#14355](https://github.com/rust-lang/cargo/issues/14355)
@@ -2497,3 +2475,9 @@ Support for `resolver.lockfile-path` config field has been stabilized in Rust 1.
24972475
## warnings
24982476

24992477
The `build.warnings` config field has been stabilized in Rust 1.97.
2478+
2479+
## `[lints.cargo]`
2480+
2481+
Cargo's linting system and the `[lints.cargo]` table have been stabilized in Rust 1.99.
2482+
See the [lints chapter](lints.md) and [the lints section](manifest.md#the-lints-section)
2483+
for information about configuring Cargo lints.

src/compiler/job_queue/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -841,15 +841,13 @@ impl<'gctx> DrainState<'gctx> {
841841
}
842842
self.progress.clear();
843843

844-
if build_runner.bcx.gctx.cli_unstable().cargo_lints {
845-
let mut global_stats = GlobalDiagnosticStats::new();
846-
drop(unused_dependencies::lint_build_results(
847-
build_runner,
848-
&mut global_stats,
849-
));
850-
errors.count += global_stats.error_count();
851-
build_runner.compilation.lint_warning_count += global_stats.lint_warning_count();
852-
}
844+
let mut global_stats = GlobalDiagnosticStats::new();
845+
drop(unused_dependencies::lint_build_results(
846+
build_runner,
847+
&mut global_stats,
848+
));
849+
errors.count += global_stats.error_count();
850+
build_runner.compilation.lint_warning_count += global_stats.lint_warning_count();
853851

854852
let profile_name = build_runner.bcx.build_config.requested_profile;
855853
// NOTE: this may be a bit inaccurate, since this may not display the

src/compiler/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,9 @@ fn prepare_rustc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult
855855
base.env("CARGO_TARGET_TMPDIR", tmp.display().to_string());
856856
}
857857

858-
if build_runner.bcx.gctx.cli_unstable().cargo_lints {
859-
// Added last to reduce the risk of RUSTFLAGS or `[lints]` from interfering with
860-
// `unused_dependencies` tracking
861-
base.arg("--force-warn=unused_crate_dependencies");
862-
}
858+
// Added last to reduce the risk of RUSTFLAGS or `[lints]` from interfering with
859+
// `unused_dependencies` tracking
860+
base.arg("--force-warn=unused_crate_dependencies");
863861

864862
Ok(base)
865863
}
@@ -1233,10 +1231,9 @@ fn add_error_format_and_color(build_runner: &BuildRunner<'_, '_>, cmd: &mut Proc
12331231

12341232
cmd.arg("--error-format=json");
12351233

1236-
let mut json = String::from("--json=diagnostic-rendered-ansi,artifacts,future-incompat");
1237-
if build_runner.bcx.gctx.cli_unstable().cargo_lints {
1238-
json.push_str(",unused-externs-silent");
1239-
}
1234+
let mut json = String::from(
1235+
"--json=diagnostic-rendered-ansi,artifacts,future-incompat,unused-externs-silent",
1236+
);
12401237
if let MessageFormat::Short | MessageFormat::Json { short: true, .. } =
12411238
build_runner.bcx.build_config.message_format
12421239
{

src/diagnostics/passes.rs

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -153,44 +153,40 @@ fn emit_parse_pkg_diagnostics(
153153
rule(workspace, manifest, &path, &mut pkg_stats, workspace.gctx())?;
154154
}
155155
ParsePassRule::LintManifest { rule, lint } => {
156-
if workspace.gctx().cli_unstable().cargo_lints {
157-
let manifest: ManifestFor<'_> = pkg.into();
158-
let level = manifest.lint_level(&cargo_lints, lint, workspace.gctx());
159-
if level.level != LintLevel::Allow {
160-
rule(
161-
workspace,
162-
manifest,
163-
&path,
164-
level,
165-
&mut pkg_stats,
166-
workspace.gctx(),
167-
)?;
168-
}
156+
let manifest: ManifestFor<'_> = pkg.into();
157+
let level = manifest.lint_level(&cargo_lints, lint, workspace.gctx());
158+
if level.level != LintLevel::Allow {
159+
rule(
160+
workspace,
161+
manifest,
162+
&path,
163+
level,
164+
&mut pkg_stats,
165+
workspace.gctx(),
166+
)?;
169167
}
170168
}
171169
ParsePassRule::DiagnosticWorkspace { .. } | ParsePassRule::LintWorkspace { .. } => {}
172170
ParsePassRule::DiagnosticPackage { rule } => {
173171
rule(workspace, pkg, &path, &mut pkg_stats, workspace.gctx())?;
174172
}
175173
ParsePassRule::LintPackage { rule, lint } => {
176-
if workspace.gctx().cli_unstable().cargo_lints {
177-
let level = lint.level(
178-
&cargo_lints,
179-
pkg.rust_version(),
180-
pkg.manifest().unstable_features(),
181-
workspace.gctx(),
182-
);
174+
let level = lint.level(
175+
&cargo_lints,
176+
pkg.rust_version(),
177+
pkg.manifest().unstable_features(),
178+
workspace.gctx(),
179+
);
183180

184-
if level.level != LintLevel::Allow {
185-
rule(
186-
workspace,
187-
pkg,
188-
&path,
189-
level,
190-
&mut pkg_stats,
191-
workspace.gctx(),
192-
)?;
193-
}
181+
if level.level != LintLevel::Allow {
182+
rule(
183+
workspace,
184+
pkg,
185+
&path,
186+
level,
187+
&mut pkg_stats,
188+
workspace.gctx(),
189+
)?;
194190
}
195191
}
196192
}
@@ -242,19 +238,17 @@ fn emit_parse_ws_diagnostics(
242238
)?;
243239
}
244240
ParsePassRule::LintManifest { rule, lint } => {
245-
if workspace.gctx().cli_unstable().cargo_lints {
246-
let manifest: ManifestFor<'_> = (workspace, workspace.root_maybe()).into();
247-
let level = manifest.lint_level(&cargo_lints, lint, workspace.gctx());
248-
if level.level != LintLevel::Allow {
249-
rule(
250-
workspace,
251-
manifest,
252-
workspace.root_manifest(),
253-
level,
254-
&mut pkg_stats,
255-
workspace.gctx(),
256-
)?;
257-
}
241+
let manifest: ManifestFor<'_> = (workspace, workspace.root_maybe()).into();
242+
let level = manifest.lint_level(&cargo_lints, lint, workspace.gctx());
243+
if level.level != LintLevel::Allow {
244+
rule(
245+
workspace,
246+
manifest,
247+
workspace.root_manifest(),
248+
level,
249+
&mut pkg_stats,
250+
workspace.gctx(),
251+
)?;
258252
}
259253
}
260254
ParsePassRule::DiagnosticWorkspace { rule } => {
@@ -267,23 +261,21 @@ fn emit_parse_ws_diagnostics(
267261
)?;
268262
}
269263
ParsePassRule::LintWorkspace { rule, lint } => {
270-
if workspace.gctx().cli_unstable().cargo_lints {
271-
let level = lint.level(
272-
&cargo_lints,
273-
workspace.lowest_rust_version(),
274-
workspace.root_maybe().unstable_features(),
264+
let level = lint.level(
265+
&cargo_lints,
266+
workspace.lowest_rust_version(),
267+
workspace.root_maybe().unstable_features(),
268+
workspace.gctx(),
269+
);
270+
if level.level != LintLevel::Allow {
271+
rule(
272+
workspace,
273+
workspace.root_maybe(),
274+
workspace.root_manifest(),
275+
level,
276+
&mut pkg_stats,
275277
workspace.gctx(),
276-
);
277-
if level.level != LintLevel::Allow {
278-
rule(
279-
workspace,
280-
workspace.root_maybe(),
281-
workspace.root_manifest(),
282-
level,
283-
&mut pkg_stats,
284-
workspace.gctx(),
285-
)?;
286-
}
278+
)?;
287279
}
288280
}
289281
ParsePassRule::DiagnosticPackage { .. } | ParsePassRule::LintPackage { .. } => {}

src/workspace/features.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,6 @@ unstable_cli_options!(
890890
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
891891
#[serde(deserialize_with = "deserialize_comma_separated_list")]
892892
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
893-
cargo_lints: bool = ("Enable the `[lints.cargo]` table"),
894893
checksum_freshness: bool = ("Use a checksum to determine if output is fresh rather than filesystem mtime"),
895894
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
896895
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
@@ -1007,6 +1006,8 @@ const STABILIZED_REGISTRY_AUTH: &str =
10071006

10081007
const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
10091008

1009+
const STABILIZED_CARGO_LINTS: &str = "The `[lints.cargo]` table is now always available.";
1010+
10101011
const STABILIZED_CHECK_CFG: &str =
10111012
"Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled.";
10121013

@@ -1423,6 +1424,7 @@ impl CliUnstable {
14231424
"config-include" => stabilized_warn(k, "1.93", STABILIZED_CONFIG_INCLUDE),
14241425
"lockfile-path" => stabilized_warn(k, "1.97", STABILIZED_LOCKFILE_PATH),
14251426
"warnings" => stabilized_warn(k, "1.97", STABILIZED_WARNINGS),
1427+
"cargo-lints" => stabilized_warn(k, "1.99", STABILIZED_CARGO_LINTS),
14261428

14271429
// Unstable features
14281430
// Sorted alphabetically:
@@ -1436,7 +1438,6 @@ impl CliUnstable {
14361438
"build-dir-new-layout" => self.build_dir_new_layout = parse_empty(k, v)?,
14371439
"build-std" => self.build_std = Some(parse_list(v)),
14381440
"build-std-features" => self.build_std_features = Some(parse_list(v)),
1439-
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,
14401441
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
14411442
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
14421443
"dual-proc-macros" => self.dual_proc_macros = parse_empty(k, v)?,

0 commit comments

Comments
 (0)