print_crate returns String instead of taking an out pointer

This commit is contained in:
Mark Rousskov 2019-07-05 17:48:21 -04:00
parent 7e3791469f
commit e0db2e606c
3 changed files with 13 additions and 15 deletions

View file

@ -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> {

View file

@ -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())
})
}

View file

@ -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> {