Skip to content
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

Add lint against ptr-to-int transmutes in consts #87525

Open
RalfJung opened this issue Jul 27, 2021 · 6 comments
Open

Add lint against ptr-to-int transmutes in consts #87525

RalfJung opened this issue Jul 27, 2021 · 6 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation)

Comments

@RalfJung
Copy link
Member

We do not allow ptr-to-int casts in const context, so people might be tempted to do a transmute instead. This will not work, and if they ever actually test their code during CTFE they will get an error, but it might still be good to add an extra layer of defense here (since this is a rather odd corner of the language) and have a lint for this.

@jhpratt started working on this, here's a link.

@RalfJung
Copy link
Member Author

Cc @rust-lang/wg-const-eval

@jhpratt do you want to work on this, or leave this issue open for anyone to pick up?

@jhpratt
Copy link
Member

jhpratt commented Jul 27, 2021

Someone else can pick this up, as I've got other priorities for the near future. As I mentioned feel free to use the code linked.

It's worth noting that a lint would ideally also catch transmutes that use a union, though that would be quite a bit more difficult I imagine.

@RalfJung
Copy link
Member Author

It's worth noting that a lint would ideally also catch transmutes that use a union, though that would be quite a bit more difficult I imagine.

That'll require a lot of complexity, for a case that I assume will be exceedingly rare. So I don't think that is effort, lines of code, and compile time well spent.

@jhpratt
Copy link
Member

jhpratt commented Jul 27, 2021

Agreed. Just throwing it out there.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 28, 2021

More context on the lint can be found in the discussion starting at #85769 (comment)

@clubby789
Copy link
Contributor

@rustbot label +A-const-eval

@rustbot rustbot added the A-const-eval Area: constant evaluation (mir interpretation) label Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation)
Projects
None yet
Development

No branches or pull requests

5 participants