1
Fork 0
This commit is contained in:
b-naber 2022-09-15 22:27:41 +02:00
parent 6af8fb7936
commit d77248e6d2
5 changed files with 9 additions and 19 deletions

View file

@ -38,6 +38,11 @@ where
}) })
} }
// FIXME(valtrees): This function is necessary because `fold_regions`
// panics for mir constants in the visitor.
//
// Once `visit_mir_constant` is removed we can also remove this function
// and just use `renumber_regions`.
fn renumber_regions_in_mir_constant<'tcx>( fn renumber_regions_in_mir_constant<'tcx>(
infcx: &InferCtxt<'_, 'tcx>, infcx: &InferCtxt<'_, 'tcx>,
value: ConstantKind<'tcx>, value: ConstantKind<'tcx>,

View file

@ -1816,12 +1816,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) { fn check_operand(&mut self, op: &Operand<'tcx>, location: Location) {
if let Operand::Constant(constant) = op { if let Operand::Constant(constant) = op {
let maybe_uneval = match constant.literal { let maybe_uneval = match constant.literal {
ConstantKind::Ty(ct) => match ct.kind() { ConstantKind::Val(..) | ConstantKind::Ty(_) => None,
ty::ConstKind::Unevaluated(uv) => Some(uv.expand()),
_ => None,
},
ConstantKind::Unevaluated(uv, _) => Some(uv), ConstantKind::Unevaluated(uv, _) => Some(uv),
ConstantKind::Val(..) => None,
}; };
if let Some(uv) = maybe_uneval { if let Some(uv) = maybe_uneval {

View file

@ -117,17 +117,7 @@ pub(crate) fn codegen_constant<'tcx>(
constant: &Constant<'tcx>, constant: &Constant<'tcx>,
) -> CValue<'tcx> { ) -> CValue<'tcx> {
let (const_val, ty) = match fx.monomorphize(constant.literal) { let (const_val, ty) = match fx.monomorphize(constant.literal) {
ConstantKind::Ty(const_) => match const_.kind() { ConstantKind::Ty(const_) => unreachable!("{:?}", const_),
ConstKind::Value(valtree) => {
(fx.tcx.valtree_to_const_val((const_.ty(), valtree)), const_.ty())
}
ConstKind::Unevaluated(_) => bug!("expected constant to be evaluated at this stage"),
ConstKind::Param(_)
| ConstKind::Infer(_)
| ConstKind::Bound(_, _)
| ConstKind::Placeholder(_)
| ConstKind::Error(_) => unreachable!("{:?}", const_),
},
ConstantKind::Unevaluated(ty::Unevaluated { def, substs, promoted }, ty) ConstantKind::Unevaluated(ty::Unevaluated { def, substs, promoted }, ty)
if fx.tcx.is_static(def.did) => if fx.tcx.is_static(def.did) =>
{ {

View file

@ -2643,6 +2643,7 @@ impl<'tcx> Display for ConstantKind<'tcx> {
match *self { match *self {
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true), ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true), ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
// FIXME(valtrees): Correctly print mir constants.
ConstantKind::Unevaluated(..) => { ConstantKind::Unevaluated(..) => {
fmt.write_str("_")?; fmt.write_str("_")?;
Ok(()) Ok(())

View file

@ -307,9 +307,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
// Promoteds must lint and not error as the user didn't ask for them // Promoteds must lint and not error as the user didn't ask for them
true true
} }
ConstantKind::Unevaluated(_, ty) | ConstantKind::Val(_, ty) => { ConstantKind::Unevaluated(..) | ConstantKind::Val(..) => c.needs_subst(),
ty.needs_subst()
}
}; };
if lint_only { if lint_only {
// Out of backwards compatibility we cannot report hard errors in unused // Out of backwards compatibility we cannot report hard errors in unused