diff options
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 8 | ||||
-rw-r--r-- | crates/syntax/src/ast/expr_ext.rs | 44 | ||||
-rw-r--r-- | crates/syntax/src/ast/make.rs | 2 | ||||
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 19 | ||||
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 5 |
5 files changed, 32 insertions, 46 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 64fac13a7..347862b8a 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -333,8 +333,7 @@ impl ast::Use { | |||
333 | .and_then(ast::Whitespace::cast); | 333 | .and_then(ast::Whitespace::cast); |
334 | if let Some(next_ws) = next_ws { | 334 | if let Some(next_ws) = next_ws { |
335 | let ws_text = next_ws.syntax().text(); | 335 | let ws_text = next_ws.syntax().text(); |
336 | if ws_text.starts_with('\n') { | 336 | if let Some(rest) = ws_text.strip_prefix('\n') { |
337 | let rest = &ws_text[1..]; | ||
338 | if rest.is_empty() { | 337 | if rest.is_empty() { |
339 | res.delete(next_ws.syntax()) | 338 | res.delete(next_ws.syntax()) |
340 | } else { | 339 | } else { |
@@ -462,8 +461,7 @@ impl ast::MatchArmList { | |||
462 | let end = if let Some(comma) = start | 461 | let end = if let Some(comma) = start |
463 | .siblings_with_tokens(Direction::Next) | 462 | .siblings_with_tokens(Direction::Next) |
464 | .skip(1) | 463 | .skip(1) |
465 | .skip_while(|it| it.kind().is_trivia()) | 464 | .find(|it| !it.kind().is_trivia()) |
466 | .next() | ||
467 | .filter(|it| it.kind() == T![,]) | 465 | .filter(|it| it.kind() == T![,]) |
468 | { | 466 | { |
469 | comma | 467 | comma |
@@ -597,7 +595,7 @@ impl IndentLevel { | |||
597 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { | 595 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { |
598 | match node.first_token() { | 596 | match node.first_token() { |
599 | Some(it) => Self::from_token(&it), | 597 | Some(it) => Self::from_token(&it), |
600 | None => return IndentLevel(0), | 598 | None => IndentLevel(0), |
601 | } | 599 | } |
602 | } | 600 | } |
603 | 601 | ||
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 {} | |||
11 | 11 | ||
12 | impl ast::Expr { | 12 | impl ast::Expr { |
13 | pub fn is_block_like(&self) -> bool { | 13 | pub fn is_block_like(&self) -> bool { |
14 | match self { | 14 | matches!( |
15 | self, | ||
15 | ast::Expr::IfExpr(_) | 16 | ast::Expr::IfExpr(_) |
16 | | ast::Expr::LoopExpr(_) | 17 | | ast::Expr::LoopExpr(_) |
17 | | ast::Expr::ForExpr(_) | 18 | | ast::Expr::ForExpr(_) |
18 | | ast::Expr::WhileExpr(_) | 19 | | ast::Expr::WhileExpr(_) |
19 | | ast::Expr::BlockExpr(_) | 20 | | ast::Expr::BlockExpr(_) |
20 | | ast::Expr::MatchExpr(_) | 21 | | ast::Expr::MatchExpr(_) |
21 | | ast::Expr::EffectExpr(_) => true, | 22 | | ast::Expr::EffectExpr(_) |
22 | _ => false, | 23 | ) |
23 | } | ||
24 | } | 24 | } |
25 | 25 | ||
26 | pub fn name_ref(&self) -> Option<ast::NameRef> { | 26 | pub fn name_ref(&self) -> Option<ast::NameRef> { |
@@ -151,20 +151,20 @@ pub enum BinOp { | |||
151 | 151 | ||
152 | impl BinOp { | 152 | impl BinOp { |
153 | pub fn is_assignment(self) -> bool { | 153 | pub fn is_assignment(self) -> bool { |
154 | match self { | 154 | matches!( |
155 | self, | ||
155 | BinOp::Assignment | 156 | BinOp::Assignment |
156 | | BinOp::AddAssign | 157 | | BinOp::AddAssign |
157 | | BinOp::DivAssign | 158 | | BinOp::DivAssign |
158 | | BinOp::MulAssign | 159 | | BinOp::MulAssign |
159 | | BinOp::RemAssign | 160 | | BinOp::RemAssign |
160 | | BinOp::ShrAssign | 161 | | BinOp::ShrAssign |
161 | | BinOp::ShlAssign | 162 | | BinOp::ShlAssign |
162 | | BinOp::SubAssign | 163 | | BinOp::SubAssign |
163 | | BinOp::BitOrAssign | 164 | | BinOp::BitOrAssign |
164 | | BinOp::BitAndAssign | 165 | | BinOp::BitAndAssign |
165 | | BinOp::BitXorAssign => true, | 166 | | BinOp::BitXorAssign |
166 | _ => false, | 167 | ) |
167 | } | ||
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
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<N: AstNode>(text: &str) -> N { | |||
532 | } | 532 | } |
533 | 533 | ||
534 | fn unroot(n: SyntaxNode) -> SyntaxNode { | 534 | fn unroot(n: SyntaxNode) -> SyntaxNode { |
535 | SyntaxNode::new_root(n.green().to_owned()) | 535 | SyntaxNode::new_root(n.green()) |
536 | } | 536 | } |
537 | 537 | ||
538 | pub mod tokens { | 538 | pub mod tokens { |
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<ast::MacroDef> for Macro { | |||
58 | 58 | ||
59 | impl AstNode for Macro { | 59 | impl AstNode for Macro { |
60 | fn can_cast(kind: SyntaxKind) -> bool { | 60 | fn can_cast(kind: SyntaxKind) -> bool { |
61 | match kind { | 61 | matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF) |
62 | SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true, | ||
63 | _ => false, | ||
64 | } | ||
65 | } | 62 | } |
66 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 63 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
67 | let res = match syntax.kind() { | 64 | let res = match syntax.kind() { |
@@ -462,10 +459,8 @@ impl ast::FieldExpr { | |||
462 | pub fn field_access(&self) -> Option<FieldKind> { | 459 | pub fn field_access(&self) -> Option<FieldKind> { |
463 | if let Some(nr) = self.name_ref() { | 460 | if let Some(nr) = self.name_ref() { |
464 | Some(FieldKind::Name(nr)) | 461 | Some(FieldKind::Name(nr)) |
465 | } else if let Some(tok) = self.index_token() { | ||
466 | Some(FieldKind::Index(tok)) | ||
467 | } else { | 462 | } else { |
468 | None | 463 | self.index_token().map(FieldKind::Index) |
469 | } | 464 | } |
470 | } | 465 | } |
471 | } | 466 | } |
@@ -482,16 +477,10 @@ impl ast::SlicePat { | |||
482 | let prefix = args | 477 | let prefix = args |
483 | .peeking_take_while(|p| match p { | 478 | .peeking_take_while(|p| match p { |
484 | ast::Pat::RestPat(_) => false, | 479 | ast::Pat::RestPat(_) => false, |
485 | ast::Pat::IdentPat(bp) => match bp.pat() { | 480 | ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))), |
486 | Some(ast::Pat::RestPat(_)) => false, | ||
487 | _ => true, | ||
488 | }, | ||
489 | ast::Pat::RefPat(rp) => match rp.pat() { | 481 | ast::Pat::RefPat(rp) => match rp.pat() { |
490 | Some(ast::Pat::RestPat(_)) => false, | 482 | Some(ast::Pat::RestPat(_)) => false, |
491 | Some(ast::Pat::IdentPat(bp)) => match bp.pat() { | 483 | Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))), |
492 | Some(ast::Pat::RestPat(_)) => false, | ||
493 | _ => true, | ||
494 | }, | ||
495 | _ => true, | 484 | _ => true, |
496 | }, | 485 | }, |
497 | _ => true, | 486 | _ => 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 { | |||
494 | } | 494 | } |
495 | _ => { | 495 | _ => { |
496 | while let Some((_, Ok(next_char))) = chars.peek() { | 496 | while let Some((_, Ok(next_char))) = chars.peek() { |
497 | match next_char { | 497 | if next_char == &'{' { |
498 | '{' => break, | 498 | break; |
499 | _ => {} | ||
500 | } | 499 | } |
501 | chars.next(); | 500 | chars.next(); |
502 | } | 501 | } |