Skip to content

borrow_as_ptr false negative when borrowing a temporary literal #16215

@xtqqczze

Description

@xtqqczze

Summary

The borrow_as_ptr lint is emitted for borrowing a local variable as a raw pointer, but it is not emitted when the borrowed expression is a temporary literal.

Lint Name

borrow_as_ptr

Reproducer

the lint does not fire for m1, but does for m2

#[inline(never)]
pub fn m1() {
    let _ptr = &42f32 as *const f32;
}

#[inline(never)]
pub fn m2() {
    let tmp = 42f32;
    let _ptr = &tmp as *const f32;
}

https://godbolt.org/z/xoPTzr6sx

Version


Metadata

Metadata

Assignees

No one assigned

    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