safe transmute: forbid reference lifetime extension
Modifies `BikeshedIntrinsicFrom` to forbid lifetime extensions on references. This static check can be opted out of with the `Assume::lifetimes` flag. Fixes #129097
This commit is contained in:
@@ -63,7 +63,9 @@ pub mod rustc {
|
||||
use std::fmt::{self, Write};
|
||||
|
||||
use rustc_middle::mir::Mutability;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::layout::{LayoutCx, LayoutError};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_target::abi::Layout;
|
||||
|
||||
/// A reference in the layout.
|
||||
#[derive(Debug, Hash, Eq, PartialEq, Clone, Copy)]
|
||||
@@ -120,4 +122,13 @@ pub mod rustc {
|
||||
self != &Self::Primitive
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn layout_of<'tcx>(
|
||||
cx: LayoutCx<'tcx, TyCtxt<'tcx>>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<Layout<'tcx>, &'tcx LayoutError<'tcx>> {
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
let ty = cx.tcx.erase_regions(ty);
|
||||
cx.layout_of(ty).map(|tl| tl.layout)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user