Skip to content

Commit b0c36dd

Browse files
committed
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.
1 parent 566cdab commit b0c36dd

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use rustc_middle::bug;
77
use rustc_middle::ty::print::{PrettyPrinter, PrintError, Printer};
88
use rustc_middle::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt};
99

10-
struct AbsolutePathPrinter<'tcx> {
10+
struct TypeNamePrinter<'tcx> {
1111
tcx: TyCtxt<'tcx>,
1212
path: String,
1313
}
1414

15-
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
15+
impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
1616
fn tcx(&self) -> TyCtxt<'tcx> {
1717
self.tcx
1818
}
@@ -133,7 +133,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
133133
}
134134
}
135135

136-
impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
136+
impl<'tcx> PrettyPrinter<'tcx> for TypeNamePrinter<'tcx> {
137137
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
138138
false
139139
}
@@ -157,15 +157,15 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
157157
}
158158
}
159159

160-
impl Write for AbsolutePathPrinter<'_> {
160+
impl Write for TypeNamePrinter<'_> {
161161
fn write_str(&mut self, s: &str) -> std::fmt::Result {
162162
self.path.push_str(s);
163163
Ok(())
164164
}
165165
}
166166

167167
pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
168-
let mut p = AbsolutePathPrinter { tcx, path: String::new() };
168+
let mut p = TypeNamePrinter { tcx, path: String::new() };
169169
p.print_type(ty).unwrap();
170170
p.path
171171
}

compiler/rustc_lint/src/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,12 @@ impl<'tcx> LateContext<'tcx> {
745745
/// }
746746
/// ```
747747
pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol> {
748-
struct AbsolutePathPrinter<'tcx> {
748+
struct LintPathPrinter<'tcx> {
749749
tcx: TyCtxt<'tcx>,
750750
path: Vec<Symbol>,
751751
}
752752

753-
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
753+
impl<'tcx> Printer<'tcx> for LintPathPrinter<'tcx> {
754754
fn tcx(&self) -> TyCtxt<'tcx> {
755755
self.tcx
756756
}
@@ -853,7 +853,7 @@ impl<'tcx> LateContext<'tcx> {
853853
}
854854
}
855855

856-
let mut p = AbsolutePathPrinter { tcx: self.tcx, path: vec![] };
856+
let mut p = LintPathPrinter { tcx: self.tcx, path: vec![] };
857857
p.print_def_path(def_id, &[]).unwrap();
858858
p.path
859859
}

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) fn mangle<'tcx>(
5858

5959
let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate);
6060

61-
let mut p = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false };
61+
let mut p = LegacySymbolMangler { tcx, path: SymbolPath::new(), keep_within_component: false };
6262
p.print_def_path(
6363
def_id,
6464
if let ty::InstanceKind::DropGlue(_, _)
@@ -213,7 +213,7 @@ impl SymbolPath {
213213
}
214214
}
215215

216-
struct SymbolPrinter<'tcx> {
216+
struct LegacySymbolMangler<'tcx> {
217217
tcx: TyCtxt<'tcx>,
218218
path: SymbolPath,
219219

@@ -228,7 +228,7 @@ struct SymbolPrinter<'tcx> {
228228
// `PrettyPrinter` aka pretty printing of e.g. types in paths,
229229
// symbol names should have their own printing machinery.
230230

231-
impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
231+
impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
232232
fn tcx(&self) -> TyCtxt<'tcx> {
233233
self.tcx
234234
}
@@ -453,7 +453,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
453453
}
454454
}
455455

456-
impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
456+
impl<'tcx> PrettyPrinter<'tcx> for LegacySymbolMangler<'tcx> {
457457
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
458458
false
459459
}
@@ -489,7 +489,7 @@ impl<'tcx> PrettyPrinter<'tcx> for SymbolPrinter<'tcx> {
489489
}
490490
}
491491

492-
impl fmt::Write for SymbolPrinter<'_> {
492+
impl fmt::Write for LegacySymbolMangler<'_> {
493493
fn write_str(&mut self, s: &str) -> fmt::Result {
494494
// Name sanitation. LLVM will happily accept identifiers with weird names, but
495495
// gas doesn't!

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(super) fn mangle<'tcx>(
3333
let args = tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), instance.args);
3434

3535
let prefix = "_R";
36-
let mut p: SymbolMangler<'_> = SymbolMangler {
36+
let mut p: V0SymbolMangler<'_> = V0SymbolMangler {
3737
tcx,
3838
start_offset: prefix.len(),
3939
is_exportable,
@@ -88,7 +88,7 @@ pub fn mangle_internal_symbol<'tcx>(tcx: TyCtxt<'tcx>, item_name: &str) -> Strin
8888
}
8989

9090
let prefix = "_R";
91-
let mut p: SymbolMangler<'_> = SymbolMangler {
91+
let mut p: V0SymbolMangler<'_> = V0SymbolMangler {
9292
tcx,
9393
start_offset: prefix.len(),
9494
is_exportable: false,
@@ -131,7 +131,7 @@ pub(super) fn mangle_typeid_for_trait_ref<'tcx>(
131131
trait_ref: ty::ExistentialTraitRef<'tcx>,
132132
) -> String {
133133
// FIXME(flip1995): See comment in `mangle_typeid_for_fnabi`.
134-
let mut p = SymbolMangler {
134+
let mut p = V0SymbolMangler {
135135
tcx,
136136
start_offset: 0,
137137
is_exportable: false,
@@ -159,7 +159,7 @@ struct BinderLevel {
159159
lifetime_depths: Range<u32>,
160160
}
161161

162-
struct SymbolMangler<'tcx> {
162+
struct V0SymbolMangler<'tcx> {
163163
tcx: TyCtxt<'tcx>,
164164
binders: Vec<BinderLevel>,
165165
out: String,
@@ -173,7 +173,7 @@ struct SymbolMangler<'tcx> {
173173
consts: FxHashMap<ty::Const<'tcx>, usize>,
174174
}
175175

176-
impl<'tcx> SymbolMangler<'tcx> {
176+
impl<'tcx> V0SymbolMangler<'tcx> {
177177
fn push(&mut self, s: &str) {
178178
self.out.push_str(s);
179179
}
@@ -272,7 +272,7 @@ impl<'tcx> SymbolMangler<'tcx> {
272272
}
273273
}
274274

275-
impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
275+
impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
276276
fn tcx(&self) -> TyCtxt<'tcx> {
277277
self.tcx
278278
}

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
224224
use ty::GenericArg;
225225
use ty::print::Printer;
226226

227-
struct AbsolutePathPrinter<'tcx> {
227+
struct ConflictingPathPrinter<'tcx> {
228228
tcx: TyCtxt<'tcx>,
229229
segments: Vec<Symbol>,
230230
}
231231

232-
impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
232+
impl<'tcx> Printer<'tcx> for ConflictingPathPrinter<'tcx> {
233233
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
234234
self.tcx
235235
}
@@ -300,7 +300,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
300300
// let _ = [{struct Foo; Foo}, {struct Foo; Foo}];
301301
if did1.krate != did2.krate {
302302
let abs_path = |def_id| {
303-
let mut p = AbsolutePathPrinter { tcx: self.tcx, segments: vec![] };
303+
let mut p = ConflictingPathPrinter { tcx: self.tcx, segments: vec![] };
304304
p.print_def_path(def_id, &[]).map(|_| p.segments)
305305
};
306306

0 commit comments

Comments
 (0)