Skip to content

Commit b6dfa8c

Browse files
committed
Modified how constraint classification happens to upvars, can now handle function call case.
1 parent ce4f446 commit b6dfa8c

File tree

1 file changed

+20
-11
lines changed
  • src/librustc_mir/borrow_check/nll/region_infer/error_reporting

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum ConstraintCategory {
3333
Assignment,
3434
AssignmentToUpvar,
3535
Return,
36+
CallArgumentToUpvar,
3637
CallArgument,
3738
Other,
3839
Boring,
@@ -45,7 +46,8 @@ impl fmt::Display for ConstraintCategory {
4546
ConstraintCategory::AssignmentToUpvar => write!(f, "assignment"),
4647
ConstraintCategory::Return => write!(f, "return"),
4748
ConstraintCategory::Cast => write!(f, "cast"),
48-
ConstraintCategory::CallArgument => write!(f, "argument"),
49+
ConstraintCategory::CallArgument |
50+
ConstraintCategory::CallArgumentToUpvar => write!(f, "argument"),
4951
_ => write!(f, "free region"),
5052
}
5153
}
@@ -133,7 +135,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
133135
&self,
134136
index: ConstraintIndex,
135137
mir: &Mir<'tcx>,
136-
infcx: &InferCtxt<'_, '_, 'tcx>,
138+
_infcx: &InferCtxt<'_, '_, 'tcx>,
137139
) -> (ConstraintCategory, Span) {
138140
let constraint = self.constraints[index];
139141
debug!("classify_constraint: constraint={:?}", constraint);
@@ -163,7 +165,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
163165
match statement.kind {
164166
StatementKind::Assign(ref place, ref rvalue) => {
165167
debug!("classify_constraint: place={:?} rvalue={:?}", place, rvalue);
166-
let initial_category = if *place == Place::Local(mir::RETURN_PLACE) {
168+
if *place == Place::Local(mir::RETURN_PLACE) {
167169
ConstraintCategory::Return
168170
} else {
169171
match rvalue {
@@ -172,13 +174,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
172174
Rvalue::Aggregate(..) => ConstraintCategory::Assignment,
173175
_ => ConstraintCategory::Other,
174176
}
175-
};
176-
177-
if initial_category == ConstraintCategory::Assignment
178-
&& place.is_upvar_field_projection(mir, &infcx.tcx).is_some() {
179-
ConstraintCategory::AssignmentToUpvar
180-
} else {
181-
initial_category
182177
}
183178
}
184179
_ => ConstraintCategory::Other,
@@ -236,8 +231,22 @@ impl<'tcx> RegionInferenceContext<'tcx> {
236231
// Get a span
237232
let (category, span) = categorized_path.first().unwrap();
238233

234+
let category = match (
235+
category,
236+
self.universal_regions.is_local_free_region(fr),
237+
self.universal_regions.is_local_free_region(outlived_fr),
238+
) {
239+
(ConstraintCategory::Assignment, true, false) =>
240+
&ConstraintCategory::AssignmentToUpvar,
241+
(ConstraintCategory::CallArgument, true, false) =>
242+
&ConstraintCategory::CallArgumentToUpvar,
243+
(category, _, _) => category,
244+
};
245+
246+
debug!("report_error: category={:?}", category);
239247
match category {
240-
ConstraintCategory::AssignmentToUpvar =>
248+
ConstraintCategory::AssignmentToUpvar |
249+
ConstraintCategory::CallArgumentToUpvar =>
241250
self.report_closure_error(mir, infcx, fr, outlived_fr, span),
242251
_ =>
243252
self.report_general_error(mir, infcx, mir_def_id, fr, outlived_fr, category, span),

0 commit comments

Comments
 (0)