about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-01-17 17:12:58 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2012-01-17 17:12:58 +0100
commit54d5a9846f6bfe0fe37e2a81c9bd74178ff1f3b4 (patch)
treee0a02ea31f019f5d0f1f60ccd56a5d3daf081d47 /src/comp
parent08c16b17e906958ce8e3902a3962e9d801fb6e8c (diff)
downloadrust-54d5a9846f6bfe0fe37e2a81c9bd74178ff1f3b4.tar.gz
rust-54d5a9846f6bfe0fe37e2a81c9bd74178ff1f3b4.zip
Try to fix pretty-printer failure
I can't reproduce it on my side, unfortunately.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/driver/driver.rs17
1 files 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<T>(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<session::os> {