From 202b51bc7b6999900e06ec2cfb8d72fe9aa4af29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Mar 2021 15:33:18 +0100 Subject: [PATCH] a lot of clippy::style fixes --- crates/base_db/src/input.rs | 2 +- crates/cfg/src/dnf.rs | 8 ++-- crates/mbe/src/expander/matcher.rs | 9 ++-- crates/mbe/src/lib.rs | 2 +- crates/mbe/src/parser.rs | 2 +- crates/mbe/src/syntax_bridge.rs | 2 +- crates/rust-analyzer/src/main_loop.rs | 7 +-- crates/rust-analyzer/src/reload.rs | 2 +- .../tests/rust-analyzer/support.rs | 2 +- crates/syntax/src/ast/edit.rs | 2 +- crates/syntax/src/ast/expr_ext.rs | 44 +++++++++---------- crates/syntax/src/ast/node_ext.rs | 19 ++------ crates/syntax/src/ast/token_ext.rs | 5 +-- crates/syntax/src/fuzz.rs | 2 +- crates/syntax/src/validation.rs | 4 +- crates/tt/src/lib.rs | 3 +- xtask/src/codegen/gen_syntax.rs | 2 +- xtask/src/main.rs | 2 +- xtask/src/tidy.rs | 2 +- 19 files changed, 52 insertions(+), 69 deletions(-) diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index d0def21815..e9e8dfc2e9 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -410,7 +410,7 @@ impl CrateId { impl CrateData { fn add_dep(&mut self, name: CrateName, crate_id: CrateId) { - self.dependencies.push(Dependency { name, crate_id }) + self.dependencies.push(Dependency { crate_id, name }) } } diff --git a/crates/cfg/src/dnf.rs b/crates/cfg/src/dnf.rs index 30f4bcdf79..75ded9aa1f 100644 --- a/crates/cfg/src/dnf.rs +++ b/crates/cfg/src/dnf.rs @@ -255,9 +255,9 @@ impl Builder { fn make_dnf(expr: CfgExpr) -> CfgExpr { match expr { CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => expr, - CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(|expr| make_dnf(expr)).collect()), + CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(make_dnf).collect()), CfgExpr::All(e) => { - let e = e.into_iter().map(|expr| make_nnf(expr)).collect::>(); + let e = e.into_iter().map(make_nnf).collect::>(); CfgExpr::Any(distribute_conj(&e)) } @@ -300,8 +300,8 @@ fn distribute_conj(conj: &[CfgExpr]) -> Vec { fn make_nnf(expr: CfgExpr) -> CfgExpr { match expr { CfgExpr::Invalid | CfgExpr::Atom(_) => expr, - CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(|expr| make_nnf(expr)).collect()), - CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(|expr| make_nnf(expr)).collect()), + CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(make_nnf).collect()), + CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(make_nnf).collect()), CfgExpr::Not(operand) => match *operand { CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr CfgExpr::Not(expr) => { diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index 1682b21b08..75d2f2eedf 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -304,7 +304,7 @@ impl BindingsBuilder { link_nodes: &'a Vec>>, nodes: &mut Vec<&'a Rc>, ) { - link_nodes.into_iter().for_each(|it| match it { + link_nodes.iter().for_each(|it| match it { LinkNode::Node(it) => nodes.push(it), LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes), }); @@ -713,10 +713,9 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult input.expect_tt().map(Some).map_err(|()| err!()), - "lifetime" => input - .expect_lifetime() - .map(|tt| Some(tt)) - .map_err(|()| err!("expected lifetime")), + "lifetime" => { + input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime")) + } "literal" => { let neg = input.eat_char('-'); input diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 33b85e23db..e74f8cf3f4 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -356,6 +356,6 @@ impl ExpandResult { impl From> for ExpandResult { fn from(result: Result) -> Self { - result.map_or_else(|e| Self::only_err(e), |it| Self::ok(it)) + result.map_or_else(Self::only_err, Self::ok) } } diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index c88387653d..61b2a49551 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs @@ -57,7 +57,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> { fn size_hint(&self) -> (usize, Option) { let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 }; - let remain = len.checked_sub(self.idx).unwrap_or(0); + let remain = len.saturating_sub(self.idx); (remain, Some(remain)) } } diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 8bba3d3d52..9d433b3b0b 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -362,7 +362,7 @@ trait TokenConvertor { if let Some((kind, closed)) = delim { let mut subtree = tt::Subtree::default(); let (id, idx) = self.id_alloc().open_delim(range); - subtree.delimiter = Some(tt::Delimiter { kind, id }); + subtree.delimiter = Some(tt::Delimiter { id, kind }); while self.peek().map(|it| it.kind() != closed).unwrap_or(false) { self.collect_leaf(&mut subtree.token_trees); diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 984790d354..c63a0eaeaf 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -242,11 +242,8 @@ impl GlobalState { } BuildDataProgress::End(collector) => { self.fetch_build_data_completed(); - let workspaces = (*self.workspaces) - .clone() - .into_iter() - .map(|it| Ok(it)) - .collect(); + let workspaces = + (*self.workspaces).clone().into_iter().map(Ok).collect(); self.switch_workspaces(workspaces, Some(collector)); (Some(Progress::End), None) } diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index aa8504c3d5..76fdbcdddb 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -237,7 +237,7 @@ impl GlobalState { None => None, }; - if &*self.workspaces == &workspaces && self.workspace_build_data == workspace_build_data { + if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data { return; } diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs index cd0c914817..95bf26f016 100644 --- a/crates/rust-analyzer/tests/rust-analyzer/support.rs +++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs @@ -54,7 +54,7 @@ impl<'a> Project<'a> { } pub(crate) fn server(self) -> Server { - let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new()); + let tmp_dir = self.tmp_dir.unwrap_or_else(TestDir::new); static INIT: Once = Once::new(); INIT.call_once(|| { env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap(); diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 365de44631..347862b8a4 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs @@ -595,7 +595,7 @@ impl IndentLevel { pub fn from_node(node: &SyntaxNode) -> IndentLevel { match node.first_token() { Some(it) => Self::from_token(&it), - None => return IndentLevel(0), + None => IndentLevel(0), } } diff --git a/crates/syntax/src/ast/expr_ext.rs b/crates/syntax/src/ast/expr_ext.rs index 636ce166d7..6317d84ba3 100644 --- a/crates/syntax/src/ast/expr_ext.rs +++ b/crates/syntax/src/ast/expr_ext.rs @@ -11,16 +11,16 @@ impl ast::AttrsOwner for ast::Expr {} impl ast::Expr { pub fn is_block_like(&self) -> bool { - match self { + matches!( + self, ast::Expr::IfExpr(_) - | ast::Expr::LoopExpr(_) - | ast::Expr::ForExpr(_) - | ast::Expr::WhileExpr(_) - | ast::Expr::BlockExpr(_) - | ast::Expr::MatchExpr(_) - | ast::Expr::EffectExpr(_) => true, - _ => false, - } + | ast::Expr::LoopExpr(_) + | ast::Expr::ForExpr(_) + | ast::Expr::WhileExpr(_) + | ast::Expr::BlockExpr(_) + | ast::Expr::MatchExpr(_) + | ast::Expr::EffectExpr(_) + ) } pub fn name_ref(&self) -> Option { @@ -151,20 +151,20 @@ pub enum BinOp { impl BinOp { pub fn is_assignment(self) -> bool { - match self { + matches!( + self, BinOp::Assignment - | BinOp::AddAssign - | BinOp::DivAssign - | BinOp::MulAssign - | BinOp::RemAssign - | BinOp::ShrAssign - | BinOp::ShlAssign - | BinOp::SubAssign - | BinOp::BitOrAssign - | BinOp::BitAndAssign - | BinOp::BitXorAssign => true, - _ => false, - } + | BinOp::AddAssign + | BinOp::DivAssign + | BinOp::MulAssign + | BinOp::RemAssign + | BinOp::ShrAssign + | BinOp::ShlAssign + | BinOp::SubAssign + | BinOp::BitOrAssign + | BinOp::BitAndAssign + | BinOp::BitXorAssign + ) } } diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 42a7b9c2a6..bdf907a21a 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -58,10 +58,7 @@ impl From for Macro { impl AstNode for Macro { fn can_cast(kind: SyntaxKind) -> bool { - match kind { - SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true, - _ => false, - } + matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF) } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { @@ -462,10 +459,8 @@ impl ast::FieldExpr { pub fn field_access(&self) -> Option { if let Some(nr) = self.name_ref() { Some(FieldKind::Name(nr)) - } else if let Some(tok) = self.index_token() { - Some(FieldKind::Index(tok)) } else { - None + self.index_token().map(FieldKind::Index) } } } @@ -482,16 +477,10 @@ impl ast::SlicePat { let prefix = args .peeking_take_while(|p| match p { ast::Pat::RestPat(_) => false, - ast::Pat::IdentPat(bp) => match bp.pat() { - Some(ast::Pat::RestPat(_)) => false, - _ => true, - }, + ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))), ast::Pat::RefPat(rp) => match rp.pat() { Some(ast::Pat::RestPat(_)) => false, - Some(ast::Pat::IdentPat(bp)) => match bp.pat() { - Some(ast::Pat::RestPat(_)) => false, - _ => true, - }, + Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))), _ => true, }, _ => true, diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 6c242d1265..090282d280 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs @@ -494,9 +494,8 @@ pub trait HasFormatSpecifier: AstToken { } _ => { while let Some((_, Ok(next_char))) = chars.peek() { - match next_char { - '{' => break, - _ => {} + if next_char == &'{' { + break; } chars.next(); } diff --git a/crates/syntax/src/fuzz.rs b/crates/syntax/src/fuzz.rs index fbb97aa273..aa84239d2f 100644 --- a/crates/syntax/src/fuzz.rs +++ b/crates/syntax/src/fuzz.rs @@ -43,7 +43,7 @@ impl CheckReparse { TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap()); let edited_text = format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]); - let edit = Indel { delete, insert }; + let edit = Indel { insert, delete }; Some(CheckReparse { text, edit, edited_text }) } diff --git a/crates/syntax/src/validation.rs b/crates/syntax/src/validation.rs index 3e216fb70b..bbe802174a 100644 --- a/crates/syntax/src/validation.rs +++ b/crates/syntax/src/validation.rs @@ -297,7 +297,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec bool { @@ -314,7 +314,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec { let s = match it { diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs index 80f26e8f59..ba4b248489 100644 --- a/xtask/src/codegen/gen_syntax.rs +++ b/xtask/src/codegen/gen_syntax.rs @@ -707,7 +707,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str let mut to_remove = Vec::new(); for (i, field) in node.fields.iter().enumerate() { let method_name = field.method_name().to_string(); - if methods.iter().any(|&it| it == &method_name) { + if methods.iter().any(|&it| it == method_name) { to_remove.push(i); } } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 915aae71a3..960927fc00 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -37,7 +37,7 @@ fn main() -> Result<()> { match flags.subcommand { flags::XtaskCmd::Help(_) => { println!("{}", flags::Xtask::HELP); - return Ok(()); + Ok(()) } flags::XtaskCmd::Install(cmd) => cmd.run(), flags::XtaskCmd::FuzzTests(_) => run_fuzzer(), diff --git a/xtask/src/tidy.rs b/xtask/src/tidy.rs index 1352d12189..50d9efccd2 100644 --- a/xtask/src/tidy.rs +++ b/xtask/src/tidy.rs @@ -193,7 +193,7 @@ https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/#redo-after- } } -fn deny_clippy(path: &PathBuf, text: &String) { +fn deny_clippy(path: &Path, text: &str) { let ignore = &[ // The documentation in string literals may contain anything for its own purposes "ide_completion/src/generated_lint_completions.rs",