Replace src: &mut dyn Read with String
This commit is contained in:
parent
0eb2e566c1
commit
7e3791469f
4 changed files with 15 additions and 21 deletions
|
@ -16,7 +16,6 @@ use crate::hir::ptr::P;
|
|||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::io::Read;
|
||||
use std::vec;
|
||||
|
||||
pub enum AnnNode<'a> {
|
||||
|
@ -93,7 +92,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
|
|||
sess: &ParseSess,
|
||||
krate: &hir::Crate,
|
||||
filename: FileName,
|
||||
input: &mut dyn Read,
|
||||
input: String,
|
||||
out: &'a mut String,
|
||||
ann: &'a dyn PpAnn)
|
||||
{
|
||||
|
@ -111,7 +110,7 @@ impl<'a> State<'a> {
|
|||
pub fn new_from_input(cm: &'a SourceMap,
|
||||
sess: &ParseSess,
|
||||
filename: FileName,
|
||||
input: &mut dyn Read,
|
||||
input: String,
|
||||
out: &'a mut String,
|
||||
ann: &'a dyn PpAnn)
|
||||
-> State<'a> {
|
||||
|
|
|
@ -687,16 +687,14 @@ pub fn visit_crate(sess: &Session, krate: &mut ast::Crate, ppm: PpMode) {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_source(input: &Input, sess: &Session) -> (Vec<u8>, FileName) {
|
||||
fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
|
||||
let src_name = source_name(input);
|
||||
let src = sess.source_map()
|
||||
let src = String::clone(&sess.source_map()
|
||||
.get_source_file(&src_name)
|
||||
.unwrap()
|
||||
.src
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
.unwrap());
|
||||
(src, src_name)
|
||||
}
|
||||
|
||||
|
@ -719,7 +717,6 @@ pub fn print_after_parsing(sess: &Session,
|
|||
ofile: Option<&Path>) {
|
||||
let (src, src_name) = get_source(input, sess);
|
||||
|
||||
let mut rdr = &*src;
|
||||
let mut out = String::new();
|
||||
|
||||
if let PpmSource(s) = ppm {
|
||||
|
@ -732,7 +729,7 @@ pub fn print_after_parsing(sess: &Session,
|
|||
&sess.parse_sess,
|
||||
krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
src,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
false)
|
||||
|
@ -764,13 +761,13 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
|
||||
let (src, src_name) = get_source(input, tcx.sess);
|
||||
|
||||
let mut rdr = &src[..];
|
||||
let mut out = String::new();
|
||||
|
||||
match (ppm, opt_uii) {
|
||||
(PpmSource(s), _) => {
|
||||
// Silently ignores an identified node.
|
||||
let out = &mut out;
|
||||
let src = src.clone();
|
||||
s.call_with_pp_support(tcx.sess, Some(tcx), move |annotation| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
|
@ -778,7 +775,7 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
&sess.parse_sess,
|
||||
krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
src,
|
||||
out,
|
||||
annotation.pp_ann(),
|
||||
true)
|
||||
|
@ -787,6 +784,7 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
|
||||
(PpmHir(s), None) => {
|
||||
let out = &mut out;
|
||||
let src = src.clone();
|
||||
s.call_with_pp_support_hir(tcx, move |annotation, krate| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
|
@ -794,7 +792,7 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
&sess.parse_sess,
|
||||
krate,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
src,
|
||||
out,
|
||||
annotation.pp_ann())
|
||||
})
|
||||
|
@ -810,6 +808,7 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
|
||||
(PpmHir(s), Some(uii)) => {
|
||||
let out = &mut out;
|
||||
let src = src.clone();
|
||||
s.call_with_pp_support_hir(tcx, move |annotation, _| {
|
||||
debug!("pretty printing source code {:?}", s);
|
||||
let sess = annotation.sess();
|
||||
|
@ -817,7 +816,7 @@ pub fn print_after_hir_lowering<'tcx>(
|
|||
let mut pp_state = pprust_hir::State::new_from_input(sess.source_map(),
|
||||
&sess.parse_sess,
|
||||
src_name,
|
||||
&mut rdr,
|
||||
src,
|
||||
out,
|
||||
annotation.pp_ann());
|
||||
for node_id in uii.all_matching_node_ids(hir_map) {
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::parse::lexer::{self, ParseSess, StringReader};
|
|||
use syntax_pos::{BytePos, CharPos, Pos, FileName};
|
||||
use log::debug;
|
||||
|
||||
use std::io::Read;
|
||||
use std::usize;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
|
@ -340,10 +339,8 @@ fn consume_comment(rdr: &mut StringReader<'_>,
|
|||
|
||||
// it appears this function is called only from pprust... that's
|
||||
// probably not a good thing.
|
||||
pub fn gather_comments(sess: &ParseSess, path: FileName, srdr: &mut dyn Read) -> Vec<Comment>
|
||||
pub fn gather_comments(sess: &ParseSess, path: FileName, src: String) -> Vec<Comment>
|
||||
{
|
||||
let mut src = String::new();
|
||||
srdr.read_to_string(&mut src).unwrap();
|
||||
let cm = SourceMap::new(sess.source_map().path_mapping().clone());
|
||||
let source_file = cm.new_source_file(path, src);
|
||||
let mut rdr = lexer::StringReader::new(sess, source_file, None);
|
||||
|
|
|
@ -21,7 +21,6 @@ use syntax_pos::{self, BytePos};
|
|||
use syntax_pos::{DUMMY_SP, FileName, Span};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::io::Read;
|
||||
|
||||
pub enum AnnNode<'a> {
|
||||
Ident(&'a ast::Ident),
|
||||
|
@ -102,7 +101,7 @@ pub fn print_crate<'a>(cm: &'a SourceMap,
|
|||
sess: &ParseSess,
|
||||
krate: &ast::Crate,
|
||||
filename: FileName,
|
||||
input: &mut dyn Read,
|
||||
input: String,
|
||||
out: &mut String,
|
||||
ann: &'a dyn PpAnn,
|
||||
is_expanded: bool) {
|
||||
|
@ -136,7 +135,7 @@ impl<'a> State<'a> {
|
|||
pub fn new_from_input(cm: &'a SourceMap,
|
||||
sess: &ParseSess,
|
||||
filename: FileName,
|
||||
input: &mut dyn Read,
|
||||
input: String,
|
||||
out: &'a mut String,
|
||||
ann: &'a dyn PpAnn,
|
||||
is_expanded: bool) -> State<'a> {
|
||||
|
|
Loading…
Reference in a new issue