1
Fork 0

nll: improve common patterns

This commit is contained in:
ljedrz 2018-10-17 16:58:12 +02:00
parent 2bda0c196f
commit ffecbc5e10
3 changed files with 32 additions and 35 deletions

View file

@ -439,17 +439,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Operand::Move(Place::Local(from)) if *from == target => { Operand::Move(Place::Local(from)) if *from == target => {
debug!("was_captured_by_trait_object: ty={:?}", ty); debug!("was_captured_by_trait_object: ty={:?}", ty);
// Check the type for a trait object. // Check the type for a trait object.
match ty.sty { return match ty.sty {
// `&dyn Trait` // `&dyn Trait`
ty::TyKind::Ref(_, ty, _) if ty.is_trait() => return true, ty::TyKind::Ref(_, ty, _) if ty.is_trait() => true,
// `Box<dyn Trait>` // `Box<dyn Trait>`
_ if ty.is_box() && ty.boxed_ty().is_trait() => _ if ty.is_box() && ty.boxed_ty().is_trait() =>
return true, true,
// `dyn Trait` // `dyn Trait`
_ if ty.is_trait() => return true, _ if ty.is_trait() => true,
// Anything else. // Anything else.
_ => return false, _ => false,
} };
}, },
_ => return false, _ => return false,
}, },
@ -464,32 +464,29 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
let terminator = block.terminator(); let terminator = block.terminator();
debug!("was_captured_by_trait_object: terminator={:?}", terminator); debug!("was_captured_by_trait_object: terminator={:?}", terminator);
match &terminator.kind { if let TerminatorKind::Call {
TerminatorKind::Call { destination: Some((Place::Local(dest), block)),
destination: Some((Place::Local(dest), block)), args,
args, ..
.. } = &terminator.kind {
} => { debug!(
debug!( "was_captured_by_trait_object: target={:?} dest={:?} args={:?}",
"was_captured_by_trait_object: target={:?} dest={:?} args={:?}", target, dest, args
target, dest, args );
); // Check if one of the arguments to this function is the target place.
// Check if one of the arguments to this function is the target place. let found_target = args.iter().any(|arg| {
let found_target = args.iter().any(|arg| { if let Operand::Move(Place::Local(potential)) = arg {
if let Operand::Move(Place::Local(potential)) = arg { *potential == target
*potential == target } else {
} else { false
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 it is, follow this to the next block and update the target.
if found_target {
target = *dest;
queue.push(block.start_location());
}
} }
} }

View file

@ -35,7 +35,7 @@ pub(super) fn generate_invalidates<'cx, 'gcx, 'tcx>(
mir: &Mir<'tcx>, mir: &Mir<'tcx>,
borrow_set: &BorrowSet<'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 // Nothing to do if we don't have any facts
return; return;
} }

View file

@ -566,10 +566,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
| hir::LifetimeName::Underscore => { | hir::LifetimeName::Underscore => {
let region_name = self.synthesize_region_name(counter); let region_name = self.synthesize_region_name(counter);
let ampersand_span = lifetime.span; let ampersand_span = lifetime.span;
return Some(RegionName { Some(RegionName {
name: region_name, name: region_name,
source: RegionNameSource::MatchedAdtAndSegment(ampersand_span), source: RegionNameSource::MatchedAdtAndSegment(ampersand_span),
}); })
} }
hir::LifetimeName::Implicit => { hir::LifetimeName::Implicit => {
@ -584,7 +584,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// T>`. We don't consider this a match; instead we let // T>`. We don't consider this a match; instead we let
// the "fully elaborated" type fallback above handle // the "fully elaborated" type fallback above handle
// it. // it.
return None; None
} }
} }
} }