diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2016-03-22 22:01:37 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2016-03-22 22:01:37 -0500 |
| commit | 0f02309e4b0ea05ee905205278fb6d131341c41f (patch) | |
| tree | a259129eeb84705de15b51587ddebd0f82735075 /src/libsyntax | |
| parent | 0dcc413e42f15f4fc51a0ca88a99cc89454ec43d (diff) | |
| download | rust-0f02309e4b0ea05ee905205278fb6d131341c41f.tar.gz rust-0f02309e4b0ea05ee905205278fb6d131341c41f.zip | |
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
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/codemap.rs | 75 | ||||
| -rw-r--r-- | src/libsyntax/diagnostics/metadata.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/errors/emitter.rs | 76 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_parser.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 978 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 1720 |
10 files changed, 1441 insertions, 1452 deletions
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: Decoder>(d: &mut D) -> Result<Name, D::Error> { - 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: Decoder>(d: &mut D) -> Result<Ident, D::Error> { - 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: Decoder>(d: &mut D) -> Result<BytePos, D::Error> { - Ok(BytePos(try!{ d.read_u32() })) + Ok(BytePos(d.read_u32()?)) } } @@ -203,9 +203,9 @@ pub struct Spanned<T> { impl Encodable for Span { fn encode<S: Encoder>(&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: Decoder>(d: &mut D) -> Result<Span, D::Error> { 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<S: Encoder>(&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: Decoder>(d: &mut D) -> Result<FileMap, D::Error> { 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<BytePos> = 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<BytePos> = 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<MultiByteChar> = try! { - d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d)) - }; + })?; + let multibyte_chars: Vec<MultiByteChar> = 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<String> { 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<Rc<FileMap>> { - 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<NamedMatch>]) 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<T>>, { - 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<T>> 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<T>> 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<Ty>> { 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<P<ast::Expr>>> { 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<ast::Lifetime>> { 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<Expr>> { 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<ThinAttributes>) -> PResult<'a, P<Expr>> { - 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<Expr>> { 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<TokenTree>> { 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<ThinAttributes>) -> PResult<'a, P<Expr>> { - 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<Expr>> { 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<P<Expr>> = 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<Expr>> { 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<Expr>> { - 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<Expr>> { // Parse: `for <src_pat> in <src_expr> <src_loop_block>` - 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<ast::Ident>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { - 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<ast::Ident>, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { - 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<Expr>> { 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<Arm> = 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<P<Expr>>> { 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<P<Pat>>> { 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<P<Pat>>> { 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<Local>> { 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<Decl>> { 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<Stmt>> { 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<P<Ty>>, Vec<TypeBinding>)> { 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<Option<Arg>> = - 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<FnDecl>> { - 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<String,i32> 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<ast::LifetimeDef>> { 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<String,i32> 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<T> where T: Copy;` style decl. VariantData::Unit(ast::DUMMY_NODE_ID) } else { // If we see: `struct Foo<T> 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<T>;` } 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<StructField>> { // This is the case where we find `struct Foo<T>(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<Attribute> ) -> 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<Mutability>) -> 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 <foo> { ... }` or `mod <foo>;` 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<ast::Attribute> )> { - 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<Attribute>) -> 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<Attribute>) -> 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<Attribute>) -> PResult<'a, P<Item>> { - 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<Attribute>) -> PResult<'a, P<Item>> { - 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<ForeignItem>> { - 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<P<Item>>> { - 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<InternedString> for &'a str { impl Decodable for InternedString { fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> { - 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<Vec<comments::Literal>>; 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<T, F>(&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<ast::Lifetime>) -> 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<ast::Expr>]) -> 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<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.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<P<ast::Expr>>, 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<ast::Expr>], 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<ast::Expr>]) -> 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<ast::Ty>], args: &[P<ast::Expr>]) -> 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<bool> { - 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<Abi>) -> 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") |
