diff options
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_map/mod.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 33 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 48 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 256 |
9 files changed, 218 insertions, 196 deletions
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index c33158193ce..faa681c0255 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -25,7 +25,7 @@ use visit::{self, Visitor}; use arena::TypedArena; use std::cell::RefCell; use std::fmt; -use std::old_io::IoResult; +use std::io; use std::iter::{self, repeat}; use std::mem; use std::slice; @@ -997,11 +997,11 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>, } pub trait NodePrinter { - fn print_node(&mut self, node: &Node) -> IoResult<()>; + fn print_node(&mut self, node: &Node) -> io::Result<()>; } impl<'a> NodePrinter for pprust::State<'a> { - fn print_node(&mut self, node: &Node) -> IoResult<()> { + fn print_node(&mut self, node: &Node) -> io::Result<()> { match *node { NodeItem(a) => self.print_item(&*a), NodeForeignItem(a) => self.print_foreign_item(&*a), diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index ba3743cdb33..62d98be8b85 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -20,7 +20,9 @@ use print::pprust; use ptr::P; use util::small_vector::SmallVector; -use std::old_io::File; +use std::fs::File; +use std::io::prelude::*; +use std::path::{Path, PathBuf}; use std::rc::Rc; // These macros all relate to the file system; they either return @@ -97,7 +99,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree cx.cfg(), &res_rel_file(cx, sp, - &Path::new(file)), + Path::new(&file)), true, None, sp); @@ -136,8 +138,10 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Some(f) => f, None => return DummyResult::expr(sp) }; - let file = res_rel_file(cx, sp, &Path::new(file)); - let bytes = match File::open(&file).read_to_end() { + let file = res_rel_file(cx, sp, Path::new(&file)); + let mut bytes = Vec::new(); + match File::open(&file).and_then(|mut f| f.read_to_end(&mut bytes)) { + Ok(..) => {} Err(e) => { cx.span_err(sp, &format!("couldn't read {}: {}", @@ -145,7 +149,6 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) e)); return DummyResult::expr(sp); } - Ok(bytes) => bytes, }; match String::from_utf8(bytes) { Ok(src) => { @@ -172,15 +175,15 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Some(f) => f, None => return DummyResult::expr(sp) }; - let file = res_rel_file(cx, sp, &Path::new(file)); - match File::open(&file).read_to_end() { + let file = res_rel_file(cx, sp, Path::new(&file)); + let mut bytes = Vec::new(); + match File::open(&file).and_then(|mut f| f.read_to_end(&mut bytes)) { Err(e) => { cx.span_err(sp, &format!("couldn't read {}: {}", file.display(), e)); return DummyResult::expr(sp); } - Ok(bytes) => { - let bytes = bytes.iter().cloned().collect(); + Ok(..) => { base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes)))) } } @@ -188,14 +191,18 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // resolve a file-system path to an absolute file-system path (if it // isn't already) -fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { +fn res_rel_file(cx: &mut ExtCtxt, sp: codemap::Span, arg: &Path) -> PathBuf { // NB: relative paths are resolved relative to the compilation unit if !arg.is_absolute() { - let mut cu = Path::new(cx.codemap().span_to_filename(sp)); - cu.pop(); + let mut cu = PathBuf::new(&cx.codemap().span_to_filename(sp)); + if cu.parent().is_some() { + cu.pop(); + } else { + cu = PathBuf::new(""); + } cu.push(arg); cu } else { - arg.clone() + arg.to_path_buf() } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index a556b2dfd2a..959e3bdb314 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1432,7 +1432,7 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T) #[cfg(test)] mod test { - use std::old_io; + use std::io; use ast; use util::parser_testing::{string_to_crate, matches_codepattern}; use parse::token; @@ -1442,7 +1442,7 @@ mod test { // this version doesn't care about getting comments or docstrings in. fn fake_print_crate(s: &mut pprust::State, - krate: &ast::Crate) -> old_io::IoResult<()> { + krate: &ast::Crate) -> io::Result<()> { s.print_mod(&krate.module, &krate.attrs) } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 7acbd10ef03..7bd9cc3b855 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -36,6 +36,9 @@ #![feature(staged_api)] #![feature(std_misc)] #![feature(unicode)] +#![feature(path)] +#![feature(fs)] +#![feature(io)] extern crate arena; extern crate fmt_macros; diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 3ad1d96a45d..fb9e0480ceb 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -19,9 +19,8 @@ use parse::lexer::is_block_doc_comment; use parse::lexer; use print::pprust; -use std::old_io; +use std::io::Read; use std::str; -use std::string::String; use std::usize; #[derive(Clone, Copy, PartialEq)] @@ -337,9 +336,10 @@ pub struct Literal { // probably not a good thing. pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler, path: String, - srdr: &mut old_io::Reader) + srdr: &mut Read) -> (Vec<Comment>, Vec<Literal>) { - let src = srdr.read_to_end().unwrap(); + let mut src = Vec::new(); + srdr.read_to_end(&mut src).unwrap(); let src = String::from_utf8(src).unwrap(); let cm = CodeMap::new(); let filemap = cm.new_filemap(path, src); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 66589d5e3d1..def5963e6f4 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -18,11 +18,13 @@ use parse::parser::Parser; use ptr::P; use std::cell::{Cell, RefCell}; -use std::old_io::File; -use std::rc::Rc; +use std::fs::File; +use std::io::Read; +use std::iter; use std::num::Int; +use std::path::{Path, PathBuf}; +use std::rc::Rc; use std::str; -use std::iter; #[macro_use] pub mod parser; @@ -39,7 +41,7 @@ pub mod obsolete; pub struct ParseSess { pub span_diagnostic: SpanHandler, // better be the same as the one in the reader! /// Used to determine and report recursive mod inclusions - included_mod_stack: RefCell<Vec<Path>>, + included_mod_stack: RefCell<Vec<PathBuf>>, pub node_id: Cell<ast::NodeId>, } @@ -250,24 +252,24 @@ pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) None => sess.span_diagnostic.handler().fatal(msg), } }; - let bytes = match File::open(path).read_to_end() { - Ok(bytes) => bytes, + let mut bytes = Vec::new(); + match File::open(path).and_then(|mut f| f.read_to_end(&mut bytes)) { + Ok(..) => {} Err(e) => { - err(&format!("couldn't read {:?}: {}", - path.display(), e)); - unreachable!() + err(&format!("couldn't read {:?}: {}", path.display(), e)); + unreachable!(); } }; match str::from_utf8(&bytes[..]).ok() { Some(s) => { - return string_to_filemap(sess, s.to_string(), - path.as_str().unwrap().to_string()) + string_to_filemap(sess, s.to_string(), + path.to_str().unwrap().to_string()) } None => { - err(&format!("{:?} is not UTF-8 encoded", path.display())) + err(&format!("{:?} is not UTF-8 encoded", path.display())); + unreachable!(); } } - unreachable!() } /// Given a session and a string, add the string to diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c1acee57cf8..88df6d6d4cd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -78,10 +78,11 @@ use ptr::P; use owned_slice::OwnedSlice; use std::collections::HashSet; -use std::old_io::fs::PathExtensions; +use std::io::prelude::*; use std::iter; use std::mem; use std::num::Float; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::slice; @@ -5248,14 +5249,23 @@ impl<'a> Parser<'a> { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::Item_, Vec<ast::Attribute> ) { - let mut prefix = Path::new(self.sess.span_diagnostic.cm.span_to_filename(self.span)); - prefix.pop(); - let mod_path = Path::new(".").join_many(&self.mod_path_stack); - let dir_path = prefix.join(&mod_path); + let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm + .span_to_filename(self.span)); + // FIXME(acrichto): right now "a".pop() == "a", but need to confirm with + // aturon whether this is expected or not. + if prefix.parent().is_some() { + prefix.pop(); + } else { + prefix = PathBuf::new(""); + } + let mut dir_path = prefix; + for part in &self.mod_path_stack { + dir_path.push(&**part); + } let mod_string = token::get_ident(id); let (file_path, owns_directory) = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { - Some(d) => (dir_path.join(d), true), + Some(d) => (dir_path.join(&*d), true), None => { let mod_name = mod_string.to_string(); let default_path_str = format!("{}.rs", mod_name); @@ -5319,7 +5329,7 @@ impl<'a> Parser<'a> { } fn eval_src_mod_from_path(&mut self, - path: Path, + path: PathBuf, owns_directory: bool, name: String, id_sp: Span) -> (ast::Item_, Vec<ast::Attribute> ) { @@ -5329,10 +5339,10 @@ impl<'a> Parser<'a> { let mut err = String::from_str("circular modules: "); let len = included_mod_stack.len(); for p in &included_mod_stack[i.. len] { - err.push_str(&p.display().as_cow()); + err.push_str(&p.to_string_lossy()); err.push_str(" -> "); } - err.push_str(&path.display().as_cow()); + err.push_str(&path.to_string_lossy()); self.span_fatal(id_sp, &err[..]); } None => () diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 4cef7ed469f..640b7d1c91d 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -59,7 +59,7 @@ //! line (which it can't) and so naturally place the content on its own line to //! avoid combining it with other lines and making matters even worse. -use std::old_io; +use std::io; use std::string; use std::iter::repeat; @@ -161,7 +161,7 @@ pub struct PrintStackElem { const SIZE_INFINITY: isize = 0xffff; -pub fn mk_printer(out: Box<old_io::Writer+'static>, linewidth: usize) -> Printer { +pub fn mk_printer<'a>(out: Box<io::Write+'a>, linewidth: usize) -> Printer<'a> { // Yes 3, it makes the ring buffers big enough to never // fall behind. let n: usize = 3 * linewidth; @@ -265,8 +265,8 @@ pub fn mk_printer(out: Box<old_io::Writer+'static>, linewidth: usize) -> Printer /// In this implementation (following the paper, again) the SCAN process is /// the method called 'pretty_print', and the 'PRINT' process is the method /// called 'print'. -pub struct Printer { - pub out: Box<old_io::Writer+'static>, +pub struct Printer<'a> { + pub out: Box<io::Write+'a>, buf_len: usize, /// Width of lines we're constrained to margin: isize, @@ -303,7 +303,7 @@ pub struct Printer { pending_indentation: isize, } -impl Printer { +impl<'a> Printer<'a> { pub fn last_token(&mut self) -> Token { self.token[self.right].clone() } @@ -311,7 +311,7 @@ impl Printer { pub fn replace_last_token(&mut self, t: Token) { self.token[self.right] = t; } - pub fn pretty_print(&mut self, token: Token) -> old_io::IoResult<()> { + pub fn pretty_print(&mut self, token: Token) -> io::Result<()> { debug!("pp ~[{},{}]", self.left, self.right); match token { Token::Eof => { @@ -385,7 +385,7 @@ impl Printer { } } } - pub fn check_stream(&mut self) -> old_io::IoResult<()> { + pub fn check_stream(&mut self) -> io::Result<()> { debug!("check_stream ~[{}, {}] with left_total={}, right_total={}", self.left, self.right, self.left_total, self.right_total); if self.right_total - self.left_total > self.space { @@ -445,7 +445,7 @@ impl Printer { self.right %= self.buf_len; assert!((self.right != self.left)); } - pub fn advance_left(&mut self) -> old_io::IoResult<()> { + pub fn advance_left(&mut self) -> io::Result<()> { debug!("advance_left ~[{},{}], sizeof({})={}", self.left, self.right, self.left, self.size[self.left]); @@ -506,7 +506,7 @@ impl Printer { } } } - pub fn print_newline(&mut self, amount: isize) -> old_io::IoResult<()> { + pub fn print_newline(&mut self, amount: isize) -> io::Result<()> { debug!("NEWLINE {}", amount); let ret = write!(self.out, "\n"); self.pending_indentation = 0; @@ -529,14 +529,14 @@ impl Printer { } } } - pub fn print_str(&mut self, s: &str) -> old_io::IoResult<()> { + pub fn print_str(&mut self, s: &str) -> io::Result<()> { while self.pending_indentation > 0 { try!(write!(self.out, " ")); self.pending_indentation -= 1; } write!(self.out, "{}", s) } - pub fn print(&mut self, token: Token, l: isize) -> old_io::IoResult<()> { + pub fn print(&mut self, token: Token, l: isize) -> io::Result<()> { debug!("print {} {} (remaining line space={})", tok_str(&token), l, self.space); debug!("{}", buf_str(&self.token, @@ -620,61 +620,61 @@ impl Printer { // Convenience functions to talk to the printer. // // "raw box" -pub fn rbox(p: &mut Printer, indent: usize, b: Breaks) -> old_io::IoResult<()> { +pub fn rbox(p: &mut Printer, indent: usize, b: Breaks) -> io::Result<()> { p.pretty_print(Token::Begin(BeginToken { offset: indent as isize, breaks: b })) } -pub fn ibox(p: &mut Printer, indent: usize) -> old_io::IoResult<()> { +pub fn ibox(p: &mut Printer, indent: usize) -> io::Result<()> { rbox(p, indent, Breaks::Inconsistent) } -pub fn cbox(p: &mut Printer, indent: usize) -> old_io::IoResult<()> { +pub fn cbox(p: &mut Printer, indent: usize) -> io::Result<()> { rbox(p, indent, Breaks::Consistent) } -pub fn break_offset(p: &mut Printer, n: usize, off: isize) -> old_io::IoResult<()> { +pub fn break_offset(p: &mut Printer, n: usize, off: isize) -> io::Result<()> { p.pretty_print(Token::Break(BreakToken { offset: off, blank_space: n as isize })) } -pub fn end(p: &mut Printer) -> old_io::IoResult<()> { +pub fn end(p: &mut Printer) -> io::Result<()> { p.pretty_print(Token::End) } -pub fn eof(p: &mut Printer) -> old_io::IoResult<()> { +pub fn eof(p: &mut Printer) -> io::Result<()> { p.pretty_print(Token::Eof) } -pub fn word(p: &mut Printer, wrd: &str) -> old_io::IoResult<()> { +pub fn word(p: &mut Printer, wrd: &str) -> io::Result<()> { p.pretty_print(Token::String(/* bad */ wrd.to_string(), wrd.len() as isize)) } -pub fn huge_word(p: &mut Printer, wrd: &str) -> old_io::IoResult<()> { +pub fn huge_word(p: &mut Printer, wrd: &str) -> io::Result<()> { p.pretty_print(Token::String(/* bad */ wrd.to_string(), SIZE_INFINITY)) } -pub fn zero_word(p: &mut Printer, wrd: &str) -> old_io::IoResult<()> { +pub fn zero_word(p: &mut Printer, wrd: &str) -> io::Result<()> { p.pretty_print(Token::String(/* bad */ wrd.to_string(), 0)) } -pub fn spaces(p: &mut Printer, n: usize) -> old_io::IoResult<()> { +pub fn spaces(p: &mut Printer, n: usize) -> io::Result<()> { break_offset(p, n, 0) } -pub fn zerobreak(p: &mut Printer) -> old_io::IoResult<()> { +pub fn zerobreak(p: &mut Printer) -> io::Result<()> { spaces(p, 0) } -pub fn space(p: &mut Printer) -> old_io::IoResult<()> { +pub fn space(p: &mut Printer) -> io::Result<()> { spaces(p, 1) } -pub fn hardbreak(p: &mut Printer) -> old_io::IoResult<()> { +pub fn hardbreak(p: &mut Printer) -> io::Result<()> { spaces(p, SIZE_INFINITY as usize) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index af16e19c9f0..883c2295a36 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -30,7 +30,7 @@ use ptr::P; use std_inject; use std::{ascii, mem}; -use std::old_io::{self, IoResult}; +use std::io::{self, Write, Read}; use std::iter; pub enum AnnNode<'a> { @@ -43,8 +43,8 @@ pub enum AnnNode<'a> { } pub trait PpAnn { - fn pre(&self, _state: &mut State, _node: AnnNode) -> IoResult<()> { Ok(()) } - fn post(&self, _state: &mut State, _node: AnnNode) -> IoResult<()> { Ok(()) } + fn pre(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) } + fn post(&self, _state: &mut State, _node: AnnNode) -> io::Result<()> { Ok(()) } } #[derive(Copy)] @@ -59,7 +59,7 @@ pub struct CurrentCommentAndLiteral { } pub struct State<'a> { - pub s: pp::Printer, + pub s: pp::Printer<'a>, cm: Option<&'a CodeMap>, comments: Option<Vec<comments::Comment> >, literals: Option<Vec<comments::Literal> >, @@ -69,12 +69,12 @@ pub struct State<'a> { encode_idents_with_hygiene: bool, } -pub fn rust_printer(writer: Box<old_io::Writer+'static>) -> State<'static> { +pub fn rust_printer<'a>(writer: Box<Write+'a>) -> State<'a> { static NO_ANN: NoAnn = NoAnn; rust_printer_annotated(writer, &NO_ANN) } -pub fn rust_printer_annotated<'a>(writer: Box<old_io::Writer+'static>, +pub fn rust_printer_annotated<'a>(writer: Box<Write+'a>, ann: &'a PpAnn) -> State<'a> { State { s: pp::mk_printer(writer, default_columns), @@ -104,10 +104,10 @@ pub fn print_crate<'a>(cm: &'a CodeMap, span_diagnostic: &diagnostic::SpanHandler, krate: &ast::Crate, filename: String, - input: &mut old_io::Reader, - out: Box<old_io::Writer+'static>, + input: &mut Read, + out: Box<Write+'a>, ann: &'a PpAnn, - is_expanded: bool) -> IoResult<()> { + is_expanded: bool) -> io::Result<()> { let mut s = State::new_from_input(cm, span_diagnostic, filename, @@ -143,8 +143,8 @@ impl<'a> State<'a> { pub fn new_from_input(cm: &'a CodeMap, span_diagnostic: &diagnostic::SpanHandler, filename: String, - input: &mut old_io::Reader, - out: Box<old_io::Writer+'static>, + input: &mut Read, + out: Box<Write+'a>, ann: &'a PpAnn, is_expanded: bool) -> State<'a> { let (cmnts, lits) = comments::gather_comments_and_literals( @@ -164,7 +164,7 @@ impl<'a> State<'a> { } pub fn new(cm: &'a CodeMap, - out: Box<old_io::Writer+'static>, + out: Box<Write+'a>, ann: &'a PpAnn, comments: Option<Vec<comments::Comment>>, literals: Option<Vec<comments::Literal>>) -> State<'a> { @@ -185,14 +185,14 @@ impl<'a> State<'a> { } pub fn to_string<F>(f: F) -> String where - F: FnOnce(&mut State) -> IoResult<()>, + F: FnOnce(&mut State) -> io::Result<()>, { use std::raw::TraitObject; let mut s = rust_printer(box Vec::new()); f(&mut s).unwrap(); eof(&mut s.s).unwrap(); let wr = unsafe { - // FIXME(pcwalton): A nasty function to extract the string from an `old_io::Writer` + // FIXME(pcwalton): A nasty function to extract the string from an `Write` // that we "know" to be a `Vec<u8>` that works around the lack of checked // downcasts. let obj: &TraitObject = mem::transmute(&s.s.out); @@ -440,13 +440,13 @@ thing_to_string_impls! { to_string } pub mod with_hygiene { use abi; use ast; - use std::old_io::IoResult; + use std::io; use super::indent_unit; // This function is the trick that all the rest of the routines // hang on. pub fn to_string_hyg<F>(f: F) -> String where - F: FnOnce(&mut super::State) -> IoResult<()>, + F: FnOnce(&mut super::State) -> io::Result<()>, { super::to_string(move |s| { s.encode_idents_with_hygiene = true; @@ -474,44 +474,44 @@ fn needs_parentheses(expr: &ast::Expr) -> bool { } impl<'a> State<'a> { - pub fn ibox(&mut self, u: usize) -> IoResult<()> { + pub fn ibox(&mut self, u: usize) -> io::Result<()> { self.boxes.push(pp::Breaks::Inconsistent); pp::ibox(&mut self.s, u) } - pub fn end(&mut self) -> IoResult<()> { + pub fn end(&mut self) -> io::Result<()> { self.boxes.pop().unwrap(); pp::end(&mut self.s) } - pub fn cbox(&mut self, u: usize) -> IoResult<()> { + pub fn cbox(&mut self, u: usize) -> io::Result<()> { self.boxes.push(pp::Breaks::Consistent); pp::cbox(&mut self.s, u) } // "raw box" - pub fn rbox(&mut self, u: usize, b: pp::Breaks) -> IoResult<()> { + pub fn rbox(&mut self, u: usize, b: pp::Breaks) -> io::Result<()> { self.boxes.push(b); pp::rbox(&mut self.s, u, b) } - pub fn nbsp(&mut self) -> IoResult<()> { word(&mut self.s, " ") } + pub fn nbsp(&mut self) -> io::Result<()> { word(&mut self.s, " ") } - pub fn word_nbsp(&mut self, w: &str) -> IoResult<()> { + pub fn word_nbsp(&mut self, w: &str) -> io::Result<()> { try!(word(&mut self.s, w)); self.nbsp() } - pub fn word_space(&mut self, w: &str) -> IoResult<()> { + pub fn word_space(&mut self, w: &str) -> io::Result<()> { try!(word(&mut self.s, w)); space(&mut self.s) } - pub fn popen(&mut self) -> IoResult<()> { word(&mut self.s, "(") } + pub fn popen(&mut self) -> io::Result<()> { word(&mut self.s, "(") } - pub fn pclose(&mut self) -> IoResult<()> { word(&mut self.s, ")") } + pub fn pclose(&mut self) -> io::Result<()> { word(&mut self.s, ")") } - pub fn head(&mut self, w: &str) -> IoResult<()> { + pub fn head(&mut self, w: &str) -> io::Result<()> { // outer-box is consistent try!(self.cbox(indent_unit)); // head-box is inconsistent @@ -523,17 +523,17 @@ impl<'a> State<'a> { Ok(()) } - pub fn bopen(&mut self) -> IoResult<()> { + pub fn bopen(&mut self) -> io::Result<()> { try!(word(&mut self.s, "{")); self.end() // close the head-box } pub fn bclose_(&mut self, span: codemap::Span, - indented: usize) -> IoResult<()> { + indented: usize) -> io::Result<()> { self.bclose_maybe_open(span, indented, true) } pub fn bclose_maybe_open (&mut self, span: codemap::Span, - indented: usize, close_box: bool) -> IoResult<()> { + indented: usize, close_box: bool) -> io::Result<()> { try!(self.maybe_print_comment(span.hi)); try!(self.break_offset_if_not_bol(1, -(indented as isize))); try!(word(&mut self.s, "}")); @@ -542,7 +542,7 @@ impl<'a> State<'a> { } Ok(()) } - pub fn bclose(&mut self, span: codemap::Span) -> IoResult<()> { + pub fn bclose(&mut self, span: codemap::Span) -> io::Result<()> { self.bclose_(span, indent_unit) } @@ -572,18 +572,18 @@ impl<'a> State<'a> { } } - pub fn hardbreak_if_not_bol(&mut self) -> IoResult<()> { + pub fn hardbreak_if_not_bol(&mut self) -> io::Result<()> { if !self.is_bol() { try!(hardbreak(&mut self.s)) } Ok(()) } - pub fn space_if_not_bol(&mut self) -> IoResult<()> { + pub fn space_if_not_bol(&mut self) -> io::Result<()> { if !self.is_bol() { try!(space(&mut self.s)); } Ok(()) } pub fn break_offset_if_not_bol(&mut self, n: usize, - off: isize) -> IoResult<()> { + off: isize) -> io::Result<()> { if !self.is_bol() { break_offset(&mut self.s, n, off) } else { @@ -599,7 +599,7 @@ impl<'a> State<'a> { // Synthesizes a comment that was not textually present in the original source // file. - pub fn synth_comment(&mut self, text: String) -> IoResult<()> { + pub fn synth_comment(&mut self, text: String) -> io::Result<()> { try!(word(&mut self.s, "/*")); try!(space(&mut self.s)); try!(word(&mut self.s, &text[..])); @@ -607,8 +607,8 @@ impl<'a> State<'a> { word(&mut self.s, "*/") } - pub fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> IoResult<()> where - F: FnMut(&mut State, &T) -> IoResult<()>, + pub fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()> where + F: FnMut(&mut State, &T) -> io::Result<()>, { try!(self.rbox(0, b)); let mut first = true; @@ -624,8 +624,8 @@ impl<'a> State<'a> { b: Breaks, elts: &[T], mut op: F, - mut get_span: G) -> IoResult<()> where - F: FnMut(&mut State, &T) -> IoResult<()>, + mut get_span: G) -> io::Result<()> where + F: FnMut(&mut State, &T) -> io::Result<()>, G: FnMut(&T) -> codemap::Span, { try!(self.rbox(0, b)); @@ -646,12 +646,12 @@ impl<'a> State<'a> { } pub fn commasep_exprs(&mut self, b: Breaks, - exprs: &[P<ast::Expr>]) -> IoResult<()> { + exprs: &[P<ast::Expr>]) -> io::Result<()> { self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&**e), |e| e.span) } pub fn print_mod(&mut self, _mod: &ast::Mod, - attrs: &[ast::Attribute]) -> IoResult<()> { + attrs: &[ast::Attribute]) -> io::Result<()> { try!(self.print_inner_attributes(attrs)); for item in &_mod.items { try!(self.print_item(&**item)); @@ -660,7 +660,7 @@ impl<'a> State<'a> { } pub fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod, - attrs: &[ast::Attribute]) -> IoResult<()> { + attrs: &[ast::Attribute]) -> io::Result<()> { try!(self.print_inner_attributes(attrs)); for item in &nmod.items { try!(self.print_foreign_item(&**item)); @@ -669,7 +669,7 @@ impl<'a> State<'a> { } pub fn print_opt_lifetime(&mut self, - lifetime: &Option<ast::Lifetime>) -> IoResult<()> { + lifetime: &Option<ast::Lifetime>) -> io::Result<()> { if let Some(l) = *lifetime { try!(self.print_lifetime(&l)); try!(self.nbsp()); @@ -677,7 +677,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> { + pub fn print_type(&mut self, ty: &ast::Ty) -> io::Result<()> { try!(self.maybe_print_comment(ty.span.lo)); try!(self.ibox(0)); match ty.node { @@ -762,7 +762,7 @@ impl<'a> State<'a> { } pub fn print_foreign_item(&mut self, - item: &ast::ForeignItem) -> IoResult<()> { + item: &ast::ForeignItem) -> io::Result<()> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(item.span.lo)); try!(self.print_outer_attributes(&item.attrs)); @@ -791,7 +791,7 @@ impl<'a> State<'a> { } fn print_associated_type(&mut self, typedef: &ast::AssociatedType) - -> IoResult<()> + -> io::Result<()> { try!(self.print_outer_attributes(&typedef.attrs)); try!(self.word_space("type")); @@ -799,7 +799,7 @@ impl<'a> State<'a> { word(&mut self.s, ";") } - fn print_typedef(&mut self, typedef: &ast::Typedef) -> IoResult<()> { + fn print_typedef(&mut self, typedef: &ast::Typedef) -> io::Result<()> { try!(self.word_space("type")); try!(self.print_ident(typedef.ident)); try!(space(&mut self.s)); @@ -809,7 +809,7 @@ impl<'a> State<'a> { } /// Pretty-print an item - pub fn print_item(&mut self, item: &ast::Item) -> IoResult<()> { + pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(item.span.lo)); try!(self.print_outer_attributes(&item.attrs)); @@ -1032,11 +1032,11 @@ impl<'a> State<'a> { self.ann.post(self, NodeItem(item)) } - fn print_trait_ref(&mut self, t: &ast::TraitRef) -> IoResult<()> { + fn print_trait_ref(&mut self, t: &ast::TraitRef) -> io::Result<()> { self.print_path(&t.path, false, 0) } - fn print_formal_lifetime_list(&mut self, lifetimes: &[ast::LifetimeDef]) -> IoResult<()> { + fn print_formal_lifetime_list(&mut self, lifetimes: &[ast::LifetimeDef]) -> io::Result<()> { if !lifetimes.is_empty() { try!(word(&mut self.s, "for<")); let mut comma = false; @@ -1052,7 +1052,7 @@ impl<'a> State<'a> { Ok(()) } - fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) -> IoResult<()> { + fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) -> io::Result<()> { try!(self.print_formal_lifetime_list(&t.bound_lifetimes)); self.print_trait_ref(&t.trait_ref) } @@ -1060,7 +1060,7 @@ impl<'a> State<'a> { pub fn print_enum_def(&mut self, enum_definition: &ast::EnumDef, generics: &ast::Generics, ident: ast::Ident, span: codemap::Span, - visibility: ast::Visibility) -> IoResult<()> { + visibility: ast::Visibility) -> io::Result<()> { try!(self.head(&visibility_qualified(visibility, "enum"))); try!(self.print_ident(ident)); try!(self.print_generics(generics)); @@ -1071,7 +1071,7 @@ impl<'a> State<'a> { pub fn print_variants(&mut self, variants: &[P<ast::Variant>], - span: codemap::Span) -> IoResult<()> { + span: codemap::Span) -> io::Result<()> { try!(self.bopen()); for v in variants { try!(self.space_if_not_bol()); @@ -1086,7 +1086,7 @@ impl<'a> State<'a> { self.bclose(span) } - pub fn print_visibility(&mut self, vis: ast::Visibility) -> IoResult<()> { + pub fn print_visibility(&mut self, vis: ast::Visibility) -> io::Result<()> { match vis { ast::Public => self.word_nbsp("pub"), ast::Inherited => Ok(()) @@ -1097,7 +1097,7 @@ impl<'a> State<'a> { struct_def: &ast::StructDef, generics: &ast::Generics, ident: ast::Ident, - span: codemap::Span) -> IoResult<()> { + span: codemap::Span) -> io::Result<()> { try!(self.print_ident(ident)); try!(self.print_generics(generics)); if ast_util::struct_def_is_tuple_like(struct_def) { @@ -1155,7 +1155,7 @@ impl<'a> State<'a> { /// appropriate macro, transcribe back into the grammar we just parsed from, /// and then pretty-print the resulting AST nodes (so, e.g., we print /// expression arguments as expressions). It can be done! I think. - pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> { + pub fn print_tt(&mut self, tt: &ast::TokenTree) -> io::Result<()> { match *tt { ast::TtToken(_, ref tk) => { try!(word(&mut self.s, &token_to_string(tk))); @@ -1193,7 +1193,7 @@ impl<'a> State<'a> { } } - pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> IoResult<()> { + pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> io::Result<()> { try!(self.ibox(0)); let mut suppress_space = false; for (i, tt) in tts.iter().enumerate() { @@ -1213,7 +1213,7 @@ impl<'a> State<'a> { self.end() } - pub fn print_variant(&mut self, v: &ast::Variant) -> IoResult<()> { + pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> { try!(self.print_visibility(v.node.vis)); match v.node.kind { ast::TupleVariantKind(ref args) => { @@ -1242,7 +1242,7 @@ impl<'a> State<'a> { } } - pub fn print_ty_method(&mut self, m: &ast::TypeMethod) -> IoResult<()> { + pub fn print_ty_method(&mut self, m: &ast::TypeMethod) -> io::Result<()> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(m.span.lo)); try!(self.print_outer_attributes(&m.attrs)); @@ -1256,7 +1256,7 @@ impl<'a> State<'a> { } pub fn print_trait_method(&mut self, - m: &ast::TraitItem) -> IoResult<()> { + m: &ast::TraitItem) -> io::Result<()> { match *m { RequiredMethod(ref ty_m) => self.print_ty_method(ty_m), ProvidedMethod(ref m) => self.print_method(&**m), @@ -1264,14 +1264,14 @@ impl<'a> State<'a> { } } - pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> IoResult<()> { + pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> io::Result<()> { match *ii { MethodImplItem(ref m) => self.print_method(&**m), TypeImplItem(ref td) => self.print_typedef(&**td), } } - pub fn print_method(&mut self, meth: &ast::Method) -> IoResult<()> { + pub fn print_method(&mut self, meth: &ast::Method) -> io::Result<()> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(meth.span.lo)); try!(self.print_outer_attributes(&meth.attrs)); @@ -1310,7 +1310,7 @@ impl<'a> State<'a> { } pub fn print_outer_attributes(&mut self, - attrs: &[ast::Attribute]) -> IoResult<()> { + attrs: &[ast::Attribute]) -> io::Result<()> { let mut count = 0; for attr in attrs { match attr.node.style { @@ -1328,7 +1328,7 @@ impl<'a> State<'a> { } pub fn print_inner_attributes(&mut self, - attrs: &[ast::Attribute]) -> IoResult<()> { + attrs: &[ast::Attribute]) -> io::Result<()> { let mut count = 0; for attr in attrs { match attr.node.style { @@ -1345,7 +1345,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_attribute(&mut self, attr: &ast::Attribute) -> IoResult<()> { + pub fn print_attribute(&mut self, attr: &ast::Attribute) -> io::Result<()> { try!(self.hardbreak_if_not_bol()); try!(self.maybe_print_comment(attr.span.lo)); if attr.node.is_sugared_doc { @@ -1361,7 +1361,7 @@ impl<'a> State<'a> { } - pub fn print_stmt(&mut self, st: &ast::Stmt) -> IoResult<()> { + pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> { try!(self.maybe_print_comment(st.span.lo)); match st.node { ast::StmtDecl(ref decl, _) => { @@ -1395,22 +1395,22 @@ impl<'a> State<'a> { self.maybe_print_trailing_comment(st.span, None) } - pub fn print_block(&mut self, blk: &ast::Block) -> IoResult<()> { + pub fn print_block(&mut self, blk: &ast::Block) -> io::Result<()> { self.print_block_with_attrs(blk, &[]) } - pub fn print_block_unclosed(&mut self, blk: &ast::Block) -> IoResult<()> { + pub fn print_block_unclosed(&mut self, blk: &ast::Block) -> io::Result<()> { self.print_block_unclosed_indent(blk, indent_unit) } pub fn print_block_unclosed_indent(&mut self, blk: &ast::Block, - indented: usize) -> IoResult<()> { + indented: usize) -> io::Result<()> { self.print_block_maybe_unclosed(blk, indented, &[], false) } pub fn print_block_with_attrs(&mut self, blk: &ast::Block, - attrs: &[ast::Attribute]) -> IoResult<()> { + attrs: &[ast::Attribute]) -> io::Result<()> { self.print_block_maybe_unclosed(blk, indent_unit, attrs, true) } @@ -1418,7 +1418,7 @@ impl<'a> State<'a> { blk: &ast::Block, indented: usize, attrs: &[ast::Attribute], - close_box: bool) -> IoResult<()> { + close_box: bool) -> io::Result<()> { match blk.rules { ast::UnsafeBlock(..) => try!(self.word_space("unsafe")), ast::DefaultBlock => () @@ -1444,7 +1444,7 @@ impl<'a> State<'a> { self.ann.post(self, NodeBlock(blk)) } - fn print_else(&mut self, els: Option<&ast::Expr>) -> IoResult<()> { + fn print_else(&mut self, els: Option<&ast::Expr>) -> io::Result<()> { match els { Some(_else) => { match _else.node { @@ -1489,7 +1489,7 @@ impl<'a> State<'a> { } pub fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block, - elseopt: Option<&ast::Expr>) -> IoResult<()> { + elseopt: Option<&ast::Expr>) -> io::Result<()> { try!(self.head("if")); try!(self.print_expr(test)); try!(space(&mut self.s)); @@ -1498,7 +1498,7 @@ impl<'a> State<'a> { } pub fn print_if_let(&mut self, pat: &ast::Pat, expr: &ast::Expr, blk: &ast::Block, - elseopt: Option<&ast::Expr>) -> IoResult<()> { + elseopt: Option<&ast::Expr>) -> io::Result<()> { try!(self.head("if let")); try!(self.print_pat(pat)); try!(space(&mut self.s)); @@ -1510,7 +1510,7 @@ impl<'a> State<'a> { } pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken) - -> IoResult<()> { + -> io::Result<()> { match m.node { // I think it's reasonable to hide the ctxt here: ast::MacInvocTT(ref pth, ref tts, _) => { @@ -1532,13 +1532,13 @@ impl<'a> State<'a> { } - fn print_call_post(&mut self, args: &[P<ast::Expr>]) -> IoResult<()> { + fn print_call_post(&mut self, args: &[P<ast::Expr>]) -> io::Result<()> { try!(self.popen()); try!(self.commasep_exprs(Inconsistent, args)); self.pclose() } - pub fn print_expr_maybe_paren(&mut self, expr: &ast::Expr) -> IoResult<()> { + pub fn print_expr_maybe_paren(&mut self, expr: &ast::Expr) -> io::Result<()> { let needs_par = needs_parentheses(expr); if needs_par { try!(self.popen()); @@ -1552,7 +1552,7 @@ impl<'a> State<'a> { fn print_expr_box(&mut self, place: &Option<P<ast::Expr>>, - expr: &ast::Expr) -> IoResult<()> { + expr: &ast::Expr) -> io::Result<()> { try!(word(&mut self.s, "box")); try!(word(&mut self.s, "(")); try!(place.as_ref().map_or(Ok(()), |e|self.print_expr(&**e))); @@ -1560,7 +1560,7 @@ impl<'a> State<'a> { self.print_expr(expr) } - fn print_expr_vec(&mut self, exprs: &[P<ast::Expr>]) -> IoResult<()> { + fn print_expr_vec(&mut self, exprs: &[P<ast::Expr>]) -> io::Result<()> { try!(self.ibox(indent_unit)); try!(word(&mut self.s, "[")); try!(self.commasep_exprs(Inconsistent, &exprs[..])); @@ -1570,7 +1570,7 @@ impl<'a> State<'a> { fn print_expr_repeat(&mut self, element: &ast::Expr, - count: &ast::Expr) -> IoResult<()> { + count: &ast::Expr) -> io::Result<()> { try!(self.ibox(indent_unit)); try!(word(&mut self.s, "[")); try!(self.print_expr(element)); @@ -1583,7 +1583,7 @@ impl<'a> State<'a> { fn print_expr_struct(&mut self, path: &ast::Path, fields: &[ast::Field], - wth: &Option<P<ast::Expr>>) -> IoResult<()> { + wth: &Option<P<ast::Expr>>) -> io::Result<()> { try!(self.print_path(path, true, 0)); if !(fields.is_empty() && wth.is_none()) { try!(word(&mut self.s, "{")); @@ -1616,7 +1616,7 @@ impl<'a> State<'a> { Ok(()) } - fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>]) -> IoResult<()> { + fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>]) -> io::Result<()> { try!(self.popen()); try!(self.commasep_exprs(Inconsistent, &exprs[..])); if exprs.len() == 1 { @@ -1627,7 +1627,7 @@ impl<'a> State<'a> { fn print_expr_call(&mut self, func: &ast::Expr, - args: &[P<ast::Expr>]) -> IoResult<()> { + args: &[P<ast::Expr>]) -> io::Result<()> { try!(self.print_expr_maybe_paren(func)); self.print_call_post(args) } @@ -1635,7 +1635,7 @@ impl<'a> State<'a> { fn print_expr_method_call(&mut self, ident: ast::SpannedIdent, tys: &[P<ast::Ty>], - args: &[P<ast::Expr>]) -> IoResult<()> { + args: &[P<ast::Expr>]) -> io::Result<()> { let base_args = &args[1..]; try!(self.print_expr(&*args[0])); try!(word(&mut self.s, ".")); @@ -1652,7 +1652,7 @@ impl<'a> State<'a> { fn print_expr_binary(&mut self, op: ast::BinOp, lhs: &ast::Expr, - rhs: &ast::Expr) -> IoResult<()> { + rhs: &ast::Expr) -> io::Result<()> { try!(self.print_expr(lhs)); try!(space(&mut self.s)); try!(self.word_space(ast_util::binop_to_string(op.node))); @@ -1661,20 +1661,20 @@ impl<'a> State<'a> { fn print_expr_unary(&mut self, op: ast::UnOp, - expr: &ast::Expr) -> IoResult<()> { + expr: &ast::Expr) -> io::Result<()> { try!(word(&mut self.s, ast_util::unop_to_string(op))); self.print_expr_maybe_paren(expr) } fn print_expr_addr_of(&mut self, mutability: ast::Mutability, - expr: &ast::Expr) -> IoResult<()> { + expr: &ast::Expr) -> io::Result<()> { try!(word(&mut self.s, "&")); try!(self.print_mutability(mutability)); self.print_expr_maybe_paren(expr) } - pub fn print_expr(&mut self, expr: &ast::Expr) -> IoResult<()> { + pub fn print_expr(&mut self, expr: &ast::Expr) -> io::Result<()> { try!(self.maybe_print_comment(expr.span.lo)); try!(self.ibox(indent_unit)); try!(self.ann.pre(self, NodeExpr(expr))); @@ -1958,7 +1958,7 @@ impl<'a> State<'a> { self.end() } - pub fn print_local_decl(&mut self, loc: &ast::Local) -> IoResult<()> { + pub fn print_local_decl(&mut self, loc: &ast::Local) -> io::Result<()> { try!(self.print_pat(&*loc.pat)); if let Some(ref ty) = loc.ty { try!(self.word_space(":")); @@ -1967,7 +1967,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_decl(&mut self, decl: &ast::Decl) -> IoResult<()> { + pub fn print_decl(&mut self, decl: &ast::Decl) -> io::Result<()> { try!(self.maybe_print_comment(decl.span.lo)); match decl.node { ast::DeclLocal(ref loc) => { @@ -1989,7 +1989,7 @@ impl<'a> State<'a> { } } - pub fn print_ident(&mut self, ident: ast::Ident) -> IoResult<()> { + pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> { if self.encode_idents_with_hygiene { let encoded = ident.encode_with_hygiene(); try!(word(&mut self.s, &encoded[..])) @@ -1999,17 +1999,17 @@ impl<'a> State<'a> { self.ann.post(self, NodeIdent(&ident)) } - pub fn print_usize(&mut self, i: usize) -> IoResult<()> { + pub fn print_usize(&mut self, i: usize) -> io::Result<()> { word(&mut self.s, &i.to_string()) } - pub fn print_name(&mut self, name: ast::Name) -> IoResult<()> { + pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> { try!(word(&mut self.s, &token::get_name(name))); self.ann.post(self, NodeName(&name)) } pub fn print_for_decl(&mut self, loc: &ast::Local, - coll: &ast::Expr) -> IoResult<()> { + coll: &ast::Expr) -> io::Result<()> { try!(self.print_local_decl(loc)); try!(space(&mut self.s)); try!(self.word_space("in")); @@ -2020,7 +2020,7 @@ impl<'a> State<'a> { path: &ast::Path, colons_before_params: bool, depth: usize) - -> IoResult<()> + -> io::Result<()> { try!(self.maybe_print_comment(path.span.lo)); @@ -2044,7 +2044,7 @@ impl<'a> State<'a> { path: &ast::Path, qself: &ast::QSelf, colons_before_params: bool) - -> IoResult<()> + -> io::Result<()> { try!(word(&mut self.s, "<")); try!(self.print_type(&qself.ty)); @@ -2064,7 +2064,7 @@ impl<'a> State<'a> { fn print_path_parameters(&mut self, parameters: &ast::PathParameters, colons_before_params: bool) - -> IoResult<()> + -> io::Result<()> { if parameters.is_empty() { return Ok(()); @@ -2134,7 +2134,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_pat(&mut self, pat: &ast::Pat) -> IoResult<()> { + pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> { try!(self.maybe_print_comment(pat.span.lo)); try!(self.ann.pre(self, NodePat(pat))); /* Pat isn't normalized, but the beauty of it @@ -2253,7 +2253,7 @@ impl<'a> State<'a> { self.ann.post(self, NodePat(pat)) } - fn print_arm(&mut self, arm: &ast::Arm) -> IoResult<()> { + fn print_arm(&mut self, arm: &ast::Arm) -> io::Result<()> { // I have no idea why this check is necessary, but here it // is :( if arm.attrs.is_empty() { @@ -2302,7 +2302,7 @@ impl<'a> State<'a> { // Returns whether it printed anything fn print_explicit_self(&mut self, explicit_self: &ast::ExplicitSelf_, - mutbl: ast::Mutability) -> IoResult<bool> { + mutbl: ast::Mutability) -> io::Result<bool> { try!(self.print_mutability(mutbl)); match *explicit_self { ast::SelfStatic => { return Ok(false); } @@ -2331,7 +2331,7 @@ impl<'a> State<'a> { name: ast::Ident, generics: &ast::Generics, opt_explicit_self: Option<&ast::ExplicitSelf_>, - vis: ast::Visibility) -> IoResult<()> { + vis: ast::Visibility) -> io::Result<()> { try!(self.head("")); try!(self.print_fn_header_info(unsafety, abi, vis)); try!(self.nbsp()); @@ -2343,7 +2343,7 @@ impl<'a> State<'a> { pub fn print_fn_args(&mut self, decl: &ast::FnDecl, opt_explicit_self: Option<&ast::ExplicitSelf_>) - -> IoResult<()> { + -> io::Result<()> { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. try!(self.rbox(0, Inconsistent)); @@ -2376,7 +2376,7 @@ impl<'a> State<'a> { pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl, opt_explicit_self: Option<&ast::ExplicitSelf_>) - -> IoResult<()> { + -> io::Result<()> { try!(self.popen()); try!(self.print_fn_args(decl, opt_explicit_self)); if decl.variadic { @@ -2390,7 +2390,7 @@ impl<'a> State<'a> { pub fn print_fn_block_args( &mut self, decl: &ast::FnDecl) - -> IoResult<()> { + -> io::Result<()> { try!(word(&mut self.s, "|")); try!(self.print_fn_args(decl, None)); try!(word(&mut self.s, "|")); @@ -2415,7 +2415,7 @@ impl<'a> State<'a> { } pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause) - -> IoResult<()> { + -> io::Result<()> { match capture_clause { ast::CaptureByValue => self.word_space("move"), ast::CaptureByRef => Ok(()), @@ -2425,7 +2425,7 @@ impl<'a> State<'a> { pub fn print_bounds(&mut self, prefix: &str, bounds: &[ast::TyParamBound]) - -> IoResult<()> { + -> io::Result<()> { if !bounds.is_empty() { try!(word(&mut self.s, prefix)); let mut first = true; @@ -2458,14 +2458,14 @@ impl<'a> State<'a> { pub fn print_lifetime(&mut self, lifetime: &ast::Lifetime) - -> IoResult<()> + -> io::Result<()> { self.print_name(lifetime.name) } pub fn print_lifetime_def(&mut self, lifetime: &ast::LifetimeDef) - -> IoResult<()> + -> io::Result<()> { try!(self.print_lifetime(&lifetime.lifetime)); let mut sep = ":"; @@ -2479,7 +2479,7 @@ impl<'a> State<'a> { pub fn print_generics(&mut self, generics: &ast::Generics) - -> IoResult<()> + -> io::Result<()> { let total = generics.lifetimes.len() + generics.ty_params.len(); if total == 0 { @@ -2508,7 +2508,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_ty_param(&mut self, param: &ast::TyParam) -> IoResult<()> { + pub fn print_ty_param(&mut self, param: &ast::TyParam) -> io::Result<()> { try!(self.print_ident(param.ident)); try!(self.print_bounds(":", ¶m.bounds)); match param.default { @@ -2522,7 +2522,7 @@ impl<'a> State<'a> { } pub fn print_where_clause(&mut self, generics: &ast::Generics) - -> IoResult<()> { + -> io::Result<()> { if generics.where_clause.predicates.len() == 0 { return Ok(()) } @@ -2573,7 +2573,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_meta_item(&mut self, item: &ast::MetaItem) -> IoResult<()> { + pub fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> { try!(self.ibox(indent_unit)); match item.node { ast::MetaWord(ref name) => { @@ -2596,7 +2596,7 @@ impl<'a> State<'a> { self.end() } - pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> IoResult<()> { + pub fn print_view_path(&mut self, vp: &ast::ViewPath) -> io::Result<()> { match vp.node { ast::ViewPathSimple(ident, ref path) => { try!(self.print_path(path, false, 0)); @@ -2640,19 +2640,19 @@ impl<'a> State<'a> { } pub fn print_mutability(&mut self, - mutbl: ast::Mutability) -> IoResult<()> { + mutbl: ast::Mutability) -> io::Result<()> { match mutbl { ast::MutMutable => self.word_nbsp("mut"), ast::MutImmutable => Ok(()), } } - pub fn print_mt(&mut self, mt: &ast::MutTy) -> IoResult<()> { + pub fn print_mt(&mut self, mt: &ast::MutTy) -> io::Result<()> { try!(self.print_mutability(mt.mutbl)); self.print_type(&*mt.ty) } - pub fn print_arg(&mut self, input: &ast::Arg) -> IoResult<()> { + pub fn print_arg(&mut self, input: &ast::Arg) -> io::Result<()> { try!(self.ibox(indent_unit)); match input.ty.node { ast::TyInfer => try!(self.print_pat(&*input.pat)), @@ -2675,7 +2675,7 @@ impl<'a> State<'a> { self.end() } - pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> IoResult<()> { + pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> io::Result<()> { if let ast::DefaultReturn(..) = decl.output { return Ok(()); } @@ -2705,7 +2705,7 @@ impl<'a> State<'a> { id: Option<ast::Ident>, generics: &ast::Generics, opt_explicit_self: Option<&ast::ExplicitSelf_>) - -> IoResult<()> { + -> io::Result<()> { try!(self.ibox(indent_unit)); try!(self.print_fn_header_info(Some(unsafety), abi, ast::Inherited)); @@ -2726,7 +2726,7 @@ impl<'a> State<'a> { pub fn maybe_print_trailing_comment(&mut self, span: codemap::Span, next_pos: Option<BytePos>) - -> IoResult<()> { + -> io::Result<()> { let cm = match self.cm { Some(cm) => cm, _ => return Ok(()) @@ -2749,7 +2749,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_remaining_comments(&mut self) -> IoResult<()> { + pub fn print_remaining_comments(&mut self) -> io::Result<()> { // If there aren't any remaining comments, then we need to manually // make sure there is a line break at the end. if self.next_comment().is_none() { @@ -2767,7 +2767,7 @@ impl<'a> State<'a> { Ok(()) } - pub fn print_literal(&mut self, lit: &ast::Lit) -> IoResult<()> { + pub fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> { try!(self.maybe_print_comment(lit.span.lo)); match self.next_lit(lit.span.lo) { Some(ref ltrl) => { @@ -2848,7 +2848,7 @@ impl<'a> State<'a> { } } - pub fn maybe_print_comment(&mut self, pos: BytePos) -> IoResult<()> { + pub fn maybe_print_comment(&mut self, pos: BytePos) -> io::Result<()> { loop { match self.next_comment() { Some(ref cmnt) => { @@ -2864,7 +2864,7 @@ impl<'a> State<'a> { } pub fn print_comment(&mut self, - cmnt: &comments::Comment) -> IoResult<()> { + cmnt: &comments::Comment) -> io::Result<()> { match cmnt.style { comments::Mixed => { assert_eq!(cmnt.lines.len(), 1); @@ -2915,7 +2915,7 @@ impl<'a> State<'a> { } pub fn print_string(&mut self, st: &str, - style: ast::StrStyle) -> IoResult<()> { + style: ast::StrStyle) -> io::Result<()> { let st = match style { ast::CookedStr => { (format!("\"{}\"", st.escape_default())) @@ -2943,7 +2943,7 @@ impl<'a> State<'a> { } pub fn print_opt_unsafety(&mut self, - opt_unsafety: Option<ast::Unsafety>) -> IoResult<()> { + opt_unsafety: Option<ast::Unsafety>) -> io::Result<()> { match opt_unsafety { Some(unsafety) => self.print_unsafety(unsafety), None => Ok(()) @@ -2952,7 +2952,7 @@ impl<'a> State<'a> { pub fn print_opt_abi_and_extern_if_nondefault(&mut self, opt_abi: Option<abi::Abi>) - -> IoResult<()> { + -> io::Result<()> { match opt_abi { Some(abi::Rust) => Ok(()), Some(abi) => { @@ -2964,7 +2964,7 @@ impl<'a> State<'a> { } pub fn print_extern_opt_abi(&mut self, - opt_abi: Option<abi::Abi>) -> IoResult<()> { + opt_abi: Option<abi::Abi>) -> io::Result<()> { match opt_abi { Some(abi) => { try!(self.word_nbsp("extern")); @@ -2977,7 +2977,7 @@ impl<'a> State<'a> { pub fn print_fn_header_info(&mut self, opt_unsafety: Option<ast::Unsafety>, abi: abi::Abi, - vis: ast::Visibility) -> IoResult<()> { + vis: ast::Visibility) -> io::Result<()> { try!(word(&mut self.s, &visibility_qualified(vis, ""))); try!(self.print_opt_unsafety(opt_unsafety)); @@ -2989,7 +2989,7 @@ impl<'a> State<'a> { word(&mut self.s, "fn") } - pub fn print_unsafety(&mut self, s: ast::Unsafety) -> IoResult<()> { + pub fn print_unsafety(&mut self, s: ast::Unsafety) -> io::Result<()> { match s { ast::Unsafety::Normal => Ok(()), ast::Unsafety::Unsafe => self.word_nbsp("unsafe"), |
