diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-28 23:37:25 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-28 23:37:25 +0100 |
commit | ca31b1d63ae91a69f1ce9c0b075403834ba19f38 (patch) | |
tree | df719c1ccd7cbd174b79ca50ffd0052731d1ea86 /crates/ra_assists/src/utils.rs | |
parent | 11f31ae4c3a38831609e4591e751ce10c4e38daf (diff) | |
parent | 36128c170d9d938cfcc52bc851aaed1fab6a2ad9 (diff) |
Merge #5105
5105: Simlify with matches!() r=matklad a=Veetaha
Co-authored-by: Veetaha <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/utils.rs')
-rw-r--r-- | crates/ra_assists/src/utils.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_assists/src/utils.rs b/crates/ra_assists/src/utils.rs index b7c45a619..02de902d6 100644 --- a/crates/ra_assists/src/utils.rs +++ b/crates/ra_assists/src/utils.rs | |||
@@ -7,7 +7,9 @@ use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type}; | |||
7 | use ra_ide_db::RootDatabase; | 7 | use ra_ide_db::RootDatabase; |
8 | use ra_syntax::{ | 8 | use ra_syntax::{ |
9 | ast::{self, make, NameOwner}, | 9 | ast::{self, make, NameOwner}, |
10 | AstNode, SyntaxNode, T, | 10 | AstNode, |
11 | SyntaxKind::*, | ||
12 | SyntaxNode, TextSize, T, | ||
11 | }; | 13 | }; |
12 | use rustc_hash::FxHashSet; | 14 | use rustc_hash::FxHashSet; |
13 | 15 | ||
@@ -120,6 +122,13 @@ pub(crate) fn resolve_target_trait( | |||
120 | } | 122 | } |
121 | } | 123 | } |
122 | 124 | ||
125 | pub(crate) fn vis_offset(node: &SyntaxNode) -> TextSize { | ||
126 | node.children_with_tokens() | ||
127 | .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR)) | ||
128 | .map(|it| it.text_range().start()) | ||
129 | .unwrap_or_else(|| node.text_range().start()) | ||
130 | } | ||
131 | |||
123 | pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { | 132 | pub(crate) fn invert_boolean_expression(expr: ast::Expr) -> ast::Expr { |
124 | if let Some(expr) = invert_special_case(&expr) { | 133 | if let Some(expr) = invert_special_case(&expr) { |
125 | return expr; | 134 | return expr; |