Skip to content

Implement arbitrary casts in custom mir - #160860

Draft
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:custom-mir-casts
Draft

Implement arbitrary casts in custom mir#160860
maxdexh wants to merge 2 commits into
rust-lang:mainfrom
maxdexh:custom-mir-casts

Conversation

@maxdexh

@maxdexh maxdexh commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

See zulip

Implement custom casts using an enum in intrinsics::mir that closely matches the CastKind enum in the compiler.

We have 5 different ways to cast in custom MIR, 3 with functions (which hard code a cast kind), 1 implicit coerce (which only does subtyping i think), 1 with as (which does a few more). They are all different and the error messages don't tell you what to do. Some are (i think) not possible at all.

This came up while testing miri. We currently have to guess the casting syntax until we find the one that generates the MIR we want. This PR changes that by allowing you to just pick.

The intrinsics::mir::CastKind is currently a flattened version of the compiler's. If nested enums are possible then I'd like to unflatten it.

This is missing tests, still figuring out how those work.

r? RalfJung

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 10, 2026
@rustbot

rustbot commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

RalfJung is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@maxdexh

This comment was marked as resolved.

@rust-bors

This comment was marked as resolved.

@RalfJung

Copy link
Copy Markdown
Member

I am on vacation this week, so this will have to wait a bit. Or maybe @saethlin has time to look at it earlier.

@maxdexh

maxdexh commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

This is not done yet anyway, I still gotta figure out how to unflatten the enum and write some tests. But thanks for letting me know :)

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

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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