1
Fork 0

Replace a custom lift method with a Lift impl

This commit is contained in:
Oli Scherer 2021-03-10 11:45:22 +00:00
parent 3127a9c60f
commit 20f737966e
2 changed files with 7 additions and 4 deletions

View file

@ -8,7 +8,7 @@ use rustc_apfloat::{
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout}; use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout};
use crate::ty::{ParamEnv, ScalarInt, Ty, TyCtxt}; use crate::ty::{Lift, ParamEnv, ScalarInt, Ty, TyCtxt};
use super::{AllocId, Allocation, InterpResult, Pointer, PointerArithmetic}; use super::{AllocId, Allocation, InterpResult, Pointer, PointerArithmetic};
@ -53,8 +53,9 @@ impl From<Scalar> for ConstValue<'tcx> {
} }
} }
impl<'tcx> ConstValue<'tcx> { impl<'a, 'tcx> Lift<'tcx> for ConstValue<'a> {
pub fn lift<'lifted>(self, tcx: TyCtxt<'lifted>) -> Option<ConstValue<'lifted>> { type Lifted = ConstValue<'tcx>;
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<ConstValue<'tcx>> {
Some(match self { Some(match self {
ConstValue::Scalar(s) => ConstValue::Scalar(s), ConstValue::Scalar(s) => ConstValue::Scalar(s),
ConstValue::Slice { data, start, end } => { ConstValue::Slice { data, start, end } => {
@ -65,7 +66,9 @@ impl<'tcx> ConstValue<'tcx> {
} }
}) })
} }
}
impl<'tcx> ConstValue<'tcx> {
#[inline] #[inline]
pub fn try_to_scalar(&self) -> Option<Scalar> { pub fn try_to_scalar(&self) -> Option<Scalar> {
match *self { match *self {

View file

@ -2738,7 +2738,7 @@ fn pretty_print_const_value(
) -> fmt::Result { ) -> fmt::Result {
use crate::ty::print::PrettyPrinter; use crate::ty::print::PrettyPrinter;
ty::tls::with(|tcx| { ty::tls::with(|tcx| {
let val = val.lift(tcx).unwrap(); let val = tcx.lift(val).unwrap();
let ty = tcx.lift(ty).unwrap(); let ty = tcx.lift(ty).unwrap();
let mut cx = FmtPrinter::new(tcx, fmt, Namespace::ValueNS); let mut cx = FmtPrinter::new(tcx, fmt, Namespace::ValueNS);
cx.print_alloc_ids = true; cx.print_alloc_ids = true;