about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohann Hemmann <johann.hemmann@code.berlin>2024-01-19 18:31:15 +0100
committerJohann Hemmann <johann.hemmann@code.berlin>2024-01-19 18:31:15 +0100
commitb1a0c9ac403dd2fba7d06ce1931ceebaa2d41889 (patch)
treee6787d572f094607ee8e02d6be67e0baca871430
parent9dd07f0bc48e9e2af0d7af8df82660040f06f372 (diff)
downloadrust-b1a0c9ac403dd2fba7d06ce1931ceebaa2d41889.tar.gz
rust-b1a0c9ac403dd2fba7d06ce1931ceebaa2d41889.zip
single_match
-rw-r--r--Cargo.toml1
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs44
-rw-r--r--crates/hir-ty/src/infer/closure.rs9
-rw-r--r--crates/hir-ty/src/mir/borrowck.rs7
-rw-r--r--crates/hir-ty/src/mir/lower.rs9
-rw-r--r--crates/ide-assists/src/handlers/extract_module.rs21
-rw-r--r--crates/ide-assists/src/handlers/generate_delegate_trait.rs40
-rw-r--r--crates/ide-assists/src/handlers/generate_trait_from_impl.rs21
-rw-r--r--crates/ide-assists/src/handlers/inline_call.rs7
-rw-r--r--crates/ide-completion/src/completions/field.rs28
-rw-r--r--crates/ide-completion/src/completions/flyimport.rs5
-rw-r--r--crates/ide-completion/src/render.rs13
-rw-r--r--crates/ide/src/syntax_highlighting.rs7
-rw-r--r--crates/rust-analyzer/src/reload.rs9
14 files changed, 90 insertions, 131 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e7ee98512fe..2547f1ccb99 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 6c09a672334..f1bf162bc6b 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 12039173dd8..572df8f7137 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 186921ae7a4..f7d043fc4e6 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<LocalId, M
 }
 
 fn record_usage(local: LocalId, result: &mut ArenaMap<LocalId, MutabilityReason>) {
-    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 d320dcdad28..99930798e87 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<Option<(Operand, BasicBlockId)>> {
         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 3bc13bde265..30c3983dc41 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 f5153b8f1f1..154a1f59c72 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 8f61b43cd0f..a8817436ba1 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 bb87b9b6c91..4ba33ada48c 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 870df63b7bf..53fcb7ca6c0 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 3cb090da1ab..e330430d6b9 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 9f5c011dc39..6fd988bfc0f 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 307812156e9..3607c486d7d 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 82712c9ae01..969211f4400 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),
             }