Ensure SMIR internal
function is safe by celinval · Pull Request #120120 · rust-lang/rust (original) (raw)
The rustc_smir::rustc_internal::internal
function was unsound. It could cause UB in rare cases where the user inadvertently stored the returned object in a location that could outlive the TyCtxt.
In order to make it safe, we now take a type context as an argument to the internal function, and we ensure that interned items are lifted using the provided context.
Thus, this change ensures that the compiler can properly enforce that the object does not outlive the type context it was lifted to.
Call-outs
- I added a
Lift
implementation toLayout
since it is directly interned, but it didn't have aLift
implementation. - To be on the safe side, I think we will need to make a similar change to the code that stores objects with
'tcx
lifetime intotables
. In cases where the code is reachable viastable()
function call, there is no guarantee that tables won't outlive the object being stored.
r? @oli-obk