Skip to content

Commit 12f1795

Browse files
Fix location of error message explanation
1 parent 5ccef56 commit 12f1795

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,16 +1323,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13231323
suggestion,
13241324
Applicability::MachineApplicable,
13251325
);
1326-
if let Some(generator_kind) = use_span.generator_kind() {
1327-
if let GeneratorKind::Async(_) = generator_kind {
1328-
err.note(
1329-
"borrows cannot be held across a yield point, because the stack space of the current \
1330-
function is not preserved",
1331-
);
1332-
err.help("see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
1333-
for more information");
1334-
}
1335-
}
13361326

13371327
let msg = match category {
13381328
ConstraintCategory::Return(_) | ConstraintCategory::OpaqueType => {
@@ -1349,6 +1339,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13491339
),
13501340
};
13511341
err.span_note(constraint_span, &msg);
1342+
if let ConstraintCategory::CallArgument = category {
1343+
if let Some(generator_kind) = use_span.generator_kind() {
1344+
if let GeneratorKind::Async(_) = generator_kind {
1345+
err.note(
1346+
"borrows cannot be held across a yield point, because the stack \
1347+
space of the current function is not preserved",
1348+
);
1349+
err.help("see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor \
1350+
for more information");
1351+
}
1352+
}
1353+
}
13521354
err
13531355
}
13541356

src/test/ui/async-await/issues/issue-78938-async-block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn game_loop(v: Arc<Vec<usize>>) {}
1616
fn spawn<F>(future: F) -> JoinHandle
1717
where
1818
F: Future + Send + 'static,
19-
F::Output: Send + 'static,
19+
F::Output: Send + 'static,
2020
{
2121
loop {}
2222
}
@@ -26,8 +26,8 @@ struct JoinHandle;
2626
impl Future for JoinHandle {
2727
type Output = ();
2828
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
29-
loop {}
29+
loop {}
3030
}
3131
}
3232

33-
fn main() {}
33+
fn main() {}

src/test/ui/async-await/issues/issue-78938-async-block.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ LL | | game_loop(Arc::clone(&room_ref))
88
LL | | });
99
| |_____^ may outlive borrowed value `room_ref`
1010
|
11-
= note: borrows cannot be held across a yield point, because the stack space of the current function is not preserved
12-
= help: see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor for more information
1311
note: function requires argument type to outlive `'static`
1412
--> $DIR/issue-78938-async-block.rs:8:33
1513
|
@@ -18,6 +16,8 @@ LL | let gameloop_handle = spawn(async {
1816
LL | | game_loop(Arc::clone(&room_ref))
1917
LL | | });
2018
| |_____^
19+
= note: borrows cannot be held across a yield point, because the stack space of the current function is not preserved
20+
= help: see https://rust-lang.github.io/async-book/03_async_await/01_chapter.html#awaiting-on-a-multithreaded-executor for more information
2121
help: to force the async block to take ownership of `room_ref` (and any other referenced variables), use the `move` keyword
2222
|
2323
LL | let gameloop_handle = spawn(async move {

0 commit comments

Comments
 (0)