about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-10-10 14:23:08 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-10-11 10:46:55 +1100
commit7d35902c6275f5236f77427c2cca8d58f8f8a579 (patch)
tree92baa2d827d05d915b218001f6b477a570154c1a
parent494bc8514aa98b7f4786b66a7774004902ef4aa2 (diff)
downloadrust-7d35902c6275f5236f77427c2cca8d58f8f8a579.tar.gz
rust-7d35902c6275f5236f77427c2cca8d58f8f8a579.zip
Fiddle with `State` functions.
Remove and inline `new_from_input`, because it has a single call site.
And move `attrs` into the earlier `impl` block.
-rw-r--r--compiler/rustc_hir_pretty/src/lib.rs32
1 files changed, 10 insertions, 22 deletions
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs
index 077f9e947e6..ab6ab391484 100644
--- a/compiler/rustc_hir_pretty/src/lib.rs
+++ b/compiler/rustc_hir_pretty/src/lib.rs
@@ -73,6 +73,10 @@ pub struct State<'a> {
 }
 
 impl<'a> State<'a> {
+    fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
+        (self.attrs)(id)
+    }
+
     fn print_node(&mut self, node: Node<'_>) {
         match node {
             Node::Param(a) => self.print_param(a),
@@ -154,7 +158,12 @@ pub fn print_crate<'a>(
     attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
     ann: &'a dyn PpAnn,
 ) -> String {
-    let mut s = State::new_from_input(sm, filename, input, attrs, ann);
+    let mut s = State {
+        s: pp::Printer::new(),
+        comments: Some(Comments::new(sm, filename, input)),
+        attrs,
+        ann,
+    };
 
     // When printing the AST, we sometimes need to inject `#[no_std]` here.
     // Since you can't compile the HIR, it's not necessary.
@@ -164,27 +173,6 @@ pub fn print_crate<'a>(
     s.s.eof()
 }
 
-impl<'a> State<'a> {
-    fn new_from_input(
-        sm: &'a SourceMap,
-        filename: FileName,
-        input: String,
-        attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
-        ann: &'a dyn PpAnn,
-    ) -> State<'a> {
-        State {
-            s: pp::Printer::new(),
-            comments: Some(Comments::new(sm, filename, input)),
-            attrs,
-            ann,
-        }
-    }
-
-    fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
-        (self.attrs)(id)
-    }
-}
-
 fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
 where
     F: FnOnce(&mut State<'_>),