Skip to content

doc_markdown: don't lint proc-macro doc text that reuses a user span - #17943

Open
GauravPawar101 wants to merge 5 commits into
rust-lang:mainfrom
GauravPawar101:fix-issue-17911
Open

GauravPawar101 wants to merge 5 commits into
rust-lang:mainfrom
GauravPawar101:fix-issue-17911

Conversation

@GauravPawar101

@GauravPawar101 GauravPawar101 commented Oct 28, 2026 •

Copy link
Copy Markdown

Fixes #17911

Problem

Currenlty, doc_markdown lints a raw #[doc = ".."] whenever its literal's span
is in user code. Some proc macros (e.g. Leptos' #[component]) builds the doc text
themselves but reuse the span of a user ident for the literal. The user can't
edit that text, so the lint can't be fixed where it's reported.

Fix

For raw #[doc = ".."] attributes, the source at the literal's span must now start
like something that can hold doc text:

  • a string literal ("..", r"..", r#".."#), or
  • a doc comment (///, //!, /** */, /*! */).

Doc comments are accepted because proc macros turn them into #[doc = ".."]
attributes whose literal keeps the comment's span. If the source is unavailable, the
lint stays silent. Raw identifiers (r#type) are not mistaken for raw strings.

Tests

  • Added additional tests that check repro and other cases
  • cargo test

changelog: [doc_markdown]: no longer lints doc text generated by proc macros that
reuse a user identifier's span

LLM discloser
Llm was used for strengthening tests and identifying fn or fp that might have been introduced

@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in clippy_lints/src/doc

cc @notriddle

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 28, 2026
@rustbot

rustbot commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

@blyxyas

blyxyas commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

@GauravPawar101 Have you used an LLM in the making of this pull request (including code or description)? You must disclose it

@GauravPawar101

GauravPawar101 commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

@blyxyas check desc

@raushan728 raushan728 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm reviewing this as a community review, not as a clippy maintainer.

View changes since this review

Comment thread clippy_lints/src/doc/mod.rs Resolved
Comment thread clippy_lints/src/doc/mod.rs Resolved

@raushan728 raushan728 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am relatively new to clippy (#17954 this is my first PR where I actually change the logic). I'm still learning the codebase, a maintainer should definitely take a final look!

View changes since this review

Comment thread clippy_lints/src/doc/mod.rs Outdated
fn is_doc_text_source(cx: &LateContext<'_>, span: Span) -> bool {
const OPENERS: [&str; 5] = ["\"", "///", "//!", "/**", "/*!"];
span.check_text(cx, |src| {
// r#foo is a raw identifier

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can be dropped since the string matching is self-documenting.

Comment thread fix.patch Resolved
Comment thread clippy_lints/src/doc/mod.rs Resolved
Comment thread clippy_lints/src/doc/mod.rs Resolved
@rustbot

rustbot commented Oct 31, 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.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Oct 31, 2026
Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
Signed-off-by: Gauravpawar101 <Gauravpawar2522@gmail.com>
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) has-merge-commits PR has merge commits, merge with caution. labels Oct 31, 2026
@GauravPawar101

Copy link
Copy Markdown
Author

THank you @raushan728
must appreciated

@raushan728 raushan728 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

@blyxyas, could you please take another look?

@GauravPawar101, a small tip for future contributions try to keep commits scoped to one logical change.

View changes since this review

@GauravPawar101

Copy link
Copy Markdown
Author

Yeah, thanks. I will keep that in mind!!

This branch has not been deployed

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

Labels

S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc_markdown lints generated doc text when a proc macro gives it a user span

4 participants