diff options
| author | bors <bors@rust-lang.org> | 2023-10-18 09:57:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-10-18 09:57:07 +0000 |
| commit | e8b8c78d84572e5b2e69dc4cc378ebfefe38562d (patch) | |
| tree | d46cc1e99ea0c2ae4e0bd61a3c45dbd3d02d6102 /compiler/rustc_const_eval | |
| parent | 6d7160ce97f4bbbd44991a7325077e08214e0ce2 (diff) | |
| parent | 6fc6a6d7831e6b7b23e9e7b7c15c6461ecbac16c (diff) | |
| download | rust-e8b8c78d84572e5b2e69dc4cc378ebfefe38562d.tar.gz rust-e8b8c78d84572e5b2e69dc4cc378ebfefe38562d.zip | |
Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errors
Remove lots of generics from `ty::print` All of these generics mostly resolve to the same thing, which means we can remove them, greatly simplifying the types involved in pretty printing and unlocking another simplification (that is not performed in this PR): Using `&mut self` instead of passing `self` through the return type. cc `@eddyb` you probably know why it's like this, just checking in and making sure I didn't do anything bad r? oli-obk
Diffstat (limited to 'compiler/rustc_const_eval')
| -rw-r--r-- | compiler/rustc_const_eval/src/util/type_name.rs | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index a924afda6f0..54eb14ae8fc 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::CrateNum; use rustc_hir::definitions::DisambiguatedDefPathData; use rustc_middle::ty::{ self, - print::{PrettyPrinter, Print, Printer}, + print::{PrettyPrinter, Print, PrintError, Printer}, GenericArg, GenericArgKind, Ty, TyCtxt, }; use std::fmt::Write; @@ -14,23 +14,15 @@ struct AbsolutePathPrinter<'tcx> { } impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { - type Error = std::fmt::Error; - - type Path = Self; - type Region = Self; - type Type = Self; - type DynExistential = Self; - type Const = Self; - fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } - fn print_region(self, _region: ty::Region<'_>) -> Result<Self::Region, Self::Error> { + fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> { Ok(self) } - fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> { + fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, PrintError> { match *ty.kind() { // Types without identity. ty::Bool @@ -68,18 +60,18 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { } } - fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> { + fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, PrintError> { self.pretty_print_const(ct, false) } fn print_dyn_existential( self, predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>, - ) -> Result<Self::DynExistential, Self::Error> { + ) -> Result<Self, PrintError> { self.pretty_print_dyn_existential(predicates) } - fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> { + fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> { self.path.push_str(self.tcx.crate_name(cnum).as_str()); Ok(self) } @@ -88,17 +80,17 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { self, self_ty: Ty<'tcx>, trait_ref: Option<ty::TraitRef<'tcx>>, - ) -> Result<Self::Path, Self::Error> { + ) -> Result<Self, PrintError> { self.pretty_path_qualified(self_ty, trait_ref) } fn path_append_impl( self, - print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>, + print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>, _disambiguated_data: &DisambiguatedDefPathData, self_ty: Ty<'tcx>, trait_ref: Option<ty::TraitRef<'tcx>>, - ) -> Result<Self::Path, Self::Error> { + ) -> Result<Self, PrintError> { self.pretty_path_append_impl( |mut cx| { cx = print_prefix(cx)?; @@ -114,9 +106,9 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn path_append( mut self, - print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>, + print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>, disambiguated_data: &DisambiguatedDefPathData, - ) -> Result<Self::Path, Self::Error> { + ) -> Result<Self, PrintError> { self = print_prefix(self)?; write!(self.path, "::{}", disambiguated_data.data).unwrap(); @@ -126,9 +118,9 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn path_generic_args( mut self, - print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>, + print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>, args: &[GenericArg<'tcx>], - ) -> Result<Self::Path, Self::Error> { + ) -> Result<Self, PrintError> { self = print_prefix(self)?; let args = args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_))); @@ -144,9 +136,9 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> { fn should_print_region(&self, _region: ty::Region<'_>) -> bool { false } - fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, Self::Error> + fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, PrintError> where - T: Print<'tcx, Self, Output = Self, Error = Self::Error>, + T: Print<'tcx, Self>, { if let Some(first) = elems.next() { self = first.print(self)?; @@ -160,8 +152,8 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> { fn generic_delimiters( mut self, - f: impl FnOnce(Self) -> Result<Self, Self::Error>, - ) -> Result<Self, Self::Error> { + f: impl FnOnce(Self) -> Result<Self, PrintError>, + ) -> Result<Self, PrintError> { write!(self, "<")?; self = f(self)?; |
