Skip to content
Permalink
Browse files

print_crate returns String instead of taking an out pointer

  • Loading branch information...
Mark-Simulacrum committed Jul 5, 2019
1 parent 7e37914 commit e0db2e606cdb242db1466ae51129c9a6b81560fe
Showing with 13 additions and 15 deletions.
  1. +5 −5 src/librustc/hir/print.rs
  2. +3 −6 src/librustc_driver/pretty.rs
  3. +5 −4 src/libsyntax/print/pprust.rs
@@ -93,17 +93,17 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
krate: &hir::Crate,
filename: FileName,
input: String,
out: &'a mut String,
ann: &'a dyn PpAnn)
{
let mut s = State::new_from_input(cm, sess, filename, input, out, ann);
ann: &'a dyn PpAnn) -> String {
let mut out = String::new();
let mut s = State::new_from_input(cm, sess, filename, input, &mut out, ann);

// When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary.

s.print_mod(&krate.module, &krate.attrs);
s.print_remaining_comments();
s.s.eof()
s.s.eof();
out
}

impl<'a> State<'a> {
@@ -725,12 +725,11 @@ pub fn print_after_parsing(sess: &Session,
s.call_with_pp_support(sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.source_map(),
*out = pprust::print_crate(sess.source_map(),
&sess.parse_sess,
krate,
src_name,
src,
out,
annotation.pp_ann(),
false)
})
@@ -771,12 +770,11 @@ pub fn print_after_hir_lowering<'tcx>(
s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust::print_crate(sess.source_map(),
*out = pprust::print_crate(sess.source_map(),
&sess.parse_sess,
krate,
src_name,
src,
out,
annotation.pp_ann(),
true)
})
@@ -788,12 +786,11 @@ pub fn print_after_hir_lowering<'tcx>(
s.call_with_pp_support_hir(tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
pprust_hir::print_crate(sess.source_map(),
*out = pprust_hir::print_crate(sess.source_map(),
&sess.parse_sess,
krate,
src_name,
src,
out,
annotation.pp_ann())
})
}
@@ -102,10 +102,10 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
krate: &ast::Crate,
filename: FileName,
input: String,
out: &mut String,
ann: &'a dyn PpAnn,
is_expanded: bool) {
let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded);
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);

if is_expanded && std_inject::injected_crate_name().is_some() {
// We need to print `#![no_std]` (and its feature gate) so that
@@ -128,7 +128,8 @@ pub fn print_crate<'a>(cm: &'a SourceMap,

s.print_mod(&krate.module, &krate.attrs);
s.print_remaining_comments();
s.s.eof()
s.s.eof();
out
}

impl<'a> State<'a> {

0 comments on commit e0db2e6

Please sign in to comment.
You can’t perform that action at this time.