rust-lang / rust-lang/rust-clippy
not_unsafe_ptr_arg_deref false positives
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
pub struct X2<T>(T, T);
impl<T> X2<*mut T> {
pub fn foo(self, a: *mut T) -> Self {
unsafe { self.bar(a) }
}
pub unsafe fn bar(self, _a: *mut T) -> Self {
self
}
}
fn main() {}
produces
error: this public function dereferences a raw pointer but is not marked `unsafe`
--> src/main.rs:5:27
|
5 | unsafe { self.bar(a) }
| ^
|
= note: #[deny(not_unsafe_ptr_arg_deref)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#not_unsafe_ptr_arg_deref
which is incorrect since no raw pointer is ever dereferenced anywhere.
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 with the linked Rust Playground reproduction and trace the not_unsafe_ptr_arg_deref lint that emits the diagnostic at self.bar(a). Confirm the false positive and update the lint behavior or its coverage so this example no longer reports a raw-pointer dereference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100