Skip to content

Add undocumented_as_casts lint - #16682

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

charlieHsiuC wants to merge 4 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 99f42bd

Lint Added Removed Changed
clippy::undocumented_as_casts 6979 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
Comment thread clippy_lints/src/undocumented_as_casts.rs Outdated
@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.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

- 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.
- Refine `undocumented_as_casts` lint error messages for clarity
@rustbot

rustbot commented Sep 14, 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.

@charlieHsiuC

Copy link
Copy Markdown
Contributor Author

Hi @samueltardieu,

Could you review this PR when you have a chance? I'm looking for some feedback to get it ready for merging.

Based on your suggestions, I added support for macros. I also updated the lint to show different messages when it triggers inside a macro, which is why I think using span_lint_and_then is better here.

I initially tried to reuse the logic from undocumented_unsafe_block, but I felt it gave the comments too much flexibility in terms of placement. Instead, I kept it simple and changed it to only expect comments right before the linted span.

@rustbot

rustbot commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

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

This branch has not been deployed

No deployments
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