mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-28 23:53:55 +00:00
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.
This commit is contained in:
parent
0b5a4c1adf
commit
6038888118
@ -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)?;
|
||||
|
@ -67,7 +67,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_middle::dep_graph::DepContext;
|
||||
use rustc_middle::ty::print::with_forced_trimmed_paths;
|
||||
use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError};
|
||||
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::{
|
||||
self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable,
|
||||
@ -583,35 +583,31 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
segments: Vec<String>,
|
||||
}
|
||||
|
||||
struct NonTrivialPath;
|
||||
|
||||
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
type Error = NonTrivialPath;
|
||||
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn print_region(self, _region: ty::Region<'_>) -> Result<Self, Self::Error> {
|
||||
Err(NonTrivialPath)
|
||||
fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self, Self::Error> {
|
||||
Err(NonTrivialPath)
|
||||
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn print_dyn_existential(
|
||||
self,
|
||||
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Err(NonTrivialPath)
|
||||
) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, Self::Error> {
|
||||
Err(NonTrivialPath)
|
||||
fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, Self::Error> {
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
self.segments = vec![self.tcx.crate_name(cnum).to_string()];
|
||||
Ok(self)
|
||||
}
|
||||
@ -619,33 +615,33 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
self,
|
||||
_self_ty: Ty<'tcx>,
|
||||
_trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Err(NonTrivialPath)
|
||||
) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
|
||||
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> {
|
||||
Err(NonTrivialPath)
|
||||
) -> Result<Self, PrintError> {
|
||||
Err(fmt::Error)
|
||||
}
|
||||
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)?;
|
||||
self.segments.push(disambiguated_data.to_string());
|
||||
Ok(self)
|
||||
}
|
||||
fn path_generic_args(
|
||||
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> {
|
||||
print_prefix(self)
|
||||
}
|
||||
}
|
||||
@ -663,7 +659,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
|
||||
// We compare strings because DefPath can be different
|
||||
// for imported and non-imported crates
|
||||
let same_path = || -> Result<_, NonTrivialPath> {
|
||||
let same_path = || -> Result<_, PrintError> {
|
||||
Ok(self.tcx.def_path_str(did1) == self.tcx.def_path_str(did2)
|
||||
|| abs_path(did1)? == abs_path(did2)?)
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::middle::privacy::EffectiveVisibilities;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::print::{with_no_trimmed_paths, PrintError};
|
||||
use rustc_middle::ty::{self, print::Printer, GenericArg, RegisteredTools, Ty, TyCtxt};
|
||||
use rustc_session::config::ExpectedValues;
|
||||
use rustc_session::lint::{BuiltinLintDiagnostics, LintExpectationId};
|
||||
@ -1206,32 +1206,30 @@ impl<'tcx> LateContext<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
type 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(self, _ty: Ty<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_dyn_existential(
|
||||
self,
|
||||
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, Self::Error> {
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
self.path = vec![self.tcx.crate_name(cnum)];
|
||||
Ok(self)
|
||||
}
|
||||
@ -1240,7 +1238,7 @@ impl<'tcx> LateContext<'tcx> {
|
||||
mut self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
if trait_ref.is_none() {
|
||||
if let ty::Adt(def, args) = self_ty.kind() {
|
||||
return self.print_def_path(def.did(), args);
|
||||
@ -1259,11 +1257,11 @@ impl<'tcx> LateContext<'tcx> {
|
||||
|
||||
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> {
|
||||
let mut path = print_prefix(self)?;
|
||||
|
||||
// This shouldn't ever be needed, but just in case:
|
||||
@ -1285,9 +1283,9 @@ impl<'tcx> LateContext<'tcx> {
|
||||
|
||||
fn path_append(
|
||||
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> {
|
||||
let mut path = print_prefix(self)?;
|
||||
|
||||
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
|
||||
@ -1301,9 +1299,9 @@ impl<'tcx> LateContext<'tcx> {
|
||||
|
||||
fn path_generic_args(
|
||||
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> {
|
||||
print_prefix(self)
|
||||
}
|
||||
}
|
||||
|
@ -10,12 +10,14 @@ use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
mod pretty;
|
||||
pub use self::pretty::*;
|
||||
|
||||
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, Self::Error>;
|
||||
fn print(&self, cx: P) -> Result<P, PrintError>;
|
||||
}
|
||||
|
||||
/// Interface for outputting user-facing "type-system entities"
|
||||
@ -28,15 +30,13 @@ pub trait Print<'tcx, P> {
|
||||
//
|
||||
// FIXME(eddyb) find a better name; this is more general than "printing".
|
||||
pub trait Printer<'tcx>: Sized {
|
||||
type Error;
|
||||
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
|
||||
|
||||
fn print_def_path(
|
||||
self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.default_print_def_path(def_id, args)
|
||||
}
|
||||
|
||||
@ -46,48 +46,48 @@ pub trait Printer<'tcx>: Sized {
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.default_print_impl_path(impl_def_id, args, self_ty, trait_ref)
|
||||
}
|
||||
|
||||
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self, Self::Error>;
|
||||
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self, PrintError>;
|
||||
|
||||
fn print_type(self, ty: Ty<'tcx>) -> Result<Self, Self::Error>;
|
||||
fn print_type(self, ty: Ty<'tcx>) -> Result<Self, PrintError>;
|
||||
|
||||
fn print_dyn_existential(
|
||||
self,
|
||||
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error>;
|
||||
) -> Result<Self, PrintError>;
|
||||
|
||||
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, Self::Error>;
|
||||
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, PrintError>;
|
||||
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, Self::Error>;
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, PrintError>;
|
||||
|
||||
fn path_qualified(
|
||||
self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error>;
|
||||
) -> Result<Self, PrintError>;
|
||||
|
||||
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>;
|
||||
|
||||
fn path_append(
|
||||
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>;
|
||||
|
||||
fn path_generic_args(
|
||||
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>;
|
||||
|
||||
// Defaults (should not be overridden):
|
||||
|
||||
@ -96,7 +96,7 @@ pub trait Printer<'tcx>: Sized {
|
||||
self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let key = self.tcx().def_key(def_id);
|
||||
debug!(?key);
|
||||
|
||||
@ -187,7 +187,7 @@ pub trait Printer<'tcx>: Sized {
|
||||
_args: &'tcx [GenericArg<'tcx>],
|
||||
self_ty: Ty<'tcx>,
|
||||
impl_trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
debug!(
|
||||
"default_print_impl_path: impl_def_id={:?}, self_ty={}, impl_trait_ref={:?}",
|
||||
impl_def_id, self_ty, impl_trait_ref
|
||||
@ -288,30 +288,30 @@ 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 = P::Error;
|
||||
fn print(&self, cx: P) -> Result<P, Self::Error> {
|
||||
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 = P::Error;
|
||||
type Error = PrintError;
|
||||
|
||||
fn print(&self, cx: P) -> Result<P, Self::Error> {
|
||||
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 = P::Error;
|
||||
fn print(&self, cx: P) -> Result<P, Self::Error> {
|
||||
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 = P::Error;
|
||||
fn print(&self, cx: P) -> Result<P, Self::Error> {
|
||||
type Error = PrintError;
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
cx.print_const(*self)
|
||||
}
|
||||
}
|
||||
|
@ -205,19 +205,19 @@ impl<'tcx> RegionHighlightMode<'tcx> {
|
||||
}
|
||||
|
||||
/// Trait for printers that pretty-print using `fmt::Write` to the printer.
|
||||
pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
|
||||
/// Like `print_def_path` but for value paths.
|
||||
fn print_value_path(
|
||||
self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.print_def_path(def_id, args)
|
||||
}
|
||||
|
||||
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, Self::Error>
|
||||
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
value.as_ref().skip_binder().print(self)
|
||||
}
|
||||
@ -226,17 +226,17 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
self,
|
||||
value: &ty::Binder<'tcx, T>,
|
||||
f: F,
|
||||
) -> Result<Self, Self::Error>
|
||||
) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
f(value.as_ref().skip_binder(), self)
|
||||
}
|
||||
|
||||
/// Prints comma-separated elements.
|
||||
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)?;
|
||||
@ -251,10 +251,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
/// Prints `{f: t}` or `{f as t}` depending on the `cast` argument
|
||||
fn typed_value(
|
||||
mut self,
|
||||
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
f: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
t: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
conversion: &str,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.write_str("{")?;
|
||||
self = f(self)?;
|
||||
self.write_str(conversion)?;
|
||||
@ -266,8 +266,8 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
/// Prints `<...>` around what `f` prints.
|
||||
fn generic_delimiters(
|
||||
self,
|
||||
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
) -> Result<Self, Self::Error>;
|
||||
f: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
) -> Result<Self, PrintError>;
|
||||
|
||||
/// Returns `true` if the region should be printed in
|
||||
/// optional positions, e.g., `&'a T` or `dyn Tr + 'b`.
|
||||
@ -281,7 +281,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
/// If possible, this returns a global path resolving to `def_id` that is visible
|
||||
/// from at least one local module, and returns `true`. If the crate defining `def_id` is
|
||||
/// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
|
||||
fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
|
||||
fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), PrintError> {
|
||||
if NO_VISIBLE_PATH.with(|flag| flag.get()) {
|
||||
return Ok((self, false));
|
||||
}
|
||||
@ -295,7 +295,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
// For enum variants, if they have an unique name, then we only print the name, otherwise we
|
||||
// print the enum name and the variant name. Otherwise, we do not print anything and let the
|
||||
// caller use the `print_def_path` fallback.
|
||||
fn force_print_trimmed_def_path(mut self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
|
||||
fn force_print_trimmed_def_path(mut self, def_id: DefId) -> Result<(Self, bool), PrintError> {
|
||||
let key = self.tcx().def_key(def_id);
|
||||
let visible_parent_map = self.tcx().visible_parent_map(());
|
||||
let kind = self.tcx().def_kind(def_id);
|
||||
@ -365,7 +365,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
}
|
||||
|
||||
/// Try to see if this path can be trimmed to a unique symbol name.
|
||||
fn try_print_trimmed_def_path(mut self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
|
||||
fn try_print_trimmed_def_path(mut self, def_id: DefId) -> Result<(Self, bool), PrintError> {
|
||||
if FORCE_TRIMMED_PATH.with(|flag| flag.get()) {
|
||||
let (s, trimmed) = self.force_print_trimmed_def_path(def_id)?;
|
||||
if trimmed {
|
||||
@ -407,7 +407,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
mut self,
|
||||
def_id: DefId,
|
||||
callers: &mut Vec<DefId>,
|
||||
) -> Result<(Self, bool), Self::Error> {
|
||||
) -> Result<(Self, bool), PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
debug!("try_print_visible_def_path: def_id={:?}", def_id);
|
||||
@ -579,7 +579,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
if trait_ref.is_none() {
|
||||
// Inherent impls. Try to print `Foo::bar` for an inherent
|
||||
// impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
|
||||
@ -613,10 +613,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
|
||||
fn pretty_path_append_impl(
|
||||
mut self,
|
||||
print_prefix: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self = print_prefix(self)?;
|
||||
|
||||
self.generic_delimiters(|mut cx| {
|
||||
@ -632,7 +632,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
})
|
||||
}
|
||||
|
||||
fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn pretty_print_type(mut self, ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
match *ty.kind() {
|
||||
@ -903,7 +903,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
mut self,
|
||||
def_id: DefId,
|
||||
args: &'tcx ty::List<ty::GenericArg<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let tcx = self.tcx();
|
||||
|
||||
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
||||
@ -1173,7 +1173,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
fn pretty_print_inherent_projection(
|
||||
self,
|
||||
alias_ty: &ty::AliasTy<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let def_key = self.tcx().def_key(alias_ty.def_id);
|
||||
self.path_generic_args(
|
||||
|cx| {
|
||||
@ -1197,7 +1197,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
fn pretty_print_dyn_existential(
|
||||
mut self,
|
||||
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
// Generate the main trait ref, including associated types.
|
||||
let mut first = true;
|
||||
|
||||
@ -1290,7 +1290,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
inputs: &[Ty<'tcx>],
|
||||
c_variadic: bool,
|
||||
output: Ty<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
p!("(", comma_sep(inputs.iter().copied()));
|
||||
@ -1312,7 +1312,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
mut self,
|
||||
ct: ty::Const<'tcx>,
|
||||
print_ty: bool,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
if self.should_print_verbose() {
|
||||
@ -1388,7 +1388,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn pretty_print_const_scalar(self, scalar: Scalar, ty: Ty<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn pretty_print_const_scalar(self, scalar: Scalar, ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
match scalar {
|
||||
Scalar::Ptr(ptr, _size) => self.pretty_print_const_scalar_ptr(ptr, ty),
|
||||
Scalar::Int(int) => {
|
||||
@ -1401,7 +1401,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
mut self,
|
||||
ptr: Pointer,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
let (alloc_id, offset) = ptr.into_parts();
|
||||
@ -1463,7 +1463,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
int: ScalarInt,
|
||||
ty: Ty<'tcx>,
|
||||
print_ty: bool,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
match ty.kind() {
|
||||
@ -1525,7 +1525,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
self,
|
||||
_: Pointer<Prov>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.typed_value(
|
||||
|mut this| {
|
||||
this.write_str("&_")?;
|
||||
@ -1536,7 +1536,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
)
|
||||
}
|
||||
|
||||
fn pretty_print_byte_str(mut self, byte_str: &'tcx [u8]) -> Result<Self, Self::Error> {
|
||||
fn pretty_print_byte_str(mut self, byte_str: &'tcx [u8]) -> Result<Self, PrintError> {
|
||||
write!(self, "b\"{}\"", byte_str.escape_ascii())?;
|
||||
Ok(self)
|
||||
}
|
||||
@ -1546,7 +1546,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
valtree: ty::ValTree<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
print_ty: bool,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
if self.should_print_verbose() {
|
||||
@ -1669,7 +1669,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx, Error = fmt::Error> + fmt::Write {
|
||||
fn pretty_closure_as_impl(
|
||||
mut self,
|
||||
closure: ty::ClosureArgs<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let sig = closure.sig();
|
||||
let kind = closure.kind_ty().to_opt_closure_kind().unwrap_or(ty::ClosureKind::Fn);
|
||||
|
||||
@ -1842,8 +1842,6 @@ impl fmt::Write for FmtPrinter<'_, '_> {
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
type Error = fmt::Error;
|
||||
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
@ -1852,7 +1850,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
mut self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
define_scoped_cx!(self);
|
||||
|
||||
if args.is_empty() {
|
||||
@ -1907,11 +1905,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
self.default_print_def_path(def_id, args)
|
||||
}
|
||||
|
||||
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_region(self, region: ty::Region<'tcx>) -> Result<Self, PrintError> {
|
||||
self.pretty_print_region(region)
|
||||
}
|
||||
|
||||
fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, PrintError> {
|
||||
if self.type_length_limit.value_within_limit(self.printed_type_count) {
|
||||
self.printed_type_count += 1;
|
||||
self.pretty_print_type(ty)
|
||||
@ -1925,15 +1923,15 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
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 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 path_crate(mut self, cnum: CrateNum) -> Result<Self, Self::Error> {
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
self.empty_path = true;
|
||||
if cnum == LOCAL_CRATE {
|
||||
if self.tcx.sess.at_least_rust_2018() {
|
||||
@ -1954,7 +1952,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
mut self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self = self.pretty_path_qualified(self_ty, trait_ref)?;
|
||||
self.empty_path = false;
|
||||
Ok(self)
|
||||
@ -1962,11 +1960,11 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
|
||||
fn path_append_impl(
|
||||
mut 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 = self.pretty_path_append_impl(
|
||||
|mut cx| {
|
||||
cx = print_prefix(cx)?;
|
||||
@ -1985,9 +1983,9 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, '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)?;
|
||||
|
||||
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
|
||||
@ -2016,9 +2014,9 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, '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 tcx = self.tcx;
|
||||
@ -2075,7 +2073,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
mut self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let was_in_value = std::mem::replace(&mut self.in_value, true);
|
||||
self = self.print_def_path(def_id, args)?;
|
||||
self.in_value = was_in_value;
|
||||
@ -2083,30 +2081,30 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, Self::Error>
|
||||
fn in_binder<T>(self, value: &ty::Binder<'tcx, T>) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.pretty_in_binder(value)
|
||||
}
|
||||
|
||||
fn wrap_binder<T, C: FnOnce(&T, Self) -> Result<Self, Self::Error>>(
|
||||
fn wrap_binder<T, C: FnOnce(&T, Self) -> Result<Self, PrintError>>(
|
||||
self,
|
||||
value: &ty::Binder<'tcx, T>,
|
||||
f: C,
|
||||
) -> Result<Self, Self::Error>
|
||||
) -> Result<Self, PrintError>
|
||||
where
|
||||
T: Print<'tcx, Self, Error = Self::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, Self, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
self.pretty_wrap_binder(value, f)
|
||||
}
|
||||
|
||||
fn typed_value(
|
||||
mut self,
|
||||
f: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
t: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
f: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
t: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
conversion: &str,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
self.write_str("{")?;
|
||||
self = f(self)?;
|
||||
self.write_str(conversion)?;
|
||||
@ -2119,8 +2117,8 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, '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, "<")?;
|
||||
|
||||
let was_in_value = std::mem::replace(&mut self.in_value, false);
|
||||
@ -2180,7 +2178,7 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
self,
|
||||
p: Pointer<Prov>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let print = |mut this: Self| {
|
||||
define_scoped_cx!(this);
|
||||
if this.print_alloc_ids {
|
||||
@ -2596,22 +2594,22 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
|
||||
|
||||
impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::Binder<'tcx, T>
|
||||
where
|
||||
T: Print<'tcx, P, Error = P::Error> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
T: Print<'tcx, P, Error = PrintError> + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
type Error = P::Error;
|
||||
type Error = PrintError;
|
||||
|
||||
fn print(&self, cx: P) -> Result<P, Self::Error> {
|
||||
fn print(&self, cx: P) -> Result<P, PrintError> {
|
||||
cx.in_binder(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx, T, U, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate<T, U>
|
||||
where
|
||||
T: Print<'tcx, P, Error = P::Error>,
|
||||
U: Print<'tcx, P, Error = P::Error>,
|
||||
T: Print<'tcx, P, Error = PrintError>,
|
||||
U: Print<'tcx, P, Error = PrintError>,
|
||||
{
|
||||
type Error = P::Error;
|
||||
fn print(&self, mut cx: P) -> Result<P, Self::Error> {
|
||||
type Error = PrintError;
|
||||
fn print(&self, mut cx: P) -> Result<P, PrintError> {
|
||||
define_scoped_cx!(cx);
|
||||
p!(print(self.0), ": ", print(self.1));
|
||||
Ok(cx)
|
||||
@ -2639,7 +2637,7 @@ 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, Self::Error> {
|
||||
fn print(&$self, $cx: P) -> Result<P, PrintError> {
|
||||
#[allow(unused_mut)]
|
||||
let mut $cx = $cx;
|
||||
define_scoped_cx!($cx);
|
||||
|
@ -1,7 +1,7 @@
|
||||
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
|
||||
use rustc_hir::def_id::CrateNum;
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::ty::print::{PrettyPrinter, Print, Printer};
|
||||
use rustc_middle::ty::print::{PrettyPrinter, Print, PrintError, Printer};
|
||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{GenericArg, GenericArgKind};
|
||||
use rustc_middle::util::common::record_time;
|
||||
@ -200,17 +200,15 @@ struct SymbolPrinter<'tcx> {
|
||||
// symbol names should have their own printing machinery.
|
||||
|
||||
impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
type Error = 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() {
|
||||
// Print all nominal types as paths (unlike `pretty_print_type`).
|
||||
ty::FnDef(def_id, args)
|
||||
@ -244,7 +242,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
fn print_dyn_existential(
|
||||
mut self,
|
||||
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let mut first = true;
|
||||
for p in predicates {
|
||||
if !first {
|
||||
@ -256,7 +254,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
|
||||
// only print integers
|
||||
match (ct.kind(), ct.ty().kind()) {
|
||||
(ty::ConstKind::Value(ty::ValTree::Leaf(scalar)), ty::Int(_) | ty::Uint(_)) => {
|
||||
@ -274,7 +272,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, Self::Error> {
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
self.write_str(self.tcx.crate_name(cnum).as_str())?;
|
||||
Ok(self)
|
||||
}
|
||||
@ -282,7 +280,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
// Similar to `pretty_path_qualified`, but for the other
|
||||
// types that are printed as paths (see `print_type` above).
|
||||
match self_ty.kind() {
|
||||
@ -298,11 +296,11 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> {
|
||||
|
||||
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)?;
|
||||
@ -322,9 +320,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'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)?;
|
||||
|
||||
// Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
|
||||
@ -345,9 +343,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'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 =
|
||||
@ -365,9 +363,9 @@ impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'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)?;
|
||||
@ -381,8 +379,8 @@ impl<'tcx> PrettyPrinter<'tcx> for &mut SymbolPrinter<'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, "<")?;
|
||||
|
||||
let kept_within_component = mem::replace(&mut self.keep_within_component, true);
|
||||
|
@ -6,7 +6,7 @@ use rustc_hir::def::CtorKind;
|
||||
use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
use rustc_middle::ty::print::{Print, Printer};
|
||||
use rustc_middle::ty::print::{Print, PrintError, Printer};
|
||||
use rustc_middle::ty::{
|
||||
self, EarlyBinder, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeVisitable, TypeVisitableExt,
|
||||
UintTy,
|
||||
@ -181,11 +181,11 @@ impl<'tcx> SymbolMangler<'tcx> {
|
||||
|
||||
fn path_append_ns<'a>(
|
||||
mut self: &'a mut Self,
|
||||
print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
|
||||
print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, PrintError>,
|
||||
ns: char,
|
||||
disambiguator: u64,
|
||||
name: &str,
|
||||
) -> Result<&'a mut Self, !> {
|
||||
) -> Result<&'a mut Self, PrintError> {
|
||||
self.push("N");
|
||||
self.out.push(ns);
|
||||
self = print_prefix(self)?;
|
||||
@ -194,7 +194,7 @@ impl<'tcx> SymbolMangler<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
|
||||
fn print_backref(&mut self, i: usize) -> Result<&mut Self, PrintError> {
|
||||
self.push("B");
|
||||
self.push_integer_62((i - self.start_offset) as u64);
|
||||
Ok(self)
|
||||
@ -203,8 +203,8 @@ impl<'tcx> SymbolMangler<'tcx> {
|
||||
fn in_binder<'a, T>(
|
||||
mut self: &'a mut Self,
|
||||
value: &ty::Binder<'tcx, T>,
|
||||
print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
|
||||
) -> Result<&'a mut Self, !>
|
||||
print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, PrintError>,
|
||||
) -> Result<&'a mut Self, PrintError>
|
||||
where
|
||||
T: TypeVisitable<TyCtxt<'tcx>>,
|
||||
{
|
||||
@ -230,8 +230,6 @@ impl<'tcx> SymbolMangler<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
type Error = !;
|
||||
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
@ -240,7 +238,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
mut self,
|
||||
def_id: DefId,
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
if let Some(&i) = self.paths.get(&(def_id, args)) {
|
||||
return self.print_backref(i);
|
||||
}
|
||||
@ -262,7 +260,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
args: &'tcx [GenericArg<'tcx>],
|
||||
mut self_ty: Ty<'tcx>,
|
||||
mut impl_trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
let key = self.tcx.def_key(impl_def_id);
|
||||
let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id };
|
||||
|
||||
@ -315,7 +313,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_region(self, region: ty::Region<'_>) -> Result<Self, Self::Error> {
|
||||
fn print_region(self, region: ty::Region<'_>) -> Result<Self, PrintError> {
|
||||
let i = match *region {
|
||||
// Erased lifetimes use the index 0, for a
|
||||
// shorter mangling of `L_`.
|
||||
@ -337,7 +335,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
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> {
|
||||
// Basic types, never cached (single-character).
|
||||
let basic_type = match ty.kind() {
|
||||
ty::Bool => "b",
|
||||
@ -492,7 +490,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
fn print_dyn_existential(
|
||||
mut self,
|
||||
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
// Okay, so this is a bit tricky. Imagine we have a trait object like
|
||||
// `dyn for<'a> Foo<'a, Bar = &'a ()>`. When we mangle this, the
|
||||
// output looks really close to the syntax, where the `Bar = &'a ()` bit
|
||||
@ -553,7 +551,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self, Self::Error> {
|
||||
fn print_const(mut self, ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
|
||||
// We only mangle a typed value if the const can be evaluated.
|
||||
let ct = ct.normalize(self.tcx, ty::ParamEnv::reveal_all());
|
||||
match ct.kind() {
|
||||
@ -725,7 +723,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, Self::Error> {
|
||||
fn path_crate(self, cnum: CrateNum) -> Result<Self, PrintError> {
|
||||
self.push("C");
|
||||
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
|
||||
self.push_disambiguator(stable_crate_id.as_u64());
|
||||
@ -738,7 +736,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
mut self,
|
||||
self_ty: Ty<'tcx>,
|
||||
trait_ref: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
assert!(trait_ref.is_some());
|
||||
let trait_ref = trait_ref.unwrap();
|
||||
|
||||
@ -749,20 +747,20 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
||||
|
||||
fn path_append_impl(
|
||||
self,
|
||||
_: impl FnOnce(Self) -> Result<Self, Self::Error>,
|
||||
_: impl FnOnce(Self) -> Result<Self, PrintError>,
|
||||
_: &DisambiguatedDefPathData,
|
||||
_: Ty<'tcx>,
|
||||
_: Option<ty::TraitRef<'tcx>>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
) -> Result<Self, PrintError> {
|
||||
// Inlined into `print_impl_path`
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
fn path_append(
|
||||
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> {
|
||||
let ns = match disambiguated_data.data {
|
||||
// Extern block segments can be skipped, names from extern blocks
|
||||
// are effectively living in their parent modules.
|
||||
@ -800,9 +798,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'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> {
|
||||
// Don't print any regions if they're all erased.
|
||||
let print_regions = args.iter().any(|arg| match arg.unpack() {
|
||||
GenericArgKind::Lifetime(r) => !r.is_erased(),
|
||||
|
Loading…
Reference in New Issue
Block a user