From 0f02309e4b0ea05ee905205278fb6d131341c41f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 22 Mar 2016 22:01:37 -0500 Subject: try! -> ? Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry --- src/libsyntax/parse/attr.rs | 16 +- src/libsyntax/parse/parser.rs | 978 +++++++++++++++++++++--------------------- src/libsyntax/parse/token.rs | 2 +- 3 files changed, 498 insertions(+), 498 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 0950d6082e7..b8e320e36e9 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -25,7 +25,7 @@ impl<'a> Parser<'a> { debug!("parse_outer_attributes: self.token={:?}", self.token); match self.token { token::Pound => { - attrs.push(try!(self.parse_attribute(false))); + attrs.push(self.parse_attribute(false)?); } token::DocComment(s) => { let attr = ::attr::mk_sugared_doc_attr( @@ -79,10 +79,10 @@ impl<'a> Parser<'a> { ast::AttrStyle::Outer }; - try!(self.expect(&token::OpenDelim(token::Bracket))); - let meta_item = try!(self.parse_meta_item()); + self.expect(&token::OpenDelim(token::Bracket))?; + let meta_item = self.parse_meta_item()?; let hi = self.span.hi; - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; (mk_sp(lo, hi), meta_item, style) } @@ -126,7 +126,7 @@ impl<'a> Parser<'a> { break; } - let attr = try!(self.parse_attribute(true)); + let attr = self.parse_attribute(true)?; assert!(attr.node.style == ast::AttrStyle::Inner); attrs.push(attr); } @@ -166,12 +166,12 @@ impl<'a> Parser<'a> { } let lo = self.span.lo; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let name = self.id_to_interned_str(ident); match self.token { token::Eq => { self.bump(); - let lit = try!(self.parse_lit()); + let lit = self.parse_lit()?; // FIXME #623 Non-string meta items are not serialized correctly; // just forbid them for now match lit.node { @@ -185,7 +185,7 @@ impl<'a> Parser<'a> { Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(name, lit)))) } token::OpenDelim(token::Paren) => { - let inner_items = try!(self.parse_meta_seq()); + let inner_items = self.parse_meta_seq()?; let hi = self.span.hi; Ok(P(spanned(lo, hi, ast::MetaItemKind::List(name, inner_items)))) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6839f11cd70..827f3331753 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -590,11 +590,11 @@ impl<'a> Parser<'a> { pub fn parse_path_list_item(&mut self) -> PResult<'a, ast::PathListItem> { let lo = self.span.lo; let node = if self.eat_keyword(keywords::SelfValue) { - let rename = try!(self.parse_rename()); + let rename = self.parse_rename()?; ast::PathListItemKind::Mod { id: ast::DUMMY_NODE_ID, rename: rename } } else { - let ident = try!(self.parse_ident()); - let rename = try!(self.parse_rename()); + let ident = self.parse_ident()?; + let rename = self.parse_rename()?; ast::PathListItemKind::Ident { name: ident, rename: rename, id: ast::DUMMY_NODE_ID } }; let hi = self.last_span.hi; @@ -811,13 +811,13 @@ impl<'a> Parser<'a> { } if i % 2 == 0 { - match try!(f(self)) { + match f(self)? { Some(result) => v.push(result), None => return Ok((P::from_vec(v), true)) } } else { if let Some(t) = sep.as_ref() { - try!(self.expect(t)); + self.expect(t)?; } } @@ -833,8 +833,8 @@ impl<'a> Parser<'a> { -> PResult<'a, P<[T]>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let (result, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, - |p| Ok(Some(try!(f(p)))))); + let (result, returned) = self.parse_seq_to_before_gt_or_return(sep, + |p| Ok(Some(f(p)?)))?; assert!(!returned); return Ok(result); } @@ -845,8 +845,8 @@ impl<'a> Parser<'a> { -> PResult<'a, P<[T]>> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let v = try!(self.parse_seq_to_before_gt(sep, f)); - try!(self.expect_gt()); + let v = self.parse_seq_to_before_gt(sep, f)?; + self.expect_gt()?; return Ok(v); } @@ -856,9 +856,9 @@ impl<'a> Parser<'a> { -> PResult<'a, (P<[T]>, bool)> where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option>, { - let (v, returned) = try!(self.parse_seq_to_before_gt_or_return(sep, f)); + let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f)?; if !returned { - try!(self.expect_gt()); + self.expect_gt()?; } return Ok((v, returned)); } @@ -953,7 +953,7 @@ impl<'a> Parser<'a> { -> PResult<'a, Vec> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - try!(self.expect(bra)); + self.expect(bra)?; let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); Ok(result) @@ -969,7 +969,7 @@ impl<'a> Parser<'a> { -> PResult<'a, Vec> where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { - let result = try!(self.parse_unspanned_seq(bra, ket, sep, f)); + let result = self.parse_unspanned_seq(bra, ket, sep, f)?; if result.is_empty() { let last_span = self.last_span; self.span_err(last_span, @@ -989,7 +989,7 @@ impl<'a> Parser<'a> { F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, { let lo = self.span.lo; - try!(self.expect(bra)); + self.expect(bra)?; let result = self.parse_seq_to_before_end(ket, sep, f); let hi = self.span.hi; self.bump(); @@ -1142,19 +1142,19 @@ impl<'a> Parser<'a> { // parse <'lt> let lo = self.span.lo; - let lifetime_defs = try!(self.parse_late_bound_lifetime_defs()); + let lifetime_defs = self.parse_late_bound_lifetime_defs()?; // examine next token to decide to do if self.token_is_bare_fn_keyword() { self.parse_ty_bare_fn(lifetime_defs) } else { let hi = self.span.hi; - let trait_ref = try!(self.parse_trait_ref()); + let trait_ref = self.parse_trait_ref()?; let poly_trait_ref = ast::PolyTraitRef { bound_lifetimes: lifetime_defs, trait_ref: trait_ref, span: mk_sp(lo, hi)}; let other_bounds = if self.eat(&token::BinOp(token::Plus)) { - try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)) + self.parse_ty_param_bounds(BoundParsingMode::Bare)? } else { P::empty() }; @@ -1167,7 +1167,7 @@ impl<'a> Parser<'a> { } pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> { - Ok(TyKind::Path(None, try!(self.parse_path(LifetimeAndTypesWithoutColons)))) + Ok(TyKind::Path(None, self.parse_path(LifetimeAndTypesWithoutColons)?)) } /// parse a TyKind::BareFn type: @@ -1185,16 +1185,16 @@ impl<'a> Parser<'a> { Function Style */ - let unsafety = try!(self.parse_unsafety()); + let unsafety = self.parse_unsafety()?; let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; - try!(self.expect_keyword(keywords::Fn)); - let (inputs, variadic) = try!(self.parse_fn_args(false, true)); - let ret_ty = try!(self.parse_ret_ty()); + self.expect_keyword(keywords::Fn)?; + let (inputs, variadic) = self.parse_fn_args(false, true)?; + let ret_ty = self.parse_ret_ty()?; let decl = P(FnDecl { inputs: inputs, output: ret_ty, @@ -1254,25 +1254,25 @@ impl<'a> Parser<'a> { SeqSep::none(), |p| -> PResult<'a, TraitItem> { maybe_whole!(no_clone_from_p p, NtTraitItem); - let mut attrs = try!(p.parse_outer_attributes()); + let mut attrs = p.parse_outer_attributes()?; let lo = p.span.lo; let (name, node) = if p.eat_keyword(keywords::Type) { - let TyParam {ident, bounds, default, ..} = try!(p.parse_ty_param()); - try!(p.expect(&token::Semi)); + let TyParam {ident, bounds, default, ..} = p.parse_ty_param()?; + p.expect(&token::Semi)?; (ident, TraitItemKind::Type(bounds, default)) } else if p.is_const_item() { - try!(p.expect_keyword(keywords::Const)); - let ident = try!(p.parse_ident()); - try!(p.expect(&token::Colon)); - let ty = try!(p.parse_ty_sum()); + p.expect_keyword(keywords::Const)?; + let ident = p.parse_ident()?; + p.expect(&token::Colon)?; + let ty = p.parse_ty_sum()?; let default = if p.check(&token::Eq) { p.bump(); - let expr = try!(p.parse_expr()); - try!(p.commit_expr_expecting(&expr, token::Semi)); + let expr = p.parse_expr()?; + p.commit_expr_expecting(&expr, token::Semi)?; Some(expr) } else { - try!(p.expect(&token::Semi)); + p.expect(&token::Semi)?; None }; (ident, TraitItemKind::Const(ty, default)) @@ -1288,7 +1288,7 @@ impl<'a> Parser<'a> { } if p.token == token::OpenDelim(token::DelimToken::Brace) { - try!(p.parse_token_tree()); + p.parse_token_tree()?; break; } } @@ -1297,17 +1297,17 @@ impl<'a> Parser<'a> { } }; - let ident = try!(p.parse_ident()); - let mut generics = try!(p.parse_generics()); + let ident = p.parse_ident()?; + let mut generics = p.parse_generics()?; - let (explicit_self, d) = try!(p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{ + let (explicit_self, d) = p.parse_fn_decl_with_self(|p: &mut Parser<'a>|{ // This is somewhat dubious; We don't want to allow // argument names to be left off if there is a // definition... p.parse_arg_general(false) - })); + })?; - generics.where_clause = try!(p.parse_where_clause()); + generics.where_clause = p.parse_where_clause()?; let sig = ast::MethodSig { unsafety: unsafety, constness: constness, @@ -1326,7 +1326,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Brace) => { debug!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = - try!(p.parse_inner_attrs_and_block()); + p.parse_inner_attrs_and_block()?; attrs.extend(inner_attrs.iter().cloned()); Some(body) } @@ -1352,8 +1352,8 @@ impl<'a> Parser<'a> { /// Parse a possibly mutable type pub fn parse_mt(&mut self) -> PResult<'a, MutTy> { - let mutbl = try!(self.parse_mutability()); - let t = try!(self.parse_ty()); + let mutbl = self.parse_mutability()?; + let t = self.parse_ty()?; Ok(MutTy { ty: t, mutbl: mutbl }) } @@ -1363,7 +1363,7 @@ impl<'a> Parser<'a> { if self.eat(&token::Not) { Ok(FunctionRetTy::None(self.last_span)) } else { - Ok(FunctionRetTy::Ty(try!(self.parse_ty()))) + Ok(FunctionRetTy::Ty(self.parse_ty()?)) } } else { let pos = self.span.lo; @@ -1374,13 +1374,13 @@ impl<'a> Parser<'a> { /// Parse a type in a context where `T1+T2` is allowed. pub fn parse_ty_sum(&mut self) -> PResult<'a, P> { let lo = self.span.lo; - let lhs = try!(self.parse_ty()); + let lhs = self.parse_ty()?; if !self.eat(&token::BinOp(token::Plus)) { return Ok(lhs); } - let bounds = try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; // In type grammar, `+` is treated like a binary operator, // and hence both L and R side are required. @@ -1411,7 +1411,7 @@ impl<'a> Parser<'a> { let mut ts = vec![]; let mut last_comma = false; while self.token != token::CloseDelim(token::Paren) { - ts.push(try!(self.parse_ty_sum())); + ts.push(self.parse_ty_sum()?); if self.check(&token::Comma) { last_comma = true; self.bump(); @@ -1421,7 +1421,7 @@ impl<'a> Parser<'a> { } } - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; if ts.len() == 1 && !last_comma { TyKind::Paren(ts.into_iter().nth(0).unwrap()) } else { @@ -1430,54 +1430,54 @@ impl<'a> Parser<'a> { } else if self.check(&token::BinOp(token::Star)) { // STAR POINTER (bare pointer?) self.bump(); - TyKind::Ptr(try!(self.parse_ptr())) + TyKind::Ptr(self.parse_ptr()?) } else if self.check(&token::OpenDelim(token::Bracket)) { // VECTOR - try!(self.expect(&token::OpenDelim(token::Bracket))); - let t = try!(self.parse_ty_sum()); + self.expect(&token::OpenDelim(token::Bracket))?; + let t = self.parse_ty_sum()?; // Parse the `; e` in `[ i32; e ]` // where `e` is a const expression - let t = match try!(self.maybe_parse_fixed_length_of_vec()) { + let t = match self.maybe_parse_fixed_length_of_vec()? { None => TyKind::Vec(t), Some(suffix) => TyKind::FixedLengthVec(t, suffix) }; - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; t } else if self.check(&token::BinOp(token::And)) || self.token == token::AndAnd { // BORROWED POINTER - try!(self.expect_and()); - try!(self.parse_borrowed_pointee()) + self.expect_and()?; + self.parse_borrowed_pointee()? } else if self.check_keyword(keywords::For) { - try!(self.parse_for_in_type()) + self.parse_for_in_type()? } else if self.token_is_bare_fn_keyword() { // BARE FUNCTION - try!(self.parse_ty_bare_fn(Vec::new())) + self.parse_ty_bare_fn(Vec::new())? } else if self.eat_keyword_noexpect(keywords::Typeof) { // TYPEOF // In order to not be ambiguous, the type must be surrounded by parens. - try!(self.expect(&token::OpenDelim(token::Paren))); - let e = try!(self.parse_expr()); - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::OpenDelim(token::Paren))?; + let e = self.parse_expr()?; + self.expect(&token::CloseDelim(token::Paren))?; TyKind::Typeof(e) } else if self.eat_lt() { let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; TyKind::Path(Some(qself), path) } else if self.check(&token::ModSep) || self.token.is_ident() || self.token.is_path() { - let path = try!(self.parse_path(LifetimeAndTypesWithoutColons)); + let path = self.parse_path(LifetimeAndTypesWithoutColons)?; if self.check(&token::Not) { // MACRO INVOCATION self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let hi = self.span.hi; TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) } else { @@ -1499,9 +1499,9 @@ impl<'a> Parser<'a> { pub fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: - let opt_lifetime = try!(self.parse_opt_lifetime()); + let opt_lifetime = self.parse_opt_lifetime()?; - let mt = try!(self.parse_mt()); + let mt = self.parse_mt()?; return Ok(TyKind::Rptr(opt_lifetime, mt)); } @@ -1518,7 +1518,7 @@ impl<'a> Parser<'a> { known as `*const T`"); Mutability::Immutable }; - let t = try!(self.parse_ty()); + let t = self.parse_ty()?; Ok(MutTy { ty: t, mutbl: mutbl }) } @@ -1549,9 +1549,9 @@ impl<'a> Parser<'a> { let pat = if require_name || self.is_named_argument() { debug!("parse_arg_general parse_pat (require_name:{})", require_name); - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; - try!(self.expect(&token::Colon)); + self.expect(&token::Colon)?; pat } else { debug!("parse_arg_general ident_to_pat"); @@ -1560,7 +1560,7 @@ impl<'a> Parser<'a> { special_idents::invalid) }; - let t = try!(self.parse_ty_sum()); + let t = self.parse_ty_sum()?; Ok(Arg { ty: t, @@ -1576,9 +1576,9 @@ impl<'a> Parser<'a> { /// Parse an argument in a lambda header e.g. |arg, arg| pub fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> { - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; let t = if self.eat(&token::Colon) { - try!(self.parse_ty_sum()) + self.parse_ty_sum()? } else { P(Ty { id: ast::DUMMY_NODE_ID, @@ -1596,7 +1596,7 @@ impl<'a> Parser<'a> { pub fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option>> { if self.check(&token::Semi) { self.bump(); - Ok(Some(try!(self.parse_expr()))) + Ok(Some(self.parse_expr()?)) } else { Ok(None) } @@ -1670,7 +1670,7 @@ impl<'a> Parser<'a> { LitKind::Bool(false) } else { let token = self.bump_and_get(); - let lit = try!(self.lit_from_token(&token)); + let lit = self.lit_from_token(&token)?; lit }; Ok(codemap::Spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }) @@ -1681,7 +1681,7 @@ impl<'a> Parser<'a> { let minus_lo = self.span.lo; let minus_present = self.eat(&token::BinOp(token::Minus)); let lo = self.span.lo; - let literal = P(try!(self.parse_lit())); + let literal = P(self.parse_lit()?); let hi = self.last_span.hi; let expr = self.mk_expr(lo, hi, ExprKind::Lit(literal), None); @@ -1712,9 +1712,9 @@ impl<'a> Parser<'a> { pub fn parse_qualified_path(&mut self, mode: PathParsingMode) -> PResult<'a, (QSelf, ast::Path)> { let span = self.last_span; - let self_type = try!(self.parse_ty_sum()); + let self_type = self.parse_ty_sum()?; let mut path = if self.eat_keyword(keywords::As) { - try!(self.parse_path(LifetimeAndTypesWithoutColons)) + self.parse_path(LifetimeAndTypesWithoutColons)? } else { ast::Path { span: span, @@ -1728,18 +1728,18 @@ impl<'a> Parser<'a> { position: path.segments.len() }; - try!(self.expect(&token::Gt)); - try!(self.expect(&token::ModSep)); + self.expect(&token::Gt)?; + self.expect(&token::ModSep)?; let segments = match mode { LifetimeAndTypesWithoutColons => { - try!(self.parse_path_segments_without_colons()) + self.parse_path_segments_without_colons()? } LifetimeAndTypesWithColons => { - try!(self.parse_path_segments_with_colons()) + self.parse_path_segments_with_colons()? } NoTypesAllowed => { - try!(self.parse_path_segments_without_types()) + self.parse_path_segments_without_types()? } }; path.segments.extend(segments); @@ -1771,13 +1771,13 @@ impl<'a> Parser<'a> { // A bound set is a set of type parameter bounds. let segments = match mode { LifetimeAndTypesWithoutColons => { - try!(self.parse_path_segments_without_colons()) + self.parse_path_segments_without_colons()? } LifetimeAndTypesWithColons => { - try!(self.parse_path_segments_with_colons()) + self.parse_path_segments_with_colons()? } NoTypesAllowed => { - try!(self.parse_path_segments_without_types()) + self.parse_path_segments_without_types()? } }; @@ -1800,11 +1800,11 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // Parse types, optionally. let parameters = if self.eat_lt() { - let (lifetimes, types, bindings) = try!(self.parse_generic_values_after_lt()); + let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?; ast::PathParameters::AngleBracketed(ast::AngleBracketedParameterData { lifetimes: lifetimes, @@ -1814,13 +1814,13 @@ impl<'a> Parser<'a> { } else if self.eat(&token::OpenDelim(token::Paren)) { let lo = self.last_span.lo; - let inputs = try!(self.parse_seq_to_end( + let inputs = self.parse_seq_to_end( &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_ty_sum())); + |p| p.parse_ty_sum())?; let output_ty = if self.eat(&token::RArrow) { - Some(try!(self.parse_ty())) + Some(self.parse_ty()?) } else { None }; @@ -1853,7 +1853,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // If we do not see a `::`, stop. if !self.eat(&token::ModSep) { @@ -1867,7 +1867,7 @@ impl<'a> Parser<'a> { // Check for a type segment. if self.eat_lt() { // Consumed `a::b::<`, go look for types - let (lifetimes, types, bindings) = try!(self.parse_generic_values_after_lt()); + let (lifetimes, types, bindings) = self.parse_generic_values_after_lt()?; let parameters = ast::AngleBracketedParameterData { lifetimes: lifetimes, types: P::from_vec(types), @@ -1899,7 +1899,7 @@ impl<'a> Parser<'a> { let mut segments = Vec::new(); loop { // First, parse an identifier. - let identifier = try!(self.parse_ident_or_self_type()); + let identifier = self.parse_ident_or_self_type()?; // Assemble and push the result. segments.push(ast::PathSegment { @@ -1918,7 +1918,7 @@ impl<'a> Parser<'a> { pub fn parse_opt_lifetime(&mut self) -> PResult<'a, Option> { match self.token { token::Lifetime(..) => { - Ok(Some(try!(self.parse_lifetime()))) + Ok(Some(self.parse_lifetime()?)) } _ => { Ok(None) @@ -1953,10 +1953,10 @@ impl<'a> Parser<'a> { loop { match self.token { token::Lifetime(_) => { - let lifetime = try!(self.parse_lifetime()); + let lifetime = self.parse_lifetime()?; let bounds = if self.eat(&token::Colon) { - try!(self.parse_lifetimes(token::BinOp(token::Plus))) + self.parse_lifetimes(token::BinOp(token::Plus))? } else { Vec::new() }; @@ -1996,7 +1996,7 @@ impl<'a> Parser<'a> { loop { match self.token { token::Lifetime(_) => { - res.push(try!(self.parse_lifetime())); + res.push(self.parse_lifetime()?); } _ => { return Ok(res); @@ -2023,10 +2023,10 @@ impl<'a> Parser<'a> { /// Parse ident COLON expr pub fn parse_field(&mut self) -> PResult<'a, Field> { let lo = self.span.lo; - let i = try!(self.parse_ident()); + let i = self.parse_ident()?; let hi = self.last_span.hi; - try!(self.expect(&token::Colon)); - let e = try!(self.parse_expr()); + self.expect(&token::Colon)?; + let e = self.parse_expr()?; Ok(ast::Field { ident: spanned(lo, hi, i), span: mk_sp(lo, e.span.hi), @@ -2152,7 +2152,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Paren) => { self.bump(); - let attrs = try!(self.parse_inner_attributes()) + let attrs = self.parse_inner_attributes()? .into_thin_attrs() .prepend(attrs); @@ -2161,9 +2161,9 @@ impl<'a> Parser<'a> { let mut es = vec![]; let mut trailing_comma = false; while self.token != token::CloseDelim(token::Paren) { - es.push(try!(self.parse_expr())); - try!(self.commit_expr(&es.last().unwrap(), &[], - &[token::Comma, token::CloseDelim(token::Paren)])); + es.push(self.parse_expr()?); + self.commit_expr(&es.last().unwrap(), &[], + &[token::Comma, token::CloseDelim(token::Paren)])?; if self.check(&token::Comma) { trailing_comma = true; @@ -2201,7 +2201,7 @@ impl<'a> Parser<'a> { token::OpenDelim(token::Bracket) => { self.bump(); - let inner_attrs = try!(self.parse_inner_attributes()) + let inner_attrs = self.parse_inner_attributes()? .into_thin_attrs(); attrs.update(|attrs| attrs.append(inner_attrs)); @@ -2211,27 +2211,27 @@ impl<'a> Parser<'a> { ex = ExprKind::Vec(Vec::new()); } else { // Nonempty vector. - let first_expr = try!(self.parse_expr()); + let first_expr = self.parse_expr()?; if self.check(&token::Semi) { // Repeating array syntax: [ 0; 512 ] self.bump(); - let count = try!(self.parse_expr()); - try!(self.expect(&token::CloseDelim(token::Bracket))); + let count = self.parse_expr()?; + self.expect(&token::CloseDelim(token::Bracket))?; ex = ExprKind::Repeat(first_expr, count); } else if self.check(&token::Comma) { // Vector with two or more elements. self.bump(); - let remaining_exprs = try!(self.parse_seq_to_end( + let remaining_exprs = self.parse_seq_to_end( &token::CloseDelim(token::Bracket), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; let mut exprs = vec!(first_expr); exprs.extend(remaining_exprs); ex = ExprKind::Vec(exprs); } else { // Vector with one element. - try!(self.expect(&token::CloseDelim(token::Bracket))); + self.expect(&token::CloseDelim(token::Bracket))?; ex = ExprKind::Vec(vec!(first_expr)); } } @@ -2240,7 +2240,7 @@ impl<'a> Parser<'a> { _ => { if self.eat_lt() { let (qself, path) = - try!(self.parse_qualified_path(LifetimeAndTypesWithColons)); + self.parse_qualified_path(LifetimeAndTypesWithColons)?; hi = path.span.hi; return Ok(self.mk_expr(lo, hi, ExprKind::Path(Some(qself), path), attrs)); } @@ -2263,7 +2263,7 @@ impl<'a> Parser<'a> { let lifetime = self.get_lifetime(); let lo = self.span.lo; self.bump(); - try!(self.expect(&token::Colon)); + self.expect(&token::Colon)?; if self.eat_keyword(keywords::While) { return self.parse_while_expr(Some(lifetime), lo, attrs) } @@ -2304,7 +2304,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Return) { if self.token.can_begin_expr() { - let e = try!(self.parse_expr()); + let e = self.parse_expr()?; hi = e.span.hi; ex = ExprKind::Ret(Some(e)); } else { @@ -2332,18 +2332,18 @@ impl<'a> Parser<'a> { !self.check_keyword(keywords::True) && !self.check_keyword(keywords::False) { let pth = - try!(self.parse_path(LifetimeAndTypesWithColons)); + self.parse_path(LifetimeAndTypesWithColons)?; // `!`, as an operator, is prefix, so we know this isn't that if self.check(&token::Not) { // MACRO INVOCATION expression self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end( + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end( &token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let hi = self.last_span.hi; return Ok(self.mk_mac_expr(lo, @@ -2364,7 +2364,7 @@ impl<'a> Parser<'a> { let mut base = None; let attrs = attrs.append( - try!(self.parse_inner_attributes()) + self.parse_inner_attributes()? .into_thin_attrs()); while self.token != token::CloseDelim(token::Brace) { @@ -2403,7 +2403,7 @@ impl<'a> Parser<'a> { } hi = self.span.hi; - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; ex = ExprKind::Struct(pth, fields, base); return Ok(self.mk_expr(lo, hi, ex, attrs)); } @@ -2413,7 +2413,7 @@ impl<'a> Parser<'a> { ex = ExprKind::Path(None, pth); } else { // other literal expression - let lit = try!(self.parse_lit()); + let lit = self.parse_lit()?; hi = lit.span.hi; ex = ExprKind::Lit(P(lit)); } @@ -2439,12 +2439,12 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { let outer_attrs = attrs; - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; - let inner_attrs = try!(self.parse_inner_attributes()).into_thin_attrs(); + let inner_attrs = self.parse_inner_attributes()?.into_thin_attrs(); let attrs = outer_attrs.append(inner_attrs); - let blk = try!(self.parse_block_tail(lo, blk_mode)); + let blk = self.parse_block_tail(lo, blk_mode)?; return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), attrs)); } @@ -2452,10 +2452,10 @@ impl<'a> Parser<'a> { pub fn parse_dot_or_call_expr(&mut self, already_parsed_attrs: Option) -> PResult<'a, P> { - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let b = self.parse_bottom_expr(); - let (span, b) = try!(self.interpolated_or_expr_span(b)); + let (span, b) = self.interpolated_or_expr_span(b)?; self.parse_dot_or_call_expr_with(b, span.lo, attrs) } @@ -2498,8 +2498,8 @@ impl<'a> Parser<'a> { lo: BytePos) -> PResult<'a, P> { let (_, tys, bindings) = if self.eat(&token::ModSep) { - try!(self.expect_lt()); - try!(self.parse_generic_values_after_lt()) + self.expect_lt()?; + self.parse_generic_values_after_lt()? } else { (Vec::new(), Vec::new(), Vec::new()) }; @@ -2512,12 +2512,12 @@ impl<'a> Parser<'a> { Ok(match self.token { // expr.f() method call. token::OpenDelim(token::Paren) => { - let mut es = try!(self.parse_unspanned_seq( + let mut es = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; let hi = self.last_span.hi; es.insert(0, self_value); @@ -2559,7 +2559,7 @@ impl<'a> Parser<'a> { hi = self.span.hi; self.bump(); - e = try!(self.parse_dot_suffix(i, mk_sp(dot_pos, hi), e, lo)); + e = self.parse_dot_suffix(i, mk_sp(dot_pos, hi), e, lo)?; } token::Literal(token::Integer(n), suf) => { let sp = self.span; @@ -2609,9 +2609,9 @@ impl<'a> Parser<'a> { self.span_err(self.span, &format!("unexpected token: `{}`", actual)); let dot_pos = self.last_span.hi; - e = try!(self.parse_dot_suffix(special_idents::invalid, + e = self.parse_dot_suffix(special_idents::invalid, mk_sp(dot_pos, dot_pos), - e, lo)); + e, lo)?; } } continue; @@ -2620,12 +2620,12 @@ impl<'a> Parser<'a> { match self.token { // expr(...) token::OpenDelim(token::Paren) => { - let es = try!(self.parse_unspanned_seq( + let es = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| Ok(try!(p.parse_expr())) - )); + |p| Ok(p.parse_expr()?) + )?; hi = self.last_span.hi; let nd = self.mk_call(e, es); @@ -2636,9 +2636,9 @@ impl<'a> Parser<'a> { // Could be either an index expression or a slicing expression. token::OpenDelim(token::Bracket) => { self.bump(); - let ix = try!(self.parse_expr()); + let ix = self.parse_expr()?; hi = self.span.hi; - try!(self.commit_expr_expecting(&ix, token::CloseDelim(token::Bracket))); + self.commit_expr_expecting(&ix, token::CloseDelim(token::Bracket))?; let index = self.mk_index(e, ix); e = self.mk_expr(lo, hi, index, None) } @@ -2656,13 +2656,13 @@ impl<'a> Parser<'a> { self.bump(); if self.token == token::OpenDelim(token::Paren) { - let Spanned { node: seq, span: seq_span } = try!(self.parse_seq( + let Spanned { node: seq, span: seq_span } = self.parse_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::none(), |p| p.parse_token_tree() - )); - let (sep, repeat) = try!(self.parse_sep_and_kleene_op()); + )?; + let (sep, repeat) = self.parse_sep_and_kleene_op()?; let name_num = macro_parser::count_names(&seq); return Ok(TokenTree::Sequence(mk_sp(sp.lo, seq_span.hi), Rc::new(SequenceRepetition { @@ -2677,7 +2677,7 @@ impl<'a> Parser<'a> { } else { sp = mk_sp(sp.lo, self.span.hi); let namep = match self.token { token::Ident(_, p) => p, _ => token::Plain }; - let name = try!(self.parse_ident()); + let name = self.parse_ident()?; (name, namep) } } @@ -2694,7 +2694,7 @@ impl<'a> Parser<'a> { self.bump(); sp = mk_sp(sp.lo, self.span.hi); let kindp = match self.token { token::Ident(_, p) => p, _ => token::Plain }; - let nt_kind = try!(self.parse_ident()); + let nt_kind = self.parse_ident()?; Ok(TokenTree::Token(sp, MatchNt(name, nt_kind, namep, kindp))) } else { Ok(TokenTree::Token(sp, SubstNt(name, namep))) @@ -2729,13 +2729,13 @@ impl<'a> Parser<'a> { } }; - match try!(parse_kleene_op(self)) { + match parse_kleene_op(self)? { Some(kleene_op) => return Ok((None, kleene_op)), None => {} } let separator = self.bump_and_get(); - match try!(parse_kleene_op(self)) { + match parse_kleene_op(self)? { Some(zerok) => Ok((Some(separator), zerok)), None => return Err(self.fatal("expected `*` or `+`")) } @@ -2827,7 +2827,7 @@ impl<'a> Parser<'a> { pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec> { let mut tts = Vec::new(); while self.token != token::Eof { - tts.push(try!(self.parse_token_tree())); + tts.push(self.parse_token_tree()?); } Ok(tts) } @@ -2836,7 +2836,7 @@ impl<'a> Parser<'a> { pub fn parse_prefix_expr(&mut self, already_parsed_attrs: Option) -> PResult<'a, P> { - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let lo = self.span.lo; let hi; // Note: when adding new unary operators, don't forget to adjust Token::can_begin_expr() @@ -2844,39 +2844,39 @@ impl<'a> Parser<'a> { token::Not => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Not, e) } token::BinOp(token::Minus) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Neg, e) } token::BinOp(token::Star) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; self.mk_unary(UnOp::Deref, e) } token::BinOp(token::And) | token::AndAnd => { - try!(self.expect_and()); - let m = try!(self.parse_mutability()); + self.expect_and()?; + let m = self.parse_mutability()?; let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; ExprKind::AddrOf(m, e) } token::Ident(..) if self.token.is_keyword(keywords::In) => { self.bump(); - let place = try!(self.parse_expr_res( + let place = self.parse_expr_res( Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None, - )); - let blk = try!(self.parse_block()); + )?; + let blk = self.parse_block()?; let span = blk.span; hi = span.hi; let blk_expr = self.mk_expr(span.lo, span.hi, ExprKind::Block(blk), @@ -2886,7 +2886,7 @@ impl<'a> Parser<'a> { token::Ident(..) if self.token.is_keyword(keywords::Box) => { self.bump(); let e = self.parse_prefix_expr(None); - let (span, e) = try!(self.interpolated_or_expr_span(e)); + let (span, e) = self.interpolated_or_expr_span(e)?; hi = span.hi; ExprKind::Box(e) } @@ -2920,7 +2920,7 @@ impl<'a> Parser<'a> { if self.token == token::DotDot || self.token == token::DotDotDot { return self.parse_prefix_range_expr(attrs); } else { - try!(self.parse_prefix_expr(attrs)) + self.parse_prefix_expr(attrs)? } }; @@ -2952,12 +2952,12 @@ impl<'a> Parser<'a> { } // Special cases: if op == AssocOp::As { - let rhs = try!(self.parse_ty()); + let rhs = self.parse_ty()?; lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::Cast(lhs, rhs), None); continue } else if op == AssocOp::Colon { - let rhs = try!(self.parse_ty()); + let rhs = self.parse_ty()?; lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::Type(lhs, rhs), None); continue @@ -2990,7 +2990,7 @@ impl<'a> Parser<'a> { break } - let rhs = try!(match op.fixity() { + let rhs = match op.fixity() { Fixity::Right => self.with_res( restrictions - Restrictions::RESTRICTION_STMT_EXPR, |this| { @@ -3011,7 +3011,7 @@ impl<'a> Parser<'a> { this.parse_assoc_expr_with(op.precedence() + 1, LhsExpr::NotYetParsed) }), - }); + }?; lhs = match op { AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | @@ -3087,19 +3087,19 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { debug_assert!(self.token == token::DotDot || self.token == token::DotDotDot); let tok = self.token.clone(); - let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs)); + let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?; let lo = self.span.lo; let mut hi = self.span.hi; self.bump(); let opt_end = if self.is_at_start_of_range_notation_rhs() { // RHS must be parsed with more associativity than the dots. let next_prec = AssocOp::from_token(&tok).unwrap().precedence() + 1; - Some(try!(self.parse_assoc_expr_with(next_prec, + Some(self.parse_assoc_expr_with(next_prec, LhsExpr::NotYetParsed) .map(|x|{ hi = x.span.hi; x - }))) + })?) } else { None }; @@ -3131,12 +3131,12 @@ impl<'a> Parser<'a> { return self.parse_if_let_expr(attrs); } let lo = self.last_span.lo; - let cond = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let thn = try!(self.parse_block()); + let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let thn = self.parse_block()?; let mut els: Option> = None; let mut hi = thn.span.hi; if self.eat_keyword(keywords::Else) { - let elexpr = try!(self.parse_else_expr()); + let elexpr = self.parse_else_expr()?; hi = elexpr.span.hi; els = Some(elexpr); } @@ -3147,13 +3147,13 @@ impl<'a> Parser<'a> { pub fn parse_if_let_expr(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.last_span.lo; - try!(self.expect_keyword(keywords::Let)); - let pat = try!(self.parse_pat()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let thn = try!(self.parse_block()); + self.expect_keyword(keywords::Let)?; + let pat = self.parse_pat()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let thn = self.parse_block()?; let (hi, els) = if self.eat_keyword(keywords::Else) { - let expr = try!(self.parse_else_expr()); + let expr = self.parse_else_expr()?; (expr.span.hi, Some(expr)) } else { (thn.span.hi, None) @@ -3167,12 +3167,12 @@ impl<'a> Parser<'a> { attrs: ThinAttributes) -> PResult<'a, P> { - let decl = try!(self.parse_fn_block_decl()); + let decl = self.parse_fn_block_decl()?; let body = match decl.output { FunctionRetTy::Default(_) => { // If no explicit return type is given, parse any // expr and wrap it up in a dummy block: - let body_expr = try!(self.parse_expr()); + let body_expr = self.parse_expr()?; P(ast::Block { id: ast::DUMMY_NODE_ID, stmts: vec![], @@ -3184,7 +3184,7 @@ impl<'a> Parser<'a> { _ => { // If an explicit return type is given, require a // block to appear (RFC 968). - try!(self.parse_block()) + self.parse_block()? } }; @@ -3199,7 +3199,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::If) { return self.parse_if_expr(None); } else { - let blk = try!(self.parse_block()); + let blk = self.parse_block()?; return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), None)); } } @@ -3210,10 +3210,10 @@ impl<'a> Parser<'a> { attrs: ThinAttributes) -> PResult<'a, P> { // Parse: `for in ` - let pat = try!(self.parse_pat()); - try!(self.expect_keyword(keywords::In)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, loop_block) = try!(self.parse_inner_attrs_and_block()); + let pat = self.parse_pat()?; + self.expect_keyword(keywords::In)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, loop_block) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = self.last_span.hi; @@ -3230,8 +3230,8 @@ impl<'a> Parser<'a> { if self.token.is_keyword(keywords::Let) { return self.parse_while_let_expr(opt_ident, span_lo, attrs); } - let cond = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + let cond = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; return Ok(self.mk_expr(span_lo, hi, ExprKind::While(cond, body, opt_ident), @@ -3242,11 +3242,11 @@ impl<'a> Parser<'a> { pub fn parse_while_let_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { - try!(self.expect_keyword(keywords::Let)); - let pat = try!(self.parse_pat()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)); - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + self.expect_keyword(keywords::Let)?; + let pat = self.parse_pat()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, None)?; + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; return Ok(self.mk_expr(span_lo, hi, ExprKind::WhileLet(pat, expr, body, opt_ident), attrs)); @@ -3256,7 +3256,7 @@ impl<'a> Parser<'a> { pub fn parse_loop_expr(&mut self, opt_ident: Option, span_lo: BytePos, attrs: ThinAttributes) -> PResult<'a, P> { - let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); + let (iattrs, body) = self.parse_inner_attrs_and_block()?; let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; Ok(self.mk_expr(span_lo, hi, ExprKind::Loop(body, opt_ident), attrs)) @@ -3266,8 +3266,8 @@ impl<'a> Parser<'a> { fn parse_match_expr(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let match_span = self.last_span; let lo = self.last_span.lo; - let discriminant = try!(self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, - None)); + let discriminant = self.parse_expr_res(Restrictions::RESTRICTION_NO_STRUCT_LITERAL, + None)?; if let Err(mut e) = self.commit_expr_expecting(&discriminant, token::OpenDelim(token::Brace)) { if self.token == token::Token::Semi { @@ -3276,7 +3276,7 @@ impl<'a> Parser<'a> { return Err(e) } let attrs = attrs.append( - try!(self.parse_inner_attributes()).into_thin_attrs()); + self.parse_inner_attributes()?.into_thin_attrs()); let mut arms: Vec = Vec::new(); while self.token != token::CloseDelim(token::Brace) { match self.parse_arm() { @@ -3301,21 +3301,21 @@ impl<'a> Parser<'a> { pub fn parse_arm(&mut self) -> PResult<'a, Arm> { maybe_whole!(no_clone self, NtArm); - let attrs = try!(self.parse_outer_attributes()); - let pats = try!(self.parse_pats()); + let attrs = self.parse_outer_attributes()?; + let pats = self.parse_pats()?; let mut guard = None; if self.eat_keyword(keywords::If) { - guard = Some(try!(self.parse_expr())); + guard = Some(self.parse_expr()?); } - try!(self.expect(&token::FatArrow)); - let expr = try!(self.parse_expr_res(Restrictions::RESTRICTION_STMT_EXPR, None)); + self.expect(&token::FatArrow)?; + let expr = self.parse_expr_res(Restrictions::RESTRICTION_STMT_EXPR, None)?; let require_comma = !classify::expr_is_simple_block(&expr) && self.token != token::CloseDelim(token::Brace); if require_comma { - try!(self.commit_expr(&expr, &[token::Comma], &[token::CloseDelim(token::Brace)])); + self.commit_expr(&expr, &[token::Comma], &[token::CloseDelim(token::Brace)])?; } else { self.eat(&token::Comma); } @@ -3358,7 +3358,7 @@ impl<'a> Parser<'a> { fn parse_initializer(&mut self) -> PResult<'a, Option>> { if self.check(&token::Eq) { self.bump(); - Ok(Some(try!(self.parse_expr()))) + Ok(Some(self.parse_expr()?)) } else { Ok(None) } @@ -3368,7 +3368,7 @@ impl<'a> Parser<'a> { fn parse_pats(&mut self) -> PResult<'a, Vec>> { let mut pats = Vec::new(); loop { - pats.push(try!(self.parse_pat())); + pats.push(self.parse_pat()?); if self.check(&token::BinOp(token::Or)) { self.bump();} else { return Ok(pats); } }; @@ -3377,15 +3377,15 @@ impl<'a> Parser<'a> { fn parse_pat_tuple_elements(&mut self) -> PResult<'a, Vec>> { let mut fields = vec![]; if !self.check(&token::CloseDelim(token::Paren)) { - fields.push(try!(self.parse_pat())); + fields.push(self.parse_pat()?); if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) { while self.eat(&token::Comma) && !self.check(&token::CloseDelim(token::Paren)) { - fields.push(try!(self.parse_pat())); + fields.push(self.parse_pat()?); } } if fields.len() == 1 { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; } } Ok(fields) @@ -3404,7 +3404,7 @@ impl<'a> Parser<'a> { if first { first = false; } else { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; if self.token == token::CloseDelim(token::Bracket) && (before_slice || !after.is_empty()) { @@ -3429,7 +3429,7 @@ impl<'a> Parser<'a> { } } - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; if before_slice && self.check(&token::DotDot) { self.bump(); slice = Some(subpat); @@ -3453,7 +3453,7 @@ impl<'a> Parser<'a> { if first { first = false; } else { - try!(self.expect(&token::Comma)); + self.expect(&token::Comma)?; // accept trailing commas if self.check(&token::CloseDelim(token::Brace)) { break } } @@ -3475,9 +3475,9 @@ impl<'a> Parser<'a> { // Check if a colon exists one ahead. This means we're parsing a fieldname. let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) { // Parsing a pattern of the form "fieldname: pat" - let fieldname = try!(self.parse_ident()); + let fieldname = self.parse_ident()?; self.bump(); - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; hi = pat.span.hi; (pat, fieldname, false) } else { @@ -3486,7 +3486,7 @@ impl<'a> Parser<'a> { let boxed_span_lo = self.span.lo; let is_ref = self.eat_keyword(keywords::Ref); let is_mut = self.eat_keyword(keywords::Mut); - let fieldname = try!(self.parse_ident()); + let fieldname = self.parse_ident()?; hi = self.last_span.hi; let bind_type = match (is_ref, is_mut) { @@ -3528,11 +3528,11 @@ impl<'a> Parser<'a> { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; (Some(qself), path) } else { // Parse an unqualified path - (None, try!(self.parse_path(LifetimeAndTypesWithColons))) + (None, self.parse_path(LifetimeAndTypesWithColons)?) }; let hi = self.last_span.hi; Ok(self.mk_expr(lo, hi, ExprKind::Path(qself, path), None)) @@ -3561,41 +3561,41 @@ impl<'a> Parser<'a> { } token::BinOp(token::And) | token::AndAnd => { // Parse &pat / &mut pat - try!(self.expect_and()); - let mutbl = try!(self.parse_mutability()); + self.expect_and()?; + let mutbl = self.parse_mutability()?; if let token::Lifetime(ident) = self.token { return Err(self.fatal(&format!("unexpected lifetime `{}` in pattern", ident))); } - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; pat = PatKind::Ref(subpat, mutbl); } token::OpenDelim(token::Paren) => { // Parse (pat,pat,pat,...) as tuple pattern self.bump(); - let fields = try!(self.parse_pat_tuple_elements()); - try!(self.expect(&token::CloseDelim(token::Paren))); + let fields = self.parse_pat_tuple_elements()?; + self.expect(&token::CloseDelim(token::Paren))?; pat = PatKind::Tup(fields); } token::OpenDelim(token::Bracket) => { // Parse [pat,pat,...] as slice pattern self.bump(); - let (before, slice, after) = try!(self.parse_pat_vec_elements()); - try!(self.expect(&token::CloseDelim(token::Bracket))); + let (before, slice, after) = self.parse_pat_vec_elements()?; + self.expect(&token::CloseDelim(token::Bracket))?; pat = PatKind::Vec(before, slice, after); } _ => { // At this point, token != _, &, &&, (, [ if self.eat_keyword(keywords::Mut) { // Parse mut ident @ pat - pat = try!(self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))); + pat = self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))?; } else if self.eat_keyword(keywords::Ref) { // Parse ref ident @ pat / ref mut ident @ pat - let mutbl = try!(self.parse_mutability()); - pat = try!(self.parse_pat_ident(BindingMode::ByRef(mutbl))); + let mutbl = self.parse_mutability()?; + pat = self.parse_pat_ident(BindingMode::ByRef(mutbl))?; } else if self.eat_keyword(keywords::Box) { // Parse box pat - let subpat = try!(self.parse_pat()); + let subpat = self.parse_pat()?; pat = PatKind::Box(subpat); } else if self.is_path_start() { // Parse pattern starting with a path @@ -3607,13 +3607,13 @@ impl<'a> Parser<'a> { // Plain idents have some extra abilities here compared to general paths if self.look_ahead(1, |t| *t == token::Not) { // Parse macro invocation - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let ident_span = self.last_span; let path = ident_to_path(ident_span, ident); self.bump(); - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), - SeqSep::none(), |p| p.parse_token_tree())); + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), + SeqSep::none(), |p| p.parse_token_tree())?; let mac = Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT }; pat = PatKind::Mac(codemap::Spanned {node: mac, span: mk_sp(lo, self.last_span.hi)}); @@ -3622,17 +3622,17 @@ impl<'a> Parser<'a> { // This can give false positives and parse nullary enums, // they are dealt with later in resolve let binding_mode = BindingMode::ByValue(Mutability::Immutable); - pat = try!(self.parse_pat_ident(binding_mode)); + pat = self.parse_pat_ident(binding_mode)?; } } else { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - try!(self.parse_qualified_path(NoTypesAllowed)); + self.parse_qualified_path(NoTypesAllowed)?; (Some(qself), path) } else { // Parse an unqualified path - (None, try!(self.parse_path(LifetimeAndTypesWithColons))) + (None, self.parse_path(LifetimeAndTypesWithColons)?) }; match self.token { token::DotDotDot => { @@ -3640,7 +3640,7 @@ impl<'a> Parser<'a> { let hi = self.last_span.hi; let begin = self.mk_expr(lo, hi, ExprKind::Path(qself, path), None); self.bump(); - let end = try!(self.parse_pat_range_end()); + let end = self.parse_pat_range_end()?; pat = PatKind::Range(begin, end); } token::OpenDelim(token::Brace) => { @@ -3666,14 +3666,14 @@ impl<'a> Parser<'a> { // This is a "top constructor only" pat self.bump(); self.bump(); - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; pat = PatKind::TupleStruct(path, None); } else { - let args = try!(self.parse_enum_variant_seq( + let args = self.parse_enum_variant_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_pat())); + |p| p.parse_pat())?; pat = PatKind::TupleStruct(path, Some(args)); } } @@ -3689,9 +3689,9 @@ impl<'a> Parser<'a> { } } else { // Try to parse everything else as literal with optional minus - let begin = try!(self.parse_pat_literal_maybe_minus()); + let begin = self.parse_pat_literal_maybe_minus()?; if self.eat(&token::DotDotDot) { - let end = try!(self.parse_pat_range_end()); + let end = self.parse_pat_range_end()?; pat = PatKind::Range(begin, end); } else { pat = PatKind::Lit(begin); @@ -3720,11 +3720,11 @@ impl<'a> Parser<'a> { return Err(self.span_fatal(span, &format!("expected identifier, found `{}`", tok_str))) } - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; let last_span = self.last_span; let name = codemap::Spanned{span: last_span, node: ident}; let sub = if self.eat(&token::At) { - Some(try!(self.parse_pat())) + Some(self.parse_pat()?) } else { None }; @@ -3748,13 +3748,13 @@ impl<'a> Parser<'a> { /// Parse a local variable declaration fn parse_local(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.span.lo; - let pat = try!(self.parse_pat()); + let pat = self.parse_pat()?; let mut ty = None; if self.eat(&token::Colon) { - ty = Some(try!(self.parse_ty_sum())); + ty = Some(self.parse_ty_sum()?); } - let init = try!(self.parse_initializer()); + let init = self.parse_initializer()?; Ok(P(ast::Local { ty: ty, pat: pat, @@ -3768,7 +3768,7 @@ impl<'a> Parser<'a> { /// Parse a "let" stmt fn parse_let(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { let lo = self.span.lo; - let local = try!(self.parse_local(attrs)); + let local = self.parse_local(attrs)?; Ok(P(spanned(lo, self.last_span.hi, DeclKind::Local(local)))) } @@ -3782,9 +3782,9 @@ impl<'a> Parser<'a> { if !self.token.is_plain_ident() { return Err(self.fatal("expected ident")); } - let name = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); + let name = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; Ok(spanned(lo, self.last_span.hi, ast::StructField_ { kind: NamedField(name, pr), id: ast::DUMMY_NODE_ID, @@ -3875,12 +3875,12 @@ impl<'a> Parser<'a> { fn parse_stmt_without_recovery(&mut self) -> PResult<'a, Option> { maybe_whole!(Some deref self, NtStmt); - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; let lo = self.span.lo; Ok(Some(if self.check_keyword(keywords::Let) { - try!(self.expect_keyword(keywords::Let)); - let decl = try!(self.parse_let(attrs.into_thin_attrs())); + self.expect_keyword(keywords::Let)?; + let decl = self.parse_let(attrs.into_thin_attrs())?; let hi = decl.span.hi; let stmt = StmtKind::Decl(decl, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) @@ -3891,12 +3891,12 @@ impl<'a> Parser<'a> { // Potential trouble: if we allow macros with paths instead of // idents, we'd need to look ahead past the whole path here... - let pth = try!(self.parse_path(NoTypesAllowed)); + let pth = self.parse_path(NoTypesAllowed)?; self.bump(); let id = match self.token { token::OpenDelim(_) => token::special_idents::invalid, // no special identifier - _ => try!(self.parse_ident()), + _ => self.parse_ident()?, }; // check that we're pointing at delimiters (need to check @@ -3919,12 +3919,12 @@ impl<'a> Parser<'a> { }, }; - let tts = try!(self.parse_unspanned_seq( + let tts = self.parse_unspanned_seq( &token::OpenDelim(delim), &token::CloseDelim(delim), SeqSep::none(), |p| p.parse_token_tree() - )); + )?; let hi = self.last_span.hi; let style = if delim == token::Brace { @@ -3962,8 +3962,8 @@ impl<'a> Parser<'a> { } else { // FIXME: Bad copy of attrs let restrictions = self.restrictions | Restrictions::NO_NONINLINE_MOD; - match try!(self.with_res(restrictions, - |this| this.parse_item_(attrs.clone(), false, true))) { + match self.with_res(restrictions, + |this| this.parse_item_(attrs.clone(), false, true))? { Some(i) => { let hi = i.span.hi; let decl = P(spanned(lo, hi, DeclKind::Item(i))); @@ -3990,8 +3990,8 @@ impl<'a> Parser<'a> { } // Remainder are line-expr stmts. - let e = try!(self.parse_expr_res( - Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))); + let e = self.parse_expr_res( + Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))?; let hi = e.span.hi; let stmt = StmtKind::Expr(e, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) @@ -4028,9 +4028,9 @@ impl<'a> Parser<'a> { maybe_whole!(pair_empty self, NtBlock); let lo = self.span.lo; - try!(self.expect(&token::OpenDelim(token::Brace))); - Ok((try!(self.parse_inner_attributes()), - try!(self.parse_block_tail(lo, BlockCheckMode::Default)))) + self.expect(&token::OpenDelim(token::Brace))?; + Ok((self.parse_inner_attributes()?, + self.parse_block_tail(lo, BlockCheckMode::Default)?)) } /// Parse the rest of a block expression or function body @@ -4048,7 +4048,7 @@ impl<'a> Parser<'a> { }; match node { StmtKind::Expr(e, _) => { - try!(self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)); + self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)?; } StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => { // statement macro without braces; might be an @@ -4066,13 +4066,13 @@ impl<'a> Parser<'a> { mac.and_then(|m| m.node), None); let lo = e.span.lo; - let e = try!(self.parse_dot_or_call_expr_with(e, lo, attrs)); - let e = try!(self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))); - try!(self.handle_expression_like_statement( + let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; + let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; + self.handle_expression_like_statement( e, span, &mut stmts, - &mut expr)); + &mut expr)?; } } } @@ -4104,7 +4104,7 @@ impl<'a> Parser<'a> { _ => { // all other kinds of statements: let mut hi = span.hi; if classify::stmt_ends_with_semi(&node) { - try!(self.commit_stmt_expecting(token::Semi)); + self.commit_stmt_expecting(token::Semi)?; hi = self.last_span.hi; } @@ -4205,7 +4205,7 @@ impl<'a> Parser<'a> { self.bump(); } token::ModSep | token::Ident(..) => { - let poly_trait_ref = try!(self.parse_poly_trait_ref()); + let poly_trait_ref = self.parse_poly_trait_ref()?; let modifier = if ate_question { if mode == BoundParsingMode::Modified { TraitBoundModifier::Maybe @@ -4233,13 +4233,13 @@ impl<'a> Parser<'a> { /// Matches typaram = IDENT (`?` unbound)? optbounds ( EQ ty )? fn parse_ty_param(&mut self) -> PResult<'a, TyParam> { let span = self.span; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; - let bounds = try!(self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)); + let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Modified)?; let default = if self.check(&token::Eq) { self.bump(); - Some(try!(self.parse_ty_sum())) + Some(self.parse_ty_sum()?) } else { None }; @@ -4264,11 +4264,11 @@ impl<'a> Parser<'a> { maybe_whole!(self, NtGenerics); if self.eat(&token::Lt) { - let lifetime_defs = try!(self.parse_lifetime_defs()); + let lifetime_defs = self.parse_lifetime_defs()?; let mut seen_default = false; - let ty_params = try!(self.parse_seq_to_gt(Some(token::Comma), |p| { - try!(p.forbid_lifetime()); - let ty_param = try!(p.parse_ty_param()); + let ty_params = self.parse_seq_to_gt(Some(token::Comma), |p| { + p.forbid_lifetime()?; + let ty_param = p.parse_ty_param()?; if ty_param.default.is_some() { seen_default = true; } else if seen_default { @@ -4277,7 +4277,7 @@ impl<'a> Parser<'a> { "type parameters with a default must be trailing"); } Ok(ty_param) - })); + })?; Ok(ast::Generics { lifetimes: lifetime_defs, ty_params: ty_params, @@ -4295,7 +4295,7 @@ impl<'a> Parser<'a> { Vec>, Vec)> { let span_lo = self.span.lo; - let lifetimes = try!(self.parse_lifetimes(token::Comma)); + let lifetimes = self.parse_lifetimes(token::Comma)?; let missing_comma = !lifetimes.is_empty() && !self.token.is_like_gt() && @@ -4327,17 +4327,17 @@ impl<'a> Parser<'a> { } // First parse types. - let (types, returned) = try!(self.parse_seq_to_gt_or_return( + let (types, returned) = self.parse_seq_to_gt_or_return( Some(token::Comma), |p| { - try!(p.forbid_lifetime()); + p.forbid_lifetime()?; if p.look_ahead(1, |t| t == &token::Eq) { Ok(None) } else { - Ok(Some(try!(p.parse_ty_sum()))) + Ok(Some(p.parse_ty_sum()?)) } } - )); + )?; // If we found the `>`, don't continue. if !returned { @@ -4345,18 +4345,18 @@ impl<'a> Parser<'a> { } // Then parse type bindings. - let bindings = try!(self.parse_seq_to_gt( + let bindings = self.parse_seq_to_gt( Some(token::Comma), |p| { - try!(p.forbid_lifetime()); + p.forbid_lifetime()?; let lo = p.span.lo; - let ident = try!(p.parse_ident()); + let ident = p.parse_ident()?; let found_eq = p.eat(&token::Eq); if !found_eq { let span = p.span; p.span_warn(span, "whoops, no =?"); } - let ty = try!(p.parse_ty()); + let ty = p.parse_ty()?; let hi = ty.span.hi; let span = mk_sp(lo, hi); return Ok(TypeBinding{id: ast::DUMMY_NODE_ID, @@ -4365,7 +4365,7 @@ impl<'a> Parser<'a> { span: span, }); } - )); + )?; Ok((lifetimes, types.into_vec(), bindings.into_vec())) } @@ -4405,12 +4405,12 @@ impl<'a> Parser<'a> { token::Lifetime(..) => { let bounded_lifetime = - try!(self.parse_lifetime()); + self.parse_lifetime()?; self.eat(&token::Colon); let bounds = - try!(self.parse_lifetimes(token::BinOp(token::Plus))); + self.parse_lifetimes(token::BinOp(token::Plus))?; let hi = self.last_span.hi; let span = mk_sp(lo, hi); @@ -4429,18 +4429,18 @@ impl<'a> Parser<'a> { _ => { let bound_lifetimes = if self.eat_keyword(keywords::For) { // Higher ranked constraint. - try!(self.expect(&token::Lt)); - let lifetime_defs = try!(self.parse_lifetime_defs()); - try!(self.expect_gt()); + self.expect(&token::Lt)?; + let lifetime_defs = self.parse_lifetime_defs()?; + self.expect_gt()?; lifetime_defs } else { vec![] }; - let bounded_ty = try!(self.parse_ty()); + let bounded_ty = self.parse_ty()?; if self.eat(&token::Colon) { - let bounds = try!(self.parse_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_ty_param_bounds(BoundParsingMode::Bare)?; let hi = self.last_span.hi; let span = mk_sp(lo, hi); @@ -4503,7 +4503,7 @@ impl<'a> Parser<'a> { let sp = self.span; let mut variadic = false; let args: Vec> = - try!(self.parse_unspanned_seq( + self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), @@ -4534,7 +4534,7 @@ impl<'a> Parser<'a> { } } } - )); + )?; let args: Vec<_> = args.into_iter().filter_map(|x| x).collect(); @@ -4549,8 +4549,8 @@ impl<'a> Parser<'a> { /// Parse the argument list and result type of a function declaration pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P> { - let (args, variadic) = try!(self.parse_fn_args(true, allow_variadic)); - let ret_ty = try!(self.parse_ret_ty()); + let (args, variadic) = self.parse_fn_args(true, allow_variadic)?; + let ret_ty = self.parse_ret_ty()?; Ok(P(FnDecl { inputs: args, @@ -4620,31 +4620,31 @@ impl<'a> Parser<'a> { if this.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - Ok(SelfKind::Region(None, Mutability::Immutable, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, Mutability::Immutable, this.expect_self_ident()?)) } else if this.look_ahead(1, |t| t.is_mutability()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let mutability = try!(this.parse_mutability()); - Ok(SelfKind::Region(None, mutability, try!(this.expect_self_ident()))) + let mutability = this.parse_mutability()?; + Ok(SelfKind::Region(None, mutability, this.expect_self_ident()?)) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let lifetime = try!(this.parse_lifetime()); - let ident = try!(this.expect_self_ident()); + let lifetime = this.parse_lifetime()?; + let ident = this.expect_self_ident()?; Ok(SelfKind::Region(Some(lifetime), Mutability::Immutable, ident)) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_mutability()) && this.look_ahead(3, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - let lifetime = try!(this.parse_lifetime()); - let mutability = try!(this.parse_mutability()); - Ok(SelfKind::Region(Some(lifetime), mutability, try!(this.expect_self_ident()))) + let lifetime = this.parse_lifetime()?; + let mutability = this.parse_mutability()?; + Ok(SelfKind::Region(Some(lifetime), mutability, this.expect_self_ident()?)) } else { Ok(SelfKind::Static) } } - try!(self.expect(&token::OpenDelim(token::Paren))); + self.expect(&token::OpenDelim(token::Paren))?; // A bit of complexity and lookahead is needed here in order to be // backwards compatible. @@ -4655,7 +4655,7 @@ impl<'a> Parser<'a> { let mut mutbl_self = Mutability::Immutable; let explicit_self = match self.token { token::BinOp(token::And) => { - let eself = try!(maybe_parse_borrowed_explicit_self(self)); + let eself = maybe_parse_borrowed_explicit_self(self)?; self_ident_lo = self.last_span.lo; self_ident_hi = self.last_span.hi; eself @@ -4665,7 +4665,7 @@ impl<'a> Parser<'a> { // emitting cryptic "unexpected token" errors. self.bump(); let _mutability = if self.token.is_mutability() { - try!(self.parse_mutability()) + self.parse_mutability()? } else { Mutability::Immutable }; @@ -4679,24 +4679,24 @@ impl<'a> Parser<'a> { } token::Ident(..) => { if self.is_self_ident() { - let self_ident = try!(self.expect_self_ident()); + let self_ident = self.expect_self_ident()?; // Determine whether this is the fully explicit form, `self: // TYPE`. if self.eat(&token::Colon) { - SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(self.parse_ty_sum()?, self_ident) } else { SelfKind::Value(self_ident) } } else if self.token.is_mutability() && self.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { - mutbl_self = try!(self.parse_mutability()); - let self_ident = try!(self.expect_self_ident()); + mutbl_self = self.parse_mutability()?; + let self_ident = self.expect_self_ident()?; // Determine whether this is the fully explicit form, // `self: TYPE`. if self.eat(&token::Colon) { - SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(self.parse_ty_sum()?, self_ident) } else { SelfKind::Value(self_ident) } @@ -4750,11 +4750,11 @@ impl<'a> Parser<'a> { }; - try!(self.expect(&token::CloseDelim(token::Paren))); + self.expect(&token::CloseDelim(token::Paren))?; let hi = self.span.hi; - let ret_ty = try!(self.parse_ret_ty()); + let ret_ty = self.parse_ret_ty()?; let fn_decl = P(FnDecl { inputs: fn_inputs, @@ -4771,8 +4771,8 @@ impl<'a> Parser<'a> { if self.eat(&token::OrOr) { Vec::new() } else { - try!(self.expect(&token::BinOp(token::Or))); - try!(self.parse_obsolete_closure_kind()); + self.expect(&token::BinOp(token::Or))?; + self.parse_obsolete_closure_kind()?; let args = self.parse_seq_to_before_end( &token::BinOp(token::Or), SeqSep::trailing_allowed(token::Comma), @@ -4782,7 +4782,7 @@ impl<'a> Parser<'a> { args } }; - let output = try!(self.parse_ret_ty()); + let output = self.parse_ret_ty()?; Ok(P(FnDecl { inputs: inputs_captures, @@ -4793,8 +4793,8 @@ impl<'a> Parser<'a> { /// Parse the name and optional generic types of a function header. fn parse_fn_header(&mut self) -> PResult<'a, (Ident, ast::Generics)> { - let id = try!(self.parse_ident()); - let generics = try!(self.parse_generics()); + let id = self.parse_ident()?; + let generics = self.parse_generics()?; Ok((id, generics)) } @@ -4817,10 +4817,10 @@ impl<'a> Parser<'a> { constness: Constness, abi: abi::Abi) -> PResult<'a, ItemInfo> { - let (ident, mut generics) = try!(self.parse_fn_header()); - let decl = try!(self.parse_fn_decl(false)); - generics.where_clause = try!(self.parse_where_clause()); - let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); + let (ident, mut generics) = self.parse_fn_header()?; + let decl = self.parse_fn_decl(false)?; + generics.where_clause = self.parse_where_clause()?; + let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; Ok((ident, ItemKind::Fn(decl, unsafety, constness, abi, generics, body), Some(inner_attrs))) } @@ -4842,18 +4842,18 @@ impl<'a> Parser<'a> { pub fn parse_fn_front_matter(&mut self) -> PResult<'a, (ast::Constness, ast::Unsafety, abi::Abi)> { let is_const_fn = self.eat_keyword(keywords::Const); - let unsafety = try!(self.parse_unsafety()); + let unsafety = self.parse_unsafety()?; let (constness, unsafety, abi) = if is_const_fn { (Constness::Const, unsafety, Abi::Rust) } else { let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; (Constness::NotConst, unsafety, abi) }; - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; Ok((constness, unsafety, abi)) } @@ -4861,27 +4861,27 @@ impl<'a> Parser<'a> { pub fn parse_impl_item(&mut self) -> PResult<'a, ImplItem> { maybe_whole!(no_clone_from_p self, NtImplItem); - let mut attrs = try!(self.parse_outer_attributes()); + let mut attrs = self.parse_outer_attributes()?; let lo = self.span.lo; - let vis = try!(self.parse_visibility()); - let defaultness = try!(self.parse_defaultness()); + let vis = self.parse_visibility()?; + let defaultness = self.parse_defaultness()?; let (name, node) = if self.eat_keyword(keywords::Type) { - let name = try!(self.parse_ident()); - try!(self.expect(&token::Eq)); - let typ = try!(self.parse_ty_sum()); - try!(self.expect(&token::Semi)); + let name = self.parse_ident()?; + self.expect(&token::Eq)?; + let typ = self.parse_ty_sum()?; + self.expect(&token::Semi)?; (name, ast::ImplItemKind::Type(typ)) } else if self.is_const_item() { - try!(self.expect_keyword(keywords::Const)); - let name = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let typ = try!(self.parse_ty_sum()); - try!(self.expect(&token::Eq)); - let expr = try!(self.parse_expr()); - try!(self.commit_expr_expecting(&expr, token::Semi)); + self.expect_keyword(keywords::Const)?; + let name = self.parse_ident()?; + self.expect(&token::Colon)?; + let typ = self.parse_ty_sum()?; + self.expect(&token::Eq)?; + let expr = self.parse_expr()?; + self.commit_expr_expecting(&expr, token::Semi)?; (name, ast::ImplItemKind::Const(typ, expr)) } else { - let (name, inner_attrs, node) = try!(self.parse_impl_method(vis)); + let (name, inner_attrs, node) = self.parse_impl_method(vis)?; attrs.extend(inner_attrs); (name, node) }; @@ -4935,31 +4935,31 @@ impl<'a> Parser<'a> { self.complain_if_pub_macro(vis, last_span); let lo = self.span.lo; - let pth = try!(self.parse_path(NoTypesAllowed)); - try!(self.expect(&token::Not)); + let pth = self.parse_path(NoTypesAllowed)?; + self.expect(&token::Not)?; // eat a matched-delimiter token tree: - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; let m_ = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(lo, self.last_span.hi) }; if delim != token::Brace { - try!(self.expect(&token::Semi)) + self.expect(&token::Semi)? } Ok((token::special_idents::invalid, vec![], ast::ImplItemKind::Macro(m))) } else { - let (constness, unsafety, abi) = try!(self.parse_fn_front_matter()); - let ident = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); - let (explicit_self, decl) = try!(self.parse_fn_decl_with_self(|p| { + let (constness, unsafety, abi) = self.parse_fn_front_matter()?; + let ident = self.parse_ident()?; + let mut generics = self.parse_generics()?; + let (explicit_self, decl) = self.parse_fn_decl_with_self(|p| { p.parse_arg() - })); - generics.where_clause = try!(self.parse_where_clause()); - let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); + })?; + generics.where_clause = self.parse_where_clause()?; + let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig { generics: generics, abi: abi, @@ -4974,15 +4974,15 @@ impl<'a> Parser<'a> { /// Parse trait Foo { ... } fn parse_item_trait(&mut self, unsafety: Unsafety) -> PResult<'a, ItemInfo> { - let ident = try!(self.parse_ident()); - let mut tps = try!(self.parse_generics()); + let ident = self.parse_ident()?; + let mut tps = self.parse_generics()?; // Parse supertrait bounds. - let bounds = try!(self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)); + let bounds = self.parse_colon_then_ty_param_bounds(BoundParsingMode::Bare)?; - tps.where_clause = try!(self.parse_where_clause()); + tps.where_clause = self.parse_where_clause()?; - let meths = try!(self.parse_trait_items()); + let meths = self.parse_trait_items()?; Ok((ident, ItemKind::Trait(unsafety, tps, bounds, meths), None)) } @@ -4994,7 +4994,7 @@ impl<'a> Parser<'a> { let impl_span = self.span; // First, parse type parameters if necessary. - let mut generics = try!(self.parse_generics()); + let mut generics = self.parse_generics()?; // Special case: if the next identifier that follows is '(', don't // allow this to be parsed as a trait. @@ -5008,7 +5008,7 @@ impl<'a> Parser<'a> { }; // Parse the trait. - let mut ty = try!(self.parse_ty_sum()); + let mut ty = self.parse_ty_sum()?; // Parse traits, if necessary. let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) { @@ -5043,22 +5043,22 @@ impl<'a> Parser<'a> { allowed to have generics"); } - try!(self.expect(&token::OpenDelim(token::Brace))); - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; + self.expect(&token::CloseDelim(token::Brace))?; Ok((ast_util::impl_pretty_name(&opt_trait, None), ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None)) } else { if opt_trait.is_some() { - ty = try!(self.parse_ty_sum()); + ty = self.parse_ty_sum()?; } - generics.where_clause = try!(self.parse_where_clause()); + generics.where_clause = self.parse_where_clause()?; - try!(self.expect(&token::OpenDelim(token::Brace))); - let attrs = try!(self.parse_inner_attributes()); + self.expect(&token::OpenDelim(token::Brace))?; + let attrs = self.parse_inner_attributes()?; let mut impl_items = vec![]; while !self.eat(&token::CloseDelim(token::Brace)) { - impl_items.push(try!(self.parse_impl_item())); + impl_items.push(self.parse_impl_item()?); } Ok((ast_util::impl_pretty_name(&opt_trait, Some(&ty)), @@ -5070,16 +5070,16 @@ impl<'a> Parser<'a> { /// Parse a::B fn parse_trait_ref(&mut self) -> PResult<'a, TraitRef> { Ok(ast::TraitRef { - path: try!(self.parse_path(LifetimeAndTypesWithoutColons)), + path: self.parse_path(LifetimeAndTypesWithoutColons)?, ref_id: ast::DUMMY_NODE_ID, }) } fn parse_late_bound_lifetime_defs(&mut self) -> PResult<'a, Vec> { if self.eat_keyword(keywords::For) { - try!(self.expect(&token::Lt)); - let lifetime_defs = try!(self.parse_lifetime_defs()); - try!(self.expect_gt()); + self.expect(&token::Lt)?; + let lifetime_defs = self.parse_lifetime_defs()?; + self.expect_gt()?; Ok(lifetime_defs) } else { Ok(Vec::new()) @@ -5089,19 +5089,19 @@ impl<'a> Parser<'a> { /// Parse for<'l> a::B fn parse_poly_trait_ref(&mut self) -> PResult<'a, PolyTraitRef> { let lo = self.span.lo; - let lifetime_defs = try!(self.parse_late_bound_lifetime_defs()); + let lifetime_defs = self.parse_late_bound_lifetime_defs()?; Ok(ast::PolyTraitRef { bound_lifetimes: lifetime_defs, - trait_ref: try!(self.parse_trait_ref()), + trait_ref: self.parse_trait_ref()?, span: mk_sp(lo, self.last_span.hi), }) } /// Parse struct Foo { ... } fn parse_item_struct(&mut self) -> PResult<'a, ItemInfo> { - let class_name = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); + let class_name = self.parse_ident()?; + let mut generics = self.parse_generics()?; // There is a special case worth noting here, as reported in issue #17904. // If we are parsing a tuple struct it is the case that the where clause @@ -5118,25 +5118,25 @@ impl<'a> Parser<'a> { // struct. let vdata = if self.token.is_keyword(keywords::Where) { - generics.where_clause = try!(self.parse_where_clause()); + generics.where_clause = self.parse_where_clause()?; if self.eat(&token::Semi) { // If we see a: `struct Foo where T: Copy;` style decl. VariantData::Unit(ast::DUMMY_NODE_ID) } else { // If we see: `struct Foo where T: Copy { ... }` - VariantData::Struct(try!(self.parse_record_struct_body()), ast::DUMMY_NODE_ID) + VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID) } // No `where` so: `struct Foo;` } else if self.eat(&token::Semi) { VariantData::Unit(ast::DUMMY_NODE_ID) // Record-style struct definition } else if self.token == token::OpenDelim(token::Brace) { - VariantData::Struct(try!(self.parse_record_struct_body()), ast::DUMMY_NODE_ID) + VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID) // Tuple-style struct definition with optional where-clause. } else if self.token == token::OpenDelim(token::Paren) { - let body = VariantData::Tuple(try!(self.parse_tuple_struct_body()), ast::DUMMY_NODE_ID); - generics.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::Semi)); + let body = VariantData::Tuple(self.parse_tuple_struct_body()?, ast::DUMMY_NODE_ID); + generics.where_clause = self.parse_where_clause()?; + self.expect(&token::Semi)?; body } else { let token_str = self.this_token_to_string(); @@ -5151,7 +5151,7 @@ impl<'a> Parser<'a> { let mut fields = Vec::new(); if self.eat(&token::OpenDelim(token::Brace)) { while self.token != token::CloseDelim(token::Brace) { - fields.push(try!(self.parse_struct_decl_field())); + fields.push(self.parse_struct_decl_field()?); } self.bump(); @@ -5168,21 +5168,21 @@ impl<'a> Parser<'a> { pub fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec> { // This is the case where we find `struct Foo(T) where T: Copy;` // Unit like structs are handled in parse_item_struct function - let fields = try!(self.parse_unspanned_seq( + let fields = self.parse_unspanned_seq( &token::OpenDelim(token::Paren), &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), |p| { - let attrs = try!(p.parse_outer_attributes()); + let attrs = p.parse_outer_attributes()?; let lo = p.span.lo; let struct_field_ = ast::StructField_ { - kind: UnnamedField(try!(p.parse_visibility())), + kind: UnnamedField(p.parse_visibility()?), id: ast::DUMMY_NODE_ID, - ty: try!(p.parse_ty_sum()), + ty: p.parse_ty_sum()?, attrs: attrs, }; Ok(spanned(lo, p.span.hi, struct_field_)) - })); + })?; Ok(fields) } @@ -5192,7 +5192,7 @@ impl<'a> Parser<'a> { vis: Visibility, attrs: Vec ) -> PResult<'a, StructField> { - let a_var = try!(self.parse_name_and_ty(vis, attrs)); + let a_var = self.parse_name_and_ty(vis, attrs)?; match self.token { token::Comma => { self.bump(); @@ -5213,7 +5213,7 @@ impl<'a> Parser<'a> { /// Parse an element of a struct definition fn parse_struct_decl_field(&mut self) -> PResult<'a, StructField> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; if self.eat_keyword(keywords::Pub) { return self.parse_single_struct_field(Visibility::Public, attrs); @@ -5240,7 +5240,7 @@ impl<'a> Parser<'a> { /// Given a termination token, parse all of the items in a module fn parse_mod_items(&mut self, term: &token::Token, inner_lo: BytePos) -> PResult<'a, Mod> { let mut items = vec![]; - while let Some(item) = try!(self.parse_item()) { + while let Some(item) = self.parse_item()? { items.push(item); } @@ -5262,12 +5262,12 @@ impl<'a> Parser<'a> { } fn parse_item_const(&mut self, m: Option) -> PResult<'a, ItemInfo> { - let id = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); - try!(self.expect(&token::Eq)); - let e = try!(self.parse_expr()); - try!(self.commit_expr_expecting(&e, token::Semi)); + let id = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; + self.expect(&token::Eq)?; + let e = self.parse_expr()?; + self.commit_expr_expecting(&e, token::Semi)?; let item = match m { Some(m) => ItemKind::Static(ty, m, e), None => ItemKind::Const(ty, e), @@ -5278,18 +5278,18 @@ impl<'a> Parser<'a> { /// Parse a `mod { ... }` or `mod ;` item fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> { let id_span = self.span; - let id = try!(self.parse_ident()); + let id = self.parse_ident()?; if self.check(&token::Semi) { self.bump(); // This mod is in an external file. Let's go get it! - let (m, attrs) = try!(self.eval_src_mod(id, outer_attrs, id_span)); + let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span)?; Ok((id, m, Some(attrs))) } else { self.push_mod_path(id, outer_attrs); - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; let mod_inner_lo = self.span.lo; - let attrs = try!(self.parse_inner_attributes()); - let m = try!(self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)); + let attrs = self.parse_inner_attributes()?; + let m = self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)?; self.pop_mod_path(); Ok((id, ItemKind::Mod(m), Some(attrs))) } @@ -5408,9 +5408,9 @@ impl<'a> Parser<'a> { outer_attrs: &[ast::Attribute], id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec )> { - let ModulePathSuccess { path, owns_directory } = try!(self.submod_path(id, + let ModulePathSuccess { path, owns_directory } = self.submod_path(id, outer_attrs, - id_sp)); + id_sp)?; self.eval_src_mod_from_path(path, owns_directory, @@ -5447,8 +5447,8 @@ impl<'a> Parser<'a> { Some(name), id_sp); let mod_inner_lo = p0.span.lo; - let mod_attrs = try!(p0.parse_inner_attributes()); - let m0 = try!(p0.parse_mod_items(&token::Eof, mod_inner_lo)); + let mod_attrs = p0.parse_inner_attributes()?; + let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?; self.sess.included_mod_stack.borrow_mut().pop(); Ok((ast::ItemKind::Mod(m0), mod_attrs)) } @@ -5456,13 +5456,13 @@ impl<'a> Parser<'a> { /// Parse a function declaration from a foreign module fn parse_item_foreign_fn(&mut self, vis: ast::Visibility, lo: BytePos, attrs: Vec) -> PResult<'a, ForeignItem> { - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; - let (ident, mut generics) = try!(self.parse_fn_header()); - let decl = try!(self.parse_fn_decl(true)); - generics.where_clause = try!(self.parse_where_clause()); + let (ident, mut generics) = self.parse_fn_header()?; + let decl = self.parse_fn_decl(true)?; + generics.where_clause = self.parse_where_clause()?; let hi = self.span.hi; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; Ok(ast::ForeignItem { ident: ident, attrs: attrs, @@ -5476,14 +5476,14 @@ impl<'a> Parser<'a> { /// Parse a static item from a foreign module fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: BytePos, attrs: Vec) -> PResult<'a, ForeignItem> { - try!(self.expect_keyword(keywords::Static)); + self.expect_keyword(keywords::Static)?; let mutbl = self.eat_keyword(keywords::Mut); - let ident = try!(self.parse_ident()); - try!(self.expect(&token::Colon)); - let ty = try!(self.parse_ty_sum()); + let ident = self.parse_ident()?; + self.expect(&token::Colon)?; + let ty = self.parse_ty_sum()?; let hi = self.span.hi; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; Ok(ForeignItem { ident: ident, attrs: attrs, @@ -5506,13 +5506,13 @@ impl<'a> Parser<'a> { attrs: Vec) -> PResult<'a, P> { - let crate_name = try!(self.parse_ident()); - let (maybe_path, ident) = if let Some(ident) = try!(self.parse_rename()) { + let crate_name = self.parse_ident()?; + let (maybe_path, ident) = if let Some(ident) = self.parse_rename()? { (Some(crate_name.name), ident) } else { (None, crate_name) }; - try!(self.expect(&token::Semi)); + self.expect(&token::Semi)?; let last_span = self.last_span; Ok(self.mk_item(lo, @@ -5539,17 +5539,17 @@ impl<'a> Parser<'a> { visibility: Visibility, mut attrs: Vec) -> PResult<'a, P> { - try!(self.expect(&token::OpenDelim(token::Brace))); + self.expect(&token::OpenDelim(token::Brace))?; let abi = opt_abi.unwrap_or(Abi::C); - attrs.extend(try!(self.parse_inner_attributes())); + attrs.extend(self.parse_inner_attributes()?); let mut foreign_items = vec![]; - while let Some(item) = try!(self.parse_foreign_item()) { + while let Some(item) = self.parse_foreign_item()? { foreign_items.push(item); } - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; let last_span = self.last_span; let m = ast::ForeignMod { @@ -5566,12 +5566,12 @@ impl<'a> Parser<'a> { /// Parse type Foo = Bar; fn parse_item_type(&mut self) -> PResult<'a, ItemInfo> { - let ident = try!(self.parse_ident()); - let mut tps = try!(self.parse_generics()); - tps.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::Eq)); - let ty = try!(self.parse_ty_sum()); - try!(self.expect(&token::Semi)); + let ident = self.parse_ident()?; + let mut tps = self.parse_generics()?; + tps.where_clause = self.parse_where_clause()?; + self.expect(&token::Eq)?; + let ty = self.parse_ty_sum()?; + self.expect(&token::Semi)?; Ok((ident, ItemKind::Ty(ty, tps), None)) } @@ -5581,23 +5581,23 @@ impl<'a> Parser<'a> { let mut all_nullary = true; let mut any_disr = None; while self.token != token::CloseDelim(token::Brace) { - let variant_attrs = try!(self.parse_outer_attributes()); + let variant_attrs = self.parse_outer_attributes()?; let vlo = self.span.lo; let struct_def; let mut disr_expr = None; - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; if self.check(&token::OpenDelim(token::Brace)) { // Parse a struct variant. all_nullary = false; - struct_def = VariantData::Struct(try!(self.parse_record_struct_body()), + struct_def = VariantData::Struct(self.parse_record_struct_body()?, ast::DUMMY_NODE_ID); } else if self.check(&token::OpenDelim(token::Paren)) { all_nullary = false; - struct_def = VariantData::Tuple(try!(self.parse_tuple_struct_body()), + struct_def = VariantData::Tuple(self.parse_tuple_struct_body()?, ast::DUMMY_NODE_ID); } else if self.eat(&token::Eq) { - disr_expr = Some(try!(self.parse_expr())); + disr_expr = Some(self.parse_expr()?); any_disr = disr_expr.as_ref().map(|expr| expr.span); struct_def = VariantData::Unit(ast::DUMMY_NODE_ID); } else { @@ -5614,7 +5614,7 @@ impl<'a> Parser<'a> { if !self.eat(&token::Comma) { break; } } - try!(self.expect(&token::CloseDelim(token::Brace))); + self.expect(&token::CloseDelim(token::Brace))?; match any_disr { Some(disr_span) if !all_nullary => self.span_err(disr_span, @@ -5627,12 +5627,12 @@ impl<'a> Parser<'a> { /// Parse an "enum" declaration fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> { - let id = try!(self.parse_ident()); - let mut generics = try!(self.parse_generics()); - generics.where_clause = try!(self.parse_where_clause()); - try!(self.expect(&token::OpenDelim(token::Brace))); + let id = self.parse_ident()?; + let mut generics = self.parse_generics()?; + generics.where_clause = self.parse_where_clause()?; + self.expect(&token::OpenDelim(token::Brace))?; - let enum_definition = try!(self.parse_enum_def(&generics)); + let enum_definition = self.parse_enum_def(&generics)?; Ok((id, ItemKind::Enum(enum_definition, generics), None)) } @@ -5687,12 +5687,12 @@ impl<'a> Parser<'a> { let lo = self.span.lo; - let visibility = try!(self.parse_visibility()); + let visibility = self.parse_visibility()?; if self.eat_keyword(keywords::Use) { // USE ITEM - let item_ = ItemKind::Use(try!(self.parse_view_path())); - try!(self.expect(&token::Semi)); + let item_ = ItemKind::Use(self.parse_view_path()?); + self.expect(&token::Semi)?; let last_span = self.last_span; let item = self.mk_item(lo, @@ -5706,16 +5706,16 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Extern) { if self.eat_keyword(keywords::Crate) { - return Ok(Some(try!(self.parse_item_extern_crate(lo, visibility, attrs)))); + return Ok(Some(self.parse_item_extern_crate(lo, visibility, attrs)?)); } - let opt_abi = try!(self.parse_opt_abi()); + let opt_abi = self.parse_opt_abi()?; if self.eat_keyword(keywords::Fn) { // EXTERN FUNCTION ITEM let abi = opt_abi.unwrap_or(Abi::C); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi)); + self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5725,10 +5725,10 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(Some(item)); } else if self.check(&token::OpenDelim(token::Brace)) { - return Ok(Some(try!(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs)))); + return Ok(Some(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs)?)); } - try!(self.unexpected()); + self.unexpected()?; } if self.eat_keyword(keywords::Static) { @@ -5738,7 +5738,7 @@ impl<'a> Parser<'a> { } else { Mutability::Immutable }; - let (ident, item_, extra_attrs) = try!(self.parse_item_const(Some(m))); + let (ident, item_, extra_attrs) = self.parse_item_const(Some(m))?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5760,7 +5760,7 @@ impl<'a> Parser<'a> { }; self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(unsafety, Constness::Const, Abi::Rust)); + self.parse_item_fn(unsafety, Constness::Const, Abi::Rust)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5778,7 +5778,7 @@ impl<'a> Parser<'a> { .fileline_help(last_span, "did you mean to declare a static?") .emit(); } - let (ident, item_, extra_attrs) = try!(self.parse_item_const(None)); + let (ident, item_, extra_attrs) = self.parse_item_const(None)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5792,10 +5792,10 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_keyword(keywords::Trait)) { // UNSAFE TRAIT ITEM - try!(self.expect_keyword(keywords::Unsafe)); - try!(self.expect_keyword(keywords::Trait)); + self.expect_keyword(keywords::Unsafe)?; + self.expect_keyword(keywords::Trait)?; let (ident, item_, extra_attrs) = - try!(self.parse_item_trait(ast::Unsafety::Unsafe)); + self.parse_item_trait(ast::Unsafety::Unsafe)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5809,9 +5809,9 @@ impl<'a> Parser<'a> { self.look_ahead(1, |t| t.is_keyword(keywords::Impl)) { // IMPL ITEM - try!(self.expect_keyword(keywords::Unsafe)); - try!(self.expect_keyword(keywords::Impl)); - let (ident, item_, extra_attrs) = try!(self.parse_item_impl(ast::Unsafety::Unsafe)); + self.expect_keyword(keywords::Unsafe)?; + self.expect_keyword(keywords::Impl)?; + let (ident, item_, extra_attrs) = self.parse_item_impl(ast::Unsafety::Unsafe)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5825,7 +5825,7 @@ impl<'a> Parser<'a> { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)); + self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5840,13 +5840,13 @@ impl<'a> Parser<'a> { // UNSAFE FUNCTION ITEM self.bump(); let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(Abi::C) + self.parse_opt_abi()?.unwrap_or(Abi::C) } else { Abi::Rust }; - try!(self.expect_keyword(keywords::Fn)); + self.expect_keyword(keywords::Fn)?; let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi)); + self.parse_item_fn(Unsafety::Unsafe, Constness::NotConst, abi)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5859,7 +5859,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Mod) { // MODULE ITEM let (ident, item_, extra_attrs) = - try!(self.parse_item_mod(&attrs[..])); + self.parse_item_mod(&attrs[..])?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5871,7 +5871,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Type) { // TYPE ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_type()); + let (ident, item_, extra_attrs) = self.parse_item_type()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5883,7 +5883,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Enum) { // ENUM ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_enum()); + let (ident, item_, extra_attrs) = self.parse_item_enum()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5896,7 +5896,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Trait) { // TRAIT ITEM let (ident, item_, extra_attrs) = - try!(self.parse_item_trait(ast::Unsafety::Normal)); + self.parse_item_trait(ast::Unsafety::Normal)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5908,7 +5908,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Impl) { // IMPL ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_impl(ast::Unsafety::Normal)); + let (ident, item_, extra_attrs) = self.parse_item_impl(ast::Unsafety::Normal)?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5920,7 +5920,7 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Struct) { // STRUCT ITEM - let (ident, item_, extra_attrs) = try!(self.parse_item_struct()); + let (ident, item_, extra_attrs) = self.parse_item_struct()?; let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5935,21 +5935,21 @@ impl<'a> Parser<'a> { /// Parse a foreign item. fn parse_foreign_item(&mut self) -> PResult<'a, Option> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; let lo = self.span.lo; - let visibility = try!(self.parse_visibility()); + let visibility = self.parse_visibility()?; if self.check_keyword(keywords::Static) { // FOREIGN STATIC ITEM - return Ok(Some(try!(self.parse_item_foreign_static(visibility, lo, attrs)))); + return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); } if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { // FOREIGN FUNCTION ITEM - return Ok(Some(try!(self.parse_item_foreign_fn(visibility, lo, attrs)))); + return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); } // FIXME #5668: this will occur for a macro invocation: - match try!(self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)) { + match self.parse_macro_use_or_failure(attrs, true, false, lo, visibility)? { Some(item) => { return Err(self.span_fatal(item.span, "macros cannot expand to foreign items")); } @@ -5979,22 +5979,22 @@ impl<'a> Parser<'a> { let mac_lo = self.span.lo; // item macro. - let pth = try!(self.parse_path(NoTypesAllowed)); - try!(self.expect(&token::Not)); + let pth = self.parse_path(NoTypesAllowed)?; + self.expect(&token::Not)?; // a 'special' identifier (like what `macro_rules!` uses) // is optional. We should eventually unify invoc syntax // and remove this. let id = if self.token.is_plain_ident() { - try!(self.parse_ident()) + self.parse_ident()? } else { token::special_idents::invalid // no special identifier }; // eat a matched-delimiter token tree: - let delim = try!(self.expect_open_delim()); - let tts = try!(self.parse_seq_to_end(&token::CloseDelim(delim), + let delim = self.expect_open_delim()?; + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), SeqSep::none(), - |p| p.parse_token_tree())); + |p| p.parse_token_tree())?; // single-variant-enum... : let m = Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }; let m: ast::Mac = codemap::Spanned { node: m, @@ -6038,7 +6038,7 @@ impl<'a> Parser<'a> { } pub fn parse_item(&mut self) -> PResult<'a, Option>> { - let attrs = try!(self.parse_outer_attributes()); + let attrs = self.parse_outer_attributes()?; self.parse_item_(attrs, true, false) } @@ -6057,11 +6057,11 @@ impl<'a> Parser<'a> { if self.check(&token::OpenDelim(token::Brace)) { // use {foo,bar} - let idents = try!(self.parse_unspanned_seq( + let idents = self.parse_unspanned_seq( &token::OpenDelim(token::Brace), &token::CloseDelim(token::Brace), SeqSep::trailing_allowed(token::Comma), - |p| p.parse_path_list_item())); + |p| p.parse_path_list_item())?; let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -6070,7 +6070,7 @@ impl<'a> Parser<'a> { return Ok(P(spanned(lo, self.span.hi, ViewPathList(path, idents)))); } - let first_ident = try!(self.parse_ident()); + let first_ident = self.parse_ident()?; let mut path = vec!(first_ident); if let token::ModSep = self.token { // foo::bar or foo::{a,b,c} or foo::* @@ -6079,18 +6079,18 @@ impl<'a> Parser<'a> { match self.token { token::Ident(..) => { - let ident = try!(self.parse_ident()); + let ident = self.parse_ident()?; path.push(ident); } // foo::bar::{a,b,c} token::OpenDelim(token::Brace) => { - let idents = try!(self.parse_unspanned_seq( + let idents = self.parse_unspanned_seq( &token::OpenDelim(token::Brace), &token::CloseDelim(token::Brace), SeqSep::trailing_allowed(token::Comma), |p| p.parse_path_list_item() - )); + )?; let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, @@ -6140,7 +6140,7 @@ impl<'a> Parser<'a> { } }).collect() }; - rename_to = try!(self.parse_rename()).unwrap_or(rename_to); + rename_to = self.parse_rename()?.unwrap_or(rename_to); Ok(P(spanned(lo, self.last_span.hi, ViewPathSimple(rename_to, path)))) } @@ -6157,8 +6157,8 @@ impl<'a> Parser<'a> { pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate> { let lo = self.span.lo; Ok(ast::Crate { - attrs: try!(self.parse_inner_attributes()), - module: try!(self.parse_mod_items(&token::Eof, lo)), + attrs: self.parse_inner_attributes()?, + module: self.parse_mod_items(&token::Eof, lo)?, config: self.cfg.clone(), span: mk_sp(lo, self.span.lo), exported_macros: Vec::new(), diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 033ac9440bc..a02a10aa003 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -706,7 +706,7 @@ impl<'a> PartialEq for &'a str { impl Decodable for InternedString { fn decode(d: &mut D) -> Result { - Ok(intern(try!(d.read_str()).as_ref()).as_str()) + Ok(intern(d.read_str()?.as_ref()).as_str()) } } -- cgit 1.4.1-3-g733a5 From 2628f3cc8f91a52d9dcc800afb6c4a7dc0c785e0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 22 Mar 2016 17:58:45 -0500 Subject: fix alignment --- src/compiletest/compiletest.rs | 8 +- src/librustc/middle/def_id.rs | 2 +- src/librustc/middle/infer/combine.rs | 18 +- src/librustc/middle/infer/sub.rs | 4 +- src/librustc/middle/traits/select.rs | 16 +- src/librustc/middle/ty/relate.rs | 14 +- src/librustc/mir/repr.rs | 4 +- src/librustc/util/ppaux.rs | 10 +- src/librustc_back/target/mod.rs | 2 +- src/librustc_borrowck/borrowck/mir/graphviz.rs | 42 ++-- src/librustc_driver/driver.rs | 32 +-- src/librustc_front/print/pprust.rs | 106 +++++----- src/librustc_mir/graphviz.rs | 10 +- src/librustc_trans/back/archive.rs | 4 +- src/librustc_trans/trans/consts.rs | 2 +- src/librustc_typeck/astconv.rs | 8 +- src/librustc_typeck/check/dropck.rs | 11 +- src/librustc_typeck/lib.rs | 12 +- src/librustdoc/html/format.rs | 27 ++- src/librustdoc/html/highlight.rs | 5 +- src/librustdoc/html/render.rs | 273 ++++++++++++------------- src/librustdoc/html/toc.rs | 8 +- src/libstd/sys/common/net.rs | 12 +- src/libstd/sys/unix/ext/net.rs | 10 +- src/libstd/sys/unix/os.rs | 12 +- src/libstd/sys/unix/process.rs | 2 +- src/libstd/sys/windows/fs.rs | 2 +- src/libstd/sys/windows/process.rs | 4 +- src/libsyntax/codemap.rs | 130 ++++++------ src/libsyntax/errors/emitter.rs | 24 +-- src/libsyntax/parse/parser.rs | 41 ++-- src/libsyntax/print/pprust.rs | 76 ++++--- src/tools/error_index_generator/main.rs | 4 +- src/tools/rustbook/build.rs | 8 +- 34 files changed, 464 insertions(+), 479 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index d98055edf85..95838e03d23 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -312,10 +312,10 @@ fn collect_tests_from_dir(config: &Config, } else if file_path.is_dir() { let relative_file_path = relative_dir_path.join(file.file_name()); collect_tests_from_dir(config, - base, - &file_path, - &relative_file_path, - tests)?; + base, + &file_path, + relative_file_path, + tests)?; } } Ok(()) diff --git a/src/librustc/middle/def_id.rs b/src/librustc/middle/def_id.rs index 98fdcc65835..f5bdf28a4b1 100644 --- a/src/librustc/middle/def_id.rs +++ b/src/librustc/middle/def_id.rs @@ -56,7 +56,7 @@ pub struct DefId { impl fmt::Debug for DefId { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "DefId {{ krate: {:?}, node: {:?}", - self.krate, self.index)?; + self.krate, self.index)?; // Unfortunately, there seems to be no way to attempt to print // a path for a def-id, so I'll just make a best effort for now diff --git a/src/librustc/middle/infer/combine.rs b/src/librustc/middle/infer/combine.rs index cbb5586f720..f67389e3c3b 100644 --- a/src/librustc/middle/infer/combine.rs +++ b/src/librustc/middle/infer/combine.rs @@ -71,9 +71,9 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>, // Relate integral variables to other types (&ty::TyInfer(ty::IntVar(a_id)), &ty::TyInfer(ty::IntVar(b_id))) => { infcx.int_unification_table - .borrow_mut() - .unify_var_var(a_id, b_id) - .map_err(|e| int_unification_error(a_is_expected, e))?; + .borrow_mut() + .unify_var_var(a_id, b_id) + .map_err(|e| int_unification_error(a_is_expected, e))?; Ok(a) } (&ty::TyInfer(ty::IntVar(v_id)), &ty::TyInt(v)) => { @@ -92,9 +92,9 @@ pub fn super_combine_tys<'a,'tcx:'a,R>(infcx: &InferCtxt<'a, 'tcx>, // Relate floating-point variables to other types (&ty::TyInfer(ty::FloatVar(a_id)), &ty::TyInfer(ty::FloatVar(b_id))) => { infcx.float_unification_table - .borrow_mut() - .unify_var_var(a_id, b_id) - .map_err(|e| float_unification_error(relation.a_is_expected(), e))?; + .borrow_mut() + .unify_var_var(a_id, b_id) + .map_err(|e| float_unification_error(relation.a_is_expected(), e))?; Ok(a) } (&ty::TyInfer(ty::FloatVar(v_id)), &ty::TyFloat(v)) => { @@ -123,8 +123,7 @@ fn unify_integral_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, val: ty::IntVarValue) -> RelateResult<'tcx, Ty<'tcx>> { - infcx - .int_unification_table + infcx.int_unification_table .borrow_mut() .unify_var_value(vid, val) .map_err(|e| int_unification_error(vid_is_expected, e))?; @@ -140,8 +139,7 @@ fn unify_float_variable<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, val: ast::FloatTy) -> RelateResult<'tcx, Ty<'tcx>> { - infcx - .float_unification_table + infcx.float_unification_table .borrow_mut() .unify_var_value(vid, val) .map_err(|e| float_unification_error(vid_is_expected, e))?; diff --git a/src/librustc/middle/infer/sub.rs b/src/librustc/middle/infer/sub.rs index 34b9953c529..e94311697c3 100644 --- a/src/librustc/middle/infer/sub.rs +++ b/src/librustc/middle/infer/sub.rs @@ -76,8 +76,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> { } (&ty::TyInfer(TyVar(a_id)), _) => { self.fields - .switch_expected() - .instantiate(b, SupertypeOf, a_id)?; + .switch_expected() + .instantiate(b, SupertypeOf, a_id)?; Ok(a) } (_, &ty::TyInfer(TyVar(b_id))) => { diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index ffef509de95..3eaf123e5be 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1038,15 +1038,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // For other types, we'll use the builtin rules. self.assemble_builtin_bound_candidates(ty::BoundCopy, - obligation, - &mut candidates)?; + obligation, + &mut candidates)?; } Some(bound @ ty::BoundSized) => { // Sized is never implementable by end-users, it is // always automatically computed. self.assemble_builtin_bound_candidates(bound, - obligation, - &mut candidates)?; + obligation, + &mut candidates)?; } None if self.tcx().lang_items.unsize_trait() == @@ -2422,8 +2422,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_bound(|(trait_ref, _)| trait_ref); self.confirm_poly_trait_refs(obligation.cause.clone(), - obligation.predicate.to_poly_trait_ref(), - trait_ref)?; + obligation.predicate.to_poly_trait_ref(), + trait_ref)?; Ok(self_ty) } @@ -2450,8 +2450,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { obligations); self.confirm_poly_trait_refs(obligation.cause.clone(), - obligation.predicate.to_poly_trait_ref(), - trait_ref)?; + obligation.predicate.to_poly_trait_ref(), + trait_ref)?; Ok(VtableClosureData { closure_def_id: closure_def_id, diff --git a/src/librustc/middle/ty/relate.rs b/src/librustc/middle/ty/relate.rs index b67fee7239b..1df7a440f4f 100644 --- a/src/librustc/middle/ty/relate.rs +++ b/src/librustc/middle/ty/relate.rs @@ -167,9 +167,9 @@ pub fn relate_substs<'a,'tcx:'a,R>(relation: &mut R, let b_regions = b.get_slice(space); let r_variances = variances.map(|v| v.regions.get_slice(space)); let regions = relate_region_params(relation, - r_variances, - a_regions, - b_regions)?; + r_variances, + a_regions, + b_regions)?; substs.mut_regions().replace(space, regions); } } @@ -261,8 +261,8 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::FnSig<'tcx> { } let inputs = relate_arg_vecs(relation, - &a.inputs, - &b.inputs)?; + &a.inputs, + &b.inputs)?; let output = match (a.output, b.output) { (ty::FnConverging(a_ty), ty::FnConverging(b_ty)) => @@ -557,8 +557,8 @@ pub fn super_relate_tys<'a,'tcx:'a,R>(relation: &mut R, { if as_.len() == bs.len() { let ts = as_.iter().zip(bs) - .map(|(a, b)| relation.relate(a, b)) - .collect::>()?; + .map(|(a, b)| relation.relate(a, b)) + .collect::>()?; Ok(tcx.mk_tup(ts)) } else if !(as_.is_empty() || bs.is_empty()) { Err(TypeError::TupleSize( diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index 8c4a91bd88d..ff3e292f458 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -809,8 +809,8 @@ impl<'tcx> Debug for Rvalue<'tcx> { let variant_def = &adt_def.variants[variant]; ppaux::parameterized(fmt, substs, variant_def.did, - ppaux::Ns::Value, &[], - |tcx| { + ppaux::Ns::Value, &[], + |tcx| { tcx.lookup_item_type(variant_def.did).generics })?; diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index cdf8912a3c4..64619e40f49 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -123,8 +123,8 @@ pub fn parameterized(f: &mut fmt::Formatter, for projection in projections { start_or_continue(f, "<", ", ")?; write!(f, "{}={}", - projection.projection_ty.item_name, - projection.ty)?; + projection.projection_ty.item_name, + projection.ty)?; } return start_or_continue(f, "", ">"); } @@ -201,8 +201,8 @@ pub fn parameterized(f: &mut fmt::Formatter, for projection in projections { start_or_continue(f, "<", ", ")?; write!(f, "{}={}", - projection.projection_ty.item_name, - projection.ty)?; + projection.projection_ty.item_name, + projection.ty)?; } start_or_continue(f, "", ">")?; @@ -865,7 +865,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { write!(f, "{} {{", bare_fn.sig.0)?; parameterized(f, substs, def_id, Ns::Value, &[], - |tcx| tcx.lookup_item_type(def_id).generics)?; + |tcx| tcx.lookup_item_type(def_id).generics)?; write!(f, "}}") } TyFnPtr(ref bare_fn) => { diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 3fc19f9bed5..a8eac524971 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -468,7 +468,7 @@ impl Target { let mut contents = Vec::new(); f.read_to_end(&mut contents).map_err(|e| e.to_string())?; let obj = json::from_reader(&mut &contents[..]) - .map_err(|e| e.to_string())?; + .map_err(|e| e.to_string())?; Ok(Target::from_json(obj)) } diff --git a/src/librustc_borrowck/borrowck/mir/graphviz.rs b/src/librustc_borrowck/borrowck/mir/graphviz.rs index b1d3b215ab4..460c71dee3d 100644 --- a/src/librustc_borrowck/borrowck/mir/graphviz.rs +++ b/src/librustc_borrowck/borrowck/mir/graphviz.rs @@ -124,15 +124,15 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { write!(w, "")?; } write!(w, "{objs:?}", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT, - objs = c)?; + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT, + objs = c)?; seen_one = true; } if !seen_one { write!(w, "[]", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT)?; + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT)?; } Ok(()) } @@ -155,18 +155,18 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { let kill = flow.interpret_set(flow.sets.kill_set_for(i)); chunked_present_left(w, &gen[..], chunk_size)?; write!(w, " = GEN:{genbits:?}\ - ", - bg = BG_FLOWCONTENT, - face = FACE_MONOSPACE, - genbits=bits_to_string( flow.sets.gen_set_for(i), - flow.sets.bytes_per_block()))?; + ", + bg = BG_FLOWCONTENT, + face = FACE_MONOSPACE, + genbits=bits_to_string( flow.sets.gen_set_for(i), + flow.sets.bytes_per_block()))?; write!(w, "KILL:\ - {killbits:?}", - bg = BG_FLOWCONTENT, - align = ALIGN_RIGHT, - face = FACE_MONOSPACE, - killbits=bits_to_string(flow.sets.kill_set_for(i), - flow.sets.bytes_per_block()))?; + {killbits:?}", + bg = BG_FLOWCONTENT, + align = ALIGN_RIGHT, + face = FACE_MONOSPACE, + killbits=bits_to_string(flow.sets.kill_set_for(i), + flow.sets.bytes_per_block()))?; // (chunked_present_right) let mut seen_one = false; @@ -174,19 +174,19 @@ impl<'c, 'b:'c, 'a:'b, 'tcx:'a> dot::Labeller<'c> for Graph<'c,'b,'a,'tcx> { if !seen_one { // continuation of row; this is fourth write!(w, "= {kill:?}", - bg = BG_FLOWCONTENT, - kill=k)?; + bg = BG_FLOWCONTENT, + kill=k)?; } else { // new row, with indent of three 's write!(w, "{kill:?}", - bg = BG_FLOWCONTENT, - kill=k)?; + bg = BG_FLOWCONTENT, + kill=k)?; } seen_one = true; } if !seen_one { write!(w, "= []", - bg = BG_FLOWCONTENT)?; + bg = BG_FLOWCONTENT)?; } Ok(()) diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index c64e6d1801d..55b873c0663 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -100,10 +100,10 @@ pub fn compile_input(sess: &Session, let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess); let id = link::find_crate_name(Some(sess), &krate.attrs, input); let expanded_crate = phase_2_configure_and_expand(sess, - &cstore, - krate, - &id[..], - addl_plugins)?; + &cstore, + krate, + &id[..], + addl_plugins)?; (outputs, expanded_crate, id) }; @@ -169,12 +169,12 @@ pub fn compile_input(sess: &Session, }; phase_3_run_analysis_passes(sess, - &cstore, - hir_map, - &arenas, - &id, - control.make_glob_map, - |tcx, mir_map, analysis, result| { + &cstore, + hir_map, + &arenas, + &id, + control.make_glob_map, + |tcx, mir_map, analysis, result| { { // Eventually, we will want to track plugins. let _ignore = tcx.dep_graph.in_ignore(); @@ -683,8 +683,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, })?; time(time_passes, - "const fn bodies and arguments", - || const_fn::check_crate(sess, &krate))?; + "const fn bodies and arguments", + || const_fn::check_crate(sess, &krate))?; if sess.opts.debugging_opts.input_stats { println!("Post-expansion node count: {}", count_nodes(&krate)); @@ -781,10 +781,10 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session, }; let named_region_map = time(time_passes, - "lifetime resolution", - || middle::resolve_lifetime::krate(sess, - &hir_map, - &def_map.borrow()))?; + "lifetime resolution", + || middle::resolve_lifetime::krate(sess, + &hir_map, + &def_map.borrow()))?; time(time_passes, "looking for entry point", diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index a647ba8b57c..3b8e6763de0 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -288,13 +288,13 @@ pub fn fun_to_string(decl: &hir::FnDecl, to_string(|s| { s.head("")?; s.print_fn(decl, - unsafety, - constness, - Abi::Rust, - Some(name), - generics, - opt_explicit_self, - hir::Inherited)?; + unsafety, + constness, + Abi::Rust, + Some(name), + generics, + opt_explicit_self, + hir::Inherited)?; s.end()?; // Close the head box s.end() // Close the outer box }) @@ -567,13 +567,13 @@ impl<'a> State<'a> { hir::ForeignItemFn(ref decl, ref generics) => { self.head("")?; self.print_fn(decl, - hir::Unsafety::Normal, - hir::Constness::NotConst, - Abi::Rust, - Some(item.name), - generics, - None, - item.vis)?; + hir::Unsafety::Normal, + hir::Constness::NotConst, + Abi::Rust, + Some(item.name), + generics, + None, + item.vis)?; self.end()?; // end head-ibox word(&mut self.s, ";")?; self.end() // end the outer fn box @@ -704,13 +704,13 @@ impl<'a> State<'a> { hir::ItemFn(ref decl, unsafety, constness, abi, ref typarams, ref body) => { self.head("")?; self.print_fn(decl, - unsafety, - constness, - abi, - Some(item.name), - typarams, - None, - item.vis)?; + unsafety, + constness, + abi, + Some(item.name), + typarams, + None, + item.vis)?; word(&mut self.s, " ")?; self.print_block_with_attrs(&body, &item.attrs)?; } @@ -984,9 +984,9 @@ impl<'a> State<'a> { match ti.node { hir::ConstTraitItem(ref ty, ref default) => { self.print_associated_const(ti.name, - &ty, - default.as_ref().map(|expr| &**expr), - hir::Inherited)?; + &ty, + default.as_ref().map(|expr| &**expr), + hir::Inherited)?; } hir::MethodTraitItem(ref sig, ref body) => { if body.is_some() { @@ -1002,8 +1002,8 @@ impl<'a> State<'a> { } hir::TypeTraitItem(ref bounds, ref default) => { self.print_associated_type(ti.name, - Some(bounds), - default.as_ref().map(|ty| &**ty))?; + Some(bounds), + default.as_ref().map(|ty| &**ty))?; } } self.ann.post(self, NodeSubItem(ti.id)) @@ -1219,15 +1219,15 @@ impl<'a> State<'a> { self.print_path(path, true, 0)?; word(&mut self.s, "{")?; self.commasep_cmnt(Consistent, - &fields[..], - |s, field| { - s.ibox(indent_unit)?; - s.print_name(field.name.node)?; - s.word_space(":")?; - s.print_expr(&field.expr)?; - s.end() - }, - |f| f.span)?; + &fields[..], + |s, field| { + s.ibox(indent_unit)?; + s.print_name(field.name.node)?; + s.word_space(":")?; + s.print_expr(&field.expr)?; + s.end() + }, + |f| f.span)?; match *wth { Some(ref expr) => { self.ibox(indent_unit)?; @@ -1760,17 +1760,17 @@ impl<'a> State<'a> { self.nbsp()?; self.word_space("{")?; self.commasep_cmnt(Consistent, - &fields[..], - |s, f| { - s.cbox(indent_unit)?; - if !f.node.is_shorthand { - s.print_name(f.node.name)?; - s.word_nbsp(":")?; - } - s.print_pat(&f.node.pat)?; - s.end() - }, - |f| f.node.pat.span)?; + &fields[..], + |s, f| { + s.cbox(indent_unit)?; + if !f.node.is_shorthand { + s.print_name(f.node.name)?; + s.word_nbsp(":")?; + } + s.print_pat(&f.node.pat)?; + s.end() + }, + |f| f.node.pat.span)?; if etc { if !fields.is_empty() { self.word_space(",")?; @@ -2261,13 +2261,13 @@ impl<'a> State<'a> { }, }; self.print_fn(decl, - unsafety, - hir::Constness::NotConst, - abi, - name, - &generics, - opt_explicit_self, - hir::Inherited)?; + unsafety, + hir::Constness::NotConst, + abi, + name, + &generics, + opt_explicit_self, + hir::Inherited)?; self.end() } diff --git a/src/librustc_mir/graphviz.rs b/src/librustc_mir/graphviz.rs index 349d8e786c4..953eb724f50 100644 --- a/src/librustc_mir/graphviz.rs +++ b/src/librustc_mir/graphviz.rs @@ -65,9 +65,9 @@ pub fn write_node_label(block: BasicBlock, // Basic block number at the top. write!(w, r#"{blk}"#, - attrs=r#"bgcolor="gray" align="center""#, - colspan=num_cols, - blk=block.index())?; + attrs=r#"bgcolor="gray" align="center""#, + colspan=num_cols, + blk=block.index())?; init(w)?; @@ -145,13 +145,13 @@ fn write_graph_label(tcx: &ty::TyCtxt, nid: NodeId, mir: &Mir, w: &mut write!(w, "mut ")?; } write!(w, r#"{:?}: {}; // {}
"#, - Lvalue::Var(i as u32), escape(&var.ty), var.name)?; + Lvalue::Var(i as u32), escape(&var.ty), var.name)?; } // Compiler-introduced temporary types. for (i, temp) in mir.temp_decls.iter().enumerate() { write!(w, r#"let mut {:?}: {};
"#, - Lvalue::Temp(i as u32), escape(&temp.ty))?; + Lvalue::Temp(i as u32), escape(&temp.ty))?; } writeln!(w, ">;") diff --git a/src/librustc_trans/back/archive.rs b/src/librustc_trans/back/archive.rs index f5b48081010..514fc52d008 100644 --- a/src/librustc_trans/back/archive.rs +++ b/src/librustc_trans/back/archive.rs @@ -255,7 +255,7 @@ impl<'a> ArchiveBuilder<'a> { // permission bits. if let Some(ref s) = self.config.src { io::copy(&mut File::open(s)?, - &mut File::create(&self.config.dst)?)?; + &mut File::create(&self.config.dst)?)?; } if removals.len() > 0 { @@ -272,7 +272,7 @@ impl<'a> ArchiveBuilder<'a> { } Addition::Archive { archive, archive_name, mut skip } => { self.add_archive_members(&mut members, archive, - &archive_name, &mut *skip)?; + &archive_name, &mut *skip)?; } } } diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 12bcd34a663..dd6856916f6 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -976,7 +976,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let method_call = ty::MethodCall::expr(e.id); let method = cx.tcx().tables.borrow().method_map[&method_call]; const_fn_call(cx, method.def_id, method.substs.clone(), - &arg_vals, param_substs, trueconst)? + &arg_vals, param_substs, trueconst)? }, hir::ExprType(ref e, _) => const_expr(cx, &e, param_substs, fn_args, trueconst)?.0, hir::ExprBlock(ref block) => { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 0cc1fb9e1c7..67bd79bb57e 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -954,10 +954,10 @@ fn ast_type_binding_to_poly_projection_predicate<'tcx>( } let candidate = one_bound_for_assoc_type(tcx, - candidates, - &trait_ref.to_string(), - &binding.item_name.as_str(), - binding.span)?; + candidates, + &trait_ref.to_string(), + &binding.item_name.as_str(), + binding.span)?; Ok(ty::Binder(ty::ProjectionPredicate { // <-------------------------+ projection_ty: ty::ProjectionTy { // | diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index c79a35b2f33..7dd5db831fd 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -47,10 +47,10 @@ pub fn check_drop_impl(tcx: &TyCtxt, drop_impl_did: DefId) -> Result<(), ()> { ty::TyEnum(adt_def, self_to_impl_substs) | ty::TyStruct(adt_def, self_to_impl_substs) => { ensure_drop_params_and_item_params_correspond(tcx, - drop_impl_did, - dtor_generics, - &dtor_self_type, - adt_def.did)?; + drop_impl_did, + dtor_generics, + &dtor_self_type, + adt_def.did)?; ensure_drop_predicates_are_implied_by_item_defn(tcx, drop_impl_did, @@ -469,8 +469,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>( ty::TyTuple(ref tys) | ty::TyClosure(_, box ty::ClosureSubsts { upvar_tys: ref tys, .. }) => { for ty in tys { - iterate_over_potentially_unsafe_regions_in_type( - cx, context, ty, depth+1)? + iterate_over_potentially_unsafe_regions_in_type(cx, context, ty, depth+1)? } Ok(()) } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 07e5ad6fb44..4e1f3d3cbb7 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -354,17 +354,13 @@ pub fn check_crate(tcx: &TyCtxt, trait_map: ty::TraitMap) -> CompileResult { coherence::check_coherence(&ccx)); })?; - time(time_passes, "wf checking", || - check::check_wf_new(&ccx))?; + time(time_passes, "wf checking", || check::check_wf_new(&ccx))?; - time(time_passes, "item-types checking", || - check::check_item_types(&ccx))?; + time(time_passes, "item-types checking", || check::check_item_types(&ccx))?; - time(time_passes, "item-bodies checking", || - check::check_item_bodies(&ccx))?; + time(time_passes, "item-bodies checking", || check::check_item_bodies(&ccx))?; - time(time_passes, "drop-impl checking", || - check::check_drop_impls(&ccx))?; + time(time_passes, "drop-impl checking", || check::check_drop_impls(&ccx))?; check_for_entry_fn(&ccx); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index f666a0a1017..e9a883d6d7a 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -344,9 +344,9 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, root.push_str(&seg.name); root.push_str("/"); write!(w, "{}::", - root, - seg.name)?; + href='{}index.html'>{}::", + root, + seg.name)?; } } } @@ -361,7 +361,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, match href(did) { Some((url, shortty, fqp)) => { write!(w, "{}", - shortty, url, fqp.join("::"), last.name)?; + shortty, url, fqp.join("::"), last.name)?; } _ => write!(w, "{}", last.name)?, } @@ -379,8 +379,8 @@ fn primitive_link(f: &mut fmt::Formatter, let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len()); let len = if len == 0 {0} else {len - 1}; write!(f, "", - repeat("../").take(len).collect::(), - prim.to_url_str())?; + repeat("../").take(len).collect::(), + prim.to_url_str())?; needs_termination = true; } Some(&cnum) => { @@ -399,9 +399,9 @@ fn primitive_link(f: &mut fmt::Formatter, match loc { Some(root) => { write!(f, "", - root, - path.0.first().unwrap(), - prim.to_url_str())?; + root, + path.0.first().unwrap(), + prim.to_url_str())?; needs_termination = true; } None => {} @@ -490,7 +490,7 @@ impl fmt::Display for clean::Type { } _ => { primitive_link(f, clean::PrimitiveType::PrimitiveRawPointer, - &format!("*{}", RawMutableSpace(m)))?; + &format!("*{}", RawMutableSpace(m)))?; write!(f, "{}", t) } } @@ -508,8 +508,7 @@ impl fmt::Display for clean::Type { primitive_link(f, clean::Slice, &format!("&{}{}[{}]", lt, m, **bt)), _ => { - primitive_link(f, clean::Slice, - &format!("&{}{}[", lt, m))?; + primitive_link(f, clean::Slice, &format!("&{}{}[", lt, m))?; write!(f, "{}", **bt)?; primitive_link(f, clean::Slice, "]") } @@ -567,8 +566,8 @@ impl fmt::Display for clean::Impl { write!(f, "impl{} ", self.generics)?; if let Some(ref ty) = self.trait_ { write!(f, "{}{} for ", - if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" }, - *ty)?; + if self.polarity == Some(clean::ImplPolarity::Negative) { "!" } else { "" }, + *ty)?; } write!(f, "{}{}", self.for_, WhereClause(&self.generics))?; Ok(()) diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 778d34c0080..b3cad90ccb5 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -71,7 +71,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, }, token::Comment => { write!(out, "{}", - Escape(&snip(next.sp)))?; + Escape(&snip(next.sp)))?; continue }, token::Shebang(s) => { @@ -180,8 +180,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, if klass == "" { write!(out, "{}", Escape(&snip))?; } else { - write!(out, "{}", klass, - Escape(&snip))?; + write!(out, "{}", klass, Escape(&snip))?; } } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 689b8bd9395..9e74702e06c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -630,45 +630,45 @@ fn write_shared(cx: &Context, // Add all the static files. These may already exist, but we just // overwrite them anyway to make sure that they're fresh and up-to-date. write(cx.dst.join("jquery.js"), - include_bytes!("static/jquery-2.1.4.min.js"))?; + include_bytes!("static/jquery-2.1.4.min.js"))?; write(cx.dst.join("main.js"), - include_bytes!("static/main.js"))?; + include_bytes!("static/main.js"))?; write(cx.dst.join("playpen.js"), - include_bytes!("static/playpen.js"))?; + include_bytes!("static/playpen.js"))?; write(cx.dst.join("rustdoc.css"), - include_bytes!("static/rustdoc.css"))?; + include_bytes!("static/rustdoc.css"))?; write(cx.dst.join("main.css"), - include_bytes!("static/styles/main.css"))?; + include_bytes!("static/styles/main.css"))?; write(cx.dst.join("normalize.css"), - include_bytes!("static/normalize.css"))?; + include_bytes!("static/normalize.css"))?; write(cx.dst.join("FiraSans-Regular.woff"), - include_bytes!("static/FiraSans-Regular.woff"))?; + include_bytes!("static/FiraSans-Regular.woff"))?; write(cx.dst.join("FiraSans-Medium.woff"), - include_bytes!("static/FiraSans-Medium.woff"))?; + include_bytes!("static/FiraSans-Medium.woff"))?; write(cx.dst.join("FiraSans-LICENSE.txt"), - include_bytes!("static/FiraSans-LICENSE.txt"))?; + include_bytes!("static/FiraSans-LICENSE.txt"))?; write(cx.dst.join("Heuristica-Italic.woff"), - include_bytes!("static/Heuristica-Italic.woff"))?; + include_bytes!("static/Heuristica-Italic.woff"))?; write(cx.dst.join("Heuristica-LICENSE.txt"), - include_bytes!("static/Heuristica-LICENSE.txt"))?; + include_bytes!("static/Heuristica-LICENSE.txt"))?; write(cx.dst.join("SourceSerifPro-Regular.woff"), - include_bytes!("static/SourceSerifPro-Regular.woff"))?; + include_bytes!("static/SourceSerifPro-Regular.woff"))?; write(cx.dst.join("SourceSerifPro-Bold.woff"), - include_bytes!("static/SourceSerifPro-Bold.woff"))?; + include_bytes!("static/SourceSerifPro-Bold.woff"))?; write(cx.dst.join("SourceSerifPro-LICENSE.txt"), - include_bytes!("static/SourceSerifPro-LICENSE.txt"))?; + include_bytes!("static/SourceSerifPro-LICENSE.txt"))?; write(cx.dst.join("SourceCodePro-Regular.woff"), - include_bytes!("static/SourceCodePro-Regular.woff"))?; + include_bytes!("static/SourceCodePro-Regular.woff"))?; write(cx.dst.join("SourceCodePro-Semibold.woff"), - include_bytes!("static/SourceCodePro-Semibold.woff"))?; + include_bytes!("static/SourceCodePro-Semibold.woff"))?; write(cx.dst.join("SourceCodePro-LICENSE.txt"), - include_bytes!("static/SourceCodePro-LICENSE.txt"))?; + include_bytes!("static/SourceCodePro-LICENSE.txt"))?; write(cx.dst.join("LICENSE-MIT.txt"), - include_bytes!("static/LICENSE-MIT.txt"))?; + include_bytes!("static/LICENSE-MIT.txt"))?; write(cx.dst.join("LICENSE-APACHE.txt"), - include_bytes!("static/LICENSE-APACHE.txt"))?; + include_bytes!("static/LICENSE-APACHE.txt"))?; write(cx.dst.join("COPYRIGHT.txt"), - include_bytes!("static/COPYRIGHT.txt"))?; + include_bytes!("static/COPYRIGHT.txt"))?; fn collect(path: &Path, krate: &str, key: &str) -> io::Result> { @@ -925,7 +925,7 @@ impl<'a> SourceCollector<'a> { keywords: BASIC_KEYWORDS, }; layout::render(&mut w, &self.cx.layout, - &page, &(""), &Source(contents))?; + &page, &(""), &Source(contents))?; w.flush()?; self.cx.local_sources.insert(p, href); Ok(()) @@ -1290,8 +1290,8 @@ impl Context { let mut writer = BufWriter::new(w); if !cx.render_redirect_pages { layout::render(&mut writer, &cx.layout, &page, - &Sidebar{ cx: cx, item: it }, - &Item{ cx: cx, item: it })?; + &Sidebar{ cx: cx, item: it }, + &Item{ cx: cx, item: it })?; } else { let mut url = repeat("../").take(cx.current.len()) .collect::(); @@ -1515,22 +1515,22 @@ impl<'a> fmt::Display for Item<'a> { let amt = if self.ismodule() { cur.len() - 1 } else { cur.len() }; for (i, component) in cur.iter().enumerate().take(amt) { write!(fmt, "{}::", - repeat("../").take(cur.len() - i - 1) - .collect::(), - component)?; + repeat("../").take(cur.len() - i - 1) + .collect::(), + component)?; } } write!(fmt, "{}", - shortty(self.item), self.item.name.as_ref().unwrap())?; + shortty(self.item), self.item.name.as_ref().unwrap())?; write!(fmt, "")?; // in-band write!(fmt, "")?; write!(fmt, - r##" - - [] - - "##)?; + r##" + + [] + + "##)?; // Write `src` tag // @@ -1541,8 +1541,8 @@ impl<'a> fmt::Display for Item<'a> { if self.cx.include_sources && !is_primitive { if let Some(l) = self.href() { write!(fmt, "[src]", - self.item.def_id.index.as_usize(), l, "goto source code")?; + href='{}' title='{}'>[src]", + self.item.def_id.index.as_usize(), l, "goto source code")?; } } @@ -1698,8 +1698,8 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, ItemType::AssociatedConst => ("associated-consts", "Associated Constants"), }; write!(w, "

\ - {name}

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

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

Fields

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

Variants

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

Fields

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

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

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

Trait \ - Implementations

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

\ - Derived Implementations \ -

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

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

    {0}

    \n", - err_code)?; + "

    {0}

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