diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-10-28 21:19:59 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-10-29 01:25:11 -0700 |
| commit | 2cebef095e61608a3d35710cb5fd3d7de18b68ac (patch) | |
| tree | cb24a5d2506444d157edfe16fac08f2d31892a28 /src/comp/syntax | |
| parent | 2b62a80202e2855d47f20d271842e0e9aec6d8e2 (diff) | |
| download | rust-2cebef095e61608a3d35710cb5fd3d7de18b68ac.tar.gz rust-2cebef095e61608a3d35710cb5fd3d7de18b68ac.zip | |
stdlib: Make io failures recoverable by returning a result
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/codemap.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 13 |
2 files changed, 19 insertions, 4 deletions
diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index 5156570c8ba..2db5e1e2c4c 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -1,4 +1,4 @@ -import std::{vec, uint, str, term, io, option}; +import std::{vec, uint, str, term, io, option, result}; import std::option::{some, none}; type filename = str; @@ -154,7 +154,13 @@ fn maybe_highlight_lines(sp: option::t<span>, cm: codemap, // FIXME: reading in the entire file is the worst possible way to // get access to the necessary lines. - let file = io::read_whole_file_str(lines.name); + let file = alt io::read_whole_file_str(lines.name) { + result::ok(file) { file } + result::err(e) { + emit_error(none, e, cm); + fail; + } + }; let fm = get_filemap(cm, lines.name); // arbitrarily only print up to six lines of the error diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index dc1b7fb3047..f605a2fb699 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1,5 +1,5 @@ -import std::{io, vec, str, option, either}; +import std::{io, vec, str, option, either, result}; import std::option::{some, none}; import std::either::{left, right}; import std::map::{hashmap, new_str_hash}; @@ -53,7 +53,16 @@ type parser = fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, chpos: uint, byte_pos: uint, ftype: file_type) -> parser { - let src = io::read_whole_file_str(path); + let src = alt io::read_whole_file_str(path) { + result::ok(src) { + // FIXME: This copy is unfortunate + src + } + result::err(e) { + codemap::emit_error(none, e, sess.cm); + fail; + } + }; let filemap = codemap::new_filemap(path, chpos, byte_pos); sess.cm.files += [filemap]; let itr = @interner::mk(str::hash, str::eq); |
