Skip to content

Commit

Permalink
print_crate returns String instead of taking an out pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jul 10, 2019
1 parent 7e37914 commit e0db2e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/librustc/hir/print.rs
Expand Up @@ -93,17 +93,17 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
krate: &hir::Crate, krate: &hir::Crate,
filename: FileName, filename: FileName,
input: String, input: String,
out: &'a mut String, ann: &'a dyn PpAnn) -> String {
ann: &'a dyn PpAnn) let mut out = String::new();
{ let mut s = State::new_from_input(cm, sess, filename, input, &mut out, ann);
let mut s = State::new_from_input(cm, sess, filename, input, out, ann);


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


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


impl<'a> State<'a> { impl<'a> State<'a> {
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_driver/pretty.rs
Expand Up @@ -725,12 +725,11 @@ pub fn print_after_parsing(sess: &Session,
s.call_with_pp_support(sess, None, move |annotation| { s.call_with_pp_support(sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.source_map(), *out = pprust::print_crate(sess.source_map(),
&sess.parse_sess, &sess.parse_sess,
krate, krate,
src_name, src_name,
src, src,
out,
annotation.pp_ann(), annotation.pp_ann(),
false) false)
}) })
Expand Down Expand Up @@ -771,12 +770,11 @@ pub fn print_after_hir_lowering<'tcx>(
s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| { s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust::print_crate(sess.source_map(), *out = pprust::print_crate(sess.source_map(),
&sess.parse_sess, &sess.parse_sess,
krate, krate,
src_name, src_name,
src, src,
out,
annotation.pp_ann(), annotation.pp_ann(),
true) true)
}) })
Expand All @@ -788,12 +786,11 @@ pub fn print_after_hir_lowering<'tcx>(
s.call_with_pp_support_hir(tcx, move |annotation, krate| { s.call_with_pp_support_hir(tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s); debug!("pretty printing source code {:?}", s);
let sess = annotation.sess(); let sess = annotation.sess();
pprust_hir::print_crate(sess.source_map(), *out = pprust_hir::print_crate(sess.source_map(),
&sess.parse_sess, &sess.parse_sess,
krate, krate,
src_name, src_name,
src, src,
out,
annotation.pp_ann()) annotation.pp_ann())
}) })
} }
Expand Down
9 changes: 5 additions & 4 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -102,10 +102,10 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
krate: &ast::Crate, krate: &ast::Crate,
filename: FileName, filename: FileName,
input: String, input: String,
out: &mut String,
ann: &'a dyn PpAnn, ann: &'a dyn PpAnn,
is_expanded: bool) { is_expanded: bool) -> String {
let mut s = State::new_from_input(cm, sess, filename, input, out, ann, is_expanded); 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() { if is_expanded && std_inject::injected_crate_name().is_some() {
// We need to print `#![no_std]` (and its feature gate) so that // We need to print `#![no_std]` (and its feature gate) so that
Expand All @@ -128,7 +128,8 @@ pub fn print_crate<'a>(cm: &'a SourceMap,


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


impl<'a> State<'a> { impl<'a> State<'a> {
Expand Down

0 comments on commit e0db2e6

Please sign in to comment.