Skip to content

Commit d7612dc

Browse files
committed
Rename some Printer methods.
I find these name clearer, and starting them all with `print_` makes things more consistent.
1 parent bbf6cde commit d7612dc

File tree

8 files changed

+71
-61
lines changed

8 files changed

+71
-61
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
@@ -73,20 +73,20 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
7373
self.pretty_print_dyn_existential(predicates)
7474
}
7575

76-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
76+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
7777
self.path.push_str(self.tcx.crate_name(cnum).as_str());
7878
Ok(())
7979
}
8080

81-
fn path_qualified(
81+
fn print_path_with_qualified(
8282
&mut self,
8383
self_ty: Ty<'tcx>,
8484
trait_ref: Option<ty::TraitRef<'tcx>>,
8585
) -> Result<(), PrintError> {
8686
self.pretty_path_qualified(self_ty, trait_ref)
8787
}
8888

89-
fn path_append_impl(
89+
fn print_path_with_impl(
9090
&mut self,
9191
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
9292
self_ty: Ty<'tcx>,
@@ -105,7 +105,7 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
105105
)
106106
}
107107

108-
fn path_append(
108+
fn print_path_with_simple(
109109
&mut self,
110110
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
111111
disambiguated_data: &DisambiguatedDefPathData,
@@ -117,7 +117,7 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
117117
Ok(())
118118
}
119119

120-
fn path_generic_args(
120+
fn print_path_with_generic_args(
121121
&mut self,
122122
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
123123
args: &[GenericArg<'tcx>],

compiler/rustc_lint/src/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -774,12 +774,12 @@ impl<'tcx> LateContext<'tcx> {
774774
unreachable!(); // because `path_generic_args` ignores the `GenericArgs`
775775
}
776776

777-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
777+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
778778
self.path = vec![self.tcx.crate_name(cnum)];
779779
Ok(())
780780
}
781781

782-
fn path_qualified(
782+
fn print_path_with_qualified(
783783
&mut self,
784784
self_ty: Ty<'tcx>,
785785
trait_ref: Option<ty::TraitRef<'tcx>>,
@@ -800,7 +800,7 @@ impl<'tcx> LateContext<'tcx> {
800800
})
801801
}
802802

803-
fn path_append_impl(
803+
fn print_path_with_impl(
804804
&mut self,
805805
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
806806
self_ty: Ty<'tcx>,
@@ -825,7 +825,7 @@ impl<'tcx> LateContext<'tcx> {
825825
Ok(())
826826
}
827827

828-
fn path_append(
828+
fn print_path_with_simple(
829829
&mut self,
830830
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
831831
disambiguated_data: &DisambiguatedDefPathData,
@@ -844,7 +844,7 @@ impl<'tcx> LateContext<'tcx> {
844844
Ok(())
845845
}
846846

847-
fn path_generic_args(
847+
fn print_path_with_generic_args(
848848
&mut self,
849849
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
850850
_args: &[GenericArg<'tcx>],

compiler/rustc_middle/src/ty/print/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@ pub trait Printer<'tcx>: Sized {
8181
fn print_const(&mut self, ct: ty::Const<'tcx>) -> Result<(), PrintError>;
8282

8383
/// Appends a representation of a crate name, e.g. "std", or even "".
84-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError>;
84+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError>;
8585

8686
/// Appends a representation of a (full or partial) simple path, in two parts. `print_prefix`,
8787
/// when called, appends the representation of the leading segments. The rest of the method
8888
/// appends the representation of the final segment, the details of which are in
8989
/// `disambiguated_data`.
9090
///
9191
/// E.g. "std::io" + "Read" -> "std::io::Read".
92-
fn path_append(
92+
fn print_path_with_simple(
9393
&mut self,
9494
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
9595
disambiguated_data: &DisambiguatedDefPathData,
9696
) -> Result<(), PrintError>;
9797

98-
/// Similar to `path_append`, but the final segment is an `impl` segment.
98+
/// Similar to `print_path_with_simple`, but the final segment is an `impl` segment.
9999
///
100100
/// E.g. "slice" + "<impl [T]>" -> "slice::<impl [T]>", which may then be further appended to,
101101
/// giving a longer path representation such as "slice::<impl [T]>::to_vec_in::ConvertVec".
102-
fn path_append_impl(
102+
fn print_path_with_impl(
103103
&mut self,
104104
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
105105
self_ty: Ty<'tcx>,
@@ -112,15 +112,15 @@ pub trait Printer<'tcx>: Sized {
112112
/// args.)
113113
///
114114
/// E.g. "ImplementsTraitForUsize" + "<usize>" -> "ImplementsTraitForUsize<usize>".
115-
fn path_generic_args(
115+
fn print_path_with_generic_args(
116116
&mut self,
117117
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
118118
args: &[GenericArg<'tcx>],
119119
) -> Result<(), PrintError>;
120120

121121
/// Appends a representation of a qualified path segment, e.g. "<OsString as From<&T>>".
122122
/// If `trait_ref` is `None`, it may fall back to simpler forms, e.g. "<Vec<T>>" or just "Foo".
123-
fn path_qualified(
123+
fn print_path_with_qualified(
124124
&mut self,
125125
self_ty: Ty<'tcx>,
126126
trait_ref: Option<ty::TraitRef<'tcx>>,
@@ -140,7 +140,7 @@ pub trait Printer<'tcx>: Sized {
140140
match key.disambiguated_data.data {
141141
DefPathData::CrateRoot => {
142142
assert!(key.parent.is_none());
143-
self.path_crate(def_id.krate)
143+
self.print_crate_name(def_id.krate)
144144
}
145145

146146
DefPathData::Impl => self.print_impl_path(def_id, args),
@@ -164,7 +164,7 @@ pub trait Printer<'tcx>: Sized {
164164
)) = self.tcx().coroutine_kind(def_id)
165165
&& args.len() > parent_args.len()
166166
{
167-
return self.path_generic_args(
167+
return self.print_path_with_generic_args(
168168
|p| p.print_def_path(def_id, parent_args),
169169
&args[..parent_args.len() + 1][..1],
170170
);
@@ -186,7 +186,7 @@ pub trait Printer<'tcx>: Sized {
186186
_ => {
187187
if !generics.is_own_empty() && args.len() >= generics.count() {
188188
let args = generics.own_args_no_defaults(self.tcx(), args);
189-
return self.path_generic_args(
189+
return self.print_path_with_generic_args(
190190
|p| p.print_def_path(def_id, parent_args),
191191
args,
192192
);
@@ -202,15 +202,15 @@ pub trait Printer<'tcx>: Sized {
202202
&& self.tcx().generics_of(parent_def_id).parent_count == 0;
203203
}
204204

205-
self.path_append(
205+
self.print_path_with_simple(
206206
|p: &mut Self| {
207207
if trait_qualify_parent {
208208
let trait_ref = ty::TraitRef::new(
209209
p.tcx(),
210210
parent_def_id,
211211
parent_args.iter().copied(),
212212
);
213-
p.path_qualified(trait_ref.self_ty(), Some(trait_ref))
213+
p.print_path_with_qualified(trait_ref.self_ty(), Some(trait_ref))
214214
} else {
215215
p.print_def_path(parent_def_id, parent_args)
216216
}
@@ -253,11 +253,15 @@ pub trait Printer<'tcx>: Sized {
253253
// If the impl is not co-located with either self-type or
254254
// trait-type, then fallback to a format that identifies
255255
// the module more clearly.
256-
self.path_append_impl(|p| p.print_def_path(parent_def_id, &[]), self_ty, impl_trait_ref)
256+
self.print_path_with_impl(
257+
|p| p.print_def_path(parent_def_id, &[]),
258+
self_ty,
259+
impl_trait_ref,
260+
)
257261
} else {
258262
// Otherwise, try to give a good form that would be valid language
259263
// syntax. Preferably using associated item notation.
260-
self.path_qualified(self_ty, impl_trait_ref)
264+
self.print_path_with_qualified(self_ty, impl_trait_ref)
261265
}
262266
}
263267
}

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
474474
// path to the crate followed by the path to the item within the crate.
475475
if let Some(cnum) = def_id.as_crate_root() {
476476
if cnum == LOCAL_CRATE {
477-
self.path_crate(cnum)?;
477+
self.print_crate_name(cnum)?;
478478
return Ok(true);
479479
}
480480

@@ -498,7 +498,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
498498
// or avoid ending up with `ExternCrateSource::Extern`,
499499
// for the injected `std`/`core`.
500500
if span.is_dummy() {
501-
self.path_crate(cnum)?;
501+
self.print_crate_name(cnum)?;
502502
return Ok(true);
503503
}
504504

@@ -512,13 +512,13 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
512512
return Ok(true);
513513
}
514514
(ExternCrateSource::Path, LOCAL_CRATE) => {
515-
self.path_crate(cnum)?;
515+
self.print_crate_name(cnum)?;
516516
return Ok(true);
517517
}
518518
_ => {}
519519
},
520520
None => {
521-
self.path_crate(cnum)?;
521+
self.print_crate_name(cnum)?;
522522
return Ok(true);
523523
}
524524
}
@@ -628,7 +628,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
628628
return Ok(false);
629629
}
630630
callers.push(visible_parent);
631-
// HACK(eddyb) this bypasses `path_append`'s prefix printing to avoid
631+
// HACK(eddyb) this bypasses `print_path_with_simple`'s prefix printing to avoid
632632
// knowing ahead of time whether the entire path will succeed or not.
633633
// To support printers that do not implement `PrettyPrinter`, a `Vec` or
634634
// linked list on the stack would need to be built, before any printing.
@@ -637,7 +637,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
637637
true => {}
638638
}
639639
callers.pop();
640-
self.path_append(|_| Ok(()), &DisambiguatedDefPathData { data, disambiguator: 0 })?;
640+
self.print_path_with_simple(
641+
|_| Ok(()),
642+
&DisambiguatedDefPathData { data, disambiguator: 0 },
643+
)?;
641644
Ok(true)
642645
}
643646

@@ -1312,10 +1315,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
13121315
alias_ty: ty::AliasTerm<'tcx>,
13131316
) -> Result<(), PrintError> {
13141317
let def_key = self.tcx().def_key(alias_ty.def_id);
1315-
self.path_generic_args(
1318+
self.print_path_with_generic_args(
13161319
|p| {
1317-
p.path_append(
1318-
|p| p.path_qualified(alias_ty.self_ty(), None),
1320+
p.print_path_with_simple(
1321+
|p| p.print_path_with_qualified(alias_ty.self_ty(), None),
13191322
&def_key.disambiguated_data,
13201323
)
13211324
},
@@ -1400,7 +1403,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
14001403
}
14011404
}
14021405

1403-
// HACK(eddyb) this duplicates `FmtPrinter`'s `path_generic_args`,
1406+
// HACK(eddyb) this duplicates `FmtPrinter`'s `print_path_with_generic_args`,
14041407
// in order to place the projections inside the `<...>`.
14051408
if !resugared {
14061409
let principal_with_self =
@@ -2234,7 +2237,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
22342237

22352238
self.print_def_path(parent_def_id, &[])?;
22362239

2237-
// HACK(eddyb) copy of `path_append` to avoid
2240+
// HACK(eddyb) copy of `print_path_with_simple` to avoid
22382241
// constructing a `DisambiguatedDefPathData`.
22392242
if !self.empty_path {
22402243
write!(self, "::")?;
@@ -2310,7 +2313,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23102313
self.pretty_print_const(ct, false)
23112314
}
23122315

2313-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
2316+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
23142317
self.empty_path = true;
23152318
if cnum == LOCAL_CRATE {
23162319
if self.tcx.sess.at_least_rust_2018() {
@@ -2327,7 +2330,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23272330
Ok(())
23282331
}
23292332

2330-
fn path_qualified(
2333+
fn print_path_with_qualified(
23312334
&mut self,
23322335
self_ty: Ty<'tcx>,
23332336
trait_ref: Option<ty::TraitRef<'tcx>>,
@@ -2337,7 +2340,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23372340
Ok(())
23382341
}
23392342

2340-
fn path_append_impl(
2343+
fn print_path_with_impl(
23412344
&mut self,
23422345
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
23432346
self_ty: Ty<'tcx>,
@@ -2359,7 +2362,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23592362
Ok(())
23602363
}
23612364

2362-
fn path_append(
2365+
fn print_path_with_simple(
23632366
&mut self,
23642367
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
23652368
disambiguated_data: &DisambiguatedDefPathData,
@@ -2390,7 +2393,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
23902393
Ok(())
23912394
}
23922395

2393-
fn path_generic_args(
2396+
fn print_path_with_generic_args(
23942397
&mut self,
23952398
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
23962399
args: &[GenericArg<'tcx>],
@@ -3229,7 +3232,7 @@ define_print! {
32293232
// The args don't contain the self ty (as it has been erased) but the corresp.
32303233
// generics do as the trait always has a self ty param. We need to offset.
32313234
let args = &self.args[p.tcx().generics_of(self.def_id).parent_count - 1..];
3232-
p.path_generic_args(|p| write!(p, "{name}"), args)?;
3235+
p.print_path_with_generic_args(|p| write!(p, "{name}"), args)?;
32333236
write!(p, " = ")?;
32343237
self.term.print(p)?;
32353238
}

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ struct LegacySymbolMangler<'tcx> {
218218
path: SymbolPath,
219219

220220
// When `true`, `finalize_pending_component` isn't used.
221-
// This is needed when recursing into `path_qualified`,
222-
// or `path_generic_args`, as any nested paths are
221+
// This is needed when recursing into `print_path_with_qualified`,
222+
// or `print_path_with_generic_args`, as any nested paths are
223223
// logically within one component.
224224
keep_within_component: bool,
225225
}
@@ -303,11 +303,12 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
303303
Ok(())
304304
}
305305

306-
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
306+
fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
307307
self.write_str(self.tcx.crate_name(cnum).as_str())?;
308308
Ok(())
309309
}
310-
fn path_qualified(
310+
311+
fn print_path_with_qualified(
311312
&mut self,
312313
self_ty: Ty<'tcx>,
313314
trait_ref: Option<ty::TraitRef<'tcx>>,
@@ -329,7 +330,7 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
329330
}
330331
}
331332

332-
fn path_append_impl(
333+
fn print_path_with_impl(
333334
&mut self,
334335
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
335336
self_ty: Ty<'tcx>,
@@ -352,7 +353,8 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
352353
trait_ref,
353354
)
354355
}
355-
fn path_append(
356+
357+
fn print_path_with_simple(
356358
&mut self,
357359
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
358360
disambiguated_data: &DisambiguatedDefPathData,
@@ -375,7 +377,8 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
375377

376378
Ok(())
377379
}
378-
fn path_generic_args(
380+
381+
fn print_path_with_generic_args(
379382
&mut self,
380383
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
381384
args: &[GenericArg<'tcx>],

0 commit comments

Comments
 (0)