replicate clippy lint ptr_offset_with_cast - #107
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR replicates the Clippy lint ptr_offset_with_cast to detect usage of the offset pointer method with a usize value casted to an isize. The lint suggests using the add method instead to avoid the numeric cast when always increasing the pointer address.
Key changes:
- Added new pattern detection for
ptr_offset_with_castin bothoffsetandwrapping_offsetvariants - Registered the new pattern in the default patterns list
- Updated existing test expectations to include the new lint warnings
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/patterns-pest/clippy/ptr-offset-with-cast.rpl | New pattern file defining the MIR patterns for detecting usize-to-isize casts in pointer offset operations and corresponding diagnostic messages |
| crates/rpl_meta/src/cli.rs | Registers the new ptr-offset-with-cast pattern in alphabetical order in the default patterns list |
| tests/ui/clippy/ptr_offset_with_cast.rs | New test file verifying the lint detects offset/wrapping_offset with usize casts and correctly ignores non-usize casts and non-pointer types |
| tests/ui/clippy/ptr_offset_with_cast.stderr | Expected error output for the new test, showing 8 errors (4 ptr_offset_with_cast, 4 unchecked_pointer_offset) |
| tests/ui/cve/cve_2021_25905/minimal.rs | Updated test annotations to expect ptr_offset_with_cast errors for inline revision; removed check-pass directive |
| tests/ui/cve/cve_2021_25905/minimal.inline.stderr | New expected output file showing 4 ptr_offset_with_cast errors for the inline revision |
| tests/ui/cve/cve_2021_25905/minimal.regular.stderr | Updated line numbers to reflect changes in the source file |
| tests/ui/cve/cve_2020_35892_3/cve_2020_35892_3.rs | Added test annotations for ptr_offset_with_cast at 4 offset call sites |
| tests/ui/cve/cve_2020_35892_3/cve_2020_35892_3.stderr | Updated expected output to include 4 new ptr_offset_with_cast errors and adjusted line numbers |
| tests/ui/clippy/size_of_in_element_count/functions.rs | Added test annotation for ptr_offset_with_cast on the offset call |
| tests/ui/clippy/size_of_in_element_count/functions.stderr | Updated expected output to include new ptr_offset_with_cast error and adjusted line numbers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.