Fix transmute goal

This commit is contained in:
Michael Goulet
2024-06-17 19:27:23 -04:00
parent fb6f4b4a6e
commit 6609501ca7
6 changed files with 59 additions and 39 deletions

View File

@@ -890,25 +890,6 @@ where
self.infcx.well_formed_goals(param_env, arg)
}
/*
pub(super) fn is_transmutable(
&self,
src_and_dst: rustc_transmute::Types<I>,
assume: rustc_transmute::Assume,
) -> Result<Certainty, NoSolution> {
use rustc_transmute::Answer;
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
ObligationCause::dummy(),
src_and_dst,
assume,
) {
Answer::Yes => Ok(Certainty::Yes),
Answer::No(_) | Answer::If(_) => Err(NoSolution),
}
}
*/
pub(super) fn trait_ref_is_knowable(
&mut self,
param_env: I::ParamEnv,
@@ -1016,6 +997,16 @@ where
) -> Option<I::Const> {
self.infcx.try_const_eval_resolve(param_env, unevaluated)
}
pub(super) fn is_transmutable(
&mut self,
param_env: I::ParamEnv,
dst: I::Ty,
src: I::Ty,
assume: I::Const,
) -> Result<Certainty, NoSolution> {
self.infcx.is_transmutable(param_env, dst, src, assume)
}
}
/// Eagerly replace aliases with inference variables, emitting `AliasRelate`

View File

@@ -601,12 +601,10 @@ where
}
fn consider_builtin_transmute_candidate(
_ecx: &mut EvalCtxt<'_, Infcx>,
_goal: Goal<I, Self>,
ecx: &mut EvalCtxt<'_, Infcx>,
goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolution> {
// TODO:
todo!()
/* if goal.predicate.polarity != ty::PredicatePolarity::Positive {
if goal.predicate.polarity != ty::PredicatePolarity::Positive {
return Err(NoSolution);
}
@@ -615,26 +613,17 @@ where
return Err(NoSolution);
}
// Erase regions because we compute layouts in `rustc_transmute`,
// which will ICE for region vars.
let args = ecx.interner().erase_regions(goal.predicate.trait_ref.args);
let Some(assume) =
rustc_transmute::Assume::from_const(ecx.interner(), goal.param_env, args.const_at(2))
else {
return Err(NoSolution);
};
// FIXME: This actually should destructure the `Result` we get from transmutability and
// register candiates. We probably need to register >1 since we may have an OR of ANDs.
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
let certainty = ecx.is_transmutable(
rustc_transmute::Types { dst: args.type_at(0), src: args.type_at(1) },
assume,
goal.param_env,
goal.predicate.trait_ref.args.type_at(0),
goal.predicate.trait_ref.args.type_at(1),
goal.predicate.trait_ref.args.const_at(2),
)?;
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
})
*/
}
/// ```ignore (builtin impl example)