rust-lang / rust-lang/rust-clippy

Warn when casting & to *mut when &mut is available.

Open
#1,087 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Warn when casting from & to *mut whenever it's possible to use &mut. I don't think this is UB currently but it still seems a bit too handwavey for unsafe code.

let owned_value = ...; // could be a mut binding

// suspect - have to inspect related code to see if there's credit to this assertion
let ptr = &owned_value as *const _ as *mut i8;

// clearer - proves minor ownership truths at this point
let ptr = &mut owned_value as *mut _ as *mut i8;

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

No file, test, or entry point is named in the issue; begin by locating the relevant rust-clippy lint implementation and its tests. Compare the two casting examples and consider the work complete when the lint warns on eligible casts from shared to mutable pointers while allowing cases where &mut is unavailable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.