-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Description
Description
The ref_as_ptr lint currently warns on all reference → pointer casts, including borrows of named locals. There is an internal TODO in the implementation:
// TODO: only block the lint if `cast_expr` is a temporary
I interpret “temporary” to mean values created by expressions without a named local, e.g., literals (&42), function return values (&foo()), struct/tuple literals, etc., whose lifetime ends at statement evaluation — not references to named variables. Under this definition:
let val = 1;
f(&val as *const _); // should *not* lint
f(&val as *const i32); // should *not* lintbut
f(&42 as *const _); // should lint
let _ = &String::new() as *const _; // should lintbecause those expressions borrow temporaries.
The current implementation lints both cases. If the goal of the TODO is to only warn when cast_expr is a true temporary, I want to confirm if this understanding is correct.
Metadata
Metadata
Assignees
Labels
No labels