Skip to content

ptr_cast_constness suggests code from wrong context #14621

@samueltardieu

Description

@samueltardieu

Summary

Code from macro shows up in suggestion

Reproducer

I tried this code:

#![deny(clippy::ptr_cast_constness)]
fn main() {
    let mut local = 4;
    let _ = std::ptr::addr_of_mut!(local) as *const _;
}

I expected to see this happen:

`4 |     let _ = std::ptr::addr_of_mut!(local) as *const _;
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `std::ptr::addr_of_mut!(local).cast_const()`

Instead, this happened:

4 |     let _ = std::ptr::addr_of_mut!(local) as *const _;
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try `pointer::cast_const`, a safer alternative: `(&raw mut $place).cast_const()`

@rustbot claim
@rustbot label +I-suggestion-causes-error

Version


Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions