Skip to content

Add undocumented_as_casts lint - #16682

Open
charlieHsiuC wants to merge 9 commits into
rust-lang:masterfrom
charlieHsiuC:master
Open

Add undocumented_as_casts lint#16682
charlieHsiuC wants to merge 9 commits into
rust-lang:masterfrom
charlieHsiuC:master

Conversation

@charlieHsiuC

@charlieHsiuC charlieHsiuC commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

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

rustbot commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented Mar 7, 2026

Copy link
Copy Markdown

Lintcheck changes for f002ab9

Lint Added Removed Changed
clippy::undocumented_as_casts 9610 0 0

This comment will be updated if you push new changes

@samueltardieu samueltardieu left a comment

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.

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

rustbot commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

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

rustbot commented Mar 7, 2026

Copy link
Copy Markdown
Collaborator

This lint has been nominated for inclusion.

A FCP topic has been created on Zulip.

@charlieHsiuC

Copy link
Copy Markdown
Contributor 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.

@rustbot

This comment has been minimized.

@charlieHsiuC

Copy link
Copy Markdown
Contributor 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

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.
- Refactored the linting logic to utilize `span_lint_and_then` for better suggestion handling.
- Updated the comment checking mechanism to ensure `// CAST:` comments are properly validated, including for casts originating from macro expansions.
- Improved documentation within the lint to clarify the requirements for cast comments.
- Adjusted test cases to cover new scenarios and ensure compliance with the updated linting rules.
@rustbot

rustbot commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

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.

@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #17499) 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