Skip to content

Commit 24c5751

Browse files
committed
Classify aggregate rvalues as assignments.
1 parent aeca042 commit 24c5751

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
132132
mir: &Mir<'tcx>,
133133
) -> (ConstraintCategory, Span) {
134134
let constraint = self.constraints[index];
135+
debug!("classify_constraint: constraint={:?}", constraint);
135136
let span = constraint.locations.span(mir);
136137
let location = constraint.locations.from_location().unwrap_or(Location::START);
137138

@@ -140,8 +141,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
140141
}
141142

142143
let data = &mir[location.block];
144+
debug!("classify_constraint: location={:?} data={:?}", location, data);
143145
let category = if location.statement_index == data.statements.len() {
144146
if let Some(ref terminator) = data.terminator {
147+
debug!("classify_constraint: terminator.kind={:?}", terminator.kind);
145148
match terminator.kind {
146149
TerminatorKind::DropAndReplace { .. } => ConstraintCategory::Assignment,
147150
TerminatorKind::Call { .. } => ConstraintCategory::CallArgument,
@@ -152,14 +155,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
152155
}
153156
} else {
154157
let statement = &data.statements[location.statement_index];
158+
debug!("classify_constraint: statement.kind={:?}", statement.kind);
155159
match statement.kind {
156160
StatementKind::Assign(ref place, ref rvalue) => {
161+
debug!("classify_constraint: place={:?} rvalue={:?}", place, rvalue);
157162
if *place == Place::Local(mir::RETURN_PLACE) {
158163
ConstraintCategory::Return
159164
} else {
160165
match rvalue {
161166
Rvalue::Cast(..) => ConstraintCategory::Cast,
162-
Rvalue::Use(..) => ConstraintCategory::Assignment,
167+
Rvalue::Use(..) |
168+
Rvalue::Aggregate(..) => ConstraintCategory::Assignment,
163169
_ => ConstraintCategory::Other,
164170
}
165171
}

src/test/ui/borrowck/issue-45983.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unsatisfied lifetime constraints
1010
LL | let x = None;
1111
| - lifetime `'2` appears in the type of `x`
1212
LL | give_any(|y| x = Some(y));
13-
| - ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
13+
| - ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
1414
| |
1515
| lifetime `'1` appears in this argument
1616

src/test/ui/borrowck/regions-escape-bound-fn-2.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unsatisfied lifetime constraints
1010
LL | let mut x = None;
1111
| ----- lifetime `'2` appears in the type of `x`
1212
LL | with_int(|y| x = Some(y));
13-
| - ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
13+
| - ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
1414
| |
1515
| lifetime `'1` appears in this argument
1616

src/test/ui/borrowck/regions-escape-bound-fn.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unsatisfied lifetime constraints
1010
LL | let mut x: Option<&isize> = None;
1111
| ----- lifetime `'2` appears in the type of `x`
1212
LL | with_int(|y| x = Some(y));
13-
| - ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
13+
| - ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
1414
| |
1515
| lifetime `'1` appears in this argument
1616

src/test/ui/borrowck/regions-escape-unboxed-closure.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unsatisfied lifetime constraints
1010
LL | let mut x: Option<&isize> = None;
1111
| ----- lifetime `'2` appears in the type of `x`
1212
LL | with_int(&mut |y| x = Some(y));
13-
| - ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
13+
| - ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
1414
| |
1515
| lifetime `'1` appears in this argument
1616

src/test/ui/closure-expected-type/expect-region-supply-region.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | let mut f: Option<&u32> = None;
3030
LL | closure_expecting_bound(|x| {
3131
| - lifetime `'1` appears in this argument
3232
LL | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
33-
| ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
33+
| ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
3434

3535
error: unsatisfied lifetime constraints
3636
--> $DIR/expect-region-supply-region.rs:38:9
@@ -40,7 +40,7 @@ LL | let mut f: Option<&u32> = None;
4040
LL | closure_expecting_bound(|x: &u32| {
4141
| - let's call the lifetime of this reference `'1`
4242
LL | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
43-
| ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
43+
| ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
4444

4545
error: unsatisfied lifetime constraints
4646
--> $DIR/expect-region-supply-region.rs:52:9
@@ -52,7 +52,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
5252
| - let's call the lifetime of this reference `'1`
5353
...
5454
LL | f = Some(x);
55-
| ^^^^^^^^^^^ free region requires that `'1` must outlive `'2`
55+
| ^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
5656

5757
error: aborting due to 3 previous errors
5858

0 commit comments

Comments
 (0)