diff --git a/Cargo.toml b/Cargo.toml index e7ee98512fe7..2547f1ccb991 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -178,7 +178,6 @@ new_without_default = "allow" non_canonical_clone_impl = "allow" non_canonical_partial_ord_impl = "allow" self_named_constructors = "allow" -single_match = "allow" skip_while_next = "allow" too_many_arguments = "allow" toplevel_ref_arg = "allow" diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index 6c09a672334a..f1bf162bc6bf 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -114,34 +114,26 @@ impl ExprValidator { ) { // Check that the number of arguments matches the number of parameters. - // FIXME: Due to shortcomings in the current type system implementation, only emit this - // diagnostic if there are no type mismatches in the containing function. if self.infer.expr_type_mismatches().next().is_some() { - return; - } - - match expr { - Expr::MethodCall { receiver, .. } => { - let (callee, _) = match self.infer.method_resolution(call_id) { - Some(it) => it, - None => return, - }; - - if filter_map_next_checker - .get_or_insert_with(|| { - FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db) - }) - .check(call_id, receiver, &callee) - .is_some() - { - self.diagnostics.push( - BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { - method_call_expr: call_id, - }, - ); - } + // FIXME: Due to shortcomings in the current type system implementation, only emit + // this diagnostic if there are no type mismatches in the containing function. + } else if let Expr::MethodCall { receiver, .. } = expr { + let (callee, _) = match self.infer.method_resolution(call_id) { + Some(it) => it, + None => return, + }; + + if filter_map_next_checker + .get_or_insert_with(|| { + FilterMapNextChecker::new(&self.owner.resolver(db.upcast()), db) + }) + .check(call_id, receiver, &callee) + .is_some() + { + self.diagnostics.push(BodyValidationDiagnostic::ReplaceFilterMapNextWithFindMap { + method_call_expr: call_id, + }); } - _ => (), } } diff --git a/crates/hir-ty/src/infer/closure.rs b/crates/hir-ty/src/infer/closure.rs index 12039173dd84..572df8f71374 100644 --- a/crates/hir-ty/src/infer/closure.rs +++ b/crates/hir-ty/src/infer/closure.rs @@ -142,13 +142,10 @@ impl HirPlace { mut current_capture: CaptureKind, len: usize, ) -> CaptureKind { - match current_capture { - CaptureKind::ByRef(BorrowKind::Mut { .. }) => { - if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) { - current_capture = CaptureKind::ByRef(BorrowKind::Unique); - } + if let CaptureKind::ByRef(BorrowKind::Mut { .. }) = current_capture { + if self.projections[len..].iter().any(|it| *it == ProjectionElem::Deref) { + current_capture = CaptureKind::ByRef(BorrowKind::Unique); } - _ => (), } current_capture } diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index 186921ae7a48..f7d043fc4e6a 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -339,11 +339,8 @@ fn push_mut_span(local: LocalId, span: MirSpan, result: &mut ArenaMap) { - match &mut result[local] { - it @ MutabilityReason::Unused => { - *it = MutabilityReason::Not; - } - _ => (), + if let it @ MutabilityReason::Unused = &mut result[local] { + *it = MutabilityReason::Not; }; } diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index d320dcdad28a..99930798e87a 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -288,12 +288,9 @@ impl<'ctx> MirLowerCtx<'ctx> { current: BasicBlockId, ) -> Result> { if !self.has_adjustments(expr_id) { - match &self.body.exprs[expr_id] { - Expr::Literal(l) => { - let ty = self.expr_ty_without_adjust(expr_id); - return Ok(Some((self.lower_literal_to_operand(ty, l)?, current))); - } - _ => (), + if let Expr::Literal(l) = &self.body.exprs[expr_id] { + let ty = self.expr_ty_without_adjust(expr_id); + return Ok(Some((self.lower_literal_to_operand(ty, l)?, current))); } } let Some((p, current)) = self.lower_expr_as_place(current, expr_id, true)? else { diff --git a/crates/ide-assists/src/handlers/extract_module.rs b/crates/ide-assists/src/handlers/extract_module.rs index 3bc13bde2652..30c3983dc411 100644 --- a/crates/ide-assists/src/handlers/extract_module.rs +++ b/crates/ide-assists/src/handlers/extract_module.rs @@ -689,27 +689,22 @@ fn does_source_exists_outside_sel_in_same_mod( match def { Definition::Module(x) => { let source = x.definition_source(ctx.db()); - let have_same_parent; - if let Some(ast_module) = &curr_parent_module { + let have_same_parent = if let Some(ast_module) = &curr_parent_module { if let Some(hir_module) = x.parent(ctx.db()) { - have_same_parent = - compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some(); + compare_hir_and_ast_module(ast_module, hir_module, ctx).is_some() } else { let source_file_id = source.file_id.original_file(ctx.db()); - have_same_parent = source_file_id == curr_file_id; + source_file_id == curr_file_id } } else { let source_file_id = source.file_id.original_file(ctx.db()); - have_same_parent = source_file_id == curr_file_id; - } + source_file_id == curr_file_id + }; if have_same_parent { - match source.value { - ModuleSource::Module(module_) => { - source_exists_outside_sel_in_same_mod = - !selection_range.contains_range(module_.syntax().text_range()); - } - _ => {} + if let ModuleSource::Module(module_) = source.value { + source_exists_outside_sel_in_same_mod = + !selection_range.contains_range(module_.syntax().text_range()); } } } diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index f5153b8f1f19..154a1f59c722 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -270,19 +270,16 @@ fn generate_impl( make::path_from_text(&format!("<{} as {}>", field_ty, delegate.trait_()?)); let delegate_assoc_items = delegate.get_or_create_assoc_item_list(); - match bound_def.assoc_item_list() { - Some(ai) => { - ai.assoc_items() - .filter(|item| matches!(item, AssocItem::MacroCall(_)).not()) - .for_each(|item| { - let assoc = - process_assoc_item(item, qualified_path_type.clone(), field_name); - if let Some(assoc) = assoc { - delegate_assoc_items.add_item(assoc); - } - }); - } - None => {} + if let Some(ai) = bound_def.assoc_item_list() { + ai.assoc_items() + .filter(|item| matches!(item, AssocItem::MacroCall(_)).not()) + .for_each(|item| { + let assoc = + process_assoc_item(item, qualified_path_type.clone(), field_name); + if let Some(assoc) = assoc { + delegate_assoc_items.add_item(assoc); + } + }); }; let target_scope = ctx.sema.scope(strukt.strukt.syntax())?; @@ -512,17 +509,14 @@ fn generate_args_for_impl( // form the substitution list let mut arg_substs = FxHashMap::default(); - match field_ty { - field_ty @ ast::Type::PathType(_) => { - let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args()); - let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args()); - if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) { - self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| { - arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg); - }) - } + if let field_ty @ ast::Type::PathType(_) = field_ty { + let field_args = field_ty.generic_arg_list().map(|gal| gal.generic_args()); + let self_ty_args = self_ty.generic_arg_list().map(|gal| gal.generic_args()); + if let (Some(field_args), Some(self_ty_args)) = (field_args, self_ty_args) { + self_ty_args.zip(field_args).for_each(|(self_ty_arg, field_arg)| { + arg_substs.entry(self_ty_arg.to_string()).or_insert(field_arg); + }) } - _ => {} } let args = old_impl_args diff --git a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs index 8f61b43cd0f7..a8817436ba1f 100644 --- a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs +++ b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs @@ -181,21 +181,18 @@ fn remove_items_visibility(item: &ast::AssocItem) { } fn strip_body(item: &ast::AssocItem) { - match item { - ast::AssocItem::Fn(f) => { - if let Some(body) = f.body() { - // In constrast to function bodies, we want to see no ws before a semicolon. - // So let's remove them if we see any. - if let Some(prev) = body.syntax().prev_sibling_or_token() { - if prev.kind() == SyntaxKind::WHITESPACE { - ted::remove(prev); - } + if let ast::AssocItem::Fn(f) = item { + if let Some(body) = f.body() { + // In constrast to function bodies, we want to see no ws before a semicolon. + // So let's remove them if we see any. + if let Some(prev) = body.syntax().prev_sibling_or_token() { + if prev.kind() == SyntaxKind::WHITESPACE { + ted::remove(prev); } - - ted::replace(body.syntax(), make::tokens::semicolon()); } + + ted::replace(body.syntax(), make::tokens::semicolon()); } - _ => (), }; } diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index bb87b9b6c912..4ba33ada48c7 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -425,8 +425,8 @@ fn inline( if is_self { let mut this_pat = make::ident_pat(false, false, make::name("this")); let mut expr = expr.clone(); - match pat { - Pat::IdentPat(pat) => match (pat.ref_token(), pat.mut_token()) { + if let Pat::IdentPat(pat) = pat { + match (pat.ref_token(), pat.mut_token()) { // self => let this = obj (None, None) => {} // mut self => let mut this = obj @@ -449,8 +449,7 @@ fn inline( make::expr_ref(expr, true) }; } - }, - _ => {} + } }; let_stmts .push(make::let_stmt(this_pat.into(), ty, Some(expr)).clone_for_update().into()) diff --git a/crates/ide-completion/src/completions/field.rs b/crates/ide-completion/src/completions/field.rs index 870df63b7bf2..53fcb7ca6c02 100644 --- a/crates/ide-completion/src/completions/field.rs +++ b/crates/ide-completion/src/completions/field.rs @@ -11,22 +11,18 @@ pub(crate) fn complete_field_list_tuple_variant( path_ctx: &PathCompletionCtx, ) { if ctx.qualifier_ctx.vis_node.is_some() { - return; - } - match path_ctx { - PathCompletionCtx { - has_macro_bang: false, - qualified: Qualified::No, - parent: None, - has_type_args: false, - .. - } => { - let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet); - add_keyword("pub(crate)", "pub(crate)"); - add_keyword("pub(super)", "pub(super)"); - add_keyword("pub", "pub"); - } - _ => (), + } else if let PathCompletionCtx { + has_macro_bang: false, + qualified: Qualified::No, + parent: None, + has_type_args: false, + .. + } = path_ctx + { + let mut add_keyword = |kw, snippet| acc.add_keyword_snippet(ctx, kw, snippet); + add_keyword("pub(crate)", "pub(crate)"); + add_keyword("pub(super)", "pub(super)"); + add_keyword("pub", "pub"); } } diff --git a/crates/ide-completion/src/completions/flyimport.rs b/crates/ide-completion/src/completions/flyimport.rs index 3cb090da1ab7..e330430d6b90 100644 --- a/crates/ide-completion/src/completions/flyimport.rs +++ b/crates/ide-completion/src/completions/flyimport.rs @@ -369,11 +369,10 @@ fn import_on_the_fly_method( }; key(&a.import_path).cmp(&key(&b.import_path)) }) - .for_each(|import| match import.original_item { - ItemInNs::Values(hir::ModuleDef::Function(f)) => { + .for_each(|import| { + if let ItemInNs::Values(hir::ModuleDef::Function(f)) = import.original_item { acc.add_method_with_import(ctx, dot_access, f, import); } - _ => (), }); Some(()) } diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 9f5c011dc39d..6fd988bfc0fc 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -295,15 +295,12 @@ fn render_resolution_pat( let _p = profile::span("render_resolution"); use hir::ModuleDef::*; - match resolution { - ScopeDef::ModuleDef(Macro(mac)) => { - let ctx = ctx.import_to_add(import_to_add); - return render_macro_pat(ctx, pattern_ctx, local_name, mac); - } - _ => (), + if let ScopeDef::ModuleDef(Macro(mac)) = resolution { + let ctx = ctx.import_to_add(import_to_add); + render_macro_pat(ctx, pattern_ctx, local_name, mac) + } else { + render_resolution_simple_(ctx, &local_name, import_to_add, resolution) } - - render_resolution_simple_(ctx, &local_name, import_to_add, resolution) } fn render_resolution_path( diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 307812156e92..3607c486d7d3 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -282,8 +282,8 @@ fn traverse( inside_attribute = false } - Enter(NodeOrToken::Node(node)) => match ast::Item::cast(node.clone()) { - Some(item) => { + Enter(NodeOrToken::Node(node)) => { + if let Some(item) = ast::Item::cast(node.clone()) { match item { ast::Item::MacroRules(mac) => { macro_highlighter.init(); @@ -324,8 +324,7 @@ fn traverse( } } } - _ => (), - }, + } Leave(NodeOrToken::Node(node)) if ast::Item::can_cast(node.kind()) => { match ast::Item::cast(node.clone()) { Some(ast::Item::MacroRules(mac)) => { diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index 82712c9ae012..969211f44007 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs @@ -567,10 +567,11 @@ impl GlobalState { for ws in &self.fetch_build_data_queue.last_op_result().1 { match ws { - Ok(data) => match data.error() { - Some(stderr) => stdx::format_to!(buf, "{:#}\n", stderr), - _ => (), - }, + Ok(data) => { + if let Some(stderr) = data.error() { + stdx::format_to!(buf, "{:#}\n", stderr) + } + } // io errors Err(err) => stdx::format_to!(buf, "{:#}\n", err), }