1
Fork 0

Address some code reviews

This commit is contained in:
Yuki Okushi 2020-10-11 04:48:17 +09:00
parent ad978e5572
commit 66226ca157
3 changed files with 89 additions and 110 deletions

View file

@ -1570,8 +1570,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
format!("does not implement `{}`", trait_ref.print_only_trait_path()) format!("does not implement `{}`", trait_ref.print_only_trait_path())
}; };
let mut explain_yield = let mut explain_yield = |interior_span: Span,
|interior_span: Span, yield_span: Span, scope_span: Option<Span>| { yield_span: Span,
scope_span: Option<Span>| {
let mut span = MultiSpan::from_span(yield_span); let mut span = MultiSpan::from_span(yield_span);
if let Ok(snippet) = source_map.span_to_snippet(interior_span) { if let Ok(snippet) = source_map.span_to_snippet(interior_span) {
// #70935: If snippet contains newlines, display "the value" instead // #70935: If snippet contains newlines, display "the value" instead
@ -1592,35 +1593,35 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// | ||_________|______| // | ||_________|______|
// | |__________| await occurs here, with value maybe used later // | |__________| await occurs here, with value maybe used later
// | has type `closure` which is not `Send` // | has type `closure` which is not `Send`
// = note: the return type of a function must have a statically known size //
// So, detect it and separate into some notes, like: // So, detect it and separate into some notes, like:
//
// note: future is not `Send` as this value is used across an await // note: future is not `Send` as this value is used across an await
// --> $DIR/issue-70935-complex-spans.rs:13:9 // --> $DIR/issue-70935-complex-spans.rs:13:9
// | // |
// LL | / baz(|| async{ // LL | / baz(|| async{
// LL | | foo(tx.clone()); // LL | | foo(tx.clone());
// LL | | }).await; // LL | | }).await;
// | |________________^ // | |________________^ first, await occurs here, with the value maybe used later...
// note: first, await occurs here, with the value maybe used later // note: the value is later dropped here
// --> $DIR/issue-70935-complex-spans.rs:13:9
// |
// LL | / baz(|| async{
// LL | | foo(tx.clone());
// LL | | }).await;
// | |________________^
// note: ...but, the value is later dropped here
// --> $DIR/issue-70935-complex-spans.rs:15:17 // --> $DIR/issue-70935-complex-spans.rs:15:17
// | // |
// LL | }).await; // LL | }).await;
// | ^ // | ^
// = note: the return type of a function must have a statically known size //
// If available, use the scope span to annotate the drop location. // If available, use the scope span to annotate the drop location.
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 is_overlapped = let is_overlapped =
yield_span.overlaps(scope_span) || yield_span.overlaps(interior_span); yield_span.overlaps(scope_span) || yield_span.overlaps(interior_span);
if is_overlapped { if is_overlapped {
span.push_span_label(
yield_span,
format!(
"first, {} occurs here, with {} maybe used later...",
await_or_yield, snippet
),
);
err.span_note( err.span_note(
span, span,
&format!( &format!(
@ -1628,17 +1629,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
future_or_generator, trait_explanation, an_await_or_yield future_or_generator, trait_explanation, an_await_or_yield
), ),
); );
err.span_note( err.span_note(scope_span, &format!("{} is later dropped here", snippet));
yield_span,
&format!(
"first, {} occurs here, with {} maybe used later",
await_or_yield, snippet
),
);
err.span_note(
scope_span,
&format!("...but, {} is later dropped here", snippet),
);
} else { } else {
span.push_span_label( span.push_span_label(
yield_span, yield_span,

View file

@ -11,15 +11,8 @@ note: future is not `Send` as this value is used across an await
LL | / baz(|| async{ LL | / baz(|| async{
LL | | foo(tx.clone()); LL | | foo(tx.clone());
LL | | }).await; LL | | }).await;
| |________________^ | |________________^ first, await occurs here, with the value maybe used later...
note: first, await occurs here, with the value maybe used later note: the value is later dropped here
--> $DIR/issue-70935-complex-spans.rs:13:9
|
LL | / baz(|| async{
LL | | foo(tx.clone());
LL | | }).await;
| |________________^
note: ...but, the value is later dropped here
--> $DIR/issue-70935-complex-spans.rs:15:17 --> $DIR/issue-70935-complex-spans.rs:15:17
| |
LL | }).await; LL | }).await;

View file

@ -12,13 +12,8 @@ note: future is not `Send` as this value is used across an await
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:9 --> $DIR/issue-65436-raw-ptr-not-send.rs:14:9
| |
LL | bar(Foo(std::ptr::null())).await; LL | bar(Foo(std::ptr::null())).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ first, await occurs here, with `std::ptr::null()` maybe used later...
note: first, await occurs here, with `std::ptr::null()` maybe used later note: `std::ptr::null()` is later dropped here
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:9
|
LL | bar(Foo(std::ptr::null())).await;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...but, `std::ptr::null()` is later dropped here
--> $DIR/issue-65436-raw-ptr-not-send.rs:14:41 --> $DIR/issue-65436-raw-ptr-not-send.rs:14:41
| |
LL | bar(Foo(std::ptr::null())).await; LL | bar(Foo(std::ptr::null())).await;