diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 819895e6d1c..f1d17c87248 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -216,15 +216,11 @@ pub trait PrettyPrinter<'tcx>: mut self, f: impl FnOnce(Self) -> Result, t: impl FnOnce(Self) -> Result, - cast: bool, + conversion: &str, ) -> Result { self.write_str("{")?; self = f(self)?; - if cast { - self.write_str(" as ")?; - } else { - self.write_str(": ")?; - } + self.write_str(conversion)?; self = t(self)?; self.write_str("}")?; Ok(self) @@ -1008,7 +1004,7 @@ pub trait PrettyPrinter<'tcx>: Ok(this) }, |this| this.print_type(ty), - true, + " as ", )?; } (Scalar::Ptr(ptr), ty::FnPtr(_)) => { @@ -1019,7 +1015,7 @@ pub trait PrettyPrinter<'tcx>: self = self.typed_value( |this| this.print_value_path(instance.def_id(), instance.substs), |this| this.print_type(ty), - true, + " as ", )?; } // For function type zsts just printing the type is enough @@ -1048,7 +1044,7 @@ pub trait PrettyPrinter<'tcx>: Ok(this) }; self = if print_ty { - self.typed_value(print, |this| this.print_type(ty), false)? + self.typed_value(print, |this| this.print_type(ty), ": ")? } else { print(self)? }; @@ -1076,7 +1072,7 @@ pub trait PrettyPrinter<'tcx>: Ok(this) }, |this| this.print_type(ty), - false, + ": ", ) } else { self.write_str("&_")?; @@ -1477,15 +1473,11 @@ impl PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> { mut self, f: impl FnOnce(Self) -> Result, t: impl FnOnce(Self) -> Result, - cast: bool, + conversion: &str, ) -> Result { self.write_str("{")?; self = f(self)?; - if cast { - self.write_str(" as ")?; - } else { - self.write_str(": ")?; - } + self.write_str(conversion)?; let was_in_value = std::mem::replace(&mut self.in_value, false); self = t(self)?; self.in_value = was_in_value; @@ -1566,7 +1558,7 @@ impl PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> { Ok(this) }; if print_ty { - self.typed_value(print, |this| this.print_type(ty), false) + self.typed_value(print, |this| this.print_type(ty), ": ") } else { print(self) } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 512eec6b9f1..75452b9395b 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -98,7 +98,7 @@ impl std::fmt::Display for ImmTy<'tcx, Tag> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { /// Helper function for printing a scalar to a FmtPrinter fn p<'a, 'tcx, F: std::fmt::Write, Tag>( - mut cx: FmtPrinter<'a, 'tcx, F>, + cx: FmtPrinter<'a, 'tcx, F>, s: ScalarMaybeUndef, ty: Ty<'tcx>, ) -> Result, std::fmt::Error> { @@ -106,12 +106,14 @@ impl std::fmt::Display for ImmTy<'tcx, Tag> { ScalarMaybeUndef::Scalar(s) => { cx.pretty_print_const_scalar(s.erase_tag(), ty, true) } - ScalarMaybeUndef::Undef => { - cx.write_str("{undef ")?; - cx = cx.print_type(ty)?; - cx.write_str("}")?; - Ok(cx) - } + ScalarMaybeUndef::Undef => cx.typed_value( + |mut this| { + this.write_str("{undef ")?; + Ok(this) + }, + |this| this.print_type(ty), + " ", + ), } } ty::tls::with(|tcx| {