about summary refs log tree commit diff
diff options
context:
space:
mode:
authorljedrz <ljedrz@gmail.com>2018-10-17 16:58:12 +0200
committerljedrz <ljedrz@gmail.com>2018-10-17 22:57:38 +0200
commitffecbc5e1027aab54402817dd1874c715ec9ba05 (patch)
tree60a8f1b4ac07ee49178656aee43729b2eaf2dfa2
parent2bda0c196f7118971801b0f5d6ddce5c6fb74fd3 (diff)
downloadrust-ffecbc5e1027aab54402817dd1874c715ec9ba05.tar.gz
rust-ffecbc5e1027aab54402817dd1874c715ec9ba05.zip
nll: improve common patterns
-rw-r--r--src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs59
-rw-r--r--src/librustc_mir/borrow_check/nll/invalidation.rs2
-rw-r--r--src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs6
3 files changed, 32 insertions, 35 deletions
diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
index b58604d1bfe..a0f832c5449 100644
--- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
+++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
@@ -439,17 +439,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                             Operand::Move(Place::Local(from)) if *from == target => {
                                 debug!("was_captured_by_trait_object: ty={:?}", ty);
                                 // Check the type for a trait object.
-                                match ty.sty {
+                                return match ty.sty {
                                     // `&dyn Trait`
-                                    ty::TyKind::Ref(_, ty, _) if ty.is_trait() => return true,
+                                    ty::TyKind::Ref(_, ty, _) if ty.is_trait() => true,
                                     // `Box<dyn Trait>`
                                     _ if ty.is_box() && ty.boxed_ty().is_trait() =>
-                                        return true,
+                                        true,
                                     // `dyn Trait`
-                                    _ if ty.is_trait() => return true,
+                                    _ if ty.is_trait() => true,
                                     // Anything else.
-                                    _ => return false,
-                                }
+                                    _ => false,
+                                };
                             },
                             _ => return false,
                         },
@@ -464,32 +464,29 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                 let terminator = block.terminator();
                 debug!("was_captured_by_trait_object: terminator={:?}", terminator);
 
-                match &terminator.kind {
-                    TerminatorKind::Call {
-                        destination: Some((Place::Local(dest), block)),
-                        args,
-                        ..
-                    } => {
-                        debug!(
-                            "was_captured_by_trait_object: target={:?} dest={:?} args={:?}",
-                            target, dest, args
-                        );
-                        // Check if one of the arguments to this function is the target place.
-                        let found_target = args.iter().any(|arg| {
-                            if let Operand::Move(Place::Local(potential)) = arg {
-                                *potential == target
-                            } else {
-                                false
-                            }
-                        });
-
-                        // If it is, follow this to the next block and update the target.
-                        if found_target {
-                            target = *dest;
-                            queue.push(block.start_location());
+                if let TerminatorKind::Call {
+                    destination: Some((Place::Local(dest), block)),
+                    args,
+                    ..
+                } = &terminator.kind {
+                    debug!(
+                        "was_captured_by_trait_object: target={:?} dest={:?} args={:?}",
+                        target, dest, args
+                    );
+                    // Check if one of the arguments to this function is the target place.
+                    let found_target = args.iter().any(|arg| {
+                        if let Operand::Move(Place::Local(potential)) = arg {
+                            *potential == target
+                        } else {
+                            false
                         }
-                    },
-                    _ => {},
+                    });
+
+                    // If it is, follow this to the next block and update the target.
+                    if found_target {
+                        target = *dest;
+                        queue.push(block.start_location());
+                    }
                 }
             }
 
diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs
index a9b5531bae5..002f35880ae 100644
--- a/src/librustc_mir/borrow_check/nll/invalidation.rs
+++ b/src/librustc_mir/borrow_check/nll/invalidation.rs
@@ -35,7 +35,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>(
     mir: &Mir<'tcx>,
     borrow_set: &BorrowSet<'tcx>,
 ) {
-    if !all_facts.is_some() {
+    if all_facts.is_none() {
         // Nothing to do if we don't have any facts
         return;
     }
diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
index 8d3cb727318..e07dfda406b 100644
--- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
+++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
@@ -566,10 +566,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
             | hir::LifetimeName::Underscore => {
                 let region_name = self.synthesize_region_name(counter);
                 let ampersand_span = lifetime.span;
-                return Some(RegionName {
+                Some(RegionName {
                     name: region_name,
                     source: RegionNameSource::MatchedAdtAndSegment(ampersand_span),
-                });
+                })
             }
 
             hir::LifetimeName::Implicit => {
@@ -584,7 +584,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
                 // T>`. We don't consider this a match; instead we let
                 // the "fully elaborated" type fallback above handle
                 // it.
-                return None;
+                None
             }
         }
     }