Remove Print::Error
All printing goes through `fmt::Error` now.
This commit is contained in:
parent
6038888118
commit
6fc6a6d783
6 changed files with 17 additions and 32 deletions
|
@ -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<P, PrintError>;
|
||||
}
|
||||
|
||||
|
@ -288,29 +286,24 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
|
|||
}
|
||||
|
||||
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for ty::Region<'tcx> {
|
||||
type Error = PrintError;
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
cx.print_region(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> {
|
||||
type Error = PrintError;
|
||||
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
cx.print_type(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
|
||||
type Error = PrintError;
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
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<P, PrintError> {
|
||||
cx.print_const(*self)
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
|||
|
||||
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
value.as_ref().skip_binder().print(self)
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
|||
f: F,
|
||||
) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
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<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, PrintError>
|
||||
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<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.pretty_in_binder(value)
|
||||
}
|
||||
|
@ -2094,7 +2094,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||
f: C,
|
||||
) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.pretty_wrap_binder(value, f)
|
||||
}
|
||||
|
@ -2343,7 +2343,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
value: &ty::Binder<'tcx, T>,
|
||||
) -> Result<(Self, T, BTreeMap<ty::BoundRegion, ty::Region<'tcx>>), fmt::Error>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
fn name_by_region_index(
|
||||
index: usize,
|
||||
|
@ -2513,7 +2513,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
|||
|
||||
pub fn pretty_in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, fmt::Error>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
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<Self, fmt::Error>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = fmt::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
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<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, P> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
type Error = PrintError;
|
||||
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
cx.in_binder(self)
|
||||
}
|
||||
|
@ -2605,10 +2603,9 @@ where
|
|||
|
||||
impl<'tcx, T, U, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate<T, U>
|
||||
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<P, PrintError> {
|
||||
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<P, PrintError> {
|
||||
#[allow(unused_mut)]
|
||||
let mut $cx = $cx;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue