]> git.lizzy.rs Git - rust.git/commitdiff
use matches!() macro for simple if let conditions
authorMatthias Krüger <matthias.krueger@famsik.de>
Fri, 18 Sep 2020 17:11:06 +0000 (19:11 +0200)
committerMatthias Krüger <matthias.krueger@famsik.de>
Fri, 18 Sep 2020 18:28:35 +0000 (20:28 +0200)
15 files changed:
compiler/rustc_ast/src/ast.rs
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_attr/src/builtin.rs
compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
compiler/rustc_errors/src/snippet.rs
compiler/rustc_lint/src/builtin.rs
compiler/rustc_middle/src/middle/cstore.rs
compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs
compiler/rustc_mir/src/transform/promote_consts.rs
compiler/rustc_mir/src/transform/simplify.rs
compiler/rustc_mir_build/src/build/block.rs
compiler/rustc_mir_build/src/build/matches/mod.rs
compiler/rustc_resolve/src/build_reduced_graph.rs
compiler/rustc_resolve/src/late.rs
compiler/rustc_typeck/src/check/expr.rs

index dee3a16f9b133a6153f0c3ff4a088b3fa298444e..95abf552915063abeece8f75ca747e6cd5460a1c 100644 (file)
@@ -1931,7 +1931,7 @@ pub enum TyKind {
 
 impl TyKind {
     pub fn is_implicit_self(&self) -> bool {
-        if let TyKind::ImplicitSelf = *self { true } else { false }
+        matches!(self, TyKind::ImplicitSelf)
     }
 
     pub fn is_unit(&self) -> bool {
@@ -2227,7 +2227,7 @@ pub enum Async {
 
 impl Async {
     pub fn is_async(self) -> bool {
-        if let Async::Yes { .. } = self { true } else { false }
+        matches!(self, Async::Yes { .. })
     }
 
     /// In this case this is an `async` return, the `NodeId` for the generated `impl Trait` item.
@@ -2508,7 +2508,7 @@ pub enum VisibilityKind {
 
 impl VisibilityKind {
     pub fn is_pub(&self) -> bool {
-        if let VisibilityKind::Public = *self { true } else { false }
+        matches!(self, VisibilityKind::Public)
     }
 }
 
index 31c05325d1d258dcc32b4f78742b57ddd1246baf..232ee35c4f7df82d9d780346c21ed379ce03d70a 100644 (file)
@@ -868,10 +868,7 @@ fn visit_ty(&mut self, ty: &'a Ty) {
                     .emit();
                 }
 
-                if !bounds
-                    .iter()
-                    .any(|b| if let GenericBound::Trait(..) = *b { true } else { false })
-                {
+                if !bounds.iter().any(|b| matches!(b, GenericBound::Trait(..))) {
                     self.err_handler().span_err(ty.span, "at least one trait must be specified");
                 }
 
index b8929fe08891305eb65e8ffa828164311b298c3a..9951c25200129da648036609adeed89640a1a85a 100644 (file)
@@ -160,10 +160,10 @@ pub enum StabilityLevel {
 
 impl StabilityLevel {
     pub fn is_unstable(&self) -> bool {
-        if let StabilityLevel::Unstable { .. } = *self { true } else { false }
+        matches!(self, StabilityLevel::Unstable { .. })
     }
     pub fn is_stable(&self) -> bool {
-        if let StabilityLevel::Stable { .. } = *self { true } else { false }
+        matches!(self, StabilityLevel::Stable { .. })
     }
 }
 
index d235caec1031f580a2ec918ff7c6d7650e49a3f4..f4924997d1af960ababae9bed61987be0d4e89a5 100644 (file)
@@ -1529,7 +1529,7 @@ fn summarise_struct(&self, cx: &mut ExtCtxt<'_>, struct_def: &VariantData) -> St
             }
         }
 
-        let is_tuple = if let ast::VariantData::Tuple(..) = struct_def { true } else { false };
+        let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
         match (just_spans.is_empty(), named_idents.is_empty()) {
             (false, false) => cx.span_bug(
                 self.span,
index 160bf57779970a58ab0b6369a5736534c634c5e4..fae5b94b3a81edc650fd124051888f4b919e47c7 100644 (file)
@@ -118,17 +118,15 @@ pub struct Annotation {
 impl Annotation {
     /// Whether this annotation is a vertical line placeholder.
     pub fn is_line(&self) -> bool {
-        if let AnnotationType::MultilineLine(_) = self.annotation_type { true } else { false }
+        matches!(self.annotation_type, AnnotationType::MultilineLine(_))
     }
 
     pub fn is_multiline(&self) -> bool {
-        match self.annotation_type {
+        matches!(self.annotation_type,
             AnnotationType::Multiline(_)
             | AnnotationType::MultilineStart(_)
             | AnnotationType::MultilineLine(_)
-            | AnnotationType::MultilineEnd(_) => true,
-            _ => false,
-        }
+            | AnnotationType::MultilineEnd(_))
     }
 
     pub fn len(&self) -> usize {
index 5b5dbcf192ca16caf6fb17405e658de0df370372..43424ce9b80e923d339833b6d637ebe07dd9bcfa 100644 (file)
@@ -1985,9 +1985,9 @@ fn collect_outlives_bound_spans<'tcx>(
             .filter_map(|(i, bound)| {
                 if let hir::GenericBound::Outlives(lifetime) = bound {
                     let is_inferred = match tcx.named_region(lifetime.hir_id) {
-                        Some(Region::Static) if infer_static => inferred_outlives
-                            .iter()
-                            .any(|r| if let ty::ReStatic = r { true } else { false }),
+                        Some(Region::Static) if infer_static => {
+                            inferred_outlives.iter().any(|r| matches!(r, ty::ReStatic))
+                        }
                         Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
                             if let ty::ReEarlyBound(ebr) = r { ebr.index == index } else { false }
                         }),
@@ -2079,9 +2079,10 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
             let mut lint_spans = Vec::new();
 
             for param in hir_generics.params {
-                let has_lifetime_bounds = param.bounds.iter().any(|bound| {
-                    if let hir::GenericBound::Outlives(_) = bound { true } else { false }
-                });
+                let has_lifetime_bounds = param
+                    .bounds
+                    .iter()
+                    .any(|bound| matches!(bound, hir::GenericBound::Outlives(_)));
                 if !has_lifetime_bounds {
                     continue;
                 }
index 1af1d58181760b65aef5ad23f5bc4239e6fc172d..f3d7c8506ab6ff3338ae7cebfb4b6859d4648f3b 100644 (file)
@@ -69,7 +69,7 @@ pub enum LibSource {
 
 impl LibSource {
     pub fn is_some(&self) -> bool {
-        if let LibSource::Some(_) = *self { true } else { false }
+        matches!(self, LibSource::Some(_))
     }
 
     pub fn option(&self) -> Option<PathBuf> {
index a775fa59c1b9dce220554c6197a3568f600462eb..7505e6e2dd11e224db3f97f0c0b91372335ac407 100644 (file)
@@ -115,9 +115,10 @@ fn compile_all_suggestions(
             //    should just replace 'a with 'static.
             // 3) Suggest unifying 'a with 'b if we have both 'a: 'b and 'b: 'a
 
-            if outlived.iter().any(|(_, outlived_name)| {
-                if let RegionNameSource::Static = outlived_name.source { true } else { false }
-            }) {
+            if outlived
+                .iter()
+                .any(|(_, outlived_name)| matches!(outlived_name.source, RegionNameSource::Static))
+            {
                 suggested.push(SuggestedConstraint::Static(fr_name));
             } else {
                 // We want to isolate out all lifetimes that should be unified and print out
index 1d2295a37dddf10bfadfef0740136e396b5c343a..75efed043ce45fda08cb7ea31c63b0f341c93de8 100644 (file)
@@ -92,7 +92,7 @@ pub enum TempState {
 impl TempState {
     pub fn is_promotable(&self) -> bool {
         debug!("is_promotable: self={:?}", self);
-        if let TempState::Defined { .. } = *self { true } else { false }
+        matches!(self, TempState::Defined { .. } )
     }
 }
 
index d8995e92abfcc7dbd780569f41dfbfebc7a35221..3fc8e6d4b04b85e046422e29909ecea88ad60791 100644 (file)
@@ -281,8 +281,7 @@ fn simplify_branch(&mut self, terminator: &mut Terminator<'tcx>) -> bool {
 
     fn strip_nops(&mut self) {
         for blk in self.basic_blocks.iter_mut() {
-            blk.statements
-                .retain(|stmt| if let StatementKind::Nop = stmt.kind { false } else { true })
+            blk.statements.retain(|stmt| !matches!(stmt.kind, StatementKind::Nop))
         }
     }
 }
index d1cbf209b06cebc4035cb783f8a3de4ccf29cfe3..beaf12b1db04255bb05e936216c0cb35a9fffd8e 100644 (file)
@@ -96,8 +96,7 @@ fn ast_block_stmts(
                     );
                 }
                 StmtKind::Let { remainder_scope, init_scope, pattern, initializer, lint_level } => {
-                    let ignores_expr_result =
-                        if let PatKind::Wild = *pattern.kind { true } else { false };
+                    let ignores_expr_result = matches!(*pattern.kind, PatKind::Wild);
                     this.block_context.push(BlockFrame::Statement { ignores_expr_result });
 
                     // Enter the remainder scope, i.e., the bindings' destruction scope.
index 3a525d10b08175cda5f8976e181f073ba7b64e78..6e9d5eedf051f231c732b2bfd0f8c3686093e90f 100644 (file)
@@ -1793,7 +1793,7 @@ fn bind_and_guard_matched_candidate<'pat>(
                     .flat_map(|(bindings, _)| bindings)
                     .chain(&candidate.bindings)
                     .filter(|binding| {
-                        if let BindingMode::ByValue = binding.binding_mode { true } else { false }
+                        matches!(binding.binding_mode, BindingMode::ByValue )
                     });
             // Read all of the by reference bindings to ensure that the
             // place they refer to can't be modified by the guard.
index 565313902a42ee1c89eea8c126573085947ef006..a48d002b2a35bb772c5e21202a91e743c334bb7d 100644 (file)
@@ -395,7 +395,7 @@ fn build_reduced_graph_for_use_tree(
         // so prefixes are prepended with crate root segment if necessary.
         // The root is prepended lazily, when the first non-empty prefix or terminating glob
         // appears, so imports in braced groups can have roots prepended independently.
-        let is_glob = if let ast::UseTreeKind::Glob = use_tree.kind { true } else { false };
+        let is_glob = matches!(use_tree.kind, ast::UseTreeKind::Glob);
         let crate_root = match prefix_iter.peek() {
             Some(seg) if !seg.ident.is_path_segment_keyword() && seg.ident.span.rust_2015() => {
                 Some(seg.ident.span.ctxt())
index 6788df9be7820489bbcdb694f4c5debc6517ded9..2c01934b490dcc429f8a2b73c98ee59f01b5ada2 100644 (file)
@@ -1034,7 +1034,7 @@ fn with_generic_param_rib<'c, F>(&'c mut self, generics: &'c Generics, kind: Rib
             let mut add_bindings_for_ns = |ns| {
                 let parent_rib = self.ribs[ns]
                     .iter()
-                    .rfind(|r| if let ItemRibKind(_) = r.kind { true } else { false })
+                    .rfind(|r| matches!(r.kind, ItemRibKind(_)))
                     .expect("associated item outside of an item");
                 seen_bindings
                     .extend(parent_rib.bindings.iter().map(|(ident, _)| (*ident, ident.span)));
index d5563cdac02de090cdb78efc989e0dfc404e55c5..af800eab67a5e36386d0ddccc96a4e8a0ac8e03c 100644 (file)
@@ -439,9 +439,11 @@ fn check_named_place_expr(&self, oprnd: &'tcx hir::Expr<'tcx>) {
             // This is maybe too permissive, since it allows
             // `let u = &raw const Box::new((1,)).0`, which creates an
             // immediately dangling raw pointer.
-            self.typeck_results.borrow().adjustments().get(base.hir_id).map_or(false, |x| {
-                x.iter().any(|adj| if let Adjust::Deref(_) = adj.kind { true } else { false })
-            })
+            self.typeck_results
+                .borrow()
+                .adjustments()
+                .get(base.hir_id)
+                .map_or(false, |x| x.iter().any(|adj| matches!(adj.kind, Adjust::Deref(_))))
         });
         if !is_named {
             self.tcx.sess.emit_err(AddressOfTemporaryTaken { span: oprnd.span })