Skip to content

Commit b5f55b7

Browse files
committed
Auto merge of #76549 - ehuss:lints-comments, r=wesleywiser
Auto-generate lint documentation. This adds a tool which will generate the lint documentation in the rustc book automatically. This is motivated by keeping the documentation up-to-date, and consistently formatted. It also ensures the examples are correct and that they actually generate the expected lint. The lint groups table is also auto-generated. See rust-lang/compiler-team#349 for the original proposal. An outline of how this works: - The `declare_lint!` macro now accepts a doc comment where the documentation is written. This is inspired by how clippy works. - A new tool `src/tools/lint-docs` scrapes the documentation and adds it to the rustc book during the build. - It runs each example and verifies its output and embeds the output in the book. - It does a few formatting checks. - It verifies that every lint is documented. - Groups are collected from `rustc -W help`. I updated the documentation for all the missing lints. I have also added an "Explanation" section to each lint providing a reason for the lint and suggestions on how to resolve it. This can lead towards a future enhancement of possibly showing these docs via the `--explain` flag to make them easily accessible and discoverable.
2 parents 56d8a93 + 49a61f5 commit b5f55b7

23 files changed

+3869
-1567
lines changed

Cargo.lock

+9
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,15 @@ version = "0.5.3"
16771677
source = "registry+https://github.com/rust-lang/crates.io-index"
16781678
checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
16791679

1680+
[[package]]
1681+
name = "lint-docs"
1682+
version = "0.1.0"
1683+
dependencies = [
1684+
"serde_json",
1685+
"tempfile",
1686+
"walkdir",
1687+
]
1688+
16801689
[[package]]
16811690
name = "lock_api"
16821691
version = "0.3.4"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"src/tools/compiletest",
1010
"src/tools/error_index_generator",
1111
"src/tools/linkchecker",
12+
"src/tools/lint-docs",
1213
"src/tools/rustbook",
1314
"src/tools/unstable-book-gen",
1415
"src/tools/tidy",

compiler/rustc_lint/src/array_into_iter.rs

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ use rustc_session::lint::FutureIncompatibleInfo;
77
use rustc_span::symbol::sym;
88

99
declare_lint! {
10+
/// The `array_into_iter` lint detects calling `into_iter` on arrays.
11+
///
12+
/// ### Example
13+
///
14+
/// ```rust
15+
/// # #![allow(unused)]
16+
/// [1, 2, 3].into_iter().for_each(|n| { *n; });
17+
/// ```
18+
///
19+
/// {{produces}}
20+
///
21+
/// ### Explanation
22+
///
23+
/// In the future, it is planned to add an `IntoIter` implementation for
24+
/// arrays such that it will iterate over *values* of the array instead of
25+
/// references. Due to how method resolution works, this will change
26+
/// existing code that uses `into_iter` on arrays. The solution to avoid
27+
/// this warning is to use `iter()` instead of `into_iter()`.
28+
///
29+
/// This is a [future-incompatible] lint to transition this to a hard error
30+
/// in the future. See [issue #66145] for more details and a more thorough
31+
/// description of the lint.
32+
///
33+
/// [issue #66145]: https://github.com/rust-lang/rust/issues/66145
34+
/// [future-incompatible]: ../index.md#future-incompatible-lints
1035
pub ARRAY_INTO_ITER,
1136
Warn,
1237
"detects calling `into_iter` on arrays",

0 commit comments

Comments
 (0)