]> git.lizzy.rs Git - rust.git/commitdiff
rustc/infer: convert single-branch matches to if-let
authorljedrz <ljedrz@gmail.com>
Fri, 28 Sep 2018 15:26:10 +0000 (17:26 +0200)
committerljedrz <ljedrz@gmail.com>
Sat, 29 Sep 2018 12:57:39 +0000 (14:57 +0200)
src/librustc/infer/error_reporting/mod.rs
src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs
src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs
src/librustc/infer/error_reporting/nice_region_error/util.rs
src/librustc/infer/lexical_region_resolve/graphviz.rs
src/librustc/infer/region_constraints/mod.rs
src/librustc/infer/type_variable.rs

index e3bbdab4fd9659db1a3b0f64fc82f2e397045684..a24eeb328427f64897a88f20532f71f4cd35e67a 100644 (file)
@@ -455,11 +455,10 @@ fn check_and_note_conflicting_crates(
             TypeError::Sorts(ref exp_found) => {
                 // if they are both "path types", there's a chance of ambiguity
                 // due to different versions of the same crate
-                match (&exp_found.expected.sty, &exp_found.found.sty) {
-                    (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) => {
-                        report_path_match(err, exp_adt.did, found_adt.did);
-                    }
-                    _ => (),
+                if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _))
+                     = (&exp_found.expected.sty, &exp_found.found.sty)
+                {
+                    report_path_match(err, exp_adt.did, found_adt.did);
                 }
             }
             TypeError::Traits(ref exp_found) => {
index 5c27cdb6fb55392198cb30678f1895d81b4ff040..009a823568131fb6b007e44aabd6b58c2ecce3cd 100644 (file)
@@ -58,18 +58,17 @@ pub(super) fn try_report_outlives_closure(&self) -> Option<ErrorReported> {
                     &RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) {
                 let hir = &self.tcx.hir;
                 if let Some(node_id) = hir.as_local_node_id(free_region.scope) {
-                    match hir.get(node_id) {
-                        Node::Expr(Expr {
-                            node: Closure(_, _, _, closure_span, None),
-                            ..
-                        }) => {
-                            let sup_sp = sup_origin.span();
-                            let origin_sp = origin.span();
-                            let mut err = self.tcx.sess.struct_span_err(
-                                sup_sp,
-                                "borrowed data cannot be stored outside of its closure");
-                            err.span_label(sup_sp, "cannot be stored outside of its closure");
-                            if origin_sp == sup_sp || origin_sp.contains(sup_sp) {
+                    if let Node::Expr(Expr {
+                        node: Closure(_, _, _, closure_span, None),
+                        ..
+                    }) = hir.get(node_id) {
+                        let sup_sp = sup_origin.span();
+                        let origin_sp = origin.span();
+                        let mut err = self.tcx.sess.struct_span_err(
+                            sup_sp,
+                            "borrowed data cannot be stored outside of its closure");
+                        err.span_label(sup_sp, "cannot be stored outside of its closure");
+                        if origin_sp == sup_sp || origin_sp.contains(sup_sp) {
 // // sup_sp == origin.span():
 //
 // let mut x = None;
@@ -87,11 +86,11 @@ pub(super) fn try_report_outlives_closure(&self) -> Option<ErrorReported> {
 //                         ------------ ... because it cannot outlive this closure
 //     f = Some(x);
 //              ^ cannot be stored outside of its closure
-                                err.span_label(*external_span,
-                                               "borrowed data cannot be stored into here...");
-                                err.span_label(*closure_span,
-                                               "...because it cannot outlive this closure");
-                            } else {
+                            err.span_label(*external_span,
+                                           "borrowed data cannot be stored into here...");
+                            err.span_label(*closure_span,
+                                           "...because it cannot outlive this closure");
+                        } else {
 // FIXME: the wording for this case could be much improved
 //
 // let mut lines_to_use: Vec<&CrateId> = Vec::new();
@@ -102,18 +101,16 @@ pub(super) fn try_report_outlives_closure(&self) -> Option<ErrorReported> {
 //     ...so that variable is valid at time of its declaration
 //     lines_to_use.push(installed_id);
 //                       ^^^^^^^^^^^^ cannot be stored outside of its closure
-                                err.span_label(origin_sp,
-                                               "cannot infer an appropriate lifetime...");
-                                err.span_label(*external_span,
-                                               "...so that variable is valid at time of its \
-                                                declaration");
-                                err.span_label(*closure_span,
-                                               "borrowed data cannot outlive this closure");
-                            }
-                            err.emit();
-                            return Some(ErrorReported);
+                            err.span_label(origin_sp,
+                                           "cannot infer an appropriate lifetime...");
+                            err.span_label(*external_span,
+                                           "...so that variable is valid at time of its \
+                                            declaration");
+                            err.span_label(*closure_span,
+                                           "borrowed data cannot outlive this closure");
                         }
-                        _ => {}
+                        err.emit();
+                        return Some(ErrorReported);
                     }
                 }
             }
index 3393eb65089c05a55e3b6cf337ff6cd98b0860c0..766173bf66283d4118d8250137a5e19daaf04381 100644 (file)
@@ -20,64 +20,62 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
     /// Print the error message for lifetime errors when the return type is a static impl Trait.
     pub(super) fn try_report_static_impl_trait(&self) -> Option<ErrorReported> {
         if let Some(ref error) = self.error {
-            match error.clone() {
-                RegionResolutionError::SubSupConflict(
+            if let RegionResolutionError::SubSupConflict(
                     var_origin,
                     sub_origin,
                     sub_r,
                     sup_origin,
                     sup_r,
-                ) => {
-                    let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?;
-                    if sub_r == &RegionKind::ReStatic &&
-                        self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some()
-                    {
-                        let sp = var_origin.span();
-                        let return_sp = sub_origin.span();
-                        let mut err = self.tcx.sess.struct_span_err(
-                            sp,
-                            "cannot infer an appropriate lifetime",
+                ) = error.clone()
+            {
+                let anon_reg_sup = self.tcx.is_suitable_region(sup_r)?;
+                if sub_r == &RegionKind::ReStatic &&
+                    self.tcx.return_type_impl_trait(anon_reg_sup.def_id).is_some()
+                {
+                    let sp = var_origin.span();
+                    let return_sp = sub_origin.span();
+                    let mut err = self.tcx.sess.struct_span_err(
+                        sp,
+                        "cannot infer an appropriate lifetime",
+                    );
+                    err.span_label(
+                        return_sp,
+                        "this return type evaluates to the `'static` lifetime...",
+                    );
+                    err.span_label(
+                        sup_origin.span(),
+                        "...but this borrow...",
+                    );
+
+                    let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r);
+                    if let Some(lifetime_sp) = lt_sp_opt {
+                        err.span_note(
+                            lifetime_sp,
+                            &format!("...can't outlive {}", lifetime),
                         );
-                        err.span_label(
+                    }
+
+                    let lifetime_name = match sup_r {
+                        RegionKind::ReFree(FreeRegion {
+                            bound_region: BoundRegion::BrNamed(_, ref name), ..
+                        }) => name.to_string(),
+                        _ => "'_".to_owned(),
+                    };
+                    if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
+                        err.span_suggestion_with_applicability(
                             return_sp,
-                            "this return type evaluates to the `'static` lifetime...",
+                            &format!(
+                                "you can add a constraint to the return type to make it last \
+                                 less than `'static` and match {}",
+                                lifetime,
+                            ),
+                            format!("{} + {}", snippet, lifetime_name),
+                            Applicability::Unspecified,
                         );
-                        err.span_label(
-                            sup_origin.span(),
-                            "...but this borrow...",
-                        );
-
-                        let (lifetime, lt_sp_opt) = self.tcx.msg_span_from_free_region(sup_r);
-                        if let Some(lifetime_sp) = lt_sp_opt {
-                            err.span_note(
-                                lifetime_sp,
-                                &format!("...can't outlive {}", lifetime),
-                            );
-                        }
-
-                        let lifetime_name = match sup_r {
-                            RegionKind::ReFree(FreeRegion {
-                                bound_region: BoundRegion::BrNamed(_, ref name), ..
-                            }) => name.to_string(),
-                            _ => "'_".to_owned(),
-                        };
-                        if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
-                            err.span_suggestion_with_applicability(
-                                return_sp,
-                                &format!(
-                                    "you can add a constraint to the return type to make it last \
-                                     less than `'static` and match {}",
-                                    lifetime,
-                                ),
-                                format!("{} + {}", snippet, lifetime_name),
-                                Applicability::Unspecified,
-                            );
-                        }
-                        err.emit();
-                        return Some(ErrorReported);
                     }
+                    err.emit();
+                    return Some(ErrorReported);
                 }
-                _ => {}
             }
         }
         None
index afc50fe1151665e3a37fb37549644f74013d5344..76a780a5a055af079c8c58bd91dcedfcc01f755f 100644 (file)
@@ -119,16 +119,13 @@ pub(super) fn is_return_type_anon(
         decl: &hir::FnDecl,
     ) -> Option<Span> {
         let ret_ty = self.tcx.type_of(scope_def_id);
-        match ret_ty.sty {
-            ty::FnDef(_, _) => {
-                let sig = ret_ty.fn_sig(self.tcx);
-                let late_bound_regions = self.tcx
-                    .collect_referenced_late_bound_regions(&sig.output());
-                if late_bound_regions.iter().any(|r| *r == br) {
-                    return Some(decl.output.span());
-                }
+        if let ty::FnDef(_, _) = ret_ty.sty {
+            let sig = ret_ty.fn_sig(self.tcx);
+            let late_bound_regions = self.tcx
+                .collect_referenced_late_bound_regions(&sig.output());
+            if late_bound_regions.iter().any(|r| *r == br) {
+                return Some(decl.output.span());
             }
-            _ => {}
         }
         None
     }
index f605da584b28f678a360ff9a8c949dbee4404989..e4705df2eea13fc4fe9a65b459b8fa73c4e550bf 100644 (file)
@@ -112,12 +112,9 @@ pub fn maybe_print_constraints_for<'a, 'gcx, 'tcx>(
         }
     };
 
-    match dump_region_data_to(region_rels, &region_data.constraints, &output_path) {
-        Ok(()) => {}
-        Err(e) => {
-            let msg = format!("io error dumping region constraints: {}", e);
-            tcx.sess.err(&msg)
-        }
+    if let Err(e) = dump_region_data_to(region_rels, &region_data.constraints, &output_path) {
+        let msg = format!("io error dumping region constraints: {}", e);
+        tcx.sess.err(&msg)
     }
 }
 
index bc9027a08258c944d91223de0111f96238ae8a66..1a79ca211283b8a5d5b8090a66985ec542ceb98b 100644 (file)
@@ -661,11 +661,10 @@ fn add_verify(&mut self, verify: Verify<'tcx>) {
         debug!("RegionConstraintCollector: add_verify({:?})", verify);
 
         // skip no-op cases known to be satisfied
-        match verify.bound {
-            VerifyBound::AllBounds(ref bs) if bs.len() == 0 => {
+        if let VerifyBound::AllBounds(ref bs) = verify.bound {
+            if bs.len() == 0 {
                 return;
             }
-            _ => {}
         }
 
         let index = self.data.verifys.len();
index b1e4fc7c7fc7b1127e9192bf3dcbbd72162ceb17..970b6e096ffe4d04370e482d43e079e29daa214e 100644 (file)
@@ -273,11 +273,8 @@ pub fn snapshot(&mut self) -> Snapshot<'tcx> {
     pub fn rollback_to(&mut self, s: Snapshot<'tcx>) {
         debug!("rollback_to{:?}", {
             for action in self.values.actions_since_snapshot(&s.snapshot) {
-                match *action {
-                    sv::UndoLog::NewElem(index) => {
-                        debug!("inference variable _#{}t popped", index)
-                    }
-                    _ => { }
+                if let sv::UndoLog::NewElem(index) = *action {
+                    debug!("inference variable _#{}t popped", index)
                 }
             }
         });