Skip to content

Apply missing transmute annotations lint - #161677

Open
GTimothy wants to merge 8 commits into
rust-lang:mainfrom
GTimothy:missing-transmute-annotations
Open

Apply missing transmute annotations lint#161677
GTimothy wants to merge 8 commits into
rust-lang:mainfrom
GTimothy:missing-transmute-annotations

Conversation

@GTimothy

Copy link
Copy Markdown
Contributor

Best reviewed case by case. Special care should be taken when involving pointers.

The missing_transmute_annotations lint.
The point of the lint is that in order to ensure that the safety invariant holds, the transmute source and destination should be explicitly fixed.

Remarks:

  • many, many many suggested fixes were invalid rust code, as they include paths when they should just use the type in scope.
    I kept the initial suggestion and the fixed suggestion in separate commit so that the issue can be observed easily and the clippy lint can be fixed before even considering enabling it.
  • the lint currently fires inside local expanded code (not in calls to external macros). Having dynamically added src and dest inside a macro is a bit iffy and sometimes impossible, as #general > Running clippy on the rustc repo @ 💬 @scottmcm points out. Perhaps there should be a lint about that :)

Notes:

Yet I still propose a fix because this case seems clear cut, it may be an exception to the iffiness rule.

Related: "Enforce even more library clippy lints in CI" by @ChrisDenton: #161328

@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

stdarch is developed in its own repository. If possible, consider making this change to rust-lang/stdarch instead.

cc @Amanieu, @folkertdev, @sayantn

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred in library/core/src/fmt/rt.rs

cc @m-ou-se

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 24, 2026
@rustbot

rustbot commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, nia-e

unsafe { crate::mem::transmute::<_, u128>(a) == crate::mem::transmute::<_, u128>(b) }
unsafe {
crate::mem::transmute::<crate::any::TypeId, u128>(a)
== crate::mem::transmute::<crate::any::TypeId, u128>(b)

@RalfJung RalfJung Aug 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW I am not sure this makes the code better. The type of a and b is right there in the function signature, what is the point in repeating it?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

maybe
a) we could add an expect/allow instead.
b) the lint should not fire in this case. Right now, the lint does not fire if the transmute is the only element in the function, which is not the case here, it is a bit more complex.

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants