From 54d5a9846f6bfe0fe37e2a81c9bd74178ff1f3b4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 17 Jan 2012 17:12:58 +0100 Subject: [PATCH] Try to fix pretty-printer failure I can't reproduce it on my side, unfortunately. --- src/comp/driver/driver.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/comp/driver/driver.rs b/src/comp/driver/driver.rs index 59ef6737a36..26ed2609ba2 100644 --- a/src/comp/driver/driver.rs +++ b/src/comp/driver/driver.rs @@ -81,22 +81,21 @@ fn parse_input(sess: session, cfg: ast::crate_cfg, input: str) -> if !input_is_stdin(input) { parser::parse_crate_from_file(input, cfg, sess.parse_sess) } else { - let srcbytes = get_input_stream(sess, input).read_whole_stream(); - let srcstring = str::unsafe_from_bytes(srcbytes); - parser::parse_crate_from_source_str(input, srcstring, cfg, - sess.parse_sess) + let src = get_input_str(sess, input); + parser::parse_crate_from_source_str(input, src, cfg, sess.parse_sess) } } -fn get_input_stream(sess: session, infile: str) -> io::reader { - if !input_is_stdin(infile) { +fn get_input_str(sess: session, infile: str) -> str { + let stream = if !input_is_stdin(infile) { alt io::file_reader(infile) { result::ok(reader) { reader } result::err(e) { sess.fatal(e) } } - } else { io::stdin() } + } else { io::stdin() }; + str::unsafe_from_bytes(stream.read_whole_stream()) } fn time(do_it: bool, what: str, thunk: fn@() -> T) -> T { @@ -285,7 +284,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str, _ { cu_parse } }; let {crate, tcx} = compile_upto(sess, cfg, input, upto, none); - let src = get_input_stream(sess, input); + let src = get_input_str(sess, input); let ann: pprust::pp_ann = pprust::no_ann(); alt ppm { @@ -299,7 +298,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str, ppm_expanded. | ppm_normal. {} } pprust::print_crate(sess.codemap, sess.diagnostic, crate, input, - src, io::stdout(), ann); + io::string_reader(src), io::stdout(), ann); } fn get_os(triple: str) -> option {