Skip to content

Conversation

@felix91gr
Copy link
Contributor

@felix91gr felix91gr commented Sep 19, 2025

  1. Converted example calls of transmute from core::intrinsics::transmute to
    std::mem::transmute.
  2. Eliminated caveat for transmute_ptr_to_ref, since dereferencing raw pointers in const contexts is now stable:
    [tracking issue] dereferencing raw pointers inside constants (const_raw_ptr_deref) rust#51911
  3. Added missing unsafe block for transmute_ptr_to_ref's example
  4. Added more context to useless_transmute's example

changelog: none

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

1. Converted example calls of `transmute` from
`core::intrinsics::transmute` to
`std::mem::transmute`.
2. Eliminated caveat for `transmute_ptr_to_ref`,
since dereferencing raw pointers in const contexts
is now stable:
rust-lang/rust#51911
3. Added missing `unsafe` block for
`transmute_ptr_to_ref`'s example
4. Added more context to `useless_transmute`'s
example
5. Added a missing space in a doc comment
Copy link
Contributor

@Jarcho Jarcho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation changes don't need changelog lines in the PR description.

View changes since this review

Comment on lines -119 to -124
/// ### Known problems
/// - `mem::transmute` in statics and constants is stable from Rust 1.46.0,
/// while dereferencing raw pointer is not stable yet.
/// If you need to do this in those places,
/// you would have to use `transmute` instead.
///
Copy link
Contributor

@Jarcho Jarcho Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint still doesn't take into account whether it's in a constant context. It would also need an MSRV check to fix this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm not sure I understand 100%.

If it doesn't check whether it's in a const context or not, but now it works properly in a const context, then this problem is effectively fixed, no?

I'm guessing this is what you mean about the MSRV, perhaps.

Though OTOH maybe the documentation could mention that "for rust versions prior to X release, this lint will have [this known issue] due to the fact that dereferencing raw pointers wasn't stable before then.". Would that be appropriate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It only works correctly if the MSRV is high enough to include const raw pointer dereferences.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ping @felix91gr. Just waiting on this. *const pointers can be dereferenced as of 1.58, *mut as of 1.83.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho ty for the ping. I got taken away for a bit. Where do I specify this? I think I've never have added a MSRV in Clippy before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For documenting it just keep it in the "known problems" section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho so then, if I got you correctly, the only change needed to correct this is of documentation, right? I thought you meant that a MSRV config should be added to differentiate between all the cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either would be an acceptable PR. Actually adding the code to handle the MSRV would be the better fix.

If you want a to actually fix the issue you'll need to add the msrv to clippy_utils/src/msrvs.rs. These are named by feature so you'll add something like CONST_RAW_CONST_PTR_DEREF and CONST_RAW_MUT_PTR_DEREF. You can use is_in_const_context to check for constness.

Everything else is already done since the lint has an MSRV check for the suggestion.

@felix91gr
Copy link
Contributor Author

Documentation changes don't need changelog lines in the PR description.

View changes since this review

Oh thank god, this is so much better! Thx, Jason!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants