Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

borrow_deref_ref does not understand &raw #13584

Closed
cyrgani opened this issue Oct 22, 2024 · 0 comments · Fixed by #13600
Closed

borrow_deref_ref does not understand &raw #13584

cyrgani opened this issue Oct 22, 2024 · 0 comments · Fixed by #13600
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@cyrgani
Copy link
Contributor

cyrgani commented Oct 22, 2024

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 4392847410ddd67f6734)

Additional Labels

No response

@cyrgani cyrgani added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 22, 2024
@bors bors closed this as completed in c02f3a2 Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant