Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup nll #55151

Merged
merged 3 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/librustc_mir/borrow_check/nll/constraint_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
if let Some(all_facts) = self.all_facts {
if let Place::Local(temp) = place {
if let Some(borrow_indices) = self.borrow_set.local_map.get(temp) {
all_facts.killed.reserve(borrow_indices.len());
for &borrow_index in borrow_indices {
let location_index = self.location_table.mid_index(location);
all_facts.killed.push((borrow_index, location_index));
Expand All @@ -164,7 +165,9 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
self.location_table.mid_index(location),
));

for successor_block in terminator.successors() {
let successor_blocks = terminator.successors();
all_facts.cfg_edge.reserve(successor_blocks.size_hint().0);
ljedrz marked this conversation as resolved.
Show resolved Hide resolved
for successor_block in successor_blocks {
ljedrz marked this conversation as resolved.
Show resolved Hide resolved
all_facts.cfg_edge.push((
self.location_table.mid_index(location),
self.location_table
Expand Down
73 changes: 34 additions & 39 deletions src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ impl<'tcx> BorrowExplanation<'tcx> {
// Otherwise, just report the whole type (and use
// the intentionally fuzzy phrase "destructor")
ty::Closure(..) =>
("destructor", format!("closure")),
("destructor", "closure".to_owned()),
ty::Generator(..) =>
("destructor", format!("generator")),
("destructor", "generator".to_owned()),

_ => ("destructor", format!("type `{}`", local_decl.ty)),
};
Expand Down Expand Up @@ -279,9 +279,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
pending_locations.push(target.start_location());
},
TerminatorKind::SwitchInt { ref targets, .. } => {
for target in targets {
pending_locations.push(target.start_location());
}
pending_locations.extend(
targets.into_iter().map(|target| target.start_location()));
},
TerminatorKind::Drop { target, unwind, .. } |
TerminatorKind::DropAndReplace { target, unwind, .. } |
Expand All @@ -303,9 +302,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
},
TerminatorKind::FalseEdges { real_target, ref imaginary_targets, .. } => {
pending_locations.push(real_target.start_location());
for target in imaginary_targets {
pending_locations.push(target.start_location());
}
pending_locations.extend(
imaginary_targets.into_iter().map(|target| target.start_location()));
},
_ => {},
}
Expand Down Expand Up @@ -441,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,
},
Expand All @@ -466,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());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/borrow_check/nll/region_infer/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let outlived_by = self.universal_region_relations.regions_outlived_by(region);
writeln!(
out,
"| {r:rw$} | {c:cw$} | {ob}",
r = format!("{:?}", region),
"| {r:rw$?} | {c:cw$?} | {ob:?}",
r = region,
rw = REGION_WIDTH,
c = format!("{:?}", classification),
c = classification,
cw = 8, // "External" at most
ob = format!("{:?}", outlived_by)
ob = outlived_by
)?;
}
}
Expand All @@ -51,8 +51,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
for region in self.regions() {
writeln!(
out,
"| {r:rw$} | {ui:4?} | {v}",
r = format!("{:?}", region),
"| {r:rw$?} | {ui:4?} | {v}",
r = region,
rw = REGION_WIDTH,
ui = self.region_universe(region),
v = self.region_value_str(region),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let span = infcx.tcx.def_span(*did);
if let Ok(snippet) = infcx.tcx.sess.source_map().span_to_snippet(span) {
let suggestable_fr_name = if fr_name.was_named() {
format!("{}", fr_name)
fr_name.to_string()
} else {
"'_".to_string()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
argument_hir_ty: &hir::Ty,
counter: &mut usize,
) -> Option<RegionName> {
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> = &mut Vec::new();

search_stack.push((argument_ty, argument_hir_ty));
let search_stack: &mut Vec<(Ty<'tcx>, &hir::Ty)> =
&mut vec![(argument_ty, argument_hir_ty)];

while let Some((ty, hir_ty)) = search_stack.pop() {
match (&ty.sty, &hir_ty.node) {
Expand Down Expand Up @@ -567,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 => {
Expand All @@ -585,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
}
}
}
Expand Down