rust-lang / rust-lang/rust-clippy

not_unsafe_ptr_arg_deref does not trigger on type aliases and trait methods

Open
#8,092 1 comment 0 reactions 0 assignees View on GitHub

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

Summary

If the raw pointer is used behind a type alias or the function is part of a trait, not_unsafe_ptr_arg_deref is not triggered.

Lint Name

not_unsafe_ptr_arg_deref

Reproducer

I tried this code:

trait Bad {
    fn f(x: *const u8) -> u8 {
        unsafe { *x }
    }
}

type Alias = *const u8;
pub fn bad(x: Alias) -> u8 {
    unsafe { *x }
}

pub fn main() {
    bad(0 as _);
}

Playground

I expected to see this happen: Lint for not_unsafe_ptr_arg_deref is triggered

Instead, this happened: Lint is not triggered

Version

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked Playground reproducer and inspect the not_unsafe_ptr_arg_deref lint entry point. Compare the raw-pointer cases involving the type alias and trait method with the existing behavior; done means the lint triggers for both cases without regressing the current lint 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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.