Explain and simplify valtree -> mir-const fallback

This commit is contained in:
Oli Scherer 2023-05-31 12:18:47 +00:00
parent 9cf7810078
commit c4d5dded57

View File

@ -519,16 +519,18 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
};
let cid = GlobalId { instance, promoted: None };
// Prefer
// Prefer valtrees over opaque constants.
let const_value = self
.tcx
.const_eval_global_id_for_typeck(param_env_reveal_all, cid, Some(span))
.and_then(|val| match val {
Some(valtree) => Ok(mir::ConstantKind::Ty(self.tcx.mk_const(valtree, ty))),
None => self
.tcx
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
.map(|lit| mir::ConstantKind::Val(lit, ty)),
.map(|val| match val {
Some(valtree) => mir::ConstantKind::Ty(self.tcx.mk_const(valtree, ty)),
None => mir::ConstantKind::Val(
self.tcx
.const_eval_global_id(param_env_reveal_all, cid, Some(span))
.expect("const_eval_global_id_for_typeck should have already failed"),
ty,
),
});
match const_value {