-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Raw pointer cast triggers "lifetime may not live long enough" #113257
Comments
I've looked into this. The issue is that typeck considers this cast to be a "coercion cast", because typeck thinks that you could replace the function body with just The bug here is that the THIR does not contain an explicit cast anymore. I'm not sure how to best fix this, as the current logic for "is this a no-op cast (called coercion cast in the code)" is just "try to coerce the types in the same way that happens on coercion sites and if it works it has to be useless". Which is wrong in the presence of lifetimes. It seems like the current strategy works this way because it reuses some code in THIR building. Thinking about it a little more, this is very special to pointer casts, because only pointer casts are allowed to change the type like this. Maybe THIR building should just special case pointer casts to always be emitted? |
Unfortunately due to this bug there is a |
I think that's a different case, these are boxes and not raw pointers, and box->box casts are not allowed to do arbitrary changes (and are in fact coercion casts, so the |
@Nilstrieb I'd like to replace the transmutes by raw pointer casts, which IMO is much preferable, similar to #114799. But this bug is in the way of that. |
replace transmute by raw pointer cast Now that rust-lang#113257 is fixed we can finally do this. :)
Rollup merge of rust-lang#117266 - RalfJung:cast-not-transmute, r=thomcc replace transmute by raw pointer cast Now that rust-lang#113257 is fixed we can finally do this. :)
Duplicate of #27214 (2015) :P I will close the OG as fixed :) |
I tried this code:
Playground.
I expected to see this happen: it compiles, since raw pointer casts should be allowed even for completely different types.
Instead, this happened: it fails with:
It looks like for some reason the compiler creates a lifetime obligation here.
Strangely, it works with
cast()
:Playground.
The text was updated successfully, but these errors were encountered: