Skip to content

Commit 09b89ef

Browse files
committed
Remove a function argument that is always passed with the same value.
1 parent a0eb348 commit 09b89ef

File tree

3 files changed

+21
-46
lines changed

3 files changed

+21
-46
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
106106
// Just print the ptr value. `pretty_print_const_scalar_ptr` would also try to
107107
// print what is points to, which would fail since it has no access to the local
108108
// memory.
109-
cx.pretty_print_const_pointer(ptr, ty, true)
109+
cx.pretty_print_const_pointer(ptr, ty)
110110
}
111111
}
112112
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2776,7 +2776,7 @@ impl<'tcx> Display for ConstantKind<'tcx> {
27762776
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
27772777
match *self {
27782778
ConstantKind::Ty(c) => pretty_print_const(c, fmt, true),
2779-
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt, true),
2779+
ConstantKind::Val(val, ty) => pretty_print_const_value(val, ty, fmt),
27802780
// FIXME(valtrees): Correctly print mir constants.
27812781
ConstantKind::Unevaluated(..) => {
27822782
fmt.write_str("_")?;
@@ -2815,7 +2815,7 @@ fn comma_sep<'tcx>(
28152815
if !first {
28162816
fmt.write_str(", ")?;
28172817
}
2818-
pretty_print_const_value(ct, ty, fmt, true)?;
2818+
pretty_print_const_value(ct, ty, fmt)?;
28192819
first = false;
28202820
}
28212821
Ok(())
@@ -2826,7 +2826,6 @@ fn pretty_print_const_value<'tcx>(
28262826
ct: ConstValue<'tcx>,
28272827
ty: Ty<'tcx>,
28282828
fmt: &mut Formatter<'_>,
2829-
print_ty: bool,
28302829
) -> fmt::Result {
28312830
use crate::ty::print::PrettyPrinter;
28322831

@@ -2935,7 +2934,7 @@ fn pretty_print_const_value<'tcx>(
29352934
fmt.write_str(", ")?;
29362935
}
29372936
write!(fmt, "{}: ", field_def.name)?;
2938-
pretty_print_const_value(ct, ty, fmt, true)?;
2937+
pretty_print_const_value(ct, ty, fmt)?;
29392938
first = false;
29402939
}
29412940
fmt.write_str(" }}")?;
@@ -2945,20 +2944,13 @@ fn pretty_print_const_value<'tcx>(
29452944
_ => unreachable!(),
29462945
}
29472946
return Ok(());
2948-
} else {
2949-
// Fall back to debug pretty printing for invalid constants.
2950-
fmt.write_str(&format!("{:?}", ct))?;
2951-
if print_ty {
2952-
fmt.write_str(&format!(": {}", ty))?;
2953-
}
2954-
return Ok(());
2955-
};
2947+
}
29562948
}
29572949
(ConstValue::Scalar(scalar), _) => {
29582950
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
29592951
cx.print_alloc_ids = true;
29602952
let ty = tcx.lift(ty).unwrap();
2961-
cx = cx.pretty_print_const_scalar(scalar, ty, print_ty)?;
2953+
cx = cx.pretty_print_const_scalar(scalar, ty)?;
29622954
fmt.write_str(&cx.into_buffer())?;
29632955
return Ok(());
29642956
}
@@ -2973,12 +2965,8 @@ fn pretty_print_const_value<'tcx>(
29732965
// their fields instead of just dumping the memory.
29742966
_ => {}
29752967
}
2976-
// fallback
2977-
fmt.write_str(&format!("{:?}", ct))?;
2978-
if print_ty {
2979-
fmt.write_str(&format!(": {}", ty))?;
2980-
}
2981-
Ok(())
2968+
// Fall back to debug pretty printing for invalid constants.
2969+
write!(fmt, "{ct:?}: {ty}")
29822970
})
29832971
}
29842972

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,19 +1393,17 @@ pub trait PrettyPrinter<'tcx>:
13931393
self,
13941394
scalar: Scalar,
13951395
ty: Ty<'tcx>,
1396-
print_ty: bool,
13971396
) -> Result<Self::Const, Self::Error> {
13981397
match scalar {
1399-
Scalar::Ptr(ptr, _size) => self.pretty_print_const_scalar_ptr(ptr, ty, print_ty),
1400-
Scalar::Int(int) => self.pretty_print_const_scalar_int(int, ty, print_ty),
1398+
Scalar::Ptr(ptr, _size) => self.pretty_print_const_scalar_ptr(ptr, ty),
1399+
Scalar::Int(int) => self.pretty_print_const_scalar_int(int, ty, true),
14011400
}
14021401
}
14031402

14041403
fn pretty_print_const_scalar_ptr(
14051404
mut self,
14061405
ptr: Pointer,
14071406
ty: Ty<'tcx>,
1408-
print_ty: bool,
14091407
) -> Result<Self::Const, Self::Error> {
14101408
define_scoped_cx!(self);
14111409

@@ -1459,7 +1457,7 @@ pub trait PrettyPrinter<'tcx>:
14591457
_ => {}
14601458
}
14611459
// Any pointer values not covered by a branch above
1462-
self = self.pretty_print_const_pointer(ptr, ty, print_ty)?;
1460+
self = self.pretty_print_const_pointer(ptr, ty)?;
14631461
Ok(self)
14641462
}
14651463

@@ -1527,24 +1525,18 @@ pub trait PrettyPrinter<'tcx>:
15271525
/// This is overridden for MIR printing because we only want to hide alloc ids from users, not
15281526
/// from MIR where it is actually useful.
15291527
fn pretty_print_const_pointer<Prov: Provenance>(
1530-
mut self,
1528+
self,
15311529
_: Pointer<Prov>,
15321530
ty: Ty<'tcx>,
1533-
print_ty: bool,
15341531
) -> Result<Self::Const, Self::Error> {
1535-
if print_ty {
1536-
self.typed_value(
1537-
|mut this| {
1538-
this.write_str("&_")?;
1539-
Ok(this)
1540-
},
1541-
|this| this.print_type(ty),
1542-
": ",
1543-
)
1544-
} else {
1545-
self.write_str("&_")?;
1546-
Ok(self)
1547-
}
1532+
self.typed_value(
1533+
|mut this| {
1534+
this.write_str("&_")?;
1535+
Ok(this)
1536+
},
1537+
|this| this.print_type(ty),
1538+
": ",
1539+
)
15481540
}
15491541

15501542
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> {
21562148
self,
21572149
p: Pointer<Prov>,
21582150
ty: Ty<'tcx>,
2159-
print_ty: bool,
21602151
) -> Result<Self::Const, Self::Error> {
21612152
let print = |mut this: Self| {
21622153
define_scoped_cx!(this);
@@ -2167,11 +2158,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
21672158
}
21682159
Ok(this)
21692160
};
2170-
if print_ty {
2171-
self.typed_value(print, |this| this.print_type(ty), ": ")
2172-
} else {
2173-
print(self)
2174-
}
2161+
self.typed_value(print, |this| this.print_type(ty), ": ")
21752162
}
21762163
}
21772164

0 commit comments

Comments
 (0)