Skip to content

Declare a new lint to properly deny warnings in rustdoc - #79816

Closed
poliorcetics wants to merge 1 commit into
rust-lang:masterfrom
poliorcetics:rustdoc-fail-on-deny
Closed

Declare a new lint to properly deny warnings in rustdoc#79816
poliorcetics wants to merge 1 commit into
rust-lang:masterfrom
poliorcetics:rustdoc-fail-on-deny

Conversation

@poliorcetics

@poliorceticspoliorcetics commented Dec 7, 2020

Copy link
Copy Markdown
Contributor

This declares a new lint: INVALID_RUST_CODEBLOCK that is used by rustdoc to properly follow -D warnings instead of unconditionally emitting a warning.

Todo List


Fix#79792.

@rustbot label T-rustdoc A-lint

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @matthewjasper

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbotrustbot added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 7, 2020
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 7, 2020
@poliorceticspoliorcetics changed the title Declare the new lint to properly deny warnings in rustdocDeclare a new lint to properly deny warnings in rustdocDec 7, 2020
@jyn514

Copy link
Copy Markdown
Member

r? @jyn514

@jyn514jyn514 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks about like what I imagined, thanks :)

Comment threadcompiler/rustc_lint_defs/src/builtin.rs Outdated
Comment threadsrc/doc/rustdoc/src/lints.md Outdated
Comment threadsrc/doc/rustdoc/src/lints.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not always local (e.g. if this is a re-export), I think we found why it wasn't a lint before. Fortunately, we don't need to check the syntax of other crates, so you can just return without doing anything if it's non-local.

See #77230 for more discussion; it would also be good to add a test, since if the behavior changes it should be intentional.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for the behavior?

@jyn514jyn514 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 12, 2020
@poliorcetics

Copy link
Copy Markdown
ContributorAuthor

@rustbot label +S-waiting-on-review -S-waiting-on-author

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 14, 2020

@jyn514jyn514 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM. Can you squash the commits before merging?

Comment threadsrc/doc/rustdoc/src/lints.md Outdated
Comment threadsrc/librustdoc/passes/check_code_block_syntax.rs Outdated
@jyn514

Copy link
Copy Markdown
Member

Also you need to update src/test/rustdoc-ui:

Some tests failed in compiletest suite=rustdoc-ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
failures:
---- [ui] rustdoc-ui/invalid-syntax.rs stdout ----
diff of stderr:
7	LL | | /// ```
8 | |_______^
9 |
+ = note: `#[warn(invalid_rust_codeblock)]` on by default
10 = note: error from rustc: unknown start of token: \
11 = note: error from rustc: unknown start of token: \
12 = note: error from rustc: unknown start of token: \

@poliorcetics

poliorcetics commented Dec 15, 2020

Copy link
Copy Markdown
ContributorAuthor

Added the changes you proposed and squashed the whole thing

Edit: I forgot to ran fmt first, made the change and squashed again

@poliorcetics
poliorcetics marked this pull request as ready for review December 15, 2020 18:27
@jyn514

Copy link
Copy Markdown
Member

@bors r+

Looks great, thanks!

@bors

bors commented Dec 16, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 0e0ae47 has been approved by jyn514

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Dec 16, 2020
…r=jyn514
Declare a new lint to properly deny warnings in rustdoc
This declares a new lint: `INVALID_RUST_CODEBLOCK` that is used by `rustdoc` to properly follow `-D warnings` instead of unconditionally emitting a warning.
## Todo List
- [x] Declare lint.
- [x] Document lint (file: `src/doc/rustdoc/src/lints.md`).
- [x] Use lint in `rustdoc` (file: `src/librustdoc/passes/check_code_block_syntax.rs`, maybe others).
- [x] Write tests.
- [x] Note: one for the behaviour of the new lint when the error is in a dependency, not the crate being tested (rust-lang#79816 (comment))
- [x] Refactor things.
## Questions
- How/where are lints tested ?
- Where are lints for `rustdoc` tested ?
Fixrust-lang#79792.
`@rustbot` label T-rustdoc A-lint
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Dec 16, 2020
…r=jyn514
Declare a new lint to properly deny warnings in rustdoc
This declares a new lint: `INVALID_RUST_CODEBLOCK` that is used by `rustdoc` to properly follow `-D warnings` instead of unconditionally emitting a warning.
## Todo List
- [x] Declare lint.
- [x] Document lint (file: `src/doc/rustdoc/src/lints.md`).
- [x] Use lint in `rustdoc` (file: `src/librustdoc/passes/check_code_block_syntax.rs`, maybe others).
- [x] Write tests.
- [x] Note: one for the behaviour of the new lint when the error is in a dependency, not the crate being tested (rust-lang#79816 (comment))
- [x] Refactor things.
## Questions
- How/where are lints tested ?
- Where are lints for `rustdoc` tested ?
Fixrust-lang#79792.
``@rustbot`` label T-rustdoc A-lint
@rust-log-analyzer

This comment has been minimized.

Matthias-Fauconneau pushed a commit to Matthias-Fauconneau/rust-analyzer that referenced this pull request Feb 7, 2021
These were the warnings previously:
```
warning: could not parse code block as Rust code
--> crates/stdx/src/lib.rs:137:9
|
137 | /// ∀ x in slice[..idx]: pred(x)
| _________^
138 | | /// && ∀ x in slice[idx..]: !pred(x)
| |____^
|
= note: error from rustc: unknown start of token: \u{2200}
warning: 1 warning emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
```
This does *not* fix the following warning, because it is actually rust
code and rustdoc is being over eager:
```
warning: Rust code block is empty
--> crates/parser/src/grammar.rs:16:5
|
16 | //! ```
| _____^
17 | | //! // test function_with_zero_parameters
18 | | //! // fn foo() {}
19 | | //! ```
| |_______^
|
help: mark blocks that do not contain Rust code as text
|
16 | //! ```text
| ^^^^^^^
```
rust-lang/rust#79816 should make this
configurable so the warning can be `allow`ed.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Feb 27, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR).
## Current status
This is waiting on FCP: rust-lang#80527 (comment)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Mar 2, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 2, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 3, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 4, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 4, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Mar 4, 2021
Make rustdoc lints a tool lint instead of built-in
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` (and similar for other rustdoc lints; I don't expect any others to be used frequently, though).
- Ensure that the old lint names still work and give deprecation errors
- Register lints even when running doctests
- Move lint machinery into a separate file
- Add `declare_rustdoc_lint!` macro
Unblocks rust-lang#80300, rust-lang#79816, rust-lang#80965. Makes the strangeness in rust-lang#77364 more apparent to the end user (note that `missing_docs` is *not* moved to rustdoc in this PR). Closesrust-lang#78786.
## Current status
This is blocked on rust-lang#82620 (see rust-lang#80527 (comment))
@bors

This comment has been minimized.

@jyn514

Copy link
Copy Markdown
Member

#80527 was merged, so this is no longer blocked :)

@rustbot label: -S-blocked +S-waiting-on-author

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Mar 4, 2021
@poliorcetics

poliorcetics commented Mar 6, 2021

Copy link
Copy Markdown
ContributorAuthor

@rustbot label: +S-waiting-on-review -S-waiting-on-author

@rustbotrustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 6, 2021
Comment threadcompiler/rustc_lint_defs/src/builtin.rs Outdated
Comment threadcompiler/rustc_lint_defs/src/builtin.rs Outdated
@bors

This comment has been minimized.

This adds a new lint to `rustc` that is used in rustdoc when a code
block is empty or cannot be parsed as valid Rust code.
Previously this was unconditionally a warning. As such some
documentation comments were (unknowingly) abusing this to pass despite
the `-Dwarnings` used when compiling `rustc`, this should not be the
case anymore.
@jyn514

Copy link
Copy Markdown
Member

This is still not correct. Any new lints should be added to librustdoc/lint.rs. rustc_lint_defs shouldn't be modified at all, that's for builtin lints, not tool lints.

LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests for when ignore is present (and for all the rest of the branching you have for the diagnostics)?

@JohnCSimon

Copy link
Copy Markdown

@poliorcetics - Ping from triage: can you please resolve the merge conflict and set it to S-waiting-on-review ?

@jyn514

Copy link
Copy Markdown
Member

Hi @poliorcetics, any updates on this? It's really close to being done :/

@jyn514

Copy link
Copy Markdown
Member

I'm going to close this - feel free to re-open if you have time to work on this again.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-langRelevant to the language teamT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustdoc -D warnings doesn't fail for all warnings

12 participants

@poliorcetics@rust-highfive@jyn514@bors@rust-log-analyzer@Dylan-DPC-zz@crlf0710@JohnCSimon@GuillaumeGomez@matthewjasper@camelid@rustbot