fix: handle empty /**/ in block_to_line assist - #22073
Merged
ChayimFriedman2 merged 1 commit intoApr 17, 2026
Merged
ChayimFriedman2 merged 1 commit into
ChayimFriedman2 merged 1 commit into
Conversation
ChayimFriedman2
requested changes
Apr 17, 2026
`Comment::prefix` iterated `CommentKind::BY_PREFIX` forward, so `/**/` matched the `/**/` entry itself and returned the full 4-char string. `block_to_line` then computed `&text[4..text.len()-2]` = `&text[4..2]` and panicked. Delegate `Comment::prefix` to `CommentKind::prefix`, which already iterates in reverse and returns the canonical short form (`/*` for non-doc block comments). The `/**/` and `/***` entries in `BY_PREFIX` are still needed for `from_text` to classify them as non-doc blocks. fixes rust-lang#22071
Albab-Hasan
force-pushed
the
fix-22071-empty-block-comment-panic
branch
from
April 17, 2026 10:37
c1f0e60 to
beacd8a
Compare
Contributor
Author
|
@ChayimFriedman2 done |
ChayimFriedman2
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
block_to_line sliced &text[prefix.len()..text.len()-2], which panicked on
/**/since its prefix matches the entire comment (len 4) and text.len() - 2 = 2, producing the invalid range [4..2].use strip_prefix/strip_suffix and emit a plain
//when the body is empty after trimming.fixes #22071