rust-lang / rust-lang/rust-clippy
Cast_ptr_alignment false negative in trait method default impl
Open
Nobody has claimed this yet.
C-enhancement
I-false-negative
L-correctness
S-needs-discussion
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
I believe Clippy should catch both of the following casts but it currently only flags the first one.
unsafe fn frob(bytes: *const u8) -> *const String {
// Correctly caught by cast_ptr_alignment.
bytes as *const String
}
trait Trait {
unsafe fn frob(bytes: *const u8) -> *const Self where Self: Sized {
// Should be caught but is not.
bytes as *const Self
}
}
Would have prevented this bug in Chrome OS: https://bugs.chromium.org/p/chromium/issues/detail?id=900962.
clippy 0.0.212 (f5d868c 2018-11-15)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the cast_ptr_alignment lint and compare how it handles the concrete pointer cast with the trait default implementation shown in the report. Add coverage for both casts and confirm that the lint flags the trait method case as well as the existing standalone case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100