Skip to content

Add new invalid_markdown_table rustdoc lint#159583

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

Add new invalid_markdown_table rustdoc lint#159583
GuillaumeGomez wants to merge 6 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
@GuillaumeGomez GuillaumeGomez changed the title Add new unescaped_pipe_in_table_cell rustdoc lint Add new invalid_markdown_table rustdoc lint Jul 24, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Ok all done.

@notriddle

notriddle commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

I noticed that this lint scans the entire row to count pipes, but it only actually needs to scan the part between the end of the last cell and the end of the row. Worse, this scanning has a corner case where it gives less-than-perfect results.

Here's a commit that implements the fixes. notriddle@3c70378ff60


The essential problem is that, with this table:

one |
----|
  a | b | c
  a | b |
  a | b
  a |

And this logic:

let too_many_pipes = divider_count > expected_cells + 1;

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

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:

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

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

Copy link
Copy Markdown
Member Author

@notriddle Please push it to my branch, don't want to steal ownership for your work. :)

@notriddle

Copy link
Copy Markdown
Contributor

Sure.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

Nice, thanks!

@camelid: Is your concern resolved?

@camelid

camelid commented Jul 25, 2026

Copy link
Copy Markdown
Member

Well, I would prefer the lint name to be even more general like invalid_markdown, and maybe be merged with invalid_html_tags (superseding it). What do you think?

I can't think of a case where people would want to control them separately. It seems more likely they'd want all these lints to be either enabled or disabled rather than one-by-one controlling them.

@notriddle

Copy link
Copy Markdown
Contributor

I can’t think of a case where anyone would want to disable this table lint at all.

The HTML lint, however, you might disable it if you intentionally rely on HTML tag correction. The rules are spelled out in the spec, after all, and they allow you to write more terse markup.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

invalid_markdown should be a lint group, I donnt think we should merge both lints.

@camelid

camelid commented Jul 25, 2026

Copy link
Copy Markdown
Member

Based on @notriddle's comment, I propose we rename this lint to just invalid_markdown (rather than having it be a lint group) but leave it separate from the invalid_html_tags lint.

@GuillaumeGomez

Copy link
Copy Markdown
Member Author

It's too general: we already have other "invalid markdown" specialized lints. If we want to make a group out of them, that's a good name for the group. But otherwise I think it's too general.

@camelid

camelid commented Jul 25, 2026

Copy link
Copy Markdown
Member

What other invalid markdown lints do we have? All of the lints I see are either specific to rustdoc features (like invalid Rust code blocks) or stylistic issues (redundant explicit links). https://doc.rust-lang.org/rustdoc/lints.html

That said, I'm not going to block on this since ultimately it's a matter of taste. I would just prefer not creating too many overly specific lints -- like I can't imagine why someone would want to control linting of tables separately from other markdown features, unless they were doing something really unusual.

@GuillaumeGomez

GuillaumeGomez commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

I see at least bare_urls and invalid_html_tags. And once we're done with #137858, there will be a new one.

EDIT: copied the wrong lint name, replaced it.

@camelid

camelid commented Jul 25, 2026

Copy link
Copy Markdown
Member

Right, but bare_urls doesn't actually indicate invalid Markdown. The other two are closer to that though. Anyway, I'll resolve my concern. I'm fine with doing a lint group for these like you proposed, even though I'd rather not separate them at all.

@rfcbot resolve overly specific lint name

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. proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-fcp Status: PR is in FCP and is awaiting for FCP to complete. 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.

Markdown tables can silently discard content containing |

7 participants