Rename most of the printers.
Three of them are named `AbsolutePathPrinter`, which is confusing, so give those names that better indicate how they are used. And then there is `SymbolPrinter` and `SymbolMangler`, which are renamed as `LegacySymbolMangler` and `V0SymbolMangler`, better indicating their similarity.
This commit is contained in:
parent
566cdab16d
commit
b0c36dd4c7
5 changed files with 22 additions and 22 deletions
|
|
@ -7,12 +7,12 @@ use rustc_middle::bug;
|
|||
use rustc_middle::ty::print::{PrettyPrinter, PrintError, Printer};
|
||||
use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};
|
||||
|
||||
struct AbsolutePathPrinter<'tcx> {
|
||||
struct TypeNamePrinter<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
|
@ -133,7 +133,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
|
||||
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Write for AbsolutePathPrinter<'_> {
|
||||
impl Write for TypeNamePrinter<'_> {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
self.path.push_str(s);
|
||||
Ok(())
|
||||
|
|
@ -165,7 +165,7 @@ impl Write for AbsolutePathPrinter<'_> {
|
|||
}
|
||||
|
||||
pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
|
||||
let mut p = AbsolutePathPrinter { tcx, path: String::new() };
|
||||
let mut p = TypeNamePrinter { tcx, path: String::new() };
|
||||
p.print_type(ty).unwrap();
|
||||
p.path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -745,12 +745,12 @@ impl<'tcx> LateContext<'tcx> {
|
|||
/// }
|
||||
/// ```
|
||||
pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol> {
|
||||
struct AbsolutePathPrinter<'tcx> {
|
||||
struct LintPathPrinter<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
path: Vec<Symbol>,
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
impl<'tcx> Printer<'tcx> for LintPathPrinter<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
|
@ -853,7 +853,7 @@ impl<'tcx> LateContext<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut p = AbsolutePathPrinter { tcx: self.tcx, path: vec![] };
|
||||
let mut p = LintPathPrinter { tcx: self.tcx, path: vec![] };
|
||||
p.print_def_path(def_id, &[]).unwrap();
|
||||
p.path
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ pub(super) fn mangle<'tcx>(
|
|||
|
||||
let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);
|
||||
|
||||
let mut p = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false };
|
||||
let mut p = LegacySymbolMangler { tcx, path: SymbolPath::new(), keep_within_component: false };
|
||||
p.print_def_path(
|
||||
def_id,
|
||||
if let ty::InstanceKind::DropGlue(_, _)
|
||||
|
|
@ -213,7 +213,7 @@ impl SymbolPath {
|
|||
}
|
||||
}
|
||||
|
||||
struct SymbolPrinter<'tcx> {
|
||||
struct LegacySymbolMangler<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
path: SymbolPath,
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ struct SymbolPrinter<'tcx> {
|
|||
// `PrettyPrinter` aka pretty printing of e.g. types in paths,
|
||||
// symbol names should have their own printing machinery.
|
||||
|
||||
impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
|
||||
impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
|
@ -453,7 +453,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
|
||||
impl<'tcx> PrettyPrinter<'tcx> for LegacySymbolMangler<'tcx> {
|
||||
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
@ -489,7 +489,7 @@ impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for SymbolPrinter<'_> {
|
||||
impl fmt::Write for LegacySymbolMangler<'_> {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
// Name sanitation. LLVM will happily accept identifiers with weird names, but
|
||||
// gas doesn't!
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ pub(super) fn mangle<'tcx>(
|
|||
let args = tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), instance.args);
|
||||
|
||||
let prefix = "_R";
|
||||
let mut p: SymbolMangler<'_> = SymbolMangler {
|
||||
let mut p: V0SymbolMangler<'_> = V0SymbolMangler {
|
||||
tcx,
|
||||
start_offset: prefix.len(),
|
||||
is_exportable,
|
||||
|
|
@ -88,7 +88,7 @@ pub fn mangle_internal_symbol<'tcx>(tcx: TyCtxt<'tcx>, item_name: &str) -> Strin
|
|||
}
|
||||
|
||||
let prefix = "_R";
|
||||
let mut p: SymbolMangler<'_> = SymbolMangler {
|
||||
let mut p: V0SymbolMangler<'_> = V0SymbolMangler {
|
||||
tcx,
|
||||
start_offset: prefix.len(),
|
||||
is_exportable: false,
|
||||
|
|
@ -131,7 +131,7 @@ pub(super) fn mangle_typeid_for_trait_ref<'tcx>(
|
|||
trait_ref: ty::ExistentialTraitRef<'tcx>,
|
||||
) -> String {
|
||||
// FIXME(flip1995): See comment in `mangle_typeid_for_fnabi`.
|
||||
let mut p = SymbolMangler {
|
||||
let mut p = V0SymbolMangler {
|
||||
tcx,
|
||||
start_offset: 0,
|
||||
is_exportable: false,
|
||||
|
|
@ -159,7 +159,7 @@ struct BinderLevel {
|
|||
lifetime_depths: Range<u32>,
|
||||
}
|
||||
|
||||
struct SymbolMangler<'tcx> {
|
||||
struct V0SymbolMangler<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
binders: Vec<BinderLevel>,
|
||||
out: String,
|
||||
|
|
@ -173,7 +173,7 @@ struct SymbolMangler<'tcx> {
|
|||
consts: FxHashMap<ty::Const<'tcx>, usize>,
|
||||
}
|
||||
|
||||
impl<'tcx> SymbolMangler<'tcx> {
|
||||
impl<'tcx> V0SymbolMangler<'tcx> {
|
||||
fn push(&mut self, s: &str) {
|
||||
self.out.push_str(s);
|
||||
}
|
||||
|
|
@ -272,7 +272,7 @@ impl<'tcx> SymbolMangler<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
||||
impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -224,12 +224,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
use ty::GenericArg;
|
||||
use ty::print::Printer;
|
||||
|
||||
struct AbsolutePathPrinter<'tcx> {
|
||||
struct ConflictingPathPrinter<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
segments: Vec<Symbol>,
|
||||
}
|
||||
|
||||
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
|
||||
impl<'tcx> Printer<'tcx> for ConflictingPathPrinter<'tcx> {
|
||||
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
// let _ = [{struct Foo; Foo}, {struct Foo; Foo}];
|
||||
if did1.krate != did2.krate {
|
||||
let abs_path = |def_id| {
|
||||
let mut p = AbsolutePathPrinter { tcx: self.tcx, segments: vec![] };
|
||||
let mut p = ConflictingPathPrinter { tcx: self.tcx, segments: vec![] };
|
||||
p.print_def_path(def_id, &[]).map(|_| p.segments)
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue