Skip to content

Commit b1a0c9a

Browse files
committed
single_match
1 parent 9dd07f0 commit b1a0c9a

File tree

14 files changed

+90
-131
lines changed

14 files changed

+90
-131
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ new_without_default = "allow"
178178
non_canonical_clone_impl = "allow"
179179
non_canonical_partial_ord_impl = "allow"
180180
self_named_constructors = "allow"
181-
single_match = "allow"
182181
skip_while_next = "allow"
183182
too_many_arguments = "allow"
184183
toplevel_ref_arg = "allow"

crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,26 @@ impl ExprValidator {
114114
) {
115115
// Check that the number of arguments matches the number of parameters.
116116

117-
// FIXME: Due to shortcomings in the current type system implementation, only emit this
118-
// diagnostic if there are no type mismatches in the containing function.
119117
if self.infer.expr_type_mismatches().next().is_some() {
120-
return;
121-
}
122-
123-
match expr {
124-
Expr::MethodCall { receiver, .. } => {
125-
let (callee, _) = match self.infer.method_resolution(call_id) {
126-
Some(it) => it,
127-
None => return,
128-
};
129-
130-
if filter_map_next_checker
131-
.get_or_insert_with(|| {
132-
FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db)
133-
})
134-
.check(call_id, receiver, &callee)
135-
.is_some()
136-
{
137-
self.diagnostics.push(
138-
BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap {
139-
method_call_expr: call_id,
140-
},
141-
);
142-
}
118+
// FIXME: Due to shortcomings in the current type system implementation, only emit
119+
// this diagnostic if there are no type mismatches in the containing function.
120+
} else if let Expr::MethodCall { receiver, .. } = expr {
121+
let (callee, _) = match self.infer.method_resolution(call_id) {
122+
Some(it) => it,
123+
None => return,
124+
};
125+
126+
if filter_map_next_checker
127+
.get_or_insert_with(|| {
128+
FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db)
129+
})
130+
.check(call_id, receiver, &callee)
131+
.is_some()
132+
{
133+
self.diagnostics.push(BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap {
134+
method_call_expr: call_id,
135+
});
143136
}
144-
_ => (),
145137
}
146138
}
147139

crates/hir-ty/src/infer/closure.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,10 @@ impl HirPlace {
142142
mut current_capture: CaptureKind,
143143
len: usize,
144144
) -> CaptureKind {
145-
match current_capture {
146-
CaptureKind::ByRef(BorrowKind::Mut { .. }) => {
147-
if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
148-
current_capture = CaptureKind::ByRef(BorrowKind::Unique);
149-
}
145+
if let CaptureKind::ByRef(BorrowKind::Mut { .. }) = current_capture {
146+
if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) {
147+
current_capture = CaptureKind::ByRef(BorrowKind::Unique);
150148
}
151-
_ => (),
152149
}
153150
current_capture
154151
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,8 @@ fn push_mut_span(local: LocalId, span: MirSpan, result: &mut ArenaMap<LocalId, M
339339
}
340340

341341
fn record_usage(local: LocalId, result: &mut ArenaMap<LocalId, MutabilityReason>) {
342-
match &mut result[local] {
343-
it @ MutabilityReason::Unused => {
344-
*it = MutabilityReason::Not;
345-
}
346-
_ => (),
342+
if let it @ MutabilityReason::Unused = &mut result[local] {
343+
*it = MutabilityReason::Not;
347344
};
348345
}
349346

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,9 @@ impl<'ctx> MirLowerCtx<'ctx> {
288288
current: BasicBlockId,
289289
) -> Result<Option<(Operand, BasicBlockId)>> {
290290
if !self.has_adjustments(expr_id) {
291-
match &self.body.exprs[expr_id] {
292-
Expr::Literal(l) => {
293-
let ty = self.expr_ty_without_adjust(expr_id);
294-
return Ok(Some((self.lower_literal_to_operand(ty, l)?, current)));
295-
}
296-
_ => (),
291+
if let Expr::Literal(l) = &self.body.exprs[expr_id] {
292+
let ty = self.expr_ty_without_adjust(expr_id);
293+
return Ok(Some((self.lower_literal_to_operand(ty, l)?, current)));
297294
}
298295
}
299296
let Some((p, current)) = self.lower_expr_as_place(current, expr_id, true)? else {

crates/ide-assists/src/handlers/extract_module.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -689,27 +689,22 @@ fn does_source_exists_outside_sel_in_same_mod(
689689
match def {
690690
Definition::Module(x) => {
691691
let source = x.definition_source(ctx.db());
692-
let have_same_parent;
693-
if let Some(ast_module) = &curr_parent_module {
692+
let have_same_parent = if let Some(ast_module) = &curr_parent_module {
694693
if let Some(hir_module) = x.parent(ctx.db()) {
695-
have_same_parent =
696-
compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some();
694+
compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some()
697695
} else {
698696
let source_file_id = source.file_id.original_file(ctx.db());
699-
have_same_parent = source_file_id == curr_file_id;
697+
source_file_id == curr_file_id
700698
}
701699
} else {
702700
let source_file_id = source.file_id.original_file(ctx.db());
703-
have_same_parent = source_file_id == curr_file_id;
704-
}
701+
source_file_id == curr_file_id
702+
};
705703

706704
if have_same_parent {
707-
match source.value {
708-
ModuleSource::Module(module_) => {
709-
source_exists_outside_sel_in_same_mod =
710-
!selection_range.contains_range(module_.syntax().text_range());
711-
}
712-
_ => {}
705+
if let ModuleSource::Module(module_) = source.value {
706+
source_exists_outside_sel_in_same_mod =
707+
!selection_range.contains_range(module_.syntax().text_range());
713708
}
714709
}
715710
}

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -270,19 +270,16 @@ fn generate_impl(
270270
make::path_from_text(&format!("<{} as {}>", field_ty, delegate.trait_()?));
271271

272272
let delegate_assoc_items = delegate.get_or_create_assoc_item_list();
273-
match bound_def.assoc_item_list() {
274-
Some(ai) => {
275-
ai.assoc_items()
276-
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
277-
.for_each(|item| {
278-
let assoc =
279-
process_assoc_item(item, qualified_path_type.clone(), field_name);
280-
if let Some(assoc) = assoc {
281-
delegate_assoc_items.add_item(assoc);
282-
}
283-
});
284-
}
285-
None => {}
273+
if let Some(ai) = bound_def.assoc_item_list() {
274+
ai.assoc_items()
275+
.filter(|item| matches!(item, AssocItem::MacroCall(_)).not())
276+
.for_each(|item| {
277+
let assoc =
278+
process_assoc_item(item, qualified_path_type.clone(), field_name);
279+
if let Some(assoc) = assoc {
280+
delegate_assoc_items.add_item(assoc);
281+
}
282+
});
286283
};
287284

288285
let target_scope = ctx.sema.scope(strukt.strukt.syntax())?;
@@ -512,17 +509,14 @@ fn generate_args_for_impl(
512509
// form the substitution list
513510
let mut arg_substs = FxHashMap::default();
514511

515-
match field_ty {
516-
field_ty @ ast::Type::PathType(_) => {
517-
let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args());
518-
let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args());
519-
if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) {
520-
self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| {
521-
arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg);
522-
})
523-
}
512+
if let field_ty @ ast::Type::PathType(_) = field_ty {
513+
let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args());
514+
let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args());
515+
if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) {
516+
self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| {
517+
arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg);
518+
})
524519
}
525-
_ => {}
526520
}
527521

528522
let args = old_impl_args

crates/ide-assists/src/handlers/generate_trait_from_impl.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,18 @@ fn remove_items_visibility(item: &ast::AssocItem) {
181181
}
182182

183183
fn strip_body(item: &ast::AssocItem) {
184-
match item {
185-
ast::AssocItem::Fn(f) => {
186-
if let Some(body) = f.body() {
187-
// In constrast to function bodies, we want to see no ws before a semicolon.
188-
// So let's remove them if we see any.
189-
if let Some(prev) = body.syntax().prev_sibling_or_token() {
190-
if prev.kind() == SyntaxKind::WHITESPACE {
191-
ted::remove(prev);
192-
}
184+
if let ast::AssocItem::Fn(f) = item {
185+
if let Some(body) = f.body() {
186+
// In constrast to function bodies, we want to see no ws before a semicolon.
187+
// So let's remove them if we see any.
188+
if let Some(prev) = body.syntax().prev_sibling_or_token() {
189+
if prev.kind() == SyntaxKind::WHITESPACE {
190+
ted::remove(prev);
193191
}
194-
195-
ted::replace(body.syntax(), make::tokens::semicolon());
196192
}
193+
194+
ted::replace(body.syntax(), make::tokens::semicolon());
197195
}
198-
_ => (),
199196
};
200197
}
201198

crates/ide-assists/src/handlers/inline_call.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ fn inline(
425425
if is_self {
426426
let mut this_pat = make::ident_pat(false, false, make::name("this"));
427427
let mut expr = expr.clone();
428-
match pat {
429-
Pat::IdentPat(pat) => match (pat.ref_token(), pat.mut_token()) {
428+
if let Pat::IdentPat(pat) = pat {
429+
match (pat.ref_token(), pat.mut_token()) {
430430
// self => let this = obj
431431
(None, None) => {}
432432
// mut self => let mut this = obj
@@ -449,8 +449,7 @@ fn inline(
449449
make::expr_ref(expr, true)
450450
};
451451
}
452-
},
453-
_ => {}
452+
}
454453
};
455454
let_stmts
456455
.push(make::let_stmt(this_pat.into(), ty, Some(expr)).clone_for_update().into())

crates/ide-completion/src/completions/field.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@ pub(crate) fn complete_field_list_tuple_variant(
1111
path_ctx: &PathCompletionCtx,
1212
) {
1313
if ctx.qualifier_ctx.vis_node.is_some() {
14-
return;
15-
}
16-
match path_ctx {
17-
PathCompletionCtx {
18-
has_macro_bang: false,
19-
qualified: Qualified::No,
20-
parent: None,
21-
has_type_args: false,
22-
..
23-
} => {
24-
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
25-
add_keyword("pub(crate)", "pub(crate)");
26-
add_keyword("pub(super)", "pub(super)");
27-
add_keyword("pub", "pub");
28-
}
29-
_ => (),
14+
} else if let PathCompletionCtx {
15+
has_macro_bang: false,
16+
qualified: Qualified::No,
17+
parent: None,
18+
has_type_args: false,
19+
..
20+
} = path_ctx
21+
{
22+
let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet);
23+
add_keyword("pub(crate)", "pub(crate)");
24+
add_keyword("pub(super)", "pub(super)");
25+
add_keyword("pub", "pub");
3026
}
3127
}
3228

crates/ide-completion/src/completions/flyimport.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,10 @@ fn import_on_the_fly_method(
369369
};
370370
key(&a.import_path).cmp(&key(&b.import_path))
371371
})
372-
.for_each(|import| match import.original_item {
373-
ItemInNs::Values(hir::ModuleDef::Function(f)) => {
372+
.for_each(|import| {
373+
if let ItemInNs::Values(hir::ModuleDef::Function(f)) = import.original_item {
374374
acc.add_method_with_import(ctx, dot_access, f, import);
375375
}
376-
_ => (),
377376
});
378377
Some(())
379378
}

crates/ide-completion/src/render.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,12 @@ fn render_resolution_pat(
295295
let _p = profile::span("render_resolution");
296296
use hir::ModuleDef::*;
297297

298-
match resolution {
299-
ScopeDef::ModuleDef(Macro(mac)) => {
300-
let ctx = ctx.import_to_add(import_to_add);
301-
return render_macro_pat(ctx, pattern_ctx, local_name, mac);
302-
}
303-
_ => (),
298+
if let ScopeDef::ModuleDef(Macro(mac)) = resolution {
299+
let ctx = ctx.import_to_add(import_to_add);
300+
render_macro_pat(ctx, pattern_ctx, local_name, mac)
301+
} else {
302+
render_resolution_simple_(ctx, &local_name, import_to_add, resolution)
304303
}
305-
306-
render_resolution_simple_(ctx, &local_name, import_to_add, resolution)
307304
}
308305

309306
fn render_resolution_path(

crates/ide/src/syntax_highlighting.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ fn traverse(
282282
inside_attribute = false
283283
}
284284

285-
Enter(NodeOrToken::Node(node)) => match ast::Item::cast(node.clone()) {
286-
Some(item) => {
285+
Enter(NodeOrToken::Node(node)) => {
286+
if let Some(item) = ast::Item::cast(node.clone()) {
287287
match item {
288288
ast::Item::MacroRules(mac) => {
289289
macro_highlighter.init();
@@ -324,8 +324,7 @@ fn traverse(
324324
}
325325
}
326326
}
327-
_ => (),
328-
},
327+
}
329328
Leave(NodeOrToken::Node(node)) if ast::Item::can_cast(node.kind()) => {
330329
match ast::Item::cast(node.clone()) {
331330
Some(ast::Item::MacroRules(mac)) => {

crates/rust-analyzer/src/reload.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,11 @@ impl GlobalState {
567567

568568
for ws in &self.fetch_build_data_queue.last_op_result().1 {
569569
match ws {
570-
Ok(data) => match data.error() {
571-
Some(stderr) => stdx::format_to!(buf, "{:#}\n", stderr),
572-
_ => (),
573-
},
570+
Ok(data) => {
571+
if let Some(stderr) = data.error() {
572+
stdx::format_to!(buf, "{:#}\n", stderr)
573+
}
574+
}
574575
// io errors
575576
Err(err) => stdx::format_to!(buf, "{:#}\n", err),
576577
}

0 commit comments

Comments
 (0)