Skip to content

Commit

Permalink
Inline State::new_from_input in pprust
Browse files Browse the repository at this point in the history
This function took too many arguments and are simple on the inside;
inlining them makes complexity go down.

hir::print's copy is unfortunately used from librustc_driver so inlining
it is not as straightforward.
  • Loading branch information
Mark-Simulacrum committed Jul 10, 2019
1 parent e0db2e6 commit e0ffa7c
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -105,7 +105,12 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
ann: &'a dyn PpAnn,
is_expanded: bool) -> String {
let mut out = String::new();
let mut s = State::new_from_input(cm, sess, filename, input, &mut out, ann, is_expanded);
let mut s = State {
s: pp::mk_printer(&mut out),
comments: Some(Comments::new(cm, sess, filename, input)),
ann,
is_expanded,
};

if is_expanded && std_inject::injected_crate_name().is_some() {
// We need to print `#![no_std]` (and its feature gate) so that
Expand All @@ -132,23 +137,6 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
out
}

impl<'a> State<'a> {
pub fn new_from_input(cm: &'a SourceMap,
sess: &ParseSess,
filename: FileName,
input: String,
out: &'a mut String,
ann: &'a dyn PpAnn,
is_expanded: bool) -> State<'a> {
State {
s: pp::mk_printer(out),
comments: Some(Comments::new(cm, sess, filename, input)),
ann,
is_expanded,
}
}
}

pub fn to_string<F>(f: F) -> String where
F: FnOnce(&mut State<'_>),
{
Expand Down

0 comments on commit e0ffa7c

Please sign in to comment.