rust-lang / rust-lang/rust-clippy

Split coercions from `borrow_as_ptr` into separate lint

Open
#15,230 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Since #14408 was merged, borrow_as_ptr triggers on both as casts and coercions. But coercions are not the same as casts, and the reasons for wanting to lint against them are different.

&expr as *const T is just a redundant cast if expr: T. You can use &raw const expr, which is simpler, or addr_of!(expr). So that seems like the use case intended for the borrow_as_ptr lint. If not expr: T, then it ought to fall outside the scope of this lint, since there are already various lints other lints covering pointer casts, such as ref_as_ptr.

For coercions on the other hand, I think a separate lint is warranted. This lint is named borrow_as_ptr which is parallel to ref_as_ptr, and the documentation of borrow_as_ptr does not make any mention of coercions. I want to be able to lint on pointer casts, but allow coercions, so having these two cases lumped together is awkward.

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 by locating the borrow_as_ptr lint, its documentation, and its tests. Read how the lint distinguishes casts from coercions, then define the separate lint behavior and update coverage so each case can be enabled or allowed independently.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.