rust-lang / rust-lang/rust-clippy
Avoding the clippy lint with type placeholder `_`
Open
Nobody has claimed this yet.
C-bug
I-false-negative
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name:
zero_ptr
I tried this code:
fn dummy_raw_waker() -> RawWaker {
fn no_op(_: *const ()) {}
fn clone(_: *const ()) -> RawWaker {
dummy_raw_waker()
}
let vtable = &RawWakerVTable::new(clone, no_op, no_op, no_op);
RawWaker::new(0 as _, vtable)
}
Clippy is not able to deduce a style lint in cases of implicit cast, but would look at the signature of function RawWaker::new():
pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker { ... }
Manually placing the type makes clippy recognize the style lint
RawWaker::new(0 as *const (), vtable)
Meta
cargo clippy -V: clippy 0.1.54 (a85f584 2021-06-16)rustc -Vv:
rustc 1.55.0-nightly (a85f584ae 2021-06-16)
binary: rustc
commit-hash: a85f584aebd9b08314bf30b9adc17b4a752143e5
commit-date: 2021-06-16
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1
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 by reproducing the reported case with cargo clippy and the zero_ptr lint, comparing RawWaker::new(0 as _, vtable) with the explicit *const () cast. Trace the lint's handling of implicit casts and function signatures. Done means the implicit-cast form is recognized consistently and regression coverage verifies the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100