Remove a function argument that is always passed with the same value.

This commit is contained in:
Oli Scherer 2023-06-28 09:43:31 +00:00
parent a0eb348d38
commit 09b89efa70
3 changed files with 21 additions and 46 deletions

View File

@ -106,7 +106,7 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
// Just print the ptr value. `pretty_print_const_scalar_ptr` would also try to
// print what is points to, which would fail since it has no access to the local
// memory.
cx.pretty_print_const_pointer(ptr, ty, true)
cx.pretty_print_const_pointer(ptr, ty)
}
}
}

View File

@ -2776,7 +2776,7 @@ impl<'tcx> Display for ConstantKind<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
match *self {
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),
// FIXME(valtrees): Correctly print mir constants.
ConstantKind::Unevaluated(..) => {
fmt.write_str("_")?;
@ -2815,7 +2815,7 @@ fn comma_sep<'tcx>(
if !first {
fmt.write_str(", ")?;
}
pretty_print_const_value(ct, ty, fmt, true)?;
pretty_print_const_value(ct, ty, fmt)?;
first = false;
}
Ok(())
@ -2826,7 +2826,6 @@ fn pretty_print_const_value<'tcx>(
ct: ConstValue<'tcx>,
ty: Ty<'tcx>,
fmt: &mut Formatter<'_>,
print_ty: bool,
) -> fmt::Result {
use crate::ty::print::PrettyPrinter;
@ -2935,7 +2934,7 @@ fn pretty_print_const_value<'tcx>(
fmt.write_str(", ")?;
}
write!(fmt, "{}: ", field_def.name)?;
pretty_print_const_value(ct, ty, fmt, true)?;
pretty_print_const_value(ct, ty, fmt)?;
first = false;
}
fmt.write_str(" }}")?;
@ -2945,20 +2944,13 @@ fn pretty_print_const_value<'tcx>(
_ => unreachable!(),
}
return Ok(());
} else {
// Fall back to debug pretty printing for invalid constants.
fmt.write_str(&format!("{:?}", ct))?;
if print_ty {
fmt.write_str(&format!(": {}", ty))?;
}
return Ok(());
};
}
}
(ConstValue::Scalar(scalar), _) => {
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
cx.print_alloc_ids = true;
let ty = tcx.lift(ty).unwrap();
cx = cx.pretty_print_const_scalar(scalar, ty, print_ty)?;
cx = cx.pretty_print_const_scalar(scalar, ty)?;
fmt.write_str(&cx.into_buffer())?;
return Ok(());
}
@ -2973,12 +2965,8 @@ fn pretty_print_const_value<'tcx>(
// their fields instead of just dumping the memory.
_ => {}
}
// fallback
fmt.write_str(&format!("{:?}", ct))?;
if print_ty {
fmt.write_str(&format!(": {}", ty))?;
}
Ok(())
// Fall back to debug pretty printing for invalid constants.
write!(fmt, "{ct:?}: {ty}")
})
}

View File

@ -1393,11 +1393,10 @@ pub trait PrettyPrinter<'tcx>:
self,
scalar: Scalar,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<Self::Const, Self::Error> {
match scalar {
Scalar::Ptr(ptr, _size) => self.pretty_print_const_scalar_ptr(ptr, ty, print_ty),
Scalar::Int(int) => self.pretty_print_const_scalar_int(int, ty, print_ty),
Scalar::Ptr(ptr, _size) => self.pretty_print_const_scalar_ptr(ptr, ty),
Scalar::Int(int) => self.pretty_print_const_scalar_int(int, ty, true),
}
}
@ -1405,7 +1404,6 @@ pub trait PrettyPrinter<'tcx>:
mut self,
ptr: Pointer,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<Self::Const, Self::Error> {
define_scoped_cx!(self);
@ -1459,7 +1457,7 @@ pub trait PrettyPrinter<'tcx>:
_ => {}
}
// Any pointer values not covered by a branch above
self = self.pretty_print_const_pointer(ptr, ty, print_ty)?;
self = self.pretty_print_const_pointer(ptr, ty)?;
Ok(self)
}
@ -1527,24 +1525,18 @@ pub trait PrettyPrinter<'tcx>:
/// This is overridden for MIR printing because we only want to hide alloc ids from users, not
/// from MIR where it is actually useful.
fn pretty_print_const_pointer<Prov: Provenance>(
mut self,
self,
_: Pointer<Prov>,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<Self::Const, Self::Error> {
if print_ty {
self.typed_value(
|mut this| {
this.write_str("&_")?;
Ok(this)
},
|this| this.print_type(ty),
": ",
)
} else {
self.write_str("&_")?;
Ok(self)
}
self.typed_value(
|mut this| {
this.write_str("&_")?;
Ok(this)
},
|this| this.print_type(ty),
": ",
)
}
fn pretty_print_byte_str(mut self, byte_str: &'tcx [u8]) -> Result<Self::Const, Self::Error> {
@ -2156,7 +2148,6 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
self,
p: Pointer<Prov>,
ty: Ty<'tcx>,
print_ty: bool,
) -> Result<Self::Const, Self::Error> {
let print = |mut this: Self| {
define_scoped_cx!(this);
@ -2167,11 +2158,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
}
Ok(this)
};
if print_ty {
self.typed_value(print, |this| this.print_type(ty), ": ")
} else {
print(self)
}
self.typed_value(print, |this| this.print_type(ty), ": ")
}
}