Skip to content

Commit

Permalink
Modified how constraint classification happens to upvars, can now han…
Browse files Browse the repository at this point in the history
…dle function call case.
  • Loading branch information
davidtwco committed Jul 22, 2018
1 parent ce4f446 commit b6dfa8c
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum ConstraintCategory {
Assignment,
AssignmentToUpvar,
Return,
CallArgumentToUpvar,
CallArgument,
Other,
Boring,
Expand All @@ -45,7 +46,8 @@ impl fmt::Display for ConstraintCategory {
ConstraintCategory::AssignmentToUpvar => write!(f, "assignment"),
ConstraintCategory::Return => write!(f, "return"),
ConstraintCategory::Cast => write!(f, "cast"),
ConstraintCategory::CallArgument => write!(f, "argument"),
ConstraintCategory::CallArgument |
ConstraintCategory::CallArgumentToUpvar => write!(f, "argument"),
_ => write!(f, "free region"),
}
}
Expand Down Expand Up @@ -133,7 +135,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self,
index: ConstraintIndex,
mir: &Mir<'tcx>,
infcx: &InferCtxt<'_, '_, 'tcx>,
_infcx: &InferCtxt<'_, '_, 'tcx>,
) -> (ConstraintCategory, Span) {
let constraint = self.constraints[index];
debug!("classify_constraint: constraint={:?}", constraint);
Expand Down Expand Up @@ -163,7 +165,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
match statement.kind {
StatementKind::Assign(ref place, ref rvalue) => {
debug!("classify_constraint: place={:?} rvalue={:?}", place, rvalue);
let initial_category = if *place == Place::Local(mir::RETURN_PLACE) {
if *place == Place::Local(mir::RETURN_PLACE) {
ConstraintCategory::Return
} else {
match rvalue {
Expand All @@ -172,13 +174,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
Rvalue::Aggregate(..) => ConstraintCategory::Assignment,
_ => ConstraintCategory::Other,
}
};

if initial_category == ConstraintCategory::Assignment
&& place.is_upvar_field_projection(mir, &infcx.tcx).is_some() {
ConstraintCategory::AssignmentToUpvar
} else {
initial_category
}
}
_ => ConstraintCategory::Other,
Expand Down Expand Up @@ -236,8 +231,22 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Get a span
let (category, span) = categorized_path.first().unwrap();

let category = match (
category,
self.universal_regions.is_local_free_region(fr),
self.universal_regions.is_local_free_region(outlived_fr),
) {
(ConstraintCategory::Assignment, true, false) =>
&ConstraintCategory::AssignmentToUpvar,
(ConstraintCategory::CallArgument, true, false) =>
&ConstraintCategory::CallArgumentToUpvar,
(category, _, _) => category,
};

debug!("report_error: category={:?}", category);
match category {
ConstraintCategory::AssignmentToUpvar =>
ConstraintCategory::AssignmentToUpvar |
ConstraintCategory::CallArgumentToUpvar =>
self.report_closure_error(mir, infcx, fr, outlived_fr, span),
_ =>
self.report_general_error(mir, infcx, mir_def_id, fr, outlived_fr, category, span),
Expand Down

0 comments on commit b6dfa8c

Please sign in to comment.