Skip to content

rustdoc: Make "rust code block is empty" and "could not parse code block" warnings a lint (INVALID_RUST_CODEBLOCKS) #84587

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

Merged
merged 5 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename INVALID_RUST_CODEBLOCK{,S}
  • Loading branch information
jyn514 committed May 18, 2021
commit b885d81a4a59fa9282ecb088e6eac8e30cb4a9bf
4 changes: 2 additions & 2 deletions src/doc/rustdoc/src/lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ warning: unclosed HTML tag `h1`
warning: 2 warnings emitted
```

## invalid_rust_codeblock
## invalid_rust_codeblocks

This lint **warns by default**. It detects Rust code blocks in documentation
examples that are invalid (e.g. empty, not parsable as Rust). For example:
Expand Down Expand Up @@ -322,7 +322,7 @@ warning: Rust code block is empty
4 | | /// ```
| |_______^
|
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
warning: Rust code block is empty
--> src/lib.rs:8:5
Expand Down
8 changes: 4 additions & 4 deletions src/librustdoc/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ declare_rustdoc_lint! {
}

declare_rustdoc_lint! {
/// The `invalid_rust_codeblock` lint detects Rust code blocks in
/// The `invalid_rust_codeblocks` lint detects Rust code blocks in
/// documentation examples that are invalid (e.g. empty, not parsable as
/// Rust code). This is a `rustdoc` only lint, see the documentation in the
/// [rustdoc book].
///
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_rust_codeblock
INVALID_RUST_CODEBLOCK,
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_rust_codeblocks
INVALID_RUST_CODEBLOCKS,
Warn,
"codeblock could not be parsed as valid Rust or is empty"
}
Expand All @@ -176,7 +176,7 @@ crate static RUSTDOC_LINTS: Lazy<Vec<&'static Lint>> = Lazy::new(|| {
MISSING_DOC_CODE_EXAMPLES,
PRIVATE_DOC_TESTS,
INVALID_CODEBLOCK_ATTRIBUTES,
INVALID_RUST_CODEBLOCK,
INVALID_RUST_CODEBLOCKS,
INVALID_HTML_TAGS,
BARE_URLS,
MISSING_CRATE_LEVEL_DOCS,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/check_code_block_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a, 'tcx> SyntaxChecker<'a, 'tcx> {
// All points of divergence have been handled earlier so this can be
// done the same way whether the span is precise or not.
self.cx.tcx.struct_span_lint_hir(
crate::lint::INVALID_RUST_CODEBLOCK,
crate::lint::INVALID_RUST_CODEBLOCKS,
hir_id,
sp,
diag_builder,
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/ignore-block-help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | | /// let heart = '❤️';
LL | | /// ```
| |_______^
|
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
help: `ignore` code blocks require valid Rust code for syntax highlighting; mark blocks that do not contain Rust code as text: ```text
--> $DIR/ignore-block-help.rs:3:5
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/invalid-syntax.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
= note: `#[warn(rustdoc::invalid_rust_codeblock)]` on by default
= note: `#[warn(rustdoc::invalid_rust_codeblocks)]` on by default
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
= note: error from rustc: unknown start of token: \
Expand Down