mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Remove Print::Error
All printing goes through `fmt::Error` now.
This commit is contained in:
parent
6038888118
commit
6fc6a6d783
@ -138,7 +138,7 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
}
|
||||
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)?;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -365,7 +365,7 @@ impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
}
|
||||
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)?;
|
||||
|
@ -60,8 +60,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
||||
suggest_increasing_limit: bool,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed>
|
||||
where
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>;
|
||||
|
||||
fn report_overflow_error<T>(
|
||||
&self,
|
||||
@ -71,8 +70,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
||||
mutate: impl FnOnce(&mut Diagnostic),
|
||||
) -> !
|
||||
where
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug;
|
||||
T: fmt::Display + TypeFoldable<TyCtxt<'tcx>> + 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<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
<T as 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<TyCtxt<'tcx>> + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
<T as 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();
|
||||
|
Loading…
Reference in New Issue
Block a user