rust-lang / rust-lang/rust-clippy

Lint "disallowed-methods" does not work with pointer methods.

Open
#10,156 1 comment 0 reactions 0 assignees View on GitHub

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

Summary

I wanted to blacklist as_ref() / as_mut() methods on raw pointers, but it seems that it doesn't work with Clippy's "disallowed-methods".

Reproducer

My config in clippy.toml:

disallowed-methods = [
    "std::ptr::as_ref",
    "std::ptr::as_mut",
    "core::ptr::const_ptr::as_ref",
    "core::ptr::mut_ptr::as_mut",
    "pointer::as_ref",
    "pointer::as_mut"
]

Example code:

fn main() {
    let x = 123;
    let ptr: *const i32 = &x;
    let x2 = unsafe { ptr.as_ref().unwrap() };
    println!("Hello, world! {x2}");
}

I expected Clippy to complain about as_ref() call but it didn't.

Version
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2
Additional Labels

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

Start with the provided clippy.toml and Rust reproducer, confirming that disallowed-methods does not report the pointer as_ref() call. Trace the disallowed-methods lint from its entry point and add coverage for the reproduced calls; done means the configured pointer methods produce diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.