about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-03 10:41:34 -0800
committerbors <bors@rust-lang.org>2014-02-03 10:41:34 -0800
commitcb40eba4b1ce12914612914b94bdccd251a9f554 (patch)
tree5cb922f942920dc7d6b0f3606e9cd914360b2707 /src/libsyntax/ext
parentbe4fc638092bf896c5c6c0672136b83b71e491ee (diff)
parentc765a8e7ad314651b92ff860cda0159c79dbec6e (diff)
downloadrust-cb40eba4b1ce12914612914b94bdccd251a9f554.tar.gz
rust-cb40eba4b1ce12914612914b94bdccd251a9f554.zip
auto merge of #11946 : alexcrichton/rust/no-io-error, r=brson
Turns out this was a little more far-reaching than I thought it was.

The first commit is the crux of this stack of commits. The `io::io_error` condition is completely removed and the `read` and `write` methods are altered to return `IoResult<T>`. This turned out to be an incredibly far-reaching change!

Overall, I'm very happy with how this turned out (in addition with the `unused_must_use` lint). I had to almost rewrite the pretty printer in `libsyntax` as well as the the formatting in `librustdoc` (as one would expect). These two modules do *tons* of I/O, and I believe that it's definitely improved.

This pull request also introduces the `if_ok!()` macro for returning-early from something that returns a result. I made quite liberal use of this in mostly the pretty printer and html renderer, and I found its usage generally quite pleasant and convenient to have. I didn't really feel like adding any other macro while I was using it, and I figured that pretty printing could be nicer, but it's nowhere near horrid today.

This may be a controversial issue closing, but I'm going to say it.

Closes #6163
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/expand.rs9
-rw-r--r--src/libsyntax/ext/source_util.rs9
2 files changed, 8 insertions, 10 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index d8d98b27793..ae93c235ad2 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -957,14 +957,13 @@ mod test {
     use ast_util;
     use codemap;
     use codemap::Spanned;
-    use fold;
     use fold::*;
     use ext::base::{CrateLoader, MacroCrate};
     use parse;
     use parse::token::{fresh_mark, gensym, intern};
     use parse::token;
     use util::parser_testing::{string_to_crate, string_to_crate_and_sess};
-    use util::parser_testing::{string_to_pat, string_to_tts, strs_to_idents};
+    use util::parser_testing::{string_to_pat, strs_to_idents};
     use visit;
     use visit::Visitor;
 
@@ -1253,14 +1252,14 @@ mod test {
                     let varref_name = mtwt_resolve(varref.segments[0].identifier);
                     let varref_marks = mtwt_marksof(varref.segments[0].identifier.ctxt,
                                                     invalid_name);
-                    if (!(varref_name==binding_name)){
+                    if !(varref_name==binding_name) {
                         println!("uh oh, should match but doesn't:");
                         println!("varref: {:?}",varref);
                         println!("binding: {:?}", bindings[binding_idx]);
                         ast_util::display_sctable(get_sctable());
                     }
                     assert_eq!(varref_name,binding_name);
-                    if (bound_ident_check) {
+                    if bound_ident_check {
                         // we're checking bound-identifier=?, and the marks
                         // should be the same, too:
                         assert_eq!(varref_marks,binding_marks.clone());
@@ -1269,7 +1268,7 @@ mod test {
                     let fail = (varref.segments.len() == 1)
                         && (mtwt_resolve(varref.segments[0].identifier) == binding_name);
                     // temp debugging:
-                    if (fail) {
+                    if fail {
                         println!("failure on test {}",test_idx);
                         println!("text of test case: \"{}\"", teststr);
                         println!("");
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs
index f3f947ec00d..52010b39a54 100644
--- a/src/libsyntax/ext/source_util.rs
+++ b/src/libsyntax/ext/source_util.rs
@@ -20,7 +20,6 @@ use parse::token::get_ident_interner;
 use parse::token;
 use print::pprust;
 
-use std::io;
 use std::io::File;
 use std::rc::Rc;
 use std::str;
@@ -109,9 +108,9 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
         None => return MacResult::dummy_expr()
     };
     let file = res_rel_file(cx, sp, &Path::new(file));
-    let bytes = match io::result(|| File::open(&file).read_to_end()) {
+    let bytes = match File::open(&file).read_to_end() {
         Err(e) => {
-            cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e.desc));
+            cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e));
             return MacResult::dummy_expr();
         }
         Ok(bytes) => bytes,
@@ -141,9 +140,9 @@ pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
         None => return MacResult::dummy_expr()
     };
     let file = res_rel_file(cx, sp, &Path::new(file));
-    match io::result(|| File::open(&file).read_to_end()) {
+    match File::open(&file).read_to_end() {
         Err(e) => {
-            cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e.desc));
+            cx.span_err(sp, format!("couldn't read {}: {}", file.display(), e));
             return MacResult::dummy_expr();
         }
         Ok(bytes) => {