From fb84fc060ead33cbb98698f50cc190e439c7413a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 2 Oct 2018 21:01:30 -0700 Subject: [PATCH] Format with rustfmt 0.99.5-nightly --- src/lit.rs | 32 ++++++++++++++++++-------------- src/lookahead.rs | 12 +++++++----- src/parse.rs | 3 ++- src/spanned.rs | 16 +++++++++++----- tests/common/parse.rs | 3 ++- tests/test_derive_input.rs | 27 ++++++++++++++++++--------- tests/test_generics.rs | 6 ++++-- tests/test_grouping.rs | 6 ++++-- tests/test_meta_item.rs | 15 ++++++++++----- 9 files changed, 76 insertions(+), 44 deletions(-) diff --git a/src/lit.rs b/src/lit.rs index 52d11567..206e319b 100644 --- a/src/lit.rs +++ b/src/lit.rs @@ -656,20 +656,24 @@ mod value { _ => {} }, b'\'' => return Lit::Char(LitChar { token: token }), - b'0'...b'9' => if number_is_int(&value) { - return Lit::Int(LitInt { token: token }); - } else if number_is_float(&value) { - return Lit::Float(LitFloat { token: token }); - } else { - // number overflow - return Lit::Verbatim(LitVerbatim { token: token }); - }, - _ => if value == "true" || value == "false" { - return Lit::Bool(LitBool { - value: value == "true", - span: token.span(), - }); - }, + b'0'...b'9' => { + if number_is_int(&value) { + return Lit::Int(LitInt { token: token }); + } else if number_is_float(&value) { + return Lit::Float(LitFloat { token: token }); + } else { + // number overflow + return Lit::Verbatim(LitVerbatim { token: token }); + } + } + _ => { + if value == "true" || value == "false" { + return Lit::Bool(LitBool { + value: value == "true", + span: token.span(), + }); + } + } } panic!("Unrecognized literal: {}", value); diff --git a/src/lookahead.rs b/src/lookahead.rs index be38a71f..7320d029 100644 --- a/src/lookahead.rs +++ b/src/lookahead.rs @@ -114,11 +114,13 @@ impl<'a> Lookahead1<'a> { pub fn error(self) -> Error { let comparisons = self.comparisons.borrow(); match comparisons.len() { - 0 => if self.cursor.eof() { - Error::new(self.scope, "unexpected end of input") - } else { - Error::new(self.cursor.span(), "unexpected token") - }, + 0 => { + if self.cursor.eof() { + Error::new(self.scope, "unexpected end of input") + } else { + Error::new(self.cursor.span(), "unexpected token") + } + } 1 => { let message = format!("expected {}", comparisons[0]); error::new_at(self.scope, self.cursor, message) diff --git a/src/parse.rs b/src/parse.rs index e9428ed9..8ca7d2ef 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -358,7 +358,8 @@ fn skip(input: ParseStream) -> bool { } else { Ok((false, *cursor)) } - }).unwrap() + }) + .unwrap() } impl private { diff --git a/src/spanned.rs b/src/spanned.rs index 6fbdd99d..767a6a71 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -130,11 +130,14 @@ where fn span(&self) -> Span { let mut tokens = TokenStream::new(); self.to_tokens(&mut tokens); - tokens.into_iter().fold(None::, |span, tt| { - check_invalid_span(tt.span()).map_or(span, |new_span| { - span.map(|span| span.join(new_span).unwrap_or(span)) + tokens + .into_iter() + .fold(None::, |span, tt| { + check_invalid_span(tt.span()).map_or(span, |new_span| { + span.map(|span| span.join(new_span).unwrap_or(span)) + }) }) - }).unwrap_or(Span::call_site()) + .unwrap_or(Span::call_site()) } #[cfg(not(procmacro2_semver_exempt))] @@ -144,7 +147,10 @@ where // We can't join spans without procmacro2_semver_exempt so just grab the // first one. - tokens.into_iter().next().and_then(|tt| check_invalid_span(tt.span())) + tokens + .into_iter() + .next() + .and_then(|tt| check_invalid_span(tt.span())) .unwrap_or(Span::call_site()) } } diff --git a/tests/common/parse.rs b/tests/common/parse.rs index a0cc40c4..1c59f632 100644 --- a/tests/common/parse.rs +++ b/tests/common/parse.rs @@ -29,7 +29,8 @@ pub fn libsyntax_expr(input: &str) -> Option> { &sess, FileName::Custom("test_precedence".to_string()), input.to_string(), - ).parse_expr(); + ) + .parse_expr(); match e { Ok(expr) => Some(expr), Err(mut diagnostic) => { diff --git a/tests/test_derive_input.rs b/tests/test_derive_input.rs index 045e506e..db62f2e1 100644 --- a/tests/test_derive_input.rs +++ b/tests/test_derive_input.rs @@ -102,7 +102,8 @@ fn test_struct() { ty: TypePath { qself: None, path: ident("Ident").into(), - }.into(), + } + .into(), }, Field { ident: Some(ident("attrs")), @@ -132,7 +133,8 @@ fn test_struct() { ), },], }, - }.into(), + } + .into(), }, ], }), @@ -150,7 +152,8 @@ fn test_struct() { NestedMeta::Meta(Meta::Word(ident("Debug"))), NestedMeta::Meta(Meta::Word(ident("Clone"))), ], - }.into(); + } + .into(); assert_eq!( expected_meta_item, @@ -197,7 +200,8 @@ fn test_union() { ty: TypeTuple { paren_token: Default::default(), elems: Punctuated::new(), - }.into(), + } + .into(), }, Field { ident: Some(ident("value")), @@ -207,7 +211,8 @@ fn test_union() { ty: TypePath { qself: None, path: ident("T").into(), - }.into(), + } + .into(), }, ], }, @@ -300,7 +305,8 @@ fn test_enum() { ty: TypePath { qself: None, path: ident("T").into(), - }.into(), + } + .into(), },], }), discriminant: None, @@ -318,7 +324,8 @@ fn test_enum() { ty: TypePath { qself: None, path: ident("E").into(), - }.into(), + } + .into(), },], }), discriminant: None, @@ -387,7 +394,8 @@ fn test_enum() { " See the std::result module documentation for details.", Span::call_site(), )), - }.into(), + } + .into(), Meta::Word(ident("must_use")), ]; @@ -572,7 +580,8 @@ fn test_pub_restricted() { ty: TypePath { qself: None, path: ident("u8").into(), - }.into(), + } + .into(), },], }), semi_token: Some(Default::default()), diff --git a/tests/test_generics.rs b/tests/test_generics.rs index 5f105937..1cf2953d 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -64,7 +64,8 @@ fn test_split_for_impl() { TypeTuple { elems: Default::default(), paren_token: Default::default(), - }.into(), + } + .into(), ), colon_token: Some(Default::default()), eq_token: Default::default(), @@ -78,7 +79,8 @@ fn test_split_for_impl() { bounded_ty: TypePath { qself: None, path: ident("T").into(), - }.into(), + } + .into(), bounds: punctuated![TypeParamBound::Trait(TraitBound { paren_token: None, modifier: TraitBoundModifier::None, diff --git a/tests/test_grouping.rs b/tests/test_grouping.rs index 78211ec9..2645cff5 100644 --- a/tests/test_grouping.rs +++ b/tests/test_grouping.rs @@ -45,12 +45,14 @@ fn test_grouping() { TokenTree::Literal(Literal::i32_suffixed(2)), TokenTree::Punct(Punct::new('+', Spacing::Alone)), TokenTree::Literal(Literal::i32_suffixed(3)), - ].into_iter() + ] + .into_iter() .collect(), )), TokenTree::Punct(Punct::new('*', Spacing::Alone)), TokenTree::Literal(Literal::i32_suffixed(4)), - ].into_iter() + ] + .into_iter() .collect(); assert_eq!(raw.to_string(), "1i32 + 2i32 + 3i32 * 4i32"); diff --git a/tests/test_meta_item.rs b/tests/test_meta_item.rs index 8c33d3ff..f3c75a91 100644 --- a/tests/test_meta_item.rs +++ b/tests/test_meta_item.rs @@ -105,7 +105,8 @@ fn test_meta_item_list_name_value() { ident: ident("bar").into(), eq_token: Default::default(), lit: lit(Literal::i32_unsuffixed(5)), - }.into(), + } + .into(), )], }, ) @@ -126,7 +127,8 @@ fn test_meta_item_list_bool_value() { value: true, span: Span::call_site() }), - }.into(), + } + .into(), )], }, ) @@ -146,7 +148,8 @@ fn test_meta_item_multiple() { ident: ident("name").into(), eq_token: Default::default(), lit: lit(Literal::i32_unsuffixed(5)), - }.into(), + } + .into(), ), NestedMeta::Meta( MetaList { @@ -157,9 +160,11 @@ fn test_meta_item_multiple() { ident: ident("name2").into(), eq_token: Default::default(), lit: lit(Literal::i32_unsuffixed(6)), - }.into(), + } + .into(), )], - }.into(), + } + .into(), ), NestedMeta::Meta(Meta::Word(ident("word2").into())), ],