@@ -1717,130 +1717,51 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
17171717 format ! ( "does not implement `{}`" , trait_ref. print_only_trait_path( ) )
17181718 } ;
17191719
1720- let mut explain_yield =
1721- |interior_span : Span , yield_span : Span , scope_span : Option < Span > | {
1722- let mut span = MultiSpan :: from_span ( yield_span) ;
1723- if let Ok ( snippet) = source_map. span_to_snippet ( interior_span) {
1724- // #70935: If snippet contains newlines, display "the value" instead
1725- // so that we do not emit complex diagnostics.
1726- let snippet = & format ! ( "`{}`" , snippet) ;
1727- let snippet = if snippet. contains ( '\n' ) { "the value" } else { snippet } ;
1728- // The multispan can be complex here, like:
1729- // note: future is not `Send` as this value is used across an await
1730- // --> $DIR/issue-70935-complex-spans.rs:13:9
1731- // |
1732- // LL | baz(|| async{
1733- // | __________^___-
1734- // | | _________|
1735- // | ||
1736- // LL | || foo(tx.clone());
1737- // LL | || }).await;
1738- // | || - ^- value is later dropped here
1739- // | ||_________|______|
1740- // | |__________| await occurs here, with value maybe used later
1741- // | has type `closure` which is not `Send`
1742- //
1743- // So, detect it and separate into some notes, like:
1744- //
1745- // note: future is not `Send` as this value is used across an await
1746- // --> $DIR/issue-70935-complex-spans.rs:13:9
1747- // |
1748- // LL | / baz(|| async{
1749- // LL | | foo(tx.clone());
1750- // LL | | }).await;
1751- // | |________________^ first, await occurs here, with the value maybe used later...
1752- // note: the value is later dropped here
1753- // --> $DIR/issue-70935-complex-spans.rs:15:17
1754- // |
1755- // LL | }).await;
1756- // | ^
1757- //
1758- // If available, use the scope span to annotate the drop location.
1759- if let Some ( scope_span) = scope_span {
1760- let scope_span = source_map. end_point ( scope_span) ;
1761- let is_overlapped =
1762- yield_span. overlaps ( scope_span) || yield_span. overlaps ( interior_span) ;
1763- if is_overlapped {
1764- span. push_span_label (
1765- yield_span,
1766- format ! (
1767- "first, {} occurs here, with {} maybe used later..." ,
1768- await_or_yield, snippet
1769- ) ,
1770- ) ;
1771- err. span_note (
1772- span,
1773- & format ! (
1774- "{} {} as this value is used across {}" ,
1775- future_or_generator, trait_explanation, an_await_or_yield
1776- ) ,
1777- ) ;
1778- if source_map. is_multiline ( interior_span) {
1779- err. span_note (
1780- scope_span,
1781- & format ! ( "{} is later dropped here" , snippet) ,
1782- ) ;
1783- err. span_note (
1784- interior_span,
1785- & format ! (
1786- "this has type `{}` which {}" ,
1787- target_ty, trait_explanation
1788- ) ,
1789- ) ;
1790- } else {
1791- let mut span = MultiSpan :: from_span ( scope_span) ;
1792- span. push_span_label (
1793- interior_span,
1794- format ! ( "has type `{}` which {}" , target_ty, trait_explanation) ,
1795- ) ;
1796- err. span_note ( span, & format ! ( "{} is later dropped here" , snippet) ) ;
1797- }
1798- } else {
1799- span. push_span_label (
1800- yield_span,
1801- format ! (
1802- "{} occurs here, with {} maybe used later" ,
1803- await_or_yield, snippet
1804- ) ,
1805- ) ;
1806- span. push_span_label (
1807- scope_span,
1808- format ! ( "{} is later dropped here" , snippet) ,
1809- ) ;
1810- span. push_span_label (
1811- interior_span,
1812- format ! ( "has type `{}` which {}" , target_ty, trait_explanation) ,
1813- ) ;
1814- err. span_note (
1815- span,
1816- & format ! (
1817- "{} {} as this value is used across {}" ,
1818- future_or_generator, trait_explanation, an_await_or_yield
1819- ) ,
1820- ) ;
1821- }
1822- } else {
1823- span. push_span_label (
1824- yield_span,
1825- format ! (
1826- "{} occurs here, with {} maybe used later" ,
1827- await_or_yield, snippet
1828- ) ,
1829- ) ;
1830- span. push_span_label (
1831- interior_span,
1832- format ! ( "has type `{}` which {}" , target_ty, trait_explanation) ,
1833- ) ;
1834- err. span_note (
1835- span,
1836- & format ! (
1837- "{} {} as this value is used across {}" ,
1838- future_or_generator, trait_explanation, an_await_or_yield
1839- ) ,
1840- ) ;
1841- }
1720+ let mut explain_yield = |interior_span : Span ,
1721+ yield_span : Span ,
1722+ scope_span : Option < Span > | {
1723+ let mut span = MultiSpan :: from_span ( yield_span) ;
1724+ if let Ok ( snippet) = source_map. span_to_snippet ( interior_span) {
1725+ // #70935: If snippet contains newlines, display "the value" instead
1726+ // so that we do not emit complex diagnostics.
1727+ let snippet = & format ! ( "`{}`" , snippet) ;
1728+ let snippet = if snippet. contains ( '\n' ) { "the value" } else { snippet } ;
1729+ // note: future is not `Send` as this value is used across an await
1730+ // --> $DIR/issue-70935-complex-spans.rs:13:9
1731+ // |
1732+ // LL | baz(|| async {
1733+ // | ______________-
1734+ // | |
1735+ // | |
1736+ // LL | | foo(tx.clone());
1737+ // LL | | }).await;
1738+ // | | - ^^^^^^- value is later dropped here
1739+ // | | | |
1740+ // | |__________| await occurs here, with value maybe used later
1741+ // | has type `closure` which is not `Send`
1742+ //
1743+ // If available, use the scope span to annotate the drop location.
1744+ if let Some ( scope_span) = scope_span {
1745+ let scope_span = source_map. end_point ( scope_span) ;
1746+ span. push_span_label ( scope_span, format ! ( "{} is later dropped here" , snippet) ) ;
18421747 }
1843- } ;
1748+ span. push_span_label (
1749+ yield_span,
1750+ format ! ( "{} occurs here, with {} maybe used later" , await_or_yield, snippet) ,
1751+ ) ;
1752+ span. push_span_label (
1753+ interior_span,
1754+ format ! ( "has type `{}` which {}" , target_ty, trait_explanation) ,
1755+ ) ;
1756+ err. span_note (
1757+ span,
1758+ & format ! (
1759+ "{} {} as this value is used across {}" ,
1760+ future_or_generator, trait_explanation, an_await_or_yield
1761+ ) ,
1762+ ) ;
1763+ }
1764+ } ;
18441765 match interior_or_upvar_span {
18451766 GeneratorInteriorOrUpvar :: Interior ( interior_span) => {
18461767 if let Some ( ( scope_span, yield_span, expr, from_awaited_ty) ) = interior_extra_info {
0 commit comments