Skip to content

borrow_as_ptr does not detect implicit casts due to coercions #14406

@RalfJung

Description

@RalfJung

Summary

borrow_as_ptr should detect &expr in places where that is coerced to a raw pointer, and suggest &raw const expr instead (and similar for the mutable case)

Lint Name

borrow_as_ptr

Reproducer

I tried this code:

#![deny(clippy::borrow_as_ptr)]

fn main() {
    let val = 1;
    let p: *const i32 = &val;
}

I expected to see this happen:
the lint should fire

Instead, this happened:
it does not fire

Version

Clippy 0.1.85 (2025-02-17 4d91de4e48) on the playground

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions