Skip to content

Commit add40c8

Browse files
committed
match_like_matches_macro
1 parent 2ae2512 commit add40c8

File tree

9 files changed

+29
-43
lines changed

9 files changed

+29
-43
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ field_reassign_with_default = "allow"
175175
forget_non_drop = "allow"
176176
format_collect = "allow"
177177
large_enum_variant = "allow"
178-
match_like_matches_macro = "allow"
179178
match_single_binding = "allow"
180179
needless_borrow = "allow"
181180
needless_doctest_main = "allow"

crates/hir-def/src/db.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,8 @@ fn crate_supports_no_std(db: &dyn DefDatabase, crate_id: CrateId) -> bool {
259259
None => continue,
260260
};
261261

262-
let segments = tt.split(|tt| match tt {
263-
tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ',' => true,
264-
_ => false,
265-
});
262+
let segments =
263+
tt.split(|tt| matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(p)) if p.char == ','));
266264
for output in segments.skip(1) {
267265
match output {
268266
[tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] if ident.text == "no_std" => {

crates/hir-def/src/import_map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ impl Query {
382382
}
383383

384384
fn matches_assoc_mode(&self, is_trait_assoc_item: IsTraitAssocItem) -> bool {
385-
match (is_trait_assoc_item, self.assoc_mode) {
385+
!matches!(
386+
(is_trait_assoc_item, self.assoc_mode),
386387
(IsTraitAssocItem::Yes, AssocSearchMode::Exclude)
387-
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly) => false,
388-
_ => true,
389-
}
388+
| (IsTraitAssocItem::No, AssocSearchMode::AssocItemsOnly)
389+
)
390390
}
391391
}
392392

crates/hir-ty/src/mir/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,10 +1387,10 @@ impl Evaluator<'_> {
13871387
| CastKind::PointerExposeAddress
13881388
| CastKind::PointerFromExposedAddress => {
13891389
let current_ty = self.operand_ty(operand, locals)?;
1390-
let is_signed = match current_ty.kind(Interner) {
1391-
TyKind::Scalar(chalk_ir::Scalar::Int(_)) => true,
1392-
_ => false,
1393-
};
1390+
let is_signed = matches!(
1391+
current_ty.kind(Interner),
1392+
TyKind::Scalar(chalk_ir::Scalar::Int(_))
1393+
);
13941394
let current = pad16(self.eval_operand(operand, locals)?.get(self)?, is_signed);
13951395
let dest_size =
13961396
self.size_of_sized(target_ty, locals, "destination of int to int cast")?;

crates/hir/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,14 +2495,7 @@ impl Trait {
24952495
db.generic_params(GenericDefId::from(self.id))
24962496
.type_or_consts
24972497
.iter()
2498-
.filter(|(_, ty)| match ty {
2499-
TypeOrConstParamData::TypeParamData(ty)
2500-
if ty.provenance != TypeParamProvenance::TypeParamList =>
2501-
{
2502-
false
2503-
}
2504-
_ => true,
2505-
})
2498+
.filter(|(_, ty)| !matches!(ty, TypeOrConstParamData::TypeParamData(ty) if ty.provenance != TypeParamProvenance::TypeParamList))
25062499
.filter(|(_, ty)| !count_required_only || !ty.has_default())
25072500
.count()
25082501
}
@@ -3872,10 +3865,7 @@ impl Type {
38723865
}
38733866

38743867
pub fn is_int_or_uint(&self) -> bool {
3875-
match self.ty.kind(Interner) {
3876-
TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_)) => true,
3877-
_ => false,
3878-
}
3868+
matches!(self.ty.kind(Interner), TyKind::Scalar(Scalar::Int(_) | Scalar::Uint(_)))
38793869
}
38803870

38813871
pub fn is_scalar(&self) -> bool {

crates/ide-assists/src/utils/suggest_name.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ fn normalize(name: &str) -> Option<String> {
185185
}
186186

187187
fn is_valid_name(name: &str) -> bool {
188-
match ide_db::syntax_helpers::LexedStr::single_token(name) {
189-
Some((syntax::SyntaxKind::IDENT, _error)) => true,
190-
_ => false,
191-
}
188+
matches!(
189+
ide_db::syntax_helpers::LexedStr::single_token(name),
190+
Some((syntax::SyntaxKind::IDENT, _error))
191+
)
192192
}
193193

194194
fn is_useless_method(method: &ast::MethodCallExpr) -> bool {

crates/ide-completion/src/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,13 @@ impl TypeLocation {
186186
}
187187

188188
pub(crate) fn complete_consts(&self) -> bool {
189-
match self {
189+
matches!(
190+
self,
190191
TypeLocation::GenericArg {
191192
corresponding_param: Some(ast::GenericParam::ConstParam(_)),
192193
..
193-
} => true,
194-
TypeLocation::AssocConstEq => true,
195-
_ => false,
196-
}
194+
} | TypeLocation::AssocConstEq
195+
)
197196
}
198197

199198
pub(crate) fn complete_types(&self) -> bool {

crates/ide-completion/src/render/literal.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ fn render(
5757
) -> Option<Builder> {
5858
let db = completion.db;
5959
let mut kind = thing.kind(db);
60-
let should_add_parens = match &path_ctx {
61-
PathCompletionCtx { has_call_parens: true, .. } => false,
62-
PathCompletionCtx { kind: PathKind::Use | PathKind::Type { .. }, .. } => false,
63-
_ => true,
64-
};
60+
let should_add_parens = !matches!(
61+
path_ctx,
62+
PathCompletionCtx { has_call_parens: true, .. }
63+
| PathCompletionCtx { kind: PathKind::Use | PathKind::Type { .. }, .. }
64+
);
6565

6666
let fields = thing.fields(completion)?;
6767
let (qualified_name, short_qualified_name, qualified) = match path {

crates/ide-db/src/symbol_index.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ impl Query {
383383
}
384384

385385
fn matches_assoc_mode(&self, is_trait_assoc_item: bool) -> bool {
386-
match (is_trait_assoc_item, self.assoc_mode) {
387-
(true, AssocSearchMode::Exclude) | (false, AssocSearchMode::AssocItemsOnly) => false,
388-
_ => true,
389-
}
386+
!matches!(
387+
(is_trait_assoc_item, self.assoc_mode),
388+
(true, AssocSearchMode::Exclude) | (false, AssocSearchMode::AssocItemsOnly)
389+
)
390390
}
391391
}
392392

0 commit comments

Comments
 (0)