aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r--crates/ide_assists/src/handlers/extract_function.rs711
1 files changed, 409 insertions, 302 deletions
diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs
index 7085a0c48..43e83d683 100644
--- a/crates/ide_assists/src/handlers/extract_function.rs
+++ b/crates/ide_assists/src/handlers/extract_function.rs
@@ -831,6 +831,7 @@ fn path_element_of_reference(
831 })?; 831 })?;
832 stdx::always!( 832 stdx::always!(
833 matches!(path, ast::Expr::PathExpr(_) | ast::Expr::MacroCall(_)), 833 matches!(path, ast::Expr::PathExpr(_) | ast::Expr::MacroCall(_)),
834
834 "unexpected expression type for variable usage: {:?}", 835 "unexpected expression type for variable usage: {:?}",
835 path 836 path
836 ); 837 );
@@ -1501,7 +1502,8 @@ mod tests {
1501 r#" 1502 r#"
1502fn foo() { 1503fn foo() {
1503 foo($01 + 1$0); 1504 foo($01 + 1$0);
1504}"#, 1505}
1506"#,
1505 r#" 1507 r#"
1506fn foo() { 1508fn foo() {
1507 foo(fun_name()); 1509 foo(fun_name());
@@ -1509,7 +1511,8 @@ fn foo() {
1509 1511
1510fn $0fun_name() -> i32 { 1512fn $0fun_name() -> i32 {
1511 1 + 1 1513 1 + 1
1512}"#, 1514}
1515"#,
1513 ); 1516 );
1514 } 1517 }
1515 1518
@@ -1522,7 +1525,8 @@ mod bar {
1522 fn foo() { 1525 fn foo() {
1523 foo($01 + 1$0); 1526 foo($01 + 1$0);
1524 } 1527 }
1525}"#, 1528}
1529"#,
1526 r#" 1530 r#"
1527mod bar { 1531mod bar {
1528 fn foo() { 1532 fn foo() {
@@ -1532,7 +1536,8 @@ mod bar {
1532 fn $0fun_name() -> i32 { 1536 fn $0fun_name() -> i32 {
1533 1 + 1 1537 1 + 1
1534 } 1538 }
1535}"#, 1539}
1540"#,
1536 ); 1541 );
1537 } 1542 }
1538 1543
@@ -1543,7 +1548,8 @@ mod bar {
1543 r#" 1548 r#"
1544fn foo() { 1549fn foo() {
1545 $0{ 1 + 1 }$0; 1550 $0{ 1 + 1 }$0;
1546}"#, 1551}
1552"#,
1547 r#" 1553 r#"
1548fn foo() { 1554fn foo() {
1549 fun_name(); 1555 fun_name();
@@ -1551,7 +1557,8 @@ fn foo() {
1551 1557
1552fn $0fun_name() -> i32 { 1558fn $0fun_name() -> i32 {
1553 1 + 1 1559 1 + 1
1554}"#, 1560}
1561"#,
1555 ); 1562 );
1556 } 1563 }
1557 1564
@@ -1564,7 +1571,8 @@ fn foo() -> i32 {
1564 let k = 1; 1571 let k = 1;
1565 $0let m = 1; 1572 $0let m = 1;
1566 m + 1$0 1573 m + 1$0
1567}"#, 1574}
1575"#,
1568 r#" 1576 r#"
1569fn foo() -> i32 { 1577fn foo() -> i32 {
1570 let k = 1; 1578 let k = 1;
@@ -1574,7 +1582,8 @@ fn foo() -> i32 {
1574fn $0fun_name() -> i32 { 1582fn $0fun_name() -> i32 {
1575 let m = 1; 1583 let m = 1;
1576 m + 1 1584 m + 1
1577}"#, 1585}
1586"#,
1578 ); 1587 );
1579 } 1588 }
1580 1589
@@ -1588,7 +1597,8 @@ fn foo() {
1588 $0let m = 1; 1597 $0let m = 1;
1589 let n = m + 1;$0 1598 let n = m + 1;$0
1590 let g = 5; 1599 let g = 5;
1591}"#, 1600}
1601"#,
1592 r#" 1602 r#"
1593fn foo() { 1603fn foo() {
1594 let k = 3; 1604 let k = 3;
@@ -1599,7 +1609,8 @@ fn foo() {
1599fn $0fun_name() { 1609fn $0fun_name() {
1600 let m = 1; 1610 let m = 1;
1601 let n = m + 1; 1611 let n = m + 1;
1602}"#, 1612}
1613"#,
1603 ); 1614 );
1604 } 1615 }
1605 1616
@@ -1610,7 +1621,8 @@ fn $0fun_name() {
1610 r#" 1621 r#"
1611fn foo() { 1622fn foo() {
1612 $0if true { }$0 1623 $0if true { }$0
1613}"#, 1624}
1625"#,
1614 r#" 1626 r#"
1615fn foo() { 1627fn foo() {
1616 fun_name(); 1628 fun_name();
@@ -1618,7 +1630,8 @@ fn foo() {
1618 1630
1619fn $0fun_name() { 1631fn $0fun_name() {
1620 if true { } 1632 if true { }
1621}"#, 1633}
1634"#,
1622 ); 1635 );
1623 } 1636 }
1624 1637
@@ -1629,7 +1642,8 @@ fn $0fun_name() {
1629 r#" 1642 r#"
1630fn foo() -> i32 { 1643fn foo() -> i32 {
1631 $0if true { 1 } else { 2 }$0 1644 $0if true { 1 } else { 2 }$0
1632}"#, 1645}
1646"#,
1633 r#" 1647 r#"
1634fn foo() -> i32 { 1648fn foo() -> i32 {
1635 fun_name() 1649 fun_name()
@@ -1637,7 +1651,8 @@ fn foo() -> i32 {
1637 1651
1638fn $0fun_name() -> i32 { 1652fn $0fun_name() -> i32 {
1639 if true { 1 } else { 2 } 1653 if true { 1 } else { 2 }
1640}"#, 1654}
1655"#,
1641 ); 1656 );
1642 } 1657 }
1643 1658
@@ -1648,7 +1663,8 @@ fn $0fun_name() -> i32 {
1648 r#" 1663 r#"
1649fn foo() -> i32 { 1664fn foo() -> i32 {
1650 $0if let true = false { 1 } else { 2 }$0 1665 $0if let true = false { 1 } else { 2 }$0
1651}"#, 1666}
1667"#,
1652 r#" 1668 r#"
1653fn foo() -> i32 { 1669fn foo() -> i32 {
1654 fun_name() 1670 fun_name()
@@ -1656,7 +1672,8 @@ fn foo() -> i32 {
1656 1672
1657fn $0fun_name() -> i32 { 1673fn $0fun_name() -> i32 {
1658 if let true = false { 1 } else { 2 } 1674 if let true = false { 1 } else { 2 }
1659}"#, 1675}
1676"#,
1660 ); 1677 );
1661 } 1678 }
1662 1679
@@ -1670,7 +1687,8 @@ fn foo() -> i32 {
1670 true => 1, 1687 true => 1,
1671 false => 2, 1688 false => 2,
1672 }$0 1689 }$0
1673}"#, 1690}
1691"#,
1674 r#" 1692 r#"
1675fn foo() -> i32 { 1693fn foo() -> i32 {
1676 fun_name() 1694 fun_name()
@@ -1681,7 +1699,8 @@ fn $0fun_name() -> i32 {
1681 true => 1, 1699 true => 1,
1682 false => 2, 1700 false => 2,
1683 } 1701 }
1684}"#, 1702}
1703"#,
1685 ); 1704 );
1686 } 1705 }
1687 1706
@@ -1692,7 +1711,8 @@ fn $0fun_name() -> i32 {
1692 r#" 1711 r#"
1693fn foo() { 1712fn foo() {
1694 $0while true { }$0 1713 $0while true { }$0
1695}"#, 1714}
1715"#,
1696 r#" 1716 r#"
1697fn foo() { 1717fn foo() {
1698 fun_name(); 1718 fun_name();
@@ -1700,7 +1720,8 @@ fn foo() {
1700 1720
1701fn $0fun_name() { 1721fn $0fun_name() {
1702 while true { } 1722 while true { }
1703}"#, 1723}
1724"#,
1704 ); 1725 );
1705 } 1726 }
1706 1727
@@ -1711,7 +1732,8 @@ fn $0fun_name() {
1711 r#" 1732 r#"
1712fn foo() { 1733fn foo() {
1713 $0for v in &[0, 1] { }$0 1734 $0for v in &[0, 1] { }$0
1714}"#, 1735}
1736"#,
1715 r#" 1737 r#"
1716fn foo() { 1738fn foo() {
1717 fun_name(); 1739 fun_name();
@@ -1719,7 +1741,8 @@ fn foo() {
1719 1741
1720fn $0fun_name() { 1742fn $0fun_name() {
1721 for v in &[0, 1] { } 1743 for v in &[0, 1] { }
1722}"#, 1744}
1745"#,
1723 ); 1746 );
1724 } 1747 }
1725 1748
@@ -1732,7 +1755,8 @@ fn foo() {
1732 $0loop { 1755 $0loop {
1733 let m = 1; 1756 let m = 1;
1734 }$0 1757 }$0
1735}"#, 1758}
1759"#,
1736 r#" 1760 r#"
1737fn foo() { 1761fn foo() {
1738 fun_name() 1762 fun_name()
@@ -1742,7 +1766,8 @@ fn $0fun_name() -> ! {
1742 loop { 1766 loop {
1743 let m = 1; 1767 let m = 1;
1744 } 1768 }
1745}"#, 1769}
1770"#,
1746 ); 1771 );
1747 } 1772 }
1748 1773
@@ -1756,7 +1781,8 @@ fn foo() {
1756 let m = 1; 1781 let m = 1;
1757 break m; 1782 break m;
1758 }$0; 1783 }$0;
1759}"#, 1784}
1785"#,
1760 r#" 1786 r#"
1761fn foo() { 1787fn foo() {
1762 let v = fun_name(); 1788 let v = fun_name();
@@ -1767,7 +1793,8 @@ fn $0fun_name() -> i32 {
1767 let m = 1; 1793 let m = 1;
1768 break m; 1794 break m;
1769 } 1795 }
1770}"#, 1796}
1797"#,
1771 ); 1798 );
1772 } 1799 }
1773 1800
@@ -1781,7 +1808,8 @@ fn foo() {
1781 Some(x) => x, 1808 Some(x) => x,
1782 None => 0, 1809 None => 0,
1783 }$0; 1810 }$0;
1784}"#, 1811}
1812"#,
1785 r#" 1813 r#"
1786fn foo() { 1814fn foo() {
1787 let v: i32 = fun_name(); 1815 let v: i32 = fun_name();
@@ -1792,7 +1820,8 @@ fn $0fun_name() -> i32 {
1792 Some(x) => x, 1820 Some(x) => x,
1793 None => 0, 1821 None => 0,
1794 } 1822 }
1795}"#, 1823}
1824"#,
1796 ); 1825 );
1797 } 1826 }
1798 1827
@@ -1805,7 +1834,8 @@ fn foo() {
1805 let n = 1; 1834 let n = 1;
1806 let mut v = $0n * n;$0 1835 let mut v = $0n * n;$0
1807 v += 1; 1836 v += 1;
1808}"#, 1837}
1838"#,
1809 r#" 1839 r#"
1810fn foo() { 1840fn foo() {
1811 let n = 1; 1841 let n = 1;
@@ -1816,7 +1846,8 @@ fn foo() {
1816fn $0fun_name(n: i32) -> i32 { 1846fn $0fun_name(n: i32) -> i32 {
1817 let mut v = n * n; 1847 let mut v = n * n;
1818 v 1848 v
1819}"#, 1849}
1850"#,
1820 ); 1851 );
1821 } 1852 }
1822 1853
@@ -1832,7 +1863,8 @@ fn foo() {
1832 let mut w = 3;$0 1863 let mut w = 3;$0
1833 v += 1; 1864 v += 1;
1834 w += 1; 1865 w += 1;
1835}"#, 1866}
1867"#,
1836 r#" 1868 r#"
1837fn foo() { 1869fn foo() {
1838 let m = 2; 1870 let m = 2;
@@ -1846,7 +1878,8 @@ fn $0fun_name(m: i32, n: i32) -> (i32, i32) {
1846 let mut v = m * n; 1878 let mut v = m * n;
1847 let mut w = 3; 1879 let mut w = 3;
1848 (v, w) 1880 (v, w)
1849}"#, 1881}
1882"#,
1850 ); 1883 );
1851 } 1884 }
1852 1885
@@ -1854,12 +1887,13 @@ fn $0fun_name(m: i32, n: i32) -> (i32, i32) {
1854 fn argument_form_expr() { 1887 fn argument_form_expr() {
1855 check_assist( 1888 check_assist(
1856 extract_function, 1889 extract_function,
1857 r" 1890 r#"
1858fn foo() -> u32 { 1891fn foo() -> u32 {
1859 let n = 2; 1892 let n = 2;
1860 $0n+2$0 1893 $0n+2$0
1861}", 1894}
1862 r" 1895"#,
1896 r#"
1863fn foo() -> u32 { 1897fn foo() -> u32 {
1864 let n = 2; 1898 let n = 2;
1865 fun_name(n) 1899 fun_name(n)
@@ -1867,7 +1901,8 @@ fn foo() -> u32 {
1867 1901
1868fn $0fun_name(n: u32) -> u32 { 1902fn $0fun_name(n: u32) -> u32 {
1869 n+2 1903 n+2
1870}", 1904}
1905"#,
1871 ) 1906 )
1872 } 1907 }
1873 1908
@@ -1875,12 +1910,13 @@ fn $0fun_name(n: u32) -> u32 {
1875 fn argument_used_twice_form_expr() { 1910 fn argument_used_twice_form_expr() {
1876 check_assist( 1911 check_assist(
1877 extract_function, 1912 extract_function,
1878 r" 1913 r#"
1879fn foo() -> u32 { 1914fn foo() -> u32 {
1880 let n = 2; 1915 let n = 2;
1881 $0n+n$0 1916 $0n+n$0
1882}", 1917}
1883 r" 1918"#,
1919 r#"
1884fn foo() -> u32 { 1920fn foo() -> u32 {
1885 let n = 2; 1921 let n = 2;
1886 fun_name(n) 1922 fun_name(n)
@@ -1888,7 +1924,8 @@ fn foo() -> u32 {
1888 1924
1889fn $0fun_name(n: u32) -> u32 { 1925fn $0fun_name(n: u32) -> u32 {
1890 n+n 1926 n+n
1891}", 1927}
1928"#,
1892 ) 1929 )
1893 } 1930 }
1894 1931
@@ -1896,13 +1933,14 @@ fn $0fun_name(n: u32) -> u32 {
1896 fn two_arguments_form_expr() { 1933 fn two_arguments_form_expr() {
1897 check_assist( 1934 check_assist(
1898 extract_function, 1935 extract_function,
1899 r" 1936 r#"
1900fn foo() -> u32 { 1937fn foo() -> u32 {
1901 let n = 2; 1938 let n = 2;
1902 let m = 3; 1939 let m = 3;
1903 $0n+n*m$0 1940 $0n+n*m$0
1904}", 1941}
1905 r" 1942"#,
1943 r#"
1906fn foo() -> u32 { 1944fn foo() -> u32 {
1907 let n = 2; 1945 let n = 2;
1908 let m = 3; 1946 let m = 3;
@@ -1911,7 +1949,8 @@ fn foo() -> u32 {
1911 1949
1912fn $0fun_name(n: u32, m: u32) -> u32 { 1950fn $0fun_name(n: u32, m: u32) -> u32 {
1913 n+n*m 1951 n+n*m
1914}", 1952}
1953"#,
1915 ) 1954 )
1916 } 1955 }
1917 1956
@@ -1919,13 +1958,14 @@ fn $0fun_name(n: u32, m: u32) -> u32 {
1919 fn argument_and_locals() { 1958 fn argument_and_locals() {
1920 check_assist( 1959 check_assist(
1921 extract_function, 1960 extract_function,
1922 r" 1961 r#"
1923fn foo() -> u32 { 1962fn foo() -> u32 {
1924 let n = 2; 1963 let n = 2;
1925 $0let m = 1; 1964 $0let m = 1;
1926 n + m$0 1965 n + m$0
1927}", 1966}
1928 r" 1967"#,
1968 r#"
1929fn foo() -> u32 { 1969fn foo() -> u32 {
1930 let n = 2; 1970 let n = 2;
1931 fun_name(n) 1971 fun_name(n)
@@ -1934,7 +1974,8 @@ fn foo() -> u32 {
1934fn $0fun_name(n: u32) -> u32 { 1974fn $0fun_name(n: u32) -> u32 {
1935 let m = 1; 1975 let m = 1;
1936 n + m 1976 n + m
1937}", 1977}
1978"#,
1938 ) 1979 )
1939 } 1980 }
1940 1981
@@ -1948,18 +1989,20 @@ fn $0fun_name(n: u32) -> u32 {
1948 fn part_of_expr_stmt() { 1989 fn part_of_expr_stmt() {
1949 check_assist( 1990 check_assist(
1950 extract_function, 1991 extract_function,
1951 " 1992 r#"
1952fn foo() { 1993fn foo() {
1953 $01$0 + 1; 1994 $01$0 + 1;
1954}", 1995}
1955 " 1996"#,
1997 r#"
1956fn foo() { 1998fn foo() {
1957 fun_name() + 1; 1999 fun_name() + 1;
1958} 2000}
1959 2001
1960fn $0fun_name() -> i32 { 2002fn $0fun_name() -> i32 {
1961 1 2003 1
1962}", 2004}
2005"#,
1963 ); 2006 );
1964 } 2007 }
1965 2008
@@ -1970,7 +2013,8 @@ fn $0fun_name() -> i32 {
1970 r#" 2013 r#"
1971fn foo() { 2014fn foo() {
1972 $0bar(1 + 1)$0 2015 $0bar(1 + 1)$0
1973}"#, 2016}
2017"#,
1974 r#" 2018 r#"
1975fn foo() { 2019fn foo() {
1976 fun_name(); 2020 fun_name();
@@ -1978,7 +2022,8 @@ fn foo() {
1978 2022
1979fn $0fun_name() { 2023fn $0fun_name() {
1980 bar(1 + 1) 2024 bar(1 + 1)
1981}"#, 2025}
2026"#,
1982 ) 2027 )
1983 } 2028 }
1984 2029
@@ -1986,15 +2031,16 @@ fn $0fun_name() {
1986 fn extract_from_nested() { 2031 fn extract_from_nested() {
1987 check_assist( 2032 check_assist(
1988 extract_function, 2033 extract_function,
1989 r" 2034 r#"
1990fn main() { 2035fn main() {
1991 let x = true; 2036 let x = true;
1992 let tuple = match x { 2037 let tuple = match x {
1993 true => ($02 + 2$0, true) 2038 true => ($02 + 2$0, true)
1994 _ => (0, false) 2039 _ => (0, false)
1995 }; 2040 };
1996}", 2041}
1997 r" 2042"#,
2043 r#"
1998fn main() { 2044fn main() {
1999 let x = true; 2045 let x = true;
2000 let tuple = match x { 2046 let tuple = match x {
@@ -2005,7 +2051,8 @@ fn main() {
2005 2051
2006fn $0fun_name() -> i32 { 2052fn $0fun_name() -> i32 {
2007 2 + 2 2053 2 + 2
2008}", 2054}
2055"#,
2009 ); 2056 );
2010 } 2057 }
2011 2058
@@ -2013,18 +2060,20 @@ fn $0fun_name() -> i32 {
2013 fn param_from_closure() { 2060 fn param_from_closure() {
2014 check_assist( 2061 check_assist(
2015 extract_function, 2062 extract_function,
2016 r" 2063 r#"
2017fn main() { 2064fn main() {
2018 let lambda = |x: u32| $0x * 2$0; 2065 let lambda = |x: u32| $0x * 2$0;
2019}", 2066}
2020 r" 2067"#,
2068 r#"
2021fn main() { 2069fn main() {
2022 let lambda = |x: u32| fun_name(x); 2070 let lambda = |x: u32| fun_name(x);
2023} 2071}
2024 2072
2025fn $0fun_name(x: u32) -> u32 { 2073fn $0fun_name(x: u32) -> u32 {
2026 x * 2 2074 x * 2
2027}", 2075}
2076"#,
2028 ); 2077 );
2029 } 2078 }
2030 2079
@@ -2032,18 +2081,20 @@ fn $0fun_name(x: u32) -> u32 {
2032 fn extract_return_stmt() { 2081 fn extract_return_stmt() {
2033 check_assist( 2082 check_assist(
2034 extract_function, 2083 extract_function,
2035 r" 2084 r#"
2036fn foo() -> u32 { 2085fn foo() -> u32 {
2037 $0return 2 + 2$0; 2086 $0return 2 + 2$0;
2038}", 2087}
2039 r" 2088"#,
2089 r#"
2040fn foo() -> u32 { 2090fn foo() -> u32 {
2041 return fun_name(); 2091 return fun_name();
2042} 2092}
2043 2093
2044fn $0fun_name() -> u32 { 2094fn $0fun_name() -> u32 {
2045 2 + 2 2095 2 + 2
2046}", 2096}
2097"#,
2047 ); 2098 );
2048 } 2099 }
2049 2100
@@ -2051,13 +2102,14 @@ fn $0fun_name() -> u32 {
2051 fn does_not_add_extra_whitespace() { 2102 fn does_not_add_extra_whitespace() {
2052 check_assist( 2103 check_assist(
2053 extract_function, 2104 extract_function,
2054 r" 2105 r#"
2055fn foo() -> u32 { 2106fn foo() -> u32 {
2056 2107
2057 2108
2058 $0return 2 + 2$0; 2109 $0return 2 + 2$0;
2059}", 2110}
2060 r" 2111"#,
2112 r#"
2061fn foo() -> u32 { 2113fn foo() -> u32 {
2062 2114
2063 2115
@@ -2066,7 +2118,8 @@ fn foo() -> u32 {
2066 2118
2067fn $0fun_name() -> u32 { 2119fn $0fun_name() -> u32 {
2068 2 + 2 2120 2 + 2
2069}", 2121}
2122"#,
2070 ); 2123 );
2071 } 2124 }
2072 2125
@@ -2074,13 +2127,14 @@ fn $0fun_name() -> u32 {
2074 fn break_stmt() { 2127 fn break_stmt() {
2075 check_assist( 2128 check_assist(
2076 extract_function, 2129 extract_function,
2077 r" 2130 r#"
2078fn main() { 2131fn main() {
2079 let result = loop { 2132 let result = loop {
2080 $0break 2 + 2$0; 2133 $0break 2 + 2$0;
2081 }; 2134 };
2082}", 2135}
2083 r" 2136"#,
2137 r#"
2084fn main() { 2138fn main() {
2085 let result = loop { 2139 let result = loop {
2086 break fun_name(); 2140 break fun_name();
@@ -2089,7 +2143,8 @@ fn main() {
2089 2143
2090fn $0fun_name() -> i32 { 2144fn $0fun_name() -> i32 {
2091 2 + 2 2145 2 + 2
2092}", 2146}
2147"#,
2093 ); 2148 );
2094 } 2149 }
2095 2150
@@ -2097,18 +2152,20 @@ fn $0fun_name() -> i32 {
2097 fn extract_cast() { 2152 fn extract_cast() {
2098 check_assist( 2153 check_assist(
2099 extract_function, 2154 extract_function,
2100 r" 2155 r#"
2101fn main() { 2156fn main() {
2102 let v = $00f32 as u32$0; 2157 let v = $00f32 as u32$0;
2103}", 2158}
2104 r" 2159"#,
2160 r#"
2105fn main() { 2161fn main() {
2106 let v = fun_name(); 2162 let v = fun_name();
2107} 2163}
2108 2164
2109fn $0fun_name() -> u32 { 2165fn $0fun_name() -> u32 {
2110 0f32 as u32 2166 0f32 as u32
2111}", 2167}
2168"#,
2112 ); 2169 );
2113 } 2170 }
2114 2171
@@ -2121,15 +2178,16 @@ fn $0fun_name() -> u32 {
2121 fn method_to_freestanding() { 2178 fn method_to_freestanding() {
2122 check_assist( 2179 check_assist(
2123 extract_function, 2180 extract_function,
2124 r" 2181 r#"
2125struct S; 2182struct S;
2126 2183
2127impl S { 2184impl S {
2128 fn foo(&self) -> i32 { 2185 fn foo(&self) -> i32 {
2129 $01+1$0 2186 $01+1$0
2130 } 2187 }
2131}", 2188}
2132 r" 2189"#,
2190 r#"
2133struct S; 2191struct S;
2134 2192
2135impl S { 2193impl S {
@@ -2140,7 +2198,8 @@ impl S {
2140 2198
2141fn $0fun_name() -> i32 { 2199fn $0fun_name() -> i32 {
2142 1+1 2200 1+1
2143}", 2201}
2202"#,
2144 ); 2203 );
2145 } 2204 }
2146 2205
@@ -2148,15 +2207,16 @@ fn $0fun_name() -> i32 {
2148 fn method_with_reference() { 2207 fn method_with_reference() {
2149 check_assist( 2208 check_assist(
2150 extract_function, 2209 extract_function,
2151 r" 2210 r#"
2152struct S { f: i32 }; 2211struct S { f: i32 };
2153 2212
2154impl S { 2213impl S {
2155 fn foo(&self) -> i32 { 2214 fn foo(&self) -> i32 {
2156 $01+self.f$0 2215 $01+self.f$0
2157 } 2216 }
2158}", 2217}
2159 r" 2218"#,
2219 r#"
2160struct S { f: i32 }; 2220struct S { f: i32 };
2161 2221
2162impl S { 2222impl S {
@@ -2167,7 +2227,8 @@ impl S {
2167 fn $0fun_name(&self) -> i32 { 2227 fn $0fun_name(&self) -> i32 {
2168 1+self.f 2228 1+self.f
2169 } 2229 }
2170}", 2230}
2231"#,
2171 ); 2232 );
2172 } 2233 }
2173 2234
@@ -2175,15 +2236,16 @@ impl S {
2175 fn method_with_mut() { 2236 fn method_with_mut() {
2176 check_assist( 2237 check_assist(
2177 extract_function, 2238 extract_function,
2178 r" 2239 r#"
2179struct S { f: i32 }; 2240struct S { f: i32 };
2180 2241
2181impl S { 2242impl S {
2182 fn foo(&mut self) { 2243 fn foo(&mut self) {
2183 $0self.f += 1;$0 2244 $0self.f += 1;$0
2184 } 2245 }
2185}", 2246}
2186 r" 2247"#,
2248 r#"
2187struct S { f: i32 }; 2249struct S { f: i32 };
2188 2250
2189impl S { 2251impl S {
@@ -2194,7 +2256,8 @@ impl S {
2194 fn $0fun_name(&mut self) { 2256 fn $0fun_name(&mut self) {
2195 self.f += 1; 2257 self.f += 1;
2196 } 2258 }
2197}", 2259}
2260"#,
2198 ); 2261 );
2199 } 2262 }
2200 2263
@@ -2202,13 +2265,14 @@ impl S {
2202 fn variable_defined_inside_and_used_after_no_ret() { 2265 fn variable_defined_inside_and_used_after_no_ret() {
2203 check_assist( 2266 check_assist(
2204 extract_function, 2267 extract_function,
2205 r" 2268 r#"
2206fn foo() { 2269fn foo() {
2207 let n = 1; 2270 let n = 1;
2208 $0let k = n * n;$0 2271 $0let k = n * n;$0
2209 let m = k + 1; 2272 let m = k + 1;
2210}", 2273}
2211 r" 2274"#,
2275 r#"
2212fn foo() { 2276fn foo() {
2213 let n = 1; 2277 let n = 1;
2214 let k = fun_name(n); 2278 let k = fun_name(n);
@@ -2218,7 +2282,8 @@ fn foo() {
2218fn $0fun_name(n: i32) -> i32 { 2282fn $0fun_name(n: i32) -> i32 {
2219 let k = n * n; 2283 let k = n * n;
2220 k 2284 k
2221}", 2285}
2286"#,
2222 ); 2287 );
2223 } 2288 }
2224 2289
@@ -2226,13 +2291,14 @@ fn $0fun_name(n: i32) -> i32 {
2226 fn variable_defined_inside_and_used_after_mutably_no_ret() { 2291 fn variable_defined_inside_and_used_after_mutably_no_ret() {
2227 check_assist( 2292 check_assist(
2228 extract_function, 2293 extract_function,
2229 r" 2294 r#"
2230fn foo() { 2295fn foo() {
2231 let n = 1; 2296 let n = 1;
2232 $0let mut k = n * n;$0 2297 $0let mut k = n * n;$0
2233 k += 1; 2298 k += 1;
2234}", 2299}
2235 r" 2300"#,
2301 r#"
2236fn foo() { 2302fn foo() {
2237 let n = 1; 2303 let n = 1;
2238 let mut k = fun_name(n); 2304 let mut k = fun_name(n);
@@ -2242,7 +2308,8 @@ fn foo() {
2242fn $0fun_name(n: i32) -> i32 { 2308fn $0fun_name(n: i32) -> i32 {
2243 let mut k = n * n; 2309 let mut k = n * n;
2244 k 2310 k
2245}", 2311}
2312"#,
2246 ); 2313 );
2247 } 2314 }
2248 2315
@@ -2250,14 +2317,15 @@ fn $0fun_name(n: i32) -> i32 {
2250 fn two_variables_defined_inside_and_used_after_no_ret() { 2317 fn two_variables_defined_inside_and_used_after_no_ret() {
2251 check_assist( 2318 check_assist(
2252 extract_function, 2319 extract_function,
2253 r" 2320 r#"
2254fn foo() { 2321fn foo() {
2255 let n = 1; 2322 let n = 1;
2256 $0let k = n * n; 2323 $0let k = n * n;
2257 let m = k + 2;$0 2324 let m = k + 2;$0
2258 let h = k + m; 2325 let h = k + m;
2259}", 2326}
2260 r" 2327"#,
2328 r#"
2261fn foo() { 2329fn foo() {
2262 let n = 1; 2330 let n = 1;
2263 let (k, m) = fun_name(n); 2331 let (k, m) = fun_name(n);
@@ -2268,7 +2336,8 @@ fn $0fun_name(n: i32) -> (i32, i32) {
2268 let k = n * n; 2336 let k = n * n;
2269 let m = k + 2; 2337 let m = k + 2;
2270 (k, m) 2338 (k, m)
2271}", 2339}
2340"#,
2272 ); 2341 );
2273 } 2342 }
2274 2343
@@ -2276,7 +2345,7 @@ fn $0fun_name(n: i32) -> (i32, i32) {
2276 fn multi_variables_defined_inside_and_used_after_mutably_no_ret() { 2345 fn multi_variables_defined_inside_and_used_after_mutably_no_ret() {
2277 check_assist( 2346 check_assist(
2278 extract_function, 2347 extract_function,
2279 r" 2348 r#"
2280fn foo() { 2349fn foo() {
2281 let n = 1; 2350 let n = 1;
2282 $0let mut k = n * n; 2351 $0let mut k = n * n;
@@ -2285,8 +2354,9 @@ fn foo() {
2285 o += 1;$0 2354 o += 1;$0
2286 k += o; 2355 k += o;
2287 m = 1; 2356 m = 1;
2288}", 2357}
2289 r" 2358"#,
2359 r#"
2290fn foo() { 2360fn foo() {
2291 let n = 1; 2361 let n = 1;
2292 let (mut k, mut m, o) = fun_name(n); 2362 let (mut k, mut m, o) = fun_name(n);
@@ -2300,7 +2370,8 @@ fn $0fun_name(n: i32) -> (i32, i32, i32) {
2300 let mut o = m + 3; 2370 let mut o = m + 3;
2301 o += 1; 2371 o += 1;
2302 (k, m, o) 2372 (k, m, o)
2303}", 2373}
2374"#,
2304 ); 2375 );
2305 } 2376 }
2306 2377
@@ -2308,13 +2379,14 @@ fn $0fun_name(n: i32) -> (i32, i32, i32) {
2308 fn nontrivial_patterns_define_variables() { 2379 fn nontrivial_patterns_define_variables() {
2309 check_assist( 2380 check_assist(
2310 extract_function, 2381 extract_function,
2311 r" 2382 r#"
2312struct Counter(i32); 2383struct Counter(i32);
2313fn foo() { 2384fn foo() {
2314 $0let Counter(n) = Counter(0);$0 2385 $0let Counter(n) = Counter(0);$0
2315 let m = n; 2386 let m = n;
2316}", 2387}
2317 r" 2388"#,
2389 r#"
2318struct Counter(i32); 2390struct Counter(i32);
2319fn foo() { 2391fn foo() {
2320 let n = fun_name(); 2392 let n = fun_name();
@@ -2324,7 +2396,8 @@ fn foo() {
2324fn $0fun_name() -> i32 { 2396fn $0fun_name() -> i32 {
2325 let Counter(n) = Counter(0); 2397 let Counter(n) = Counter(0);
2326 n 2398 n
2327}", 2399}
2400"#,
2328 ); 2401 );
2329 } 2402 }
2330 2403
@@ -2332,13 +2405,14 @@ fn $0fun_name() -> i32 {
2332 fn struct_with_two_fields_pattern_define_variables() { 2405 fn struct_with_two_fields_pattern_define_variables() {
2333 check_assist( 2406 check_assist(
2334 extract_function, 2407 extract_function,
2335 r" 2408 r#"
2336struct Counter { n: i32, m: i32 }; 2409struct Counter { n: i32, m: i32 };
2337fn foo() { 2410fn foo() {
2338 $0let Counter { n, m: k } = Counter { n: 1, m: 2 };$0 2411 $0let Counter { n, m: k } = Counter { n: 1, m: 2 };$0
2339 let h = n + k; 2412 let h = n + k;
2340}", 2413}
2341 r" 2414"#,
2415 r#"
2342struct Counter { n: i32, m: i32 }; 2416struct Counter { n: i32, m: i32 };
2343fn foo() { 2417fn foo() {
2344 let (n, k) = fun_name(); 2418 let (n, k) = fun_name();
@@ -2348,7 +2422,8 @@ fn foo() {
2348fn $0fun_name() -> (i32, i32) { 2422fn $0fun_name() -> (i32, i32) {
2349 let Counter { n, m: k } = Counter { n: 1, m: 2 }; 2423 let Counter { n, m: k } = Counter { n: 1, m: 2 };
2350 (n, k) 2424 (n, k)
2351}", 2425}
2426"#,
2352 ); 2427 );
2353 } 2428 }
2354 2429
@@ -2356,13 +2431,14 @@ fn $0fun_name() -> (i32, i32) {
2356 fn mut_var_from_outer_scope() { 2431 fn mut_var_from_outer_scope() {
2357 check_assist( 2432 check_assist(
2358 extract_function, 2433 extract_function,
2359 r" 2434 r#"
2360fn foo() { 2435fn foo() {
2361 let mut n = 1; 2436 let mut n = 1;
2362 $0n += 1;$0 2437 $0n += 1;$0
2363 let m = n + 1; 2438 let m = n + 1;
2364}", 2439}
2365 r" 2440"#,
2441 r#"
2366fn foo() { 2442fn foo() {
2367 let mut n = 1; 2443 let mut n = 1;
2368 fun_name(&mut n); 2444 fun_name(&mut n);
@@ -2371,7 +2447,8 @@ fn foo() {
2371 2447
2372fn $0fun_name(n: &mut i32) { 2448fn $0fun_name(n: &mut i32) {
2373 *n += 1; 2449 *n += 1;
2374}", 2450}
2451"#,
2375 ); 2452 );
2376 } 2453 }
2377 2454
@@ -2379,14 +2456,15 @@ fn $0fun_name(n: &mut i32) {
2379 fn mut_field_from_outer_scope() { 2456 fn mut_field_from_outer_scope() {
2380 check_assist( 2457 check_assist(
2381 extract_function, 2458 extract_function,
2382 r" 2459 r#"
2383struct C { n: i32 } 2460struct C { n: i32 }
2384fn foo() { 2461fn foo() {
2385 let mut c = C { n: 0 }; 2462 let mut c = C { n: 0 };
2386 $0c.n += 1;$0 2463 $0c.n += 1;$0
2387 let m = c.n + 1; 2464 let m = c.n + 1;
2388}", 2465}
2389 r" 2466"#,
2467 r#"
2390struct C { n: i32 } 2468struct C { n: i32 }
2391fn foo() { 2469fn foo() {
2392 let mut c = C { n: 0 }; 2470 let mut c = C { n: 0 };
@@ -2396,7 +2474,8 @@ fn foo() {
2396 2474
2397fn $0fun_name(c: &mut C) { 2475fn $0fun_name(c: &mut C) {
2398 c.n += 1; 2476 c.n += 1;
2399}", 2477}
2478"#,
2400 ); 2479 );
2401 } 2480 }
2402 2481
@@ -2404,7 +2483,7 @@ fn $0fun_name(c: &mut C) {
2404 fn mut_nested_field_from_outer_scope() { 2483 fn mut_nested_field_from_outer_scope() {
2405 check_assist( 2484 check_assist(
2406 extract_function, 2485 extract_function,
2407 r" 2486 r#"
2408struct P { n: i32} 2487struct P { n: i32}
2409struct C { p: P } 2488struct C { p: P }
2410fn foo() { 2489fn foo() {
@@ -2414,8 +2493,9 @@ fn foo() {
2414 $0c.p.n += u.p.n; 2493 $0c.p.n += u.p.n;
2415 let r = &mut v.p.n;$0 2494 let r = &mut v.p.n;$0
2416 let m = c.p.n + v.p.n + u.p.n; 2495 let m = c.p.n + v.p.n + u.p.n;
2417}", 2496}
2418 r" 2497"#,
2498 r#"
2419struct P { n: i32} 2499struct P { n: i32}
2420struct C { p: P } 2500struct C { p: P }
2421fn foo() { 2501fn foo() {
@@ -2429,7 +2509,8 @@ fn foo() {
2429fn $0fun_name(c: &mut C, u: &C, v: &mut C) { 2509fn $0fun_name(c: &mut C, u: &C, v: &mut C) {
2430 c.p.n += u.p.n; 2510 c.p.n += u.p.n;
2431 let r = &mut v.p.n; 2511 let r = &mut v.p.n;
2432}", 2512}
2513"#,
2433 ); 2514 );
2434 } 2515 }
2435 2516
@@ -2437,7 +2518,7 @@ fn $0fun_name(c: &mut C, u: &C, v: &mut C) {
2437 fn mut_param_many_usages_stmt() { 2518 fn mut_param_many_usages_stmt() {
2438 check_assist( 2519 check_assist(
2439 extract_function, 2520 extract_function,
2440 r" 2521 r#"
2441fn bar(k: i32) {} 2522fn bar(k: i32) {}
2442trait I: Copy { 2523trait I: Copy {
2443 fn succ(&self) -> Self; 2524 fn succ(&self) -> Self;
@@ -2458,8 +2539,9 @@ fn foo() {
2458 *v = v.succ(); 2539 *v = v.succ();
2459 n.succ();$0 2540 n.succ();$0
2460 let m = n + 1; 2541 let m = n + 1;
2461}", 2542}
2462 r" 2543"#,
2544 r#"
2463fn bar(k: i32) {} 2545fn bar(k: i32) {}
2464trait I: Copy { 2546trait I: Copy {
2465 fn succ(&self) -> Self; 2547 fn succ(&self) -> Self;
@@ -2484,7 +2566,8 @@ fn $0fun_name(n: &mut i32) {
2484 let v = n; 2566 let v = n;
2485 *v = v.succ(); 2567 *v = v.succ();
2486 n.succ(); 2568 n.succ();
2487}", 2569}
2570"#,
2488 ); 2571 );
2489 } 2572 }
2490 2573
@@ -2492,7 +2575,7 @@ fn $0fun_name(n: &mut i32) {
2492 fn mut_param_many_usages_expr() { 2575 fn mut_param_many_usages_expr() {
2493 check_assist( 2576 check_assist(
2494 extract_function, 2577 extract_function,
2495 r" 2578 r#"
2496fn bar(k: i32) {} 2579fn bar(k: i32) {}
2497trait I: Copy { 2580trait I: Copy {
2498 fn succ(&self) -> Self; 2581 fn succ(&self) -> Self;
@@ -2515,8 +2598,9 @@ fn foo() {
2515 n.succ(); 2598 n.succ();
2516 }$0 2599 }$0
2517 let m = n + 1; 2600 let m = n + 1;
2518}", 2601}
2519 r" 2602"#,
2603 r#"
2520fn bar(k: i32) {} 2604fn bar(k: i32) {}
2521trait I: Copy { 2605trait I: Copy {
2522 fn succ(&self) -> Self; 2606 fn succ(&self) -> Self;
@@ -2541,7 +2625,8 @@ fn $0fun_name(n: &mut i32) {
2541 let v = n; 2625 let v = n;
2542 *v = v.succ(); 2626 *v = v.succ();
2543 n.succ(); 2627 n.succ();
2544}", 2628}
2629"#,
2545 ); 2630 );
2546 } 2631 }
2547 2632
@@ -2549,11 +2634,12 @@ fn $0fun_name(n: &mut i32) {
2549 fn mut_param_by_value() { 2634 fn mut_param_by_value() {
2550 check_assist( 2635 check_assist(
2551 extract_function, 2636 extract_function,
2552 r" 2637 r#"
2553fn foo() { 2638fn foo() {
2554 let mut n = 1; 2639 let mut n = 1;
2555 $0n += 1;$0 2640 $0n += 1;$0
2556}", 2641}
2642"#,
2557 r" 2643 r"
2558fn foo() { 2644fn foo() {
2559 let mut n = 1; 2645 let mut n = 1;
@@ -2562,7 +2648,8 @@ fn foo() {
2562 2648
2563fn $0fun_name(mut n: i32) { 2649fn $0fun_name(mut n: i32) {
2564 n += 1; 2650 n += 1;
2565}", 2651}
2652",
2566 ); 2653 );
2567 } 2654 }
2568 2655
@@ -2570,14 +2657,15 @@ fn $0fun_name(mut n: i32) {
2570 fn mut_param_because_of_mut_ref() { 2657 fn mut_param_because_of_mut_ref() {
2571 check_assist( 2658 check_assist(
2572 extract_function, 2659 extract_function,
2573 r" 2660 r#"
2574fn foo() { 2661fn foo() {
2575 let mut n = 1; 2662 let mut n = 1;
2576 $0let v = &mut n; 2663 $0let v = &mut n;
2577 *v += 1;$0 2664 *v += 1;$0
2578 let k = n; 2665 let k = n;
2579}", 2666}
2580 r" 2667"#,
2668 r#"
2581fn foo() { 2669fn foo() {
2582 let mut n = 1; 2670 let mut n = 1;
2583 fun_name(&mut n); 2671 fun_name(&mut n);
@@ -2587,7 +2675,8 @@ fn foo() {
2587fn $0fun_name(n: &mut i32) { 2675fn $0fun_name(n: &mut i32) {
2588 let v = n; 2676 let v = n;
2589 *v += 1; 2677 *v += 1;
2590}", 2678}
2679"#,
2591 ); 2680 );
2592 } 2681 }
2593 2682
@@ -2600,8 +2689,9 @@ fn foo() {
2600 let mut n = 1; 2689 let mut n = 1;
2601 $0let v = &mut n; 2690 $0let v = &mut n;
2602 *v += 1;$0 2691 *v += 1;$0
2603}", 2692}
2604 r" 2693",
2694 r#"
2605fn foo() { 2695fn foo() {
2606 let mut n = 1; 2696 let mut n = 1;
2607 fun_name(n); 2697 fun_name(n);
@@ -2610,7 +2700,8 @@ fn foo() {
2610fn $0fun_name(mut n: i32) { 2700fn $0fun_name(mut n: i32) {
2611 let v = &mut n; 2701 let v = &mut n;
2612 *v += 1; 2702 *v += 1;
2613}", 2703}
2704"#,
2614 ); 2705 );
2615 } 2706 }
2616 2707
@@ -2618,7 +2709,7 @@ fn $0fun_name(mut n: i32) {
2618 fn mut_method_call() { 2709 fn mut_method_call() {
2619 check_assist( 2710 check_assist(
2620 extract_function, 2711 extract_function,
2621 r" 2712 r#"
2622trait I { 2713trait I {
2623 fn inc(&mut self); 2714 fn inc(&mut self);
2624} 2715}
@@ -2628,8 +2719,9 @@ impl I for i32 {
2628fn foo() { 2719fn foo() {
2629 let mut n = 1; 2720 let mut n = 1;
2630 $0n.inc();$0 2721 $0n.inc();$0
2631}", 2722}
2632 r" 2723"#,
2724 r#"
2633trait I { 2725trait I {
2634 fn inc(&mut self); 2726 fn inc(&mut self);
2635} 2727}
@@ -2643,7 +2735,8 @@ fn foo() {
2643 2735
2644fn $0fun_name(mut n: i32) { 2736fn $0fun_name(mut n: i32) {
2645 n.inc(); 2737 n.inc();
2646}", 2738}
2739"#,
2647 ); 2740 );
2648 } 2741 }
2649 2742
@@ -2651,7 +2744,7 @@ fn $0fun_name(mut n: i32) {
2651 fn shared_method_call() { 2744 fn shared_method_call() {
2652 check_assist( 2745 check_assist(
2653 extract_function, 2746 extract_function,
2654 r" 2747 r#"
2655trait I { 2748trait I {
2656 fn succ(&self); 2749 fn succ(&self);
2657} 2750}
@@ -2661,7 +2754,8 @@ impl I for i32 {
2661fn foo() { 2754fn foo() {
2662 let mut n = 1; 2755 let mut n = 1;
2663 $0n.succ();$0 2756 $0n.succ();$0
2664}", 2757}
2758"#,
2665 r" 2759 r"
2666trait I { 2760trait I {
2667 fn succ(&self); 2761 fn succ(&self);
@@ -2676,7 +2770,8 @@ fn foo() {
2676 2770
2677fn $0fun_name(n: i32) { 2771fn $0fun_name(n: i32) {
2678 n.succ(); 2772 n.succ();
2679}", 2773}
2774",
2680 ); 2775 );
2681 } 2776 }
2682 2777
@@ -2684,7 +2779,7 @@ fn $0fun_name(n: i32) {
2684 fn mut_method_call_with_other_receiver() { 2779 fn mut_method_call_with_other_receiver() {
2685 check_assist( 2780 check_assist(
2686 extract_function, 2781 extract_function,
2687 r" 2782 r#"
2688trait I { 2783trait I {
2689 fn inc(&mut self, n: i32); 2784 fn inc(&mut self, n: i32);
2690} 2785}
@@ -2695,7 +2790,8 @@ fn foo() {
2695 let mut n = 1; 2790 let mut n = 1;
2696 $0let mut m = 2; 2791 $0let mut m = 2;
2697 m.inc(n);$0 2792 m.inc(n);$0
2698}", 2793}
2794"#,
2699 r" 2795 r"
2700trait I { 2796trait I {
2701 fn inc(&mut self, n: i32); 2797 fn inc(&mut self, n: i32);
@@ -2711,7 +2807,8 @@ fn foo() {
2711fn $0fun_name(n: i32) { 2807fn $0fun_name(n: i32) {
2712 let mut m = 2; 2808 let mut m = 2;
2713 m.inc(n); 2809 m.inc(n);
2714}", 2810}
2811",
2715 ); 2812 );
2716 } 2813 }
2717 2814
@@ -2719,12 +2816,13 @@ fn $0fun_name(n: i32) {
2719 fn non_copy_without_usages_after() { 2816 fn non_copy_without_usages_after() {
2720 check_assist( 2817 check_assist(
2721 extract_function, 2818 extract_function,
2722 r" 2819 r#"
2723struct Counter(i32); 2820struct Counter(i32);
2724fn foo() { 2821fn foo() {
2725 let c = Counter(0); 2822 let c = Counter(0);
2726 $0let n = c.0;$0 2823 $0let n = c.0;$0
2727}", 2824}
2825"#,
2728 r" 2826 r"
2729struct Counter(i32); 2827struct Counter(i32);
2730fn foo() { 2828fn foo() {
@@ -2734,7 +2832,8 @@ fn foo() {
2734 2832
2735fn $0fun_name(c: Counter) { 2833fn $0fun_name(c: Counter) {
2736 let n = c.0; 2834 let n = c.0;
2737}", 2835}
2836",
2738 ); 2837 );
2739 } 2838 }
2740 2839
@@ -2748,8 +2847,9 @@ fn foo() {
2748 let c = Counter(0); 2847 let c = Counter(0);
2749 $0let n = c.0;$0 2848 $0let n = c.0;$0
2750 let m = c.0; 2849 let m = c.0;
2751}", 2850}
2752 r" 2851",
2852 r#"
2753struct Counter(i32); 2853struct Counter(i32);
2754fn foo() { 2854fn foo() {
2755 let c = Counter(0); 2855 let c = Counter(0);
@@ -2759,7 +2859,8 @@ fn foo() {
2759 2859
2760fn $0fun_name(c: &Counter) { 2860fn $0fun_name(c: &Counter) {
2761 let n = c.0; 2861 let n = c.0;
2762}", 2862}
2863"#,
2763 ); 2864 );
2764 } 2865 }
2765 2866
@@ -2767,19 +2868,15 @@ fn $0fun_name(c: &Counter) {
2767 fn copy_used_after() { 2868 fn copy_used_after() {
2768 check_assist( 2869 check_assist(
2769 extract_function, 2870 extract_function,
2770 r##" 2871 r#"
2771#[lang = "copy"] 2872//- minicore: copy
2772pub trait Copy {}
2773impl Copy for i32 {}
2774fn foo() { 2873fn foo() {
2775 let n = 0; 2874 let n = 0;
2776 $0let m = n;$0 2875 $0let m = n;$0
2777 let k = n; 2876 let k = n;
2778}"##, 2877}
2779 r##" 2878"#,
2780#[lang = "copy"] 2879 r#"
2781pub trait Copy {}
2782impl Copy for i32 {}
2783fn foo() { 2880fn foo() {
2784 let n = 0; 2881 let n = 0;
2785 fun_name(n); 2882 fun_name(n);
@@ -2788,7 +2885,8 @@ fn foo() {
2788 2885
2789fn $0fun_name(n: i32) { 2886fn $0fun_name(n: i32) {
2790 let m = n; 2887 let m = n;
2791}"##, 2888}
2889"#,
2792 ) 2890 )
2793 } 2891 }
2794 2892
@@ -2796,21 +2894,19 @@ fn $0fun_name(n: i32) {
2796 fn copy_custom_used_after() { 2894 fn copy_custom_used_after() {
2797 check_assist( 2895 check_assist(
2798 extract_function, 2896 extract_function,
2799 r##" 2897 r#"
2800#[lang = "copy"] 2898//- minicore: copy, derive
2801pub trait Copy {} 2899#[derive(Clone, Copy)]
2802struct Counter(i32); 2900struct Counter(i32);
2803impl Copy for Counter {}
2804fn foo() { 2901fn foo() {
2805 let c = Counter(0); 2902 let c = Counter(0);
2806 $0let n = c.0;$0 2903 $0let n = c.0;$0
2807 let m = c.0; 2904 let m = c.0;
2808}"##, 2905}
2809 r##" 2906"#,
2810#[lang = "copy"] 2907 r#"
2811pub trait Copy {} 2908#[derive(Clone, Copy)]
2812struct Counter(i32); 2909struct Counter(i32);
2813impl Copy for Counter {}
2814fn foo() { 2910fn foo() {
2815 let c = Counter(0); 2911 let c = Counter(0);
2816 fun_name(c); 2912 fun_name(c);
@@ -2819,7 +2915,8 @@ fn foo() {
2819 2915
2820fn $0fun_name(c: Counter) { 2916fn $0fun_name(c: Counter) {
2821 let n = c.0; 2917 let n = c.0;
2822}"##, 2918}
2919"#,
2823 ); 2920 );
2824 } 2921 }
2825 2922
@@ -2827,7 +2924,7 @@ fn $0fun_name(c: Counter) {
2827 fn indented_stmts() { 2924 fn indented_stmts() {
2828 check_assist( 2925 check_assist(
2829 extract_function, 2926 extract_function,
2830 r" 2927 r#"
2831fn foo() { 2928fn foo() {
2832 if true { 2929 if true {
2833 loop { 2930 loop {
@@ -2835,8 +2932,9 @@ fn foo() {
2835 let m = 2;$0 2932 let m = 2;$0
2836 } 2933 }
2837 } 2934 }
2838}", 2935}
2839 r" 2936"#,
2937 r#"
2840fn foo() { 2938fn foo() {
2841 if true { 2939 if true {
2842 loop { 2940 loop {
@@ -2848,7 +2946,8 @@ fn foo() {
2848fn $0fun_name() { 2946fn $0fun_name() {
2849 let n = 1; 2947 let n = 1;
2850 let m = 2; 2948 let m = 2;
2851}", 2949}
2950"#,
2852 ); 2951 );
2853 } 2952 }
2854 2953
@@ -2856,7 +2955,7 @@ fn $0fun_name() {
2856 fn indented_stmts_inside_mod() { 2955 fn indented_stmts_inside_mod() {
2857 check_assist( 2956 check_assist(
2858 extract_function, 2957 extract_function,
2859 r" 2958 r#"
2860mod bar { 2959mod bar {
2861 fn foo() { 2960 fn foo() {
2862 if true { 2961 if true {
@@ -2866,8 +2965,9 @@ mod bar {
2866 } 2965 }
2867 } 2966 }
2868 } 2967 }
2869}", 2968}
2870 r" 2969"#,
2970 r#"
2871mod bar { 2971mod bar {
2872 fn foo() { 2972 fn foo() {
2873 if true { 2973 if true {
@@ -2881,7 +2981,8 @@ mod bar {
2881 let n = 1; 2981 let n = 1;
2882 let m = 2; 2982 let m = 2;
2883 } 2983 }
2884}", 2984}
2985"#,
2885 ); 2986 );
2886 } 2987 }
2887 2988
@@ -2889,7 +2990,7 @@ mod bar {
2889 fn break_loop() { 2990 fn break_loop() {
2890 check_assist( 2991 check_assist(
2891 extract_function, 2992 extract_function,
2892 r##" 2993 r#"
2893enum Option<T> { 2994enum Option<T> {
2894 #[lang = "None"] None, 2995 #[lang = "None"] None,
2895 #[lang = "Some"] Some(T), 2996 #[lang = "Some"] Some(T),
@@ -2903,8 +3004,9 @@ fn foo() {
2903 let k = 2;$0 3004 let k = 2;$0
2904 let h = 1 + k; 3005 let h = 1 + k;
2905 } 3006 }
2906}"##, 3007}
2907 r##" 3008"#,
3009 r#"
2908enum Option<T> { 3010enum Option<T> {
2909 #[lang = "None"] None, 3011 #[lang = "None"] None,
2910 #[lang = "Some"] Some(T), 3012 #[lang = "Some"] Some(T),
@@ -2926,7 +3028,8 @@ fn $0fun_name(n: i32) -> Option<i32> {
2926 return None; 3028 return None;
2927 let k = 2; 3029 let k = 2;
2928 Some(k) 3030 Some(k)
2929}"##, 3031}
3032"#,
2930 ); 3033 );
2931 } 3034 }
2932 3035
@@ -2934,31 +3037,17 @@ fn $0fun_name(n: i32) -> Option<i32> {
2934 fn return_to_parent() { 3037 fn return_to_parent() {
2935 check_assist( 3038 check_assist(
2936 extract_function, 3039 extract_function,
2937 r##" 3040 r#"
2938#[lang = "copy"] 3041//- minicore: copy, result
2939pub trait Copy {}
2940impl Copy for i32 {}
2941enum Result<T, E> {
2942 #[lang = "Ok"] Ok(T),
2943 #[lang = "Err"] Err(E),
2944}
2945use Result::*;
2946fn foo() -> i64 { 3042fn foo() -> i64 {
2947 let n = 1; 3043 let n = 1;
2948 $0let m = n + 1; 3044 $0let m = n + 1;
2949 return 1; 3045 return 1;
2950 let k = 2;$0 3046 let k = 2;$0
2951 (n + k) as i64 3047 (n + k) as i64
2952}"##, 3048}
2953 r##" 3049"#,
2954#[lang = "copy"] 3050 r#"
2955pub trait Copy {}
2956impl Copy for i32 {}
2957enum Result<T, E> {
2958 #[lang = "Ok"] Ok(T),
2959 #[lang = "Err"] Err(E),
2960}
2961use Result::*;
2962fn foo() -> i64 { 3051fn foo() -> i64 {
2963 let n = 1; 3052 let n = 1;
2964 let k = match fun_name(n) { 3053 let k = match fun_name(n) {
@@ -2973,7 +3062,8 @@ fn $0fun_name(n: i32) -> Result<i32, i64> {
2973 return Err(1); 3062 return Err(1);
2974 let k = 2; 3063 let k = 2;
2975 Ok(k) 3064 Ok(k)
2976}"##, 3065}
3066"#,
2977 ); 3067 );
2978 } 3068 }
2979 3069
@@ -2982,7 +3072,7 @@ fn $0fun_name(n: i32) -> Result<i32, i64> {
2982 cov_mark::check!(external_control_flow_break_and_continue); 3072 cov_mark::check!(external_control_flow_break_and_continue);
2983 check_assist_not_applicable( 3073 check_assist_not_applicable(
2984 extract_function, 3074 extract_function,
2985 r##" 3075 r#"
2986fn foo() { 3076fn foo() {
2987 loop { 3077 loop {
2988 let n = 1; 3078 let n = 1;
@@ -2993,7 +3083,8 @@ fn foo() {
2993 let k = k + 1;$0 3083 let k = k + 1;$0
2994 let r = n + k; 3084 let r = n + k;
2995 } 3085 }
2996}"##, 3086}
3087"#,
2997 ); 3088 );
2998 } 3089 }
2999 3090
@@ -3002,7 +3093,7 @@ fn foo() {
3002 cov_mark::check!(external_control_flow_return_and_bc); 3093 cov_mark::check!(external_control_flow_return_and_bc);
3003 check_assist_not_applicable( 3094 check_assist_not_applicable(
3004 extract_function, 3095 extract_function,
3005 r##" 3096 r#"
3006fn foo() { 3097fn foo() {
3007 loop { 3098 loop {
3008 let n = 1; 3099 let n = 1;
@@ -3013,7 +3104,8 @@ fn foo() {
3013 let k = k + 1;$0 3104 let k = k + 1;$0
3014 let r = n + k; 3105 let r = n + k;
3015 } 3106 }
3016}"##, 3107}
3108"#,
3017 ); 3109 );
3018 } 3110 }
3019 3111
@@ -3021,7 +3113,7 @@ fn foo() {
3021 fn break_loop_with_if() { 3113 fn break_loop_with_if() {
3022 check_assist( 3114 check_assist(
3023 extract_function, 3115 extract_function,
3024 r##" 3116 r#"
3025fn foo() { 3117fn foo() {
3026 loop { 3118 loop {
3027 let mut n = 1; 3119 let mut n = 1;
@@ -3030,8 +3122,9 @@ fn foo() {
3030 n += m;$0 3122 n += m;$0
3031 let h = 1 + n; 3123 let h = 1 + n;
3032 } 3124 }
3033}"##, 3125}
3034 r##" 3126"#,
3127 r#"
3035fn foo() { 3128fn foo() {
3036 loop { 3129 loop {
3037 let mut n = 1; 3130 let mut n = 1;
@@ -3047,7 +3140,8 @@ fn $0fun_name(n: &mut i32) -> bool {
3047 return true; 3140 return true;
3048 *n += m; 3141 *n += m;
3049 false 3142 false
3050}"##, 3143}
3144"#,
3051 ); 3145 );
3052 } 3146 }
3053 3147
@@ -3055,7 +3149,7 @@ fn $0fun_name(n: &mut i32) -> bool {
3055 fn break_loop_nested() { 3149 fn break_loop_nested() {
3056 check_assist( 3150 check_assist(
3057 extract_function, 3151 extract_function,
3058 r##" 3152 r#"
3059fn foo() { 3153fn foo() {
3060 loop { 3154 loop {
3061 let mut n = 1; 3155 let mut n = 1;
@@ -3065,8 +3159,9 @@ fn foo() {
3065 }$0 3159 }$0
3066 let h = 1; 3160 let h = 1;
3067 } 3161 }
3068}"##, 3162}
3069 r##" 3163"#,
3164 r#"
3070fn foo() { 3165fn foo() {
3071 loop { 3166 loop {
3072 let mut n = 1; 3167 let mut n = 1;
@@ -3083,7 +3178,8 @@ fn $0fun_name(n: i32) -> bool {
3083 return true; 3178 return true;
3084 } 3179 }
3085 false 3180 false
3086}"##, 3181}
3182"#,
3087 ); 3183 );
3088 } 3184 }
3089 3185
@@ -3091,7 +3187,7 @@ fn $0fun_name(n: i32) -> bool {
3091 fn return_from_nested_loop() { 3187 fn return_from_nested_loop() {
3092 check_assist( 3188 check_assist(
3093 extract_function, 3189 extract_function,
3094 r##" 3190 r#"
3095fn foo() { 3191fn foo() {
3096 loop { 3192 loop {
3097 let n = 1; 3193 let n = 1;
@@ -3103,8 +3199,9 @@ fn foo() {
3103 let m = k + 1;$0 3199 let m = k + 1;$0
3104 let h = 1 + m; 3200 let h = 1 + m;
3105 } 3201 }
3106}"##, 3202}
3107 r##" 3203"#,
3204 r#"
3108fn foo() { 3205fn foo() {
3109 loop { 3206 loop {
3110 let n = 1; 3207 let n = 1;
@@ -3123,7 +3220,8 @@ fn $0fun_name() -> Option<i32> {
3123 } 3220 }
3124 let m = k + 1; 3221 let m = k + 1;
3125 Some(m) 3222 Some(m)
3126}"##, 3223}
3224"#,
3127 ); 3225 );
3128 } 3226 }
3129 3227
@@ -3131,7 +3229,7 @@ fn $0fun_name() -> Option<i32> {
3131 fn break_from_nested_loop() { 3229 fn break_from_nested_loop() {
3132 check_assist( 3230 check_assist(
3133 extract_function, 3231 extract_function,
3134 r##" 3232 r#"
3135fn foo() { 3233fn foo() {
3136 loop { 3234 loop {
3137 let n = 1; 3235 let n = 1;
@@ -3142,8 +3240,9 @@ fn foo() {
3142 let m = k + 1;$0 3240 let m = k + 1;$0
3143 let h = 1 + m; 3241 let h = 1 + m;
3144 } 3242 }
3145}"##, 3243}
3146 r##" 3244"#,
3245 r#"
3147fn foo() { 3246fn foo() {
3148 loop { 3247 loop {
3149 let n = 1; 3248 let n = 1;
@@ -3159,7 +3258,8 @@ fn $0fun_name() -> i32 {
3159 } 3258 }
3160 let m = k + 1; 3259 let m = k + 1;
3161 m 3260 m
3162}"##, 3261}
3262"#,
3163 ); 3263 );
3164 } 3264 }
3165 3265
@@ -3167,7 +3267,7 @@ fn $0fun_name() -> i32 {
3167 fn break_from_nested_and_outer_loops() { 3267 fn break_from_nested_and_outer_loops() {
3168 check_assist( 3268 check_assist(
3169 extract_function, 3269 extract_function,
3170 r##" 3270 r#"
3171fn foo() { 3271fn foo() {
3172 loop { 3272 loop {
3173 let n = 1; 3273 let n = 1;
@@ -3181,8 +3281,9 @@ fn foo() {
3181 let m = k + 1;$0 3281 let m = k + 1;$0
3182 let h = 1 + m; 3282 let h = 1 + m;
3183 } 3283 }
3184}"##, 3284}
3185 r##" 3285"#,
3286 r#"
3186fn foo() { 3287fn foo() {
3187 loop { 3288 loop {
3188 let n = 1; 3289 let n = 1;
@@ -3204,7 +3305,8 @@ fn $0fun_name() -> Option<i32> {
3204 } 3305 }
3205 let m = k + 1; 3306 let m = k + 1;
3206 Some(m) 3307 Some(m)
3207}"##, 3308}
3309"#,
3208 ); 3310 );
3209 } 3311 }
3210 3312
@@ -3212,7 +3314,7 @@ fn $0fun_name() -> Option<i32> {
3212 fn return_from_nested_fn() { 3314 fn return_from_nested_fn() {
3213 check_assist( 3315 check_assist(
3214 extract_function, 3316 extract_function,
3215 r##" 3317 r#"
3216fn foo() { 3318fn foo() {
3217 loop { 3319 loop {
3218 let n = 1; 3320 let n = 1;
@@ -3223,8 +3325,9 @@ fn foo() {
3223 let m = k + 1;$0 3325 let m = k + 1;$0
3224 let h = 1 + m; 3326 let h = 1 + m;
3225 } 3327 }
3226}"##, 3328}
3227 r##" 3329"#,
3330 r#"
3228fn foo() { 3331fn foo() {
3229 loop { 3332 loop {
3230 let n = 1; 3333 let n = 1;
@@ -3240,7 +3343,8 @@ fn $0fun_name() -> i32 {
3240 } 3343 }
3241 let m = k + 1; 3344 let m = k + 1;
3242 m 3345 m
3243}"##, 3346}
3347"#,
3244 ); 3348 );
3245 } 3349 }
3246 3350
@@ -3248,7 +3352,7 @@ fn $0fun_name() -> i32 {
3248 fn break_with_value() { 3352 fn break_with_value() {
3249 check_assist( 3353 check_assist(
3250 extract_function, 3354 extract_function,
3251 r##" 3355 r#"
3252fn foo() -> i32 { 3356fn foo() -> i32 {
3253 loop { 3357 loop {
3254 let n = 1; 3358 let n = 1;
@@ -3259,8 +3363,9 @@ fn foo() -> i32 {
3259 let m = k + 1;$0 3363 let m = k + 1;$0
3260 let h = 1; 3364 let h = 1;
3261 } 3365 }
3262}"##, 3366}
3263 r##" 3367"#,
3368 r#"
3264fn foo() -> i32 { 3369fn foo() -> i32 {
3265 loop { 3370 loop {
3266 let n = 1; 3371 let n = 1;
@@ -3278,7 +3383,8 @@ fn $0fun_name() -> Option<i32> {
3278 } 3383 }
3279 let m = k + 1; 3384 let m = k + 1;
3280 None 3385 None
3281}"##, 3386}
3387"#,
3282 ); 3388 );
3283 } 3389 }
3284 3390
@@ -3286,7 +3392,7 @@ fn $0fun_name() -> Option<i32> {
3286 fn break_with_value_and_return() { 3392 fn break_with_value_and_return() {
3287 check_assist( 3393 check_assist(
3288 extract_function, 3394 extract_function,
3289 r##" 3395 r#"
3290fn foo() -> i64 { 3396fn foo() -> i64 {
3291 loop { 3397 loop {
3292 let n = 1; 3398 let n = 1;
@@ -3298,8 +3404,9 @@ fn foo() -> i64 {
3298 let m = k + 1;$0 3404 let m = k + 1;$0
3299 let h = 1 + m; 3405 let h = 1 + m;
3300 } 3406 }
3301}"##, 3407}
3302 r##" 3408"#,
3409 r#"
3303fn foo() -> i64 { 3410fn foo() -> i64 {
3304 loop { 3411 loop {
3305 let n = 1; 3412 let n = 1;
@@ -3318,7 +3425,8 @@ fn $0fun_name() -> Result<i32, i64> {
3318 } 3425 }
3319 let m = k + 1; 3426 let m = k + 1;
3320 Ok(m) 3427 Ok(m)
3321}"##, 3428}
3429"#,
3322 ); 3430 );
3323 } 3431 }
3324 3432
@@ -3326,9 +3434,8 @@ fn $0fun_name() -> Result<i32, i64> {
3326 fn try_option() { 3434 fn try_option() {
3327 check_assist( 3435 check_assist(
3328 extract_function, 3436 extract_function,
3329 r##" 3437 r#"
3330enum Option<T> { None, Some(T), } 3438//- minicore: option
3331use Option::*;
3332fn bar() -> Option<i32> { None } 3439fn bar() -> Option<i32> { None }
3333fn foo() -> Option<()> { 3440fn foo() -> Option<()> {
3334 let n = bar()?; 3441 let n = bar()?;
@@ -3336,10 +3443,9 @@ fn foo() -> Option<()> {
3336 let m = k + 1;$0 3443 let m = k + 1;$0
3337 let h = 1 + m; 3444 let h = 1 + m;
3338 Some(()) 3445 Some(())
3339}"##, 3446}
3340 r##" 3447"#,
3341enum Option<T> { None, Some(T), } 3448 r#"
3342use Option::*;
3343fn bar() -> Option<i32> { None } 3449fn bar() -> Option<i32> { None }
3344fn foo() -> Option<()> { 3450fn foo() -> Option<()> {
3345 let n = bar()?; 3451 let n = bar()?;
@@ -3352,7 +3458,8 @@ fn $0fun_name() -> Option<i32> {
3352 let k = foo()?; 3458 let k = foo()?;
3353 let m = k + 1; 3459 let m = k + 1;
3354 Some(m) 3460 Some(m)
3355}"##, 3461}
3462"#,
3356 ); 3463 );
3357 } 3464 }
3358 3465
@@ -3360,19 +3467,17 @@ fn $0fun_name() -> Option<i32> {
3360 fn try_option_unit() { 3467 fn try_option_unit() {
3361 check_assist( 3468 check_assist(
3362 extract_function, 3469 extract_function,
3363 r##" 3470 r#"
3364enum Option<T> { None, Some(T), } 3471//- minicore: option
3365use Option::*;
3366fn foo() -> Option<()> { 3472fn foo() -> Option<()> {
3367 let n = 1; 3473 let n = 1;
3368 $0let k = foo()?; 3474 $0let k = foo()?;
3369 let m = k + 1;$0 3475 let m = k + 1;$0
3370 let h = 1 + n; 3476 let h = 1 + n;
3371 Some(()) 3477 Some(())
3372}"##, 3478}
3373 r##" 3479"#,
3374enum Option<T> { None, Some(T), } 3480 r#"
3375use Option::*;
3376fn foo() -> Option<()> { 3481fn foo() -> Option<()> {
3377 let n = 1; 3482 let n = 1;
3378 fun_name()?; 3483 fun_name()?;
@@ -3384,7 +3489,8 @@ fn $0fun_name() -> Option<()> {
3384 let k = foo()?; 3489 let k = foo()?;
3385 let m = k + 1; 3490 let m = k + 1;
3386 Some(()) 3491 Some(())
3387}"##, 3492}
3493"#,
3388 ); 3494 );
3389 } 3495 }
3390 3496
@@ -3392,19 +3498,17 @@ fn $0fun_name() -> Option<()> {
3392 fn try_result() { 3498 fn try_result() {
3393 check_assist( 3499 check_assist(
3394 extract_function, 3500 extract_function,
3395 r##" 3501 r#"
3396enum Result<T, E> { Ok(T), Err(E), } 3502//- minicore: result
3397use Result::*;
3398fn foo() -> Result<(), i64> { 3503fn foo() -> Result<(), i64> {
3399 let n = 1; 3504 let n = 1;
3400 $0let k = foo()?; 3505 $0let k = foo()?;
3401 let m = k + 1;$0 3506 let m = k + 1;$0
3402 let h = 1 + m; 3507 let h = 1 + m;
3403 Ok(()) 3508 Ok(())
3404}"##, 3509}
3405 r##" 3510"#,
3406enum Result<T, E> { Ok(T), Err(E), } 3511 r#"
3407use Result::*;
3408fn foo() -> Result<(), i64> { 3512fn foo() -> Result<(), i64> {
3409 let n = 1; 3513 let n = 1;
3410 let m = fun_name()?; 3514 let m = fun_name()?;
@@ -3416,7 +3520,8 @@ fn $0fun_name() -> Result<i32, i64> {
3416 let k = foo()?; 3520 let k = foo()?;
3417 let m = k + 1; 3521 let m = k + 1;
3418 Ok(m) 3522 Ok(m)
3419}"##, 3523}
3524"#,
3420 ); 3525 );
3421 } 3526 }
3422 3527
@@ -3424,9 +3529,8 @@ fn $0fun_name() -> Result<i32, i64> {
3424 fn try_option_with_return() { 3529 fn try_option_with_return() {
3425 check_assist( 3530 check_assist(
3426 extract_function, 3531 extract_function,
3427 r##" 3532 r#"
3428enum Option<T> { None, Some(T) } 3533//- minicore: option
3429use Option::*;
3430fn foo() -> Option<()> { 3534fn foo() -> Option<()> {
3431 let n = 1; 3535 let n = 1;
3432 $0let k = foo()?; 3536 $0let k = foo()?;
@@ -3436,10 +3540,9 @@ fn foo() -> Option<()> {
3436 let m = k + 1;$0 3540 let m = k + 1;$0
3437 let h = 1 + m; 3541 let h = 1 + m;
3438 Some(()) 3542 Some(())
3439}"##, 3543}
3440 r##" 3544"#,
3441enum Option<T> { None, Some(T) } 3545 r#"
3442use Option::*;
3443fn foo() -> Option<()> { 3546fn foo() -> Option<()> {
3444 let n = 1; 3547 let n = 1;
3445 let m = fun_name()?; 3548 let m = fun_name()?;
@@ -3454,7 +3557,8 @@ fn $0fun_name() -> Option<i32> {
3454 } 3557 }
3455 let m = k + 1; 3558 let m = k + 1;
3456 Some(m) 3559 Some(m)
3457}"##, 3560}
3561"#,
3458 ); 3562 );
3459 } 3563 }
3460 3564
@@ -3462,9 +3566,8 @@ fn $0fun_name() -> Option<i32> {
3462 fn try_result_with_return() { 3566 fn try_result_with_return() {
3463 check_assist( 3567 check_assist(
3464 extract_function, 3568 extract_function,
3465 r##" 3569 r#"
3466enum Result<T, E> { Ok(T), Err(E), } 3570//- minicore: result
3467use Result::*;
3468fn foo() -> Result<(), i64> { 3571fn foo() -> Result<(), i64> {
3469 let n = 1; 3572 let n = 1;
3470 $0let k = foo()?; 3573 $0let k = foo()?;
@@ -3474,10 +3577,9 @@ fn foo() -> Result<(), i64> {
3474 let m = k + 1;$0 3577 let m = k + 1;$0
3475 let h = 1 + m; 3578 let h = 1 + m;
3476 Ok(()) 3579 Ok(())
3477}"##, 3580}
3478 r##" 3581"#,
3479enum Result<T, E> { Ok(T), Err(E), } 3582 r#"
3480use Result::*;
3481fn foo() -> Result<(), i64> { 3583fn foo() -> Result<(), i64> {
3482 let n = 1; 3584 let n = 1;
3483 let m = fun_name()?; 3585 let m = fun_name()?;
@@ -3492,7 +3594,8 @@ fn $0fun_name() -> Result<i32, i64> {
3492 } 3594 }
3493 let m = k + 1; 3595 let m = k + 1;
3494 Ok(m) 3596 Ok(m)
3495}"##, 3597}
3598"#,
3496 ); 3599 );
3497 } 3600 }
3498 3601
@@ -3501,9 +3604,8 @@ fn $0fun_name() -> Result<i32, i64> {
3501 cov_mark::check!(external_control_flow_try_and_bc); 3604 cov_mark::check!(external_control_flow_try_and_bc);
3502 check_assist_not_applicable( 3605 check_assist_not_applicable(
3503 extract_function, 3606 extract_function,
3504 r##" 3607 r#"
3505enum Option<T> { None, Some(T) } 3608//- minicore: option
3506use Option::*;
3507fn foo() -> Option<()> { 3609fn foo() -> Option<()> {
3508 loop { 3610 loop {
3509 let n = Some(1); 3611 let n = Some(1);
@@ -3514,7 +3616,8 @@ fn foo() -> Option<()> {
3514 let r = n + k; 3616 let r = n + k;
3515 } 3617 }
3516 Some(()) 3618 Some(())
3517}"##, 3619}
3620"#,
3518 ); 3621 );
3519 } 3622 }
3520 3623
@@ -3523,9 +3626,8 @@ fn foo() -> Option<()> {
3523 cov_mark::check!(external_control_flow_try_and_return_non_err); 3626 cov_mark::check!(external_control_flow_try_and_return_non_err);
3524 check_assist_not_applicable( 3627 check_assist_not_applicable(
3525 extract_function, 3628 extract_function,
3526 r##" 3629 r#"
3527enum Result<T, E> { Ok(T), Err(E), } 3630//- minicore: result
3528use Result::*;
3529fn foo() -> Result<(), i64> { 3631fn foo() -> Result<(), i64> {
3530 let n = 1; 3632 let n = 1;
3531 $0let k = foo()?; 3633 $0let k = foo()?;
@@ -3535,7 +3637,8 @@ fn foo() -> Result<(), i64> {
3535 let m = k + 1;$0 3637 let m = k + 1;$0
3536 let h = 1 + m; 3638 let h = 1 + m;
3537 Ok(()) 3639 Ok(())
3538}"##, 3640}
3641"#,
3539 ); 3642 );
3540 } 3643 }
3541 3644
@@ -3543,7 +3646,7 @@ fn foo() -> Result<(), i64> {
3543 fn param_usage_in_macro() { 3646 fn param_usage_in_macro() {
3544 check_assist( 3647 check_assist(
3545 extract_function, 3648 extract_function,
3546 r" 3649 r#"
3547macro_rules! m { 3650macro_rules! m {
3548 ($val:expr) => { $val }; 3651 ($val:expr) => { $val };
3549} 3652}
@@ -3552,8 +3655,9 @@ fn foo() {
3552 let n = 1; 3655 let n = 1;
3553 $0let k = n * m!(n);$0 3656 $0let k = n * m!(n);$0
3554 let m = k + 1; 3657 let m = k + 1;
3555}", 3658}
3556 r" 3659"#,
3660 r#"
3557macro_rules! m { 3661macro_rules! m {
3558 ($val:expr) => { $val }; 3662 ($val:expr) => { $val };
3559} 3663}
@@ -3567,7 +3671,8 @@ fn foo() {
3567fn $0fun_name(n: i32) -> i32 { 3671fn $0fun_name(n: i32) -> i32 {
3568 let k = n * m!(n); 3672 let k = n * m!(n);
3569 k 3673 k
3570}", 3674}
3675"#,
3571 ); 3676 );
3572 } 3677 }
3573 3678
@@ -3575,7 +3680,8 @@ fn $0fun_name(n: i32) -> i32 {
3575 fn extract_with_await() { 3680 fn extract_with_await() {
3576 check_assist( 3681 check_assist(
3577 extract_function, 3682 extract_function,
3578 r#"fn main() { 3683 r#"
3684fn main() {
3579 $0some_function().await;$0 3685 $0some_function().await;$0
3580} 3686}
3581 3687
@@ -3603,7 +3709,8 @@ async fn some_function() {
3603 fn extract_with_await_in_args() { 3709 fn extract_with_await_in_args() {
3604 check_assist( 3710 check_assist(
3605 extract_function, 3711 extract_function,
3606 r#"fn main() { 3712 r#"
3713fn main() {
3607 $0function_call("a", some_function().await);$0 3714 $0function_call("a", some_function().await);$0
3608} 3715}
3609 3716