From 3d9b3a8575ef3cb557fd847b941000df3b2db670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Mar 2021 12:05:08 +0100 Subject: remove more redundant clones (clippy::redundant_clone()) --- crates/syntax/src/ast/make.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/syntax/src/ast') diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 810c8d4c8..7049affd9 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs @@ -532,7 +532,7 @@ fn ast_from_text(text: &str) -> N { } fn unroot(n: SyntaxNode) -> SyntaxNode { - SyntaxNode::new_root(n.green().to_owned()) + SyntaxNode::new_root(n.green()) } pub mod tokens { -- cgit v1.2.3 From 8a671168576b9b552a22be285646fc293a80d8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Mar 2021 12:38:21 +0100 Subject: use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) --- crates/syntax/src/ast/edit.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/syntax/src/ast') diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 64fac13a7..80be8b79c 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs @@ -333,8 +333,7 @@ impl ast::Use { .and_then(ast::Whitespace::cast); if let Some(next_ws) = next_ws { let ws_text = next_ws.syntax().text(); - if ws_text.starts_with('\n') { - let rest = &ws_text[1..]; + if let Some(rest) = ws_text.strip_prefix('\n') { if rest.is_empty() { res.delete(next_ws.syntax()) } else { -- cgit v1.2.3 From ae7e55c1dd801c60092205ec8890179e10a47814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 21 Mar 2021 13:13:34 +0100 Subject: clippy::complexity simplifications related to Iterators --- crates/syntax/src/ast/edit.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/syntax/src/ast') diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 80be8b79c..365de4463 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs @@ -461,8 +461,7 @@ impl ast::MatchArmList { let end = if let Some(comma) = start .siblings_with_tokens(Direction::Next) .skip(1) - .skip_while(|it| it.kind().is_trivia()) - .next() + .find(|it| !it.kind().is_trivia()) .filter(|it| it.kind() == T![,]) { comma -- cgit v1.2.3 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: a lot of clippy::style fixes --- 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 ++--- 4 files changed, 29 insertions(+), 41 deletions(-) (limited to 'crates/syntax/src/ast') diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 365de4463..347862b8a 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 636ce166d..6317d84ba 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 42a7b9c2a..bdf907a21 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 6c242d126..090282d28 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(); } -- cgit v1.2.3