aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVeetaha <[email protected]>2020-06-28 02:02:03 +0100
committerVeetaha <[email protected]>2020-06-28 02:03:59 +0100
commite75e2ae5b6b6b1364368ceb3d4081b6508b2f001 (patch)
treee88a9920a908bfdf66c156ab582ce90d77d55c2f
parent513924a7e01ef81a03869249c902daf148439736 (diff)
Simlify with matches!()
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs11
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs6
-rw-r--r--crates/ra_assists/src/handlers/merge_match_arms.rs5
-rw-r--r--crates/ra_hir_def/src/nameres.rs5
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs6
-rw-r--r--crates/ra_hir_ty/src/lib.rs10
-rw-r--r--crates/ra_ide/src/inlay_hints.rs6
-rw-r--r--crates/ra_ide/src/join_lines.rs5
-rw-r--r--crates/ra_ide_db/src/symbol_index.rs5
-rw-r--r--crates/ra_mbe/src/parser.rs5
-rw-r--r--crates/ra_parser/src/grammar.rs5
-rw-r--r--crates/ra_parser/src/grammar/paths.rs5
-rw-r--r--crates/ra_parser/src/grammar/type_params.rs5
-rw-r--r--crates/ra_parser/src/syntax_kind.rs5
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs5
-rw-r--r--crates/ra_syntax/src/ast/extensions.rs16
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs5
-rw-r--r--crates/ra_tt/src/buffer.rs5
-rw-r--r--crates/rust-analyzer/src/cli.rs10
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs5
20 files changed, 32 insertions, 98 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index c21d75be0..18e92e393 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -30,9 +30,8 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio
30} 30}
31 31
32fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 32fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
33 let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() { 33 let item_keyword = ctx.token_at_offset().find(|leaf| {
34 T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true, 34 matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait])
35 _ => false,
36 }); 35 });
37 36
38 let (offset, target) = if let Some(keyword) = item_keyword { 37 let (offset, target) = if let Some(keyword) = item_keyword {
@@ -73,11 +72,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
73 72
74fn vis_offset(node: &SyntaxNode) -> TextSize { 73fn vis_offset(node: &SyntaxNode) -> TextSize {
75 node.children_with_tokens() 74 node.children_with_tokens()
76 .skip_while(|it| match it.kind() { 75 .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
77 WHITESPACE | COMMENT | ATTR => true,
78 _ => false,
79 })
80 .next()
81 .map(|it| it.text_range().start()) 76 .map(|it| it.text_range().start())
82 .unwrap_or_else(|| node.text_range().start()) 77 .unwrap_or_else(|| node.text_range().start())
83} 78}
diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs
index 54601d1f3..02763c5b9 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -179,11 +179,7 @@ fn target_data_for_def(
179 179
180fn vis_offset(node: &SyntaxNode) -> TextSize { 180fn vis_offset(node: &SyntaxNode) -> TextSize {
181 node.children_with_tokens() 181 node.children_with_tokens()
182 .skip_while(|it| match it.kind() { 182 .find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
183 WHITESPACE | COMMENT | ATTR => true,
184 _ => false,
185 })
186 .next()
187 .map(|it| it.text_range().start()) 183 .map(|it| it.text_range().start())
188 .unwrap_or_else(|| node.text_range().start()) 184 .unwrap_or_else(|| node.text_range().start())
189} 185}
diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs
index ca04ec671..53c2c130f 100644
--- a/crates/ra_assists/src/handlers/merge_match_arms.rs
+++ b/crates/ra_assists/src/handlers/merge_match_arms.rs
@@ -81,10 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
81} 81}
82 82
83fn contains_placeholder(a: &ast::MatchArm) -> bool { 83fn contains_placeholder(a: &ast::MatchArm) -> bool {
84 match a.pat() { 84 matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..)))
85 Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true,
86 _ => false,
87 }
88} 85}
89 86
90#[cfg(test)] 87#[cfg(test)]
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index b279bdeef..0c18df1a9 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -137,10 +137,7 @@ impl ModuleOrigin {
137 } 137 }
138 138
139 pub fn is_inline(&self) -> bool { 139 pub fn is_inline(&self) -> bool {
140 match self { 140 matches!(self, ModuleOrigin::Inline { .. })
141 ModuleOrigin::Inline { .. } => true,
142 ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false,
143 }
144 } 141 }
145 142
146 /// Returns a node which defines this module. 143 /// Returns a node which defines this module.
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 61af5f064..22884522a 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -785,11 +785,7 @@ impl<'a> InferenceContext<'a> {
785 for &check_closures in &[false, true] { 785 for &check_closures in &[false, true] {
786 let param_iter = param_tys.iter().cloned().chain(repeat(Ty::Unknown)); 786 let param_iter = param_tys.iter().cloned().chain(repeat(Ty::Unknown));
787 for (&arg, param_ty) in args.iter().zip(param_iter) { 787 for (&arg, param_ty) in args.iter().zip(param_iter) {
788 let is_closure = match &self.body[arg] { 788 let is_closure = matches!(&self.body[arg], Expr::Lambda { .. });
789 Expr::Lambda { .. } => true,
790 _ => false,
791 };
792
793 if is_closure != check_closures { 789 if is_closure != check_closures {
794 continue; 790 continue;
795 } 791 }
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 414158139..c9513b752 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -620,17 +620,11 @@ pub enum GenericPredicate {
620 620
621impl GenericPredicate { 621impl GenericPredicate {
622 pub fn is_error(&self) -> bool { 622 pub fn is_error(&self) -> bool {
623 match self { 623 matches!(self, GenericPredicate::Error)
624 GenericPredicate::Error => true,
625 _ => false,
626 }
627 } 624 }
628 625
629 pub fn is_implemented(&self) -> bool { 626 pub fn is_implemented(&self) -> bool {
630 match self { 627 matches!(self, GenericPredicate::Implemented(_))
631 GenericPredicate::Implemented(_) => true,
632 _ => false,
633 }
634 } 628 }
635 629
636 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> { 630 pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 3fd08b1e8..886346991 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -312,10 +312,8 @@ fn get_string_representation(expr: &ast::Expr) -> Option<String> {
312} 312}
313 313
314fn is_obvious_param(param_name: &str) -> bool { 314fn is_obvious_param(param_name: &str) -> bool {
315 let is_obvious_param_name = match param_name { 315 let is_obvious_param_name =
316 "predicate" | "value" | "pat" | "rhs" | "other" => true, 316 matches!(param_name, "predicate" | "value" | "pat" | "rhs" | "other");
317 _ => false,
318 };
319 param_name.len() == 1 || is_obvious_param_name 317 param_name.len() == 1 || is_obvious_param_name
320} 318}
321 319
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs
index 5036c1fb0..6907c09e8 100644
--- a/crates/ra_ide/src/join_lines.rs
+++ b/crates/ra_ide/src/join_lines.rs
@@ -165,10 +165,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Opti
165} 165}
166 166
167fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool { 167fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
168 match (left, right) { 168 matches!((left, right), (T![,], T![')']) | (T![,], T![']']))
169 (T![,], T![')']) | (T![,], T![']']) => true,
170 _ => false,
171 }
172} 169}
173 170
174#[cfg(test)] 171#[cfg(test)]
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs
index 6929055b2..5a09e7d1d 100644
--- a/crates/ra_ide_db/src/symbol_index.rs
+++ b/crates/ra_ide_db/src/symbol_index.rs
@@ -346,10 +346,7 @@ impl Query {
346} 346}
347 347
348fn is_type(kind: SyntaxKind) -> bool { 348fn is_type(kind: SyntaxKind) -> bool {
349 match kind { 349 matches!(kind, STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF)
350 STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => true,
351 _ => false,
352 }
353} 350}
354 351
355/// The actual data that is stored in the index. It should be as compact as 352/// The actual data that is stored in the index. It should be as compact as
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs
index 034150432..1e5dafbdf 100644
--- a/crates/ra_mbe/src/parser.rs
+++ b/crates/ra_mbe/src/parser.rs
@@ -137,10 +137,7 @@ fn eat_fragment_kind<'a>(
137} 137}
138 138
139fn is_boolean_literal(lit: &tt::Literal) -> bool { 139fn is_boolean_literal(lit: &tt::Literal) -> bool {
140 match lit.text.as_str() { 140 matches!(lit.text.as_str(), "true" | "false")
141 "true" | "false" => true,
142 _ => false,
143 }
144} 141}
145 142
146fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), ExpandError> { 143fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), ExpandError> {
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index 293baecf6..caedeead0 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -73,10 +73,7 @@ pub(crate) mod fragments {
73 // Parse a meta item , which excluded [], e.g : #[ MetaItem ] 73 // Parse a meta item , which excluded [], e.g : #[ MetaItem ]
74 pub(crate) fn meta_item(p: &mut Parser) { 74 pub(crate) fn meta_item(p: &mut Parser) {
75 fn is_delimiter(p: &mut Parser) -> bool { 75 fn is_delimiter(p: &mut Parser) -> bool {
76 match p.current() { 76 matches!(p.current(), T!['{'] | T!['('] | T!['['])
77 T!['{'] | T!['('] | T!['['] => true,
78 _ => false,
79 }
80 } 77 }
81 78
82 if is_delimiter(p) { 79 if is_delimiter(p) {
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs
index fd51189d5..b503af1dc 100644
--- a/crates/ra_parser/src/grammar/paths.rs
+++ b/crates/ra_parser/src/grammar/paths.rs
@@ -41,10 +41,7 @@ fn path(p: &mut Parser, mode: Mode) {
41 path_segment(p, mode, true); 41 path_segment(p, mode, true);
42 let mut qual = path.complete(p, PATH); 42 let mut qual = path.complete(p, PATH);
43 loop { 43 loop {
44 let use_tree = match p.nth(2) { 44 let use_tree = matches!(p.nth(2), T![*] | T!['{']);
45 T![*] | T!['{'] => true,
46 _ => false,
47 };
48 if p.at(T![::]) && !use_tree { 45 if p.at(T![::]) && !use_tree {
49 let path = qual.precede(p); 46 let path = qual.precede(p);
50 p.bump(T![::]); 47 p.bump(T![::]);
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs
index 325d566ad..d1330d4b9 100644
--- a/crates/ra_parser/src/grammar/type_params.rs
+++ b/crates/ra_parser/src/grammar/type_params.rs
@@ -169,10 +169,7 @@ fn is_where_predicate(p: &mut Parser) -> bool {
169} 169}
170 170
171fn is_where_clause_end(p: &mut Parser) -> bool { 171fn is_where_clause_end(p: &mut Parser) -> bool {
172 match p.current() { 172 matches!(p.current(), T!['{'] | T![;] | T![=])
173 T!['{'] | T![;] | T![=] => true,
174 _ => false,
175 }
176} 173}
177 174
178fn where_predicate(p: &mut Parser) { 175fn where_predicate(p: &mut Parser) {
diff --git a/crates/ra_parser/src/syntax_kind.rs b/crates/ra_parser/src/syntax_kind.rs
index 8d6bd057b..63204436c 100644
--- a/crates/ra_parser/src/syntax_kind.rs
+++ b/crates/ra_parser/src/syntax_kind.rs
@@ -20,9 +20,6 @@ impl From<SyntaxKind> for u16 {
20 20
21impl SyntaxKind { 21impl SyntaxKind {
22 pub fn is_trivia(self) -> bool { 22 pub fn is_trivia(self) -> bool {
23 match self { 23 matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT)
24 SyntaxKind::WHITESPACE | SyntaxKind::COMMENT => true,
25 _ => false,
26 }
27 } 24 }
28} 25}
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 7771d6759..db5438d68 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -399,10 +399,7 @@ impl ast::BlockExpr {
399 Some(it) => it, 399 Some(it) => it,
400 None => return true, 400 None => return true,
401 }; 401 };
402 match parent.kind() { 402 !matches!(parent.kind(), FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR)
403 FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false,
404 _ => true,
405 }
406 } 403 }
407} 404}
408 405
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs
index 98c38d009..662c6f73e 100644
--- a/crates/ra_syntax/src/ast/extensions.rs
+++ b/crates/ra_syntax/src/ast/extensions.rs
@@ -459,16 +459,16 @@ impl ast::RangePat {
459 459
460impl ast::TokenTree { 460impl ast::TokenTree {
461 pub fn left_delimiter_token(&self) -> Option<SyntaxToken> { 461 pub fn left_delimiter_token(&self) -> Option<SyntaxToken> {
462 self.syntax().first_child_or_token()?.into_token().filter(|it| match it.kind() { 462 self.syntax()
463 T!['{'] | T!['('] | T!['['] => true, 463 .first_child_or_token()?
464 _ => false, 464 .into_token()
465 }) 465 .filter(|it| matches!(it.kind(), T!['{'] | T!['('] | T!['[']))
466 } 466 }
467 467
468 pub fn right_delimiter_token(&self) -> Option<SyntaxToken> { 468 pub fn right_delimiter_token(&self) -> Option<SyntaxToken> {
469 self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { 469 self.syntax()
470 T!['}'] | T![')'] | T![']'] => true, 470 .last_child_or_token()?
471 _ => false, 471 .into_token()
472 }) 472 .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']']))
473 } 473 }
474} 474}
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index edbc190f8..ed5a42ea3 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -120,10 +120,7 @@ fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String {
120} 120}
121 121
122fn is_contextual_kw(text: &str) -> bool { 122fn is_contextual_kw(text: &str) -> bool {
123 match text { 123 matches!(text, "auto" | "default" | "union")
124 "auto" | "default" | "union" => true,
125 _ => false,
126 }
127} 124}
128 125
129fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> { 126fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> {
diff --git a/crates/ra_tt/src/buffer.rs b/crates/ra_tt/src/buffer.rs
index 5967f44cd..02c771f70 100644
--- a/crates/ra_tt/src/buffer.rs
+++ b/crates/ra_tt/src/buffer.rs
@@ -105,10 +105,7 @@ impl<'a> Eq for Cursor<'a> {}
105impl<'a> Cursor<'a> { 105impl<'a> Cursor<'a> {
106 /// Check whether it is eof 106 /// Check whether it is eof
107 pub fn eof(self) -> bool { 107 pub fn eof(self) -> bool {
108 match self.buffer.entry(&self.ptr) { 108 matches!(self.buffer.entry(&self.ptr), None | Some(Entry::End(None)))
109 None | Some(Entry::End(None)) => true,
110 _ => false,
111 }
112 } 109 }
113 110
114 /// If the cursor is pointing at the end of a subtree, returns 111 /// If the cursor is pointing at the end of a subtree, returns
diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs
index 39ce77900..c5faec83a 100644
--- a/crates/rust-analyzer/src/cli.rs
+++ b/crates/rust-analyzer/src/cli.rs
@@ -28,16 +28,10 @@ pub enum Verbosity {
28 28
29impl Verbosity { 29impl Verbosity {
30 pub fn is_verbose(self) -> bool { 30 pub fn is_verbose(self) -> bool {
31 match self { 31 matches!(self, Verbosity::Verbose | Verbosity::Spammy)
32 Verbosity::Verbose | Verbosity::Spammy => true,
33 _ => false,
34 }
35 } 32 }
36 pub fn is_spammy(self) -> bool { 33 pub fn is_spammy(self) -> bool {
37 match self { 34 matches!(self, Verbosity::Spammy)
38 Verbosity::Spammy => true,
39 _ => false,
40 }
41 } 35 }
42} 36}
43 37
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 4fe99ff68..930375d3e 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -78,10 +78,7 @@ pub fn analysis_bench(
78 } 78 }
79 } 79 }
80 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => { 80 BenchWhat::Complete(pos) | BenchWhat::GotoDef(pos) => {
81 let is_completion = match what { 81 let is_completion = matches!(what, BenchWhat::Complete(..));
82 BenchWhat::Complete(..) => true,
83 _ => false,
84 };
85 82
86 let offset = host 83 let offset = host
87 .analysis() 84 .analysis()