Skip to content

Commit 3b82edd

Browse files
committed
Print braces only in print_ty mode
1 parent 02f4eeb commit 3b82edd

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,16 @@ pub trait PrettyPrinter<'tcx>:
210210
Ok(self)
211211
}
212212

213-
/// Prints `{...}` around what `f` and optionally `t` print
213+
/// Prints `{...}` around what `f` (and optionally `t`) print
214214
fn type_ascribed_value(
215215
mut self,
216216
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
217217
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
218-
print_ty: bool,
219218
) -> Result<Self::Const, Self::Error> {
220219
self.write_str("{")?;
221220
self = f(self)?;
222-
if print_ty {
223-
self.write_str(": ")?;
224-
self = t(self)?;
225-
}
221+
self.write_str(": ")?;
222+
self = t(self)?;
226223
self.write_str("}")?;
227224
Ok(self)
228225
}
@@ -1003,14 +1000,15 @@ pub trait PrettyPrinter<'tcx>:
10031000
(Scalar::Raw { size: 0, .. }, _) => p!(print(ty)),
10041001
// Nontrivial types with scalar bit representation
10051002
(Scalar::Raw { data, size }, _) => {
1006-
self = self.type_ascribed_value(
1007-
|mut this| {
1008-
write!(this, "0x{:01$x}", data, size as usize * 2)?;
1009-
Ok(this)
1010-
},
1011-
|this| this.print_type(ty),
1012-
print_ty,
1013-
)?
1003+
let print = |mut this: Self| {
1004+
write!(this, "0x{:01$x}", data, size as usize * 2)?;
1005+
Ok(this)
1006+
};
1007+
self = if print_ty {
1008+
self.type_ascribed_value(print, |this| this.print_type(ty))?
1009+
} else {
1010+
print(self)?
1011+
};
10141012
}
10151013
// Any pointer values not covered by a branch above
10161014
(Scalar::Ptr(p), _) => {
@@ -1023,19 +1021,23 @@ pub trait PrettyPrinter<'tcx>:
10231021
/// This is overridden for MIR printing because we only want to hide alloc ids from users, not
10241022
/// from MIR where it is actually useful.
10251023
fn pretty_print_const_pointer(
1026-
self,
1024+
mut self,
10271025
_: Pointer,
10281026
ty: Ty<'tcx>,
10291027
print_ty: bool,
10301028
) -> Result<Self::Const, Self::Error> {
1031-
self.type_ascribed_value(
1032-
|mut this| {
1033-
this.write_str("pointer")?;
1034-
Ok(this)
1035-
},
1036-
|this| this.print_type(ty),
1037-
print_ty,
1038-
)
1029+
if print_ty {
1030+
self.type_ascribed_value(
1031+
|mut this| {
1032+
this.write_str("&_")?;
1033+
Ok(this)
1034+
},
1035+
|this| this.print_type(ty),
1036+
)
1037+
} else {
1038+
self.write_str("&_")?;
1039+
Ok(self)
1040+
}
10391041
}
10401042

10411043
fn pretty_print_byte_str(mut self, byte_str: &'tcx [u8]) -> Result<Self::Const, Self::Error> {
@@ -1430,16 +1432,13 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
14301432
mut self,
14311433
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
14321434
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
1433-
print_ty: bool,
14341435
) -> Result<Self::Const, Self::Error> {
14351436
self.write_str("{")?;
14361437
self = f(self)?;
1437-
if print_ty {
1438-
self.write_str(": ")?;
1439-
let was_in_value = std::mem::replace(&mut self.in_value, false);
1440-
self = t(self)?;
1441-
self.in_value = was_in_value;
1442-
}
1438+
self.write_str(": ")?;
1439+
let was_in_value = std::mem::replace(&mut self.in_value, false);
1440+
self = t(self)?;
1441+
self.in_value = was_in_value;
14431442
self.write_str("}")?;
14441443
Ok(self)
14451444
}
@@ -1507,19 +1506,20 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
15071506
ty: Ty<'tcx>,
15081507
print_ty: bool,
15091508
) -> Result<Self::Const, Self::Error> {
1510-
self.type_ascribed_value(
1511-
|mut this| {
1512-
define_scoped_cx!(this);
1513-
if this.print_alloc_ids {
1514-
p!(write("{:?}", p));
1515-
} else {
1516-
p!(write("pointer"));
1517-
}
1518-
Ok(this)
1519-
},
1520-
|this| this.print_type(ty),
1521-
print_ty,
1522-
)
1509+
let print = |mut this: Self| {
1510+
define_scoped_cx!(this);
1511+
if this.print_alloc_ids {
1512+
p!(write("{:?}", p));
1513+
} else {
1514+
p!(write("&_"));
1515+
}
1516+
Ok(this)
1517+
};
1518+
if print_ty {
1519+
self.type_ascribed_value(print, |this| this.print_type(ty))
1520+
} else {
1521+
print(self)
1522+
}
15231523
}
15241524
}
15251525

0 commit comments

Comments
 (0)