From 6fc6a6d7831e6b7b23e9e7b7c15c6461ecbac16c Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:50:46 +0200 Subject: [PATCH] Remove `Print::Error` All printing goes through `fmt::Error` now. --- .../rustc_const_eval/src/util/type_name.rs | 2 +- .../nice_region_error/placeholder_error.rs | 4 +-- compiler/rustc_middle/src/ty/print/mod.rs | 7 ----- compiler/rustc_middle/src/ty/print/pretty.rs | 26 ++++++++----------- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- .../error_reporting/type_err_ctxt_ext.rs | 8 ++---- 6 files changed, 17 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 06944a93d3b..54eb14ae8fc 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -138,7 +138,7 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> { } fn comma_sep(mut self, mut elems: impl Iterator) -> Result where - T: Print<'tcx, Self, Error = PrintError>, + T: Print<'tcx, Self>, { if let Some(first) = elems.next() { self = first.print(self)?; diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 17a265fd4f4..d6a3bc32cc9 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -28,7 +28,7 @@ pub struct Highlighted<'tcx, T> { impl<'tcx, T> IntoDiagnosticArg for Highlighted<'tcx, T> where - T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error>, + T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>, { fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> { rustc_errors::DiagnosticArgValue::Str(self.to_string().into()) @@ -43,7 +43,7 @@ impl<'tcx, T> Highlighted<'tcx, T> { impl<'tcx, T> fmt::Display for Highlighted<'tcx, T> where - T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>, Error = fmt::Error>, + T: for<'a> Print<'tcx, FmtPrinter<'a, 'tcx>>, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut printer = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS); diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index a1384c1616f..107b44285ac 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -15,8 +15,6 @@ pub type PrintError = std::fmt::Error; // FIXME(eddyb) false positive, the lifetime parameters are used with `P: Printer<...>`. #[allow(unused_lifetimes)] pub trait Print<'tcx, P> { - type Error; - fn print(&self, cx: P) -> Result; } @@ -288,29 +286,24 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option { } impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Region<'tcx> { - type Error = PrintError; fn print(&self, cx: P) -> Result { cx.print_region(*self) } } impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> { - type Error = PrintError; - fn print(&self, cx: P) -> Result { cx.print_type(*self) } } impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List> { - type Error = PrintError; fn print(&self, cx: P) -> Result { cx.print_dyn_existential(self) } } impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Const<'tcx> { - type Error = PrintError; fn print(&self, cx: P) -> Result { cx.print_const(*self) } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index f1b17ddd230..d8010c71497 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -217,7 +217,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { fn in_binder(self, value: &ty::Binder<'tcx, T>) -> Result where - T: Print<'tcx, Self, Error = PrintError> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { value.as_ref().skip_binder().print(self) } @@ -228,7 +228,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { f: F, ) -> Result where - T: Print<'tcx, Self, Error = PrintError> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { f(value.as_ref().skip_binder(), self) } @@ -236,7 +236,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { /// Prints comma-separated elements. fn comma_sep(mut self, mut elems: impl Iterator) -> Result where - T: Print<'tcx, Self, Error = PrintError>, + T: Print<'tcx, Self>, { if let Some(first) = elems.next() { self = first.print(self)?; @@ -2083,7 +2083,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> { fn in_binder(self, value: &ty::Binder<'tcx, T>) -> Result where - T: Print<'tcx, Self, Error = PrintError> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { self.pretty_in_binder(value) } @@ -2094,7 +2094,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> { f: C, ) -> Result where - T: Print<'tcx, Self, Error = PrintError> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { self.pretty_wrap_binder(value, f) } @@ -2343,7 +2343,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { value: &ty::Binder<'tcx, T>, ) -> Result<(Self, T, BTreeMap>), fmt::Error> where - T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { fn name_by_region_index( index: usize, @@ -2513,7 +2513,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { pub fn pretty_in_binder(self, value: &ty::Binder<'tcx, T>) -> Result where - T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { let old_region_index = self.region_index; let (new, new_value, _) = self.name_all_regions(value)?; @@ -2529,7 +2529,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { f: C, ) -> Result where - T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable>, + T: Print<'tcx, Self> + TypeFoldable>, { let old_region_index = self.region_index; let (new, new_value, _) = self.name_all_regions(value)?; @@ -2594,10 +2594,8 @@ impl<'tcx> FmtPrinter<'_, 'tcx> { impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::Binder<'tcx, T> where - T: Print<'tcx, P, Error = PrintError> + TypeFoldable>, + T: Print<'tcx, P> + TypeFoldable>, { - type Error = PrintError; - fn print(&self, cx: P) -> Result { cx.in_binder(self) } @@ -2605,10 +2603,9 @@ where impl<'tcx, T, U, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate where - T: Print<'tcx, P, Error = PrintError>, - U: Print<'tcx, P, Error = PrintError>, + T: Print<'tcx, P>, + U: Print<'tcx, P>, { - type Error = PrintError; fn print(&self, mut cx: P) -> Result { define_scoped_cx!(cx); p!(print(self.0), ": ", print(self.1)); @@ -2636,7 +2633,6 @@ macro_rules! forward_display_to_print { macro_rules! define_print_and_forward_display { (($self:ident, $cx:ident): $($ty:ty $print:block)+) => { $(impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for $ty { - type Error = fmt::Error; fn print(&$self, $cx: P) -> Result { #[allow(unused_mut)] let mut $cx = $cx; diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 5e7dba63ff7..5290da9a25b 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -365,7 +365,7 @@ impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> { } fn comma_sep(mut self, mut elems: impl Iterator) -> Result where - T: Print<'tcx, Self, Error = PrintError>, + T: Print<'tcx, Self>, { if let Some(first) = elems.next() { self = first.print(self)?; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 1133d4302fe..640bd3fad7c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -60,8 +60,7 @@ pub trait TypeErrCtxtExt<'tcx> { suggest_increasing_limit: bool, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> where - T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, - >>::Error: std::fmt::Debug; + T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>; fn report_overflow_error( &self, @@ -71,8 +70,7 @@ pub trait TypeErrCtxtExt<'tcx> { mutate: impl FnOnce(&mut Diagnostic), ) -> ! where - T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, - >>::Error: std::fmt::Debug; + T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>; fn report_overflow_no_abort(&self, obligation: PredicateObligation<'tcx>) -> ErrorGuaranteed; @@ -224,7 +222,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ) -> ! where T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, - >>::Error: std::fmt::Debug, { let mut err = self.build_overflow_error(predicate, span, suggest_increasing_limit); mutate(&mut err); @@ -242,7 +239,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> where T: fmt::Display + TypeFoldable> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, - >>::Error: std::fmt::Debug, { let predicate = self.resolve_vars_if_possible(predicate.clone()); let mut pred_str = predicate.to_string();