diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-10-16 20:46:24 +0200 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-10-17 18:02:55 +0200 |
| commit | 6038888118d88ed4175ccb49e9e429865432f253 (patch) | |
| tree | d83edc4b02e6a92e7885134ce1ccc71f49800404 /compiler/rustc_const_eval/src/util | |
| parent | 0b5a4c1adfc4cede0fa06243ef9e7447e286affb (diff) | |
| download | rust-6038888118d88ed4175ccb49e9e429865432f253.tar.gz rust-6038888118d88ed4175ccb49e9e429865432f253.zip | |
Remove `Printer::Error`
It's always a `fmt::Error` except in some cases where it was `!`, but we're not really winning anything in that case.
Diffstat (limited to 'compiler/rustc_const_eval/src/util')
| -rw-r--r-- | compiler/rustc_const_eval/src/util/type_name.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index fba8121ead0..06944a93d3b 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,17 +14,15 @@ struct AbsolutePathPrinter<'tcx> { } impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { - type Error = std::fmt::Error; - fn tcx(&self) -> TyCtxt<'tcx> { self.tcx } - fn print_region(self, _region: ty::Region<'_>) -> Result<Self, Self::Error> { + fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> { Ok(self) } - fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, Self::Error> { + fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, PrintError> { match *ty.kind() { // Types without identity. ty::Bool @@ -62,18 +60,18 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { } } - fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, 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, Self::Error> { + ) -> Result<Self, PrintError> { self.pretty_print_dyn_existential(predicates) } - fn path_crate(mut self, cnum: CrateNum) -> Result<Self, 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) } @@ -82,17 +80,17 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { self, self_ty: Ty<'tcx>, trait_ref: Option<ty::TraitRef<'tcx>>, - ) -> Result<Self, 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, 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, Self::Error> { + ) -> Result<Self, PrintError> { self.pretty_path_append_impl( |mut cx| { cx = print_prefix(cx)?; @@ -108,9 +106,9 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn path_append( mut self, - print_prefix: impl FnOnce(Self) -> Result<Self, Self::Error>, + print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>, disambiguated_data: &DisambiguatedDefPathData, - ) -> Result<Self, Self::Error> { + ) -> Result<Self, PrintError> { self = print_prefix(self)?; write!(self.path, "::{}", disambiguated_data.data).unwrap(); @@ -120,9 +118,9 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { fn path_generic_args( mut self, - print_prefix: impl FnOnce(Self) -> Result<Self, Self::Error>, + print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>, args: &[GenericArg<'tcx>], - ) -> Result<Self, Self::Error> { + ) -> Result<Self, PrintError> { self = print_prefix(self)?; let args = args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_))); @@ -138,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, Error = Self::Error>, + T: Print<'tcx, Self, Error = PrintError>, { if let Some(first) = elems.next() { self = first.print(self)?; @@ -154,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)?; |
