Skip to content

Commit ffecbc5

Browse files
committed
nll: improve common patterns
1 parent 2bda0c1 commit ffecbc5

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
439439
Operand::Move(Place::Local(from)) if *from == target => {
440440
debug!("was_captured_by_trait_object: ty={:?}", ty);
441441
// Check the type for a trait object.
442-
match ty.sty {
442+
return match ty.sty {
443443
// `&dyn Trait`
444-
ty::TyKind::Ref(_, ty, _) if ty.is_trait() => return true,
444+
ty::TyKind::Ref(_, ty, _) if ty.is_trait() => true,
445445
// `Box<dyn Trait>`
446446
_ if ty.is_box() && ty.boxed_ty().is_trait() =>
447-
return true,
447+
true,
448448
// `dyn Trait`
449-
_ if ty.is_trait() => return true,
449+
_ if ty.is_trait() => true,
450450
// Anything else.
451-
_ => return false,
452-
}
451+
_ => false,
452+
};
453453
},
454454
_ => return false,
455455
},
@@ -464,32 +464,29 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
464464
let terminator = block.terminator();
465465
debug!("was_captured_by_trait_object: terminator={:?}", terminator);
466466

467-
match &terminator.kind {
468-
TerminatorKind::Call {
469-
destination: Some((Place::Local(dest), block)),
470-
args,
471-
..
472-
} => {
473-
debug!(
474-
"was_captured_by_trait_object: target={:?} dest={:?} args={:?}",
475-
target, dest, args
476-
);
477-
// Check if one of the arguments to this function is the target place.
478-
let found_target = args.iter().any(|arg| {
479-
if let Operand::Move(Place::Local(potential)) = arg {
480-
*potential == target
481-
} else {
482-
false
483-
}
484-
});
485-
486-
// If it is, follow this to the next block and update the target.
487-
if found_target {
488-
target = *dest;
489-
queue.push(block.start_location());
467+
if let TerminatorKind::Call {
468+
destination: Some((Place::Local(dest), block)),
469+
args,
470+
..
471+
} = &terminator.kind {
472+
debug!(
473+
"was_captured_by_trait_object: target={:?} dest={:?} args={:?}",
474+
target, dest, args
475+
);
476+
// Check if one of the arguments to this function is the target place.
477+
let found_target = args.iter().any(|arg| {
478+
if let Operand::Move(Place::Local(potential)) = arg {
479+
*potential == target
480+
} else {
481+
false
490482
}
491-
},
492-
_ => {},
483+
});
484+
485+
// If it is, follow this to the next block and update the target.
486+
if found_target {
487+
target = *dest;
488+
queue.push(block.start_location());
489+
}
493490
}
494491
}
495492

src/librustc_mir/borrow_check/nll/invalidation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>(
3535
mir: &Mir<'tcx>,
3636
borrow_set: &BorrowSet<'tcx>,
3737
) {
38-
if !all_facts.is_some() {
38+
if all_facts.is_none() {
3939
// Nothing to do if we don't have any facts
4040
return;
4141
}

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
566566
| hir::LifetimeName::Underscore => {
567567
let region_name = self.synthesize_region_name(counter);
568568
let ampersand_span = lifetime.span;
569-
return Some(RegionName {
569+
Some(RegionName {
570570
name: region_name,
571571
source: RegionNameSource::MatchedAdtAndSegment(ampersand_span),
572-
});
572+
})
573573
}
574574

575575
hir::LifetimeName::Implicit => {
@@ -584,7 +584,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
584584
// T>`. We don't consider this a match; instead we let
585585
// the "fully elaborated" type fallback above handle
586586
// it.
587-
return None;
587+
None
588588
}
589589
}
590590
}

0 commit comments

Comments
 (0)