diff options
| author | varkor <github@varkor.com> | 2020-01-24 16:22:24 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2020-01-24 16:23:32 +0000 |
| commit | 50dd8eaeb9ebbccb8b79ff30d3068d0ee337cd2f (patch) | |
| tree | b0f9a40f3f36b1e0056386f68f3342720e6b6f36 /src/librustc | |
| parent | dee12bb2b7d75cce8fc8f21b5d7ea0da920df5e5 (diff) | |
Print constants in `type_name` for const generics
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/ty/print/pretty.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 9091de55b7d..7dd3c8f4a72 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -831,7 +831,11 @@ pub trait PrettyPrinter<'tcx>: Ok(self) } - fn pretty_print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> { + fn pretty_print_const( + mut self, + ct: &'tcx ty::Const<'tcx>, + print_ty: bool, + ) -> Result<Self::Const, Self::Error> { define_scoped_cx!(self); if self.tcx().sess.verbose() { @@ -839,6 +843,15 @@ pub trait PrettyPrinter<'tcx>: return Ok(self); } + macro_rules! print_underscore { + () => {{ + p!(write("_")); + if print_ty { + p!(write(": "), print(ct.ty)); + } + }}; + } + match (ct.val, &ct.ty.kind) { (_, ty::FnDef(did, substs)) => p!(print_value_path(*did, substs)), (ty::ConstKind::Unevaluated(did, substs, promoted), _) => { @@ -857,22 +870,27 @@ pub trait PrettyPrinter<'tcx>: { p!(write("{}", snip)) } else { - p!(write("_: "), print(ct.ty)) + print_underscore!() } } else { - p!(write("_: "), print(ct.ty)) + print_underscore!() } } } } } - (ty::ConstKind::Infer(..), _) => p!(write("_: "), print(ct.ty)), + (ty::ConstKind::Infer(..), _) => print_underscore!(), (ty::ConstKind::Param(ParamConst { name, .. }), _) => p!(write("{}", name)), - (ty::ConstKind::Value(value), _) => return self.pretty_print_const_value(value, ct.ty), + (ty::ConstKind::Value(value), _) => { + return self.pretty_print_const_value(value, ct.ty, print_ty); + } _ => { // fallback - p!(write("{:?} : ", ct.val), print(ct.ty)) + p!(write("{:?}", ct.val)); + if print_ty { + p!(write(" : "), print(ct.ty)); + } } }; Ok(self) @@ -882,6 +900,7 @@ pub trait PrettyPrinter<'tcx>: mut self, ct: ConstValue<'tcx>, ty: Ty<'tcx>, + print_ty: bool, ) -> Result<Self::Const, Self::Error> { define_scoped_cx!(self); @@ -988,7 +1007,10 @@ pub trait PrettyPrinter<'tcx>: }; if !printed { // fallback - p!(write("{:?} : ", ct), print(ty)) + p!(write("{:?}", ct)); + if print_ty { + p!(write(" : "), print(ty)); + } } } }; @@ -1162,7 +1184,7 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> { } fn print_const(self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> { - self.pretty_print_const(ct) + self.pretty_print_const(ct, true) } fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> { |
