rust-lang / rust-lang/rust-clippy
Split coercions from `borrow_as_ptr` into separate lint
Nobody has claimed this yet.
- 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
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 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