review comments

This commit is contained in:
Esteban Kuber 2021-12-02 23:41:45 +00:00
parent d59f74aeaf
commit 64dea33a3d
5 changed files with 37 additions and 17 deletions

View file

@ -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),
@ -1753,6 +1750,18 @@ 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!(
@ -1760,6 +1769,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
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 {

View file

@ -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

View file

@ -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
|