Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Dec 13, 2021
1 parent d59f74a commit 64dea33
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
Expand Up @@ -1735,16 +1735,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// | |
// LL | | foo(tx.clone());
// LL | | }).await;
// | | - ^^^^^^- value is later dropped here
// | | | |
// | |__________| await occurs here, with value maybe used later
// | | - ^^^^^^ await occurs here, with value maybe used later
// | |__________|
// | has type `closure` which is not `Send`
// note: value is later dropped here
// LL | | }).await;
// | | ^
//
// If available, use the scope span to annotate the drop location.
if let Some(scope_span) = scope_span {
let scope_span = source_map.end_point(scope_span);
span.push_span_label(scope_span, format!("{} is later dropped here", snippet));
}
span.push_span_label(
yield_span,
format!("{} occurs here, with {} maybe used later", await_or_yield, snippet),
Expand All @@ -1753,13 +1750,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
interior_span,
format!("has type `{}` which {}", target_ty, trait_explanation),
);
// If available, use the scope span to annotate the drop location.
let mut scope_note = None;
if let Some(scope_span) = scope_span {
let scope_span = source_map.end_point(scope_span);

let msg = format!("{} is later dropped here", snippet);
if source_map.is_multiline(yield_span.between(scope_span)) {
span.push_span_label(scope_span, msg);
} else {
scope_note = Some((scope_span, msg));
}
}
err.span_note(
span,
&format!(
"{} {} as this value is used across {}",
future_or_generator, trait_explanation, an_await_or_yield
),
);
if let Some((span, msg)) = scope_note {
err.span_note(span, &msg);
}
}
};
match interior_or_upvar_span {
Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/async-await/issue-70935-complex-spans.stderr
Expand Up @@ -12,10 +12,14 @@ LL | baz(|| async{
| _____________-
LL | | foo(tx.clone());
LL | | }).await;
| | - ^^^^^^- the value is later dropped here
| | | |
| |_________| await occurs here, with the value maybe used later
| | - ^^^^^^ await occurs here, with the value maybe used later
| |_________|
| has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10]` which is not `Send`
note: the value is later dropped here
--> $DIR/issue-70935-complex-spans.rs:15:17
|
LL | }).await;
| ^

error: aborting due to previous error

Expand Up @@ -9,10 +9,14 @@ note: future is not `Send` as this value is used across an await
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:35
|
LL | bar(Foo(std::ptr::null())).await;
| ---------------- ^^^^^^- `std::ptr::null()` is later dropped here
| | |
| | await occurs here, with `std::ptr::null()` maybe used later
| ---------------- ^^^^^^ await occurs here, with `std::ptr::null()` maybe used later
| |
| has type `*const u8` which is not `Send`
note: `std::ptr::null()` is later dropped here
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:41
|
LL | bar(Foo(std::ptr::null())).await;
| ^
help: consider moving this into a `let` binding to create a shorter lived borrow
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:13
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/async-await/unnecessary-await.rs
@@ -1,8 +1,8 @@
// edition:2018

async fn foo () { }
fn bar () -> impl std::future::Future { async {} }
fn boo () {}
fn bar() -> impl std::future::Future { async {} }
fn boo() {}

async fn baz() -> std::io::Result<()> {
foo().await;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/unnecessary-await.stderr
Expand Up @@ -16,7 +16,7 @@ LL + boo();
|
help: alternatively, consider making `fn boo` asynchronous
|
LL | async fn boo () {}
LL | async fn boo() {}
| +++++

error: aborting due to previous error
Expand Down

0 comments on commit 64dea33

Please sign in to comment.