mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Fix format
This commit is contained in:
parent
54d9ffc0b9
commit
8d651013e4
@ -1570,78 +1570,107 @@ 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 = |interior_span: Span,
|
let mut explain_yield =
|
||||||
yield_span: Span,
|
|interior_span: Span, yield_span: Span, scope_span: Option<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
|
// so that we do not emit complex diagnostics.
|
||||||
// so that we do not emit complex diagnostics.
|
let snippet = &format!("`{}`", snippet);
|
||||||
let snippet = &format!("`{}`", snippet);
|
let snippet = if snippet.contains('\n') { "the value" } else { snippet };
|
||||||
let snippet = if snippet.contains('\n') { "the value" } else { snippet };
|
// The multispan can be complex here, like:
|
||||||
// The multispan can be complex here, 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;
|
// | || - ^- value is later dropped here
|
||||||
// | || - ^- 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`
|
||||||
// | has type `closure` which is not `Send`
|
//
|
||||||
//
|
// 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...
|
||||||
// | |________________^ first, await occurs here, with the value maybe used later...
|
// note: the value is later dropped here
|
||||||
// note: 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;
|
// | ^
|
||||||
// | ^
|
//
|
||||||
//
|
// 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(
|
||||||
span.push_span_label(
|
yield_span,
|
||||||
yield_span,
|
format!(
|
||||||
format!(
|
"first, {} occurs here, with {} maybe used later...",
|
||||||
"first, {} occurs here, with {} maybe used later...",
|
await_or_yield, snippet
|
||||||
await_or_yield, snippet
|
),
|
||||||
),
|
|
||||||
);
|
|
||||||
err.span_note(
|
|
||||||
span,
|
|
||||||
&format!(
|
|
||||||
"{} {} as this value is used across {}",
|
|
||||||
future_or_generator, trait_explanation, an_await_or_yield
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if source_map.is_multiline(interior_span) {
|
|
||||||
err.span_note(scope_span, &format!("{} is later dropped here", snippet));
|
|
||||||
err.span_note(
|
|
||||||
interior_span,
|
|
||||||
&format!("this has type `{}` which {}", target_ty, trait_explanation),
|
|
||||||
);
|
);
|
||||||
|
err.span_note(
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"{} {} as this value is used across {}",
|
||||||
|
future_or_generator, trait_explanation, an_await_or_yield
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if source_map.is_multiline(interior_span) {
|
||||||
|
err.span_note(
|
||||||
|
scope_span,
|
||||||
|
&format!("{} is later dropped here", snippet),
|
||||||
|
);
|
||||||
|
err.span_note(
|
||||||
|
interior_span,
|
||||||
|
&format!(
|
||||||
|
"this has type `{}` which {}",
|
||||||
|
target_ty, trait_explanation
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
let mut span = MultiSpan::from_span(scope_span);
|
||||||
|
span.push_span_label(
|
||||||
|
interior_span,
|
||||||
|
format!("has type `{}` which {}", target_ty, trait_explanation),
|
||||||
|
);
|
||||||
|
err.span_note(span, &format!("{} is later dropped here", snippet));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut span = MultiSpan::from_span(scope_span);
|
span.push_span_label(
|
||||||
|
yield_span,
|
||||||
|
format!(
|
||||||
|
"{} occurs here, with {} maybe used later",
|
||||||
|
await_or_yield, snippet
|
||||||
|
),
|
||||||
|
);
|
||||||
|
span.push_span_label(
|
||||||
|
scope_span,
|
||||||
|
format!("{} is later dropped here", snippet),
|
||||||
|
);
|
||||||
span.push_span_label(
|
span.push_span_label(
|
||||||
interior_span,
|
interior_span,
|
||||||
format!("has type `{}` which {}", target_ty, trait_explanation),
|
format!("has type `{}` which {}", target_ty, trait_explanation),
|
||||||
);
|
);
|
||||||
err.span_note(span, &format!("{} is later dropped here", snippet));
|
err.span_note(
|
||||||
|
span,
|
||||||
|
&format!(
|
||||||
|
"{} {} as this value is used across {}",
|
||||||
|
future_or_generator, trait_explanation, an_await_or_yield
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
span.push_span_label(
|
span.push_span_label(
|
||||||
@ -1651,10 +1680,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
await_or_yield, snippet
|
await_or_yield, snippet
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
span.push_span_label(
|
|
||||||
scope_span,
|
|
||||||
format!("{} is later dropped here", snippet),
|
|
||||||
);
|
|
||||||
span.push_span_label(
|
span.push_span_label(
|
||||||
interior_span,
|
interior_span,
|
||||||
format!("has type `{}` which {}", target_ty, trait_explanation),
|
format!("has type `{}` which {}", target_ty, trait_explanation),
|
||||||
@ -1667,28 +1692,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
span.push_span_label(
|
|
||||||
yield_span,
|
|
||||||
format!(
|
|
||||||
"{} occurs here, with {} maybe used later",
|
|
||||||
await_or_yield, snippet
|
|
||||||
),
|
|
||||||
);
|
|
||||||
span.push_span_label(
|
|
||||||
interior_span,
|
|
||||||
format!("has type `{}` which {}", target_ty, trait_explanation),
|
|
||||||
);
|
|
||||||
err.span_note(
|
|
||||||
span,
|
|
||||||
&format!(
|
|
||||||
"{} {} as this value is used across {}",
|
|
||||||
future_or_generator, trait_explanation, an_await_or_yield
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
match interior_or_upvar_span {
|
match interior_or_upvar_span {
|
||||||
GeneratorInteriorOrUpvar::Interior(interior_span) => {
|
GeneratorInteriorOrUpvar::Interior(interior_span) => {
|
||||||
if let Some((scope_span, yield_span, expr, from_awaited_ty)) = interior_extra_info {
|
if let Some((scope_span, yield_span, expr, from_awaited_ty)) = interior_extra_info {
|
||||||
|
Loading…
Reference in New Issue
Block a user