summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_transmute/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_transmute/src')
-rw-r--r--compiler/rustc_transmute/src/layout/tree.rs16
-rw-r--r--compiler/rustc_transmute/src/lib.rs13
2 files changed, 20 insertions, 9 deletions
diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs
index be434eb7d..e8ddb0a43 100644
--- a/compiler/rustc_transmute/src/layout/tree.rs
+++ b/compiler/rustc_transmute/src/layout/tree.rs
@@ -175,8 +175,8 @@ pub(crate) mod rustc {
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::util::Discr;
use rustc_middle::ty::AdtDef;
+ use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::ParamEnv;
- use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::VariantDef;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::ErrorGuaranteed;
@@ -195,7 +195,7 @@ pub(crate) mod rustc {
impl<'tcx> From<&LayoutError<'tcx>> for Err {
fn from(err: &LayoutError<'tcx>) -> Self {
match err {
- LayoutError::Unknown(..) => Self::UnknownLayout,
+ LayoutError::Unknown(..) | LayoutError::ReferencesError(..) => Self::UnknownLayout,
err => unimplemented!("{:?}", err),
}
}
@@ -297,7 +297,7 @@ pub(crate) mod rustc {
.fold(Tree::unit(), |tree, elt| tree.then(elt)))
}
- ty::Adt(adt_def, substs_ref) => {
+ ty::Adt(adt_def, args_ref) => {
use rustc_middle::ty::AdtKind;
// If the layout is ill-specified, halt.
@@ -316,7 +316,7 @@ pub(crate) mod rustc {
AdtKind::Struct => Self::from_repr_c_variant(
ty,
*adt_def,
- substs_ref,
+ args_ref,
&layout_summary,
None,
adt_def.non_enum_variant(),
@@ -330,7 +330,7 @@ pub(crate) mod rustc {
tree = tree.or(Self::from_repr_c_variant(
ty,
*adt_def,
- substs_ref,
+ args_ref,
&layout_summary,
Some(discr),
adt_def.variant(idx),
@@ -351,7 +351,7 @@ pub(crate) mod rustc {
let mut tree = Tree::uninhabited();
for field in adt_def.all_fields() {
- let variant_ty = field.ty(tcx, substs_ref);
+ let variant_ty = field.ty(tcx, args_ref);
let variant_layout = layout_of(tcx, variant_ty)?;
let padding_needed = ty_layout.size() - variant_layout.size();
let variant = Self::def(Def::Field(field))
@@ -383,7 +383,7 @@ pub(crate) mod rustc {
fn from_repr_c_variant(
ty: Ty<'tcx>,
adt_def: AdtDef<'tcx>,
- substs_ref: SubstsRef<'tcx>,
+ args_ref: GenericArgsRef<'tcx>,
layout_summary: &LayoutSummary,
discr: Option<Discr<'tcx>>,
variant_def: &'tcx VariantDef,
@@ -427,7 +427,7 @@ pub(crate) mod rustc {
// Next come fields.
let fields_span = trace_span!("treeifying fields").entered();
for field_def in variant_def.fields.iter() {
- let field_ty = field_def.ty(tcx, substs_ref);
+ let field_ty = field_def.ty(tcx, args_ref);
let _span = trace_span!("treeifying field", field = ?field_ty).entered();
// begin with the field's visibility
diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs
index 34ad6bd8c..05ad4a4a1 100644
--- a/compiler/rustc_transmute/src/lib.rs
+++ b/compiler/rustc_transmute/src/lib.rs
@@ -78,6 +78,7 @@ mod rustc {
use rustc_middle::ty::ParamEnv;
use rustc_middle::ty::Ty;
use rustc_middle::ty::TyCtxt;
+ use rustc_middle::ty::ValTree;
/// The source and destination types of a transmutation.
#[derive(TypeVisitable, Debug, Clone, Copy)]
@@ -148,7 +149,17 @@ mod rustc {
);
let variant = adt_def.non_enum_variant();
- let fields = c.to_valtree().unwrap_branch();
+ let fields = match c.try_to_valtree() {
+ Some(ValTree::Branch(branch)) => branch,
+ _ => {
+ return Some(Self {
+ alignment: true,
+ lifetimes: true,
+ safety: true,
+ validity: true,
+ });
+ }
+ };
let get_field = |name| {
let (field_idx, _) = variant