From c765a8e7ad314651b92ff860cda0159c79dbec6e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 1 Feb 2014 11:24:42 -0800 Subject: Fixing remaining warnings and errors throughout --- src/libsyntax/parse/token.rs | 4 +- src/libsyntax/print/pp.rs | 67 ++++++++----- src/libsyntax/print/pprust.rs | 218 +++++++++++------------------------------- 3 files changed, 99 insertions(+), 190 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 6d2acd3d803..f1dd844fc7c 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -588,8 +588,8 @@ impl BytesContainer for InternedString { } impl fmt::Show for InternedString { - fn fmt(obj: &InternedString, f: &mut fmt::Formatter) { - write!(f.buf, "{}", obj.string.as_slice()); + fn fmt(obj: &InternedString, f: &mut fmt::Formatter) -> fmt::Result { + write!(f.buf, "{}", obj.string.as_slice()) } } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index bb287c0f5f8..f6952261723 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -299,19 +299,34 @@ impl Printer { if !self.scan_stack_empty { self.check_stack(0); let left = self.token[self.left].clone(); - self.advance_left(left, self.size[self.left]); + if_ok!(self.advance_left(left, self.size[self.left])); } - Begin(b) => { - if self.scan_stack_empty { - self.left_total = 1; - self.right_total = 1; - self.left = 0u; - self.right = 0u; - } else { self.advance_right(); } - debug!("pp Begin({})/buffer ~[{},{}]", - b.offset, self.left, self.right); + self.indent(0); + Ok(()) + } + Begin(b) => { + if self.scan_stack_empty { + self.left_total = 1; + self.right_total = 1; + self.left = 0u; + self.right = 0u; + } else { self.advance_right(); } + debug!("pp Begin({})/buffer ~[{},{}]", + b.offset, self.left, self.right); + self.token[self.right] = t; + self.size[self.right] = -self.right_total; + self.scan_push(self.right); + Ok(()) + } + End => { + if self.scan_stack_empty { + debug!("pp End/print ~[{},{}]", self.left, self.right); + self.print(t, 0) + } else { + debug!("pp End/buffer ~[{},{}]", self.left, self.right); + self.advance_right(); self.token[self.right] = t; - self.size[self.right] = -self.right_total; + self.size[self.right] = -1; self.scan_push(self.right); Ok(()) } @@ -330,12 +345,13 @@ impl Printer { self.token[self.right] = t; self.size[self.right] = -self.right_total; self.right_total += b.blank_space; + Ok(()) } String(ref s, len) => { if self.scan_stack_empty { debug!("pp String('{}')/print ~[{},{}]", *s, self.left, self.right); - self.print(t.clone(), len); + self.print(t.clone(), len) } else { debug!("pp String('{}')/buffer ~[{},{}]", *s, self.left, self.right); @@ -343,8 +359,9 @@ impl Printer { self.token[self.right] = t.clone(); self.size[self.right] = len; self.right_total += len; - self.check_stream(); + self.check_stream() } + } } } pub fn check_stream(&mut self) -> io::IoResult<()> { @@ -360,8 +377,10 @@ impl Printer { } } let left = self.token[self.left].clone(); - self.advance_left(left, self.size[self.left]); - if self.left != self.right { self.check_stream(); } + if_ok!(self.advance_left(left, self.size[self.left])); + if self.left != self.right { + if_ok!(self.check_stream()); + } } Ok(()) } @@ -405,7 +424,7 @@ impl Printer { debug!("advnce_left ~[{},{}], sizeof({})={}", self.left, self.right, self.left, L); if L >= 0 { - self.print(x.clone(), L); + let ret = self.print(x.clone(), L); match x { Break(b) => self.left_total += b.blank_space, String(_, len) => { @@ -417,7 +436,7 @@ impl Printer { self.left += 1u; self.left %= self.buf_len; let left = self.token[self.left].clone(); - self.advance_left(left, self.size[self.left]); + if_ok!(self.advance_left(left, self.size[self.left])); } ret } else { @@ -477,7 +496,7 @@ impl Printer { } write!(self.out, "{}", s) } - pub fn print(&mut self, x: Token, L: int) { + pub fn print(&mut self, x: Token, L: int) -> io::IoResult<()> { debug!("print {} {} (remaining line space={})", tok_str(x.clone()), L, self.space); debug!("{}", buf_str(self.token.clone(), @@ -587,16 +606,16 @@ pub fn end(p: &mut Printer) -> io::IoResult<()> { p.pretty_print(End) } pub fn eof(p: &mut Printer) -> io::IoResult<()> { p.pretty_print(Eof) } -pub fn word(p: &mut Printer, wrd: &str) { - p.pretty_print(String(/* bad */ wrd.to_str(), wrd.len() as int)); +pub fn word(p: &mut Printer, wrd: &str) -> io::IoResult<()> { + p.pretty_print(String(/* bad */ wrd.to_str(), wrd.len() as int)) } -pub fn huge_word(p: &mut Printer, wrd: &str) { - p.pretty_print(String(/* bad */ wrd.to_str(), SIZE_INFINITY)); +pub fn huge_word(p: &mut Printer, wrd: &str) -> io::IoResult<()> { + p.pretty_print(String(/* bad */ wrd.to_str(), SIZE_INFINITY)) } -pub fn zero_word(p: &mut Printer, wrd: &str) { - p.pretty_print(String(/* bad */ wrd.to_str(), 0)); +pub fn zero_word(p: &mut Printer, wrd: &str) -> io::IoResult<()> { + p.pretty_print(String(/* bad */ wrd.to_str(), 0)) } pub fn spaces(p: &mut Printer, n: uint) -> io::IoResult<()> { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f0ef5014ca8..e291583d121 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -964,11 +964,7 @@ pub fn print_attribute(s: &mut State, attr: &ast::Attribute) -> io::IoResult<()> if_ok!(maybe_print_comment(s, attr.span.lo)); if attr.node.is_sugared_doc { let comment = attr.value_str().unwrap(); -<<<<<<< HEAD - word(&mut s.s, comment.get()); -======= - if_ok!(word(&mut s.s, comment)); ->>>>>>> syntax: Remove io_error usage + if_ok!(word(&mut s.s, comment.get())); } else { if_ok!(word(&mut s.s, "#[")); if_ok!(print_meta_item(s, attr.meta())); @@ -1139,24 +1135,7 @@ pub fn print_mac(s: &mut State, m: &ast::Mac) -> io::IoResult<()> { } } -<<<<<<< HEAD -pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) { -======= -pub fn print_vstore(s: &mut State, t: ast::Vstore) -> io::IoResult<()> { - match t { - ast::VstoreFixed(Some(i)) => word(&mut s.s, format!("{}", i)), - ast::VstoreFixed(None) => word(&mut s.s, "_"), - ast::VstoreUniq => word(&mut s.s, "~"), - ast::VstoreBox => word(&mut s.s, "@"), - ast::VstoreSlice(ref r) => { - if_ok!(word(&mut s.s, "&")); - print_opt_lifetime(s, r) - } - } -} - pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()> { ->>>>>>> syntax: Remove io_error usage match t { ast::ExprVstoreUniq => word(&mut s.s, "~"), ast::ExprVstoreSlice => word(&mut s.s, "&"), @@ -1557,51 +1536,27 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { } else { if_ok!(word(&mut s.s, "asm!")); } -<<<<<<< HEAD - popen(s); - print_string(s, a.asm.get(), a.asm_str_style); - word_space(s, ":"); - for &(ref co, o) in a.outputs.iter() { - print_string(s, co.get(), ast::CookedStr); - popen(s); - print_expr(s, o); - pclose(s); - word_space(s, ","); - } - word_space(s, ":"); - for &(ref co, o) in a.inputs.iter() { - print_string(s, co.get(), ast::CookedStr); - popen(s); - print_expr(s, o); - pclose(s); - word_space(s, ","); - } - word_space(s, ":"); - print_string(s, a.clobbers.get(), ast::CookedStr); - pclose(s); -======= if_ok!(popen(s)); - if_ok!(print_string(s, a.asm, a.asm_str_style)); + if_ok!(print_string(s, a.asm.get(), a.asm_str_style)); if_ok!(word_space(s, ":")); - for &(co, o) in a.outputs.iter() { - if_ok!(print_string(s, co, ast::CookedStr)); + for &(ref co, o) in a.outputs.iter() { + if_ok!(print_string(s, co.get(), ast::CookedStr)); if_ok!(popen(s)); if_ok!(print_expr(s, o)); if_ok!(pclose(s)); if_ok!(word_space(s, ",")); } if_ok!(word_space(s, ":")); - for &(co, o) in a.inputs.iter() { - if_ok!(print_string(s, co, ast::CookedStr)); + for &(ref co, o) in a.inputs.iter() { + if_ok!(print_string(s, co.get(), ast::CookedStr)); if_ok!(popen(s)); if_ok!(print_expr(s, o)); if_ok!(pclose(s)); if_ok!(word_space(s, ",")); } if_ok!(word_space(s, ":")); - if_ok!(print_string(s, a.clobbers, ast::CookedStr)); + if_ok!(print_string(s, a.clobbers.get(), ast::CookedStr)); if_ok!(pclose(s)); ->>>>>>> syntax: Remove io_error usage } ast::ExprMac(ref m) => if_ok!(print_mac(s, m)), ast::ExprParen(e) => { @@ -1659,23 +1614,14 @@ pub fn print_decl(s: &mut State, decl: &ast::Decl) -> io::IoResult<()> { } } -<<<<<<< HEAD -pub fn print_ident(s: &mut State, ident: ast::Ident) { - let string = token::get_ident(ident.name); - word(&mut s.s, string.get()); -} - -pub fn print_name(s: &mut State, name: ast::Name) { - let string = token::get_ident(name); - word(&mut s.s, string.get()); -======= pub fn print_ident(s: &mut State, ident: ast::Ident) -> io::IoResult<()> { - word(&mut s.s, ident_to_str(&ident)) + let string = token::get_ident(ident.name); + word(&mut s.s, string.get()) } pub fn print_name(s: &mut State, name: ast::Name) -> io::IoResult<()> { - word(&mut s.s, interner_get(name)) ->>>>>>> syntax: Remove io_error usage + let string = token::get_ident(name); + word(&mut s.s, string.get()) } pub fn print_for_decl(s: &mut State, loc: &ast::Local, @@ -2088,38 +2034,23 @@ pub fn print_generics(s: &mut State, pub fn print_meta_item(s: &mut State, item: &ast::MetaItem) -> io::IoResult<()> { if_ok!(ibox(s, indent_unit)); match item.node { -<<<<<<< HEAD - ast::MetaWord(ref name) => word(&mut s.s, name.get()), - ast::MetaNameValue(ref name, ref value) => { - word_space(s, name.get()); - word_space(s, "="); - print_literal(s, value); - } - ast::MetaList(ref name, ref items) => { - word(&mut s.s, name.get()); - popen(s); - commasep(s, - Consistent, - items.as_slice(), - |p, &i| print_meta_item(p, i)); - pclose(s); -======= - ast::MetaWord(name) => { if_ok!(word(&mut s.s, name)); } - ast::MetaNameValue(name, value) => { - if_ok!(word_space(s, name)); - if_ok!(word_space(s, "=")); - if_ok!(print_literal(s, &value)); - } - ast::MetaList(name, ref items) => { - if_ok!(word(&mut s.s, name)); - if_ok!(popen(s)); - if_ok!(commasep(s, - Consistent, - items.as_slice(), - |p, &i| print_meta_item(p, i))); - if_ok!(pclose(s)); ->>>>>>> syntax: Remove io_error usage - } + ast::MetaWord(ref name) => { + if_ok!(word(&mut s.s, name.get())); + } + ast::MetaNameValue(ref name, ref value) => { + if_ok!(word_space(s, name.get())); + if_ok!(word_space(s, "=")); + if_ok!(print_literal(s, value)); + } + ast::MetaList(ref name, ref items) => { + if_ok!(word(&mut s.s, name.get())); + if_ok!(popen(s)); + if_ok!(commasep(s, + Consistent, + items.as_slice(), + |p, &i| print_meta_item(p, i))); + if_ok!(pclose(s)); + } } end(s) } @@ -2171,17 +2102,10 @@ pub fn print_view_item(s: &mut State, item: &ast::ViewItem) -> io::IoResult<()> if_ok!(head(s, "extern mod")); if_ok!(print_ident(s, id)); for &(ref p, style) in optional_path.iter() { -<<<<<<< HEAD - space(&mut s.s); - word(&mut s.s, "="); - space(&mut s.s); - print_string(s, p.get(), style); -======= if_ok!(space(&mut s.s)); if_ok!(word(&mut s.s, "=")); if_ok!(space(&mut s.s)); - if_ok!(print_string(s, *p, style)); ->>>>>>> syntax: Remove io_error usage + if_ok!(print_string(s, p.get(), style)); } } @@ -2373,88 +2297,54 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) -> io::IoResult<()> { _ => () } match lit.node { -<<<<<<< HEAD ast::LitStr(ref st, style) => print_string(s, st.get(), style), ast::LitChar(ch) => { let mut res = ~"'"; char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); res.push_char('\''); - word(&mut s.s, res); + word(&mut s.s, res) } ast::LitInt(i, t) => { if i < 0_i64 { word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u) - + ast_util::int_ty_to_str(t)); + + ast_util::int_ty_to_str(t)) } else { word(&mut s.s, (i as u64).to_str_radix(10u) - + ast_util::int_ty_to_str(t)); -======= - ast::LitStr(st, style) => print_string(s, st, style), - ast::LitChar(ch) => { - let mut res = ~"'"; - char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); - res.push_char('\''); - word(&mut s.s, res) - } - ast::LitInt(i, t) => { - if i < 0_i64 { - word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u) - + ast_util::int_ty_to_str(t)) - } else { - word(&mut s.s, (i as u64).to_str_radix(10u) - + ast_util::int_ty_to_str(t)) - } ->>>>>>> syntax: Remove io_error usage - } - ast::LitUint(u, t) => { - word(&mut s.s, u.to_str_radix(10u) + ast_util::uint_ty_to_str(t)) + + ast_util::int_ty_to_str(t)) } - ast::LitIntUnsuffixed(i) => { - if i < 0_i64 { - word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u)) - } else { - word(&mut s.s, (i as u64).to_str_radix(10u)) - } - } - ast::LitFloat(f, t) => { - word(&mut s.s, f.to_owned() + ast_util::float_ty_to_str(t)) - } - ast::LitFloatUnsuffixed(f) => word(&mut s.s, f), - ast::LitNil => word(&mut s.s, "()"), - ast::LitBool(val) => { - if val { word(&mut s.s, "true") } else { word(&mut s.s, "false") } - } - ast::LitBinary(arr) => { - if_ok!(ibox(s, indent_unit)); - if_ok!(word(&mut s.s, "[")); - if_ok!(commasep_cmnt(s, Inconsistent, arr, - |s, u| word(&mut s.s, format!("{}", *u)), - |_| lit.span)); - if_ok!(word(&mut s.s, "]")); - end(s) + } + ast::LitUint(u, t) => { + word(&mut s.s, + u.to_str_radix(10u) + + ast_util::uint_ty_to_str(t)) + } + ast::LitIntUnsuffixed(i) => { + if i < 0_i64 { + word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u)) + } else { + word(&mut s.s, (i as u64).to_str_radix(10u)) } -<<<<<<< HEAD } + ast::LitFloat(ref f, t) => { - word(&mut s.s, f.get() + ast_util::float_ty_to_str(t)); + word(&mut s.s, f.get() + ast_util::float_ty_to_str(t)) } ast::LitFloatUnsuffixed(ref f) => word(&mut s.s, f.get()), ast::LitNil => word(&mut s.s, "()"), ast::LitBool(val) => { - if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); } + if val { word(&mut s.s, "true") } else { word(&mut s.s, "false") } } ast::LitBinary(ref arr) => { - ibox(s, indent_unit); - word(&mut s.s, "["); - commasep_cmnt(s, Inconsistent, *arr.borrow(), |s, u| word(&mut s.s, format!("{}", *u)), - |_| lit.span); - word(&mut s.s, "]"); - end(s); - } -======= ->>>>>>> syntax: Remove io_error usage + if_ok!(ibox(s, indent_unit)); + if_ok!(word(&mut s.s, "[")); + if_ok!(commasep_cmnt(s, Inconsistent, *arr.borrow(), + |s, u| word(&mut s.s, format!("{}", *u)), + |_| lit.span)); + if_ok!(word(&mut s.s, "]")); + end(s) + } } } -- cgit 1.4.1-3-g733a5