Skip to content
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

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

Closed

Conversation

poliorcetics
Copy link
Contributor

@poliorcetics poliorcetics commented Dec 7, 2020

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
Collaborator

r? @matthewjasper

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

@rustbot rustbot added A-lint 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-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 7, 2020
@poliorcetics poliorcetics changed the title Declare the new lint to properly deny warnings in rustdoc Declare a new lint to properly deny warnings in rustdoc Dec 7, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 12, 2020

r? @jyn514

Copy link
Member

@jyn514 jyn514 left a comment

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 :)

compiler/rustc_lint_defs/src/builtin.rs Outdated Show resolved Hide resolved
src/doc/rustdoc/src/lints.md Outdated Show resolved Hide resolved
src/doc/rustdoc/src/lints.md Show resolved Hide resolved

diag
// NOTE(poliorcetics): is 'item' always local here ? Or will this panic one day ?
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local());
Copy link
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
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?

@jyn514 jyn514 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
Contributor Author

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

@rustbot rustbot 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
Copy link
Member

@jyn514 jyn514 left a comment

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?

src/doc/rustdoc/src/lints.md Show resolved Hide resolved
src/librustdoc/passes/check_code_block_syntax.rs Outdated Show resolved Hide resolved
@jyn514
Copy link
Member

jyn514 commented Dec 14, 2020

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
Copy link
Contributor Author

poliorcetics commented Dec 15, 2020

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
Member

jyn514 commented Dec 16, 2020

@bors r+

Looks great, thanks!

@bors
Copy link
Contributor

bors commented Dec 16, 2020

📌 Commit 0e0ae47 has been approved by jyn514

@bors bors 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 ?

Fix rust-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 ?

Fix rust-lang#79792.

``@rustbot`` label T-rustdoc A-lint
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 4, 2021
@poliorcetics
Copy link
Contributor Author

poliorcetics commented Mar 6, 2021

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

@rustbot rustbot 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 Mar 6, 2021
@jyn514 jyn514 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 Mar 6, 2021
@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.
@rustbot rustbot 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 Mar 13, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 19, 2021

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.

@@ -7,6 +7,7 @@ LL | | /// \__________pkt->size___________/ \_result->size_/ \__pkt->si
LL | | /// ```
| |_______^
|
= note: `#[warn(invalid_rust_codeblock)]` on by default
Copy link
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)?

@jyn514 jyn514 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 Mar 19, 2021
@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 4, 2021
@JohnCSimon
Copy link
Member

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

@camelid camelid 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 23, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 23, 2021

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

@jyn514
Copy link
Member

jyn514 commented Apr 26, 2021

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

@jyn514 jyn514 closed this Apr 26, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…pider

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

Fixes rust-lang#79792. This already went through FCP in rust-lang#79816, so it only needs final review.

This is mostly a rebase of rust-lang#79816 - thank you `@poliorcetics` for doing most of the work!
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 15, 2021
…pider

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

Fixes rust-lang#79792. This already went through FCP in rust-lang#79816, so it only needs final review.

This is mostly a rebase of rust-lang#79816 - thank you ``@poliorcetics`` for doing most of the work!
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 18, 2021
…pider

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

Fixes rust-lang#79792. This already went through FCP in rust-lang#79816, so it only needs final review.

This is mostly a rebase of rust-lang#79816 - thank you `@poliorcetics` for doing most of the work!
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 18, 2021
…pider

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

Fixes rust-lang#79792. This already went through FCP in rust-lang#79816, so it only needs final review.

This is mostly a rebase of rust-lang#79816 - thank you ``@poliorcetics`` for doing most of the work!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-lang Relevant to the language team, which will review and decide on the PR/issue. T-rustdoc Relevant 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