Skip to content

Fix: strip leading asterisk decoration from block doc comments - #22901

Open
kivancgnlp wants to merge 1 commit into
rust-lang:masterfrom
kivancgnlp:fix-block-doc-asterisks
Open

Fix: strip leading asterisk decoration from block doc comments#22901
kivancgnlp wants to merge 1 commit into
rust-lang:masterfrom
kivancgnlp:fix-block-doc-asterisks

Conversation

@kivancgnlp

@kivancgnlp kivancgnlp commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Strip a consistent leading * decoration from multiline block doc comments, matching rustdoc behavior.
  • Preserve existing behavior for line docs, #[doc = "..."] attributes, *foo, and blocks without a consistent star column.
  • Adjust per-line source-map offsets by the stripped byte count so doc links and syntax highlighting continue to map to the correct source ranges.

Tests Passed :

  • cargo test -p hir-def
  • cargo test -p ide -- hover doc_links
  • cargo test -p ide -- syntax_highlighting
  • cargo fmt -p hir-def -p ide -- --check
  • cargo clippy -p hir-def -p ide --all-targets -- --cap-lints warn

Fixes #1759

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2026
@rustbot

This comment has been minimized.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Did you write the PR description using AI? I'm not sure you did, but if yes, please note that our AI policy forbids doing that.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

Looking at the code, it's pretty clear that you used AI for the code as well without disclosing it, also contrary to our AI policy. And I'm not sure it's properly reviewed either: I am pretty sure it's possible to implement the same thing using at most half the lines, and probably with better perf.

@kivancgnlp

Copy link
Copy Markdown
Contributor Author

Did you write the PR description using AI? I'm not sure you did, but if yes, please note that our AI policy forbids doing that.

Yes I used Claude for draft message but then I edit the message.

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

So, this is also disallowed. Please take notice for the next time.

@kivancgnlp

Copy link
Copy Markdown
Contributor Author

Looking at the code, it's pretty clear that you used AI for the code as well without disclosing it, also contrary to our AI policy. And I'm not sure it's properly reviewed either: I am pretty sure it's possible to implement the same thing using at most half the lines, and probably with better perf.

Claude generated the initial code and tests. I reviewed the changes and tests by myself. I'm sorry that I discovered the policy afterward. I also evaluated possible pitfalls and alternative solutions. I’ll simplify the code.

@kivancgnlp
kivancgnlp force-pushed the fix-block-doc-asterisks branch from 98508e8 to 42dc49c Compare July 26, 2026 05:01
Block doc comments (`/** ... */`) commonly decorate each line with a
leading `*`. rust-analyzer previously left this decoration in the
rendered docs, so hover and doc-link resolution saw literal `* foo`
lines. Normalize the common `[ \t]*\*` prefix during doc extraction,
mirroring rustdoc's `beautify_doc_string`, while keeping the source map
offsets accurate for `find_ast_range`.

Fixes rust-lang#1759
@kivancgnlp
kivancgnlp force-pushed the fix-block-doc-asterisks branch from 42dc49c to de72f8f Compare July 26, 2026 05:21
@kivancgnlp

Copy link
Copy Markdown
Contributor Author
  • Implementation simplified
  • Hover documentation was tested using a local rust-analyzer server and VS Code.
  • The following behaviors were checked and verified: stars disappeared, formatting remained correct, and the documentation link worked.

@kivancgnlp

Copy link
Copy Markdown
Contributor Author

Hi @ChayimFriedman2, just checking in on this one. As noted above, I simplified the implementation and removed the AI-generated parts entirely. The current version reflects my own review and manual testing (verified with a local rust-analyzer server and VS Code, doc-comment stars are stripped correctly, formatting stays intact, and the documentation link still resolves).

Happy to make further changes if the simplified approach still isn't the right shape. Let me know what you'd like adjusted.

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

Labels

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 comment block should strip leading asterisk (*)

3 participants