diff options
| author | bors <bors@rust-lang.org> | 2013-11-04 12:21:11 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-04 12:21:11 -0800 |
| commit | 658637baf45b41e4cff049440bc07f267d810218 (patch) | |
| tree | 019eee1761d43461ef06f1e5307b57b0b8b47019 /src/libsyntax | |
| parent | 70e9b5ab3912da84a32557bc1a34db5fb2178927 (diff) | |
| parent | 3c3ed1499a9b9e23d4a2d2243a7b0b1c9015f34b (diff) | |
auto merge of #10179 : alexcrichton/rust/rt-improvements, r=cmr
This fleshes out the io::file module a fair bit more, adding all of the functionality that I can think of that we would want. Some questions about the representation which I'm curious about: * I modified `FileStat` to be a little less platform-agnostic, but it's still fairly platform-specific. I don't want to hide information that we have, but I don't want to depend on this information being available. One possible route is to have an `extra` field which has all this os-dependent stuff which is clearly documented as it should be avoided. * Does it make sense for directory functions to be top-level functions instead of static methods? It seems silly to import `std::rt::io::file` and `std::rt::io::File` at the top of files that need to deal with directories and files.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 17 |
2 files changed, 14 insertions, 29 deletions
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index fda6f782af4..75b5ab81f9b 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -20,8 +20,7 @@ use parse::token::{get_ident_interner}; use print::pprust; use std::rt::io; -use std::rt::io::Reader; -use std::rt::io::file::FileInfo; +use std::rt::io::File; use std::str; // These macros all relate to the file system; they either return @@ -92,17 +91,13 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); let file = res_rel_file(cx, sp, &Path::new(file)); - let mut error = None; - let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { - file.open_reader(io::Open).read_to_end() - }; - match error { - Some(e) => { + let bytes = match io::result(|| File::open(&file).read_to_end()) { + Err(e) => { cx.span_fatal(sp, format!("couldn't read {}: {}", file.display(), e.desc)); } - None => {} - } + Ok(bytes) => bytes, + }; match str::from_utf8_owned_opt(bytes) { Some(s) => base::MRExpr(cx.expr_str(sp, s.to_managed())), None => { @@ -118,17 +113,12 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); let file = res_rel_file(cx, sp, &Path::new(file)); - - let mut error = None; - let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { - file.open_reader(io::Open).read_to_end() - }; - match error { - Some(e) => { + match io::result(|| File::open(&file).read_to_end()) { + Err(e) => { cx.span_fatal(sp, format!("couldn't read {}: {}", file.display(), e.desc)); } - None => { + Ok(bytes) => { let bytes = at_vec::to_managed_move(bytes); base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes))) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 003bc006ebe..fbe711b5efe 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -19,10 +19,8 @@ use parse::attr::parser_attr; use parse::lexer::reader; use parse::parser::Parser; -use std::path::Path; use std::rt::io; -use std::rt::io::Reader; -use std::rt::io::file::FileInfo; +use std::rt::io::File; use std::str; pub mod lexer; @@ -269,16 +267,13 @@ pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<Span>) None => sess.span_diagnostic.handler().fatal(msg), } }; - let mut error = None; - let bytes = do io::io_error::cond.trap(|e| error = Some(e)).inside { - path.open_reader(io::Open).read_to_end() - }; - match error { - Some(e) => { + let bytes = match io::result(|| File::open(path).read_to_end()) { + Ok(bytes) => bytes, + Err(e) => { err(format!("couldn't read {}: {}", path.display(), e.desc)); + unreachable!() } - None => {} - } + }; match str::from_utf8_owned_opt(bytes) { Some(s) => { return string_to_filemap(sess, s.to_managed(), |
