Use a label instead of a note for the drop site to create denser diagnostics

This commit is contained in:
Oli Scherer
2022-12-12 15:57:31 +00:00
parent 6984085088
commit 1f5cb9e50e
6 changed files with 16 additions and 45 deletions

View File

@@ -2212,17 +2212,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
interior_span, interior_span,
format!("has type `{}` which {}", target_ty, trait_explanation), 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 { if let Some(scope_span) = scope_span {
let scope_span = source_map.end_point(scope_span); let scope_span = source_map.end_point(scope_span);
let msg = format!("{} is later dropped here", snippet); 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);
span.push_span_label(scope_span, msg);
} else {
scope_note = Some((scope_span, msg));
}
} }
err.span_note( err.span_note(
span, span,
@@ -2231,9 +2225,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
future_or_generator, trait_explanation, an_await_or_yield 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 { match interior_or_upvar_span {
GeneratorInteriorOrUpvar::Interior(interior_span, interior_extra_info) => { GeneratorInteriorOrUpvar::Interior(interior_span, interior_extra_info) => {

View File

@@ -68,14 +68,10 @@ note: future is not `Send` as this value is used across an await
--> $DIR/async-await-let-else.rs:33:28 --> $DIR/async-await-let-else.rs:33:28
| |
LL | (Rc::new(()), bar().await); LL | (Rc::new(()), bar().await);
| ----------- ^^^^^^ await occurs here, with `Rc::new(())` maybe used later | ----------- ^^^^^^ - `Rc::new(())` is later dropped here
| | | | |
| | await occurs here, with `Rc::new(())` maybe used later
| has type `Rc<()>` which is not `Send` | has type `Rc<()>` which is not `Send`
note: `Rc::new(())` is later dropped here
--> $DIR/async-await-let-else.rs:33:35
|
LL | (Rc::new(()), bar().await);
| ^
note: required by a bound in `is_send` note: required by a bound in `is_send`
--> $DIR/async-await-let-else.rs:19:15 --> $DIR/async-await-let-else.rs:19:15
| |

View File

@@ -53,14 +53,10 @@ note: future is not `Send` as this value is used across an await
--> $DIR/async-await-let-else.rs:33:28 --> $DIR/async-await-let-else.rs:33:28
| |
LL | (Rc::new(()), bar().await); LL | (Rc::new(()), bar().await);
| ----------- ^^^^^^ await occurs here, with `Rc::new(())` maybe used later | ----------- ^^^^^^ - `Rc::new(())` is later dropped here
| | | | |
| | await occurs here, with `Rc::new(())` maybe used later
| has type `Rc<()>` which is not `Send` | has type `Rc<()>` which is not `Send`
note: `Rc::new(())` is later dropped here
--> $DIR/async-await-let-else.rs:33:35
|
LL | (Rc::new(()), bar().await);
| ^
note: required by a bound in `is_send` note: required by a bound in `is_send`
--> $DIR/async-await-let-else.rs:19:15 --> $DIR/async-await-let-else.rs:19:15
| |

View File

@@ -12,14 +12,10 @@ LL | baz(|| async{
| _____________- | _____________-
LL | | foo(tx.clone()); LL | | foo(tx.clone());
LL | | }).await; LL | | }).await;
| | - ^^^^^^ await occurs here, with the value maybe used later | | - ^^^^^^- the value is later dropped here
| |_________| | | | |
| |_________| await occurs here, with the value maybe used later
| has type `[closure@$DIR/issue-70935-complex-spans.rs:17:13: 17:15]` which is not `Send` | has type `[closure@$DIR/issue-70935-complex-spans.rs:17:13: 17:15]` which is not `Send`
note: the value is later dropped here
--> $DIR/issue-70935-complex-spans.rs:19:17
|
LL | }).await;
| ^
error: aborting due to previous error error: aborting due to previous error

View File

@@ -13,14 +13,10 @@ note: future is not `Send` as this value is used across an await
--> $DIR/issue-65436-raw-ptr-not-send.rs:18:35 --> $DIR/issue-65436-raw-ptr-not-send.rs:18:35
| |
LL | bar(Foo(std::ptr::null())).await; LL | bar(Foo(std::ptr::null())).await;
| ---------------- ^^^^^^ await occurs here, with `std::ptr::null()` maybe used later | ---------------- ^^^^^^- `std::ptr::null()` is later dropped here
| | | | |
| | await occurs here, with `std::ptr::null()` maybe used later
| has type `*const u8` which is not `Send` | has type `*const u8` which is not `Send`
note: `std::ptr::null()` is later dropped here
--> $DIR/issue-65436-raw-ptr-not-send.rs:18:41
|
LL | bar(Foo(std::ptr::null())).await;
| ^
help: consider moving this into a `let` binding to create a shorter lived borrow help: consider moving this into a `let` binding to create a shorter lived borrow
--> $DIR/issue-65436-raw-ptr-not-send.rs:18:13 --> $DIR/issue-65436-raw-ptr-not-send.rs:18:13
| |

View File

@@ -9,14 +9,10 @@ note: future is not `Send` as this value is used across an await
--> $DIR/auxiliary/issue_67893.rs:9:26 --> $DIR/auxiliary/issue_67893.rs:9:26
| |
LL | f(*x.lock().unwrap()).await; LL | f(*x.lock().unwrap()).await;
| ----------------- ^^^^^^ await occurs here, with `x.lock().unwrap()` maybe used later | ----------------- ^^^^^^- `x.lock().unwrap()` is later dropped here
| | | | |
| | await occurs here, with `x.lock().unwrap()` maybe used later
| has type `MutexGuard<'_, ()>` which is not `Send` | has type `MutexGuard<'_, ()>` which is not `Send`
note: `x.lock().unwrap()` is later dropped here
--> $DIR/auxiliary/issue_67893.rs:9:32
|
LL | f(*x.lock().unwrap()).await;
| ^
note: required by a bound in `g` note: required by a bound in `g`
--> $DIR/issue-67893.rs:6:14 --> $DIR/issue-67893.rs:6:14
| |