Skip to content

borrow_deref_ref does not understand &raw #13584

Closed
@cyrgani

Description

@cyrgani

Summary

borrow_deref_ref ignores the usage of &raw const *s and treats it like &*s, which is obviously wrong.

Lint Name

borrow_deref_ref

Reproducer

I tried this code:

fn main() {
    let s = "Hello, world!\n";
    let p = &raw const *s;

    unsafe {
        libc::printf(p as *const i8);
    }
}

I saw this happen:

warning: deref on an immutable reference
 --> src/main.rs:3:13
  |
3 |     let p = &raw const *s;
  |             ^^^^^^^^^^^^^ help: if you would like to reborrow, try removing `&*`: `s`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
  = note: `#[warn(clippy::borrow_deref_ref)]` on by default

I expected to see this happen:
no such warning

Version

rustc 1.84.0-nightly

(2024-10-21 4392847)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions