From 0f02309e4b0ea05ee905205278fb6d131341c41f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 22 Mar 2016 22:01:37 -0500 Subject: try! -> ? Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry --- src/libsyntax/ast.rs | 4 +- src/libsyntax/codemap.rs | 75 +- src/libsyntax/diagnostics/metadata.rs | 8 +- src/libsyntax/errors/emitter.rs | 76 +- src/libsyntax/ext/tt/macro_parser.rs | 4 +- src/libsyntax/parse/attr.rs | 16 +- src/libsyntax/parse/parser.rs | 978 +++++++++---------- src/libsyntax/parse/token.rs | 2 +- src/libsyntax/print/pp.rs | 10 +- src/libsyntax/print/pprust.rs | 1720 ++++++++++++++++----------------- 10 files changed, 1441 insertions(+), 1452 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c830fed5db9..ac1a07d1cb5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -83,7 +83,7 @@ impl Encodable for Name { impl Decodable for Name { fn decode(d: &mut D) -> Result { - Ok(token::intern(&try!(d.read_str())[..])) + Ok(token::intern(&d.read_str()?[..])) } } @@ -152,7 +152,7 @@ impl Encodable for Ident { impl Decodable for Ident { fn decode(d: &mut D) -> Result { - Ok(Ident::with_empty_ctxt(try!(Name::decode(d)))) + Ok(Ident::with_empty_ctxt(Name::decode(d)?)) } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index c7f8a56135d..80b806b7b50 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -86,7 +86,7 @@ impl Encodable for BytePos { impl Decodable for BytePos { fn decode(d: &mut D) -> Result { - Ok(BytePos(try!{ d.read_u32() })) + Ok(BytePos(d.read_u32()?)) } } @@ -203,9 +203,9 @@ pub struct Spanned { impl Encodable for Span { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_struct("Span", 2, |s| { - try!(s.emit_struct_field("lo", 0, |s| { + s.emit_struct_field("lo", 0, |s| { self.lo.encode(s) - })); + })?; s.emit_struct_field("hi", 1, |s| { self.hi.encode(s) @@ -217,13 +217,13 @@ impl Encodable for Span { impl Decodable for Span { fn decode(d: &mut D) -> Result { d.read_struct("Span", 2, |d| { - let lo = try!(d.read_struct_field("lo", 0, |d| { + let lo = d.read_struct_field("lo", 0, |d| { BytePos::decode(d) - })); + })?; - let hi = try!(d.read_struct_field("hi", 1, |d| { + let hi = d.read_struct_field("hi", 1, |d| { BytePos::decode(d) - })); + })?; Ok(mk_sp(lo, hi)) }) @@ -526,13 +526,13 @@ pub struct FileMap { impl Encodable for FileMap { fn encode(&self, s: &mut S) -> Result<(), S::Error> { s.emit_struct("FileMap", 5, |s| { - try! { s.emit_struct_field("name", 0, |s| self.name.encode(s)) }; - try! { s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s)) }; - try! { s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s)) }; - try! { s.emit_struct_field("lines", 3, |s| { + s.emit_struct_field("name", 0, |s| self.name.encode(s))?; + s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s))?; + s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s))?; + s.emit_struct_field("lines", 3, |s| { let lines = self.lines.borrow(); // store the length - try! { s.emit_u32(lines.len() as u32) }; + s.emit_u32(lines.len() as u32)?; if !lines.is_empty() { // In order to preserve some space, we exploit the fact that @@ -557,25 +557,24 @@ impl Encodable for FileMap { }; // Encode the number of bytes used per diff. - try! { bytes_per_diff.encode(s) }; + bytes_per_diff.encode(s)?; // Encode the first element. - try! { lines[0].encode(s) }; + lines[0].encode(s)?; let diff_iter = (&lines[..]).windows(2) .map(|w| (w[1] - w[0])); match bytes_per_diff { - 1 => for diff in diff_iter { try! { (diff.0 as u8).encode(s) } }, - 2 => for diff in diff_iter { try! { (diff.0 as u16).encode(s) } }, - 4 => for diff in diff_iter { try! { diff.0.encode(s) } }, + 1 => for diff in diff_iter { (diff.0 as u8).encode(s)? }, + 2 => for diff in diff_iter { (diff.0 as u16).encode(s)? }, + 4 => for diff in diff_iter { diff.0.encode(s)? }, _ => unreachable!() } } Ok(()) - }) - }; + })?; s.emit_struct_field("multibyte_chars", 4, |s| { (*self.multibyte_chars.borrow()).encode(s) }) @@ -587,33 +586,26 @@ impl Decodable for FileMap { fn decode(d: &mut D) -> Result { d.read_struct("FileMap", 5, |d| { - let name: String = try! { - d.read_struct_field("name", 0, |d| Decodable::decode(d)) - }; - let start_pos: BytePos = try! { - d.read_struct_field("start_pos", 1, |d| Decodable::decode(d)) - }; - let end_pos: BytePos = try! { - d.read_struct_field("end_pos", 2, |d| Decodable::decode(d)) - }; - let lines: Vec = try! { - d.read_struct_field("lines", 3, |d| { - let num_lines: u32 = try! { Decodable::decode(d) }; + let name: String = d.read_struct_field("name", 0, |d| Decodable::decode(d))?; + let start_pos: BytePos = d.read_struct_field("start_pos", 1, |d| Decodable::decode(d))?; + let end_pos: BytePos = d.read_struct_field("end_pos", 2, |d| Decodable::decode(d))?; + let lines: Vec = d.read_struct_field("lines", 3, |d| { + let num_lines: u32 = Decodable::decode(d)?; let mut lines = Vec::with_capacity(num_lines as usize); if num_lines > 0 { // Read the number of bytes used per diff. - let bytes_per_diff: u8 = try! { Decodable::decode(d) }; + let bytes_per_diff: u8 = Decodable::decode(d)?; // Read the first element. - let mut line_start: BytePos = try! { Decodable::decode(d) }; + let mut line_start: BytePos = Decodable::decode(d)?; lines.push(line_start); for _ in 1..num_lines { let diff = match bytes_per_diff { - 1 => try! { d.read_u8() } as u32, - 2 => try! { d.read_u16() } as u32, - 4 => try! { d.read_u32() }, + 1 => d.read_u8()? as u32, + 2 => d.read_u16()? as u32, + 4 => d.read_u32()?, _ => unreachable!() }; @@ -624,11 +616,8 @@ impl Decodable for FileMap { } Ok(lines) - }) - }; - let multibyte_chars: Vec = try! { - d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d)) - }; + })?; + let multibyte_chars: Vec = d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?; Ok(FileMap { name: name, start_pos: start_pos, @@ -730,7 +719,7 @@ impl FileLoader for RealFileLoader { fn read_file(&self, path: &Path) -> io::Result { let mut src = String::new(); - try!(try!(fs::File::open(path)).read_to_string(&mut src)); + fs::File::open(path)?.read_to_string(&mut src)?; Ok(src) } } @@ -767,7 +756,7 @@ impl CodeMap { } pub fn load_file(&self, path: &Path) -> io::Result> { - let src = try!(self.file_loader.read_file(path)); + let src = self.file_loader.read_file(path)?; Ok(self.new_filemap(path.to_str().unwrap().to_string(), src)) } diff --git a/src/libsyntax/diagnostics/metadata.rs b/src/libsyntax/diagnostics/metadata.rs index e988b74cb3d..181b32594f1 100644 --- a/src/libsyntax/diagnostics/metadata.rs +++ b/src/libsyntax/diagnostics/metadata.rs @@ -76,11 +76,11 @@ pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorM { // Create the directory to place the file in. let metadata_dir = get_metadata_dir(prefix); - try!(create_dir_all(&metadata_dir)); + create_dir_all(&metadata_dir)?; // Open the metadata file. let metadata_path = get_metadata_path(metadata_dir, name); - let mut metadata_file = try!(File::create(&metadata_path)); + let mut metadata_file = File::create(&metadata_path)?; // Construct a serializable map. let json_map = err_map.iter().map(|(k, &ErrorInfo { description, use_site })| { @@ -95,7 +95,7 @@ pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorM // Write the data to the file, deleting it if the write fails. let result = write!(&mut metadata_file, "{}", as_json(&json_map)); if result.is_err() { - try!(remove_file(&metadata_path)); + remove_file(&metadata_path)?; } - Ok(try!(result)) + Ok(result?) } diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index 4272f281edb..c846b1866a7 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -184,20 +184,20 @@ impl EmitterWriter { self.cm.span_to_string(bounds) }; - try!(print_diagnostic(&mut self.dst, &ss[..], lvl, msg, code)); + print_diagnostic(&mut self.dst, &ss[..], lvl, msg, code)?; match *rsp { FullSpan(_) => { - try!(self.highlight_lines(msp, lvl)); - try!(self.print_macro_backtrace(bounds)); + self.highlight_lines(msp, lvl)?; + self.print_macro_backtrace(bounds)?; } EndSpan(_) => { - try!(self.end_highlight_lines(msp, lvl)); - try!(self.print_macro_backtrace(bounds)); + self.end_highlight_lines(msp, lvl)?; + self.print_macro_backtrace(bounds)?; } Suggestion(ref suggestion) => { - try!(self.highlight_suggestion(suggestion)); - try!(self.print_macro_backtrace(bounds)); + self.highlight_suggestion(suggestion)?; + self.print_macro_backtrace(bounds)?; } FileLine(..) => { // no source text in this case! @@ -207,9 +207,9 @@ impl EmitterWriter { if let Some(code) = code { if let Some(_) = self.registry.as_ref() .and_then(|registry| registry.find_description(code)) { - try!(print_diagnostic(&mut self.dst, &ss[..], Help, + print_diagnostic(&mut self.dst, &ss[..], Help, &format!("run `rustc --explain {}` to see a \ - detailed explanation", code), None)); + detailed explanation", code), None)?; } } Ok(()) @@ -233,14 +233,14 @@ impl EmitterWriter { // snippets from the actual error being reported. let mut lines = complete.lines(); for line in lines.by_ref().take(MAX_HIGHLIGHT_LINES) { - try!(write!(&mut self.dst, "{0}:{1:2$} {3}\n", - fm.name, "", max_digits, line)); + write!(&mut self.dst, "{0}:{1:2$} {3}\n", + fm.name, "", max_digits, line)?; } // if we elided some lines, add an ellipsis if let Some(_) = lines.next() { - try!(write!(&mut self.dst, "{0:1$} {0:2$} ...\n", - "", fm.name.len(), max_digits)); + write!(&mut self.dst, "{0:1$} {0:2$} ...\n", + "", fm.name.len(), max_digits)?; } Ok(()) @@ -254,7 +254,7 @@ impl EmitterWriter { let lines = match self.cm.span_to_lines(msp.to_span_bounds()) { Ok(lines) => lines, Err(_) => { - try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n")); + write!(&mut self.dst, "(internal compiler error: unprintable span)\n")?; return Ok(()); } }; @@ -418,26 +418,26 @@ impl EmitterWriter { // If we elided something put an ellipsis. if prev_line_index != line.line_index.wrapping_sub(1) && !overflowed { - try!(write!(&mut self.dst, "{0:1$}...\n", "", skip)); + write!(&mut self.dst, "{0:1$}...\n", "", skip)?; } // Print offending code-line remaining_err_lines -= 1; - try!(write!(&mut self.dst, "{}:{:>width$} {}\n", + write!(&mut self.dst, "{}:{:>width$} {}\n", fm.name, line.line_index + 1, cur_line_str, - width=digits)); + width=digits)?; if s.len() > skip { // Render the spans we assembled previously (if any). - try!(println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), - "{}", s)); + println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), + "{}", s)?; } if !overflowed_buf.is_empty() { // Print code-lines trailing the rendered spans (when a span overflows) - try!(write!(&mut self.dst, "{}", &overflowed_buf)); + write!(&mut self.dst, "{}", &overflowed_buf)?; overflowed_buf.clear(); } else { prev_line_index = line.line_index; @@ -446,7 +446,7 @@ impl EmitterWriter { // If we elided something, put an ellipsis. if lines.next().is_some() { - try!(write!(&mut self.dst, "{0:1$}...\n", "", skip)); + write!(&mut self.dst, "{0:1$}...\n", "", skip)?; } Ok(()) } @@ -465,7 +465,7 @@ impl EmitterWriter { let lines = match self.cm.span_to_lines(msp.to_span_bounds()) { Ok(lines) => lines, Err(_) => { - try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n")); + write!(&mut self.dst, "(internal compiler error: unprintable span)\n")?; return Ok(()); } }; @@ -556,18 +556,18 @@ impl EmitterWriter { if prev_line_index != line.line_index.wrapping_sub(1) { // If we elided something, put an ellipsis. - try!(write!(&mut self.dst, "{0:1$}...\n", "", skip)); + write!(&mut self.dst, "{0:1$}...\n", "", skip)?; } // Print offending code-lines - try!(write!(&mut self.dst, "{}:{:>width$} {}\n", fm.name, - line.line_index + 1, line_str, width=digits)); + write!(&mut self.dst, "{}:{:>width$} {}\n", fm.name, + line.line_index + 1, line_str, width=digits)?; remaining_err_lines -= 1; if s.len() > skip { // Render the spans we assembled previously (if any) - try!(println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), - "{}", s)); + println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), + "{}", s)?; } prev_line_index = line.line_index; } @@ -612,7 +612,7 @@ impl EmitterWriter { } let snippet = self.cm.span_to_string(span); - try!(print_diagnostic(&mut self.dst, &snippet, Note, &diag_string, None)); + print_diagnostic(&mut self.dst, &snippet, Note, &diag_string, None)?; } last_span = span; } @@ -638,18 +638,18 @@ fn print_diagnostic(dst: &mut Destination, code: Option<&str>) -> io::Result<()> { if !topic.is_empty() { - try!(write!(dst, "{} ", topic)); + write!(dst, "{} ", topic)?; } - try!(print_maybe_styled!(dst, term::Attr::ForegroundColor(lvl.color()), - "{}: ", lvl.to_string())); - try!(print_maybe_styled!(dst, term::Attr::Bold, "{}", msg)); + print_maybe_styled!(dst, term::Attr::ForegroundColor(lvl.color()), + "{}: ", lvl.to_string())?; + print_maybe_styled!(dst, term::Attr::Bold, "{}", msg)?; if let Some(code) = code { let style = term::Attr::ForegroundColor(term::color::BRIGHT_MAGENTA); - try!(print_maybe_styled!(dst, style, " [{}]", code.clone())); + print_maybe_styled!(dst, style, " [{}]", code.clone())?; } - try!(write!(dst, "\n")); + write!(dst, "\n")?; Ok(()) } @@ -696,7 +696,7 @@ impl Destination { -> io::Result<()> { match *self { Terminal(ref mut t) => { - try!(t.attr(color)); + t.attr(color)?; // If `msg` ends in a newline, we need to reset the color before // the newline. We're making the assumption that we end up writing // to a `LineBufferedWriter`, which means that emitting the reset @@ -710,8 +710,8 @@ impl Destination { // once, which still leaves the opportunity for interleaved output // to be miscolored. We assume this is rare enough that we don't // have to worry about it. - try!(t.write_fmt(args)); - try!(t.reset()); + t.write_fmt(args)?; + t.reset()?; if print_newline_at_end { t.write_all(b"\n") } else { @@ -719,7 +719,7 @@ impl Destination { } } Raw(ref mut w) => { - try!(w.write_fmt(args)); + w.write_fmt(args)?; if print_newline_at_end { w.write_all(b"\n") } else { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index c4e1f32a52c..4e4c644776a 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -208,12 +208,12 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc]) match *m { TokenTree::Sequence(_, ref seq) => { for next_m in &seq.tts { - try!(n_rec(p_s, next_m, res, ret_val, idx)) + n_rec(p_s, next_m, res, ret_val, idx)? } } TokenTree::Delimited(_, ref delim) => { for next_m in &delim.tts { - try!(n_rec(p_s, next_m, res, ret_val, idx)); + n_rec(p_s, next_m, res, ret_val, idx)?; } } TokenTree::Token(sp, MatchNt(bind_name, _, _, _)) => { diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 0950d6082e7..b8e320e36e9 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -25,7 +25,7 @@ impl<'a> Parser<'a> { debug!("parse_outer_attributes: self.token={:?}", self.token); match self.token { token::Pound => { - attrs.push(try!(self.parse_attribute(false))); + attrs.push(self.parse_attribute(false)?); } token::DocComment(s) => { let attr = ::attr::mk_sugared_doc_attr( @@ -79,10 +79,10 @@ impl<'a> Parser<'a> { ast::AttrStyle::Outer }; - try!(self.expect(&token::OpenDelim(token::Bracket))); - let meta_item = try!(self.parse_meta_item()); + self.expect(&token::OpenDelim(token::Bracket))?; + let meta_item = self.parse_meta_item()?; let hi = self.span.hi; - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; (mk_sp(lo, hi), meta_item, style) } @@ -126,7 +126,7 @@ impl<'a> Parser<'a> { break; } - let attr = try!(self.parse_attribute(true)); + let attr = self.parse_attribute(true)?; assert!(attr.node.style == ast::AttrStyle::Inner); attrs.push(attr); } @@ -166,12 +166,12 @@ impl<'a> Parser<'a> { } let lo = self.span.lo; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let name = self.id_to_interned_str(ident); match self.token { token::Eq => { self.bump(); - let lit = try!(self.parse_lit()); + let lit = self.parse_lit()?; // FIXME #623 Non-string meta items are not serialized correctly; // just forbid them for now match lit.node { @@ -185,7 +185,7 @@ impl<'a> Parser<'a> { Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(name, lit)))) } token::OpenDelim(token::Paren) => { - let inner_items = try!(self.parse_meta_seq()); + let inner_items = self.parse_meta_seq()?; let hi = self.span.hi; Ok(P(spanned(lo, hi, ast::MetaItemKind::List(name, inner_items)))) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6839f11cd70..827f3331753 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -590,11 +590,11 @@ impl<'a> Parser<'a> { pub fn parse_path_list_item(&mut self) -> PResult<'a, ast::PathListItem> { let lo = self.span.lo; let node = if self.eat_keyword(keywords::SelfValue) { - let rename = try!(self.parse_rename()); + let rename = self.parse_rename()?; ast::PathListItemKind::Mod { id: ast::DUMMY_NODE_ID, rename: rename } } else { - let ident = try!(self.parse_ident()); - let rename = try!(self.parse_rename()); + let ident = self.parse_ident()?; + let rename = self.parse_rename()?; ast::PathListItemKind::Ident { name: ident, rename: rename, id: ast::DUMMY_NODE_ID } }; let hi = self.last_span.hi; @@ -811,13 +811,13 @@ impl<'a> Parser<'a> { } if i % 2 == 0 { - match try!(f(self)) { + match f(self)? { Some(result) => v.push(result), None => return Ok((P::from_vec(v), true)) } } else { if let Some(t) = sep.as_ref() { - try!(self.expect(t)); + self.expect(t)?; } } @@ -833,8 +833,8 @@ impl<'a> Parser<'a> { -> PResult<'a, P<[T]>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let (result, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, - |p| Ok(Some(try!(f(p)))))); + let (result, returned) = self.parse_seq_to_before_gt_or_return(sep, + |p| Ok(Some(f(p)?)))?; assert!(!returned); return Ok(result); } @@ -845,8 +845,8 @@ impl<'a> Parser<'a> { -> PResult<'a, P<[T]>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let v = try!(self.parse_seq_to_before_gt(sep, f)); - try!(self.expect_gt()); + let v = self.parse_seq_to_before_gt(sep, f)?; + self.expect_gt()?; return Ok(v); } @@ -856,9 +856,9 @@ impl<'a> Parser<'a> { -> PResult<'a, (P<[T]>, bool)> where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option>, { - let (v, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, f)); + let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f)?; if !returned { - try!(self.expect_gt()); + self.expect_gt()?; } return Ok((v, returned)); } @@ -953,7 +953,7 @@ impl<'a> Parser<'a> { -> PResult<'a, Vec> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - try!(self.expect(bra)); + self.expect(bra)?; let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); Ok(result) @@ -969,7 +969,7 @@ impl<'a> Parser<'a> { -> PResult<'a, Vec> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let result = try!(self.parse_unspanned_seq(bra, ket, sep, f)); + let result = self.parse_unspanned_seq(bra, ket, sep, f)?; if result.is_empty() { let last_span = self.last_span; self.span_err(last_span, @@ -989,7 +989,7 @@ impl<'a> Parser<'a> { F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { let lo = self.span.lo; - try!(self.expect(bra)); + self.expect(bra)?; let result = self.parse_seq_to_before_end(ket, sep, f); let hi = self.span.hi; self.bump(); @@ -1142,19 +1142,19 @@ impl<'a> Parser<'a> { // parse <'lt> let lo = self.span.lo; - let lifetime_defs = try!(self.parse_late_bound_lifetime_defs()); + let lifetime_defs = self.parse_late_bound_lifetime_defs()?; // examine next token to decide to do if self.token_is_bare_fn_keyword() { self.parse_ty_bare_fn(lifetime_defs) } else { let hi = self.span.hi; - let trait_ref = try!(self.parse_trait_ref()); + let trait_ref = self.parse_trait_ref()?; let poly_trait_ref = ast::PolyTraitRef { bound_lifetimes: lifetime_defs, trait_ref: trait_ref, span: mk_sp(lo, hi)}; let other_bounds = if self.eat(&token::BinOp(token::Plus)) { - try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)) + self.parse_ty_param_bounds(BoundParsingMode::Bare)? } else { P::empty() }; @@ -1167,7 +1167,7 @@ impl<'a> Parser<'a> { } pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> { - Ok(TyKind::Path(None, try!(self.parse_path(LifetimeAndTypesWithoutColons)))) + Ok(TyKind::Path(None, self.parse_path(LifetimeAndTypesWithoutColons)?)) } /// parse a TyKind::BareFn type: @@ -1185,16 +1185,16 @@ impl<'a> Parser<'a> { Function Style */ - let unsafety = try!(self.parse_unsafety()); + let unsafety = self.parse_unsafety()?; let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; - try!(self.expect_keyword(keywords::Fn)); - let (inputs, variadic) = try!(self.parse_fn_args(false, true)); - let ret_ty = try!(self.parse_ret_ty()); + self.expect_keyword(keywords::Fn)?; + let (inputs, variadic) = self.parse_fn_args(false, true)?; + let ret_ty = self.parse_ret_ty()?; let decl = P(FnDecl { inputs: inputs, output: ret_ty, @@ -1254,25 +1254,25 @@ impl<'a> Parser<'a> { SeqSep::none(), |p| -> PResult<'a, TraitItem> { maybe_whole!(no_clone_from_p p, NtTraitItem); - let mut attrs = try!(p.parse_outer_attributes()); + let mut attrs = p.parse_outer_attributes()?; let lo = p.span.lo; let (name, node) = if p.eat_keyword(keywords::Type) { - let TyParam {ident, bounds, default, ..} = try!(p.parse_ty_param()); - try!(p.expect(&token::Semi)); + let TyParam {ident, bounds, default, ..} = p.parse_ty_param()?; + p.expect(&token::Semi)?; (ident, TraitItemKind::Type(bounds, default)) } else if p.is_const_item() { - try!(p.expect_keyword(keywords::Const)); - let ident = try!(p.parse_ident()); - try!(p.expect(&token::Colon)); - let ty = try!(p.parse_ty_sum()); + p.expect_keyword(keywords::Const)?; + let ident = p.parse_ident()?; + p.expect(&token::Colon)?; + let ty = p.parse_ty_sum()?; let default = if p.check(&token::Eq) { p.bump(); - let expr = try!(p.parse_expr()); - try!(p.commit_expr_expecting(&expr, token::Semi)); + let expr = p.parse_expr()?; + p.commit_expr_expecting(&expr, token::Semi)?; Some(expr) } else { - try!(p.expect(&token::Semi)); + p.expect(&token::Semi)?; None }; (ident, TraitItemKind::Const(ty, default)) @@ -1288,7 +1288,7 @@ impl<'a> Parser<'a> { } if p.token == token::OpenDelim(token::DelimToken::Brace) { - try!(p.parse_token_tree()); + p.parse_token_tree()?; break; } } @@ -1297,17 +1297,17 @@ impl<'a> Parser<'a> { } }; - let ident = try!(p.parse_ident()); - let mut generics = try!(p.parse_generics()); + let ident = p.parse_ident()?; + let mut generics = p.parse_generics()?; - let (explicit_self, d) = try!(p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{ + let (explicit_self, d) = p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{ // This is somewhat dubious; We don't want to allow // argument names to be left off if there is a // definition... p.parse_arg_general(false) - })); + })?; - generics.where_clause = try!(p.parse_where_clause()); + generics.where_clause = p.parse_where_clause()?; let sig = ast::MethodSig { unsafety: unsafety, constness: constness, @@ -1326,7 +1326,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Brace) => { debug!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = - try!(p.parse_inner_attrs_and_block()); + p.parse_inner_attrs_and_block()?; attrs.extend(inner_attrs.iter().cloned()); Some(body) } @@ -1352,8 +1352,8 @@ impl<'a> Parser<'a> { /// Parse a possibly mutable type pub fn parse_mt(&mut self) -> PResult<'a, MutTy> { - let mutbl = try!(self.parse_mutability()); - let t = try!(self.parse_ty()); + let mutbl = self.parse_mutability()?; + let t = self.parse_ty()?; Ok(MutTy { ty: t, mutbl: mutbl }) } @@ -1363,7 +1363,7 @@ impl<'a> Parser<'a> { if self.eat(&token::Not) { Ok(FunctionRetTy::None(self.last_span)) } else { - Ok(FunctionRetTy::Ty(try!(self.parse_ty()))) + Ok(FunctionRetTy::Ty(self.parse_ty()?)) } } else { let pos = self.span.lo; @@ -1374,13 +1374,13 @@ impl<'a> Parser<'a> { /// Parse a type in a context where `T1+T2` is allowed. pub fn parse_ty_sum(&mut self) -> PResult<'a, P> { let lo = self.span.lo; - let lhs = try!(self.parse_ty()); + let lhs = self.parse_ty()?; if !self.eat(&token::BinOp(token::Plus)) { return Ok(lhs); } - let bounds = try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; // In type grammar, `+` is treated like a binary operator, // and hence both L and R side are required. @@ -1411,7 +1411,7 @@ impl<'a> Parser<'a> { let mut ts = vec![]; let mut last_comma = false; while self.token != token::CloseDelim(token::Paren) { - ts.push(try!(self.parse_ty_sum())); + ts.push(self.parse_ty_sum()?); if self.check(&token::Comma) { last_comma = true; self.bump(); @@ -1421,7 +1421,7 @@ impl<'a> Parser<'a> { } } - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; if ts.len() == 1 && !last_comma { TyKind::Paren(ts.into_iter().nth(0).unwrap()) } else { @@ -1430,54 +1430,54 @@ impl<'a> Parser<'a> { } else if self.check(&token::BinOp(token::Star)) { // STAR POINTER (bare pointer?) self.bump(); - TyKind::Ptr(try!(self.parse_ptr())) + TyKind::Ptr(self.parse_ptr()?) } else if self.check(&token::OpenDelim(token::Bracket)) { // VECTOR - try!(self.expect(&token::OpenDelim(token::Bracket))); - let t = try!(self.parse_ty_sum()); + self.expect(&token::OpenDelim(token::Bracket))?; + let t = self.parse_ty_sum()?; // Parse the `; e` in `[ i32; e ]` // where `e` is a const expression - let t = match try!(self.maybe_parse_fixed_length_of_vec()) { + let t = match self.maybe_parse_fixed_length_of_vec()? { None => TyKind::Vec(t), Some(suffix) => TyKind::FixedLengthVec(t, suffix) }; - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; t } else if self.check(&token::BinOp(token::And)) || self.token == token::AndAnd { // BORROWED POINTER - try!(self.expect_and()); - try!(self.parse_borrowed_pointee()) + self.expect_and()?; + self.parse_borrowed_pointee()? } else if self.check_keyword(keywords::For) { - try!(self.parse_for_in_type()) + self.parse_for_in_type()? } else if self.token_is_bare_fn_keyword() { // BARE FUNCTION - try!(self.parse_ty_bare_fn(Vec::new())) + self.parse_ty_bare_fn(Vec::new())? } else if self.eat_keyword_noexpect(keywords::Typeof) { // TYPEOF // In order to not be ambiguous, the type must be surrounded by parens. - try!(self.expect(&token::OpenDelim(token::Paren))); - let e = try!(self.parse_expr()); - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::OpenDelim(token::Paren))?; + let e = self.parse_expr()?; + self.expect(&token::CloseDelim(token::Paren))?; TyKind::Typeof(e) } else if self.eat_lt() { let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; TyKind::Path(Some(qself), path) } else if self.check(&token::ModSep) || self.token.is_ident() || self.token.is_path() { - let path = try!(self.parse_path(LifetimeAndTypesWithoutColons)); + let path = self.parse_path(LifetimeAndTypesWithoutColons)?; if self.check(&token::Not) { // MACRO INVOCATION self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let hi = self.span.hi; TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) } else { @@ -1499,9 +1499,9 @@ impl<'a> Parser<'a> { pub fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: - let opt_lifetime = try!(self.parse_opt_lifetime()); + let opt_lifetime = self.parse_opt_lifetime()?; - let mt = try!(self.parse_mt()); + let mt = self.parse_mt()?; return Ok(TyKind::Rptr(opt_lifetime, mt)); } @@ -1518,7 +1518,7 @@ impl<'a> Parser<'a> { known as `*const T`"); Mutability::Immutable }; - let t = try!(self.parse_ty()); + let t = self.parse_ty()?; Ok(MutTy { ty: t, mutbl: mutbl }) } @@ -1549,9 +1549,9 @@ impl<'a> Parser<'a> { let pat = if require_name || self.is_named_argument() { debug!("parse_arg_general parse_pat (require_name:{})", require_name); - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; - try!(self.expect(&token::Colon)); + self.expect(&token::Colon)?; pat } else { debug!("parse_arg_general ident_to_pat"); @@ -1560,7 +1560,7 @@ impl<'a> Parser<'a> { special_idents::invalid) }; - let t = try!(self.parse_ty_sum()); + let t = self.parse_ty_sum()?; Ok(Arg { ty: t, @@ -1576,9 +1576,9 @@ impl<'a> Parser<'a> { /// Parse an argument in a lambda header e.g. |arg, arg| pub fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> { - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; let t = if self.eat(&token::Colon) { - try!(self.parse_ty_sum()) + self.parse_ty_sum()? } else { P(Ty { id: ast::DUMMY_NODE_ID, @@ -1596,7 +1596,7 @@ impl<'a> Parser<'a> { pub fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option>> { if self.check(&token::Semi) { self.bump(); - Ok(Some(try!(self.parse_expr()))) + Ok(Some(self.parse_expr()?)) } else { Ok(None) } @@ -1670,7 +1670,7 @@ impl<'a> Parser<'a> { LitKind::Bool(false) } else { let token = self.bump_and_get(); - let lit = try!(self.lit_from_token(&token)); + let lit = self.lit_from_token(&token)?; lit }; Ok(codemap::Spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }) @@ -1681,7 +1681,7 @@ impl<'a> Parser<'a> { let minus_lo = self.span.lo; let minus_present = self.eat(&token::BinOp(token::Minus)); let lo = self.span.lo; - let literal = P(try!(self.parse_lit())); + let literal = P(self.parse_lit()?); let hi = self.last_span.hi; let expr = self.mk_expr(lo, hi, ExprKind::Lit(literal), None); @@ -1712,9 +1712,9 @@ impl<'a> Parser<'a> { pub fn parse_qualified_path(&mut self, mode: PathParsingMode) -> PResult<'a, (QSelf, ast::Path)> { let span = self.last_span; - let self_type = try!(self.parse_ty_sum()); + let self_type = self.parse_ty_sum()?; let mut path = if self.eat_keyword(keywords::As) { - try!(self.parse_path(LifetimeAndTypesWithoutColons)) + self.parse_path(LifetimeAndTypesWithoutColons)? } else { ast::Path { span: span, @@ -1728,18 +1728,18 @@ impl<'a> Parser<'a> { position: path.segments.len() }; - try!(self.expect(&token::Gt)); - try!(self.expect(&token::ModSep)); + self.expect(&token::Gt)?; + self.expect(&token::ModSep)?; let segments = match mode { LifetimeAndTypesWithoutColons => { - try!(self.parse_path_segments_without_colons()) + self.parse_path_segments_without_colons()? } LifetimeAndTypesWithColons => { - try!(self.parse_path_segments_with_colons()) + self.parse_path_segments_with_colons()? } NoTypesAllowed => { - try!(self.parse_path_segments_without_types()) + self.parse_path_segments_without_types()? } }; path.segments.extend(segments); @@ -1771,13 +1771,13 @@ impl<'a> Parser<'a> { // A bound set is a set of type parameter bounds. let segments = match mode { LifetimeAndTypesWithoutColons => { - try!(self.parse_path_segments_without_colons()) + self.parse_path_segments_without_colons()? } LifetimeAndTypesWithColons => { - try!(self.parse_path_segments_with_colons()) + self.parse_path_segments_with_colons()? } NoTypesAllowed => { - try!(self.parse_path_segments_without_types()) + self.parse_path_segments_without_types()? } }; @@ -1800,11 +1800,11 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // Parse types, optionally. let parameters = if self.eat_lt() { - let (lifetimes, types, bindings) = try!(self.parse_generic_values_after_lt()); + let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?; ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData { lifetimes: lifetimes, @@ -1814,13 +1814,13 @@ impl<'a> Parser<'a> { } else if self.eat(&token::OpenDelim(token::Paren)) { let lo = self.last_span.lo; - let inputs = try!(self.parse_seq_to_end( + let inputs = self.parse_seq_to_end( &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_ty_sum())); + |p| p.parse_ty_sum())?; let output_ty = if self.eat(&token::RArrow) { - Some(try!(self.parse_ty())) + Some(self.parse_ty()?) } else { None }; @@ -1853,7 +1853,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // If we do not see a `::`, stop. if !self.eat(&token::ModSep) { @@ -1867,7 +1867,7 @@ impl<'a> Parser<'a> { // Check for a type segment. if self.eat_lt() { // Consumed `a::b::<`, go look for types - let (lifetimes, types, bindings) = try!(self.parse_generic_values_after_lt()); + let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?; let parameters = ast::AngleBracketedParameterData { lifetimes: lifetimes, types: P::from_vec(types), @@ -1899,7 +1899,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // Assemble and push the result. segments.push(ast::PathSegment { @@ -1918,7 +1918,7 @@ impl<'a> Parser<'a> { pub fn parse_opt_lifetime(&mut self) -> PResult<'a, Option> { match self.token { token::Lifetime(..) => { - Ok(Some(try!(self.parse_lifetime()))) + Ok(Some(self.parse_lifetime()?)) } _ => { Ok(None) @@ -1953,10 +1953,10 @@ impl<'a> Parser<'a> { loop { match self.token { token::Lifetime(_) => { - let lifetime = try!(self.parse_lifetime()); + let lifetime = self.parse_lifetime()?; let bounds = if self.eat(&token::Colon) { - try!(self.parse_lifetimes(token::BinOp(token::Plus))) + self.parse_lifetimes(token::BinOp(token::Plus))? } else { Vec::new() }; @@ -1996,7 +1996,7 @@ impl<'a> Parser<'a> { loop { match self.token { token::Lifetime(_) => { - res.push(try!(self.parse_lifetime())); + res.push(self.parse_lifetime()?); } _ => { return Ok(res); @@ -2023,10 +2023,10 @@ impl<'a> Parser<'a> { /// Parse ident COLON expr pub fn parse_field(&mut self) -> PResult<'a, Field> { let lo = self.span.lo; - let i = try!(self.parse_ident()); + let i = self.parse_ident()?; let hi = self.last_span.hi; - try!(self.expect(&token::Colon)); - let e = try!(self.parse_expr()); + self.expect(&token::Colon)?; + let e = self.parse_expr()?; Ok(ast::Field { ident: spanned(lo, hi, i), span: mk_sp(lo, e.span.hi), @@ -2152,7 +2152,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Paren) => { self.bump(); - let attrs = try!(self.parse_inner_attributes()) + let attrs = self.parse_inner_attributes()? .into_thin_attrs() .prepend(attrs); @@ -2161,9 +2161,9 @@ impl<'a> Parser<'a> { let mut es = vec![]; let mut trailing_comma = false; while self.token != token::CloseDelim(token::Paren) { - es.push(try!(self.parse_expr())); - try!(self.commit_expr(&es.last().unwrap(), &[], - &[token::Comma, token::CloseDelim(token::Paren)])); + es.push(self.parse_expr()?); + self.commit_expr(&es.last().unwrap(), &[], + &[token::Comma, token::CloseDelim(token::Paren)])?; if self.check(&token::Comma) { trailing_comma = true; @@ -2201,7 +2201,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Bracket) => { self.bump(); - let inner_attrs = try!(self.parse_inner_attributes()) + let inner_attrs = self.parse_inner_attributes()? .into_thin_attrs(); attrs.update(|attrs| attrs.append(inner_attrs)); @@ -2211,27 +2211,27 @@ impl<'a> Parser<'a> { ex = ExprKind::Vec(Vec::new()); } else { // Nonempty vector. - let first_expr = try!(self.parse_expr()); + let first_expr = self.parse_expr()?; if self.check(&token::Semi) { // Repeating array syntax: [ 0; 512 ] self.bump(); - let count = try!(self.parse_expr()); - try!(self.expect(&token::CloseDelim(token::Bracket))); + let count = self.parse_expr()?; + self.expect(&token::CloseDelim(token::Bracket))?; ex = ExprKind::Repeat(first_expr, count); } else if self.check(&token::Comma) { // Vector with two or more elements. self.bump(); - let remaining_exprs = try!(self.parse_seq_to_end( + let remaining_exprs = self.parse_seq_to_end( &token::CloseDelim(token::Bracket), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; let mut exprs = vec!(first_expr); exprs.extend(remaining_exprs); ex = ExprKind::Vec(exprs); } else { // Vector with one element. - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; ex = ExprKind::Vec(vec!(first_expr)); } } @@ -2240,7 +2240,7 @@ impl<'a> Parser<'a> { _ => { if self.eat_lt() { let (qself, path) = - try!(self.parse_qualified_path(LifetimeAndTypesWithColons)); + self.parse_qualified_path(LifetimeAndTypesWithColons)?; hi = path.span.hi; return Ok(self.mk_expr(lo, hi, ExprKind::Path(Some(qself), path), attrs)); } @@ -2263,7 +2263,7 @@ impl<'a> Parser<'a> { let lifetime = self.get_lifetime(); let lo = self.span.lo; self.bump(); - try!(self.expect(&token::Colon)); + self.expect(&token::Colon)?; if self.eat_keyword(keywords::While) { return self.parse_while_expr(Some(lifetime), lo, attrs) } @@ -2304,7 +2304,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Return) { if self.token.can_begin_expr() { - let e = try!(self.parse_expr()); + let e = self.parse_expr()?; hi = e.span.hi; ex = ExprKind::Ret(Some(e)); } else { @@ -2332,18 +2332,18 @@ impl<'a> Parser<'a> { !self.check_keyword(keywords::True) && !self.check_keyword(keywords::False) { let pth = - try!(self.parse_path(LifetimeAndTypesWithColons)); + self.parse_path(LifetimeAndTypesWithColons)?; // `!`, as an operator, is prefix, so we know this isn't that if self.check(&token::Not) { // MACRO INVOCATION expression self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end( + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end( &token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let hi = self.last_span.hi; return Ok(self.mk_mac_expr(lo, @@ -2364,7 +2364,7 @@ impl<'a> Parser<'a> { let mut base = None; let attrs = attrs.append( - try!(self.parse_inner_attributes()) + self.parse_inner_attributes()? .into_thin_attrs()); while self.token != token::CloseDelim(token::Brace) { @@ -2403,7 +2403,7 @@ impl<'a> Parser<'a> { } hi = self.span.hi; - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; ex = ExprKind::Struct(pth, fields, base); return Ok(self.mk_expr(lo, hi, ex, attrs)); } @@ -2413,7 +2413,7 @@ impl<'a> Parser<'a> { ex = ExprKind::Path(None, pth); } else { // other literal expression - let lit = try!(self.parse_lit()); + let lit = self.parse_lit()?; hi = lit.span.hi; ex = ExprKind::Lit(P(lit)); } @@ -2439,12 +2439,12 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { let outer_attrs = attrs; - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; - let inner_attrs = try!(self.parse_inner_attributes()).into_thin_attrs(); + let inner_attrs = self.parse_inner_attributes()?.into_thin_attrs(); let attrs = outer_attrs.append(inner_attrs); - let blk = try!(self.parse_block_tail(lo, blk_mode)); + let blk = self.parse_block_tail(lo, blk_mode)?; return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), attrs)); } @@ -2452,10 +2452,10 @@ impl<'a> Parser<'a> { pub fn parse_dot_or_call_expr(&mut self, already_parsed_attrs: Option) -> PResult<'a, P> { - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let b = self.parse_bottom_expr(); - let (span, b) = try!(self.interpolated_or_expr_span(b)); + let (span, b) = self.interpolated_or_expr_span(b)?; self.parse_dot_or_call_expr_with(b, span.lo, attrs) } @@ -2498,8 +2498,8 @@ impl<'a> Parser<'a> { lo: BytePos) -> PResult<'a, P> { let (_, tys, bindings) = if self.eat(&token::ModSep) { - try!(self.expect_lt()); - try!(self.parse_generic_values_after_lt()) + self.expect_lt()?; + self.parse_generic_values_after_lt()? } else { (Vec::new(), Vec::new(), Vec::new()) }; @@ -2512,12 +2512,12 @@ impl<'a> Parser<'a> { Ok(match self.token { // expr.f() method call. token::OpenDelim(token::Paren) => { - let mut es = try!(self.parse_unspanned_seq( + let mut es = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; let hi = self.last_span.hi; es.insert(0, self_value); @@ -2559,7 +2559,7 @@ impl<'a> Parser<'a> { hi = self.span.hi; self.bump(); - e = try!(self.parse_dot_suffix(i, mk_sp(dot_pos, hi), e, lo)); + e = self.parse_dot_suffix(i, mk_sp(dot_pos, hi), e, lo)?; } token::Literal(token::Integer(n), suf) => { let sp = self.span; @@ -2609,9 +2609,9 @@ impl<'a> Parser<'a> { self.span_err(self.span, &format!("unexpected token: `{}`", actual)); let dot_pos = self.last_span.hi; - e = try!(self.parse_dot_suffix(special_idents::invalid, + e = self.parse_dot_suffix(special_idents::invalid, mk_sp(dot_pos, dot_pos), - e, lo)); + e, lo)?; } } continue; @@ -2620,12 +2620,12 @@ impl<'a> Parser<'a> { match self.token { // expr(...) token::OpenDelim(token::Paren) => { - let es = try!(self.parse_unspanned_seq( + let es = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; hi = self.last_span.hi; let nd = self.mk_call(e, es); @@ -2636,9 +2636,9 @@ impl<'a> Parser<'a> { // Could be either an index expression or a slicing expression. token::OpenDelim(token::Bracket) => { self.bump(); - let ix = try!(self.parse_expr()); + let ix = self.parse_expr()?; hi = self.span.hi; - try!(self.commit_expr_expecting(&ix, token::CloseDelim(token::Bracket))); + self.commit_expr_expecting(&ix, token::CloseDelim(token::Bracket))?; let index = self.mk_index(e, ix); e = self.mk_expr(lo, hi, index, None) } @@ -2656,13 +2656,13 @@ impl<'a> Parser<'a> { self.bump(); if self.token == token::OpenDelim(token::Paren) { - let Spanned { node: seq, span: seq_span } = try!(self.parse_seq( + let Spanned { node: seq, span: seq_span } = self.parse_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::none(), |p| p.parse_token_tree() - )); - let (sep, repeat) = try!(self.parse_sep_and_kleene_op()); + )?; + let (sep, repeat) = self.parse_sep_and_kleene_op()?; let name_num = macro_parser::count_names(&seq); return Ok(TokenTree::Sequence(mk_sp(sp.lo, seq_span.hi), Rc::new(SequenceRepetition { @@ -2677,7 +2677,7 @@ impl<'a> Parser<'a> { } else { sp = mk_sp(sp.lo, self.span.hi); let namep = match self.token { token::Ident(_, p) => p, _ => token::Plain }; - let name = try!(self.parse_ident()); + let name = self.parse_ident()?; (name, namep) } } @@ -2694,7 +2694,7 @@ impl<'a> Parser<'a> { self.bump(); sp = mk_sp(sp.lo, self.span.hi); let kindp = match self.token { token::Ident(_, p) => p, _ => token::Plain }; - let nt_kind = try!(self.parse_ident()); + let nt_kind = self.parse_ident()?; Ok(TokenTree::Token(sp, MatchNt(name, nt_kind, namep, kindp))) } else { Ok(TokenTree::Token(sp, SubstNt(name, namep))) @@ -2729,13 +2729,13 @@ impl<'a> Parser<'a> { } }; - match try!(parse_kleene_op(self)) { + match parse_kleene_op(self)? { Some(kleene_op) => return Ok((None, kleene_op)), None => {} } let separator = self.bump_and_get(); - match try!(parse_kleene_op(self)) { + match parse_kleene_op(self)? { Some(zerok) => Ok((Some(separator), zerok)), None => return Err(self.fatal("expected `*` or `+`")) } @@ -2827,7 +2827,7 @@ impl<'a> Parser<'a> { pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec> { let mut tts = Vec::new(); while self.token != token::Eof { - tts.push(try!(self.parse_token_tree())); + tts.push(self.parse_token_tree()?); } Ok(tts) } @@ -2836,7 +2836,7 @@ impl<'a> Parser<'a> { pub fn parse_prefix_expr(&mut self, already_parsed_attrs: Option) -> PResult<'a, P> { - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let lo = self.span.lo; let hi; // Note: when adding new unary operators, don't forget to adjust Token::can_begin_expr() @@ -2844,39 +2844,39 @@ impl<'a> Parser<'a> { token::Not => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Not, e) } token::BinOp(token::Minus) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Neg, e) } token::BinOp(token::Star) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Deref, e) } token::BinOp(token::And) | token::AndAnd => { - try!(self.expect_and()); - let m = try!(self.parse_mutability()); + self.expect_and()?; + let m = self.parse_mutability()?; let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; ExprKind::AddrOf(m, e) } token::Ident(..) if self.token.is_keyword(keywords::In) => { self.bump(); - let place = try!(self.parse_expr_res( + let place = self.parse_expr_res( Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None, - )); - let blk = try!(self.parse_block()); + )?; + let blk = self.parse_block()?; let span = blk.span; hi = span.hi; let blk_expr = self.mk_expr(span.lo, span.hi, ExprKind::Block(blk), @@ -2886,7 +2886,7 @@ impl<'a> Parser<'a> { token::Ident(..) if self.token.is_keyword(keywords::Box) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; ExprKind::Box(e) } @@ -2920,7 +2920,7 @@ impl<'a> Parser<'a> { if self.token == token::DotDot || self.token == token::DotDotDot { return self.parse_prefix_range_expr(attrs); } else { - try!(self.parse_prefix_expr(attrs)) + self.parse_prefix_expr(attrs)? } }; @@ -2952,12 +2952,12 @@ impl<'a> Parser<'a> { } // Special cases: if op == AssocOp::As { - let rhs = try!(self.parse_ty()); + let rhs = self.parse_ty()?; lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::Cast(lhs, rhs), None); continue } else if op == AssocOp::Colon { - let rhs = try!(self.parse_ty()); + let rhs = self.parse_ty()?; lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::Type(lhs, rhs), None); continue @@ -2990,7 +2990,7 @@ impl<'a> Parser<'a> { break } - let rhs = try!(match op.fixity() { + let rhs = match op.fixity() { Fixity::Right => self.with_res( restrictions - Restrictions::RESTRICTION_STMT_EXPR, |this| { @@ -3011,7 +3011,7 @@ impl<'a> Parser<'a> { this.parse_assoc_expr_with(op.precedence() + 1, LhsExpr::NotYetParsed) }), - }); + }?; lhs = match op { AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | @@ -3087,19 +3087,19 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { debug_assert!(self.token == token::DotDot || self.token == token::DotDotDot); let tok = self.token.clone(); - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let lo = self.span.lo; let mut hi = self.span.hi; self.bump(); let opt_end = if self.is_at_start_of_range_notation_rhs() { // RHS must be parsed with more associativity than the dots. let next_prec = AssocOp::from_token(&tok).unwrap().precedence() + 1; - Some(try!(self.parse_assoc_expr_with(next_prec, + Some(self.parse_assoc_expr_with(next_prec, LhsExpr::NotYetParsed) .map(|x|{ hi = x.span.hi; x - }))) + })?) } else { None }; @@ -3131,12 +3131,12 @@ impl<'a> Parser<'a> { return self.parse_if_let_expr(attrs); } let lo = self.last_span.lo; - let cond = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let thn = try!(self.parse_block()); + let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let thn = self.parse_block()?; let mut els: Option> = None; let mut hi = thn.span.hi; if self.eat_keyword(keywords::Else) { - let elexpr = try!(self.parse_else_expr()); + let elexpr = self.parse_else_expr()?; hi = elexpr.span.hi; els = Some(elexpr); } @@ -3147,13 +3147,13 @@ impl<'a> Parser<'a> { pub fn parse_if_let_expr(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.last_span.lo; - try!(self.expect_keyword(keywords::Let)); - let pat = try!(self.parse_pat()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let thn = try!(self.parse_block()); + self.expect_keyword(keywords::Let)?; + let pat = self.parse_pat()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let thn = self.parse_block()?; let (hi, els) = if self.eat_keyword(keywords::Else) { - let expr = try!(self.parse_else_expr()); + let expr = self.parse_else_expr()?; (expr.span.hi, Some(expr)) } else { (thn.span.hi, None) @@ -3167,12 +3167,12 @@ impl<'a> Parser<'a> { attrs: ThinAttributes) -> PResult<'a, P> { - let decl = try!(self.parse_fn_block_decl()); + let decl = self.parse_fn_block_decl()?; let body = match decl.output { FunctionRetTy::Default(_) => { // If no explicit return type is given, parse any // expr and wrap it up in a dummy block: - let body_expr = try!(self.parse_expr()); + let body_expr = self.parse_expr()?; P(ast::Block { id: ast::DUMMY_NODE_ID, stmts: vec![], @@ -3184,7 +3184,7 @@ impl<'a> Parser<'a> { _ => { // If an explicit return type is given, require a // block to appear (RFC 968). - try!(self.parse_block()) + self.parse_block()? } }; @@ -3199,7 +3199,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::If) { return self.parse_if_expr(None); } else { - let blk = try!(self.parse_block()); + let blk = self.parse_block()?; return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), None)); } } @@ -3210,10 +3210,10 @@ impl<'a> Parser<'a> { attrs: ThinAttributes) -> PResult<'a, P> { // Parse: `for in ` - let pat = try!(self.parse_pat()); - try!(self.expect_keyword(keywords::In)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, loop_block) = try!(self.parse_inner_attrs_and_block()); + let pat = self.parse_pat()?; + self.expect_keyword(keywords::In)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, loop_block) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = self.last_span.hi; @@ -3230,8 +3230,8 @@ impl<'a> Parser<'a> { if self.token.is_keyword(keywords::Let) { return self.parse_while_let_expr(opt_ident, span_lo, attrs); } - let cond = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; return Ok(self.mk_expr(span_lo, hi, ExprKind::While(cond, body, opt_ident), @@ -3242,11 +3242,11 @@ impl<'a> Parser<'a> { pub fn parse_while_let_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { - try!(self.expect_keyword(keywords::Let)); - let pat = try!(self.parse_pat()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + self.expect_keyword(keywords::Let)?; + let pat = self.parse_pat()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; return Ok(self.mk_expr(span_lo, hi, ExprKind::WhileLet(pat, expr, body, opt_ident), attrs)); @@ -3256,7 +3256,7 @@ impl<'a> Parser<'a> { pub fn parse_loop_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; Ok(self.mk_expr(span_lo, hi, ExprKind::Loop(body, opt_ident), attrs)) @@ -3266,8 +3266,8 @@ impl<'a> Parser<'a> { fn parse_match_expr(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let match_span = self.last_span; let lo = self.last_span.lo; - let discriminant = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, - None)); + let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, + None)?; if let Err(mut e) = self.commit_expr_expecting(&discriminant, token::OpenDelim(token::Brace)) { if self.token == token::Token::Semi { @@ -3276,7 +3276,7 @@ impl<'a> Parser<'a> { return Err(e) } let attrs = attrs.append( - try!(self.parse_inner_attributes()).into_thin_attrs()); + self.parse_inner_attributes()?.into_thin_attrs()); let mut arms: Vec = Vec::new(); while self.token != token::CloseDelim(token::Brace) { match self.parse_arm() { @@ -3301,21 +3301,21 @@ impl<'a> Parser<'a> { pub fn parse_arm(&mut self) -> PResult<'a, Arm> { maybe_whole!(no_clone self, NtArm); - let attrs = try!(self.parse_outer_attributes()); - let pats = try!(self.parse_pats()); + let attrs = self.parse_outer_attributes()?; + let pats = self.parse_pats()?; let mut guard = None; if self.eat_keyword(keywords::If) { - guard = Some(try!(self.parse_expr())); + guard = Some(self.parse_expr()?); } - try!(self.expect(&token::FatArrow)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_STMT_EXPR, None)); + self.expect(&token::FatArrow)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_STMT_EXPR, None)?; let require_comma = !classify::expr_is_simple_block(&expr) && self.token != token::CloseDelim(token::Brace); if require_comma { - try!(self.commit_expr(&expr, &[token::Comma], &[token::CloseDelim(token::Brace)])); + self.commit_expr(&expr, &[token::Comma], &[token::CloseDelim(token::Brace)])?; } else { self.eat(&token::Comma); } @@ -3358,7 +3358,7 @@ impl<'a> Parser<'a> { fn parse_initializer(&mut self) -> PResult<'a, Option>> { if self.check(&token::Eq) { self.bump(); - Ok(Some(try!(self.parse_expr()))) + Ok(Some(self.parse_expr()?)) } else { Ok(None) } @@ -3368,7 +3368,7 @@ impl<'a> Parser<'a> { fn parse_pats(&mut self) -> PResult<'a, Vec>> { let mut pats = Vec::new(); loop { - pats.push(try!(self.parse_pat())); + pats.push(self.parse_pat()?); if self.check(&token::BinOp(token::Or)) { self.bump();} else { return Ok(pats); } }; @@ -3377,15 +3377,15 @@ impl<'a> Parser<'a> { fn parse_pat_tuple_elements(&mut self) -> PResult<'a, Vec>> { let mut fields = vec![]; if !self.check(&token::CloseDelim(token::Paren)) { - fields.push(try!(self.parse_pat())); + fields.push(self.parse_pat()?); if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) { while self.eat(&token::Comma) && !self.check(&token::CloseDelim(token::Paren)) { - fields.push(try!(self.parse_pat())); + fields.push(self.parse_pat()?); } } if fields.len() == 1 { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; } } Ok(fields) @@ -3404,7 +3404,7 @@ impl<'a> Parser<'a> { if first { first = false; } else { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; if self.token == token::CloseDelim(token::Bracket) && (before_slice || !after.is_empty()) { @@ -3429,7 +3429,7 @@ impl<'a> Parser<'a> { } } - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; if before_slice && self.check(&token::DotDot) { self.bump(); slice = Some(subpat); @@ -3453,7 +3453,7 @@ impl<'a> Parser<'a> { if first { first = false; } else { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; // accept trailing commas if self.check(&token::CloseDelim(token::Brace)) { break } } @@ -3475,9 +3475,9 @@ impl<'a> Parser<'a> { // Check if a colon exists one ahead. This means we're parsing a fieldname. let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) { // Parsing a pattern of the form "fieldname: pat" - let fieldname = try!(self.parse_ident()); + let fieldname = self.parse_ident()?; self.bump(); - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; hi = pat.span.hi; (pat, fieldname, false) } else { @@ -3486,7 +3486,7 @@ impl<'a> Parser<'a> { let boxed_span_lo = self.span.lo; let is_ref = self.eat_keyword(keywords::Ref); let is_mut = self.eat_keyword(keywords::Mut); - let fieldname = try!(self.parse_ident()); + let fieldname = self.parse_ident()?; hi = self.last_span.hi; let bind_type = match (is_ref, is_mut) { @@ -3528,11 +3528,11 @@ impl<'a> Parser<'a> { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; (Some(qself), path) } else { // Parse an unqualified path - (None, try!(self.parse_path(LifetimeAndTypesWithColons))) + (None, self.parse_path(LifetimeAndTypesWithColons)?) }; let hi = self.last_span.hi; Ok(self.mk_expr(lo, hi, ExprKind::Path(qself, path), None)) @@ -3561,41 +3561,41 @@ impl<'a> Parser<'a> { } token::BinOp(token::And) | token::AndAnd => { // Parse &pat / &mut pat - try!(self.expect_and()); - let mutbl = try!(self.parse_mutability()); + self.expect_and()?; + let mutbl = self.parse_mutability()?; if let token::Lifetime(ident) = self.token { return Err(self.fatal(&format!("unexpected lifetime `{}` in pattern", ident))); } - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; pat = PatKind::Ref(subpat, mutbl); } token::OpenDelim(token::Paren) => { // Parse (pat,pat,pat,...) as tuple pattern self.bump(); - let fields = try!(self.parse_pat_tuple_elements()); - try!(self.expect(&token::CloseDelim(token::Paren))); + let fields = self.parse_pat_tuple_elements()?; + self.expect(&token::CloseDelim(token::Paren))?; pat = PatKind::Tup(fields); } token::OpenDelim(token::Bracket) => { // Parse [pat,pat,...] as slice pattern self.bump(); - let (before, slice, after) = try!(self.parse_pat_vec_elements()); - try!(self.expect(&token::CloseDelim(token::Bracket))); + let (before, slice, after) = self.parse_pat_vec_elements()?; + self.expect(&token::CloseDelim(token::Bracket))?; pat = PatKind::Vec(before, slice, after); } _ => { // At this point, token != _, &, &&, (, [ if self.eat_keyword(keywords::Mut) { // Parse mut ident @ pat - pat = try!(self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))); + pat = self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))?; } else if self.eat_keyword(keywords::Ref) { // Parse ref ident @ pat / ref mut ident @ pat - let mutbl = try!(self.parse_mutability()); - pat = try!(self.parse_pat_ident(BindingMode::ByRef(mutbl))); + let mutbl = self.parse_mutability()?; + pat = self.parse_pat_ident(BindingMode::ByRef(mutbl))?; } else if self.eat_keyword(keywords::Box) { // Parse box pat - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; pat = PatKind::Box(subpat); } else if self.is_path_start() { // Parse pattern starting with a path @@ -3607,13 +3607,13 @@ impl<'a> Parser<'a> { // Plain idents have some extra abilities here compared to general paths if self.look_ahead(1, |t| *t == token::Not) { // Parse macro invocation - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let ident_span = self.last_span; let path = ident_to_path(ident_span, ident); self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), |p| p.parse_token_tree())); + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), + SeqSep::none(), |p| p.parse_token_tree())?; let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; pat = PatKind::Mac(codemap::Spanned {node: mac, span: mk_sp(lo, self.last_span.hi)}); @@ -3622,17 +3622,17 @@ impl<'a> Parser<'a> { // This can give false positives and parse nullary enums, // they are dealt with later in resolve let binding_mode = BindingMode::ByValue(Mutability::Immutable); - pat = try!(self.parse_pat_ident(binding_mode)); + pat = self.parse_pat_ident(binding_mode)?; } } else { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; (Some(qself), path) } else { // Parse an unqualified path - (None, try!(self.parse_path(LifetimeAndTypesWithColons))) + (None, self.parse_path(LifetimeAndTypesWithColons)?) }; match self.token { token::DotDotDot => { @@ -3640,7 +3640,7 @@ impl<'a> Parser<'a> { let hi = self.last_span.hi; let begin = self.mk_expr(lo, hi, ExprKind::Path(qself, path), None); self.bump(); - let end = try!(self.parse_pat_range_end()); + let end = self.parse_pat_range_end()?; pat = PatKind::Range(begin, end); } token::OpenDelim(token::Brace) => { @@ -3666,14 +3666,14 @@ impl<'a> Parser<'a> { // This is a "top constructor only" pat self.bump(); self.bump(); - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; pat = PatKind::TupleStruct(path, None); } else { - let args = try!(self.parse_enum_variant_seq( + let args = self.parse_enum_variant_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_pat())); + |p| p.parse_pat())?; pat = PatKind::TupleStruct(path, Some(args)); } } @@ -3689,9 +3689,9 @@ impl<'a> Parser<'a> { } } else { // Try to parse everything else as literal with optional minus - let begin = try!(self.parse_pat_literal_maybe_minus()); + let begin = self.parse_pat_literal_maybe_minus()?; if self.eat(&token::DotDotDot) { - let end = try!(self.parse_pat_range_end()); + let end = self.parse_pat_range_end()?; pat = PatKind::Range(begin, end); } else { pat = PatKind::Lit(begin); @@ -3720,11 +3720,11 @@ impl<'a> Parser<'a> { return Err(self.span_fatal(span, &format!("expected identifier, found `{}`", tok_str))) } - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let last_span = self.last_span; let name = codemap::Spanned{span: last_span, node: ident}; let sub = if self.eat(&token::At) { - Some(try!(self.parse_pat())) + Some(self.parse_pat()?) } else { None }; @@ -3748,13 +3748,13 @@ impl<'a> Parser<'a> { /// Parse a local variable declaration fn parse_local(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.span.lo; - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; let mut ty = None; if self.eat(&token::Colon) { - ty = Some(try!(self.parse_ty_sum())); + ty = Some(self.parse_ty_sum()?); } - let init = try!(self.parse_initializer()); + let init = self.parse_initializer()?; Ok(P(ast::Local { ty: ty, pat: pat, @@ -3768,7 +3768,7 @@ impl<'a> Parser<'a> { /// Parse a "let" stmt fn parse_let(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.span.lo; - let local = try!(self.parse_local(attrs)); + let local = self.parse_local(attrs)?; Ok(P(spanned(lo, self.last_span.hi, DeclKind::Local(local)))) } @@ -3782,9 +3782,9 @@ impl<'a> Parser<'a> { if !self.token.is_plain_ident() { return Err(self.fatal("expected ident")); } - let name = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); + let name = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; Ok(spanned(lo, self.last_span.hi, ast::StructField_ { kind: NamedField(name, pr), id: ast::DUMMY_NODE_ID, @@ -3875,12 +3875,12 @@ impl<'a> Parser<'a> { fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option> { maybe_whole!(Some deref self, NtStmt); - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; let lo = self.span.lo; Ok(Some(if self.check_keyword(keywords::Let) { - try!(self.expect_keyword(keywords::Let)); - let decl = try!(self.parse_let(attrs.into_thin_attrs())); + self.expect_keyword(keywords::Let)?; + let decl = self.parse_let(attrs.into_thin_attrs())?; let hi = decl.span.hi; let stmt = StmtKind::Decl(decl, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) @@ -3891,12 +3891,12 @@ impl<'a> Parser<'a> { // Potential trouble: if we allow macros with paths instead of // idents, we'd need to look ahead past the whole path here... - let pth = try!(self.parse_path(NoTypesAllowed)); + let pth = self.parse_path(NoTypesAllowed)?; self.bump(); let id = match self.token { token::OpenDelim(_) => token::special_idents::invalid, // no special identifier - _ => try!(self.parse_ident()), + _ => self.parse_ident()?, }; // check that we're pointing at delimiters (need to check @@ -3919,12 +3919,12 @@ impl<'a> Parser<'a> { }, }; - let tts = try!(self.parse_unspanned_seq( + let tts = self.parse_unspanned_seq( &token::OpenDelim(delim), &token::CloseDelim(delim), SeqSep::none(), |p| p.parse_token_tree() - )); + )?; let hi = self.last_span.hi; let style = if delim == token::Brace { @@ -3962,8 +3962,8 @@ impl<'a> Parser<'a> { } else { // FIXME: Bad copy of attrs let restrictions = self.restrictions | Restrictions::NO_NONINLINE_MOD; - match try!(self.with_res(restrictions, - |this| this.parse_item_(attrs.clone(), false, true))) { + match self.with_res(restrictions, + |this| this.parse_item_(attrs.clone(), false, true))? { Some(i) => { let hi = i.span.hi; let decl = P(spanned(lo, hi, DeclKind::Item(i))); @@ -3990,8 +3990,8 @@ impl<'a> Parser<'a> { } // Remainder are line-expr stmts. - let e = try!(self.parse_expr_res( - Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))); + let e = self.parse_expr_res( + Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))?; let hi = e.span.hi; let stmt = StmtKind::Expr(e, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) @@ -4028,9 +4028,9 @@ impl<'a> Parser<'a> { maybe_whole!(pair_empty self, NtBlock); let lo = self.span.lo; - try!(self.expect(&token::OpenDelim(token::Brace))); - Ok((try!(self.parse_inner_attributes()), - try!(self.parse_block_tail(lo, BlockCheckMode::Default)))) + self.expect(&token::OpenDelim(token::Brace))?; + Ok((self.parse_inner_attributes()?, + self.parse_block_tail(lo, BlockCheckMode::Default)?)) } /// Parse the rest of a block expression or function body @@ -4048,7 +4048,7 @@ impl<'a> Parser<'a> { }; match node { StmtKind::Expr(e, _) => { - try!(self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)); + self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)?; } StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => { // statement macro without braces; might be an @@ -4066,13 +4066,13 @@ impl<'a> Parser<'a> { mac.and_then(|m| m.node), None); let lo = e.span.lo; - let e = try!(self.parse_dot_or_call_expr_with(e, lo, attrs)); - let e = try!(self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))); - try!(self.handle_expression_like_statement( + let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; + let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; + self.handle_expression_like_statement( e, span, &mut stmts, - &mut expr)); + &mut expr)?; } } } @@ -4104,7 +4104,7 @@ impl<'a> Parser<'a> { _ => { // all other kinds of statements: let mut hi = span.hi; if classify::stmt_ends_with_semi(&node) { - try!(self.commit_stmt_expecting(token::Semi)); + self.commit_stmt_expecting(token::Semi)?; hi = self.last_span.hi; } @@ -4205,7 +4205,7 @@ impl<'a> Parser<'a> { self.bump(); } token::ModSep | token::Ident(..) => { - let poly_trait_ref = try!(self.parse_poly_trait_ref()); + let poly_trait_ref = self.parse_poly_trait_ref()?; let modifier = if ate_question { if mode == BoundParsingMode::Modified { TraitBoundModifier::Maybe @@ -4233,13 +4233,13 @@ impl<'a> Parser<'a> { /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? fn parse_ty_param(&mut self) -> PResult<'a, TyParam> { let span = self.span; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; - let bounds = try!(self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)); + let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)?; let default = if self.check(&token::Eq) { self.bump(); - Some(try!(self.parse_ty_sum())) + Some(self.parse_ty_sum()?) } else { None }; @@ -4264,11 +4264,11 @@ impl<'a> Parser<'a> { maybe_whole!(self, NtGenerics); if self.eat(&token::Lt) { - let lifetime_defs = try!(self.parse_lifetime_defs()); + let lifetime_defs = self.parse_lifetime_defs()?; let mut seen_default = false; - let ty_params = try!(self.parse_seq_to_gt(Some(token::Comma), |p| { - try!(p.forbid_lifetime()); - let ty_param = try!(p.parse_ty_param()); + let ty_params = self.parse_seq_to_gt(Some(token::Comma), |p| { + p.forbid_lifetime()?; + let ty_param = p.parse_ty_param()?; if ty_param.default.is_some() { seen_default = true; } else if seen_default { @@ -4277,7 +4277,7 @@ impl<'a> Parser<'a> { "type parameters with a default must be trailing"); } Ok(ty_param) - })); + })?; Ok(ast::Generics { lifetimes: lifetime_defs, ty_params: ty_params, @@ -4295,7 +4295,7 @@ impl<'a> Parser<'a> { Vec>, Vec)> { let span_lo = self.span.lo; - let lifetimes = try!(self.parse_lifetimes(token::Comma)); + let lifetimes = self.parse_lifetimes(token::Comma)?; let missing_comma = !lifetimes.is_empty() && !self.token.is_like_gt() && @@ -4327,17 +4327,17 @@ impl<'a> Parser<'a> { } // First parse types. - let (types, returned) = try!(self.parse_seq_to_gt_or_return( + let (types, returned) = self.parse_seq_to_gt_or_return( Some(token::Comma), |p| { - try!(p.forbid_lifetime()); + p.forbid_lifetime()?; if p.look_ahead(1, |t| t == &token::Eq) { Ok(None) } else { - Ok(Some(try!(p.parse_ty_sum()))) + Ok(Some(p.parse_ty_sum()?)) } } - )); + )?; // If we found the `>`, don't continue. if !returned { @@ -4345,18 +4345,18 @@ impl<'a> Parser<'a> { } // Then parse type bindings. - let bindings = try!(self.parse_seq_to_gt( + let bindings = self.parse_seq_to_gt( Some(token::Comma), |p| { - try!(p.forbid_lifetime()); + p.forbid_lifetime()?; let lo = p.span.lo; - let ident = try!(p.parse_ident()); + let ident = p.parse_ident()?; let found_eq = p.eat(&token::Eq); if !found_eq { let span = p.span; p.span_warn(span, "whoops, no =?"); } - let ty = try!(p.parse_ty()); + let ty = p.parse_ty()?; let hi = ty.span.hi; let span = mk_sp(lo, hi); return Ok(TypeBinding{id: ast::DUMMY_NODE_ID, @@ -4365,7 +4365,7 @@ impl<'a> Parser<'a> { span: span, }); } - )); + )?; Ok((lifetimes, types.into_vec(), bindings.into_vec())) } @@ -4405,12 +4405,12 @@ impl<'a> Parser<'a> { token::Lifetime(..) => { let bounded_lifetime = - try!(self.parse_lifetime()); + self.parse_lifetime()?; self.eat(&token::Colon); let bounds = - try!(self.parse_lifetimes(token::BinOp(token::Plus))); + self.parse_lifetimes(token::BinOp(token::Plus))?; let hi = self.last_span.hi; let span = mk_sp(lo, hi); @@ -4429,18 +4429,18 @@ impl<'a> Parser<'a> { _ => { let bound_lifetimes = if self.eat_keyword(keywords::For) { // Higher ranked constraint. - try!(self.expect(&token::Lt)); - let lifetime_defs = try!(self.parse_lifetime_defs()); - try!(self.expect_gt()); + self.expect(&token::Lt)?; + let lifetime_defs = self.parse_lifetime_defs()?; + self.expect_gt()?; lifetime_defs } else { vec![] }; - let bounded_ty = try!(self.parse_ty()); + let bounded_ty = self.parse_ty()?; if self.eat(&token::Colon) { - let bounds = try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; let hi = self.last_span.hi; let span = mk_sp(lo, hi); @@ -4503,7 +4503,7 @@ impl<'a> Parser<'a> { let sp = self.span; let mut variadic = false; let args: Vec> = - try!(self.parse_unspanned_seq( + self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), @@ -4534,7 +4534,7 @@ impl<'a> Parser<'a> { } } } - )); + )?; let args: Vec<_> = args.into_iter().filter_map(|x| x).collect(); @@ -4549,8 +4549,8 @@ impl<'a> Parser<'a> { /// Parse the argument list and result type of a function declaration pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P> { - let (args, variadic) = try!(self.parse_fn_args(true, allow_variadic)); - let ret_ty = try!(self.parse_ret_ty()); + let (args, variadic) = self.parse_fn_args(true, allow_variadic)?; + let ret_ty = self.parse_ret_ty()?; Ok(P(FnDecl { inputs: args, @@ -4620,31 +4620,31 @@ impl<'a> Parser<'a> { if this.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - Ok(SelfKind::Region(None, Mutability::Immutable, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, Mutability::Immutable, this.expect_self_ident()?)) } else if this.look_ahead(1, |t| t.is_mutability()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let mutability = try!(this.parse_mutability()); - Ok(SelfKind::Region(None, mutability, try!(this.expect_self_ident()))) + let mutability = this.parse_mutability()?; + Ok(SelfKind::Region(None, mutability, this.expect_self_ident()?)) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let lifetime = try!(this.parse_lifetime()); - let ident = try!(this.expect_self_ident()); + let lifetime = this.parse_lifetime()?; + let ident = this.expect_self_ident()?; Ok(SelfKind::Region(Some(lifetime), Mutability::Immutable, ident)) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_mutability()) && this.look_ahead(3, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let lifetime = try!(this.parse_lifetime()); - let mutability = try!(this.parse_mutability()); - Ok(SelfKind::Region(Some(lifetime), mutability, try!(this.expect_self_ident()))) + let lifetime = this.parse_lifetime()?; + let mutability = this.parse_mutability()?; + Ok(SelfKind::Region(Some(lifetime), mutability, this.expect_self_ident()?)) } else { Ok(SelfKind::Static) } } - try!(self.expect(&token::OpenDelim(token::Paren))); + self.expect(&token::OpenDelim(token::Paren))?; // A bit of complexity and lookahead is needed here in order to be // backwards compatible. @@ -4655,7 +4655,7 @@ impl<'a> Parser<'a> { let mut mutbl_self = Mutability::Immutable; let explicit_self = match self.token { token::BinOp(token::And) => { - let eself = try!(maybe_parse_borrowed_explicit_self(self)); + let eself = maybe_parse_borrowed_explicit_self(self)?; self_ident_lo = self.last_span.lo; self_ident_hi = self.last_span.hi; eself @@ -4665,7 +4665,7 @@ impl<'a> Parser<'a> { // emitting cryptic "unexpected token" errors. self.bump(); let _mutability = if self.token.is_mutability() { - try!(self.parse_mutability()) + self.parse_mutability()? } else { Mutability::Immutable }; @@ -4679,24 +4679,24 @@ impl<'a> Parser<'a> { } token::Ident(..) => { if self.is_self_ident() { - let self_ident = try!(self.expect_self_ident()); + let self_ident = self.expect_self_ident()?; // Determine whether this is the fully explicit form, `self: // TYPE`. if self.eat(&token::Colon) { - SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(self.parse_ty_sum()?, self_ident) } else { SelfKind::Value(self_ident) } } else if self.token.is_mutability() && self.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { - mutbl_self = try!(self.parse_mutability()); - let self_ident = try!(self.expect_self_ident()); + mutbl_self = self.parse_mutability()?; + let self_ident = self.expect_self_ident()?; // Determine whether this is the fully explicit form, // `self: TYPE`. if self.eat(&token::Colon) { - SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(self.parse_ty_sum()?, self_ident) } else { SelfKind::Value(self_ident) } @@ -4750,11 +4750,11 @@ impl<'a> Parser<'a> { }; - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; let hi = self.span.hi; - let ret_ty = try!(self.parse_ret_ty()); + let ret_ty = self.parse_ret_ty()?; let fn_decl = P(FnDecl { inputs: fn_inputs, @@ -4771,8 +4771,8 @@ impl<'a> Parser<'a> { if self.eat(&token::OrOr) { Vec::new() } else { - try!(self.expect(&token::BinOp(token::Or))); - try!(self.parse_obsolete_closure_kind()); + self.expect(&token::BinOp(token::Or))?; + self.parse_obsolete_closure_kind()?; let args = self.parse_seq_to_before_end( &token::BinOp(token::Or), SeqSep::trailing_allowed(token::Comma), @@ -4782,7 +4782,7 @@ impl<'a> Parser<'a> { args } }; - let output = try!(self.parse_ret_ty()); + let output = self.parse_ret_ty()?; Ok(P(FnDecl { inputs: inputs_captures, @@ -4793,8 +4793,8 @@ impl<'a> Parser<'a> { /// Parse the name and optional generic types of a function header. fn parse_fn_header(&mut self) -> PResult<'a, (Ident, ast::Generics)> { - let id = try!(self.parse_ident()); - let generics = try!(self.parse_generics()); + let id = self.parse_ident()?; + let generics = self.parse_generics()?; Ok((id, generics)) } @@ -4817,10 +4817,10 @@ impl<'a> Parser<'a> { constness: Constness, abi: abi::Abi) -> PResult<'a, ItemInfo> { - let (ident, mut generics) = try!(self.parse_fn_header()); - let decl = try!(self.parse_fn_decl(false)); - generics.where_clause = try!(self.parse_where_clause()); - let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); + let (ident, mut generics) = self.parse_fn_header()?; + let decl = self.parse_fn_decl(false)?; + generics.where_clause = self.parse_where_clause()?; + let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; Ok((ident, ItemKind::Fn(decl, unsafety, constness, abi, generics, body), Some(inner_attrs))) } @@ -4842,18 +4842,18 @@ impl<'a> Parser<'a> { pub fn parse_fn_front_matter(&mut self) -> PResult<'a, (ast::Constness, ast::Unsafety, abi::Abi)> { let is_const_fn = self.eat_keyword(keywords::Const); - let unsafety = try!(self.parse_unsafety()); + let unsafety = self.parse_unsafety()?; let (constness, unsafety, abi) = if is_const_fn { (Constness::Const, unsafety, Abi::Rust) } else { let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; (Constness::NotConst, unsafety, abi) }; - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; Ok((constness, unsafety, abi)) } @@ -4861,27 +4861,27 @@ impl<'a> Parser<'a> { pub fn parse_impl_item(&mut self) -> PResult<'a, ImplItem> { maybe_whole!(no_clone_from_p self, NtImplItem); - let mut attrs = try!(self.parse_outer_attributes()); + let mut attrs = self.parse_outer_attributes()?; let lo = self.span.lo; - let vis = try!(self.parse_visibility()); - let defaultness = try!(self.parse_defaultness()); + let vis = self.parse_visibility()?; + let defaultness = self.parse_defaultness()?; let (name, node) = if self.eat_keyword(keywords::Type) { - let name = try!(self.parse_ident()); - try!(self.expect(&token::Eq)); - let typ = try!(self.parse_ty_sum()); - try!(self.expect(&token::Semi)); + let name = self.parse_ident()?; + self.expect(&token::Eq)?; + let typ = self.parse_ty_sum()?; + self.expect(&token::Semi)?; (name, ast::ImplItemKind::Type(typ)) } else if self.is_const_item() { - try!(self.expect_keyword(keywords::Const)); - let name = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let typ = try!(self.parse_ty_sum()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr()); - try!(self.commit_expr_expecting(&expr, token::Semi)); + self.expect_keyword(keywords::Const)?; + let name = self.parse_ident()?; + self.expect(&token::Colon)?; + let typ = self.parse_ty_sum()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr()?; + self.commit_expr_expecting(&expr, token::Semi)?; (name, ast::ImplItemKind::Const(typ, expr)) } else { - let (name, inner_attrs, node) = try!(self.parse_impl_method(vis)); + let (name, inner_attrs, node) = self.parse_impl_method(vis)?; attrs.extend(inner_attrs); (name, node) }; @@ -4935,31 +4935,31 @@ impl<'a> Parser<'a> { self.complain_if_pub_macro(vis, last_span); let lo = self.span.lo; - let pth = try!(self.parse_path(NoTypesAllowed)); - try!(self.expect(&token::Not)); + let pth = self.parse_path(NoTypesAllowed)?; + self.expect(&token::Not)?; // eat a matched-delimiter token tree: - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, self.last_span.hi) }; if delim != token::Brace { - try!(self.expect(&token::Semi)) + self.expect(&token::Semi)? } Ok((token::special_idents::invalid, vec![], ast::ImplItemKind::Macro(m))) } else { - let (constness, unsafety, abi) = try!(self.parse_fn_front_matter()); - let ident = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); - let (explicit_self, decl) = try!(self.parse_fn_decl_with_self(|p| { + let (constness, unsafety, abi) = self.parse_fn_front_matter()?; + let ident = self.parse_ident()?; + let mut generics = self.parse_generics()?; + let (explicit_self, decl) = self.parse_fn_decl_with_self(|p| { p.parse_arg() - })); - generics.where_clause = try!(self.parse_where_clause()); - let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); + })?; + generics.where_clause = self.parse_where_clause()?; + let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig { generics: generics, abi: abi, @@ -4974,15 +4974,15 @@ impl<'a> Parser<'a> { /// Parse trait Foo { ... } fn parse_item_trait(&mut self, unsafety: Unsafety) -> PResult<'a, ItemInfo> { - let ident = try!(self.parse_ident()); - let mut tps = try!(self.parse_generics()); + let ident = self.parse_ident()?; + let mut tps = self.parse_generics()?; // Parse supertrait bounds. - let bounds = try!(self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)?; - tps.where_clause = try!(self.parse_where_clause()); + tps.where_clause = self.parse_where_clause()?; - let meths = try!(self.parse_trait_items()); + let meths = self.parse_trait_items()?; Ok((ident, ItemKind::Trait(unsafety, tps, bounds, meths), None)) } @@ -4994,7 +4994,7 @@ impl<'a> Parser<'a> { let impl_span = self.span; // First, parse type parameters if necessary. - let mut generics = try!(self.parse_generics()); + let mut generics = self.parse_generics()?; // Special case: if the next identifier that follows is '(', don't // allow this to be parsed as a trait. @@ -5008,7 +5008,7 @@ impl<'a> Parser<'a> { }; // Parse the trait. - let mut ty = try!(self.parse_ty_sum()); + let mut ty = self.parse_ty_sum()?; // Parse traits, if necessary. let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) { @@ -5043,22 +5043,22 @@ impl<'a> Parser<'a> { allowed to have generics"); } - try!(self.expect(&token::OpenDelim(token::Brace))); - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; + self.expect(&token::CloseDelim(token::Brace))?; Ok((ast_util::impl_pretty_name(&opt_trait, None), ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None)) } else { if opt_trait.is_some() { - ty = try!(self.parse_ty_sum()); + ty = self.parse_ty_sum()?; } - generics.where_clause = try!(self.parse_where_clause()); + generics.where_clause = self.parse_where_clause()?; - try!(self.expect(&token::OpenDelim(token::Brace))); - let attrs = try!(self.parse_inner_attributes()); + self.expect(&token::OpenDelim(token::Brace))?; + let attrs = self.parse_inner_attributes()?; let mut impl_items = vec![]; while !self.eat(&token::CloseDelim(token::Brace)) { - impl_items.push(try!(self.parse_impl_item())); + impl_items.push(self.parse_impl_item()?); } Ok((ast_util::impl_pretty_name(&opt_trait, Some(&ty)), @@ -5070,16 +5070,16 @@ impl<'a> Parser<'a> { /// Parse a::B fn parse_trait_ref(&mut self) -> PResult<'a, TraitRef> { Ok(ast::TraitRef { - path: try!(self.parse_path(LifetimeAndTypesWithoutColons)), + path: self.parse_path(LifetimeAndTypesWithoutColons)?, ref_id: ast::DUMMY_NODE_ID, }) } fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(keywords::For) { - try!(self.expect(&token::Lt)); - let lifetime_defs = try!(self.parse_lifetime_defs()); - try!(self.expect_gt()); + self.expect(&token::Lt)?; + let lifetime_defs = self.parse_lifetime_defs()?; + self.expect_gt()?; Ok(lifetime_defs) } else { Ok(Vec::new()) @@ -5089,19 +5089,19 @@ impl<'a> Parser<'a> { /// Parse for<'l> a::B fn parse_poly_trait_ref(&mut self) -> PResult<'a, PolyTraitRef> { let lo = self.span.lo; - let lifetime_defs = try!(self.parse_late_bound_lifetime_defs()); + let lifetime_defs = self.parse_late_bound_lifetime_defs()?; Ok(ast::PolyTraitRef { bound_lifetimes: lifetime_defs, - trait_ref: try!(self.parse_trait_ref()), + trait_ref: self.parse_trait_ref()?, span: mk_sp(lo, self.last_span.hi), }) } /// Parse struct Foo { ... } fn parse_item_struct(&mut self) -> PResult<'a, ItemInfo> { - let class_name = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); + let class_name = self.parse_ident()?; + let mut generics = self.parse_generics()?; // There is a special case worth noting here, as reported in issue #17904. // If we are parsing a tuple struct it is the case that the where clause @@ -5118,25 +5118,25 @@ impl<'a> Parser<'a> { // struct. let vdata = if self.token.is_keyword(keywords::Where) { - generics.where_clause = try!(self.parse_where_clause()); + generics.where_clause = self.parse_where_clause()?; if self.eat(&token::Semi) { // If we see a: `struct Foo where T: Copy;` style decl. VariantData::Unit(ast::DUMMY_NODE_ID) } else { // If we see: `struct Foo where T: Copy { ... }` - VariantData::Struct(try!(self.parse_record_struct_body()), ast::DUMMY_NODE_ID) + VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID) } // No `where` so: `struct Foo;` } else if self.eat(&token::Semi) { VariantData::Unit(ast::DUMMY_NODE_ID) // Record-style struct definition } else if self.token == token::OpenDelim(token::Brace) { - VariantData::Struct(try!(self.parse_record_struct_body()), ast::DUMMY_NODE_ID) + VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID) // Tuple-style struct definition with optional where-clause. } else if self.token == token::OpenDelim(token::Paren) { - let body = VariantData::Tuple(try!(self.parse_tuple_struct_body()), ast::DUMMY_NODE_ID); - generics.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::Semi)); + let body = VariantData::Tuple(self.parse_tuple_struct_body()?, ast::DUMMY_NODE_ID); + generics.where_clause = self.parse_where_clause()?; + self.expect(&token::Semi)?; body } else { let token_str = self.this_token_to_string(); @@ -5151,7 +5151,7 @@ impl<'a> Parser<'a> { let mut fields = Vec::new(); if self.eat(&token::OpenDelim(token::Brace)) { while self.token != token::CloseDelim(token::Brace) { - fields.push(try!(self.parse_struct_decl_field())); + fields.push(self.parse_struct_decl_field()?); } self.bump(); @@ -5168,21 +5168,21 @@ impl<'a> Parser<'a> { pub fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec> { // This is the case where we find `struct Foo(T) where T: Copy;` // Unit like structs are handled in parse_item_struct function - let fields = try!(self.parse_unspanned_seq( + let fields = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), |p| { - let attrs = try!(p.parse_outer_attributes()); + let attrs = p.parse_outer_attributes()?; let lo = p.span.lo; let struct_field_ = ast::StructField_ { - kind: UnnamedField(try!(p.parse_visibility())), + kind: UnnamedField(p.parse_visibility()?), id: ast::DUMMY_NODE_ID, - ty: try!(p.parse_ty_sum()), + ty: p.parse_ty_sum()?, attrs: attrs, }; Ok(spanned(lo, p.span.hi, struct_field_)) - })); + })?; Ok(fields) } @@ -5192,7 +5192,7 @@ impl<'a> Parser<'a> { vis: Visibility, attrs: Vec ) -> PResult<'a, StructField> { - let a_var = try!(self.parse_name_and_ty(vis, attrs)); + let a_var = self.parse_name_and_ty(vis, attrs)?; match self.token { token::Comma => { self.bump(); @@ -5213,7 +5213,7 @@ impl<'a> Parser<'a> { /// Parse an element of a struct definition fn parse_struct_decl_field(&mut self) -> PResult<'a, StructField> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; if self.eat_keyword(keywords::Pub) { return self.parse_single_struct_field(Visibility::Public, attrs); @@ -5240,7 +5240,7 @@ impl<'a> Parser<'a> { /// Given a termination token, parse all of the items in a module fn parse_mod_items(&mut self, term: &token::Token, inner_lo: BytePos) -> PResult<'a, Mod> { let mut items = vec![]; - while let Some(item) = try!(self.parse_item()) { + while let Some(item) = self.parse_item()? { items.push(item); } @@ -5262,12 +5262,12 @@ impl<'a> Parser<'a> { } fn parse_item_const(&mut self, m: Option) -> PResult<'a, ItemInfo> { - let id = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); - try!(self.expect(&token::Eq)); - let e = try!(self.parse_expr()); - try!(self.commit_expr_expecting(&e, token::Semi)); + let id = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; + self.expect(&token::Eq)?; + let e = self.parse_expr()?; + self.commit_expr_expecting(&e, token::Semi)?; let item = match m { Some(m) => ItemKind::Static(ty, m, e), None => ItemKind::Const(ty, e), @@ -5278,18 +5278,18 @@ impl<'a> Parser<'a> { /// Parse a `mod { ... }` or `mod ;` item fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> { let id_span = self.span; - let id = try!(self.parse_ident()); + let id = self.parse_ident()?; if self.check(&token::Semi) { self.bump(); // This mod is in an external file. Let's go get it! - let (m, attrs) = try!(self.eval_src_mod(id, outer_attrs, id_span)); + let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span)?; Ok((id, m, Some(attrs))) } else { self.push_mod_path(id, outer_attrs); - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; let mod_inner_lo = self.span.lo; - let attrs = try!(self.parse_inner_attributes()); - let m = try!(self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)); + let attrs = self.parse_inner_attributes()?; + let m = self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)?; self.pop_mod_path(); Ok((id, ItemKind::Mod(m), Some(attrs))) } @@ -5408,9 +5408,9 @@ impl<'a> Parser<'a> { outer_attrs: &[ast::Attribute], id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec )> { - let ModulePathSuccess { path, owns_directory } = try!(self.submod_path(id, + let ModulePathSuccess { path, owns_directory } = self.submod_path(id, outer_attrs, - id_sp)); + id_sp)?; self.eval_src_mod_from_path(path, owns_directory, @@ -5447,8 +5447,8 @@ impl<'a> Parser<'a> { Some(name), id_sp); let mod_inner_lo = p0.span.lo; - let mod_attrs = try!(p0.parse_inner_attributes()); - let m0 = try!(p0.parse_mod_items(&token::Eof, mod_inner_lo)); + let mod_attrs = p0.parse_inner_attributes()?; + let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; self.sess.included_mod_stack.borrow_mut().pop(); Ok((ast::ItemKind::Mod(m0), mod_attrs)) } @@ -5456,13 +5456,13 @@ impl<'a> Parser<'a> { /// Parse a function declaration from a foreign module fn parse_item_foreign_fn(&mut self, vis: ast::Visibility, lo: BytePos, attrs: Vec) -> PResult<'a, ForeignItem> { - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; - let (ident, mut generics) = try!(self.parse_fn_header()); - let decl = try!(self.parse_fn_decl(true)); - generics.where_clause = try!(self.parse_where_clause()); + let (ident, mut generics) = self.parse_fn_header()?; + let decl = self.parse_fn_decl(true)?; + generics.where_clause = self.parse_where_clause()?; let hi = self.span.hi; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; Ok(ast::ForeignItem { ident: ident, attrs: attrs, @@ -5476,14 +5476,14 @@ impl<'a> Parser<'a> { /// Parse a static item from a foreign module fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: BytePos, attrs: Vec) -> PResult<'a, ForeignItem> { - try!(self.expect_keyword(keywords::Static)); + self.expect_keyword(keywords::Static)?; let mutbl = self.eat_keyword(keywords::Mut); - let ident = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); + let ident = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; let hi = self.span.hi; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; Ok(ForeignItem { ident: ident, attrs: attrs, @@ -5506,13 +5506,13 @@ impl<'a> Parser<'a> { attrs: Vec) -> PResult<'a, P> { - let crate_name = try!(self.parse_ident()); - let (maybe_path, ident) = if let Some(ident) = try!(self.parse_rename()) { + let crate_name = self.parse_ident()?; + let (maybe_path, ident) = if let Some(ident) = self.parse_rename()? { (Some(crate_name.name), ident) } else { (None, crate_name) }; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; let last_span = self.last_span; Ok(self.mk_item(lo, @@ -5539,17 +5539,17 @@ impl<'a> Parser<'a> { visibility: Visibility, mut attrs: Vec) -> PResult<'a, P> { - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; let abi = opt_abi.unwrap_or(Abi::C); - attrs.extend(try!(self.parse_inner_attributes())); + attrs.extend(self.parse_inner_attributes()?); let mut foreign_items = vec![]; - while let Some(item) = try!(self.parse_foreign_item()) { + while let Some(item) = self.parse_foreign_item()? { foreign_items.push(item); } - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; let last_span = self.last_span; let m = ast::ForeignMod { @@ -5566,12 +5566,12 @@ impl<'a> Parser<'a> { /// Parse type Foo = Bar; fn parse_item_type(&mut self) -> PResult<'a, ItemInfo> { - let ident = try!(self.parse_ident()); - let mut tps = try!(self.parse_generics()); - tps.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::Eq)); - let ty = try!(self.parse_ty_sum()); - try!(self.expect(&token::Semi)); + let ident = self.parse_ident()?; + let mut tps = self.parse_generics()?; + tps.where_clause = self.parse_where_clause()?; + self.expect(&token::Eq)?; + let ty = self.parse_ty_sum()?; + self.expect(&token::Semi)?; Ok((ident, ItemKind::Ty(ty, tps), None)) } @@ -5581,23 +5581,23 @@ impl<'a> Parser<'a> { let mut all_nullary = true; let mut any_disr = None; while self.token != token::CloseDelim(token::Brace) { - let variant_attrs = try!(self.parse_outer_attributes()); + let variant_attrs = self.parse_outer_attributes()?; let vlo = self.span.lo; let struct_def; let mut disr_expr = None; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; if self.check(&token::OpenDelim(token::Brace)) { // Parse a struct variant. all_nullary = false; - struct_def = VariantData::Struct(try!(self.parse_record_struct_body()), + struct_def = VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID); } else if self.check(&token::OpenDelim(token::Paren)) { all_nullary = false; - struct_def = VariantData::Tuple(try!(self.parse_tuple_struct_body()), + struct_def = VariantData::Tuple(self.parse_tuple_struct_body()?, ast::DUMMY_NODE_ID); } else if self.eat(&token::Eq) { - disr_expr = Some(try!(self.parse_expr())); + disr_expr = Some(self.parse_expr()?); any_disr = disr_expr.as_ref().map(|expr| expr.span); struct_def = VariantData::Unit(ast::DUMMY_NODE_ID); } else { @@ -5614,7 +5614,7 @@ impl<'a> Parser<'a> { if !self.eat(&token::Comma) { break; } } - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; match any_disr { Some(disr_span) if !all_nullary => self.span_err(disr_span, @@ -5627,12 +5627,12 @@ impl<'a> Parser<'a> { /// Parse an "enum" declaration fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> { - let id = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); - generics.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::OpenDelim(token::Brace))); + let id = self.parse_ident()?; + let mut generics = self.parse_generics()?; + generics.where_clause = self.parse_where_clause()?; + self.expect(&token::OpenDelim(token::Brace))?; - let enum_definition = try!(self.parse_enum_def(&generics)); + let enum_definition = self.parse_enum_def(&generics)?; Ok((id, ItemKind::Enum(enum_definition, generics), None)) } @@ -5687,12 +5687,12 @@ impl<'a> Parser<'a> { let lo = self.span.lo; - let visibility = try!(self.parse_visibility()); + let visibility = self.parse_visibility()?; if self.eat_keyword(keywords::Use) { // USE ITEM - let item_ = ItemKind::Use(try!(self.parse_view_path())); - try!(self.expect(&token::Semi)); + let item_ = ItemKind::Use(self.parse_view_path()?); + self.expect(&token::Semi)?; let last_span = self.last_span; let item = self.mk_item(lo, @@ -5706,16 +5706,16 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Extern) { if self.eat_keyword(keywords::Crate) { - return Ok(Some(try!(self.parse_item_extern_crate(lo, visibility, attrs)))); + return Ok(Some(self.parse_item_extern_crate(lo, visibility, attrs)?)); } - let opt_abi = try!(self.parse_opt_abi()); + let opt_abi = self.parse_opt_abi()?; if self.eat_keyword(keywords::Fn) { // EXTERN FUNCTION ITEM let abi = opt_abi.unwrap_or(Abi::C); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi)); + self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5725,10 +5725,10 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(Some(item)); } else if self.check(&token::OpenDelim(token::Brace)) { - return Ok(Some(try!(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs)))); + return Ok(Some(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs)?)); } - try!(self.unexpected()); + self.unexpected()?; } if self.eat_keyword(keywords::Static) { @@ -5738,7 +5738,7 @@ impl<'a> Parser<'a> { } else { Mutability::Immutable }; - let (ident, item_, extra_attrs) = try!(self.parse_item_const(Some(m))); + let (ident, item_, extra_attrs) = self.parse_item_const(Some(m))?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5760,7 +5760,7 @@ impl<'a> Parser<'a> { }; self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(unsafety, Constness::Const, Abi::Rust)); + self.parse_item_fn(unsafety, Constness::Const, Abi::Rust)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5778,7 +5778,7 @@ impl<'a> Parser<'a> { .fileline_help(last_span, "did you mean to declare a static?") .emit(); } - let (ident, item_, extra_attrs) = try!(self.parse_item_const(None)); + let (ident, item_, extra_attrs) = self.parse_item_const(None)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5792,10 +5792,10 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_keyword(keywords::Trait)) { // UNSAFE TRAIT ITEM - try!(self.expect_keyword(keywords::Unsafe)); - try!(self.expect_keyword(keywords::Trait)); + self.expect_keyword(keywords::Unsafe)?; + self.expect_keyword(keywords::Trait)?; let (ident, item_, extra_attrs) = - try!(self.parse_item_trait(ast::Unsafety::Unsafe)); + self.parse_item_trait(ast::Unsafety::Unsafe)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5809,9 +5809,9 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_keyword(keywords::Impl)) { // IMPL ITEM - try!(self.expect_keyword(keywords::Unsafe)); - try!(self.expect_keyword(keywords::Impl)); - let (ident, item_, extra_attrs) = try!(self.parse_item_impl(ast::Unsafety::Unsafe)); + self.expect_keyword(keywords::Unsafe)?; + self.expect_keyword(keywords::Impl)?; + let (ident, item_, extra_attrs) = self.parse_item_impl(ast::Unsafety::Unsafe)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5825,7 +5825,7 @@ impl<'a> Parser<'a> { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)); + self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5840,13 +5840,13 @@ impl<'a> Parser<'a> { // UNSAFE FUNCTION ITEM self.bump(); let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi)); + self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5859,7 +5859,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Mod) { // MODULE ITEM let (ident, item_, extra_attrs) = - try!(self.parse_item_mod(&attrs[..])); + self.parse_item_mod(&attrs[..])?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5871,7 +5871,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Type) { // TYPE ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_type()); + let (ident, item_, extra_attrs) = self.parse_item_type()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5883,7 +5883,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Enum) { // ENUM ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_enum()); + let (ident, item_, extra_attrs) = self.parse_item_enum()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5896,7 +5896,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Trait) { // TRAIT ITEM let (ident, item_, extra_attrs) = - try!(self.parse_item_trait(ast::Unsafety::Normal)); + self.parse_item_trait(ast::Unsafety::Normal)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5908,7 +5908,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Impl) { // IMPL ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_impl(ast::Unsafety::Normal)); + let (ident, item_, extra_attrs) = self.parse_item_impl(ast::Unsafety::Normal)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5920,7 +5920,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Struct) { // STRUCT ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_struct()); + let (ident, item_, extra_attrs) = self.parse_item_struct()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5935,21 +5935,21 @@ impl<'a> Parser<'a> { /// Parse a foreign item. fn parse_foreign_item(&mut self) -> PResult<'a, Option> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; let lo = self.span.lo; - let visibility = try!(self.parse_visibility()); + let visibility = self.parse_visibility()?; if self.check_keyword(keywords::Static) { // FOREIGN STATIC ITEM - return Ok(Some(try!(self.parse_item_foreign_static(visibility, lo, attrs)))); + return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { // FOREIGN FUNCTION ITEM - return Ok(Some(try!(self.parse_item_foreign_fn(visibility, lo, attrs)))); + return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } // FIXME #5668: this will occur for a macro invocation: - match try!(self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)) { + match self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)? { Some(item) => { return Err(self.span_fatal(item.span, "macros cannot expand to foreign items")); } @@ -5979,22 +5979,22 @@ impl<'a> Parser<'a> { let mac_lo = self.span.lo; // item macro. - let pth = try!(self.parse_path(NoTypesAllowed)); - try!(self.expect(&token::Not)); + let pth = self.parse_path(NoTypesAllowed)?; + self.expect(&token::Not)?; // a 'special' identifier (like what `macro_rules!` uses) // is optional. We should eventually unify invoc syntax // and remove this. let id = if self.token.is_plain_ident() { - try!(self.parse_ident()) + self.parse_ident()? } else { token::special_idents::invalid // no special identifier }; // eat a matched-delimiter token tree: - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; // single-variant-enum... : let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m, @@ -6038,7 +6038,7 @@ impl<'a> Parser<'a> { } pub fn parse_item(&mut self) -> PResult<'a, Option>> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; self.parse_item_(attrs, true, false) } @@ -6057,11 +6057,11 @@ impl<'a> Parser<'a> { if self.check(&token::OpenDelim(token::Brace)) { // use {foo,bar} - let idents = try!(self.parse_unspanned_seq( + let idents = self.parse_unspanned_seq( &token::OpenDelim(token::Brace), &token::CloseDelim(token::Brace), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_path_list_item())); + |p| p.parse_path_list_item())?; let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -6070,7 +6070,7 @@ impl<'a> Parser<'a> { return Ok(P(spanned(lo, self.span.hi, ViewPathList(path, idents)))); } - let first_ident = try!(self.parse_ident()); + let first_ident = self.parse_ident()?; let mut path = vec!(first_ident); if let token::ModSep = self.token { // foo::bar or foo::{a,b,c} or foo::* @@ -6079,18 +6079,18 @@ impl<'a> Parser<'a> { match self.token { token::Ident(..) => { - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; path.push(ident); } // foo::bar::{a,b,c} token::OpenDelim(token::Brace) => { - let idents = try!(self.parse_unspanned_seq( + let idents = self.parse_unspanned_seq( &token::OpenDelim(token::Brace), &token::CloseDelim(token::Brace), SeqSep::trailing_allowed(token::Comma), |p| p.parse_path_list_item() - )); + )?; let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -6140,7 +6140,7 @@ impl<'a> Parser<'a> { } }).collect() }; - rename_to = try!(self.parse_rename()).unwrap_or(rename_to); + rename_to = self.parse_rename()?.unwrap_or(rename_to); Ok(P(spanned(lo, self.last_span.hi, ViewPathSimple(rename_to, path)))) } @@ -6157,8 +6157,8 @@ impl<'a> Parser<'a> { pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate> { let lo = self.span.lo; Ok(ast::Crate { - attrs: try!(self.parse_inner_attributes()), - module: try!(self.parse_mod_items(&token::Eof, lo)), + attrs: self.parse_inner_attributes()?, + module: self.parse_mod_items(&token::Eof, lo)?, config: self.cfg.clone(), span: mk_sp(lo, self.span.lo), exported_macros: Vec::new(), diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 033ac9440bc..a02a10aa003 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -706,7 +706,7 @@ impl<'a> PartialEq for &'a str { impl Decodable for InternedString { fn decode(d: &mut D) -> Result { - Ok(intern(try!(d.read_str()).as_ref()).as_str()) + Ok(intern(d.read_str()?.as_ref()).as_str()) } } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index c1d922ea665..c381a3a8437 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -318,7 +318,7 @@ impl<'a> Printer<'a> { Token::Eof => { if !self.scan_stack_empty { self.check_stack(0); - try!(self.advance_left()); + self.advance_left()?; } self.indent(0); Ok(()) @@ -399,9 +399,9 @@ impl<'a> Printer<'a> { self.size[scanned] = SIZE_INFINITY; } } - try!(self.advance_left()); + self.advance_left()?; if self.left != self.right { - try!(self.check_stream()); + self.check_stream()?; } } Ok(()) @@ -464,7 +464,7 @@ impl<'a> Printer<'a> { _ => 0 }; - try!(self.print(left, left_size)); + self.print(left, left_size)?; self.left_total += len; @@ -532,7 +532,7 @@ impl<'a> Printer<'a> { } pub fn print_str(&mut self, s: &str) -> io::Result<()> { while self.pending_indentation > 0 { - try!(write!(self.out, " ")); + write!(self.out, " ")?; self.pending_indentation -= 1; } write!(self.out, "{}", s) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 430d13b87fc..9a3400025a8 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -123,16 +123,16 @@ pub fn print_crate<'a>(cm: &'a CodeMap, let list = attr::mk_list_item(InternedString::new("feature"), vec![prelude_import_meta]); let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), list); - try!(s.print_attribute(&fake_attr)); + s.print_attribute(&fake_attr)?; // #![no_std] let no_std_meta = attr::mk_word_item(InternedString::new("no_std")); let fake_attr = attr::mk_attr_inner(attr::mk_attr_id(), no_std_meta); - try!(s.print_attribute(&fake_attr)); + s.print_attribute(&fake_attr)?; } - try!(s.print_mod(&krate.module, &krate.attrs)); - try!(s.print_remaining_comments()); + s.print_mod(&krate.module, &krate.attrs)?; + s.print_remaining_comments()?; eof(&mut s.s) } @@ -386,10 +386,10 @@ pub fn fun_to_string(decl: &ast::FnDecl, generics: &ast::Generics) -> String { to_string(|s| { - try!(s.head("")); - try!(s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), - generics, opt_explicit_self, ast::Visibility::Inherited)); - try!(s.end()); // Close the head box + s.head("")?; + s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), + generics, opt_explicit_self, ast::Visibility::Inherited)?; + s.end()?; // Close the head box s.end() // Close the outer box }) } @@ -397,9 +397,9 @@ pub fn fun_to_string(decl: &ast::FnDecl, pub fn block_to_string(blk: &ast::Block) -> String { to_string(|s| { // containing cbox, will be closed by print-block at } - try!(s.cbox(INDENT_UNIT)); + s.cbox(INDENT_UNIT)?; // head-ibox, will be closed by print-block after { - try!(s.ibox(0)); + s.ibox(0)?; s.print_block(blk) }) } @@ -457,7 +457,7 @@ pub trait PrintState<'a> { fn literals(&self) -> &Option>; fn word_space(&mut self, w: &str) -> io::Result<()> { - try!(word(self.writer(), w)); + word(self.writer(), w)?; space(self.writer()) } @@ -486,7 +486,7 @@ pub trait PrintState<'a> { fn hardbreak_if_not_bol(&mut self) -> io::Result<()> { if !self.is_bol() { - try!(hardbreak(self.writer())) + hardbreak(self.writer())? } Ok(()) } @@ -510,11 +510,11 @@ pub trait PrintState<'a> { fn commasep(&mut self, b: Breaks, elts: &[T], mut op: F) -> io::Result<()> where F: FnMut(&mut Self, &T) -> io::Result<()>, { - try!(self.rbox(0, b)); + self.rbox(0, b)?; let mut first = true; for elt in elts { - if first { first = false; } else { try!(self.word_space(",")); } - try!(op(self, elt)); + if first { first = false; } else { self.word_space(",")?; } + op(self, elt)?; } self.end() } @@ -546,7 +546,7 @@ pub trait PrintState<'a> { match self.next_comment() { Some(ref cmnt) => { if (*cmnt).pos < pos { - try!(self.print_comment(cmnt)); + self.print_comment(cmnt)?; self.cur_cmnt_and_lit().cur_cmnt += 1; } else { break; } } @@ -561,34 +561,34 @@ pub trait PrintState<'a> { match cmnt.style { comments::Mixed => { assert_eq!(cmnt.lines.len(), 1); - try!(zerobreak(self.writer())); - try!(word(self.writer(), &cmnt.lines[0])); + zerobreak(self.writer())?; + word(self.writer(), &cmnt.lines[0])?; zerobreak(self.writer()) } comments::Isolated => { - try!(self.hardbreak_if_not_bol()); + self.hardbreak_if_not_bol()?; for line in &cmnt.lines { // Don't print empty lines because they will end up as trailing // whitespace if !line.is_empty() { - try!(word(self.writer(), &line[..])); + word(self.writer(), &line[..])?; } - try!(hardbreak(self.writer())); + hardbreak(self.writer())?; } Ok(()) } comments::Trailing => { - try!(word(self.writer(), " ")); + word(self.writer(), " ")?; if cmnt.lines.len() == 1 { - try!(word(self.writer(), &cmnt.lines[0])); + word(self.writer(), &cmnt.lines[0])?; hardbreak(self.writer()) } else { - try!(self.ibox(0)); + self.ibox(0)?; for line in &cmnt.lines { if !line.is_empty() { - try!(word(self.writer(), &line[..])); + word(self.writer(), &line[..])?; } - try!(hardbreak(self.writer())); + hardbreak(self.writer())?; } self.end() } @@ -600,7 +600,7 @@ pub trait PrintState<'a> { _ => false }; if is_semi || self.is_begin() || self.is_end() { - try!(hardbreak(self.writer())); + hardbreak(self.writer())?; } hardbreak(self.writer()) } @@ -622,7 +622,7 @@ pub trait PrintState<'a> { } fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> { - try!(self.maybe_print_comment(lit.span.lo)); + self.maybe_print_comment(lit.span.lo)?; match self.next_lit(lit.span.lo) { Some(ref ltrl) => { return word(self.writer(), &(*ltrl).lit); @@ -728,15 +728,15 @@ pub trait PrintState<'a> { let mut count = 0; for attr in attrs { if attr.node.style == kind { - try!(self.print_attribute_inline(attr, is_inline)); + self.print_attribute_inline(attr, is_inline)?; if is_inline { - try!(self.nbsp()); + self.nbsp()?; } count += 1; } } if count > 0 && trailing_hardbreak && !is_inline { - try!(self.hardbreak_if_not_bol()); + self.hardbreak_if_not_bol()?; } Ok(()) } @@ -748,47 +748,47 @@ pub trait PrintState<'a> { fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> io::Result<()> { if !is_inline { - try!(self.hardbreak_if_not_bol()); + self.hardbreak_if_not_bol()?; } - try!(self.maybe_print_comment(attr.span.lo)); + self.maybe_print_comment(attr.span.lo)?; if attr.node.is_sugared_doc { - try!(word(self.writer(), &attr.value_str().unwrap())); + word(self.writer(), &attr.value_str().unwrap())?; hardbreak(self.writer()) } else { match attr.node.style { - ast::AttrStyle::Inner => try!(word(self.writer(), "#![")), - ast::AttrStyle::Outer => try!(word(self.writer(), "#[")), + ast::AttrStyle::Inner => word(self.writer(), "#![")?, + ast::AttrStyle::Outer => word(self.writer(), "#[")?, } - try!(self.print_meta_item(&attr.meta())); + self.print_meta_item(&attr.meta())?; word(self.writer(), "]") } } fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> { - try!(self.ibox(INDENT_UNIT)); + self.ibox(INDENT_UNIT)?; match item.node { ast::MetaItemKind::Word(ref name) => { - try!(word(self.writer(), &name)); + word(self.writer(), &name)?; } ast::MetaItemKind::NameValue(ref name, ref value) => { - try!(self.word_space(&name[..])); - try!(self.word_space("=")); - try!(self.print_literal(value)); + self.word_space(&name[..])?; + self.word_space("=")?; + self.print_literal(value)?; } ast::MetaItemKind::List(ref name, ref items) => { - try!(word(self.writer(), &name)); - try!(self.popen()); - try!(self.commasep(Consistent, + word(self.writer(), &name)?; + self.popen()?; + self.commasep(Consistent, &items[..], - |s, i| s.print_meta_item(&i))); - try!(self.pclose()); + |s, i| s.print_meta_item(&i))?; + self.pclose()?; } } self.end() } fn space_if_not_bol(&mut self) -> io::Result<()> { - if !self.is_bol() { try!(space(self.writer())); } + if !self.is_bol() { space(self.writer())?; } Ok(()) } @@ -824,24 +824,24 @@ impl<'a> State<'a> { } pub fn word_nbsp(&mut self, w: &str) -> io::Result<()> { - try!(word(&mut self.s, w)); + word(&mut self.s, w)?; self.nbsp() } pub fn head(&mut self, w: &str) -> io::Result<()> { // outer-box is consistent - try!(self.cbox(INDENT_UNIT)); + self.cbox(INDENT_UNIT)?; // head-box is inconsistent - try!(self.ibox(w.len() + 1)); + self.ibox(w.len() + 1)?; // keyword that starts the head if !w.is_empty() { - try!(self.word_nbsp(w)); + self.word_nbsp(w)?; } Ok(()) } pub fn bopen(&mut self) -> io::Result<()> { - try!(word(&mut self.s, "{")); + word(&mut self.s, "{")?; self.end() // close the head-box } @@ -851,11 +851,11 @@ impl<'a> State<'a> { } pub fn bclose_maybe_open(&mut self, span: codemap::Span, 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, "}")); + self.maybe_print_comment(span.hi)?; + self.break_offset_if_not_bol(1, -(indented as isize))?; + word(&mut self.s, "}")?; if close_box { - try!(self.end()); // close the outer-box + self.end()?; // close the outer-box } Ok(()) } @@ -888,10 +888,10 @@ 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) -> io::Result<()> { - try!(word(&mut self.s, "/*")); - try!(space(&mut self.s)); - try!(word(&mut self.s, &text[..])); - try!(space(&mut self.s)); + word(&mut self.s, "/*")?; + space(&mut self.s)?; + word(&mut self.s, &text[..])?; + space(&mut self.s)?; word(&mut self.s, "*/") } @@ -905,18 +905,18 @@ impl<'a> State<'a> { F: FnMut(&mut State, &T) -> io::Result<()>, G: FnMut(&T) -> codemap::Span, { - try!(self.rbox(0, b)); + self.rbox(0, b)?; let len = elts.len(); let mut i = 0; for elt in elts { - try!(self.maybe_print_comment(get_span(elt).hi)); - try!(op(self, elt)); + self.maybe_print_comment(get_span(elt).hi)?; + op(self, elt)?; i += 1; if i < len { - try!(word(&mut self.s, ",")); - try!(self.maybe_print_trailing_comment(get_span(elt), - Some(get_span(&elts[i]).hi))); - try!(self.space_if_not_bol()); + word(&mut self.s, ",")?; + self.maybe_print_trailing_comment(get_span(elt), + Some(get_span(&elts[i]).hi))?; + self.space_if_not_bol()?; } } self.end() @@ -929,18 +929,18 @@ impl<'a> State<'a> { pub fn print_mod(&mut self, _mod: &ast::Mod, attrs: &[ast::Attribute]) -> io::Result<()> { - try!(self.print_inner_attributes(attrs)); + self.print_inner_attributes(attrs)?; for item in &_mod.items { - try!(self.print_item(&item)); + self.print_item(&item)?; } Ok(()) } pub fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod, attrs: &[ast::Attribute]) -> io::Result<()> { - try!(self.print_inner_attributes(attrs)); + self.print_inner_attributes(attrs)?; for item in &nmod.items { - try!(self.print_foreign_item(item)); + self.print_foreign_item(item)?; } Ok(()) } @@ -948,47 +948,47 @@ impl<'a> State<'a> { pub fn print_opt_lifetime(&mut self, lifetime: &Option) -> io::Result<()> { if let Some(l) = *lifetime { - try!(self.print_lifetime(&l)); - try!(self.nbsp()); + self.print_lifetime(&l)?; + self.nbsp()?; } Ok(()) } pub fn print_type(&mut self, ty: &ast::Ty) -> io::Result<()> { - try!(self.maybe_print_comment(ty.span.lo)); - try!(self.ibox(0)); + self.maybe_print_comment(ty.span.lo)?; + self.ibox(0)?; match ty.node { ast::TyKind::Vec(ref ty) => { - try!(word(&mut self.s, "[")); - try!(self.print_type(&ty)); - try!(word(&mut self.s, "]")); + word(&mut self.s, "[")?; + self.print_type(&ty)?; + word(&mut self.s, "]")?; } ast::TyKind::Ptr(ref mt) => { - try!(word(&mut self.s, "*")); + word(&mut self.s, "*")?; match mt.mutbl { - ast::Mutability::Mutable => try!(self.word_nbsp("mut")), - ast::Mutability::Immutable => try!(self.word_nbsp("const")), + ast::Mutability::Mutable => self.word_nbsp("mut")?, + ast::Mutability::Immutable => self.word_nbsp("const")?, } - try!(self.print_type(&mt.ty)); + self.print_type(&mt.ty)?; } ast::TyKind::Rptr(ref lifetime, ref mt) => { - try!(word(&mut self.s, "&")); - try!(self.print_opt_lifetime(lifetime)); - try!(self.print_mt(mt)); + word(&mut self.s, "&")?; + self.print_opt_lifetime(lifetime)?; + self.print_mt(mt)?; } ast::TyKind::Tup(ref elts) => { - try!(self.popen()); - try!(self.commasep(Inconsistent, &elts[..], - |s, ty| s.print_type(&ty))); + self.popen()?; + self.commasep(Inconsistent, &elts[..], + |s, ty| s.print_type(&ty))?; if elts.len() == 1 { - try!(word(&mut self.s, ",")); + word(&mut self.s, ",")?; } - try!(self.pclose()); + self.pclose()?; } ast::TyKind::Paren(ref typ) => { - try!(self.popen()); - try!(self.print_type(&typ)); - try!(self.pclose()); + self.popen()?; + self.print_type(&typ)?; + self.pclose()?; } ast::TyKind::BareFn(ref f) => { let generics = ast::Generics { @@ -999,43 +999,43 @@ impl<'a> State<'a> { predicates: Vec::new(), }, }; - try!(self.print_ty_fn(f.abi, + self.print_ty_fn(f.abi, f.unsafety, &f.decl, None, &generics, - None)); + None)?; } ast::TyKind::Path(None, ref path) => { - try!(self.print_path(path, false, 0)); + self.print_path(path, false, 0)?; } ast::TyKind::Path(Some(ref qself), ref path) => { - try!(self.print_qpath(path, qself, false)) + self.print_qpath(path, qself, false)? } ast::TyKind::ObjectSum(ref ty, ref bounds) => { - try!(self.print_type(&ty)); - try!(self.print_bounds("+", &bounds[..])); + self.print_type(&ty)?; + self.print_bounds("+", &bounds[..])?; } ast::TyKind::PolyTraitRef(ref bounds) => { - try!(self.print_bounds("", &bounds[..])); + self.print_bounds("", &bounds[..])?; } ast::TyKind::FixedLengthVec(ref ty, ref v) => { - try!(word(&mut self.s, "[")); - try!(self.print_type(&ty)); - try!(word(&mut self.s, "; ")); - try!(self.print_expr(&v)); - try!(word(&mut self.s, "]")); + word(&mut self.s, "[")?; + self.print_type(&ty)?; + word(&mut self.s, "; ")?; + self.print_expr(&v)?; + word(&mut self.s, "]")?; } ast::TyKind::Typeof(ref e) => { - try!(word(&mut self.s, "typeof(")); - try!(self.print_expr(&e)); - try!(word(&mut self.s, ")")); + word(&mut self.s, "typeof(")?; + self.print_expr(&e)?; + word(&mut self.s, ")")?; } ast::TyKind::Infer => { - try!(word(&mut self.s, "_")); + word(&mut self.s, "_")?; } ast::TyKind::Mac(ref m) => { - try!(self.print_mac(m, token::Paren)); + self.print_mac(m, token::Paren)?; } } self.end() @@ -1043,31 +1043,31 @@ impl<'a> State<'a> { pub fn print_foreign_item(&mut self, 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)); + self.hardbreak_if_not_bol()?; + self.maybe_print_comment(item.span.lo)?; + self.print_outer_attributes(&item.attrs)?; match item.node { ast::ForeignItemKind::Fn(ref decl, ref generics) => { - try!(self.head("")); - try!(self.print_fn(decl, ast::Unsafety::Normal, + self.head("")?; + self.print_fn(decl, ast::Unsafety::Normal, ast::Constness::NotConst, Abi::Rust, Some(item.ident), - generics, None, item.vis)); - try!(self.end()); // end head-ibox - try!(word(&mut self.s, ";")); + generics, None, item.vis)?; + self.end()?; // end head-ibox + word(&mut self.s, ";")?; self.end() // end the outer fn box } ast::ForeignItemKind::Static(ref t, m) => { - try!(self.head(&visibility_qualified(item.vis, - "static"))); + self.head(&visibility_qualified(item.vis, + "static"))?; if m { - try!(self.word_space("mut")); + self.word_space("mut")?; } - try!(self.print_ident(item.ident)); - try!(self.word_space(":")); - try!(self.print_type(&t)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end the head-ibox + self.print_ident(item.ident)?; + self.word_space(":")?; + self.print_type(&t)?; + word(&mut self.s, ";")?; + self.end()?; // end the head-ibox self.end() // end the outer cbox } } @@ -1080,15 +1080,15 @@ impl<'a> State<'a> { vis: ast::Visibility) -> io::Result<()> { - try!(word(&mut self.s, &visibility_qualified(vis, ""))); - try!(self.word_space("const")); - try!(self.print_ident(ident)); - try!(self.word_space(":")); - try!(self.print_type(ty)); + word(&mut self.s, &visibility_qualified(vis, ""))?; + self.word_space("const")?; + self.print_ident(ident)?; + self.word_space(":")?; + self.print_type(ty)?; if let Some(expr) = default { - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_expr(expr)); + space(&mut self.s)?; + self.word_space("=")?; + self.print_expr(expr)?; } word(&mut self.s, ";") } @@ -1098,87 +1098,87 @@ impl<'a> State<'a> { bounds: Option<&ast::TyParamBounds>, ty: Option<&ast::Ty>) -> io::Result<()> { - try!(self.word_space("type")); - try!(self.print_ident(ident)); + self.word_space("type")?; + self.print_ident(ident)?; if let Some(bounds) = bounds { - try!(self.print_bounds(":", bounds)); + self.print_bounds(":", bounds)?; } if let Some(ty) = ty { - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_type(ty)); + space(&mut self.s)?; + self.word_space("=")?; + self.print_type(ty)?; } word(&mut self.s, ";") } /// Pretty-print an item 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)); - try!(self.ann.pre(self, NodeItem(item))); + self.hardbreak_if_not_bol()?; + self.maybe_print_comment(item.span.lo)?; + self.print_outer_attributes(&item.attrs)?; + self.ann.pre(self, NodeItem(item))?; match item.node { ast::ItemKind::ExternCrate(ref optional_path) => { - try!(self.head(&visibility_qualified(item.vis, - "extern crate"))); + self.head(&visibility_qualified(item.vis, + "extern crate"))?; if let Some(p) = *optional_path { let val = p.as_str(); if val.contains("-") { - try!(self.print_string(&val, ast::StrStyle::Cooked)); + self.print_string(&val, ast::StrStyle::Cooked)?; } else { - try!(self.print_name(p)); + self.print_name(p)?; } - try!(space(&mut self.s)); - try!(word(&mut self.s, "as")); - try!(space(&mut self.s)); + space(&mut self.s)?; + word(&mut self.s, "as")?; + space(&mut self.s)?; } - try!(self.print_ident(item.ident)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end inner head-block - try!(self.end()); // end outer head-block + self.print_ident(item.ident)?; + word(&mut self.s, ";")?; + self.end()?; // end inner head-block + self.end()?; // end outer head-block } ast::ItemKind::Use(ref vp) => { - try!(self.head(&visibility_qualified(item.vis, - "use"))); - try!(self.print_view_path(&vp)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end inner head-block - try!(self.end()); // end outer head-block + self.head(&visibility_qualified(item.vis, + "use"))?; + self.print_view_path(&vp)?; + word(&mut self.s, ";")?; + self.end()?; // end inner head-block + self.end()?; // end outer head-block } ast::ItemKind::Static(ref ty, m, ref expr) => { - try!(self.head(&visibility_qualified(item.vis, - "static"))); + self.head(&visibility_qualified(item.vis, + "static"))?; if m == ast::Mutability::Mutable { - try!(self.word_space("mut")); + self.word_space("mut")?; } - try!(self.print_ident(item.ident)); - try!(self.word_space(":")); - try!(self.print_type(&ty)); - try!(space(&mut self.s)); - try!(self.end()); // end the head-ibox + self.print_ident(item.ident)?; + self.word_space(":")?; + self.print_type(&ty)?; + space(&mut self.s)?; + self.end()?; // end the head-ibox - try!(self.word_space("=")); - try!(self.print_expr(&expr)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end the outer cbox + self.word_space("=")?; + self.print_expr(&expr)?; + word(&mut self.s, ";")?; + self.end()?; // end the outer cbox } ast::ItemKind::Const(ref ty, ref expr) => { - try!(self.head(&visibility_qualified(item.vis, - "const"))); - try!(self.print_ident(item.ident)); - try!(self.word_space(":")); - try!(self.print_type(&ty)); - try!(space(&mut self.s)); - try!(self.end()); // end the head-ibox - - try!(self.word_space("=")); - try!(self.print_expr(&expr)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end the outer cbox + self.head(&visibility_qualified(item.vis, + "const"))?; + self.print_ident(item.ident)?; + self.word_space(":")?; + self.print_type(&ty)?; + space(&mut self.s)?; + self.end()?; // end the head-ibox + + self.word_space("=")?; + self.print_expr(&expr)?; + word(&mut self.s, ";")?; + self.end()?; // end the outer cbox } ast::ItemKind::Fn(ref decl, unsafety, constness, abi, ref typarams, ref body) => { - try!(self.head("")); - try!(self.print_fn( + self.head("")?; + self.print_fn( decl, unsafety, constness, @@ -1187,66 +1187,66 @@ impl<'a> State<'a> { typarams, None, item.vis - )); - try!(word(&mut self.s, " ")); - try!(self.print_block_with_attrs(&body, &item.attrs)); + )?; + word(&mut self.s, " ")?; + self.print_block_with_attrs(&body, &item.attrs)?; } ast::ItemKind::Mod(ref _mod) => { - try!(self.head(&visibility_qualified(item.vis, - "mod"))); - try!(self.print_ident(item.ident)); - try!(self.nbsp()); - try!(self.bopen()); - try!(self.print_mod(_mod, &item.attrs)); - try!(self.bclose(item.span)); + self.head(&visibility_qualified(item.vis, + "mod"))?; + self.print_ident(item.ident)?; + self.nbsp()?; + self.bopen()?; + self.print_mod(_mod, &item.attrs)?; + self.bclose(item.span)?; } ast::ItemKind::ForeignMod(ref nmod) => { - try!(self.head("extern")); - try!(self.word_nbsp(&nmod.abi.to_string())); - try!(self.bopen()); - try!(self.print_foreign_mod(nmod, &item.attrs)); - try!(self.bclose(item.span)); + self.head("extern")?; + self.word_nbsp(&nmod.abi.to_string())?; + self.bopen()?; + self.print_foreign_mod(nmod, &item.attrs)?; + self.bclose(item.span)?; } ast::ItemKind::Ty(ref ty, ref params) => { - try!(self.ibox(INDENT_UNIT)); - try!(self.ibox(0)); - try!(self.word_nbsp(&visibility_qualified(item.vis, "type"))); - try!(self.print_ident(item.ident)); - try!(self.print_generics(params)); - try!(self.end()); // end the inner ibox - - try!(self.print_where_clause(¶ms.where_clause)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_type(&ty)); - try!(word(&mut self.s, ";")); - try!(self.end()); // end the outer ibox + self.ibox(INDENT_UNIT)?; + self.ibox(0)?; + self.word_nbsp(&visibility_qualified(item.vis, "type"))?; + self.print_ident(item.ident)?; + self.print_generics(params)?; + self.end()?; // end the inner ibox + + self.print_where_clause(¶ms.where_clause)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_type(&ty)?; + word(&mut self.s, ";")?; + self.end()?; // end the outer ibox } ast::ItemKind::Enum(ref enum_definition, ref params) => { - try!(self.print_enum_def( + self.print_enum_def( enum_definition, params, item.ident, item.span, item.vis - )); + )?; } ast::ItemKind::Struct(ref struct_def, ref generics) => { - try!(self.head(&visibility_qualified(item.vis,"struct"))); - try!(self.print_struct(&struct_def, generics, item.ident, item.span, true)); + self.head(&visibility_qualified(item.vis,"struct"))?; + self.print_struct(&struct_def, generics, item.ident, item.span, true)?; } ast::ItemKind::DefaultImpl(unsafety, ref trait_ref) => { - try!(self.head("")); - try!(self.print_visibility(item.vis)); - try!(self.print_unsafety(unsafety)); - try!(self.word_nbsp("impl")); - try!(self.print_trait_ref(trait_ref)); - try!(space(&mut self.s)); - try!(self.word_space("for")); - try!(self.word_space("..")); - try!(self.bopen()); - try!(self.bclose(item.span)); + self.head("")?; + self.print_visibility(item.vis)?; + self.print_unsafety(unsafety)?; + self.word_nbsp("impl")?; + self.print_trait_ref(trait_ref)?; + space(&mut self.s)?; + self.word_space("for")?; + self.word_space("..")?; + self.bopen()?; + self.bclose(item.span)?; } ast::ItemKind::Impl(unsafety, polarity, @@ -1254,80 +1254,80 @@ impl<'a> State<'a> { ref opt_trait, ref ty, ref impl_items) => { - try!(self.head("")); - try!(self.print_visibility(item.vis)); - try!(self.print_unsafety(unsafety)); - try!(self.word_nbsp("impl")); + self.head("")?; + self.print_visibility(item.vis)?; + self.print_unsafety(unsafety)?; + self.word_nbsp("impl")?; if generics.is_parameterized() { - try!(self.print_generics(generics)); - try!(space(&mut self.s)); + self.print_generics(generics)?; + space(&mut self.s)?; } match polarity { ast::ImplPolarity::Negative => { - try!(word(&mut self.s, "!")); + word(&mut self.s, "!")?; }, _ => {} } match *opt_trait { Some(ref t) => { - try!(self.print_trait_ref(t)); - try!(space(&mut self.s)); - try!(self.word_space("for")); + self.print_trait_ref(t)?; + space(&mut self.s)?; + self.word_space("for")?; } None => {} } - try!(self.print_type(&ty)); - try!(self.print_where_clause(&generics.where_clause)); + self.print_type(&ty)?; + self.print_where_clause(&generics.where_clause)?; - try!(space(&mut self.s)); - try!(self.bopen()); - try!(self.print_inner_attributes(&item.attrs)); + space(&mut self.s)?; + self.bopen()?; + self.print_inner_attributes(&item.attrs)?; for impl_item in impl_items { - try!(self.print_impl_item(impl_item)); + self.print_impl_item(impl_item)?; } - try!(self.bclose(item.span)); + self.bclose(item.span)?; } ast::ItemKind::Trait(unsafety, ref generics, ref bounds, ref trait_items) => { - try!(self.head("")); - try!(self.print_visibility(item.vis)); - try!(self.print_unsafety(unsafety)); - try!(self.word_nbsp("trait")); - try!(self.print_ident(item.ident)); - try!(self.print_generics(generics)); + self.head("")?; + self.print_visibility(item.vis)?; + self.print_unsafety(unsafety)?; + self.word_nbsp("trait")?; + self.print_ident(item.ident)?; + self.print_generics(generics)?; let mut real_bounds = Vec::with_capacity(bounds.len()); for b in bounds.iter() { if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = *b { - try!(space(&mut self.s)); - try!(self.word_space("for ?")); - try!(self.print_trait_ref(&ptr.trait_ref)); + space(&mut self.s)?; + self.word_space("for ?")?; + self.print_trait_ref(&ptr.trait_ref)?; } else { real_bounds.push(b.clone()); } } - try!(self.print_bounds(":", &real_bounds[..])); - try!(self.print_where_clause(&generics.where_clause)); - try!(word(&mut self.s, " ")); - try!(self.bopen()); + self.print_bounds(":", &real_bounds[..])?; + self.print_where_clause(&generics.where_clause)?; + word(&mut self.s, " ")?; + self.bopen()?; for trait_item in trait_items { - try!(self.print_trait_item(trait_item)); + self.print_trait_item(trait_item)?; } - try!(self.bclose(item.span)); + self.bclose(item.span)?; } ast::ItemKind::Mac(codemap::Spanned { ref node, .. }) => { - try!(self.print_visibility(item.vis)); - try!(self.print_path(&node.path, false, 0)); - try!(word(&mut self.s, "! ")); - try!(self.print_ident(item.ident)); - try!(self.cbox(INDENT_UNIT)); - try!(self.popen()); - try!(self.print_tts(&node.tts[..])); - try!(self.pclose()); - try!(word(&mut self.s, ";")); - try!(self.end()); + self.print_visibility(item.vis)?; + self.print_path(&node.path, false, 0)?; + word(&mut self.s, "! ")?; + self.print_ident(item.ident)?; + self.cbox(INDENT_UNIT)?; + self.popen()?; + self.print_tts(&node.tts[..])?; + self.pclose()?; + word(&mut self.s, ";")?; + self.end()?; } } self.ann.post(self, NodeItem(item)) @@ -1339,22 +1339,22 @@ impl<'a> State<'a> { fn print_formal_lifetime_list(&mut self, lifetimes: &[ast::LifetimeDef]) -> io::Result<()> { if !lifetimes.is_empty() { - try!(word(&mut self.s, "for<")); + word(&mut self.s, "for<")?; let mut comma = false; for lifetime_def in lifetimes { if comma { - try!(self.word_space(",")) + self.word_space(",")? } - try!(self.print_lifetime_def(lifetime_def)); + self.print_lifetime_def(lifetime_def)?; comma = true; } - try!(word(&mut self.s, ">")); + word(&mut self.s, ">")?; } Ok(()) } fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) -> io::Result<()> { - try!(self.print_formal_lifetime_list(&t.bound_lifetimes)); + self.print_formal_lifetime_list(&t.bound_lifetimes)?; self.print_trait_ref(&t.trait_ref) } @@ -1362,27 +1362,27 @@ impl<'a> State<'a> { generics: &ast::Generics, ident: ast::Ident, span: codemap::Span, visibility: ast::Visibility) -> io::Result<()> { - try!(self.head(&visibility_qualified(visibility, "enum"))); - try!(self.print_ident(ident)); - try!(self.print_generics(generics)); - try!(self.print_where_clause(&generics.where_clause)); - try!(space(&mut self.s)); + self.head(&visibility_qualified(visibility, "enum"))?; + self.print_ident(ident)?; + self.print_generics(generics)?; + self.print_where_clause(&generics.where_clause)?; + space(&mut self.s)?; self.print_variants(&enum_definition.variants, span) } pub fn print_variants(&mut self, variants: &[ast::Variant], span: codemap::Span) -> io::Result<()> { - try!(self.bopen()); + self.bopen()?; for v in variants { - try!(self.space_if_not_bol()); - try!(self.maybe_print_comment(v.span.lo)); - try!(self.print_outer_attributes(&v.node.attrs)); - try!(self.ibox(INDENT_UNIT)); - try!(self.print_variant(v)); - try!(word(&mut self.s, ",")); - try!(self.end()); - try!(self.maybe_print_trailing_comment(v.span, None)); + self.space_if_not_bol()?; + self.maybe_print_comment(v.span.lo)?; + self.print_outer_attributes(&v.node.attrs)?; + self.ibox(INDENT_UNIT)?; + self.print_variant(v)?; + word(&mut self.s, ",")?; + self.end()?; + self.maybe_print_trailing_comment(v.span, None)?; } self.bclose(span) } @@ -1400,50 +1400,50 @@ impl<'a> State<'a> { ident: ast::Ident, span: codemap::Span, print_finalizer: bool) -> io::Result<()> { - try!(self.print_ident(ident)); - try!(self.print_generics(generics)); + self.print_ident(ident)?; + self.print_generics(generics)?; if !struct_def.is_struct() { if struct_def.is_tuple() { - try!(self.popen()); - try!(self.commasep( + self.popen()?; + self.commasep( Inconsistent, struct_def.fields(), |s, field| { match field.node.kind { ast::NamedField(..) => panic!("unexpected named field"), ast::UnnamedField(vis) => { - try!(s.print_visibility(vis)); - try!(s.maybe_print_comment(field.span.lo)); + s.print_visibility(vis)?; + s.maybe_print_comment(field.span.lo)?; s.print_type(&field.node.ty) } } } - )); - try!(self.pclose()); + )?; + self.pclose()?; } - try!(self.print_where_clause(&generics.where_clause)); + self.print_where_clause(&generics.where_clause)?; if print_finalizer { - try!(word(&mut self.s, ";")); + word(&mut self.s, ";")?; } - try!(self.end()); + self.end()?; self.end() // close the outer-box } else { - try!(self.print_where_clause(&generics.where_clause)); - try!(self.nbsp()); - try!(self.bopen()); - try!(self.hardbreak_if_not_bol()); + self.print_where_clause(&generics.where_clause)?; + self.nbsp()?; + self.bopen()?; + self.hardbreak_if_not_bol()?; for field in struct_def.fields() { match field.node.kind { ast::UnnamedField(..) => panic!("unexpected unnamed field"), ast::NamedField(ident, visibility) => { - try!(self.hardbreak_if_not_bol()); - try!(self.maybe_print_comment(field.span.lo)); - try!(self.print_outer_attributes(&field.node.attrs)); - try!(self.print_visibility(visibility)); - try!(self.print_ident(ident)); - try!(self.word_nbsp(":")); - try!(self.print_type(&field.node.ty)); - try!(word(&mut self.s, ",")); + self.hardbreak_if_not_bol()?; + self.maybe_print_comment(field.span.lo)?; + self.print_outer_attributes(&field.node.attrs)?; + self.print_visibility(visibility)?; + self.print_ident(ident)?; + self.word_nbsp(":")?; + self.print_type(&field.node.ty)?; + word(&mut self.s, ",")?; } } } @@ -1462,7 +1462,7 @@ impl<'a> State<'a> { pub fn print_tt(&mut self, tt: &ast::TokenTree) -> io::Result<()> { match *tt { TokenTree::Token(_, ref tk) => { - try!(word(&mut self.s, &token_to_string(tk))); + word(&mut self.s, &token_to_string(tk))?; match *tk { parse::token::DocComment(..) => { hardbreak(&mut self.s) @@ -1471,21 +1471,21 @@ impl<'a> State<'a> { } } TokenTree::Delimited(_, ref delimed) => { - try!(word(&mut self.s, &token_to_string(&delimed.open_token()))); - try!(space(&mut self.s)); - try!(self.print_tts(&delimed.tts)); - try!(space(&mut self.s)); + word(&mut self.s, &token_to_string(&delimed.open_token()))?; + space(&mut self.s)?; + self.print_tts(&delimed.tts)?; + space(&mut self.s)?; word(&mut self.s, &token_to_string(&delimed.close_token())) }, TokenTree::Sequence(_, ref seq) => { - try!(word(&mut self.s, "$(")); + word(&mut self.s, "$(")?; for tt_elt in &seq.tts { - try!(self.print_tt(tt_elt)); + self.print_tt(tt_elt)?; } - try!(word(&mut self.s, ")")); + word(&mut self.s, ")")?; match seq.separator { Some(ref tk) => { - try!(word(&mut self.s, &token_to_string(tk))); + word(&mut self.s, &token_to_string(tk))?; } None => {}, } @@ -1498,13 +1498,13 @@ impl<'a> State<'a> { } pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> io::Result<()> { - try!(self.ibox(0)); + self.ibox(0)?; let mut suppress_space = false; for (i, tt) in tts.iter().enumerate() { if i != 0 && !suppress_space { - try!(space(&mut self.s)); + space(&mut self.s)?; } - try!(self.print_tt(tt)); + self.print_tt(tt)?; // There should be no space between the module name and the following `::` in paths, // otherwise imported macros get re-parsed from crate metadata incorrectly (#20701) suppress_space = match *tt { @@ -1518,13 +1518,13 @@ impl<'a> State<'a> { } pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> { - try!(self.head("")); + self.head("")?; let generics = ast::Generics::default(); - try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false)); + self.print_struct(&v.node.data, &generics, v.node.name, v.span, false)?; match v.node.disr_expr { Some(ref d) => { - try!(space(&mut self.s)); - try!(self.word_space("=")); + space(&mut self.s)?; + self.word_space("=")?; self.print_expr(&d) } _ => Ok(()) @@ -1548,103 +1548,103 @@ impl<'a> State<'a> { pub fn print_trait_item(&mut self, ti: &ast::TraitItem) -> io::Result<()> { - try!(self.ann.pre(self, NodeSubItem(ti.id))); - try!(self.hardbreak_if_not_bol()); - try!(self.maybe_print_comment(ti.span.lo)); - try!(self.print_outer_attributes(&ti.attrs)); + self.ann.pre(self, NodeSubItem(ti.id))?; + self.hardbreak_if_not_bol()?; + self.maybe_print_comment(ti.span.lo)?; + self.print_outer_attributes(&ti.attrs)?; match ti.node { ast::TraitItemKind::Const(ref ty, ref default) => { - try!(self.print_associated_const(ti.ident, &ty, + self.print_associated_const(ti.ident, &ty, default.as_ref().map(|expr| &**expr), - ast::Visibility::Inherited)); + ast::Visibility::Inherited)?; } ast::TraitItemKind::Method(ref sig, ref body) => { if body.is_some() { - try!(self.head("")); + self.head("")?; } - try!(self.print_method_sig(ti.ident, sig, ast::Visibility::Inherited)); + self.print_method_sig(ti.ident, sig, ast::Visibility::Inherited)?; if let Some(ref body) = *body { - try!(self.nbsp()); - try!(self.print_block_with_attrs(body, &ti.attrs)); + self.nbsp()?; + self.print_block_with_attrs(body, &ti.attrs)?; } else { - try!(word(&mut self.s, ";")); + word(&mut self.s, ";")?; } } ast::TraitItemKind::Type(ref bounds, ref default) => { - try!(self.print_associated_type(ti.ident, Some(bounds), - default.as_ref().map(|ty| &**ty))); + self.print_associated_type(ti.ident, Some(bounds), + default.as_ref().map(|ty| &**ty))?; } } self.ann.post(self, NodeSubItem(ti.id)) } pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> io::Result<()> { - try!(self.ann.pre(self, NodeSubItem(ii.id))); - try!(self.hardbreak_if_not_bol()); - try!(self.maybe_print_comment(ii.span.lo)); - try!(self.print_outer_attributes(&ii.attrs)); + self.ann.pre(self, NodeSubItem(ii.id))?; + self.hardbreak_if_not_bol()?; + self.maybe_print_comment(ii.span.lo)?; + self.print_outer_attributes(&ii.attrs)?; if let ast::Defaultness::Default = ii.defaultness { - try!(self.word_nbsp("default")); + self.word_nbsp("default")?; } match ii.node { ast::ImplItemKind::Const(ref ty, ref expr) => { - try!(self.print_associated_const(ii.ident, &ty, Some(&expr), ii.vis)); + self.print_associated_const(ii.ident, &ty, Some(&expr), ii.vis)?; } ast::ImplItemKind::Method(ref sig, ref body) => { - try!(self.head("")); - try!(self.print_method_sig(ii.ident, sig, ii.vis)); - try!(self.nbsp()); - try!(self.print_block_with_attrs(body, &ii.attrs)); + self.head("")?; + self.print_method_sig(ii.ident, sig, ii.vis)?; + self.nbsp()?; + self.print_block_with_attrs(body, &ii.attrs)?; } ast::ImplItemKind::Type(ref ty) => { - try!(self.print_associated_type(ii.ident, None, Some(ty))); + self.print_associated_type(ii.ident, None, Some(ty))?; } ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => { // code copied from ItemKind::Mac: - try!(self.print_path(&node.path, false, 0)); - try!(word(&mut self.s, "! ")); - try!(self.cbox(INDENT_UNIT)); - try!(self.popen()); - try!(self.print_tts(&node.tts[..])); - try!(self.pclose()); - try!(word(&mut self.s, ";")); - try!(self.end()) + self.print_path(&node.path, false, 0)?; + word(&mut self.s, "! ")?; + self.cbox(INDENT_UNIT)?; + self.popen()?; + self.print_tts(&node.tts[..])?; + self.pclose()?; + word(&mut self.s, ";")?; + self.end()? } } self.ann.post(self, NodeSubItem(ii.id)) } pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> { - try!(self.maybe_print_comment(st.span.lo)); + self.maybe_print_comment(st.span.lo)?; match st.node { ast::StmtKind::Decl(ref decl, _) => { - try!(self.print_decl(&decl)); + self.print_decl(&decl)?; } ast::StmtKind::Expr(ref expr, _) => { - try!(self.space_if_not_bol()); - try!(self.print_expr_outer_attr_style(&expr, false)); + self.space_if_not_bol()?; + self.print_expr_outer_attr_style(&expr, false)?; } ast::StmtKind::Semi(ref expr, _) => { - try!(self.space_if_not_bol()); - try!(self.print_expr_outer_attr_style(&expr, false)); - try!(word(&mut self.s, ";")); + self.space_if_not_bol()?; + self.print_expr_outer_attr_style(&expr, false)?; + word(&mut self.s, ";")?; } ast::StmtKind::Mac(ref mac, style, ref attrs) => { - try!(self.space_if_not_bol()); - try!(self.print_outer_attributes(attrs.as_attr_slice())); + self.space_if_not_bol()?; + self.print_outer_attributes(attrs.as_attr_slice())?; let delim = match style { ast::MacStmtStyle::Braces => token::Brace, _ => token::Paren }; - try!(self.print_mac(&mac, delim)); + self.print_mac(&mac, delim)?; match style { ast::MacStmtStyle::Braces => {} - _ => try!(word(&mut self.s, ";")), + _ => word(&mut self.s, ";")?, } } } if parse::classify::stmt_ends_with_semi(&st.node) { - try!(word(&mut self.s, ";")); + word(&mut self.s, ";")?; } self.maybe_print_trailing_comment(st.span, None) } @@ -1680,27 +1680,27 @@ impl<'a> State<'a> { attrs: &[ast::Attribute], close_box: bool) -> io::Result<()> { match blk.rules { - BlockCheckMode::Unsafe(..) => try!(self.word_space("unsafe")), + BlockCheckMode::Unsafe(..) => self.word_space("unsafe")?, BlockCheckMode::Default => () } - try!(self.maybe_print_comment(blk.span.lo)); - try!(self.ann.pre(self, NodeBlock(blk))); - try!(self.bopen()); + self.maybe_print_comment(blk.span.lo)?; + self.ann.pre(self, NodeBlock(blk))?; + self.bopen()?; - try!(self.print_inner_attributes(attrs)); + self.print_inner_attributes(attrs)?; for st in &blk.stmts { - try!(self.print_stmt(st)); + self.print_stmt(st)?; } match blk.expr { Some(ref expr) => { - try!(self.space_if_not_bol()); - try!(self.print_expr_outer_attr_style(&expr, false)); - try!(self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi))); + self.space_if_not_bol()?; + self.print_expr_outer_attr_style(&expr, false)?; + self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi))?; } _ => () } - try!(self.bclose_maybe_open(blk.span, indented, close_box)); + self.bclose_maybe_open(blk.span, indented, close_box)?; self.ann.post(self, NodeBlock(blk)) } @@ -1710,32 +1710,32 @@ impl<'a> State<'a> { match _else.node { // "another else-if" ast::ExprKind::If(ref i, ref then, ref e) => { - try!(self.cbox(INDENT_UNIT - 1)); - try!(self.ibox(0)); - try!(word(&mut self.s, " else if ")); - try!(self.print_expr(&i)); - try!(space(&mut self.s)); - try!(self.print_block(&then)); + self.cbox(INDENT_UNIT - 1)?; + self.ibox(0)?; + word(&mut self.s, " else if ")?; + self.print_expr(&i)?; + space(&mut self.s)?; + self.print_block(&then)?; self.print_else(e.as_ref().map(|e| &**e)) } // "another else-if-let" ast::ExprKind::IfLet(ref pat, ref expr, ref then, ref e) => { - try!(self.cbox(INDENT_UNIT - 1)); - try!(self.ibox(0)); - try!(word(&mut self.s, " else if let ")); - try!(self.print_pat(&pat)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_expr(&expr)); - try!(space(&mut self.s)); - try!(self.print_block(&then)); + self.cbox(INDENT_UNIT - 1)?; + self.ibox(0)?; + word(&mut self.s, " else if let ")?; + self.print_pat(&pat)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_expr(&expr)?; + space(&mut self.s)?; + self.print_block(&then)?; self.print_else(e.as_ref().map(|e| &**e)) } // "final else" ast::ExprKind::Block(ref b) => { - try!(self.cbox(INDENT_UNIT - 1)); - try!(self.ibox(0)); - try!(word(&mut self.s, " else ")); + self.cbox(INDENT_UNIT - 1)?; + self.ibox(0)?; + word(&mut self.s, " else ")?; self.print_block(&b) } // BLEAH, constraints would be great here @@ -1750,38 +1750,38 @@ impl<'a> State<'a> { pub fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block, elseopt: Option<&ast::Expr>) -> io::Result<()> { - try!(self.head("if")); - try!(self.print_expr(test)); - try!(space(&mut self.s)); - try!(self.print_block(blk)); + self.head("if")?; + self.print_expr(test)?; + space(&mut self.s)?; + self.print_block(blk)?; self.print_else(elseopt) } pub fn print_if_let(&mut self, pat: &ast::Pat, expr: &ast::Expr, blk: &ast::Block, elseopt: Option<&ast::Expr>) -> io::Result<()> { - try!(self.head("if let")); - try!(self.print_pat(pat)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_expr(expr)); - try!(space(&mut self.s)); - try!(self.print_block(blk)); + self.head("if let")?; + self.print_pat(pat)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_expr(expr)?; + space(&mut self.s)?; + self.print_block(blk)?; self.print_else(elseopt) } pub fn print_mac(&mut self, m: &ast::Mac, delim: token::DelimToken) -> io::Result<()> { - try!(self.print_path(&m.node.path, false, 0)); - try!(word(&mut self.s, "!")); + self.print_path(&m.node.path, false, 0)?; + word(&mut self.s, "!")?; match delim { - token::Paren => try!(self.popen()), - token::Bracket => try!(word(&mut self.s, "[")), + token::Paren => self.popen()?, + token::Bracket => word(&mut self.s, "[")?, token::Brace => { - try!(self.head("")); - try!(self.bopen()); + self.head("")?; + self.bopen()?; } } - try!(self.print_tts(&m.node.tts)); + self.print_tts(&m.node.tts)?; match delim { token::Paren => self.pclose(), token::Bracket => word(&mut self.s, "]"), @@ -1791,8 +1791,8 @@ impl<'a> State<'a> { fn print_call_post(&mut self, args: &[P]) -> io::Result<()> { - try!(self.popen()); - try!(self.commasep_exprs(Inconsistent, args)); + self.popen()?; + self.commasep_exprs(Inconsistent, args)?; self.pclose() } @@ -1814,11 +1814,11 @@ impl<'a> State<'a> { 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()); + self.popen()?; } - try!(self.print_expr(expr)); + self.print_expr(expr)?; if needs_par { - try!(self.pclose()); + self.pclose()?; } Ok(()) } @@ -1826,19 +1826,19 @@ impl<'a> State<'a> { fn print_expr_in_place(&mut self, place: &ast::Expr, expr: &ast::Expr) -> io::Result<()> { - try!(self.print_expr_maybe_paren(place)); - try!(space(&mut self.s)); - try!(self.word_space("<-")); + self.print_expr_maybe_paren(place)?; + space(&mut self.s)?; + self.word_space("<-")?; self.print_expr_maybe_paren(expr) } fn print_expr_vec(&mut self, exprs: &[P], attrs: &[Attribute]) -> io::Result<()> { - try!(self.ibox(INDENT_UNIT)); - try!(word(&mut self.s, "[")); - try!(self.print_inner_attributes_inline(attrs)); - try!(self.commasep_exprs(Inconsistent, &exprs[..])); - try!(word(&mut self.s, "]")); + self.ibox(INDENT_UNIT)?; + word(&mut self.s, "[")?; + self.print_inner_attributes_inline(attrs)?; + self.commasep_exprs(Inconsistent, &exprs[..])?; + word(&mut self.s, "]")?; self.end() } @@ -1846,13 +1846,13 @@ impl<'a> State<'a> { element: &ast::Expr, count: &ast::Expr, attrs: &[Attribute]) -> io::Result<()> { - try!(self.ibox(INDENT_UNIT)); - try!(word(&mut self.s, "[")); - try!(self.print_inner_attributes_inline(attrs)); - try!(self.print_expr(element)); - try!(self.word_space(";")); - try!(self.print_expr(count)); - try!(word(&mut self.s, "]")); + self.ibox(INDENT_UNIT)?; + word(&mut self.s, "[")?; + self.print_inner_attributes_inline(attrs)?; + self.print_expr(element)?; + self.word_space(";")?; + self.print_expr(count)?; + word(&mut self.s, "]")?; self.end() } @@ -1861,46 +1861,46 @@ impl<'a> State<'a> { fields: &[ast::Field], wth: &Option>, attrs: &[Attribute]) -> io::Result<()> { - try!(self.print_path(path, true, 0)); - try!(word(&mut self.s, "{")); - try!(self.print_inner_attributes_inline(attrs)); - try!(self.commasep_cmnt( + self.print_path(path, true, 0)?; + word(&mut self.s, "{")?; + self.print_inner_attributes_inline(attrs)?; + self.commasep_cmnt( Consistent, &fields[..], |s, field| { - try!(s.ibox(INDENT_UNIT)); - try!(s.print_ident(field.ident.node)); - try!(s.word_space(":")); - try!(s.print_expr(&field.expr)); + s.ibox(INDENT_UNIT)?; + s.print_ident(field.ident.node)?; + s.word_space(":")?; + s.print_expr(&field.expr)?; s.end() }, - |f| f.span)); + |f| f.span)?; match *wth { Some(ref expr) => { - try!(self.ibox(INDENT_UNIT)); + self.ibox(INDENT_UNIT)?; if !fields.is_empty() { - try!(word(&mut self.s, ",")); - try!(space(&mut self.s)); + word(&mut self.s, ",")?; + space(&mut self.s)?; } - try!(word(&mut self.s, "..")); - try!(self.print_expr(&expr)); - try!(self.end()); + word(&mut self.s, "..")?; + self.print_expr(&expr)?; + self.end()?; } _ => if !fields.is_empty() { - try!(word(&mut self.s, ",")) + word(&mut self.s, ",")? } } - try!(word(&mut self.s, "}")); + word(&mut self.s, "}")?; Ok(()) } fn print_expr_tup(&mut self, exprs: &[P], attrs: &[Attribute]) -> io::Result<()> { - try!(self.popen()); - try!(self.print_inner_attributes_inline(attrs)); - try!(self.commasep_exprs(Inconsistent, &exprs[..])); + self.popen()?; + self.print_inner_attributes_inline(attrs)?; + self.commasep_exprs(Inconsistent, &exprs[..])?; if exprs.len() == 1 { - try!(word(&mut self.s, ",")); + word(&mut self.s, ",")?; } self.pclose() } @@ -1908,7 +1908,7 @@ impl<'a> State<'a> { fn print_expr_call(&mut self, func: &ast::Expr, args: &[P]) -> io::Result<()> { - try!(self.print_expr_maybe_paren(func)); + self.print_expr_maybe_paren(func)?; self.print_call_post(args) } @@ -1917,14 +1917,14 @@ impl<'a> State<'a> { tys: &[P], args: &[P]) -> io::Result<()> { let base_args = &args[1..]; - try!(self.print_expr(&args[0])); - try!(word(&mut self.s, ".")); - try!(self.print_ident(ident.node)); + self.print_expr(&args[0])?; + word(&mut self.s, ".")?; + self.print_ident(ident.node)?; if !tys.is_empty() { - try!(word(&mut self.s, "::<")); - try!(self.commasep(Inconsistent, tys, - |s, ty| s.print_type(&ty))); - try!(word(&mut self.s, ">")); + word(&mut self.s, "::<")?; + self.commasep(Inconsistent, tys, + |s, ty| s.print_type(&ty))?; + word(&mut self.s, ">")?; } self.print_call_post(base_args) } @@ -1934,12 +1934,12 @@ impl<'a> State<'a> { lhs: &ast::Expr, rhs: &ast::Expr) -> io::Result<()> { if self.check_expr_bin_needs_paren(lhs, op) { - try!(self.print_expr_maybe_paren(lhs)); + self.print_expr_maybe_paren(lhs)?; } else { - try!(self.print_expr(lhs)); + self.print_expr(lhs)?; } - try!(space(&mut self.s)); - try!(self.word_space(op.node.to_string())); + space(&mut self.s)?; + self.word_space(op.node.to_string())?; if self.check_expr_bin_needs_paren(rhs, op) { self.print_expr_maybe_paren(rhs) } else { @@ -1950,15 +1950,15 @@ impl<'a> State<'a> { fn print_expr_unary(&mut self, op: ast::UnOp, expr: &ast::Expr) -> io::Result<()> { - try!(word(&mut self.s, ast::UnOp::to_string(op))); + word(&mut self.s, ast::UnOp::to_string(op))?; self.print_expr_maybe_paren(expr) } fn print_expr_addr_of(&mut self, mutability: ast::Mutability, expr: &ast::Expr) -> io::Result<()> { - try!(word(&mut self.s, "&")); - try!(self.print_mutability(mutability)); + word(&mut self.s, "&")?; + self.print_mutability(mutability)?; self.print_expr_maybe_paren(expr) } @@ -1969,139 +1969,139 @@ impl<'a> State<'a> { fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline: bool) -> io::Result<()> { - try!(self.maybe_print_comment(expr.span.lo)); + self.maybe_print_comment(expr.span.lo)?; let attrs = expr.attrs.as_attr_slice(); if is_inline { - try!(self.print_outer_attributes_inline(attrs)); + self.print_outer_attributes_inline(attrs)?; } else { - try!(self.print_outer_attributes(attrs)); + self.print_outer_attributes(attrs)?; } - try!(self.ibox(INDENT_UNIT)); - try!(self.ann.pre(self, NodeExpr(expr))); + self.ibox(INDENT_UNIT)?; + self.ann.pre(self, NodeExpr(expr))?; match expr.node { ast::ExprKind::Box(ref expr) => { - try!(self.word_space("box")); - try!(self.print_expr(expr)); + self.word_space("box")?; + self.print_expr(expr)?; } ast::ExprKind::InPlace(ref place, ref expr) => { - try!(self.print_expr_in_place(place, expr)); + self.print_expr_in_place(place, expr)?; } ast::ExprKind::Vec(ref exprs) => { - try!(self.print_expr_vec(&exprs[..], attrs)); + self.print_expr_vec(&exprs[..], attrs)?; } ast::ExprKind::Repeat(ref element, ref count) => { - try!(self.print_expr_repeat(&element, &count, attrs)); + self.print_expr_repeat(&element, &count, attrs)?; } ast::ExprKind::Struct(ref path, ref fields, ref wth) => { - try!(self.print_expr_struct(path, &fields[..], wth, attrs)); + self.print_expr_struct(path, &fields[..], wth, attrs)?; } ast::ExprKind::Tup(ref exprs) => { - try!(self.print_expr_tup(&exprs[..], attrs)); + self.print_expr_tup(&exprs[..], attrs)?; } ast::ExprKind::Call(ref func, ref args) => { - try!(self.print_expr_call(&func, &args[..])); + self.print_expr_call(&func, &args[..])?; } ast::ExprKind::MethodCall(ident, ref tys, ref args) => { - try!(self.print_expr_method_call(ident, &tys[..], &args[..])); + self.print_expr_method_call(ident, &tys[..], &args[..])?; } ast::ExprKind::Binary(op, ref lhs, ref rhs) => { - try!(self.print_expr_binary(op, &lhs, &rhs)); + self.print_expr_binary(op, &lhs, &rhs)?; } ast::ExprKind::Unary(op, ref expr) => { - try!(self.print_expr_unary(op, &expr)); + self.print_expr_unary(op, &expr)?; } ast::ExprKind::AddrOf(m, ref expr) => { - try!(self.print_expr_addr_of(m, &expr)); + self.print_expr_addr_of(m, &expr)?; } ast::ExprKind::Lit(ref lit) => { - try!(self.print_literal(&lit)); + self.print_literal(&lit)?; } ast::ExprKind::Cast(ref expr, ref ty) => { if let ast::ExprKind::Cast(..) = expr.node { - try!(self.print_expr(&expr)); + self.print_expr(&expr)?; } else { - try!(self.print_expr_maybe_paren(&expr)); + self.print_expr_maybe_paren(&expr)?; } - try!(space(&mut self.s)); - try!(self.word_space("as")); - try!(self.print_type(&ty)); + space(&mut self.s)?; + self.word_space("as")?; + self.print_type(&ty)?; } ast::ExprKind::Type(ref expr, ref ty) => { - try!(self.print_expr(&expr)); - try!(self.word_space(":")); - try!(self.print_type(&ty)); + self.print_expr(&expr)?; + self.word_space(":")?; + self.print_type(&ty)?; } ast::ExprKind::If(ref test, ref blk, ref elseopt) => { - try!(self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e))); + self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e))?; } ast::ExprKind::IfLet(ref pat, ref expr, ref blk, ref elseopt) => { - try!(self.print_if_let(&pat, &expr, &blk, elseopt.as_ref().map(|e| &**e))); + self.print_if_let(&pat, &expr, &blk, elseopt.as_ref().map(|e| &**e))?; } ast::ExprKind::While(ref test, ref blk, opt_ident) => { if let Some(ident) = opt_ident { - try!(self.print_ident(ident)); - try!(self.word_space(":")); + self.print_ident(ident)?; + self.word_space(":")?; } - try!(self.head("while")); - try!(self.print_expr(&test)); - try!(space(&mut self.s)); - try!(self.print_block_with_attrs(&blk, attrs)); + self.head("while")?; + self.print_expr(&test)?; + space(&mut self.s)?; + self.print_block_with_attrs(&blk, attrs)?; } ast::ExprKind::WhileLet(ref pat, ref expr, ref blk, opt_ident) => { if let Some(ident) = opt_ident { - try!(self.print_ident(ident)); - try!(self.word_space(":")); + self.print_ident(ident)?; + self.word_space(":")?; } - try!(self.head("while let")); - try!(self.print_pat(&pat)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_expr(&expr)); - try!(space(&mut self.s)); - try!(self.print_block_with_attrs(&blk, attrs)); + self.head("while let")?; + self.print_pat(&pat)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_expr(&expr)?; + space(&mut self.s)?; + self.print_block_with_attrs(&blk, attrs)?; } ast::ExprKind::ForLoop(ref pat, ref iter, ref blk, opt_ident) => { if let Some(ident) = opt_ident { - try!(self.print_ident(ident)); - try!(self.word_space(":")); + self.print_ident(ident)?; + self.word_space(":")?; } - try!(self.head("for")); - try!(self.print_pat(&pat)); - try!(space(&mut self.s)); - try!(self.word_space("in")); - try!(self.print_expr(&iter)); - try!(space(&mut self.s)); - try!(self.print_block_with_attrs(&blk, attrs)); + self.head("for")?; + self.print_pat(&pat)?; + space(&mut self.s)?; + self.word_space("in")?; + self.print_expr(&iter)?; + space(&mut self.s)?; + self.print_block_with_attrs(&blk, attrs)?; } ast::ExprKind::Loop(ref blk, opt_ident) => { if let Some(ident) = opt_ident { - try!(self.print_ident(ident)); - try!(self.word_space(":")); + self.print_ident(ident)?; + self.word_space(":")?; } - try!(self.head("loop")); - try!(space(&mut self.s)); - try!(self.print_block_with_attrs(&blk, attrs)); + self.head("loop")?; + space(&mut self.s)?; + self.print_block_with_attrs(&blk, attrs)?; } ast::ExprKind::Match(ref expr, ref arms) => { - try!(self.cbox(INDENT_UNIT)); - try!(self.ibox(4)); - try!(self.word_nbsp("match")); - try!(self.print_expr(&expr)); - try!(space(&mut self.s)); - try!(self.bopen()); - try!(self.print_inner_attributes_no_trailing_hardbreak(attrs)); + self.cbox(INDENT_UNIT)?; + self.ibox(4)?; + self.word_nbsp("match")?; + self.print_expr(&expr)?; + space(&mut self.s)?; + self.bopen()?; + self.print_inner_attributes_no_trailing_hardbreak(attrs)?; for arm in arms { - try!(self.print_arm(arm)); + self.print_arm(arm)?; } - try!(self.bclose_(expr.span, INDENT_UNIT)); + self.bclose_(expr.span, INDENT_UNIT)?; } ast::ExprKind::Closure(capture_clause, ref decl, ref body) => { - try!(self.print_capture_clause(capture_clause)); + self.print_capture_clause(capture_clause)?; - try!(self.print_fn_block_args(&decl)); - try!(space(&mut self.s)); + self.print_fn_block_args(&decl)?; + space(&mut self.s)?; let default_return = match decl.output { ast::FunctionRetTy::Default(..) => true, @@ -2109,148 +2109,148 @@ impl<'a> State<'a> { }; if !default_return || !body.stmts.is_empty() || body.expr.is_none() { - try!(self.print_block_unclosed(&body)); + self.print_block_unclosed(&body)?; } else { // we extract the block, so as not to create another set of boxes let i_expr = body.expr.as_ref().unwrap(); match i_expr.node { ast::ExprKind::Block(ref blk) => { - try!(self.print_block_unclosed_with_attrs( + self.print_block_unclosed_with_attrs( &blk, - i_expr.attrs.as_attr_slice())); + i_expr.attrs.as_attr_slice())?; } _ => { // this is a bare expression - try!(self.print_expr(&i_expr)); - try!(self.end()); // need to close a box + self.print_expr(&i_expr)?; + self.end()?; // need to close a box } } } // a box will be closed by print_expr, but we didn't want an overall // wrapper so we closed the corresponding opening. so create an // empty box to satisfy the close. - try!(self.ibox(0)); + self.ibox(0)?; } ast::ExprKind::Block(ref blk) => { // containing cbox, will be closed by print-block at } - try!(self.cbox(INDENT_UNIT)); + self.cbox(INDENT_UNIT)?; // head-box, will be closed by print-block after { - try!(self.ibox(0)); - try!(self.print_block_with_attrs(&blk, attrs)); + self.ibox(0)?; + self.print_block_with_attrs(&blk, attrs)?; } ast::ExprKind::Assign(ref lhs, ref rhs) => { - try!(self.print_expr(&lhs)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_expr(&rhs)); + self.print_expr(&lhs)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_expr(&rhs)?; } ast::ExprKind::AssignOp(op, ref lhs, ref rhs) => { - try!(self.print_expr(&lhs)); - try!(space(&mut self.s)); - try!(word(&mut self.s, op.node.to_string())); - try!(self.word_space("=")); - try!(self.print_expr(&rhs)); + self.print_expr(&lhs)?; + space(&mut self.s)?; + word(&mut self.s, op.node.to_string())?; + self.word_space("=")?; + self.print_expr(&rhs)?; } ast::ExprKind::Field(ref expr, id) => { - try!(self.print_expr(&expr)); - try!(word(&mut self.s, ".")); - try!(self.print_ident(id.node)); + self.print_expr(&expr)?; + word(&mut self.s, ".")?; + self.print_ident(id.node)?; } ast::ExprKind::TupField(ref expr, id) => { - try!(self.print_expr(&expr)); - try!(word(&mut self.s, ".")); - try!(self.print_usize(id.node)); + self.print_expr(&expr)?; + word(&mut self.s, ".")?; + self.print_usize(id.node)?; } ast::ExprKind::Index(ref expr, ref index) => { - try!(self.print_expr(&expr)); - try!(word(&mut self.s, "[")); - try!(self.print_expr(&index)); - try!(word(&mut self.s, "]")); + self.print_expr(&expr)?; + word(&mut self.s, "[")?; + self.print_expr(&index)?; + word(&mut self.s, "]")?; } ast::ExprKind::Range(ref start, ref end, limits) => { if let &Some(ref e) = start { - try!(self.print_expr(&e)); + self.print_expr(&e)?; } if limits == ast::RangeLimits::HalfOpen { - try!(word(&mut self.s, "..")); + word(&mut self.s, "..")?; } else { - try!(word(&mut self.s, "...")); + word(&mut self.s, "...")?; } if let &Some(ref e) = end { - try!(self.print_expr(&e)); + self.print_expr(&e)?; } } ast::ExprKind::Path(None, ref path) => { - try!(self.print_path(path, true, 0)) + self.print_path(path, true, 0)? } ast::ExprKind::Path(Some(ref qself), ref path) => { - try!(self.print_qpath(path, qself, true)) + self.print_qpath(path, qself, true)? } ast::ExprKind::Break(opt_ident) => { - try!(word(&mut self.s, "break")); - try!(space(&mut self.s)); + word(&mut self.s, "break")?; + space(&mut self.s)?; if let Some(ident) = opt_ident { - try!(self.print_ident(ident.node)); - try!(space(&mut self.s)); + self.print_ident(ident.node)?; + space(&mut self.s)?; } } ast::ExprKind::Again(opt_ident) => { - try!(word(&mut self.s, "continue")); - try!(space(&mut self.s)); + word(&mut self.s, "continue")?; + space(&mut self.s)?; if let Some(ident) = opt_ident { - try!(self.print_ident(ident.node)); - try!(space(&mut self.s)) + self.print_ident(ident.node)?; + space(&mut self.s)? } } ast::ExprKind::Ret(ref result) => { - try!(word(&mut self.s, "return")); + word(&mut self.s, "return")?; match *result { Some(ref expr) => { - try!(word(&mut self.s, " ")); - try!(self.print_expr(&expr)); + word(&mut self.s, " ")?; + self.print_expr(&expr)?; } _ => () } } ast::ExprKind::InlineAsm(ref a) => { - try!(word(&mut self.s, "asm!")); - try!(self.popen()); - try!(self.print_string(&a.asm, a.asm_str_style)); - try!(self.word_space(":")); + word(&mut self.s, "asm!")?; + self.popen()?; + self.print_string(&a.asm, a.asm_str_style)?; + self.word_space(":")?; - try!(self.commasep(Inconsistent, &a.outputs, + self.commasep(Inconsistent, &a.outputs, |s, out| { match out.constraint.slice_shift_char() { Some(('=', operand)) if out.is_rw => { - try!(s.print_string(&format!("+{}", operand), - ast::StrStyle::Cooked)) + s.print_string(&format!("+{}", operand), + ast::StrStyle::Cooked)? } - _ => try!(s.print_string(&out.constraint, ast::StrStyle::Cooked)) + _ => s.print_string(&out.constraint, ast::StrStyle::Cooked)? } - try!(s.popen()); - try!(s.print_expr(&out.expr)); - try!(s.pclose()); + s.popen()?; + s.print_expr(&out.expr)?; + s.pclose()?; Ok(()) - })); - try!(space(&mut self.s)); - try!(self.word_space(":")); + })?; + space(&mut self.s)?; + self.word_space(":")?; - try!(self.commasep(Inconsistent, &a.inputs, + self.commasep(Inconsistent, &a.inputs, |s, &(ref co, ref o)| { - try!(s.print_string(&co, ast::StrStyle::Cooked)); - try!(s.popen()); - try!(s.print_expr(&o)); - try!(s.pclose()); + s.print_string(&co, ast::StrStyle::Cooked)?; + s.popen()?; + s.print_expr(&o)?; + s.pclose()?; Ok(()) - })); - try!(space(&mut self.s)); - try!(self.word_space(":")); + })?; + space(&mut self.s)?; + self.word_space(":")?; - try!(self.commasep(Inconsistent, &a.clobbers, + self.commasep(Inconsistent, &a.clobbers, |s, co| { - try!(s.print_string(&co, ast::StrStyle::Cooked)); + s.print_string(&co, ast::StrStyle::Cooked)?; Ok(()) - })); + })?; let mut options = vec!(); if a.volatile { @@ -2264,58 +2264,58 @@ impl<'a> State<'a> { } if !options.is_empty() { - try!(space(&mut self.s)); - try!(self.word_space(":")); - try!(self.commasep(Inconsistent, &options, + space(&mut self.s)?; + self.word_space(":")?; + self.commasep(Inconsistent, &options, |s, &co| { - try!(s.print_string(co, ast::StrStyle::Cooked)); + s.print_string(co, ast::StrStyle::Cooked)?; Ok(()) - })); + })?; } - try!(self.pclose()); + self.pclose()?; } - ast::ExprKind::Mac(ref m) => try!(self.print_mac(m, token::Paren)), + ast::ExprKind::Mac(ref m) => self.print_mac(m, token::Paren)?, ast::ExprKind::Paren(ref e) => { - try!(self.popen()); - try!(self.print_inner_attributes_inline(attrs)); - try!(self.print_expr(&e)); - try!(self.pclose()); + self.popen()?; + self.print_inner_attributes_inline(attrs)?; + self.print_expr(&e)?; + self.pclose()?; }, ast::ExprKind::Try(ref e) => { - try!(self.print_expr(e)); - try!(word(&mut self.s, "?")) + self.print_expr(e)?; + word(&mut self.s, "?")? } } - try!(self.ann.post(self, NodeExpr(expr))); + self.ann.post(self, NodeExpr(expr))?; self.end() } pub fn print_local_decl(&mut self, loc: &ast::Local) -> io::Result<()> { - try!(self.print_pat(&loc.pat)); + self.print_pat(&loc.pat)?; if let Some(ref ty) = loc.ty { - try!(self.word_space(":")); - try!(self.print_type(&ty)); + self.word_space(":")?; + self.print_type(&ty)?; } Ok(()) } pub fn print_decl(&mut self, decl: &ast::Decl) -> io::Result<()> { - try!(self.maybe_print_comment(decl.span.lo)); + self.maybe_print_comment(decl.span.lo)?; match decl.node { ast::DeclKind::Local(ref loc) => { - try!(self.print_outer_attributes(loc.attrs.as_attr_slice())); - try!(self.space_if_not_bol()); - try!(self.ibox(INDENT_UNIT)); - try!(self.word_nbsp("let")); - - try!(self.ibox(INDENT_UNIT)); - try!(self.print_local_decl(&loc)); - try!(self.end()); + self.print_outer_attributes(loc.attrs.as_attr_slice())?; + self.space_if_not_bol()?; + self.ibox(INDENT_UNIT)?; + self.word_nbsp("let")?; + + self.ibox(INDENT_UNIT)?; + self.print_local_decl(&loc)?; + self.end()?; if let Some(ref init) = loc.init { - try!(self.nbsp()); - try!(self.word_space("=")); - try!(self.print_expr(&init)); + self.nbsp()?; + self.word_space("=")?; + self.print_expr(&init)?; } self.end() } @@ -2324,7 +2324,7 @@ impl<'a> State<'a> { } pub fn print_ident(&mut self, ident: ast::Ident) -> io::Result<()> { - try!(word(&mut self.s, &ident.name.as_str())); + word(&mut self.s, &ident.name.as_str())?; self.ann.post(self, NodeIdent(&ident)) } @@ -2333,15 +2333,15 @@ impl<'a> State<'a> { } pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> { - try!(word(&mut self.s, &name.as_str())); + word(&mut self.s, &name.as_str())?; self.ann.post(self, NodeName(&name)) } pub fn print_for_decl(&mut self, loc: &ast::Local, coll: &ast::Expr) -> io::Result<()> { - try!(self.print_local_decl(loc)); - try!(space(&mut self.s)); - try!(self.word_space("in")); + self.print_local_decl(loc)?; + space(&mut self.s)?; + self.word_space("in")?; self.print_expr(coll) } @@ -2351,19 +2351,19 @@ impl<'a> State<'a> { depth: usize) -> io::Result<()> { - try!(self.maybe_print_comment(path.span.lo)); + self.maybe_print_comment(path.span.lo)?; let mut first = !path.global; for segment in &path.segments[..path.segments.len()-depth] { if first { first = false } else { - try!(word(&mut self.s, "::")) + word(&mut self.s, "::")? } - try!(self.print_ident(segment.identifier)); + self.print_ident(segment.identifier)?; - try!(self.print_path_parameters(&segment.parameters, colons_before_params)); + self.print_path_parameters(&segment.parameters, colons_before_params)?; } Ok(()) @@ -2375,18 +2375,18 @@ impl<'a> State<'a> { colons_before_params: bool) -> io::Result<()> { - try!(word(&mut self.s, "<")); - try!(self.print_type(&qself.ty)); + word(&mut self.s, "<")?; + self.print_type(&qself.ty)?; if qself.position > 0 { - try!(space(&mut self.s)); - try!(self.word_space("as")); + space(&mut self.s)?; + self.word_space("as")?; let depth = path.segments.len() - qself.position; - try!(self.print_path(&path, false, depth)); + self.print_path(&path, false, depth)?; } - try!(word(&mut self.s, ">")); - try!(word(&mut self.s, "::")); + word(&mut self.s, ">")?; + word(&mut self.s, "::")?; let item_segment = path.segments.last().unwrap(); - try!(self.print_ident(item_segment.identifier)); + self.print_ident(item_segment.identifier)?; self.print_path_parameters(&item_segment.parameters, colons_before_params) } @@ -2400,61 +2400,61 @@ impl<'a> State<'a> { } if colons_before_params { - try!(word(&mut self.s, "::")) + word(&mut self.s, "::")? } match *parameters { ast::PathParameters::AngleBracketed(ref data) => { - try!(word(&mut self.s, "<")); + word(&mut self.s, "<")?; let mut comma = false; for lifetime in &data.lifetimes { if comma { - try!(self.word_space(",")) + self.word_space(",")? } - try!(self.print_lifetime(lifetime)); + self.print_lifetime(lifetime)?; comma = true; } if !data.types.is_empty() { if comma { - try!(self.word_space(",")) + self.word_space(",")? } - try!(self.commasep( + self.commasep( Inconsistent, &data.types, - |s, ty| s.print_type(&ty))); + |s, ty| s.print_type(&ty))?; comma = true; } for binding in data.bindings.iter() { if comma { - try!(self.word_space(",")) + self.word_space(",")? } - try!(self.print_ident(binding.ident)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_type(&binding.ty)); + self.print_ident(binding.ident)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_type(&binding.ty)?; comma = true; } - try!(word(&mut self.s, ">")) + word(&mut self.s, ">")? } ast::PathParameters::Parenthesized(ref data) => { - try!(word(&mut self.s, "(")); - try!(self.commasep( + word(&mut self.s, "(")?; + self.commasep( Inconsistent, &data.inputs, - |s, ty| s.print_type(&ty))); - try!(word(&mut self.s, ")")); + |s, ty| s.print_type(&ty))?; + word(&mut self.s, ")")?; match data.output { None => { } Some(ref ty) => { - try!(self.space_if_not_bol()); - try!(self.word_space("->")); - try!(self.print_type(&ty)); + self.space_if_not_bol()?; + self.word_space("->")?; + self.print_type(&ty)?; } } } @@ -2464,120 +2464,120 @@ impl<'a> State<'a> { } 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))); + self.maybe_print_comment(pat.span.lo)?; + self.ann.pre(self, NodePat(pat))?; /* Pat isn't normalized, but the beauty of it is that it doesn't matter */ match pat.node { - PatKind::Wild => try!(word(&mut self.s, "_")), + PatKind::Wild => word(&mut self.s, "_")?, PatKind::Ident(binding_mode, ref path1, ref sub) => { match binding_mode { ast::BindingMode::ByRef(mutbl) => { - try!(self.word_nbsp("ref")); - try!(self.print_mutability(mutbl)); + self.word_nbsp("ref")?; + self.print_mutability(mutbl)?; } ast::BindingMode::ByValue(ast::Mutability::Immutable) => {} ast::BindingMode::ByValue(ast::Mutability::Mutable) => { - try!(self.word_nbsp("mut")); + self.word_nbsp("mut")?; } } - try!(self.print_ident(path1.node)); + self.print_ident(path1.node)?; match *sub { Some(ref p) => { - try!(word(&mut self.s, "@")); - try!(self.print_pat(&p)); + word(&mut self.s, "@")?; + self.print_pat(&p)?; } None => () } } PatKind::TupleStruct(ref path, ref args_) => { - try!(self.print_path(path, true, 0)); + self.print_path(path, true, 0)?; match *args_ { - None => try!(word(&mut self.s, "(..)")), + None => word(&mut self.s, "(..)")?, Some(ref args) => { - try!(self.popen()); - try!(self.commasep(Inconsistent, &args[..], - |s, p| s.print_pat(&p))); - try!(self.pclose()); + self.popen()?; + self.commasep(Inconsistent, &args[..], + |s, p| s.print_pat(&p))?; + self.pclose()?; } } } PatKind::Path(ref path) => { - try!(self.print_path(path, true, 0)); + self.print_path(path, true, 0)?; } PatKind::QPath(ref qself, ref path) => { - try!(self.print_qpath(path, qself, false)); + self.print_qpath(path, qself, false)?; } PatKind::Struct(ref path, ref fields, etc) => { - try!(self.print_path(path, true, 0)); - try!(self.nbsp()); - try!(self.word_space("{")); - try!(self.commasep_cmnt( + self.print_path(path, true, 0)?; + self.nbsp()?; + self.word_space("{")?; + self.commasep_cmnt( Consistent, &fields[..], |s, f| { - try!(s.cbox(INDENT_UNIT)); + s.cbox(INDENT_UNIT)?; if !f.node.is_shorthand { - try!(s.print_ident(f.node.ident)); - try!(s.word_nbsp(":")); + s.print_ident(f.node.ident)?; + s.word_nbsp(":")?; } - try!(s.print_pat(&f.node.pat)); + s.print_pat(&f.node.pat)?; s.end() }, - |f| f.node.pat.span)); + |f| f.node.pat.span)?; if etc { - if !fields.is_empty() { try!(self.word_space(",")); } - try!(word(&mut self.s, "..")); + if !fields.is_empty() { self.word_space(",")?; } + word(&mut self.s, "..")?; } - try!(space(&mut self.s)); - try!(word(&mut self.s, "}")); + space(&mut self.s)?; + word(&mut self.s, "}")?; } PatKind::Tup(ref elts) => { - try!(self.popen()); - try!(self.commasep(Inconsistent, + self.popen()?; + self.commasep(Inconsistent, &elts[..], - |s, p| s.print_pat(&p))); + |s, p| s.print_pat(&p))?; if elts.len() == 1 { - try!(word(&mut self.s, ",")); + word(&mut self.s, ",")?; } - try!(self.pclose()); + self.pclose()?; } PatKind::Box(ref inner) => { - try!(word(&mut self.s, "box ")); - try!(self.print_pat(&inner)); + word(&mut self.s, "box ")?; + self.print_pat(&inner)?; } PatKind::Ref(ref inner, mutbl) => { - try!(word(&mut self.s, "&")); + word(&mut self.s, "&")?; if mutbl == ast::Mutability::Mutable { - try!(word(&mut self.s, "mut ")); + word(&mut self.s, "mut ")?; } - try!(self.print_pat(&inner)); + self.print_pat(&inner)?; } - PatKind::Lit(ref e) => try!(self.print_expr(&**e)), + PatKind::Lit(ref e) => self.print_expr(&**e)?, PatKind::Range(ref begin, ref end) => { - try!(self.print_expr(&begin)); - try!(space(&mut self.s)); - try!(word(&mut self.s, "...")); - try!(self.print_expr(&end)); + self.print_expr(&begin)?; + space(&mut self.s)?; + word(&mut self.s, "...")?; + self.print_expr(&end)?; } PatKind::Vec(ref before, ref slice, ref after) => { - try!(word(&mut self.s, "[")); - try!(self.commasep(Inconsistent, + word(&mut self.s, "[")?; + self.commasep(Inconsistent, &before[..], - |s, p| s.print_pat(&p))); + |s, p| s.print_pat(&p))?; if let Some(ref p) = *slice { - if !before.is_empty() { try!(self.word_space(",")); } + if !before.is_empty() { self.word_space(",")?; } if p.node != PatKind::Wild { - try!(self.print_pat(&p)); + self.print_pat(&p)?; } - try!(word(&mut self.s, "..")); - if !after.is_empty() { try!(self.word_space(",")); } + word(&mut self.s, "..")?; + if !after.is_empty() { self.word_space(",")?; } } - try!(self.commasep(Inconsistent, + self.commasep(Inconsistent, &after[..], - |s, p| s.print_pat(&p))); - try!(word(&mut self.s, "]")); + |s, p| s.print_pat(&p))?; + word(&mut self.s, "]")?; } - PatKind::Mac(ref m) => try!(self.print_mac(m, token::Paren)), + PatKind::Mac(ref m) => self.print_mac(m, token::Paren)?, } self.ann.post(self, NodePat(pat)) } @@ -2586,43 +2586,43 @@ impl<'a> State<'a> { // I have no idea why this check is necessary, but here it // is :( if arm.attrs.is_empty() { - try!(space(&mut self.s)); + space(&mut self.s)?; } - try!(self.cbox(INDENT_UNIT)); - try!(self.ibox(0)); - try!(self.print_outer_attributes(&arm.attrs)); + self.cbox(INDENT_UNIT)?; + self.ibox(0)?; + self.print_outer_attributes(&arm.attrs)?; let mut first = true; for p in &arm.pats { if first { first = false; } else { - try!(space(&mut self.s)); - try!(self.word_space("|")); + space(&mut self.s)?; + self.word_space("|")?; } - try!(self.print_pat(&p)); + self.print_pat(&p)?; } - try!(space(&mut self.s)); + space(&mut self.s)?; if let Some(ref e) = arm.guard { - try!(self.word_space("if")); - try!(self.print_expr(&e)); - try!(space(&mut self.s)); + self.word_space("if")?; + self.print_expr(&e)?; + space(&mut self.s)?; } - try!(self.word_space("=>")); + self.word_space("=>")?; match arm.body.node { ast::ExprKind::Block(ref blk) => { // the block will close the pattern's ibox - try!(self.print_block_unclosed_indent(&blk, INDENT_UNIT)); + self.print_block_unclosed_indent(&blk, INDENT_UNIT)?; // If it is a user-provided unsafe block, print a comma after it if let BlockCheckMode::Unsafe(ast::UserProvided) = blk.rules { - try!(word(&mut self.s, ",")); + word(&mut self.s, ",")?; } } _ => { - try!(self.end()); // close the ibox for the pattern - try!(self.print_expr(&arm.body)); - try!(word(&mut self.s, ",")); + self.end()?; // close the ibox for the pattern + self.print_expr(&arm.body)?; + word(&mut self.s, ",")?; } } self.end() // close enclosing cbox @@ -2632,22 +2632,22 @@ impl<'a> State<'a> { fn print_explicit_self(&mut self, explicit_self: &ast::SelfKind, mutbl: ast::Mutability) -> io::Result { - try!(self.print_mutability(mutbl)); + self.print_mutability(mutbl)?; match *explicit_self { ast::SelfKind::Static => { return Ok(false); } ast::SelfKind::Value(_) => { - try!(word(&mut self.s, "self")); + word(&mut self.s, "self")?; } ast::SelfKind::Region(ref lt, m, _) => { - try!(word(&mut self.s, "&")); - try!(self.print_opt_lifetime(lt)); - try!(self.print_mutability(m)); - try!(word(&mut self.s, "self")); + word(&mut self.s, "&")?; + self.print_opt_lifetime(lt)?; + self.print_mutability(m)?; + word(&mut self.s, "self")?; } ast::SelfKind::Explicit(ref typ, _) => { - try!(word(&mut self.s, "self")); - try!(self.word_space(":")); - try!(self.print_type(&typ)); + word(&mut self.s, "self")?; + self.word_space(":")?; + self.print_type(&typ)?; } } return Ok(true); @@ -2662,14 +2662,14 @@ impl<'a> State<'a> { generics: &ast::Generics, opt_explicit_self: Option<&ast::SelfKind>, vis: ast::Visibility) -> io::Result<()> { - try!(self.print_fn_header_info(unsafety, constness, abi, vis)); + self.print_fn_header_info(unsafety, constness, abi, vis)?; if let Some(name) = name { - try!(self.nbsp()); - try!(self.print_ident(name)); + self.nbsp()?; + self.print_ident(name)?; } - try!(self.print_generics(generics)); - try!(self.print_fn_args_and_ret(decl, opt_explicit_self)); + self.print_generics(generics)?; + self.print_fn_args_and_ret(decl, opt_explicit_self)?; self.print_where_clause(&generics.where_clause) } @@ -2678,7 +2678,7 @@ impl<'a> State<'a> { is_closure: bool) -> 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)); + self.rbox(0, Inconsistent)?; let mut first = true; if let Some(explicit_self) = opt_explicit_self { let m = match *explicit_self { @@ -2688,7 +2688,7 @@ impl<'a> State<'a> { _ => ast::Mutability::Immutable } }; - first = !try!(self.print_explicit_self(explicit_self, m)); + first = !self.print_explicit_self(explicit_self, m)?; } // HACK(eddyb) ignore the separately printed self argument. @@ -2699,8 +2699,8 @@ impl<'a> State<'a> { }; for arg in args { - if first { first = false; } else { try!(self.word_space(",")); } - try!(self.print_arg(arg, is_closure)); + if first { first = false; } else { self.word_space(",")?; } + self.print_arg(arg, is_closure)?; } self.end() @@ -2709,12 +2709,12 @@ impl<'a> State<'a> { pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl, opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { - try!(self.popen()); - try!(self.print_fn_args(decl, opt_explicit_self, false)); + self.popen()?; + self.print_fn_args(decl, opt_explicit_self, false)?; if decl.variadic { - try!(word(&mut self.s, ", ...")); + word(&mut self.s, ", ...")?; } - try!(self.pclose()); + self.pclose()?; self.print_fn_output(decl) } @@ -2723,24 +2723,24 @@ impl<'a> State<'a> { &mut self, decl: &ast::FnDecl) -> io::Result<()> { - try!(word(&mut self.s, "|")); - try!(self.print_fn_args(decl, None, true)); - try!(word(&mut self.s, "|")); + word(&mut self.s, "|")?; + self.print_fn_args(decl, None, true)?; + word(&mut self.s, "|")?; if let ast::FunctionRetTy::Default(..) = decl.output { return Ok(()); } - try!(self.space_if_not_bol()); - try!(self.word_space("->")); + self.space_if_not_bol()?; + self.word_space("->")?; match decl.output { ast::FunctionRetTy::Ty(ref ty) => { - try!(self.print_type(&ty)); + self.print_type(&ty)?; self.maybe_print_comment(ty.span.lo) } ast::FunctionRetTy::Default(..) => unreachable!(), ast::FunctionRetTy::None(span) => { - try!(self.word_nbsp("!")); + self.word_nbsp("!")?; self.maybe_print_comment(span.lo) } } @@ -2759,28 +2759,28 @@ impl<'a> State<'a> { bounds: &[ast::TyParamBound]) -> io::Result<()> { if !bounds.is_empty() { - try!(word(&mut self.s, prefix)); + word(&mut self.s, prefix)?; let mut first = true; for bound in bounds { - try!(self.nbsp()); + self.nbsp()?; if first { first = false; } else { - try!(self.word_space("+")); + self.word_space("+")?; } - try!(match *bound { + match *bound { TraitTyParamBound(ref tref, TraitBoundModifier::None) => { self.print_poly_trait_ref(tref) } TraitTyParamBound(ref tref, TraitBoundModifier::Maybe) => { - try!(word(&mut self.s, "?")); + word(&mut self.s, "?")?; self.print_poly_trait_ref(tref) } RegionTyParamBound(ref lt) => { self.print_lifetime(lt) } - }) + }? } Ok(()) } else { @@ -2799,11 +2799,11 @@ impl<'a> State<'a> { lifetime: &ast::LifetimeDef) -> io::Result<()> { - try!(self.print_lifetime(&lifetime.lifetime)); + self.print_lifetime(&lifetime.lifetime)?; let mut sep = ":"; for v in &lifetime.bounds { - try!(word(&mut self.s, sep)); - try!(self.print_lifetime(v)); + word(&mut self.s, sep)?; + self.print_lifetime(v)?; sep = "+"; } Ok(()) @@ -2818,14 +2818,14 @@ impl<'a> State<'a> { return Ok(()); } - try!(word(&mut self.s, "<")); + word(&mut self.s, "<")?; let mut ints = Vec::new(); for i in 0..total { ints.push(i); } - try!(self.commasep(Inconsistent, &ints[..], |s, &idx| { + self.commasep(Inconsistent, &ints[..], |s, &idx| { if idx < generics.lifetimes.len() { let lifetime = &generics.lifetimes[idx]; s.print_lifetime_def(lifetime) @@ -2834,19 +2834,19 @@ impl<'a> State<'a> { let param = &generics.ty_params[idx]; s.print_ty_param(param) } - })); + })?; - try!(word(&mut self.s, ">")); + word(&mut self.s, ">")?; Ok(()) } pub fn print_ty_param(&mut self, param: &ast::TyParam) -> io::Result<()> { - try!(self.print_ident(param.ident)); - try!(self.print_bounds(":", ¶m.bounds)); + self.print_ident(param.ident)?; + self.print_bounds(":", ¶m.bounds)?; match param.default { Some(ref default) => { - try!(space(&mut self.s)); - try!(self.word_space("=")); + space(&mut self.s)?; + self.word_space("=")?; self.print_type(&default) } _ => Ok(()) @@ -2859,12 +2859,12 @@ impl<'a> State<'a> { return Ok(()) } - try!(space(&mut self.s)); - try!(self.word_space("where")); + space(&mut self.s)?; + self.word_space("where")?; for (i, predicate) in where_clause.predicates.iter().enumerate() { if i != 0 { - try!(self.word_space(",")); + self.word_space(",")?; } match *predicate { @@ -2872,29 +2872,29 @@ impl<'a> State<'a> { ref bounded_ty, ref bounds, ..}) => { - try!(self.print_formal_lifetime_list(bound_lifetimes)); - try!(self.print_type(&bounded_ty)); - try!(self.print_bounds(":", bounds)); + self.print_formal_lifetime_list(bound_lifetimes)?; + self.print_type(&bounded_ty)?; + self.print_bounds(":", bounds)?; } ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, ref bounds, ..}) => { - try!(self.print_lifetime(lifetime)); - try!(word(&mut self.s, ":")); + self.print_lifetime(lifetime)?; + word(&mut self.s, ":")?; for (i, bound) in bounds.iter().enumerate() { - try!(self.print_lifetime(bound)); + self.print_lifetime(bound)?; if i != 0 { - try!(word(&mut self.s, ":")); + word(&mut self.s, ":")?; } } } ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { - try!(self.print_path(path, false, 0)); - try!(space(&mut self.s)); - try!(self.word_space("=")); - try!(self.print_type(&ty)); + self.print_path(path, false, 0)?; + space(&mut self.s)?; + self.word_space("=")?; + self.print_type(&ty)?; } } } @@ -2905,52 +2905,52 @@ impl<'a> State<'a> { 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)); + self.print_path(path, false, 0)?; if path.segments.last().unwrap().identifier.name != ident.name { - try!(space(&mut self.s)); - try!(self.word_space("as")); - try!(self.print_ident(ident)); + space(&mut self.s)?; + self.word_space("as")?; + self.print_ident(ident)?; } Ok(()) } ast::ViewPathGlob(ref path) => { - try!(self.print_path(path, false, 0)); + self.print_path(path, false, 0)?; word(&mut self.s, "::*") } ast::ViewPathList(ref path, ref idents) => { if path.segments.is_empty() { - try!(word(&mut self.s, "{")); + word(&mut self.s, "{")?; } else { - try!(self.print_path(path, false, 0)); - try!(word(&mut self.s, "::{")); + self.print_path(path, false, 0)?; + word(&mut self.s, "::{")?; } - try!(self.commasep(Inconsistent, &idents[..], |s, w| { + self.commasep(Inconsistent, &idents[..], |s, w| { match w.node { ast::PathListItemKind::Ident { name, rename, .. } => { - try!(s.print_ident(name)); + s.print_ident(name)?; if let Some(ident) = rename { - try!(space(&mut s.s)); - try!(s.word_space("as")); - try!(s.print_ident(ident)); + space(&mut s.s)?; + s.word_space("as")?; + s.print_ident(ident)?; } Ok(()) }, ast::PathListItemKind::Mod { rename, .. } => { - try!(word(&mut s.s, "self")); + word(&mut s.s, "self")?; if let Some(ident) = rename { - try!(space(&mut s.s)); - try!(s.word_space("as")); - try!(s.print_ident(ident)); + space(&mut s.s)?; + s.word_space("as")?; + s.print_ident(ident)?; } Ok(()) } } - })); + })?; word(&mut self.s, "}") } } @@ -2965,14 +2965,14 @@ impl<'a> State<'a> { } pub fn print_mt(&mut self, mt: &ast::MutTy) -> io::Result<()> { - try!(self.print_mutability(mt.mutbl)); + self.print_mutability(mt.mutbl)?; self.print_type(&mt.ty) } pub fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) -> io::Result<()> { - try!(self.ibox(INDENT_UNIT)); + self.ibox(INDENT_UNIT)?; match input.ty.node { - ast::TyKind::Infer if is_closure => try!(self.print_pat(&input.pat)), + ast::TyKind::Infer if is_closure => self.print_pat(&input.pat)?, _ => { match input.pat.node { PatKind::Ident(_, ref path1, _) if @@ -2981,12 +2981,12 @@ impl<'a> State<'a> { // Do nothing. } _ => { - try!(self.print_pat(&input.pat)); - try!(word(&mut self.s, ":")); - try!(space(&mut self.s)); + self.print_pat(&input.pat)?; + word(&mut self.s, ":")?; + space(&mut self.s)?; } } - try!(self.print_type(&input.ty)); + self.print_type(&input.ty)?; } } self.end() @@ -2997,17 +2997,17 @@ impl<'a> State<'a> { return Ok(()); } - try!(self.space_if_not_bol()); - try!(self.ibox(INDENT_UNIT)); - try!(self.word_space("->")); + self.space_if_not_bol()?; + self.ibox(INDENT_UNIT)?; + self.word_space("->")?; match decl.output { ast::FunctionRetTy::None(_) => - try!(self.word_nbsp("!")), + self.word_nbsp("!")?, ast::FunctionRetTy::Default(..) => unreachable!(), ast::FunctionRetTy::Ty(ref ty) => - try!(self.print_type(&ty)) + self.print_type(&ty)? } - try!(self.end()); + self.end()?; match decl.output { ast::FunctionRetTy::Ty(ref output) => self.maybe_print_comment(output.span.lo), @@ -3023,10 +3023,10 @@ impl<'a> State<'a> { generics: &ast::Generics, opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { - try!(self.ibox(INDENT_UNIT)); + self.ibox(INDENT_UNIT)?; if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() { - try!(word(&mut self.s, "for")); - try!(self.print_generics(generics)); + word(&mut self.s, "for")?; + self.print_generics(generics)?; } let generics = ast::Generics { lifetimes: Vec::new(), @@ -3036,14 +3036,14 @@ impl<'a> State<'a> { predicates: Vec::new(), }, }; - try!(self.print_fn(decl, + self.print_fn(decl, unsafety, ast::Constness::NotConst, abi, name, &generics, opt_explicit_self, - ast::Visibility::Inherited)); + ast::Visibility::Inherited)?; self.end() } @@ -3063,7 +3063,7 @@ impl<'a> State<'a> { match next_pos { None => (), Some(p) => next = p } if span.hi < (*cmnt).pos && (*cmnt).pos < next && span_line.line == comment_line.line { - try!(self.print_comment(cmnt)); + self.print_comment(cmnt)?; self.cur_cmnt_and_lit.cur_cmnt += 1; } } @@ -3076,12 +3076,12 @@ impl<'a> State<'a> { // 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() { - try!(hardbreak(&mut self.s)); + hardbreak(&mut self.s)?; } loop { match self.next_comment() { Some(ref cmnt) => { - try!(self.print_comment(cmnt)); + self.print_comment(cmnt)?; self.cur_cmnt_and_lit.cur_cmnt += 1; } _ => break @@ -3096,7 +3096,7 @@ impl<'a> State<'a> { match opt_abi { Some(Abi::Rust) => Ok(()), Some(abi) => { - try!(self.word_nbsp("extern")); + self.word_nbsp("extern")?; self.word_nbsp(&abi.to_string()) } None => Ok(()) @@ -3107,7 +3107,7 @@ impl<'a> State<'a> { opt_abi: Option) -> io::Result<()> { match opt_abi { Some(abi) => { - try!(self.word_nbsp("extern")); + self.word_nbsp("extern")?; self.word_nbsp(&abi.to_string()) } None => Ok(()) @@ -3119,18 +3119,18 @@ impl<'a> State<'a> { constness: ast::Constness, abi: Abi, vis: ast::Visibility) -> io::Result<()> { - try!(word(&mut self.s, &visibility_qualified(vis, ""))); + word(&mut self.s, &visibility_qualified(vis, ""))?; match constness { ast::Constness::NotConst => {} - ast::Constness::Const => try!(self.word_nbsp("const")) + ast::Constness::Const => self.word_nbsp("const")? } - try!(self.print_unsafety(unsafety)); + self.print_unsafety(unsafety)?; if abi != Abi::Rust { - try!(self.word_nbsp("extern")); - try!(self.word_nbsp(&abi.to_string())); + self.word_nbsp("extern")?; + self.word_nbsp(&abi.to_string())?; } word(&mut self.s, "fn") -- cgit 1.4.1-3-g733a5 From aa7fe93d4a6217dd6f2538bce857ab6a097afbeb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 21 Mar 2016 02:23:03 -0500 Subject: sprinkle feature gates here and there --- src/compiletest/compiletest.rs | 1 + src/libcore/lib.rs | 1 + src/libgraphviz/lib.rs | 1 + src/librbml/lib.rs | 1 + src/librustc/lib.rs | 1 + src/librustc_back/lib.rs | 1 + src/librustc_const_eval/lib.rs | 1 + src/librustc_driver/lib.rs | 1 + src/librustc_front/lib.rs | 1 + src/librustc_metadata/lib.rs | 1 + src/librustc_mir/lib.rs | 1 + src/librustc_trans/lib.rs | 1 + src/librustc_typeck/lib.rs | 1 + src/librustdoc/lib.rs | 1 + src/libserialize/lib.rs | 1 + src/libstd/lib.rs | 1 + src/libsyntax/lib.rs | 1 + src/libterm/lib.rs | 1 + src/libtest/lib.rs | 1 + src/test/run-pass/ifmt.rs | 1 + src/test/run-pass/issue-17121.rs | 2 ++ src/test/run-pass/issue-20797.rs | 2 ++ src/test/run-pass/issue-21400.rs | 2 ++ src/tools/error_index_generator/main.rs | 1 + src/tools/rustbook/main.rs | 1 + 25 files changed, 28 insertions(+) (limited to 'src/libsyntax') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 4c845efdf34..d98055edf85 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -15,6 +15,7 @@ #![feature(rustc_private)] #![feature(str_char)] #![feature(test)] +#![feature(question_mark)] #![deny(warnings)] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index f199909dfa9..648b652772a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -77,6 +77,7 @@ #![feature(rustc_attrs)] #![feature(staged_api)] #![feature(unboxed_closures)] +#![feature(question_mark)] #[macro_use] mod macros; diff --git a/src/libgraphviz/lib.rs b/src/libgraphviz/lib.rs index d4d3ac93c97..74cc498a7df 100644 --- a/src/libgraphviz/lib.rs +++ b/src/libgraphviz/lib.rs @@ -295,6 +295,7 @@ #![cfg_attr(not(stage0), deny(warnings))] #![feature(str_escape)] +#![feature(question_mark)] use self::LabelText::*; diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index a02c02cc030..34726a7a6c8 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -125,6 +125,7 @@ #![feature(copy_from_slice)] #![feature(rustc_private)] #![feature(staged_api)] +#![feature(question_mark)] #![cfg_attr(test, feature(test))] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d2ca1cd3f93..d8d0079b3e3 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -39,6 +39,7 @@ #![feature(slice_patterns)] #![feature(staged_api)] #![feature(str_char)] +#![feature(question_mark)] #![cfg_attr(test, feature(test))] extern crate arena; diff --git a/src/librustc_back/lib.rs b/src/librustc_back/lib.rs index 3ffc031d621..d854b9ed697 100644 --- a/src/librustc_back/lib.rs +++ b/src/librustc_back/lib.rs @@ -38,6 +38,7 @@ #![feature(rustc_private)] #![feature(staged_api)] #![feature(step_by)] +#![feature(question_mark)] #![cfg_attr(unix, feature(static_mutex))] #![cfg_attr(test, feature(test, rand))] diff --git a/src/librustc_const_eval/lib.rs b/src/librustc_const_eval/lib.rs index e4c702f643b..80b8c75104a 100644 --- a/src/librustc_const_eval/lib.rs +++ b/src/librustc_const_eval/lib.rs @@ -25,6 +25,7 @@ #![feature(rustc_private)] #![feature(staged_api)] +#![feature(question_mark)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 0fb192bb4db..dc30b4f91a9 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -30,6 +30,7 @@ #![feature(rustc_private)] #![feature(set_stdio)] #![feature(staged_api)] +#![feature(question_mark)] extern crate arena; extern crate flate; diff --git a/src/librustc_front/lib.rs b/src/librustc_front/lib.rs index 02ad69e8a7c..b9e3b71cf1a 100644 --- a/src/librustc_front/lib.rs +++ b/src/librustc_front/lib.rs @@ -33,6 +33,7 @@ #![feature(slice_patterns)] #![feature(staged_api)] #![feature(str_char)] +#![feature(question_mark)] extern crate serialize; #[macro_use] diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index f0f0fb84754..a6c612f5397 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -23,6 +23,7 @@ #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] +#![feature(question_mark)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 7c8c8945bbc..67bac196f48 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -23,6 +23,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(box_patterns)] #![feature(rustc_private)] #![feature(staged_api)] +#![feature(question_mark)] #[macro_use] extern crate log; extern crate graphviz as dot; diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index c8ce09b4d79..f8bbde60109 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -36,6 +36,7 @@ #![feature(slice_patterns)] #![feature(staged_api)] #![feature(unicode)] +#![feature(question_mark)] extern crate arena; extern crate flate; diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index ac760cc9056..07e5ad6fb44 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -81,6 +81,7 @@ This API is completely unstable and subject to change. #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] #![feature(staged_api)] +#![feature(question_mark)] #[macro_use] extern crate log; #[macro_use] extern crate syntax; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 9dec4eb32d7..cde472a3b20 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -29,6 +29,7 @@ #![feature(std_panic)] #![feature(test)] #![feature(unicode)] +#![feature(question_mark)] extern crate arena; extern crate getopts; diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index d683769af7b..173ecca648c 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -34,6 +34,7 @@ Core encoding and decoding interfaces. #![feature(staged_api)] #![feature(str_char)] #![feature(unicode)] +#![feature(question_mark)] #![cfg_attr(test, feature(test))] // test harness access diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 85e48f85d3d..5608bb646a4 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -270,6 +270,7 @@ #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(zero_one)] +#![feature(question_mark)] // Issue# 30592: Systematically use alloc_system during stage0 since jemalloc // might be unavailable or disabled diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 04a3cf096ba..7f8472f8b28 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -32,6 +32,7 @@ #![feature(str_char)] #![feature(str_escape)] #![feature(unicode)] +#![feature(question_mark)] extern crate serialize; extern crate term; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 01daa938142..0244e265796 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -59,6 +59,7 @@ #![cfg_attr(windows, feature(libc))] // Handle rustfmt skips #![feature(custom_attribute)] +#![feature(question_mark)] #![allow(unused_attributes)] use std::io::prelude::*; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index e637246a157..e4d7697a71b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -40,6 +40,7 @@ #![feature(rustc_private)] #![feature(set_stdio)] #![feature(staged_api)] +#![feature(question_mark)] extern crate getopts; extern crate term; diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 71fe4d6ece6..267b162a1d2 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -14,6 +14,7 @@ #![allow(unused_must_use)] #![allow(unknown_features)] #![feature(box_syntax)] +#![feature(question_mark)] use std::fmt::{self, Write}; use std::usize; diff --git a/src/test/run-pass/issue-17121.rs b/src/test/run-pass/issue-17121.rs index dcbcc2d44b5..b3c80041ef8 100644 --- a/src/test/run-pass/issue-17121.rs +++ b/src/test/run-pass/issue-17121.rs @@ -10,6 +10,8 @@ // pretty-expanded FIXME #23616 +#![feature(question_mark)] + use std::fs::File; use std::io::{self, BufReader, Read}; diff --git a/src/test/run-pass/issue-20797.rs b/src/test/run-pass/issue-20797.rs index d4c5dfb7463..321ed1a3bb2 100644 --- a/src/test/run-pass/issue-20797.rs +++ b/src/test/run-pass/issue-20797.rs @@ -12,6 +12,8 @@ // pretty-expanded FIXME #23616 +#![feature(question_mark)] + use std::default::Default; use std::io; use std::fs; diff --git a/src/test/run-pass/issue-21400.rs b/src/test/run-pass/issue-21400.rs index 6715b71a5f5..0d1be964748 100644 --- a/src/test/run-pass/issue-21400.rs +++ b/src/test/run-pass/issue-21400.rs @@ -11,6 +11,8 @@ // Regression test for #21400 which itself was extracted from // stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580 +#![feature(question_mark)] + fn main() { let mut t = Test; assert_eq!(t.method1("one"), Ok(1)); diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 7f80c17b756..fd7441d85ce 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -9,6 +9,7 @@ // except according to those terms. #![feature(rustc_private, rustdoc)] +#![feature(question_mark)] extern crate syntax; extern crate rustdoc; diff --git a/src/tools/rustbook/main.rs b/src/tools/rustbook/main.rs index bd4fc899293..5ad4982e8af 100644 --- a/src/tools/rustbook/main.rs +++ b/src/tools/rustbook/main.rs @@ -13,6 +13,7 @@ #![feature(iter_arith)] #![feature(rustc_private)] #![feature(rustdoc)] +#![feature(question_mark)] extern crate rustdoc; extern crate rustc_back; -- cgit 1.4.1-3-g733a5 From bd71d11a8f75b9957489c795a1551a0cd489eca3 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 21 Mar 2016 03:38:25 -0500 Subject: break long line --- src/libsyntax/codemap.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 80b806b7b50..a12016418c6 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -617,7 +617,8 @@ impl Decodable for FileMap { Ok(lines) })?; - let multibyte_chars: Vec = d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?; + let multibyte_chars: Vec = + d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?; Ok(FileMap { name: name, start_pos: start_pos, -- cgit 1.4.1-3-g733a5 From 2628f3cc8f91a52d9dcc800afb6c4a7dc0c785e0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 22 Mar 2016 17:58:45 -0500 Subject: fix alignment --- src/compiletest/compiletest.rs | 8 +- src/librustc/middle/def_id.rs | 2 +- src/librustc/middle/infer/combine.rs | 18 +- src/librustc/middle/infer/sub.rs | 4 +- src/librustc/middle/traits/select.rs | 16 +- src/librustc/middle/ty/relate.rs | 14 +- src/librustc/mir/repr.rs | 4 +- src/librustc/util/ppaux.rs | 10 +- src/librustc_back/target/mod.rs | 2 +- src/librustc_borrowck/borrowck/mir/graphviz.rs | 42 ++-- src/librustc_driver/driver.rs | 32 +-- src/librustc_front/print/pprust.rs | 106 +++++----- src/librustc_mir/graphviz.rs | 10 +- src/librustc_trans/back/archive.rs | 4 +- src/librustc_trans/trans/consts.rs | 2 +- src/librustc_typeck/astconv.rs | 8 +- src/librustc_typeck/check/dropck.rs | 11 +- src/librustc_typeck/lib.rs | 12 +- src/librustdoc/html/format.rs | 27 ++- src/librustdoc/html/highlight.rs | 5 +- src/librustdoc/html/render.rs | 273 ++++++++++++------------- src/librustdoc/html/toc.rs | 8 +- src/libstd/sys/common/net.rs | 12 +- src/libstd/sys/unix/ext/net.rs | 10 +- src/libstd/sys/unix/os.rs | 12 +- src/libstd/sys/unix/process.rs | 2 +- src/libstd/sys/windows/fs.rs | 2 +- src/libstd/sys/windows/process.rs | 4 +- src/libsyntax/codemap.rs | 130 ++++++------ src/libsyntax/errors/emitter.rs | 24 +-- src/libsyntax/parse/parser.rs | 41 ++-- src/libsyntax/print/pprust.rs | 76 ++++--- src/tools/error_index_generator/main.rs | 4 +- src/tools/rustbook/build.rs | 8 +- 34 files changed, 464 insertions(+), 479 deletions(-) (limited to 'src/libsyntax') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index d98055edf85..95838e03d23 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -312,10 +312,10 @@ fn collect_tests_from_dir(config: &Config, } else if file_path.is_dir() { let relative_file_path = relative_dir_path.join(file.file_name()); collect_tests_from_dir(config, - base, - &file_path, - &relative_file_path, - tests)?; + base, + &file_path, + relative_file_path, + tests)?; } } Ok(()) diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs index 98fdcc65835..f5bdf28a4b1 100644 --- a/src/librustc/middle/def_id.rs +++ b/src/librustc/middle/def_id.rs @@ -56,7 +56,7 @@ pub struct DefId { impl fmt::Debug for DefId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "DefId {{ krate: {:?}, node: {:?}", - self.krate, self.index)?; + self.krate, self.index)?; // Unfortunately, there seems to be no way to attempt to print // a path for a def-id, so I'll just make a best effort for now diff --git a/src/librustc/middle/infer/combine.rs b/src/librustc/middle/infer/combine.rs index cbb5586f720..f67389e3c3b 100644 --- a/src/librustc/middle/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -71,9 +71,9 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>, // Relate integral variables to other types (&ty::TyInfer(ty::IntVar(a_id)), &ty::TyInfer(ty::IntVar(b_id))) => { infcx.int_unification_table - .borrow_mut() - .unify_var_var(a_id, b_id) - .map_err(|e| int_unification_error(a_is_expected, e))?; + .borrow_mut() + .unify_var_var(a_id, b_id) + .map_err(|e| int_unification_error(a_is_expected, e))?; Ok(a) } (&ty::TyInfer(ty::IntVar(v_id)), &ty::TyInt(v)) => { @@ -92,9 +92,9 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>, // Relate floating-point variables to other types (&ty::TyInfer(ty::FloatVar(a_id)), &ty::TyInfer(ty::FloatVar(b_id))) => { infcx.float_unification_table - .borrow_mut() - .unify_var_var(a_id, b_id) - .map_err(|e| float_unification_error(relation.a_is_expected(), e))?; + .borrow_mut() + .unify_var_var(a_id, b_id) + .map_err(|e| float_unification_error(relation.a_is_expected(), e))?; Ok(a) } (&ty::TyInfer(ty::FloatVar(v_id)), &ty::TyFloat(v)) => { @@ -123,8 +123,7 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, val: ty::IntVarValue) -> RelateResult<'tcx, Ty<'tcx>> { - infcx - .int_unification_table + infcx.int_unification_table .borrow_mut() .unify_var_value(vid, val) .map_err(|e| int_unification_error(vid_is_expected, e))?; @@ -140,8 +139,7 @@ fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, val: ast::FloatTy) -> RelateResult<'tcx, Ty<'tcx>> { - infcx - .float_unification_table + infcx.float_unification_table .borrow_mut() .unify_var_value(vid, val) .map_err(|e| float_unification_error(vid_is_expected, e))?; diff --git a/src/librustc/middle/infer/sub.rs b/src/librustc/middle/infer/sub.rs index 34b9953c529..e94311697c3 100644 --- a/src/librustc/middle/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -76,8 +76,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> { } (&ty::TyInfer(TyVar(a_id)), _) => { self.fields - .switch_expected() - .instantiate(b, SupertypeOf, a_id)?; + .switch_expected() + .instantiate(b, SupertypeOf, a_id)?; Ok(a) } (_, &ty::TyInfer(TyVar(b_id))) => { diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index ffef509de95..3eaf123e5be 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1038,15 +1038,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // For other types, we'll use the builtin rules. self.assemble_builtin_bound_candidates(ty::BoundCopy, - obligation, - &mut candidates)?; + obligation, + &mut candidates)?; } Some(bound @ ty::BoundSized) => { // Sized is never implementable by end-users, it is // always automatically computed. self.assemble_builtin_bound_candidates(bound, - obligation, - &mut candidates)?; + obligation, + &mut candidates)?; } None if self.tcx().lang_items.unsize_trait() == @@ -2422,8 +2422,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_bound(|(trait_ref, _)| trait_ref); self.confirm_poly_trait_refs(obligation.cause.clone(), - obligation.predicate.to_poly_trait_ref(), - trait_ref)?; + obligation.predicate.to_poly_trait_ref(), + trait_ref)?; Ok(self_ty) } @@ -2450,8 +2450,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations); self.confirm_poly_trait_refs(obligation.cause.clone(), - obligation.predicate.to_poly_trait_ref(), - trait_ref)?; + obligation.predicate.to_poly_trait_ref(), + trait_ref)?; Ok(VtableClosureData { closure_def_id: closure_def_id, diff --git a/src/librustc/middle/ty/relate.rs b/src/librustc/middle/ty/relate.rs index b67fee7239b..1df7a440f4f 100644 --- a/src/librustc/middle/ty/relate.rs +++ b/src/librustc/middle/ty/relate.rs @@ -167,9 +167,9 @@ pub fn relate_substs<'a,'tcx:'a,R>(relation: &mut R, let b_regions = b.get_slice(space); let r_variances = variances.map(|v| v.regions.get_slice(space)); let regions = relate_region_params(relation, - r_variances, - a_regions, - b_regions)?; + r_variances, + a_regions, + b_regions)?; substs.mut_regions().replace(space, regions); } } @@ -261,8 +261,8 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> { } let inputs = relate_arg_vecs(relation, - &a.inputs, - &b.inputs)?; + &a.inputs, + &b.inputs)?; let output = match (a.output, b.output) { (ty::FnConverging(a_ty), ty::FnConverging(b_ty)) => @@ -557,8 +557,8 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R, { if as_.len() == bs.len() { let ts = as_.iter().zip(bs) - .map(|(a, b)| relation.relate(a, b)) - .collect::>()?; + .map(|(a, b)| relation.relate(a, b)) + .collect::>()?; Ok(tcx.mk_tup(ts)) } else if !(as_.is_empty() || bs.is_empty()) { Err(TypeError::TupleSize( diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 8c4a91bd88d..ff3e292f458 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -809,8 +809,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { let variant_def = &adt_def.variants[variant]; ppaux::parameterized(fmt, substs, variant_def.did, - ppaux::Ns::Value, &[], - |tcx| { + ppaux::Ns::Value, &[], + |tcx| { tcx.lookup_item_type(variant_def.did).generics })?; diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index cdf8912a3c4..64619e40f49 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -123,8 +123,8 @@ pub fn parameterized(f: &mut fmt::Formatter, for projection in projections { start_or_continue(f, "<", ", ")?; write!(f, "{}={}", - projection.projection_ty.item_name, - projection.ty)?; + projection.projection_ty.item_name, + projection.ty)?; } return start_or_continue(f, "", ">"); } @@ -201,8 +201,8 @@ pub fn parameterized(f: &mut fmt::Formatter, for projection in projections { start_or_continue(f, "<", ", ")?; write!(f, "{}={}", - projection.projection_ty.item_name, - projection.ty)?; + projection.projection_ty.item_name, + projection.ty)?; } start_or_continue(f, "", ">")?; @@ -865,7 +865,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { write!(f, "{} {{", bare_fn.sig.0)?; parameterized(f, substs, def_id, Ns::Value, &[], - |tcx| tcx.lookup_item_type(def_id).generics)?; + |tcx| tcx.lookup_item_type(def_id).generics)?; write!(f, "}}") } TyFnPtr(ref bare_fn) => { diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 3fc19f9bed5..a8eac524971 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -468,7 +468,7 @@ impl Target { let mut contents = Vec::new(); f.read_to_end(&mut contents).map_err(|e| e.to_string())?; let obj = json::from_reader(&mut &contents[..]) - .map_err(|e| e.to_string())?; + .map_err(|e| e.to_string())?; Ok(Target::from_json(obj)) } diff --git a/src/librustc_borrowck/borrowck/mir/graphviz.rs b/src/librustc_borrowck/borrowck/mir/graphviz.rs index b1d3b215ab4..460c71dee3d 100644 --- a/src/librustc_borrowck/borrowck/mir/graphviz.rs +++ b/src/librustc_borrowck/borrowck/mir/graphviz.rs @@ -124,15 +124,15 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { write!(w, "")?; } write!(w, "{objs:?}", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT, - objs = c)?; + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT, + objs = c)?; seen_one = true; } if !seen_one { write!(w, "[]", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT)?; + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT)?; } Ok(()) } @@ -155,18 +155,18 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { let kill = flow.interpret_set(flow.sets.kill_set_for(i)); chunked_present_left(w, &gen[..], chunk_size)?; write!(w, " = GEN:{genbits:?}\ - ", - bg = BG_FLOWCONTENT, - face = FACE_MONOSPACE, - genbits=bits_to_string( flow.sets.gen_set_for(i), - flow.sets.bytes_per_block()))?; + ", + bg = BG_FLOWCONTENT, + face = FACE_MONOSPACE, + genbits=bits_to_string( flow.sets.gen_set_for(i), + flow.sets.bytes_per_block()))?; write!(w, "KILL:\ - {killbits:?}", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT, - face = FACE_MONOSPACE, - killbits=bits_to_string(flow.sets.kill_set_for(i), - flow.sets.bytes_per_block()))?; + {killbits:?}", + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT, + face = FACE_MONOSPACE, + killbits=bits_to_string(flow.sets.kill_set_for(i), + flow.sets.bytes_per_block()))?; // (chunked_present_right) let mut seen_one = false; @@ -174,19 +174,19 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { if !seen_one { // continuation of row; this is fourth write!(w, "= {kill:?}", - bg = BG_FLOWCONTENT, - kill=k)?; + bg = BG_FLOWCONTENT, + kill=k)?; } else { // new row, with indent of three 's write!(w, "{kill:?}", - bg = BG_FLOWCONTENT, - kill=k)?; + bg = BG_FLOWCONTENT, + kill=k)?; } seen_one = true; } if !seen_one { write!(w, "= []", - bg = BG_FLOWCONTENT)?; + bg = BG_FLOWCONTENT)?; } Ok(()) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c64e6d1801d..55b873c0663 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -100,10 +100,10 @@ pub fn compile_input(sess: &Session, let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess); let id = link::find_crate_name(Some(sess), &krate.attrs, input); let expanded_crate = phase_2_configure_and_expand(sess, - &cstore, - krate, - &id[..], - addl_plugins)?; + &cstore, + krate, + &id[..], + addl_plugins)?; (outputs, expanded_crate, id) }; @@ -169,12 +169,12 @@ pub fn compile_input(sess: &Session, }; phase_3_run_analysis_passes(sess, - &cstore, - hir_map, - &arenas, - &id, - control.make_glob_map, - |tcx, mir_map, analysis, result| { + &cstore, + hir_map, + &arenas, + &id, + control.make_glob_map, + |tcx, mir_map, analysis, result| { { // Eventually, we will want to track plugins. let _ignore = tcx.dep_graph.in_ignore(); @@ -683,8 +683,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, })?; time(time_passes, - "const fn bodies and arguments", - || const_fn::check_crate(sess, &krate))?; + "const fn bodies and arguments", + || const_fn::check_crate(sess, &krate))?; if sess.opts.debugging_opts.input_stats { println!("Post-expansion node count: {}", count_nodes(&krate)); @@ -781,10 +781,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, }; let named_region_map = time(time_passes, - "lifetime resolution", - || middle::resolve_lifetime::krate(sess, - &hir_map, - &def_map.borrow()))?; + "lifetime resolution", + || middle::resolve_lifetime::krate(sess, + &hir_map, + &def_map.borrow()))?; time(time_passes, "looking for entry point", diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index a647ba8b57c..3b8e6763de0 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -288,13 +288,13 @@ pub fn fun_to_string(decl: &hir::FnDecl, to_string(|s| { s.head("")?; s.print_fn(decl, - unsafety, - constness, - Abi::Rust, - Some(name), - generics, - opt_explicit_self, - hir::Inherited)?; + unsafety, + constness, + Abi::Rust, + Some(name), + generics, + opt_explicit_self, + hir::Inherited)?; s.end()?; // Close the head box s.end() // Close the outer box }) @@ -567,13 +567,13 @@ impl<'a> State<'a> { hir::ForeignItemFn(ref decl, ref generics) => { self.head("")?; self.print_fn(decl, - hir::Unsafety::Normal, - hir::Constness::NotConst, - Abi::Rust, - Some(item.name), - generics, - None, - item.vis)?; + hir::Unsafety::Normal, + hir::Constness::NotConst, + Abi::Rust, + Some(item.name), + generics, + None, + item.vis)?; self.end()?; // end head-ibox word(&mut self.s, ";")?; self.end() // end the outer fn box @@ -704,13 +704,13 @@ impl<'a> State<'a> { hir::ItemFn(ref decl, unsafety, constness, abi, ref typarams, ref body) => { self.head("")?; self.print_fn(decl, - unsafety, - constness, - abi, - Some(item.name), - typarams, - None, - item.vis)?; + unsafety, + constness, + abi, + Some(item.name), + typarams, + None, + item.vis)?; word(&mut self.s, " ")?; self.print_block_with_attrs(&body, &item.attrs)?; } @@ -984,9 +984,9 @@ impl<'a> State<'a> { match ti.node { hir::ConstTraitItem(ref ty, ref default) => { self.print_associated_const(ti.name, - &ty, - default.as_ref().map(|expr| &**expr), - hir::Inherited)?; + &ty, + default.as_ref().map(|expr| &**expr), + hir::Inherited)?; } hir::MethodTraitItem(ref sig, ref body) => { if body.is_some() { @@ -1002,8 +1002,8 @@ impl<'a> State<'a> { } hir::TypeTraitItem(ref bounds, ref default) => { self.print_associated_type(ti.name, - Some(bounds), - default.as_ref().map(|ty| &**ty))?; + Some(bounds), + default.as_ref().map(|ty| &**ty))?; } } self.ann.post(self, NodeSubItem(ti.id)) @@ -1219,15 +1219,15 @@ impl<'a> State<'a> { self.print_path(path, true, 0)?; word(&mut self.s, "{")?; self.commasep_cmnt(Consistent, - &fields[..], - |s, field| { - s.ibox(indent_unit)?; - s.print_name(field.name.node)?; - s.word_space(":")?; - s.print_expr(&field.expr)?; - s.end() - }, - |f| f.span)?; + &fields[..], + |s, field| { + s.ibox(indent_unit)?; + s.print_name(field.name.node)?; + s.word_space(":")?; + s.print_expr(&field.expr)?; + s.end() + }, + |f| f.span)?; match *wth { Some(ref expr) => { self.ibox(indent_unit)?; @@ -1760,17 +1760,17 @@ impl<'a> State<'a> { self.nbsp()?; self.word_space("{")?; self.commasep_cmnt(Consistent, - &fields[..], - |s, f| { - s.cbox(indent_unit)?; - if !f.node.is_shorthand { - s.print_name(f.node.name)?; - s.word_nbsp(":")?; - } - s.print_pat(&f.node.pat)?; - s.end() - }, - |f| f.node.pat.span)?; + &fields[..], + |s, f| { + s.cbox(indent_unit)?; + if !f.node.is_shorthand { + s.print_name(f.node.name)?; + s.word_nbsp(":")?; + } + s.print_pat(&f.node.pat)?; + s.end() + }, + |f| f.node.pat.span)?; if etc { if !fields.is_empty() { self.word_space(",")?; @@ -2261,13 +2261,13 @@ impl<'a> State<'a> { }, }; self.print_fn(decl, - unsafety, - hir::Constness::NotConst, - abi, - name, - &generics, - opt_explicit_self, - hir::Inherited)?; + unsafety, + hir::Constness::NotConst, + abi, + name, + &generics, + opt_explicit_self, + hir::Inherited)?; self.end() } diff --git a/src/librustc_mir/graphviz.rs b/src/librustc_mir/graphviz.rs index 349d8e786c4..953eb724f50 100644 --- a/src/librustc_mir/graphviz.rs +++ b/src/librustc_mir/graphviz.rs @@ -65,9 +65,9 @@ pub fn write_node_label(block: BasicBlock, // Basic block number at the top. write!(w, r#"{blk}"#, - attrs=r#"bgcolor="gray" align="center""#, - colspan=num_cols, - blk=block.index())?; + attrs=r#"bgcolor="gray" align="center""#, + colspan=num_cols, + blk=block.index())?; init(w)?; @@ -145,13 +145,13 @@ fn write_graph_label(tcx: &ty::TyCtxt, nid: NodeId, mir: &Mir, w: &mut write!(w, "mut ")?; } write!(w, r#"{:?}: {}; // {}
"#, - Lvalue::Var(i as u32), escape(&var.ty), var.name)?; + Lvalue::Var(i as u32), escape(&var.ty), var.name)?; } // Compiler-introduced temporary types. for (i, temp) in mir.temp_decls.iter().enumerate() { write!(w, r#"let mut {:?}: {};
"#, - Lvalue::Temp(i as u32), escape(&temp.ty))?; + Lvalue::Temp(i as u32), escape(&temp.ty))?; } writeln!(w, ">;") diff --git a/src/librustc_trans/back/archive.rs b/src/librustc_trans/back/archive.rs index f5b48081010..514fc52d008 100644 --- a/src/librustc_trans/back/archive.rs +++ b/src/librustc_trans/back/archive.rs @@ -255,7 +255,7 @@ impl<'a> ArchiveBuilder<'a> { // permission bits. if let Some(ref s) = self.config.src { io::copy(&mut File::open(s)?, - &mut File::create(&self.config.dst)?)?; + &mut File::create(&self.config.dst)?)?; } if removals.len() > 0 { @@ -272,7 +272,7 @@ impl<'a> ArchiveBuilder<'a> { } Addition::Archive { archive, archive_name, mut skip } => { self.add_archive_members(&mut members, archive, - &archive_name, &mut *skip)?; + &archive_name, &mut *skip)?; } } } diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 12bcd34a663..dd6856916f6 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -976,7 +976,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let method_call = ty::MethodCall::expr(e.id); let method = cx.tcx().tables.borrow().method_map[&method_call]; const_fn_call(cx, method.def_id, method.substs.clone(), - &arg_vals, param_substs, trueconst)? + &arg_vals, param_substs, trueconst)? }, hir::ExprType(ref e, _) => const_expr(cx, &e, param_substs, fn_args, trueconst)?.0, hir::ExprBlock(ref block) => { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 0cc1fb9e1c7..67bd79bb57e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -954,10 +954,10 @@ fn ast_type_binding_to_poly_projection_predicate<'tcx>( } let candidate = one_bound_for_assoc_type(tcx, - candidates, - &trait_ref.to_string(), - &binding.item_name.as_str(), - binding.span)?; + candidates, + &trait_ref.to_string(), + &binding.item_name.as_str(), + binding.span)?; Ok(ty::Binder(ty::ProjectionPredicate { // <-------------------------+ projection_ty: ty::ProjectionTy { // | diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index c79a35b2f33..7dd5db831fd 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -47,10 +47,10 @@ pub fn check_drop_impl(tcx: &TyCtxt, drop_impl_did: DefId) -> Result<(), ()> { ty::TyEnum(adt_def, self_to_impl_substs) | ty::TyStruct(adt_def, self_to_impl_substs) => { ensure_drop_params_and_item_params_correspond(tcx, - drop_impl_did, - dtor_generics, - &dtor_self_type, - adt_def.did)?; + drop_impl_did, + dtor_generics, + &dtor_self_type, + adt_def.did)?; ensure_drop_predicates_are_implied_by_item_defn(tcx, drop_impl_did, @@ -469,8 +469,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>( ty::TyTuple(ref tys) | ty::TyClosure(_, box ty::ClosureSubsts { upvar_tys: ref tys, .. }) => { for ty in tys { - iterate_over_potentially_unsafe_regions_in_type( - cx, context, ty, depth+1)? + iterate_over_potentially_unsafe_regions_in_type(cx, context, ty, depth+1)? } Ok(()) } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 07e5ad6fb44..4e1f3d3cbb7 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -354,17 +354,13 @@ pub fn check_crate(tcx: &TyCtxt, trait_map: ty::TraitMap) -> CompileResult { coherence::check_coherence(&ccx)); })?; - time(time_passes, "wf checking", || - check::check_wf_new(&ccx))?; + time(time_passes, "wf checking", || check::check_wf_new(&ccx))?; - time(time_passes, "item-types checking", || - check::check_item_types(&ccx))?; + time(time_passes, "item-types checking", || check::check_item_types(&ccx))?; - time(time_passes, "item-bodies checking", || - check::check_item_bodies(&ccx))?; + time(time_passes, "item-bodies checking", || check::check_item_bodies(&ccx))?; - time(time_passes, "drop-impl checking", || - check::check_drop_impls(&ccx))?; + time(time_passes, "drop-impl checking", || check::check_drop_impls(&ccx))?; check_for_entry_fn(&ccx); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index f666a0a1017..e9a883d6d7a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -344,9 +344,9 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, root.push_str(&seg.name); root.push_str("/"); write!(w, "{}::", - root, - seg.name)?; + href='{}index.html'>{}::", + root, + seg.name)?; } } } @@ -361,7 +361,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, match href(did) { Some((url, shortty, fqp)) => { write!(w, "{}", - shortty, url, fqp.join("::"), last.name)?; + shortty, url, fqp.join("::"), last.name)?; } _ => write!(w, "{}", last.name)?, } @@ -379,8 +379,8 @@ fn primitive_link(f: &mut fmt::Formatter, let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len()); let len = if len == 0 {0} else {len - 1}; write!(f, "", - repeat("../").take(len).collect::(), - prim.to_url_str())?; + repeat("../").take(len).collect::(), + prim.to_url_str())?; needs_termination = true; } Some(&cnum) => { @@ -399,9 +399,9 @@ fn primitive_link(f: &mut fmt::Formatter, match loc { Some(root) => { write!(f, "", - root, - path.0.first().unwrap(), - prim.to_url_str())?; + root, + path.0.first().unwrap(), + prim.to_url_str())?; needs_termination = true; } None => {} @@ -490,7 +490,7 @@ impl fmt::Display for clean::Type { } _ => { primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer, - &format!("*{}", RawMutableSpace(m)))?; + &format!("*{}", RawMutableSpace(m)))?; write!(f, "{}", t) } } @@ -508,8 +508,7 @@ impl fmt::Display for clean::Type { primitive_link(f, clean::Slice, &format!("&{}{}[{}]", lt, m, **bt)), _ => { - primitive_link(f, clean::Slice, - &format!("&{}{}[", lt, m))?; + primitive_link(f, clean::Slice, &format!("&{}{}[", lt, m))?; write!(f, "{}", **bt)?; primitive_link(f, clean::Slice, "]") } @@ -567,8 +566,8 @@ impl fmt::Display for clean::Impl { write!(f, "impl{} ", self.generics)?; if let Some(ref ty) = self.trait_ { write!(f, "{}{} for ", - if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" }, - *ty)?; + if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" }, + *ty)?; } write!(f, "{}{}", self.for_, WhereClause(&self.generics))?; Ok(()) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 778d34c0080..b3cad90ccb5 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -71,7 +71,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, }, token::Comment => { write!(out, "{}", - Escape(&snip(next.sp)))?; + Escape(&snip(next.sp)))?; continue }, token::Shebang(s) => { @@ -180,8 +180,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, if klass == "" { write!(out, "{}", Escape(&snip))?; } else { - write!(out, "{}", klass, - Escape(&snip))?; + write!(out, "{}", klass, Escape(&snip))?; } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 689b8bd9395..9e74702e06c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -630,45 +630,45 @@ fn write_shared(cx: &Context, // Add all the static files. These may already exist, but we just // overwrite them anyway to make sure that they're fresh and up-to-date. write(cx.dst.join("jquery.js"), - include_bytes!("static/jquery-2.1.4.min.js"))?; + include_bytes!("static/jquery-2.1.4.min.js"))?; write(cx.dst.join("main.js"), - include_bytes!("static/main.js"))?; + include_bytes!("static/main.js"))?; write(cx.dst.join("playpen.js"), - include_bytes!("static/playpen.js"))?; + include_bytes!("static/playpen.js"))?; write(cx.dst.join("rustdoc.css"), - include_bytes!("static/rustdoc.css"))?; + include_bytes!("static/rustdoc.css"))?; write(cx.dst.join("main.css"), - include_bytes!("static/styles/main.css"))?; + include_bytes!("static/styles/main.css"))?; write(cx.dst.join("normalize.css"), - include_bytes!("static/normalize.css"))?; + include_bytes!("static/normalize.css"))?; write(cx.dst.join("FiraSans-Regular.woff"), - include_bytes!("static/FiraSans-Regular.woff"))?; + include_bytes!("static/FiraSans-Regular.woff"))?; write(cx.dst.join("FiraSans-Medium.woff"), - include_bytes!("static/FiraSans-Medium.woff"))?; + include_bytes!("static/FiraSans-Medium.woff"))?; write(cx.dst.join("FiraSans-LICENSE.txt"), - include_bytes!("static/FiraSans-LICENSE.txt"))?; + include_bytes!("static/FiraSans-LICENSE.txt"))?; write(cx.dst.join("Heuristica-Italic.woff"), - include_bytes!("static/Heuristica-Italic.woff"))?; + include_bytes!("static/Heuristica-Italic.woff"))?; write(cx.dst.join("Heuristica-LICENSE.txt"), - include_bytes!("static/Heuristica-LICENSE.txt"))?; + include_bytes!("static/Heuristica-LICENSE.txt"))?; write(cx.dst.join("SourceSerifPro-Regular.woff"), - include_bytes!("static/SourceSerifPro-Regular.woff"))?; + include_bytes!("static/SourceSerifPro-Regular.woff"))?; write(cx.dst.join("SourceSerifPro-Bold.woff"), - include_bytes!("static/SourceSerifPro-Bold.woff"))?; + include_bytes!("static/SourceSerifPro-Bold.woff"))?; write(cx.dst.join("SourceSerifPro-LICENSE.txt"), - include_bytes!("static/SourceSerifPro-LICENSE.txt"))?; + include_bytes!("static/SourceSerifPro-LICENSE.txt"))?; write(cx.dst.join("SourceCodePro-Regular.woff"), - include_bytes!("static/SourceCodePro-Regular.woff"))?; + include_bytes!("static/SourceCodePro-Regular.woff"))?; write(cx.dst.join("SourceCodePro-Semibold.woff"), - include_bytes!("static/SourceCodePro-Semibold.woff"))?; + include_bytes!("static/SourceCodePro-Semibold.woff"))?; write(cx.dst.join("SourceCodePro-LICENSE.txt"), - include_bytes!("static/SourceCodePro-LICENSE.txt"))?; + include_bytes!("static/SourceCodePro-LICENSE.txt"))?; write(cx.dst.join("LICENSE-MIT.txt"), - include_bytes!("static/LICENSE-MIT.txt"))?; + include_bytes!("static/LICENSE-MIT.txt"))?; write(cx.dst.join("LICENSE-APACHE.txt"), - include_bytes!("static/LICENSE-APACHE.txt"))?; + include_bytes!("static/LICENSE-APACHE.txt"))?; write(cx.dst.join("COPYRIGHT.txt"), - include_bytes!("static/COPYRIGHT.txt"))?; + include_bytes!("static/COPYRIGHT.txt"))?; fn collect(path: &Path, krate: &str, key: &str) -> io::Result> { @@ -925,7 +925,7 @@ impl<'a> SourceCollector<'a> { keywords: BASIC_KEYWORDS, }; layout::render(&mut w, &self.cx.layout, - &page, &(""), &Source(contents))?; + &page, &(""), &Source(contents))?; w.flush()?; self.cx.local_sources.insert(p, href); Ok(()) @@ -1290,8 +1290,8 @@ impl Context { let mut writer = BufWriter::new(w); if !cx.render_redirect_pages { layout::render(&mut writer, &cx.layout, &page, - &Sidebar{ cx: cx, item: it }, - &Item{ cx: cx, item: it })?; + &Sidebar{ cx: cx, item: it }, + &Item{ cx: cx, item: it })?; } else { let mut url = repeat("../").take(cx.current.len()) .collect::(); @@ -1515,22 +1515,22 @@ impl<'a> fmt::Display for Item<'a> { let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() }; for (i, component) in cur.iter().enumerate().take(amt) { write!(fmt, "{}::", - repeat("../").take(cur.len() - i - 1) - .collect::(), - component)?; + repeat("../").take(cur.len() - i - 1) + .collect::(), + component)?; } } write!(fmt, "{}", - shortty(self.item), self.item.name.as_ref().unwrap())?; + shortty(self.item), self.item.name.as_ref().unwrap())?; write!(fmt, "")?; // in-band write!(fmt, "")?; write!(fmt, - r##" - - [] - - "##)?; + r##" + + [] + + "##)?; // Write `src` tag // @@ -1541,8 +1541,8 @@ impl<'a> fmt::Display for Item<'a> { if self.cx.include_sources && !is_primitive { if let Some(l) = self.href() { write!(fmt, "[src]", - self.item.def_id.index.as_usize(), l, "goto source code")?; + href='{}' title='{}'>[src]", + self.item.def_id.index.as_usize(), l, "goto source code")?; } } @@ -1698,8 +1698,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, ItemType::AssociatedConst => ("associated-consts", "Associated Constants"), }; write!(w, "

\ - {name}

\n", - id = derive_id(short.to_owned()), name = name)?; + {name}\n
", + id = derive_id(short.to_owned()), name = name)?; } match myitem.inner { @@ -1707,13 +1707,13 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, match *src { Some(ref src) => { write!(w, "")?; @@ -1721,7 +1721,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, clean::ImportItem(ref import) => { write!(w, "", - VisSpace(myitem.visibility), *import)?; + VisSpace(myitem.visibility), *import)?; } _ => { @@ -1733,21 +1733,20 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, }; let doc_value = myitem.doc_value().unwrap_or(""); write!(w, " - - - - - ", - name = *myitem.name.as_ref().unwrap(), - stab_docs = stab_docs, - docs = shorter(Some(&Markdown(doc_value).to_string())), - class = shortty(myitem), - stab = myitem.stability_class(), - href = item_path(myitem), - title = full_path(cx, myitem))?; + + + + ", + name = *myitem.name.as_ref().unwrap(), + stab_docs = stab_docs, + docs = shorter(Some(&Markdown(doc_value).to_string())), + class = shortty(myitem), + stab = myitem.stability_class(), + href = item_path(myitem), + title = full_path(cx, myitem))?; } } } @@ -1824,7 +1823,7 @@ impl<'a> fmt::Display for Initializer<'a> { fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, c: &clean::Constant) -> fmt::Result { write!(w, "
{vis}const \
-                    {name}: {typ}{init}
", + {name}: {typ}{init}", vis = VisSpace(it.visibility), name = it.name.as_ref().unwrap(), typ = c.type_, @@ -1835,7 +1834,7 @@ fn item_constant(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, s: &clean::Static) -> fmt::Result { write!(w, "
{vis}static {mutability}\
-                    {name}: {typ}{init}
", + {name}: {typ}{init}", vis = VisSpace(it.visibility), mutability = MutableSpace(s.mutability), name = it.name.as_ref().unwrap(), @@ -1851,7 +1850,7 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, _ => hir::Constness::NotConst }; write!(w, "
{vis}{constness}{unsafety}{abi}fn \
-                    {name}{generics}{decl}{where_clause}
", + {name}{generics}{decl}{where_clause}", vis = VisSpace(it.visibility), constness = ConstnessSpace(vis_constness), unsafety = UnsafetySpace(f.unsafety), @@ -1880,12 +1879,12 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, // Output the trait definition write!(w, "
{}{}trait {}{}{}{} ",
-                  VisSpace(it.visibility),
-                  UnsafetySpace(t.unsafety),
-                  it.name.as_ref().unwrap(),
-                  t.generics,
-                  bounds,
-                  WhereClause(&t.generics))?;
+           VisSpace(it.visibility),
+           UnsafetySpace(t.unsafety),
+           it.name.as_ref().unwrap(),
+           t.generics,
+           bounds,
+           WhereClause(&t.generics))?;
 
     let types = t.items.iter().filter(|m| m.is_associated_type()).collect::>();
     let consts = t.items.iter().filter(|m| m.is_associated_const()).collect::>();
@@ -1937,8 +1936,8 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         let name = m.name.as_ref().unwrap();
         let id = derive_id(format!("{}.{}", shortty(m), name));
         write!(w, "

", - id = id, - stab = m.stability_class())?; + id = id, + stab = m.stability_class())?; render_assoc_item(w, m, AssocItemLink::Anchor)?; write!(w, "")?; render_stability_since(w, m, t)?; @@ -2009,17 +2008,17 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } write!(w, "")?; write!(w, r#""#, - root_path = vec![".."; cx.current.len()].join("/"), - path = if it.def_id.is_local() { - cx.current.join("/") - } else { - let path = &cache.external_paths[&it.def_id]; - path[..path.len() - 1].join("/") - }, - ty = shortty(it).to_static_str(), - name = *it.name.as_ref().unwrap())?; + src="{root_path}/implementors/{path}/{ty}.{name}.js"> + "#, + root_path = vec![".."; cx.current.len()].join("/"), + path = if it.def_id.is_local() { + cx.current.join("/") + } else { + let path = &cache.external_paths[&it.def_id]; + path[..path.len() - 1].join("/") + }, + ty = shortty(it).to_static_str(), + name = *it.name.as_ref().unwrap())?; Ok(()) } @@ -2054,7 +2053,7 @@ fn render_stability_since_raw<'a>(w: &mut fmt::Formatter, if let Some(v) = ver { if containing_ver != ver && v.len() > 0 { write!(w, "{}", - v)? + v)? } } Ok(()) @@ -2131,12 +2130,12 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "
")?;
     render_attributes(w, it)?;
     render_struct(w,
-                       it,
-                       Some(&s.generics),
-                       s.struct_type,
-                       &s.fields,
-                       "",
-                       true)?;
+                  it,
+                  Some(&s.generics),
+                  s.struct_type,
+                  &s.fields,
+                  "",
+                  true)?;
     write!(w, "
")?; render_stability_since_raw(w, it.stable_since(), None)?; @@ -2153,10 +2152,10 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "

Fields

\n
{}extern crate {} as {};", - VisSpace(myitem.visibility), - src, - name)? + VisSpace(myitem.visibility), + src, + name)? } None => { write!(w, "
{}extern crate {};", - VisSpace(myitem.visibility), name)? + VisSpace(myitem.visibility), name)? } } write!(w, "
{}{}
{name} - {stab_docs} {docs} -
{name} + {stab_docs} {docs} +
")?; for field in fields { write!(w, " - ")?; } @@ -2171,10 +2170,10 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, write!(w, "
")?;
     render_attributes(w, it)?;
     write!(w, "{}enum {}{}{}",
-                  VisSpace(it.visibility),
-                  it.name.as_ref().unwrap(),
-                  e.generics,
-                  WhereClause(&e.generics))?;
+           VisSpace(it.visibility),
+           it.name.as_ref().unwrap(),
+           e.generics,
+           WhereClause(&e.generics))?;
     if e.variants.is_empty() && !e.variants_stripped {
         write!(w, " {{}}")?;
     } else {
@@ -2198,12 +2197,12 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
                         }
                         clean::StructVariant(ref s) => {
                             render_struct(w,
-                                               v,
-                                               None,
-                                               s.struct_type,
-                                               &s.fields,
-                                               "    ",
-                                               false)?;
+                                          v,
+                                          None,
+                                          s.struct_type,
+                                          &s.fields,
+                                          "    ",
+                                          false)?;
                         }
                     }
                 }
@@ -2225,7 +2224,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
         write!(w, "

Variants

\n
\ - {name}", - stab = field.stability_class(), - name = field.name.as_ref().unwrap())?; + \ + {name}", + stab = field.stability_class(), + name = field.name.as_ref().unwrap())?; document(w, cx, field)?; write!(w, "
")?; for variant in &e.variants { write!(w, "
{name}", - name = variant.name.as_ref().unwrap())?; + name = variant.name.as_ref().unwrap())?; document(w, cx, variant)?; use clean::{Variant, StructVariant}; @@ -2237,13 +2236,13 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, } }); write!(w, "

Fields

\n - ")?; +
")?; for field in fields { write!(w, "")?; } @@ -2281,9 +2280,9 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, tab: &str, structhead: bool) -> fmt::Result { write!(w, "{}{}{}", - VisSpace(it.visibility), - if structhead {"struct "} else {""}, - it.name.as_ref().unwrap())?; + VisSpace(it.visibility), + if structhead {"struct "} else {""}, + it.name.as_ref().unwrap())?; if let Some(g) = g { write!(w, "{}{}", *g, WhereClause(g))? } @@ -2298,10 +2297,10 @@ fn render_struct(w: &mut fmt::Formatter, it: &clean::Item, } clean::StructFieldItem(clean::TypedStructField(ref ty)) => { write!(w, " {}{}: {},\n{}", - VisSpace(field.visibility), - field.name.as_ref().unwrap(), - *ty, - tab)?; + VisSpace(field.visibility), + field.name.as_ref().unwrap(), + *ty, + tab)?; } _ => unreachable!(), }; @@ -2369,13 +2368,13 @@ fn render_assoc_items(w: &mut fmt::Formatter, } AssocItemRender::DerefFor { trait_, type_ } => { write!(w, "

Methods from \ - {}<Target={}>

", trait_, type_)?; + {}<Target={}>", trait_, type_)?; false } }; for i in &non_trait { render_impl(w, cx, i, AssocItemLink::Anchor, render_header, - containing_item.stable_since())?; + containing_item.stable_since())?; } } if let AssocItemRender::DerefFor { .. } = what { @@ -2394,23 +2393,23 @@ fn render_assoc_items(w: &mut fmt::Formatter, render_deref_methods(w, cx, impl_, containing_item)?; } write!(w, "

Trait \ - Implementations

")?; + Implementations")?; let (derived, manual): (Vec<_>, Vec<&Impl>) = traits.iter().partition(|i| { i.impl_.derived }); for i in &manual { let did = i.trait_did().unwrap(); render_impl(w, cx, i, AssocItemLink::GotoSource(did), true, - containing_item.stable_since())?; + containing_item.stable_since())?; } if !derived.is_empty() { write!(w, "

\ - Derived Implementations \ -

")?; + Derived Implementations \ + ")?; for i in &derived { let did = i.trait_did().unwrap(); render_impl(w, cx, i, AssocItemLink::GotoSource(did), true, - containing_item.stable_since())?; + containing_item.stable_since())?; } } } @@ -2533,7 +2532,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi } doctraititem(w, cx, trait_item, AssocItemLink::GotoSource(did), render_static, - outer_version)?; + outer_version)?; } Ok(()) } @@ -2554,10 +2553,10 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi fn item_typedef(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, t: &clean::Typedef) -> fmt::Result { write!(w, "
type {}{}{where_clause} = {type_};
", - it.name.as_ref().unwrap(), - t.generics, - where_clause = WhereClause(&t.generics), - type_ = t.type_)?; + it.name.as_ref().unwrap(), + t.generics, + where_clause = WhereClause(&t.generics), + type_ = t.type_)?; document(w, cx, it) } @@ -2582,28 +2581,28 @@ impl<'a> fmt::Display for Sidebar<'a> { write!(fmt, "::")?; } write!(fmt, "{}", - &cx.root_path[..(cx.current.len() - i - 1) * 3], - *name)?; + &cx.root_path[..(cx.current.len() - i - 1) * 3], + *name)?; } write!(fmt, "

")?; // sidebar refers to the enclosing module, not this module let relpath = if it.is_mod() { "../" } else { "" }; write!(fmt, - "", - name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""), - ty = shortty(it).to_static_str(), - path = relpath)?; + "", + name = it.name.as_ref().map(|x| &x[..]).unwrap_or(""), + ty = shortty(it).to_static_str(), + path = relpath)?; if parentlen == 0 { // there is no sidebar-items.js beyond the crate root path // FIXME maybe dynamic crate loading can be merged here } else { write!(fmt, "", - path = relpath)?; + path = relpath)?; } Ok(()) @@ -2633,8 +2632,8 @@ impl<'a> fmt::Display for Source<'a> { fn item_macro(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item, t: &clean::Macro) -> fmt::Result { w.write_str(&highlight::highlight(&t.source, - Some("macro"), - None))?; + Some("macro"), + None))?; render_stability_since_raw(w, it.stable_since(), None)?; document(w, cx, it) } diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index b9d41471d41..305e6258baa 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -188,10 +188,10 @@ impl fmt::Display for Toc { // recursively format this table of contents (the // `{children}` is the key). write!(fmt, - "\n
  • {num} {name}{children}
  • ", - id = entry.id, - num = entry.sec_number, name = entry.name, - children = entry.children)? + "\n
  • {num} {name}{children}
  • ", + id = entry.id, + num = entry.sec_number, name = entry.name, + children = entry.children)? } write!(fmt, "") } diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 07c535bf730..d5d967114c4 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -49,7 +49,7 @@ pub fn setsockopt(sock: &Socket, opt: c_int, val: c_int, unsafe { let payload = &payload as *const T as *const c_void; cvt(c::setsockopt(*sock.as_inner(), opt, val, payload, - mem::size_of::() as c::socklen_t))?; + mem::size_of::() as c::socklen_t))?; Ok(()) } } @@ -60,8 +60,8 @@ pub fn getsockopt(sock: &Socket, opt: c_int, let mut slot: T = mem::zeroed(); let mut len = mem::size_of::() as c::socklen_t; cvt(c::getsockopt(*sock.as_inner(), opt, val, - &mut slot as *mut _ as *mut _, - &mut len))?; + &mut slot as *mut _ as *mut _, + &mut len))?; assert_eq!(len as usize, mem::size_of::()); Ok(slot) } @@ -147,7 +147,7 @@ pub fn lookup_host(host: &str) -> io::Result { let mut res = ptr::null_mut(); unsafe { cvt_gai(c::getaddrinfo(c_host.as_ptr(), ptr::null(), ptr::null(), - &mut res))?; + &mut res))?; Ok(LookupHost { original: res, cur: res }) } } @@ -308,7 +308,7 @@ impl TcpListener { // the OS to clean up the previous one. if !cfg!(windows) { setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, - 1 as c_int)?; + 1 as c_int)?; } // Bind our new socket @@ -334,7 +334,7 @@ impl TcpListener { let mut storage: c::sockaddr_storage = unsafe { mem::zeroed() }; let mut len = mem::size_of_val(&storage) as c::socklen_t; let sock = self.inner.accept(&mut storage as *mut _ as *mut _, - &mut len)?; + &mut len)?; let addr = sockaddr_to_addr(&storage, len as usize)?; Ok((TcpStream { inner: sock, }, addr)) } diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 51ac8cb82d1..a74f7ea13b4 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -642,11 +642,11 @@ impl UnixDatagram { let (addr, len) = sockaddr_un(path)?; let count = cvt(libc::sendto(*d.0.as_inner(), - buf.as_ptr() as *const _, - buf.len(), - 0, - &addr as *const _ as *const _, - len))?; + buf.as_ptr() as *const _, + buf.len(), + 0, + &addr as *const _ as *const _, + len))?; Ok(count as usize) } } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 0d77f344914..eed62c9ecfd 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -181,15 +181,15 @@ pub fn current_exe() -> io::Result { -1 as c_int]; let mut sz: libc::size_t = 0; cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - ptr::null_mut(), &mut sz, ptr::null_mut(), - 0 as libc::size_t))?; + ptr::null_mut(), &mut sz, ptr::null_mut(), + 0 as libc::size_t))?; if sz == 0 { return Err(io::Error::last_os_error()) } let mut v: Vec = Vec::with_capacity(sz as usize); cvt(libc::sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint, - v.as_mut_ptr() as *mut libc::c_void, &mut sz, - ptr::null_mut(), 0 as libc::size_t))?; + v.as_mut_ptr() as *mut libc::c_void, &mut sz, + ptr::null_mut(), 0 as libc::size_t))?; if sz == 0 { return Err(io::Error::last_os_error()); } @@ -218,10 +218,10 @@ pub fn current_exe() -> io::Result { let mib = mib.as_mut_ptr(); let mut argv_len = 0; cvt(libc::sysctl(mib, 4, 0 as *mut _, &mut argv_len, - 0 as *mut _, 0))?; + 0 as *mut _, 0))?; let mut argv = Vec::<*const libc::c_char>::with_capacity(argv_len as usize); cvt(libc::sysctl(mib, 4, argv.as_mut_ptr() as *mut _, - &mut argv_len, 0 as *mut _, 0))?; + &mut argv_len, 0 as *mut _, 0))?; argv.set_len(argv_len as usize); if argv[0].is_null() { return Err(io::Error::new(io::ErrorKind::Other, diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index b712091dc0b..6f56f3ade06 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -392,7 +392,7 @@ impl Command { let mut set: libc::sigset_t = mem::uninitialized(); t!(cvt(libc::sigemptyset(&mut set))); t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, - ptr::null_mut()))); + ptr::null_mut()))); let ret = libc::signal(libc::SIGPIPE, libc::SIG_DFL); if ret == libc::SIG_ERR { return io::Error::last_os_error() diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 46397e14718..529e42248f6 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -290,7 +290,7 @@ impl File { unsafe { let mut info: c::BY_HANDLE_FILE_INFORMATION = mem::zeroed(); cvt(c::GetFileInformationByHandle(self.handle.raw(), - &mut info))?; + &mut info))?; let mut attr = FileAttr { attributes: info.dwFileAttributes, creation_time: info.ftCreationTime, diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index f479b36ebbd..f4957297581 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -188,9 +188,9 @@ impl Command { let stderr = self.stderr.as_ref().unwrap_or(&default); let stdin = stdin.to_handle(c::STD_INPUT_HANDLE, &mut pipes.stdin)?; let stdout = stdout.to_handle(c::STD_OUTPUT_HANDLE, - &mut pipes.stdout)?; + &mut pipes.stdout)?; let stderr = stderr.to_handle(c::STD_ERROR_HANDLE, - &mut pipes.stderr)?; + &mut pipes.stderr)?; si.hStdInput = stdin.raw(); si.hStdOutput = stdout.raw(); si.hStdError = stderr.raw(); diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index a12016418c6..804ca6705ec 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -530,51 +530,51 @@ impl Encodable for FileMap { s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s))?; s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s))?; s.emit_struct_field("lines", 3, |s| { - let lines = self.lines.borrow(); - // store the length - s.emit_u32(lines.len() as u32)?; - - if !lines.is_empty() { - // In order to preserve some space, we exploit the fact that - // the lines list is sorted and individual lines are - // probably not that long. Because of that we can store lines - // as a difference list, using as little space as possible - // for the differences. - let max_line_length = if lines.len() == 1 { - 0 - } else { - lines.windows(2) - .map(|w| w[1] - w[0]) - .map(|bp| bp.to_usize()) - .max() - .unwrap() - }; - - let bytes_per_diff: u8 = match max_line_length { - 0 ... 0xFF => 1, - 0x100 ... 0xFFFF => 2, - _ => 4 - }; - - // Encode the number of bytes used per diff. - bytes_per_diff.encode(s)?; - - // Encode the first element. - lines[0].encode(s)?; - - let diff_iter = (&lines[..]).windows(2) - .map(|w| (w[1] - w[0])); - - match bytes_per_diff { - 1 => for diff in diff_iter { (diff.0 as u8).encode(s)? }, - 2 => for diff in diff_iter { (diff.0 as u16).encode(s)? }, - 4 => for diff in diff_iter { diff.0.encode(s)? }, - _ => unreachable!() - } + let lines = self.lines.borrow(); + // store the length + s.emit_u32(lines.len() as u32)?; + + if !lines.is_empty() { + // In order to preserve some space, we exploit the fact that + // the lines list is sorted and individual lines are + // probably not that long. Because of that we can store lines + // as a difference list, using as little space as possible + // for the differences. + let max_line_length = if lines.len() == 1 { + 0 + } else { + lines.windows(2) + .map(|w| w[1] - w[0]) + .map(|bp| bp.to_usize()) + .max() + .unwrap() + }; + + let bytes_per_diff: u8 = match max_line_length { + 0 ... 0xFF => 1, + 0x100 ... 0xFFFF => 2, + _ => 4 + }; + + // Encode the number of bytes used per diff. + bytes_per_diff.encode(s)?; + + // Encode the first element. + lines[0].encode(s)?; + + let diff_iter = (&lines[..]).windows(2) + .map(|w| (w[1] - w[0])); + + match bytes_per_diff { + 1 => for diff in diff_iter { (diff.0 as u8).encode(s)? }, + 2 => for diff in diff_iter { (diff.0 as u16).encode(s)? }, + 4 => for diff in diff_iter { diff.0.encode(s)? }, + _ => unreachable!() } + } - Ok(()) - })?; + Ok(()) + })?; s.emit_struct_field("multibyte_chars", 4, |s| { (*self.multibyte_chars.borrow()).encode(s) }) @@ -590,33 +590,33 @@ impl Decodable for FileMap { let start_pos: BytePos = d.read_struct_field("start_pos", 1, |d| Decodable::decode(d))?; let end_pos: BytePos = d.read_struct_field("end_pos", 2, |d| Decodable::decode(d))?; let lines: Vec = d.read_struct_field("lines", 3, |d| { - let num_lines: u32 = Decodable::decode(d)?; - let mut lines = Vec::with_capacity(num_lines as usize); + let num_lines: u32 = Decodable::decode(d)?; + let mut lines = Vec::with_capacity(num_lines as usize); + + if num_lines > 0 { + // Read the number of bytes used per diff. + let bytes_per_diff: u8 = Decodable::decode(d)?; + + // Read the first element. + let mut line_start: BytePos = Decodable::decode(d)?; + lines.push(line_start); + + for _ in 1..num_lines { + let diff = match bytes_per_diff { + 1 => d.read_u8()? as u32, + 2 => d.read_u16()? as u32, + 4 => d.read_u32()?, + _ => unreachable!() + }; - if num_lines > 0 { - // Read the number of bytes used per diff. - let bytes_per_diff: u8 = Decodable::decode(d)?; + line_start = line_start + BytePos(diff); - // Read the first element. - let mut line_start: BytePos = Decodable::decode(d)?; lines.push(line_start); - - for _ in 1..num_lines { - let diff = match bytes_per_diff { - 1 => d.read_u8()? as u32, - 2 => d.read_u16()? as u32, - 4 => d.read_u32()?, - _ => unreachable!() - }; - - line_start = line_start + BytePos(diff); - - lines.push(line_start); - } } + } - Ok(lines) - })?; + Ok(lines) + })?; let multibyte_chars: Vec = d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?; Ok(FileMap { diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index c846b1866a7..61fdc8453d8 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -208,8 +208,8 @@ impl EmitterWriter { if let Some(_) = self.registry.as_ref() .and_then(|registry| registry.find_description(code)) { print_diagnostic(&mut self.dst, &ss[..], Help, - &format!("run `rustc --explain {}` to see a \ - detailed explanation", code), None)?; + &format!("run `rustc --explain {}` to see a \ + detailed explanation", code), None)?; } } Ok(()) @@ -234,13 +234,13 @@ impl EmitterWriter { let mut lines = complete.lines(); for line in lines.by_ref().take(MAX_HIGHLIGHT_LINES) { write!(&mut self.dst, "{0}:{1:2$} {3}\n", - fm.name, "", max_digits, line)?; + fm.name, "", max_digits, line)?; } // if we elided some lines, add an ellipsis if let Some(_) = lines.next() { write!(&mut self.dst, "{0:1$} {0:2$} ...\n", - "", fm.name.len(), max_digits)?; + "", fm.name.len(), max_digits)?; } Ok(()) @@ -424,15 +424,15 @@ impl EmitterWriter { // Print offending code-line remaining_err_lines -= 1; write!(&mut self.dst, "{}:{:>width$} {}\n", - fm.name, - line.line_index + 1, - cur_line_str, - width=digits)?; + fm.name, + line.line_index + 1, + cur_line_str, + width=digits)?; if s.len() > skip { // Render the spans we assembled previously (if any). println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), - "{}", s)?; + "{}", s)?; } if !overflowed_buf.is_empty() { @@ -561,13 +561,13 @@ impl EmitterWriter { // Print offending code-lines write!(&mut self.dst, "{}:{:>width$} {}\n", fm.name, - line.line_index + 1, line_str, width=digits)?; + line.line_index + 1, line_str, width=digits)?; remaining_err_lines -= 1; if s.len() > skip { // Render the spans we assembled previously (if any) println_maybe_styled!(&mut self.dst, term::Attr::ForegroundColor(lvl.color()), - "{}", s)?; + "{}", s)?; } prev_line_index = line.line_index; } @@ -642,7 +642,7 @@ fn print_diagnostic(dst: &mut Destination, } print_maybe_styled!(dst, term::Attr::ForegroundColor(lvl.color()), - "{}: ", lvl.to_string())?; + "{}: ", lvl.to_string())?; print_maybe_styled!(dst, term::Attr::Bold, "{}", msg)?; if let Some(code) = code { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 827f3331753..a1adc99055f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -834,7 +834,7 @@ impl<'a> Parser<'a> { F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { let (result, returned) = self.parse_seq_to_before_gt_or_return(sep, - |p| Ok(Some(f(p)?)))?; + |p| Ok(Some(f(p)?)))?; assert!(!returned); return Ok(result); } @@ -1476,8 +1476,8 @@ impl<'a> Parser<'a> { self.bump(); let delim = self.expect_open_delim()?; let tts = self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), - |p| p.parse_token_tree())?; + SeqSep::none(), + |p| p.parse_token_tree())?; let hi = self.span.hi; TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) } else { @@ -2225,7 +2225,7 @@ impl<'a> Parser<'a> { &token::CloseDelim(token::Bracket), SeqSep::trailing_allowed(token::Comma), |p| Ok(p.parse_expr()?) - )?; + )?; let mut exprs = vec!(first_expr); exprs.extend(remaining_exprs); ex = ExprKind::Vec(exprs); @@ -2610,8 +2610,8 @@ impl<'a> Parser<'a> { let dot_pos = self.last_span.hi; e = self.parse_dot_suffix(special_idents::invalid, - mk_sp(dot_pos, dot_pos), - e, lo)?; + mk_sp(dot_pos, dot_pos), + e, lo)?; } } continue; @@ -3267,7 +3267,7 @@ impl<'a> Parser<'a> { let match_span = self.last_span; let lo = self.last_span.lo; let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, - None)?; + None)?; if let Err(mut e) = self.commit_expr_expecting(&discriminant, token::OpenDelim(token::Brace)) { if self.token == token::Token::Semi { @@ -3612,8 +3612,9 @@ impl<'a> Parser<'a> { let path = ident_to_path(ident_span, ident); self.bump(); let delim = self.expect_open_delim()?; - let tts = self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), |p| p.parse_token_tree())?; + let tts = self.parse_seq_to_end( + &token::CloseDelim(delim), + SeqSep::none(), |p| p.parse_token_tree())?; let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; pat = PatKind::Mac(codemap::Spanned {node: mac, span: mk_sp(lo, self.last_span.hi)}); @@ -3670,10 +3671,10 @@ impl<'a> Parser<'a> { pat = PatKind::TupleStruct(path, None); } else { let args = self.parse_enum_variant_seq( - &token::OpenDelim(token::Paren), - &token::CloseDelim(token::Paren), - SeqSep::trailing_allowed(token::Comma), - |p| p.parse_pat())?; + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), + SeqSep::trailing_allowed(token::Comma), + |p| p.parse_pat())?; pat = PatKind::TupleStruct(path, Some(args)); } } @@ -3963,7 +3964,7 @@ impl<'a> Parser<'a> { // FIXME: Bad copy of attrs let restrictions = self.restrictions | Restrictions::NO_NONINLINE_MOD; match self.with_res(restrictions, - |this| this.parse_item_(attrs.clone(), false, true))? { + |this| this.parse_item_(attrs.clone(), false, true))? { Some(i) => { let hi = i.span.hi; let decl = P(spanned(lo, hi, DeclKind::Item(i))); @@ -4941,8 +4942,8 @@ impl<'a> Parser<'a> { // eat a matched-delimiter token tree: let delim = self.expect_open_delim()?; let tts = self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), - |p| p.parse_token_tree())?; + SeqSep::none(), + |p| p.parse_token_tree())?; let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, @@ -5409,8 +5410,8 @@ impl<'a> Parser<'a> { id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec )> { let ModulePathSuccess { path, owns_directory } = self.submod_path(id, - outer_attrs, - id_sp)?; + outer_attrs, + id_sp)?; self.eval_src_mod_from_path(path, owns_directory, @@ -5993,8 +5994,8 @@ impl<'a> Parser<'a> { // eat a matched-delimiter token tree: let delim = self.expect_open_delim()?; let tts = self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), - |p| p.parse_token_tree())?; + SeqSep::none(), + |p| p.parse_token_tree())?; // single-variant-enum... : let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 9a3400025a8..5b06eb026d6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -388,7 +388,7 @@ pub fn fun_to_string(decl: &ast::FnDecl, to_string(|s| { s.head("")?; s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), - generics, opt_explicit_self, ast::Visibility::Inherited)?; + generics, opt_explicit_self, ast::Visibility::Inherited)?; s.end()?; // Close the head box s.end() // Close the outer box }) @@ -779,8 +779,8 @@ pub trait PrintState<'a> { word(self.writer(), &name)?; self.popen()?; self.commasep(Consistent, - &items[..], - |s, i| s.print_meta_item(&i))?; + &items[..], + |s, i| s.print_meta_item(&i))?; self.pclose()?; } } @@ -915,7 +915,7 @@ impl<'a> State<'a> { if i < len { word(&mut self.s, ",")?; self.maybe_print_trailing_comment(get_span(elt), - Some(get_span(&elts[i]).hi))?; + Some(get_span(&elts[i]).hi))?; self.space_if_not_bol()?; } } @@ -979,7 +979,7 @@ impl<'a> State<'a> { ast::TyKind::Tup(ref elts) => { self.popen()?; self.commasep(Inconsistent, &elts[..], - |s, ty| s.print_type(&ty))?; + |s, ty| s.print_type(&ty))?; if elts.len() == 1 { word(&mut self.s, ",")?; } @@ -1000,11 +1000,11 @@ impl<'a> State<'a> { }, }; self.print_ty_fn(f.abi, - f.unsafety, - &f.decl, - None, - &generics, - None)?; + f.unsafety, + &f.decl, + None, + &generics, + None)?; } ast::TyKind::Path(None, ref path) => { self.print_path(path, false, 0)?; @@ -1050,16 +1050,15 @@ impl<'a> State<'a> { ast::ForeignItemKind::Fn(ref decl, ref generics) => { self.head("")?; self.print_fn(decl, ast::Unsafety::Normal, - ast::Constness::NotConst, - Abi::Rust, Some(item.ident), - generics, None, item.vis)?; + ast::Constness::NotConst, + Abi::Rust, Some(item.ident), + generics, None, item.vis)?; self.end()?; // end head-ibox word(&mut self.s, ";")?; self.end() // end the outer fn box } ast::ForeignItemKind::Static(ref t, m) => { - self.head(&visibility_qualified(item.vis, - "static"))?; + self.head(&visibility_qualified(item.vis, "static"))?; if m { self.word_space("mut")?; } @@ -1119,8 +1118,7 @@ impl<'a> State<'a> { self.ann.pre(self, NodeItem(item))?; match item.node { ast::ItemKind::ExternCrate(ref optional_path) => { - self.head(&visibility_qualified(item.vis, - "extern crate"))?; + self.head(&visibility_qualified(item.vis, "extern crate"))?; if let Some(p) = *optional_path { let val = p.as_str(); if val.contains("-") { @@ -1138,16 +1136,14 @@ impl<'a> State<'a> { self.end()?; // end outer head-block } ast::ItemKind::Use(ref vp) => { - self.head(&visibility_qualified(item.vis, - "use"))?; + self.head(&visibility_qualified(item.vis, "use"))?; self.print_view_path(&vp)?; word(&mut self.s, ";")?; self.end()?; // end inner head-block self.end()?; // end outer head-block } ast::ItemKind::Static(ref ty, m, ref expr) => { - self.head(&visibility_qualified(item.vis, - "static"))?; + self.head(&visibility_qualified(item.vis, "static"))?; if m == ast::Mutability::Mutable { self.word_space("mut")?; } @@ -1163,8 +1159,7 @@ impl<'a> State<'a> { self.end()?; // end the outer cbox } ast::ItemKind::Const(ref ty, ref expr) => { - self.head(&visibility_qualified(item.vis, - "const"))?; + self.head(&visibility_qualified(item.vis, "const"))?; self.print_ident(item.ident)?; self.word_space(":")?; self.print_type(&ty)?; @@ -1192,8 +1187,7 @@ impl<'a> State<'a> { self.print_block_with_attrs(&body, &item.attrs)?; } ast::ItemKind::Mod(ref _mod) => { - self.head(&visibility_qualified(item.vis, - "mod"))?; + self.head(&visibility_qualified(item.vis, "mod"))?; self.print_ident(item.ident)?; self.nbsp()?; self.bopen()?; @@ -1555,8 +1549,8 @@ impl<'a> State<'a> { match ti.node { ast::TraitItemKind::Const(ref ty, ref default) => { self.print_associated_const(ti.ident, &ty, - default.as_ref().map(|expr| &**expr), - ast::Visibility::Inherited)?; + default.as_ref().map(|expr| &**expr), + ast::Visibility::Inherited)?; } ast::TraitItemKind::Method(ref sig, ref body) => { if body.is_some() { @@ -1572,7 +1566,7 @@ impl<'a> State<'a> { } ast::TraitItemKind::Type(ref bounds, ref default) => { self.print_associated_type(ti.ident, Some(bounds), - default.as_ref().map(|ty| &**ty))?; + default.as_ref().map(|ty| &**ty))?; } } self.ann.post(self, NodeSubItem(ti.id)) @@ -1923,7 +1917,7 @@ impl<'a> State<'a> { if !tys.is_empty() { word(&mut self.s, "::<")?; self.commasep(Inconsistent, tys, - |s, ty| s.print_type(&ty))?; + |s, ty| s.print_type(&ty))?; word(&mut self.s, ">")?; } self.print_call_post(base_args) @@ -2223,7 +2217,7 @@ impl<'a> State<'a> { match out.constraint.slice_shift_char() { Some(('=', operand)) if out.is_rw => { s.print_string(&format!("+{}", operand), - ast::StrStyle::Cooked)? + ast::StrStyle::Cooked)? } _ => s.print_string(&out.constraint, ast::StrStyle::Cooked)? } @@ -2267,10 +2261,10 @@ impl<'a> State<'a> { space(&mut self.s)?; self.word_space(":")?; self.commasep(Inconsistent, &options, - |s, &co| { - s.print_string(co, ast::StrStyle::Cooked)?; - Ok(()) - })?; + |s, &co| { + s.print_string(co, ast::StrStyle::Cooked)?; + Ok(()) + })?; } self.pclose()?; @@ -3037,13 +3031,13 @@ impl<'a> State<'a> { }, }; self.print_fn(decl, - unsafety, - ast::Constness::NotConst, - abi, - name, - &generics, - opt_explicit_self, - ast::Visibility::Inherited)?; + unsafety, + ast::Constness::NotConst, + abi, + name, + &generics, + opt_explicit_self, + ast::Visibility::Inherited)?; self.end() } diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index fd7441d85ce..2c734c8e3e4 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -96,8 +96,8 @@ impl Formatter for HTMLFormatter { // Error title (with self-link). write!(output, - "

    {0}

    \n", - err_code)?; + "

    {0}

    \n", + err_code)?; // Description rendered as markdown. match info.description { diff --git a/src/tools/rustbook/build.rs b/src/tools/rustbook/build.rs index f9dc8ffa4c4..6014439fafc 100644 --- a/src/tools/rustbook/build.rs +++ b/src/tools/rustbook/build.rs @@ -56,10 +56,10 @@ fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Resul }; writeln!(out, "
  • {} {}", - class_string, - current_page.path_to_root.join(&item.path).with_extension("html").display(), - section, - item.title)?; + class_string, + current_page.path_to_root.join(&item.path).with_extension("html").display(), + section, + item.title)?; if !item.children.is_empty() { writeln!(out, "
      ")?; let _ = walk_items(&item.children[..], section, current_page, out); -- cgit 1.4.1-3-g733a5
  • \ - {f}", - v = variant.name.as_ref().unwrap(), - f = field.name.as_ref().unwrap())?; + id='variant.{v}.field.{f}'>\ + {f}", + v = variant.name.as_ref().unwrap(), + f = field.name.as_ref().unwrap())?; document(w, cx, field)?; write!(w, "