Skip to content

Add undocumented_as_casts lint#16682

Open
charlieHsiuC wants to merge 5 commits intorust-lang:masterfrom
charlieHsiuC:master
Open

Add undocumented_as_casts lint#16682
charlieHsiuC wants to merge 5 commits intorust-lang:masterfrom
charlieHsiuC:master

Conversation

@charlieHsiuC
Copy link
Copy Markdown

@charlieHsiuC charlieHsiuC commented Mar 7, 2026

Checks for as casts that do not have a preceding // CAST: comment.

fixes #15963

changelog: new lint: [undocumented_as_casts]

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 7, 2026

r? @samueltardieu

rustbot has assigned @samueltardieu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 7, 2026

Lintcheck changes for d3a2c82

Lint Added Removed Changed
clippy::undocumented_as_casts 8647 0 0

This comment will be updated if you push new changes

Copy link
Copy Markdown
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

Initial review.

Also, please add tests where parts of the cast expression come from a declarative macro. For example, a cast!(expr, type) which expands to (expr) as type, or a copy!(expr as type).

View changes since this review

Comment thread clippy_lints/src/undocumented_as_casts.rs Outdated
Comment thread clippy_lints/src/undocumented_as_casts.rs Outdated
}
}

/// Checks if there is a `// CAST:` or `/* CAST:` comment preceding the cast expression.
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.

Wouldn't it be better to share the logic with the "SAFETY" logic? It looks like a lot of duplicated functionalities.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 7, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@samueltardieu samueltardieu added the lint-nominated Create an FCP-thread on Zulip for this PR label Mar 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 7, 2026

This lint has been nominated for inclusion.

A FCP topic has been created on Zulip.

@charlieHsiuC
Copy link
Copy Markdown
Author

Hi, @samueltardieu
I've updated the code based on your suggestions.

@rustbot ready

@rustbot rustbot 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 from the author. (Use `@rustbot ready` to update this status) labels Mar 11, 2026
@rustbot

This comment has been minimized.

- Added new configuration options: `check-undocumented-as-any-cast`, `check-undocumented-as-const-ptr-cast`, and `check-undocumented-as-mut-ptr-cast` to enforce documentation comments for `as` casts.
- Updated the linting logic to check for `// CAST:` comments for `as` casts, including specific checks for mutable and constant pointer casts.
- Enhanced documentation in the lint configuration and changelog to reflect the new checks.
- Created comprehensive tests to validate the behavior of the new lint checks, including scenarios with and without comments.
- Removed outdated test files related to the previous undocumented casts implementation.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 12, 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.

@charlieHsiuC
Copy link
Copy Markdown
Author

To allow the existing projects to gradually adopt this lint, I have added configurations to enable checks for specific scenarios that users may be most concerned about.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 14, 2026

☔ The latest upstream changes (possibly #16850) made this pull request unmergeable. Please resolve the merge conflicts.

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

Labels

lint-nominated Create an FCP-thread on Zulip for this PR needs-fcp PRs that add, remove, or rename lints and need an FCP 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.

// CAST: ... comment on as casts

3 participants