diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libsyntax/util | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/classify.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/util/comments.rs | 48 | ||||
| -rw-r--r-- | src/libsyntax/util/lev_distance.rs | 56 | ||||
| -rw-r--r-- | src/libsyntax/util/lev_distance/tests.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/util/literal.rs | 112 | ||||
| -rw-r--r-- | src/libsyntax/util/map_in_place.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/util/node_count.rs | 15 | ||||
| -rw-r--r-- | src/libsyntax/util/parser.rs | 50 |
8 files changed, 167 insertions, 164 deletions
diff --git a/src/libsyntax/util/classify.rs b/src/libsyntax/util/classify.rs index 44560688750..60422a2e573 100644 --- a/src/libsyntax/util/classify.rs +++ b/src/libsyntax/util/classify.rs @@ -13,13 +13,13 @@ use crate::ast; /// isn't parsed as (if true {...} else {...} | x) | 5 pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { match e.kind { - ast::ExprKind::If(..) | - ast::ExprKind::Match(..) | - ast::ExprKind::Block(..) | - ast::ExprKind::While(..) | - ast::ExprKind::Loop(..) | - ast::ExprKind::ForLoop(..) | - ast::ExprKind::TryBlock(..) => false, + ast::ExprKind::If(..) + | ast::ExprKind::Match(..) + | ast::ExprKind::Block(..) + | ast::ExprKind::While(..) + | ast::ExprKind::Loop(..) + | ast::ExprKind::ForLoop(..) + | ast::ExprKind::TryBlock(..) => false, _ => true, } } diff --git a/src/libsyntax/util/comments.rs b/src/libsyntax/util/comments.rs index 5e9b7bf8322..1d2b753b69a 100644 --- a/src/libsyntax/util/comments.rs +++ b/src/libsyntax/util/comments.rs @@ -1,10 +1,10 @@ pub use CommentStyle::*; use crate::ast; -use crate::source_map::SourceMap; use crate::sess::ParseSess; +use crate::source_map::SourceMap; -use syntax_pos::{BytePos, CharPos, Pos, FileName}; +use syntax_pos::{BytePos, CharPos, FileName, Pos}; use std::usize; @@ -33,24 +33,27 @@ pub struct Comment { } pub fn is_line_doc_comment(s: &str) -> bool { - let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') || - s.starts_with("//!"); + let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') + || s.starts_with("//!"); debug!("is {:?} a doc comment? {}", s, res); res } pub fn is_block_doc_comment(s: &str) -> bool { // Prevent `/**/` from being parsed as a doc comment - let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') || - s.starts_with("/*!")) && s.len() >= 5; + let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') + || s.starts_with("/*!")) + && s.len() >= 5; debug!("is {:?} a doc comment? {}", s, res); res } // FIXME(#64197): Try to privatize this again. pub fn is_doc_comment(s: &str) -> bool { - (s.starts_with("///") && is_line_doc_comment(s)) || s.starts_with("//!") || - (s.starts_with("/**") && is_block_doc_comment(s)) || s.starts_with("/*!") + (s.starts_with("///") && is_line_doc_comment(s)) + || s.starts_with("//!") + || (s.starts_with("/**") && is_block_doc_comment(s)) + || s.starts_with("/*!") } pub fn doc_comment_style(comment: &str) -> ast::AttrStyle { @@ -76,11 +79,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { i += 1; } // like the first, a last line of all stars should be omitted - if j > i && - lines[j - 1] - .chars() - .skip(1) - .all(|c| c == '*') { + if j > i && lines[j - 1].chars().skip(1).all(|c| c == '*') { j -= 1; } @@ -122,9 +121,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { } if can_trim { - lines.iter() - .map(|line| (&line[i + 1..line.len()]).to_string()) - .collect() + lines.iter().map(|line| (&line[i + 1..line.len()]).to_string()).collect() } else { lines } @@ -140,10 +137,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { } if comment.starts_with("/*") { - let lines = comment[3..comment.len() - 2] - .lines() - .map(|s| s.to_string()) - .collect::<Vec<String>>(); + let lines = + comment[3..comment.len() - 2].lines().map(|s| s.to_string()).collect::<Vec<String>>(); let lines = vertical_trim(lines); let lines = horizontal_trim(lines); @@ -171,15 +166,18 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> { fn trim_whitespace_prefix(s: &str, col: CharPos) -> &str { let len = s.len(); match all_whitespace(&s, col) { - Some(col) => if col < len { &s[col..] } else { "" }, + Some(col) => { + if col < len { + &s[col..] + } else { + "" + } + } None => s, } } -fn split_block_comment_into_lines( - text: &str, - col: CharPos, -) -> Vec<String> { +fn split_block_comment_into_lines(text: &str, col: CharPos) -> Vec<String> { let mut res: Vec<String> = vec![]; let mut lines = text.lines(); // just push the first line diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index efb3c2396c3..f55b58d7d13 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -1,5 +1,5 @@ -use std::cmp; use crate::symbol::Symbol; +use std::cmp; #[cfg(test)] mod tests; @@ -43,36 +43,36 @@ pub fn lev_distance(a: &str, b: &str) -> usize { /// /// Besides Levenshtein, we use case insensitive comparison to improve accuracy on an edge case with /// a lower(upper)case letters mismatch. -pub fn find_best_match_for_name<'a, T>(iter_names: T, - lookup: &str, - dist: Option<usize>) -> Option<Symbol> - where T: Iterator<Item = &'a Symbol> { +pub fn find_best_match_for_name<'a, T>( + iter_names: T, + lookup: &str, + dist: Option<usize>, +) -> Option<Symbol> +where + T: Iterator<Item = &'a Symbol>, +{ let max_dist = dist.map_or_else(|| cmp::max(lookup.len(), 3) / 3, |d| d); let (case_insensitive_match, levenstein_match) = iter_names - .filter_map(|&name| { - let dist = lev_distance(lookup, &name.as_str()); - if dist <= max_dist { - Some((name, dist)) - } else { - None - } - }) - // Here we are collecting the next structure: - // (case_insensitive_match, (levenstein_match, levenstein_distance)) - .fold((None, None), |result, (candidate, dist)| { - ( - if candidate.as_str().to_uppercase() == lookup.to_uppercase() { - Some(candidate) - } else { - result.0 - }, - match result.1 { - None => Some((candidate, dist)), - Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }) - } - ) - }); + .filter_map(|&name| { + let dist = lev_distance(lookup, &name.as_str()); + if dist <= max_dist { Some((name, dist)) } else { None } + }) + // Here we are collecting the next structure: + // (case_insensitive_match, (levenstein_match, levenstein_distance)) + .fold((None, None), |result, (candidate, dist)| { + ( + if candidate.as_str().to_uppercase() == lookup.to_uppercase() { + Some(candidate) + } else { + result.0 + }, + match result.1 { + None => Some((candidate, dist)), + Some((c, d)) => Some(if dist < d { (candidate, dist) } else { (c, d) }), + }, + ) + }); if let Some(candidate) = case_insensitive_match { Some(candidate) // exact case insensitive match has a higher priority diff --git a/src/libsyntax/util/lev_distance/tests.rs b/src/libsyntax/util/lev_distance/tests.rs index 1a746a67ec0..f65f9275d03 100644 --- a/src/libsyntax/util/lev_distance/tests.rs +++ b/src/libsyntax/util/lev_distance/tests.rs @@ -4,9 +4,7 @@ use super::*; fn test_lev_distance() { use std::char::{from_u32, MAX}; // Test bytelength agnosticity - for c in (0..MAX as u32) - .filter_map(|i| from_u32(i)) - .map(|i| i.to_string()) { + for c in (0..MAX as u32).filter_map(|i| from_u32(i)).map(|i| i.to_string()) { assert_eq!(lev_distance(&c[..], &c[..]), 0); } @@ -31,10 +29,7 @@ fn test_find_best_match_for_name() { Some(Symbol::intern("aaab")) ); - assert_eq!( - find_best_match_for_name(input.iter(), "1111111111", None), - None - ); + assert_eq!(find_best_match_for_name(input.iter(), "1111111111", None), None); let input = vec![Symbol::intern("aAAA")]; assert_eq!( @@ -44,10 +39,7 @@ fn test_find_best_match_for_name() { let input = vec![Symbol::intern("AAAA")]; // Returns None because `lev_distance > max_dist / 3` - assert_eq!( - find_best_match_for_name(input.iter(), "aaaa", None), - None - ); + assert_eq!(find_best_match_for_name(input.iter(), "aaaa", None), None); let input = vec![Symbol::intern("AAAA")]; assert_eq!( diff --git a/src/libsyntax/util/literal.rs b/src/libsyntax/util/literal.rs index af7afab6b9b..27ce180a4bc 100644 --- a/src/libsyntax/util/literal.rs +++ b/src/libsyntax/util/literal.rs @@ -7,10 +7,10 @@ use crate::tokenstream::TokenTree; use log::debug; use rustc_data_structures::sync::Lrc; +use rustc_lexer::unescape::{unescape_byte, unescape_char}; +use rustc_lexer::unescape::{unescape_byte_str, unescape_str}; +use rustc_lexer::unescape::{unescape_raw_byte_str, unescape_raw_str}; use syntax_pos::Span; -use rustc_lexer::unescape::{unescape_char, unescape_byte}; -use rustc_lexer::unescape::{unescape_str, unescape_byte_str}; -use rustc_lexer::unescape::{unescape_raw_str, unescape_raw_byte_str}; use std::ascii; @@ -37,10 +37,16 @@ impl LitKind { assert!(symbol.is_bool_lit()); LitKind::Bool(symbol == kw::True) } - token::Byte => return unescape_byte(&symbol.as_str()) - .map(LitKind::Byte).map_err(|_| LitError::LexerError), - token::Char => return unescape_char(&symbol.as_str()) - .map(LitKind::Char).map_err(|_| LitError::LexerError), + token::Byte => { + return unescape_byte(&symbol.as_str()) + .map(LitKind::Byte) + .map_err(|_| LitError::LexerError); + } + token::Char => { + return unescape_char(&symbol.as_str()) + .map(LitKind::Char) + .map_err(|_| LitError::LexerError); + } // There are some valid suffixes for integer and float literals, // so all the handling is done internally. @@ -56,11 +62,9 @@ impl LitKind { let symbol = if s.contains(&['\\', '\r'][..]) { let mut buf = String::with_capacity(s.len()); let mut error = Ok(()); - unescape_str(&s, &mut |_, unescaped_char| { - match unescaped_char { - Ok(c) => buf.push(c), - Err(_) => error = Err(LitError::LexerError), - } + unescape_str(&s, &mut |_, unescaped_char| match unescaped_char { + Ok(c) => buf.push(c), + Err(_) => error = Err(LitError::LexerError), }); error?; Symbol::intern(&buf) @@ -75,11 +79,9 @@ impl LitKind { let symbol = if s.contains('\r') { let mut buf = String::with_capacity(s.len()); let mut error = Ok(()); - unescape_raw_str(&s, &mut |_, unescaped_char| { - match unescaped_char { - Ok(c) => buf.push(c), - Err(_) => error = Err(LitError::LexerError), - } + unescape_raw_str(&s, &mut |_, unescaped_char| match unescaped_char { + Ok(c) => buf.push(c), + Err(_) => error = Err(LitError::LexerError), }); error?; buf.shrink_to_fit(); @@ -93,11 +95,9 @@ impl LitKind { let s = symbol.as_str(); let mut buf = Vec::with_capacity(s.len()); let mut error = Ok(()); - unescape_byte_str(&s, &mut |_, unescaped_byte| { - match unescaped_byte { - Ok(c) => buf.push(c), - Err(_) => error = Err(LitError::LexerError), - } + unescape_byte_str(&s, &mut |_, unescaped_byte| match unescaped_byte { + Ok(c) => buf.push(c), + Err(_) => error = Err(LitError::LexerError), }); error?; buf.shrink_to_fit(); @@ -108,11 +108,9 @@ impl LitKind { let bytes = if s.contains('\r') { let mut buf = Vec::with_capacity(s.len()); let mut error = Ok(()); - unescape_raw_byte_str(&s, &mut |_, unescaped_byte| { - match unescaped_byte { - Ok(c) => buf.push(c), - Err(_) => error = Err(LitError::LexerError), - } + unescape_raw_byte_str(&s, &mut |_, unescaped_byte| match unescaped_byte { + Ok(c) => buf.push(c), + Err(_) => error = Err(LitError::LexerError), }); error?; buf.shrink_to_fit(); @@ -122,7 +120,7 @@ impl LitKind { }; LitKind::ByteStr(Lrc::new(bytes)) - }, + } token::Err => LitKind::Err(symbol), }) } @@ -139,12 +137,14 @@ impl LitKind { let symbol = if s == escaped { symbol } else { Symbol::intern(&escaped) }; (token::Str, symbol, None) } - LitKind::Str(symbol, ast::StrStyle::Raw(n)) => { - (token::StrRaw(n), symbol, None) - } + LitKind::Str(symbol, ast::StrStyle::Raw(n)) => (token::StrRaw(n), symbol, None), LitKind::ByteStr(ref bytes) => { - let string = bytes.iter().cloned().flat_map(ascii::escape_default) - .map(Into::<char>::into).collect::<String>(); + let string = bytes + .iter() + .cloned() + .flat_map(ascii::escape_default) + .map(Into::<char>::into) + .collect::<String>(); (token::ByteStr, Symbol::intern(&string), None) } LitKind::Byte(byte) => { @@ -174,9 +174,7 @@ impl LitKind { let symbol = if value { kw::True } else { kw::False }; (token::Bool, symbol, None) } - LitKind::Err(symbol) => { - (token::Err, symbol, None) - } + LitKind::Err(symbol) => (token::Err, symbol, None), }; token::Lit::new(kind, symbol, suffix) @@ -192,10 +190,10 @@ impl Lit { /// Converts arbitrary token into an AST literal. pub fn from_token(token: &Token) -> Result<Lit, LitError> { let lit = match token.kind { - token::Ident(name, false) if name.is_bool_lit() => - token::Lit::new(token::Bool, name, None), - token::Literal(lit) => - lit, + token::Ident(name, false) if name.is_bool_lit() => { + token::Lit::new(token::Bool, name, None) + } + token::Literal(lit) => lit, token::Interpolated(ref nt) => { if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt { if let ast::ExprKind::Lit(lit) = &expr.kind { @@ -204,7 +202,7 @@ impl Lit { } return Err(LitError::NotLiteral); } - _ => return Err(LitError::NotLiteral) + _ => return Err(LitError::NotLiteral), }; Lit::from_lit_token(lit, token.span) @@ -238,19 +236,25 @@ fn strip_underscores(symbol: Symbol) -> Symbol { symbol } -fn filtered_float_lit(symbol: Symbol, suffix: Option<Symbol>, base: u32) - -> Result<LitKind, LitError> { +fn filtered_float_lit( + symbol: Symbol, + suffix: Option<Symbol>, + base: u32, +) -> Result<LitKind, LitError> { debug!("filtered_float_lit: {:?}, {:?}, {:?}", symbol, suffix, base); if base != 10 { return Err(LitError::NonDecimalFloat(base)); } Ok(match suffix { - Some(suf) => LitKind::Float(symbol, ast::LitFloatType::Suffixed(match suf { - sym::f32 => ast::FloatTy::F32, - sym::f64 => ast::FloatTy::F64, - _ => return Err(LitError::InvalidFloatSuffix), - })), - None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed) + Some(suf) => LitKind::Float( + symbol, + ast::LitFloatType::Suffixed(match suf { + sym::f32 => ast::FloatTy::F32, + sym::f64 => ast::FloatTy::F64, + _ => return Err(LitError::InvalidFloatSuffix), + }), + ), + None => LitKind::Float(symbol, ast::LitFloatType::Unsuffixed), }) } @@ -274,13 +278,13 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr let ty = match suffix { Some(suf) => match suf { sym::isize => ast::LitIntType::Signed(ast::IntTy::Isize), - sym::i8 => ast::LitIntType::Signed(ast::IntTy::I8), + sym::i8 => ast::LitIntType::Signed(ast::IntTy::I8), sym::i16 => ast::LitIntType::Signed(ast::IntTy::I16), sym::i32 => ast::LitIntType::Signed(ast::IntTy::I32), sym::i64 => ast::LitIntType::Signed(ast::IntTy::I64), sym::i128 => ast::LitIntType::Signed(ast::IntTy::I128), sym::usize => ast::LitIntType::Unsigned(ast::UintTy::Usize), - sym::u8 => ast::LitIntType::Unsigned(ast::UintTy::U8), + sym::u8 => ast::LitIntType::Unsigned(ast::UintTy::U8), sym::u16 => ast::LitIntType::Unsigned(ast::UintTy::U16), sym::u32 => ast::LitIntType::Unsigned(ast::UintTy::U32), sym::u64 => ast::LitIntType::Unsigned(ast::UintTy::U64), @@ -289,11 +293,11 @@ fn integer_lit(symbol: Symbol, suffix: Option<Symbol>) -> Result<LitKind, LitErr // `fxxx` looks more like an invalid float literal than invalid integer literal. _ if suf.as_str().starts_with('f') => return filtered_float_lit(symbol, suffix, base), _ => return Err(LitError::InvalidIntSuffix), - } - _ => ast::LitIntType::Unsuffixed + }, + _ => ast::LitIntType::Unsuffixed, }; - let s = &s[if base != 10 { 2 } else { 0 } ..]; + let s = &s[if base != 10 { 2 } else { 0 }..]; u128::from_str_radix(s, base).map(|i| LitKind::Int(i, ty)).map_err(|_| { // Small bases are lexed as if they were base 10, e.g, the string // might be `0b10201`. This will cause the conversion above to fail, diff --git a/src/libsyntax/util/map_in_place.rs b/src/libsyntax/util/map_in_place.rs index 5724b540a0d..5dd9fc6e8bc 100644 --- a/src/libsyntax/util/map_in_place.rs +++ b/src/libsyntax/util/map_in_place.rs @@ -1,20 +1,25 @@ -use std::ptr; use smallvec::{Array, SmallVec}; +use std::ptr; pub trait MapInPlace<T>: Sized { - fn map_in_place<F>(&mut self, mut f: F) where F: FnMut(T) -> T { + fn map_in_place<F>(&mut self, mut f: F) + where + F: FnMut(T) -> T, + { self.flat_map_in_place(|e| Some(f(e))) } fn flat_map_in_place<F, I>(&mut self, f: F) - where F: FnMut(T) -> I, - I: IntoIterator<Item=T>; + where + F: FnMut(T) -> I, + I: IntoIterator<Item = T>; } impl<T> MapInPlace<T> for Vec<T> { fn flat_map_in_place<F, I>(&mut self, mut f: F) - where F: FnMut(T) -> I, - I: IntoIterator<Item=T> + where + F: FnMut(T) -> I, + I: IntoIterator<Item = T>, { let mut read_i = 0; let mut write_i = 0; @@ -58,8 +63,9 @@ impl<T> MapInPlace<T> for Vec<T> { impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> { fn flat_map_in_place<F, I>(&mut self, mut f: F) - where F: FnMut(T) -> I, - I: IntoIterator<Item=T> + where + F: FnMut(T) -> I, + I: IntoIterator<Item = T>, { let mut read_i = 0; let mut write_i = 0; diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index 3db9955d304..e768ab4c648 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -1,7 +1,7 @@ // Simply gives a rought count of the number of nodes in an AST. -use crate::visit::*; use crate::ast::*; +use crate::visit::*; use syntax_pos::Span; pub struct NodeCounter { @@ -10,9 +10,7 @@ pub struct NodeCounter { impl NodeCounter { pub fn new() -> NodeCounter { - NodeCounter { - count: 0, - } + NodeCounter { count: 0 } } } @@ -97,8 +95,13 @@ impl<'ast> Visitor<'ast> for NodeCounter { self.count += 1; walk_struct_field(self, s) } - fn visit_enum_def(&mut self, enum_definition: &EnumDef, - generics: &Generics, item_id: NodeId, _: Span) { + fn visit_enum_def( + &mut self, + enum_definition: &EnumDef, + generics: &Generics, + item_id: NodeId, + _: Span, + ) { self.count += 1; walk_enum_def(self, enum_definition, generics, item_id) } diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index df72fdc8014..88e3d8daf70 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -1,6 +1,6 @@ -use crate::token::{self, Token, BinOpToken}; -use crate::symbol::kw; use crate::ast::{self, BinOpKind}; +use crate::symbol::kw; +use crate::token::{self, BinOpToken, Token}; /// Associative operator with precedence. /// @@ -64,7 +64,7 @@ pub enum Fixity { /// The operator is right-associative Right, /// The operator is not associative - None + None, } impl AssocOp { @@ -100,7 +100,7 @@ impl AssocOp { // `<-` should probably be `< -` token::LArrow => Some(Less), _ if t.is_keyword(kw::As) => Some(As), - _ => None + _ => None, } } @@ -125,7 +125,7 @@ impl AssocOp { BinOpKind::BitXor => BitXor, BinOpKind::BitOr => BitOr, BinOpKind::And => LAnd, - BinOpKind::Or => LOr + BinOpKind::Or => LOr, } } @@ -154,10 +154,10 @@ impl AssocOp { // NOTE: it is a bug to have an operators that has same precedence but different fixities! match *self { Assign | AssignOp(_) => Fixity::Right, - As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | - BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | - LAnd | LOr | Colon => Fixity::Left, - DotDot | DotDotEq => Fixity::None + As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd + | BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual + | LAnd | LOr | Colon => Fixity::Left, + DotDot | DotDotEq => Fixity::None, } } @@ -165,9 +165,9 @@ impl AssocOp { use AssocOp::*; match *self { Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true, - Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | - Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | - DotDot | DotDotEq | Colon => false + Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract + | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | DotDotEq + | Colon => false, } } @@ -175,9 +175,9 @@ impl AssocOp { use AssocOp::*; match *self { Assign | AssignOp(_) => true, - Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide | - Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | - LOr | DotDot | DotDotEq | Colon => false + Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply + | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor + | BitOr | LAnd | LOr | DotDot | DotDotEq | Colon => false, } } @@ -202,7 +202,7 @@ impl AssocOp { BitOr => Some(BinOpKind::BitOr), LAnd => Some(BinOpKind::And), LOr => Some(BinOpKind::Or), - Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None + Assign | AssignOp(_) | As | DotDot | DotDotEq | Colon => None, } } @@ -378,18 +378,18 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool { match value.kind { ast::ExprKind::Struct(..) => true, - ast::ExprKind::Assign(ref lhs, ref rhs) | - ast::ExprKind::AssignOp(_, ref lhs, ref rhs) | - ast::ExprKind::Binary(_, ref lhs, ref rhs) => { + ast::ExprKind::Assign(ref lhs, ref rhs) + | ast::ExprKind::AssignOp(_, ref lhs, ref rhs) + | ast::ExprKind::Binary(_, ref lhs, ref rhs) => { // X { y: 1 } + X { y: 2 } contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs) } - ast::ExprKind::Await(ref x) | - ast::ExprKind::Unary(_, ref x) | - ast::ExprKind::Cast(ref x, _) | - ast::ExprKind::Type(ref x, _) | - ast::ExprKind::Field(ref x, _) | - ast::ExprKind::Index(ref x, _) => { + ast::ExprKind::Await(ref x) + | ast::ExprKind::Unary(_, ref x) + | ast::ExprKind::Cast(ref x, _) + | ast::ExprKind::Type(ref x, _) + | ast::ExprKind::Field(ref x, _) + | ast::ExprKind::Index(ref x, _) => { // &X { y: 1 }, X { y: 1 }.y contains_exterior_struct_lit(&x) } |
