Skip to content

Add new invalid_markdown_table rustdoc lint - #159583

Open
GuillaumeGomez wants to merge 7 commits into
rust-lang:mainfrom
GuillaumeGomez:unescaped_pipe_in_table_cell
Open

Add new invalid_markdown_table rustdoc lint#159583
GuillaumeGomez wants to merge 7 commits into
rust-lang:mainfrom
GuillaumeGomez:unescaped_pipe_in_table_cell

Conversation

@GuillaumeGomez

@GuillaumeGomez GuillaumeGomez commented Jul 19, 2026

Copy link
Copy Markdown
Member

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jul 19, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread tests/rustdoc-ui/lints/invalid_markdown_table.rs
Comment thread src/librustdoc/passes/lint/invalid_markdown_table.rs Outdated
Comment thread src/librustdoc/passes/lint/table_pipe_escape.rs Outdated
Comment thread src/librustdoc/passes/lint/table_pipe_escape.rs Outdated
Comment thread src/librustdoc/passes/lint/table_pipe_escape.rs Outdated
Comment thread src/librustdoc/passes/lint/table_pipe_escape.rs Outdated
Comment thread src/librustdoc/passes/lint/invalid_markdown_table.rs Outdated
@Urgau Urgau 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 Jul 20, 2026
@GuillaumeGomez
GuillaumeGomez force-pushed the unescaped_pipe_in_table_cell branch from 045f5a3 to 6fd9b1b Compare July 21, 2026 12:16
@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Applied comments.

@Urgau Urgau 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.

Implementation looks good to me.

View changes since this review

@Urgau Urgau 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 Jul 21, 2026
@Urgau

This comment was marked as outdated.

@rust-rfcbot

This comment was marked as resolved.

@Urgau

Urgau commented Jul 21, 2026

Copy link
Copy Markdown
Member

2nd try. Let's do an FCP.

unescaped_pipe_in_table_cell details

unescaped_pipe_in_table_cell

This lint is warn-by-default. It detects unescaped pipes (|) in table rows which
lead to some row cells being ignored. For example:

//! | col1 |
//! | ---- |
//! | `code_with(|arg| arg)` |

Which will give:

error: table row has too many columns
  --> $DIR/unescaped_pipe_in_table_cell.rs:5:18
   |
5  | //! | `code_with(|arg| arg)` |
   |                  ^ help: any content after this column divider is discarded
   |
   = help: to escape `|` characters in tables, add a `\` before them like `\|`
note: the lint level is defined here
  --> $DIR/unescaped_pipe_in_table_cell.rs:1:9
   |
1  | #![deny(rustdoc::unescaped_pipe_in_table_cell)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@rfcbot merge rustdoc-internals

@rust-rfcbot

rust-rfcbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

@Urgau has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jul 21, 2026
@Urgau Urgau added S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2026
```rust
//! | col1 |
//! | ---- |
//! | `code_with(|arg| arg)` |

@camelid camelid Jul 21, 2026

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.

Wow TIL that this is how GFM works. Very strange design...

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah I was super confused as well.

Comment thread src/librustdoc/passes/lint/table_pipe_escape.rs Outdated
Comment thread tests/rustdoc-ui/lints/invalid_markdown_table.rs
Comment thread tests/rustdoc-ui/lints/unescaped_pipe_in_table_cell.rs Outdated
@notriddle

Copy link
Copy Markdown
Contributor

Minor nits about the implementation, but massive approval for the lint in concept!

@camelid

camelid commented Jul 23, 2026

Copy link
Copy Markdown
Member

Definitely in favor of the lint itself, but I wonder if we should have a more generic lint name and then we group together this and any related (current or future) lints about Markdown gotchas? E.g. we have rustdoc::invalid_html_tags that groups together anything related to that, including (soon: #158709) issues when HTML is interleaved with Markdown.

For example, it could be rustdoc::invalid_markdown, or rustdoc::markdown_gotchas, or a Better Name (TM). I could even imagine us renaming rustdoc::invalid_html_tags to something more general like rustdoc::invalid_markdown and including this as part of it.

On a related note, my feeling with #158709 is that additions of new cases to an existing warn-by-default lint do not require FCP since they are not part of stability guarantees, but please let me know if you disagree.

@camelid

camelid commented Jul 23, 2026

Copy link
Copy Markdown
Member

@rfcbot reviewed
@rfcbot concern overly specific lint name

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@camelid: Very fair point. I think having a lint group for all such lints is a good idea. As for the current lint name, I'll rename it as invalid_markdown_table.

@GuillaumeGomez
GuillaumeGomez force-pushed the unescaped_pipe_in_table_cell branch from 6fd9b1b to 52c8615 Compare July 24, 2026 15:59
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez
GuillaumeGomez force-pushed the unescaped_pipe_in_table_cell branch from 52c8615 to a88e74a Compare July 24, 2026 16:00
@rust-bors

rust-bors Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#160661), which was unapproved.

View changes since this unapproval

@rust-bors

This comment has been minimized.

GuillaumeGomez and others added 6 commits August 24, 2026 15:37
The essential problem is that, with this table:

```text
one |
----|
  a | b | c
  a | b |
  a | b
  a |
```

And this logic:

```rust
let too_many_pipes = divider_count > expected_cells + 1;
```

`expected_cells + 1` winds up as 2, so you get this warning:

```text
error: unused content after last table cell
  --> $DIR/invalid_markdown_table.rs:81:14
   |
LL |     //!   a | b | c
   |              ^^^^^^ this content is discarded

error: unused content after last table cell
  --> $DIR/invalid_markdown_table.rs:83:14
   |
LL |     //!   a | b |
   |              ^^^^ this content is discarded

error: unused content after last table cell
  --> $DIR/invalid_markdown_table.rs:85:14
   |
LL |     //!   a | b
   |              ^^ this content is discarded
```

We really want our warning to give the suggest-escaping flow, like this:

```text
error: table row has too many columns
  --> $DIR/invalid_markdown_table.rs:81:13
   |
LL |     //!   a | b | c
   |             ^ any content after this column divider is discarded
   |
   = help: to escape `|` characters in tables, add a `\` before them like `\|`

error: table row has too many columns
  --> $DIR/invalid_markdown_table.rs:83:13
   |
LL |     //!   a | b |
   |             ^ any content after this column divider is discarded
   |
   = help: to escape `|` characters in tables, add a `\` before them like `\|`

error: unused content after last table cell
  --> $DIR/invalid_markdown_table.rs:85:14
   |
LL |     //!   a | b
   |              ^^ this content is discarded
```

By only scanning the text between the end of the last cell and the row,
instead of doing the entire row, we don't have to re-implement as much
of pulldown-cmark's logic.
@GuillaumeGomez
GuillaumeGomez force-pushed the unescaped_pipe_in_table_cell branch from 3c70378 to df734af Compare August 24, 2026 14:11
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

@bors r=Urgau,notriddle,camelid rollup

@rust-bors

rust-bors Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit aeb0d4a has been approved by Urgau,notriddle,camelid

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 24, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #155499 (stabilize never type)
 - #161294 (add crashtests [6/N])
 - #161050 (Only use dlltool.exe on MinGW if -Cdlltool is passed)
 - #159583 (Add new `invalid_markdown_table` rustdoc lint)
 - #161098 (PassWrapper: handle LLVM 24 change in function types)
 - #161661 (Don't treat slashes as path seps after drive letters in verbatim paths)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #161294 (add crashtests [6/N])
 - #161050 (Only use dlltool.exe on MinGW if -Cdlltool is passed)
 - #159583 (Add new `invalid_markdown_table` rustdoc lint)
 - #161098 (PassWrapper: handle LLVM 24 change in function types)
 - #161661 (Don't treat slashes as path seps after drive letters in verbatim paths)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
rust-bors Bot pushed a commit that referenced this pull request Aug 24, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #155499 (stabilize never type)
 - #161294 (add crashtests [6/N])
 - #161050 (Only use dlltool.exe on MinGW if -Cdlltool is passed)
 - #159583 (Add new `invalid_markdown_table` rustdoc lint)
 - #161098 (PassWrapper: handle LLVM 24 change in function types)
 - #161661 (Don't treat slashes as path seps after drive letters in verbatim paths)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 24, 2026
…able_cell, r=Urgau,notriddle,camelid

Add new `invalid_markdown_table` rustdoc lint

Fixes rust-lang#159186.

r? @Urgau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown tables can silently discard content containing |

8 participants