Skip to content

ptr_cast_constness suggests code from wrong context #14621

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

Closed
samueltardieu opened this issue Apr 15, 2025 · 0 comments · Fixed by #14622
Closed

ptr_cast_constness suggests code from wrong context #14621

samueltardieu opened this issue Apr 15, 2025 · 0 comments · Fixed by #14622
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@samueltardieu
Copy link
Contributor

samueltardieu commented Apr 15, 2025

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

@samueltardieu samueltardieu added the C-bug Category: Clippy is not doing the correct thing label Apr 15, 2025
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Apr 15, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 20, 2025
changelog: [`ptr_cast_constness`]: do not replace suggestion by content
of macro

Fixes #14621
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants