Skip to content

Commit e75e2ae

Browse files
committed
Simlify with matches!()
1 parent 513924a commit e75e2ae

File tree

20 files changed

+32
-98
lines changed

20 files changed

+32
-98
lines changed

crates/ra_assists/src/handlers/change_visibility.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ pub(crate) fn change_visibility(acc: &mut Assists, ctx: &AssistContext) -> Optio
3030
}
3131

3232
fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
33-
let item_keyword = ctx.token_at_offset().find(|leaf| match leaf.kind() {
34-
T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait] => true,
35-
_ => false,
33+
let item_keyword = ctx.token_at_offset().find(|leaf| {
34+
matches!(leaf.kind(), T![const] | T![fn] | T![mod] | T![struct] | T![enum] | T![trait])
3635
});
3736

3837
let (offset, target) = if let Some(keyword) = item_keyword {
@@ -73,11 +72,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
7372

7473
fn vis_offset(node: &SyntaxNode) -> TextSize {
7574
node.children_with_tokens()
76-
.skip_while(|it| match it.kind() {
77-
WHITESPACE | COMMENT | ATTR => true,
78-
_ => false,
79-
})
80-
.next()
75+
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
8176
.map(|it| it.text_range().start())
8277
.unwrap_or_else(|| node.text_range().start())
8378
}

crates/ra_assists/src/handlers/fix_visibility.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,7 @@ fn target_data_for_def(
179179

180180
fn vis_offset(node: &SyntaxNode) -> TextSize {
181181
node.children_with_tokens()
182-
.skip_while(|it| match it.kind() {
183-
WHITESPACE | COMMENT | ATTR => true,
184-
_ => false,
185-
})
186-
.next()
182+
.find(|it| !matches!(it.kind(), WHITESPACE | COMMENT | ATTR))
187183
.map(|it| it.text_range().start())
188184
.unwrap_or_else(|| node.text_range().start())
189185
}

crates/ra_assists/src/handlers/merge_match_arms.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
8181
}
8282

8383
fn contains_placeholder(a: &ast::MatchArm) -> bool {
84-
match a.pat() {
85-
Some(ra_syntax::ast::Pat::PlaceholderPat(..)) => true,
86-
_ => false,
87-
}
84+
matches!(a.pat(), Some(ra_syntax::ast::Pat::PlaceholderPat(..)))
8885
}
8986

9087
#[cfg(test)]

crates/ra_hir_def/src/nameres.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ impl ModuleOrigin {
137137
}
138138

139139
pub fn is_inline(&self) -> bool {
140-
match self {
141-
ModuleOrigin::Inline { .. } => true,
142-
ModuleOrigin::CrateRoot { .. } | ModuleOrigin::File { .. } => false,
143-
}
140+
matches!(self, ModuleOrigin::Inline { .. })
144141
}
145142

146143
/// Returns a node which defines this module.

crates/ra_hir_ty/src/infer/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,11 +785,7 @@ impl<'a> InferenceContext<'a> {
785785
for &check_closures in &[false, true] {
786786
let param_iter = param_tys.iter().cloned().chain(repeat(Ty::Unknown));
787787
for (&arg, param_ty) in args.iter().zip(param_iter) {
788-
let is_closure = match &self.body[arg] {
789-
Expr::Lambda { .. } => true,
790-
_ => false,
791-
};
792-
788+
let is_closure = matches!(&self.body[arg], Expr::Lambda { .. });
793789
if is_closure != check_closures {
794790
continue;
795791
}

crates/ra_hir_ty/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -620,17 +620,11 @@ pub enum GenericPredicate {
620620

621621
impl GenericPredicate {
622622
pub fn is_error(&self) -> bool {
623-
match self {
624-
GenericPredicate::Error => true,
625-
_ => false,
626-
}
623+
matches!(self, GenericPredicate::Error)
627624
}
628625

629626
pub fn is_implemented(&self) -> bool {
630-
match self {
631-
GenericPredicate::Implemented(_) => true,
632-
_ => false,
633-
}
627+
matches!(self, GenericPredicate::Implemented(_))
634628
}
635629

636630
pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> {

crates/ra_ide/src/inlay_hints.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,8 @@ fn get_string_representation(expr: &ast::Expr) -> Option<String> {
312312
}
313313

314314
fn is_obvious_param(param_name: &str) -> bool {
315-
let is_obvious_param_name = match param_name {
316-
"predicate" | "value" | "pat" | "rhs" | "other" => true,
317-
_ => false,
318-
};
315+
let is_obvious_param_name =
316+
matches!(param_name, "predicate" | "value" | "pat" | "rhs" | "other");
319317
param_name.len() == 1 || is_obvious_param_name
320318
}
321319

crates/ra_ide/src/join_lines.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Opti
165165
}
166166

167167
fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
168-
match (left, right) {
169-
(T![,], T![')']) | (T![,], T![']']) => true,
170-
_ => false,
171-
}
168+
matches!((left, right), (T![,], T![')']) | (T![,], T![']']))
172169
}
173170

174171
#[cfg(test)]

crates/ra_ide_db/src/symbol_index.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@ impl Query {
346346
}
347347

348348
fn is_type(kind: SyntaxKind) -> bool {
349-
match kind {
350-
STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => true,
351-
_ => false,
352-
}
349+
matches!(kind, STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF)
353350
}
354351

355352
/// The actual data that is stored in the index. It should be as compact as

crates/ra_mbe/src/parser.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,7 @@ fn eat_fragment_kind<'a>(
137137
}
138138

139139
fn is_boolean_literal(lit: &tt::Literal) -> bool {
140-
match lit.text.as_str() {
141-
"true" | "false" => true,
142-
_ => false,
143-
}
140+
matches!(lit.text.as_str(), "true" | "false")
144141
}
145142

146143
fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), ExpandError> {

0 commit comments

Comments
 (0)