Safe Transmute: Fix ICE (due to UnevaluatedConst)

This patch updates the code that looks at the `Assume` type when evaluating if
transmutation is possible. An ICE was being triggered in the case that the
`Assume` parameter contained an unevaluated const (in this test case, due to a
function with missing parameter names).

Fixes #110892
This commit is contained in:
Bryan Garza 2023-07-13 16:32:36 -07:00
parent 8ca44ef9ca
commit ef50e204f3
4 changed files with 96 additions and 1 deletions

View file

@ -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