diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-02-26 19:36:10 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-03-11 09:10:50 +0100 |
| commit | 2e91065a6f4f3d27eab5fe66dc34c33c016c244d (patch) | |
| tree | df419a8f6a3689fdbd4a027ebabcf04489fb6d1a /src/librustc/ty/print | |
| parent | cc9ca640c2a402f620a6b664a25b4417e8d3615a (diff) | |
| download | rust-2e91065a6f4f3d27eab5fe66dc34c33c016c244d.tar.gz rust-2e91065a6f4f3d27eab5fe66dc34c33c016c244d.zip | |
Generalize typed value printing and use for undef printing
Diffstat (limited to 'src/librustc/ty/print')
| -rw-r--r-- | src/librustc/ty/print/pretty.rs | 26 |
1 files changed, 9 insertions, 17 deletions
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<Self, Self::Error>, t: impl FnOnce(Self) -> Result<Self, Self::Error>, - cast: bool, + conversion: &str, ) -> Result<Self::Const, Self::Error> { 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<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> { mut self, f: impl FnOnce(Self) -> Result<Self, Self::Error>, t: impl FnOnce(Self) -> Result<Self, Self::Error>, - cast: bool, + conversion: &str, ) -> Result<Self::Const, Self::Error> { 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<F: fmt::Write> 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) } |
