Skip to content

Conversation

@borngraced
Copy link
Contributor

@borngraced borngraced commented Jan 4, 2026

fixes false positives for undocumented_unsafe_blocks #16210

Same-line comments in macros (e.g., let _x =// SAFETY: ...) and inner safety comments (e.g., unsafe { // SAFETY: ... }) were not recognized because

only checked for lines starting with // or /*.

note: block_has_inner_safety_comment does not respect accept-comment-above-statement or accept-comment-above-attributes. These configs control comments above statements or attributes; inner comments are inside the block, so no ambiguity exists.

changelog: [`undocumented_unsafe_block`]: recognize safety comments inside blocks and on same line in macros

r? @llogiq

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 4, 2026
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

Lintcheck changes for d37d04a

Lint Added Removed Changed
clippy::undocumented_unsafe_blocks 0 67 3

This comment will be updated if you push new changes

// We only check the first (immediate preceding) line for this pattern.
let comment_start = [line.find("//"), line.find("/*")].into_iter().flatten().min();
if let Some(comment_start) = comment_start
&& let Some(safety_offset) = line[comment_start..].to_ascii_uppercase().find("SAFETY:")
Copy link
Contributor

Choose a reason for hiding this comment

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

This will find things like // This has no safety: comment. I think we should ask there be nothing but whitespace between the start of the comment and the Safety: prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good edge case. Will apply fix thanks

@borngraced borngraced force-pushed the fix-undocumented-unsafe-blocks branch from aee94d7 to 45b38ba Compare January 6, 2026 14:39
@rustbot
Copy link
Collaborator

rustbot commented Jan 6, 2026

This PR was rebased onto a different master 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.

allow only whitespace between the comment marker and `SAFETY:`
@borngraced borngraced force-pushed the fix-undocumented-unsafe-blocks branch from 03d8acd to d37d04a Compare January 7, 2026 09:03
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.

3 participants