Safe Transmute: Use 'not yet supported', not 'unspecified' in errors

We can (and will) support analyzing the transmutability of types
whose layouts aren't completely specified by its repr. This change
ensures that the error messages remain sensible after this support
lands.
This commit is contained in:
Jack Wrenn
2024-03-15 17:11:11 +00:00
parent c5b571310d
commit dc35339514
8 changed files with 43 additions and 43 deletions

View File

@@ -186,8 +186,8 @@ pub(crate) mod rustc {
#[derive(Debug, Copy, Clone)]
pub(crate) enum Err {
/// The layout of the type is unspecified.
Unspecified,
/// The layout of the type is not yet supported.
NotYetSupported,
/// This error will be surfaced elsewhere by rustc, so don't surface it.
UnknownLayout,
/// Overflow size
@@ -288,14 +288,14 @@ pub(crate) mod rustc {
if members.len() == 0 {
Ok(Tree::unit())
} else {
Err(Err::Unspecified)
Err(Err::NotYetSupported)
}
}
ty::Array(ty, len) => {
let len = len
.try_eval_target_usize(tcx, ParamEnv::reveal_all())
.ok_or(Err::Unspecified)?;
.ok_or(Err::NotYetSupported)?;
let elt = Tree::from_ty(*ty, tcx)?;
Ok(std::iter::repeat(elt)
.take(len as usize)
@@ -307,7 +307,7 @@ pub(crate) mod rustc {
// If the layout is ill-specified, halt.
if !(adt_def.repr().c() || adt_def.repr().int.is_some()) {
return Err(Err::Unspecified);
return Err(Err::NotYetSupported);
}
// Compute a summary of the type's layout.
@@ -348,7 +348,7 @@ pub(crate) mod rustc {
AdtKind::Union => {
// is the layout well-defined?
if !adt_def.repr().c() {
return Err(Err::Unspecified);
return Err(Err::NotYetSupported);
}
let ty_layout = layout_of(tcx, ty)?;
@@ -384,7 +384,7 @@ pub(crate) mod rustc {
}))
}
_ => Err(Err::Unspecified),
_ => Err(Err::NotYetSupported),
}
}