Skip to content

Commit b6b11c7

Browse files
committed
Rejig some top-level rustc_hir_pretty functions.
There are several that are unused and can be removed. And there are some calls to `to_string`, which can be expressed more nicely as a `foo_to_string` call, and then `to_string` need not be `pub`. (This requires adding `pat_to_string`).
1 parent bf9a1c8 commit b6b11c7

File tree

4 files changed

+8
-46
lines changed

4 files changed

+8
-46
lines changed

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+3-35
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a> State<'a> {
187187
}
188188
}
189189

190-
pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
190+
fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
191191
where
192192
F: FnOnce(&mut State<'_>),
193193
{
@@ -196,48 +196,16 @@ where
196196
printer.s.eof()
197197
}
198198

199-
pub fn generic_params_to_string(generic_params: &[GenericParam<'_>]) -> String {
200-
to_string(NO_ANN, |s| s.print_generic_params(generic_params))
201-
}
202-
203-
pub fn bounds_to_string<'b>(bounds: impl IntoIterator<Item = &'b hir::GenericBound<'b>>) -> String {
204-
to_string(NO_ANN, |s| s.print_bounds("", bounds))
205-
}
206-
207199
pub fn ty_to_string(ty: &hir::Ty<'_>) -> String {
208200
to_string(NO_ANN, |s| s.print_type(ty))
209201
}
210202

211-
pub fn path_segment_to_string(segment: &hir::PathSegment<'_>) -> String {
212-
to_string(NO_ANN, |s| s.print_path_segment(segment))
213-
}
214-
215-
pub fn path_to_string(segment: &hir::Path<'_>) -> String {
216-
to_string(NO_ANN, |s| s.print_path(segment, false))
217-
}
218-
219203
pub fn qpath_to_string(segment: &hir::QPath<'_>) -> String {
220204
to_string(NO_ANN, |s| s.print_qpath(segment, false))
221205
}
222206

223-
pub fn fn_to_string(
224-
decl: &hir::FnDecl<'_>,
225-
header: hir::FnHeader,
226-
name: Option<Symbol>,
227-
generics: &hir::Generics<'_>,
228-
arg_names: &[Ident],
229-
body_id: Option<hir::BodyId>,
230-
) -> String {
231-
to_string(NO_ANN, |s| s.print_fn(decl, header, name, generics, arg_names, body_id))
232-
}
233-
234-
pub fn enum_def_to_string(
235-
enum_definition: &hir::EnumDef<'_>,
236-
generics: &hir::Generics<'_>,
237-
name: Symbol,
238-
span: rustc_span::Span,
239-
) -> String {
240-
to_string(NO_ANN, |s| s.print_enum_def(enum_definition, generics, name, span))
207+
pub fn pat_to_string(pat: &hir::Pat<'_>) -> String {
208+
to_string(NO_ANN, |s| s.print_pat(pat))
241209
}
242210

243211
impl<'a> State<'a> {

Diff for: compiler/rustc_hir_typeck/src/pat.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1504,9 +1504,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15041504
{
15051505
let has_shorthand_field_name = field_patterns.iter().any(|field| field.is_shorthand);
15061506
if has_shorthand_field_name {
1507-
let path = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| {
1508-
s.print_qpath(qpath, false)
1509-
});
1507+
let path = rustc_hir_pretty::qpath_to_string(qpath);
15101508
let mut err = struct_span_err!(
15111509
self.tcx.sess,
15121510
pat.span,
@@ -1688,9 +1686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16881686
return None;
16891687
}
16901688

1691-
let path = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| {
1692-
s.print_qpath(qpath, false)
1693-
});
1689+
let path = rustc_hir_pretty::qpath_to_string(qpath);
16941690
let mut err = struct_span_err!(
16951691
self.tcx.sess,
16961692
pat.span,
@@ -1740,9 +1736,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17401736
f
17411737
}
17421738
}
1743-
Err(_) => rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| {
1744-
s.print_pat(field.pat)
1745-
}),
1739+
Err(_) => rustc_hir_pretty::pat_to_string(field.pat),
17461740
}
17471741
})
17481742
.collect::<Vec<String>>()

Diff for: src/tools/clippy/clippy_lints/src/matches/match_wild_err_arm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'
1919
if is_type_diagnostic_item(cx, ex_ty, sym::Result) {
2020
for arm in arms {
2121
if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind {
22-
let path_str = rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false));
22+
let path_str = rustc_hir_pretty::qpath_to_string(path);
2323
if path_str == "Err" {
2424
let mut matching_wild = inner.iter().any(is_wild);
2525
let mut ident_bind_name = kw::Underscore;

Diff for: src/tools/clippy/clippy_lints/src/mut_reference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
4949
cx,
5050
arguments.iter().collect(),
5151
cx.typeck_results().expr_ty(fn_expr),
52-
&rustc_hir_pretty::to_string(rustc_hir_pretty::NO_ANN, |s| s.print_qpath(path, false)),
52+
&rustc_hir_pretty::qpath_to_string(path),
5353
"function",
5454
);
5555
}

0 commit comments

Comments
 (0)