Generalize typed value printing and use for undef printing
This commit is contained in:
parent
cc9ca640c2
commit
2e91065a6f
2 changed files with 18 additions and 24 deletions
|
@ -216,15 +216,11 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
mut self,
|
mut self,
|
||||||
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||||
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||||
cast: bool,
|
conversion: &str,
|
||||||
) -> Result<Self::Const, Self::Error> {
|
) -> Result<Self::Const, Self::Error> {
|
||||||
self.write_str("{")?;
|
self.write_str("{")?;
|
||||||
self = f(self)?;
|
self = f(self)?;
|
||||||
if cast {
|
self.write_str(conversion)?;
|
||||||
self.write_str(" as ")?;
|
|
||||||
} else {
|
|
||||||
self.write_str(": ")?;
|
|
||||||
}
|
|
||||||
self = t(self)?;
|
self = t(self)?;
|
||||||
self.write_str("}")?;
|
self.write_str("}")?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
|
@ -1008,7 +1004,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
Ok(this)
|
Ok(this)
|
||||||
},
|
},
|
||||||
|this| this.print_type(ty),
|
|this| this.print_type(ty),
|
||||||
true,
|
" as ",
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
|
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
|
||||||
|
@ -1019,7 +1015,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
self = self.typed_value(
|
self = self.typed_value(
|
||||||
|this| this.print_value_path(instance.def_id(), instance.substs),
|
|this| this.print_value_path(instance.def_id(), instance.substs),
|
||||||
|this| this.print_type(ty),
|
|this| this.print_type(ty),
|
||||||
true,
|
" as ",
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
// For function type zsts just printing the type is enough
|
// For function type zsts just printing the type is enough
|
||||||
|
@ -1048,7 +1044,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
Ok(this)
|
Ok(this)
|
||||||
};
|
};
|
||||||
self = if print_ty {
|
self = if print_ty {
|
||||||
self.typed_value(print, |this| this.print_type(ty), false)?
|
self.typed_value(print, |this| this.print_type(ty), ": ")?
|
||||||
} else {
|
} else {
|
||||||
print(self)?
|
print(self)?
|
||||||
};
|
};
|
||||||
|
@ -1076,7 +1072,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||||
Ok(this)
|
Ok(this)
|
||||||
},
|
},
|
||||||
|this| this.print_type(ty),
|
|this| this.print_type(ty),
|
||||||
false,
|
": ",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.write_str("&_")?;
|
self.write_str("&_")?;
|
||||||
|
@ -1477,15 +1473,11 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
|
||||||
mut self,
|
mut self,
|
||||||
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||||
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||||
cast: bool,
|
conversion: &str,
|
||||||
) -> Result<Self::Const, Self::Error> {
|
) -> Result<Self::Const, Self::Error> {
|
||||||
self.write_str("{")?;
|
self.write_str("{")?;
|
||||||
self = f(self)?;
|
self = f(self)?;
|
||||||
if cast {
|
self.write_str(conversion)?;
|
||||||
self.write_str(" as ")?;
|
|
||||||
} else {
|
|
||||||
self.write_str(": ")?;
|
|
||||||
}
|
|
||||||
let was_in_value = std::mem::replace(&mut self.in_value, false);
|
let was_in_value = std::mem::replace(&mut self.in_value, false);
|
||||||
self = t(self)?;
|
self = t(self)?;
|
||||||
self.in_value = was_in_value;
|
self.in_value = was_in_value;
|
||||||
|
@ -1566,7 +1558,7 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
|
||||||
Ok(this)
|
Ok(this)
|
||||||
};
|
};
|
||||||
if print_ty {
|
if print_ty {
|
||||||
self.typed_value(print, |this| this.print_type(ty), false)
|
self.typed_value(print, |this| this.print_type(ty), ": ")
|
||||||
} else {
|
} else {
|
||||||
print(self)
|
print(self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
/// Helper function for printing a scalar to a FmtPrinter
|
/// Helper function for printing a scalar to a FmtPrinter
|
||||||
fn p<'a, 'tcx, F: std::fmt::Write, Tag>(
|
fn p<'a, 'tcx, F: std::fmt::Write, Tag>(
|
||||||
mut cx: FmtPrinter<'a, 'tcx, F>,
|
cx: FmtPrinter<'a, 'tcx, F>,
|
||||||
s: ScalarMaybeUndef<Tag>,
|
s: ScalarMaybeUndef<Tag>,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
) -> Result<FmtPrinter<'a, 'tcx, F>, std::fmt::Error> {
|
) -> Result<FmtPrinter<'a, 'tcx, F>, std::fmt::Error> {
|
||||||
|
@ -106,12 +106,14 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
|
||||||
ScalarMaybeUndef::Scalar(s) => {
|
ScalarMaybeUndef::Scalar(s) => {
|
||||||
cx.pretty_print_const_scalar(s.erase_tag(), ty, true)
|
cx.pretty_print_const_scalar(s.erase_tag(), ty, true)
|
||||||
}
|
}
|
||||||
ScalarMaybeUndef::Undef => {
|
ScalarMaybeUndef::Undef => cx.typed_value(
|
||||||
cx.write_str("{undef ")?;
|
|mut this| {
|
||||||
cx = cx.print_type(ty)?;
|
this.write_str("{undef ")?;
|
||||||
cx.write_str("}")?;
|
Ok(this)
|
||||||
Ok(cx)
|
},
|
||||||
}
|
|this| this.print_type(ty),
|
||||||
|
" ",
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ty::tls::with(|tcx| {
|
ty::tls::with(|tcx| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue