From a6b221cb9fce7b16676099a1c59057959e43bcdb Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Fri, 4 Sep 2026 10:13:29 -0400 Subject: [PATCH 1/2] docs(lints): how to configure Cargo lints --- crates/xtask-lint-docs/src/main.rs | 31 +++++++++++++++++++++++++----- doc/book/src/reference/lints.md | 22 +++++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/crates/xtask-lint-docs/src/main.rs b/crates/xtask-lint-docs/src/main.rs index a7ce7daf853..4cb202387a2 100644 --- a/crates/xtask-lint-docs/src/main.rs +++ b/crates/xtask-lint-docs/src/main.rs @@ -41,11 +41,25 @@ fn main() -> anyhow::Result<()> { writeln!( buf, "> [!NOTE] -> This chapter is about lints emitted by `cargo` itself. -> -> See [the lints section in the Manifest Format -> chapter](manifest.md#the-lints-section) to configure lint levels for tools -> such as `rustc` or `clippy`." +> This chapter is about lints emitted by `cargo` itself." + )?; + writeln!(buf)?; + + writeln!( + buf, + r#"## Configuring Cargo lints + +Cargo lints can be configured in the `[lints.cargo]` table of the `Cargo.toml` manifest. +The key is the lint name without the `cargo::` prefix. +For example: + +```toml +[lints.cargo] +unused_dependencies = "deny" +``` + +See [the `[lints]` section](manifest.md#the-lints-section) +for details about lint levels and priorities."# )?; writeln!(buf)?; @@ -83,6 +97,13 @@ fn main() -> anyhow::Result<()> { } fn lint_groups(buf: &mut String) -> anyhow::Result<()> { + writeln!( + buf, + r#"## Lint groups + +Cargo has the concept of a "lint group", +where you can toggle several warnings through one name."# + )?; let (max_name_len, max_desc_len) = cargo::diagnostics::LINT_GROUPS .iter() .filter(|g| !g.hidden) diff --git a/doc/book/src/reference/lints.md b/doc/book/src/reference/lints.md index 103db3b76a4..82e0d3fb22a 100644 --- a/doc/book/src/reference/lints.md +++ b/doc/book/src/reference/lints.md @@ -2,11 +2,25 @@ > [!NOTE] > This chapter is about lints emitted by `cargo` itself. -> -> See [the lints section in the Manifest Format -> chapter](manifest.md#the-lints-section) to configure lint levels for tools -> such as `rustc` or `clippy`. +## Configuring Cargo lints + +Cargo lints can be configured in the `[lints.cargo]` table of the `Cargo.toml` manifest. +The key is the lint name without the `cargo::` prefix. +For example: + +```toml +[lints.cargo] +unused_dependencies = "deny" +``` + +See [the `[lints]` section](manifest.md#the-lints-section) +for details about lint levels and priorities. + +## Lint groups + +Cargo has the concept of a "lint group", +where you can toggle several warnings through one name. | Group | Description | Default level | From e104453f8e3f19c794499a4e81d664589ff38945 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sat, 5 Sep 2026 08:15:58 -0400 Subject: [PATCH 2/2] docs(manifest): cross-reference cargo lint docs --- doc/book/src/reference/manifest.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/book/src/reference/manifest.md b/doc/book/src/reference/manifest.md index b4e1d77f39c..d3f9c4b65c6 100644 --- a/doc/book/src/reference/manifest.md +++ b/doc/book/src/reference/manifest.md @@ -567,6 +567,9 @@ unsafe_code = "forbid" [lints.clippy] enum_glob_use = "deny" + +[lints.cargo] +unused_dependencies = "deny" ``` Generally, these will only affect local development of the current package. @@ -574,6 +577,8 @@ Cargo only applies these to the current package and not to dependencies. As for dependents, Cargo suppresses lints from non-path dependencies with features like [`--cap-lints`](../../rustc/lints/levels.html#capping-lints). +See also the [lints chapter](lints.md) for the available lints emitted by Cargo itself. + > **MSRV:** Respected as of 1.74 ## The `[hints]` section