Skip to content

Commit 0da4c44

Browse files
committed
Account for closures
1 parent 3a471b5 commit 0da4c44

File tree

6 files changed

+9
-24
lines changed

6 files changed

+9
-24
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
167167
);
168168
}
169169

170-
self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
170+
let closure = self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
171171

172172
let mut is_loop_move = false;
173173
let mut in_pattern = false;
@@ -193,7 +193,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
193193
}
194194

195195
if !seen_spans.contains(&move_span) {
196-
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
196+
if !closure {
197+
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
198+
}
197199

198200
self.explain_captures(
199201
&mut err,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
7070
location: Location,
7171
place: PlaceRef<'tcx>,
7272
diag: &mut Diagnostic,
73-
) {
73+
) -> bool {
7474
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
7575
let mut target = place.local_or_deref_local();
7676
for stmt in &self.body[location.block].statements[location.statement_index..] {
@@ -106,7 +106,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
106106
{
107107
place.local_or_deref_local().unwrap()
108108
}
109-
_ => return,
109+
_ => return false,
110110
};
111111

112112
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
@@ -125,7 +125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
125125
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
126126
),
127127
);
128-
return;
128+
return true;
129129
}
130130
}
131131
}
@@ -149,9 +149,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
149149
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
150150
),
151151
);
152+
return true;
152153
}
153154
}
154155
}
156+
false
155157
}
156158

157159
/// End-user visible description of `place` if one can be found.

src/test/ui/closure_context/issue-42065.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ note: this value implements `FnOnce`, which causes it to be moved when called
1616
|
1717
LL | debug_dump_dict();
1818
| ^^^^^^^^^^^^^^^
19-
help: consider cloning the value if the performance cost is acceptable
20-
|
21-
LL | debug_dump_dict.clone()();
22-
| ++++++++
2319

2420
error: aborting due to previous error
2521

src/test/ui/moves/borrow-closures-instead-of-move.stderr

-7
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ note: closure cannot be moved more than once as it is not `Copy` due to moving t
5858
|
5959
LL | x += 1;
6060
| ^
61-
note: consider changing this parameter type in function `takes_fnonce` to borrow instead if owning the value isn't necessary
62-
--> $DIR/borrow-closures-instead-of-move.rs:34:20
63-
|
64-
LL | fn takes_fnonce(_: impl FnOnce()) {}
65-
| ------------ ^^^^^^^^^^^^^ this parameter takes ownership of the value
66-
| |
67-
| in this function
6861
help: consider mutably borrowing `closure`
6962
|
7063
LL | takes_fnonce(&mut closure);

src/test/ui/unboxed-closures/unboxed-closures-infer-fnonce-call-twice.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ note: this value implements `FnOnce`, which causes it to be moved when called
1616
|
1717
LL | tick();
1818
| ^^^^
19-
help: consider cloning the value if the performance cost is acceptable
20-
|
21-
LL | tick.clone()();
22-
| ++++++++
2319

2420
error: aborting due to previous error
2521

src/test/ui/unboxed-closures/unboxed-closures-infer-fnonce-move-call-twice.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ note: this value implements `FnOnce`, which causes it to be moved when called
1616
|
1717
LL | tick();
1818
| ^^^^
19-
help: consider cloning the value if the performance cost is acceptable
20-
|
21-
LL | tick.clone()();
22-
| ++++++++
2319

2420
error: aborting due to previous error
2521

0 commit comments

Comments
 (0)