Skip to content

Commit 8d65101

Browse files
committed
Fix format
1 parent 54d9ffc commit 8d65101

File tree

1 file changed

+95
-90
lines changed
  • compiler/rustc_trait_selection/src/traits/error_reporting

1 file changed

+95
-90
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+95-90
Original file line numberDiff line numberDiff line change
@@ -1570,78 +1570,107 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
15701570
format!("does not implement `{}`", trait_ref.print_only_trait_path())
15711571
};
15721572

1573-
let mut explain_yield = |interior_span: Span,
1574-
yield_span: Span,
1575-
scope_span: Option<Span>| {
1576-
let mut span = MultiSpan::from_span(yield_span);
1577-
if let Ok(snippet) = source_map.span_to_snippet(interior_span) {
1578-
// #70935: If snippet contains newlines, display "the value" instead
1579-
// so that we do not emit complex diagnostics.
1580-
let snippet = &format!("`{}`", snippet);
1581-
let snippet = if snippet.contains('\n') { "the value" } else { snippet };
1582-
// The multispan can be complex here, like:
1583-
// note: future is not `Send` as this value is used across an await
1584-
// --> $DIR/issue-70935-complex-spans.rs:13:9
1585-
// |
1586-
// LL | baz(|| async{
1587-
// | __________^___-
1588-
// | | _________|
1589-
// | ||
1590-
// LL | || foo(tx.clone());
1591-
// LL | || }).await;
1592-
// | || - ^- value is later dropped here
1593-
// | ||_________|______|
1594-
// | |__________| await occurs here, with value maybe used later
1595-
// | has type `closure` which is not `Send`
1596-
//
1597-
// So, detect it and separate into some notes, like:
1598-
//
1599-
// note: future is not `Send` as this value is used across an await
1600-
// --> $DIR/issue-70935-complex-spans.rs:13:9
1601-
// |
1602-
// LL | / baz(|| async{
1603-
// LL | | foo(tx.clone());
1604-
// LL | | }).await;
1605-
// | |________________^ first, await occurs here, with the value maybe used later...
1606-
// note: the value is later dropped here
1607-
// --> $DIR/issue-70935-complex-spans.rs:15:17
1608-
// |
1609-
// LL | }).await;
1610-
// | ^
1611-
//
1612-
// If available, use the scope span to annotate the drop location.
1613-
if let Some(scope_span) = scope_span {
1614-
let scope_span = source_map.end_point(scope_span);
1615-
let is_overlapped =
1616-
yield_span.overlaps(scope_span) || yield_span.overlaps(interior_span);
1617-
if is_overlapped {
1618-
span.push_span_label(
1619-
yield_span,
1620-
format!(
1621-
"first, {} occurs here, with {} maybe used later...",
1622-
await_or_yield, snippet
1623-
),
1624-
);
1625-
err.span_note(
1626-
span,
1627-
&format!(
1628-
"{} {} as this value is used across {}",
1629-
future_or_generator, trait_explanation, an_await_or_yield
1630-
),
1631-
);
1632-
if source_map.is_multiline(interior_span) {
1633-
err.span_note(scope_span, &format!("{} is later dropped here", snippet));
1573+
let mut explain_yield =
1574+
|interior_span: Span, yield_span: Span, scope_span: Option<Span>| {
1575+
let mut span = MultiSpan::from_span(yield_span);
1576+
if let Ok(snippet) = source_map.span_to_snippet(interior_span) {
1577+
// #70935: If snippet contains newlines, display "the value" instead
1578+
// so that we do not emit complex diagnostics.
1579+
let snippet = &format!("`{}`", snippet);
1580+
let snippet = if snippet.contains('\n') { "the value" } else { snippet };
1581+
// The multispan can be complex here, like:
1582+
// note: future is not `Send` as this value is used across an await
1583+
// --> $DIR/issue-70935-complex-spans.rs:13:9
1584+
// |
1585+
// LL | baz(|| async{
1586+
// | __________^___-
1587+
// | | _________|
1588+
// | ||
1589+
// LL | || foo(tx.clone());
1590+
// LL | || }).await;
1591+
// | || - ^- value is later dropped here
1592+
// | ||_________|______|
1593+
// | |__________| await occurs here, with value maybe used later
1594+
// | has type `closure` which is not `Send`
1595+
//
1596+
// So, detect it and separate into some notes, like:
1597+
//
1598+
// note: future is not `Send` as this value is used across an await
1599+
// --> $DIR/issue-70935-complex-spans.rs:13:9
1600+
// |
1601+
// LL | / baz(|| async{
1602+
// LL | | foo(tx.clone());
1603+
// LL | | }).await;
1604+
// | |________________^ first, await occurs here, with the value maybe used later...
1605+
// note: the value is later dropped here
1606+
// --> $DIR/issue-70935-complex-spans.rs:15:17
1607+
// |
1608+
// LL | }).await;
1609+
// | ^
1610+
//
1611+
// If available, use the scope span to annotate the drop location.
1612+
if let Some(scope_span) = scope_span {
1613+
let scope_span = source_map.end_point(scope_span);
1614+
let is_overlapped =
1615+
yield_span.overlaps(scope_span) || yield_span.overlaps(interior_span);
1616+
if is_overlapped {
1617+
span.push_span_label(
1618+
yield_span,
1619+
format!(
1620+
"first, {} occurs here, with {} maybe used later...",
1621+
await_or_yield, snippet
1622+
),
1623+
);
16341624
err.span_note(
1635-
interior_span,
1636-
&format!("this has type `{}` which {}", target_ty, trait_explanation),
1625+
span,
1626+
&format!(
1627+
"{} {} as this value is used across {}",
1628+
future_or_generator, trait_explanation, an_await_or_yield
1629+
),
16371630
);
1631+
if source_map.is_multiline(interior_span) {
1632+
err.span_note(
1633+
scope_span,
1634+
&format!("{} is later dropped here", snippet),
1635+
);
1636+
err.span_note(
1637+
interior_span,
1638+
&format!(
1639+
"this has type `{}` which {}",
1640+
target_ty, trait_explanation
1641+
),
1642+
);
1643+
} else {
1644+
let mut span = MultiSpan::from_span(scope_span);
1645+
span.push_span_label(
1646+
interior_span,
1647+
format!("has type `{}` which {}", target_ty, trait_explanation),
1648+
);
1649+
err.span_note(span, &format!("{} is later dropped here", snippet));
1650+
}
16381651
} else {
1639-
let mut span = MultiSpan::from_span(scope_span);
1652+
span.push_span_label(
1653+
yield_span,
1654+
format!(
1655+
"{} occurs here, with {} maybe used later",
1656+
await_or_yield, snippet
1657+
),
1658+
);
1659+
span.push_span_label(
1660+
scope_span,
1661+
format!("{} is later dropped here", snippet),
1662+
);
16401663
span.push_span_label(
16411664
interior_span,
16421665
format!("has type `{}` which {}", target_ty, trait_explanation),
16431666
);
1644-
err.span_note(span, &format!("{} is later dropped here", snippet));
1667+
err.span_note(
1668+
span,
1669+
&format!(
1670+
"{} {} as this value is used across {}",
1671+
future_or_generator, trait_explanation, an_await_or_yield
1672+
),
1673+
);
16451674
}
16461675
} else {
16471676
span.push_span_label(
@@ -1651,10 +1680,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
16511680
await_or_yield, snippet
16521681
),
16531682
);
1654-
span.push_span_label(
1655-
scope_span,
1656-
format!("{} is later dropped here", snippet),
1657-
);
16581683
span.push_span_label(
16591684
interior_span,
16601685
format!("has type `{}` which {}", target_ty, trait_explanation),
@@ -1667,28 +1692,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
16671692
),
16681693
);
16691694
}
1670-
} else {
1671-
span.push_span_label(
1672-
yield_span,
1673-
format!(
1674-
"{} occurs here, with {} maybe used later",
1675-
await_or_yield, snippet
1676-
),
1677-
);
1678-
span.push_span_label(
1679-
interior_span,
1680-
format!("has type `{}` which {}", target_ty, trait_explanation),
1681-
);
1682-
err.span_note(
1683-
span,
1684-
&format!(
1685-
"{} {} as this value is used across {}",
1686-
future_or_generator, trait_explanation, an_await_or_yield
1687-
),
1688-
);
16891695
}
1690-
}
1691-
};
1696+
};
16921697
match interior_or_upvar_span {
16931698
GeneratorInteriorOrUpvar::Interior(interior_span) => {
16941699
if let Some((scope_span, yield_span, expr, from_awaited_ty)) = interior_extra_info {

0 commit comments

Comments
 (0)