1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000
//! Some lints that are built in to the compiler.
//!
//! These are the built-in lints that are emitted direct in the main
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
use rustc_span::edition::Edition;
use rustc_span::symbol::sym;
declare_lint! {
/// The `forbidden_lint_groups` lint detects violations of
/// `forbid` applied to a lint group. Due to a bug in the compiler,
/// these used to be overlooked entirely. They now generate a warning.
///
/// ### Example
///
/// ```rust
/// #![forbid(warnings)]
/// #![deny(bad_style)]
///
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Recommended fix
///
/// If your crate is using `#![forbid(warnings)]`,
/// we recommend that you change to `#![deny(warnings)]`.
///
/// ### Explanation
///
/// Due to a compiler bug, applying `forbid` to lint groups
/// previously had no effect. The bug is now fixed but instead of
/// enforcing `forbid` we issue this future-compatibility warning
/// to avoid breaking existing crates.
pub FORBIDDEN_LINT_GROUPS,
Warn,
"applying forbid to lint-groups",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
};
}
declare_lint! {
/// The `ill_formed_attribute_input` lint detects ill-formed attribute
/// inputs that were previously accepted and used in practice.
///
/// ### Example
///
/// ```rust,compile_fail
/// #[inline = "this is not valid"]
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previously, inputs for many built-in attributes weren't validated and
/// nonsensical attribute inputs were accepted. After validation was
/// added, it was determined that some existing projects made use of these
/// invalid forms. This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #57571] for more details.
///
/// Check the [attribute reference] for details on the valid inputs for
/// attributes.
///
/// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
/// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub ILL_FORMED_ATTRIBUTE_INPUT,
Deny,
"ill-formed attribute inputs that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
};
crate_level_only
}
declare_lint! {
/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
/// conflicting hints.
///
/// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
///
/// ### Example
///
/// ```rust,compile_fail
/// #[repr(u32, u64)]
/// enum Foo {
/// Variant1,
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler incorrectly accepted these conflicting representations in
/// the past. This is a [future-incompatible] lint to transition this to a
/// hard error in the future. See [issue #68585] for more details.
///
/// To correct the issue, remove one of the conflicting hints.
///
/// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub CONFLICTING_REPR_HINTS,
Deny,
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
};
}
declare_lint! {
/// The `meta_variable_misuse` lint detects possible meta-variable misuse
/// in macro definitions.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(meta_variable_misuse)]
///
/// macro_rules! foo {
/// () => {};
/// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
/// }
///
/// fn main() {
/// foo!();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// There are quite a few different ways a [`macro_rules`] macro can be
/// improperly defined. Many of these errors were previously only detected
/// when the macro was expanded or not at all. This lint is an attempt to
/// catch some of these problems when the macro is *defined*.
///
/// This lint is "allow" by default because it may have false positives
/// and other issues. See [issue #61053] for more details.
///
/// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
/// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
pub META_VARIABLE_MISUSE,
Allow,
"possible meta-variable misuse at macro definition"
}
declare_lint! {
/// The `incomplete_include` lint detects the use of the [`include!`]
/// macro with a file that contains more than one expression.
///
/// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
///
/// ### Example
///
/// ```rust,ignore (needs separate file)
/// fn main() {
/// include!("foo.txt");
/// }
/// ```
///
/// where the file `foo.txt` contains:
///
/// ```text
/// println!("hi!");
/// ```
///
/// produces:
///
/// ```text
/// error: include macro expected single expression in source
/// --> foo.txt:1:14
/// |
/// 1 | println!("1");
/// | ^
/// |
/// = note: `#[deny(incomplete_include)]` on by default
/// ```
///
/// ### Explanation
///
/// The [`include!`] macro is currently only intended to be used to
/// include a single [expression] or multiple [items]. Historically it
/// would ignore any contents after the first expression, but that can be
/// confusing. In the example above, the `println!` expression ends just
/// before the semicolon, making the semicolon "extra" information that is
/// ignored. Perhaps even more surprising, if the included file had
/// multiple print statements, the subsequent ones would be ignored!
///
/// One workaround is to place the contents in braces to create a [block
/// expression]. Also consider alternatives, like using functions to
/// encapsulate the expressions, or use [proc-macros].
///
/// This is a lint instead of a hard error because existing projects were
/// found to hit this error. To be cautious, it is a lint for now. The
/// future semantics of the `include!` macro are also uncertain, see
/// [issue #35560].
///
/// [items]: https://doc.rust-lang.org/reference/items.html
/// [expression]: https://doc.rust-lang.org/reference/expressions.html
/// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
/// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
/// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
pub INCOMPLETE_INCLUDE,
Deny,
"trailing content in included file"
}
declare_lint! {
/// The `arithmetic_overflow` lint detects that an arithmetic operation
/// will [overflow].
///
/// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
///
/// ### Example
///
/// ```rust,compile_fail
/// 1_i32 << 32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is very likely a mistake to perform an arithmetic operation that
/// overflows its value. If the compiler is able to detect these kinds of
/// overflows at compile-time, it will trigger this lint. Consider
/// adjusting the expression to avoid overflow, or use a data type that
/// will not overflow.
pub ARITHMETIC_OVERFLOW,
Deny,
"arithmetic operation overflows"
}
declare_lint! {
/// The `unconditional_panic` lint detects an operation that will cause a
/// panic at runtime.
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![allow(unused)]
/// let x = 1 / 0;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint detects code that is very likely incorrect because it will
/// always panic, such as division by zero and out-of-bounds array
/// accesses. Consider adjusting your code if this is a bug, or using the
/// `panic!` or `unreachable!` macro instead in case the panic is intended.
pub UNCONDITIONAL_PANIC,
Deny,
"operation will cause a panic at runtime"
}
declare_lint! {
/// The `unused_imports` lint detects imports that are never used.
///
/// ### Example
///
/// ```rust
/// use std::collections::HashMap;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused imports may signal a mistake or unfinished code, and clutter
/// the code, and should be removed. If you intended to re-export the item
/// to make it available outside of the module, add a visibility modifier
/// like `pub`.
pub UNUSED_IMPORTS,
Warn,
"imports that are never used"
}
declare_lint! {
/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
/// (`.await`)
///
/// ### Example
///
/// ```rust
/// #![feature(must_not_suspend)]
/// #![warn(must_not_suspend)]
///
/// #[must_not_suspend]
/// struct SyncThing {}
///
/// async fn yield_now() {}
///
/// pub async fn uhoh() {
/// let guard = SyncThing {};
/// yield_now().await;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
/// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
/// function.
///
/// This attribute can be used to mark values that are semantically incorrect across suspends
/// (like certain types of timers), values that have async alternatives, and values that
/// regularly cause problems with the `Send`-ness of async fn's returned futures (like
/// `MutexGuard`'s)
///
pub MUST_NOT_SUSPEND,
Allow,
"use of a `#[must_not_suspend]` value across a yield point",
@feature_gate = rustc_span::symbol::sym::must_not_suspend;
}
declare_lint! {
/// The `unused_extern_crates` lint guards against `extern crate` items
/// that are never used.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unused_extern_crates)]
/// extern crate proc_macro;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// `extern crate` items that are unused have no effect and should be
/// removed. Note that there are some cases where specifying an `extern
/// crate` is desired for the side effect of ensuring the given crate is
/// linked, even though it is not otherwise directly referenced. The lint
/// can be silenced by aliasing the crate to an underscore, such as
/// `extern crate foo as _`. Also note that it is no longer idiomatic to
/// use `extern crate` in the [2018 edition], as extern crates are now
/// automatically added in scope.
///
/// This lint is "allow" by default because it can be noisy, and produce
/// false-positives. If a dependency is being removed from a project, it
/// is recommended to remove it from the build configuration (such as
/// `Cargo.toml`) to ensure stale build entries aren't left behind.
///
/// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
pub UNUSED_EXTERN_CRATES,
Allow,
"extern crates that are never used"
}
declare_lint! {
/// The `unused_crate_dependencies` lint detects crate dependencies that
/// are never used.
///
/// ### Example
///
/// ```rust,ignore (needs extern crate)
/// #![deny(unused_crate_dependencies)]
/// ```
///
/// This will produce:
///
/// ```text
/// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
/// |
/// note: the lint level is defined here
/// --> src/lib.rs:1:9
/// |
/// 1 | #![deny(unused_crate_dependencies)]
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^
/// ```
///
/// ### Explanation
///
/// After removing the code that uses a dependency, this usually also
/// requires removing the dependency from the build configuration.
/// However, sometimes that step can be missed, which leads to time wasted
/// building dependencies that are no longer used. This lint can be
/// enabled to detect dependencies that are never used (more specifically,
/// any dependency passed with the `--extern` command-line flag that is
/// never referenced via [`use`], [`extern crate`], or in any [path]).
///
/// This lint is "allow" by default because it can provide false positives
/// depending on how the build system is configured. For example, when
/// using Cargo, a "package" consists of multiple crates (such as a
/// library and a binary), but the dependencies are defined for the
/// package as a whole. If there is a dependency that is only used in the
/// binary, but not the library, then the lint will be incorrectly issued
/// in the library.
///
/// [path]: https://doc.rust-lang.org/reference/paths.html
/// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
/// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
pub UNUSED_CRATE_DEPENDENCIES,
Allow,
"crate dependencies that are never used",
crate_level_only
}
declare_lint! {
/// The `unused_qualifications` lint detects unnecessarily qualified
/// names.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unused_qualifications)]
/// mod foo {
/// pub fn bar() {}
/// }
///
/// fn main() {
/// use foo::bar;
/// foo::bar();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// If an item from another module is already brought into scope, then
/// there is no need to qualify it in this case. You can call `bar()`
/// directly, without the `foo::`.
///
/// This lint is "allow" by default because it is somewhat pedantic, and
/// doesn't indicate an actual problem, but rather a stylistic choice, and
/// can be noisy when refactoring or moving around code.
pub UNUSED_QUALIFICATIONS,
Allow,
"detects unnecessarily qualified names"
}
declare_lint! {
/// The `unknown_lints` lint detects unrecognized lint attributes.
///
/// ### Example
///
/// ```rust
/// #![allow(not_a_real_lint)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to specify a lint that does not exist. Check
/// the spelling, and check the lint listing for the correct name. Also
/// consider if you are using an old version of the compiler, and the lint
/// is only available in a newer version.
pub UNKNOWN_LINTS,
Warn,
"unrecognized lint attribute"
}
declare_lint! {
/// The `unfulfilled_lint_expectations` lint detects lint trigger expectations
/// that have not been fulfilled.
///
/// ### Example
///
/// ```rust
/// #![feature(lint_reasons)]
///
/// #[expect(unused_variables)]
/// let x = 10;
/// println!("{}", x);
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It was expected that the marked code would emit a lint. This expectation
/// has not been fulfilled.
///
/// The `expect` attribute can be removed if this is intended behavior otherwise
/// it should be investigated why the expected lint is no longer issued.
///
/// In rare cases, the expectation might be emitted at a different location than
/// shown in the shown code snippet. In most cases, the `#[expect]` attribute
/// works when added to the outer scope. A few lints can only be expected
/// on a crate level.
///
/// Part of RFC 2383. The progress is being tracked in [#54503]
///
/// [#54503]: https://github.com/rust-lang/rust/issues/54503
pub UNFULFILLED_LINT_EXPECTATIONS,
Warn,
"unfulfilled lint expectation",
@feature_gate = rustc_span::sym::lint_reasons;
}
declare_lint! {
/// The `unused_variables` lint detects variables which are not used in
/// any way.
///
/// ### Example
///
/// ```rust
/// let x = 5;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused variables may signal a mistake or unfinished code. To silence
/// the warning for the individual variable, prefix it with an underscore
/// such as `_x`.
pub UNUSED_VARIABLES,
Warn,
"detect variables which are not used in any way"
}
declare_lint! {
/// The `unused_assignments` lint detects assignments that will never be read.
///
/// ### Example
///
/// ```rust
/// let mut x = 5;
/// x = 6;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused assignments may signal a mistake or unfinished code. If the
/// variable is never used after being assigned, then the assignment can
/// be removed. Variables with an underscore prefix such as `_x` will not
/// trigger this lint.
pub UNUSED_ASSIGNMENTS,
Warn,
"detect assignments that will never be read"
}
declare_lint! {
/// The `dead_code` lint detects unused, unexported items.
///
/// ### Example
///
/// ```rust
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Dead code may signal a mistake or unfinished code. To silence the
/// warning for individual items, prefix the name with an underscore such
/// as `_foo`. If it was intended to expose the item outside of the crate,
/// consider adding a visibility modifier like `pub`. Otherwise consider
/// removing the unused code.
pub DEAD_CODE,
Warn,
"detect unused, unexported items"
}
declare_lint! {
/// The `unused_attributes` lint detects attributes that were not used by
/// the compiler.
///
/// ### Example
///
/// ```rust
/// #![ignore]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused [attributes] may indicate the attribute is placed in the wrong
/// position. Consider removing it, or placing it in the correct position.
/// Also consider if you intended to use an _inner attribute_ (with a `!`
/// such as `#![allow(unused)]`) which applies to the item the attribute
/// is within, or an _outer attribute_ (without a `!` such as
/// `#[allow(unused)]`) which applies to the item *following* the
/// attribute.
///
/// [attributes]: https://doc.rust-lang.org/reference/attributes.html
pub UNUSED_ATTRIBUTES,
Warn,
"detects attributes that were not used by the compiler"
}
declare_lint! {
/// The `unused_tuple_struct_fields` lint detects fields of tuple structs
/// that are never read.
///
/// ### Example
///
/// ```rust
/// #[warn(unused_tuple_struct_fields)]
/// struct S(i32, i32, i32);
/// let s = S(1, 2, 3);
/// let _ = (s.0, s.2);
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Tuple struct fields that are never read anywhere may indicate a
/// mistake or unfinished code. To silence this warning, consider
/// removing the unused field(s) or, to preserve the numbering of the
/// remaining fields, change the unused field(s) to have unit type.
pub UNUSED_TUPLE_STRUCT_FIELDS,
Allow,
"detects tuple struct fields that are never read"
}
declare_lint! {
/// The `unreachable_code` lint detects unreachable code paths.
///
/// ### Example
///
/// ```rust,no_run
/// panic!("we never go past here!");
///
/// let x = 5;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unreachable code may signal a mistake or unfinished code. If the code
/// is no longer in use, consider removing it.
pub UNREACHABLE_CODE,
Warn,
"detects unreachable code paths",
report_in_external_macro
}
declare_lint! {
/// The `unreachable_patterns` lint detects unreachable patterns.
///
/// ### Example
///
/// ```rust
/// let x = 5;
/// match x {
/// y => (),
/// 5 => (),
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This usually indicates a mistake in how the patterns are specified or
/// ordered. In this example, the `y` pattern will always match, so the
/// five is impossible to reach. Remember, match arms match in order, you
/// probably wanted to put the `5` case above the `y` case.
pub UNREACHABLE_PATTERNS,
Warn,
"detects unreachable patterns"
}
declare_lint! {
/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
/// overlap on their endpoints.
///
/// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
///
/// ### Example
///
/// ```rust
/// let x = 123u8;
/// match x {
/// 0..=100 => { println!("small"); }
/// 100..=255 => { println!("large"); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is likely a mistake to have range patterns in a match expression that overlap in this
/// way. Check that the beginning and end values are what you expect, and keep in mind that
/// with `..=` the left and right bounds are inclusive.
pub OVERLAPPING_RANGE_ENDPOINTS,
Warn,
"detects range patterns with overlapping endpoints"
}
declare_lint! {
/// The `bindings_with_variant_name` lint detects pattern bindings with
/// the same name as one of the matched variants.
///
/// ### Example
///
/// ```rust
/// pub enum Enum {
/// Foo,
/// Bar,
/// }
///
/// pub fn foo(x: Enum) {
/// match x {
/// Foo => {}
/// Bar => {}
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to specify an enum variant name as an
/// [identifier pattern]. In the example above, the `match` arms are
/// specifying a variable name to bind the value of `x` to. The second arm
/// is ignored because the first one matches *all* values. The likely
/// intent is that the arm was intended to match on the enum variant.
///
/// Two possible solutions are:
///
/// * Specify the enum variant using a [path pattern], such as
/// `Enum::Foo`.
/// * Bring the enum variants into local scope, such as adding `use
/// Enum::*;` to the beginning of the `foo` function in the example
/// above.
///
/// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
/// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
pub BINDINGS_WITH_VARIANT_NAME,
Warn,
"detects pattern bindings with the same name as one of the matched variants"
}
declare_lint! {
/// The `unused_macros` lint detects macros that were not used.
///
/// Note that this lint is distinct from the `unused_macro_rules` lint,
/// which checks for single rules that never match of an otherwise used
/// macro, and thus never expand.
///
/// ### Example
///
/// ```rust
/// macro_rules! unused {
/// () => {};
/// }
///
/// fn main() {
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused macros may signal a mistake or unfinished code. To silence the
/// warning for the individual macro, prefix the name with an underscore
/// such as `_my_macro`. If you intended to export the macro to make it
/// available outside of the crate, use the [`macro_export` attribute].
///
/// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
pub UNUSED_MACROS,
Warn,
"detects macros that were not used"
}
declare_lint! {
/// The `unused_macro_rules` lint detects macro rules that were not used.
///
/// Note that the lint is distinct from the `unused_macros` lint, which
/// fires if the entire macro is never called, while this lint fires for
/// single unused rules of the macro that is otherwise used.
/// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
///
/// ### Example
///
/// ```rust
/// #[warn(unused_macro_rules)]
/// macro_rules! unused_empty {
/// (hello) => { println!("Hello, world!") }; // This rule is unused
/// () => { println!("empty") }; // This rule is used
/// }
///
/// fn main() {
/// unused_empty!(hello);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused macro rules may signal a mistake or unfinished code. Furthermore,
/// they slow down compilation. Right now, silencing the warning is not
/// supported on a single rule level, so you have to add an allow to the
/// entire macro definition.
///
/// If you intended to export the macro to make it
/// available outside of the crate, use the [`macro_export` attribute].
///
/// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
pub UNUSED_MACRO_RULES,
Allow,
"detects macro rules that were not used"
}
declare_lint! {
/// The `warnings` lint allows you to change the level of other
/// lints which produce warnings.
///
/// ### Example
///
/// ```rust
/// #![deny(warnings)]
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The `warnings` lint is a bit special; by changing its level, you
/// change every other warning that would produce a warning to whatever
/// value you'd like. As such, you won't ever trigger this lint in your
/// code directly.
pub WARNINGS,
Warn,
"mass-change the level for lints which produce warnings"
}
declare_lint! {
/// The `unused_features` lint detects unused or unknown features found in
/// crate-level [`feature` attributes].
///
/// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// Note: This lint is currently not functional, see [issue #44232] for
/// more details.
///
/// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
pub UNUSED_FEATURES,
Warn,
"unused features found in crate-level `#[feature]` directives"
}
declare_lint! {
/// The `stable_features` lint detects a [`feature` attribute] that
/// has since been made stable.
///
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// ### Example
///
/// ```rust
/// #![feature(test_accepted_feature)]
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// When a feature is stabilized, it is no longer necessary to include a
/// `#![feature]` attribute for it. To fix, simply remove the
/// `#![feature]` attribute.
pub STABLE_FEATURES,
Warn,
"stable features found in `#[feature]` directive"
}
declare_lint! {
/// The `unknown_crate_types` lint detects an unknown crate type found in
/// a [`crate_type` attribute].
///
/// ### Example
///
/// ```rust,compile_fail
/// #![crate_type="lol"]
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// An unknown value give to the `crate_type` attribute is almost
/// certainly a mistake.
///
/// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
pub UNKNOWN_CRATE_TYPES,
Deny,
"unknown crate type found in `#[crate_type]` directive",
crate_level_only
}
declare_lint! {
/// The `trivial_casts` lint detects trivial casts which could be replaced
/// with coercion, which may require a temporary variable.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(trivial_casts)]
/// let x: &u32 = &42;
/// let y = x as *const u32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
/// subtype of `T`. This type of cast is usually unnecessary, as it can be
/// usually be inferred.
///
/// This lint is "allow" by default because there are situations, such as
/// with FFI interfaces or complex type aliases, where it triggers
/// incorrectly, or in situations where it will be more difficult to
/// clearly express the intent. It may be possible that this will become a
/// warning in the future, possibly with an explicit syntax for coercions
/// providing a convenient way to work around the current issues.
/// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
/// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
///
/// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
/// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
/// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
pub TRIVIAL_CASTS,
Allow,
"detects trivial casts which could be removed"
}
declare_lint! {
/// The `trivial_numeric_casts` lint detects trivial numeric casts of types
/// which could be removed.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(trivial_numeric_casts)]
/// let x = 42_i32 as i32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A trivial numeric cast is a cast of a numeric type to the same numeric
/// type. This type of cast is usually unnecessary.
///
/// This lint is "allow" by default because there are situations, such as
/// with FFI interfaces or complex type aliases, where it triggers
/// incorrectly, or in situations where it will be more difficult to
/// clearly express the intent. It may be possible that this will become a
/// warning in the future, possibly with an explicit syntax for coercions
/// providing a convenient way to work around the current issues.
/// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
/// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
///
/// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
/// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
/// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
pub TRIVIAL_NUMERIC_CASTS,
Allow,
"detects trivial casts of numeric types which could be removed"
}
declare_lint! {
/// The `private_in_public` lint detects private items in public
/// interfaces not caught by the old implementation.
///
/// ### Example
///
/// ```rust
/// # #![allow(unused)]
/// struct SemiPriv;
///
/// mod m1 {
/// struct Priv;
/// impl super::SemiPriv {
/// pub fn f(_: Priv) {}
/// }
/// }
/// # fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The visibility rules are intended to prevent exposing private items in
/// public interfaces. This is a [future-incompatible] lint to transition
/// this to a hard error in the future. See [issue #34537] for more
/// details.
///
/// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PRIVATE_IN_PUBLIC,
Warn,
"detect private items in public interfaces not caught by the old implementation",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
};
}
declare_lint! {
/// The `invalid_alignment` lint detects dereferences of misaligned pointers during
/// constant evluation.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![feature(const_ptr_read)]
/// const FOO: () = unsafe {
/// let x = &[0_u8; 4];
/// let y = x.as_ptr().cast::<u32>();
/// y.read(); // the address of a `u8` array is unknown and thus we don't know if
/// // it is aligned enough for reading a `u32`.
/// };
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler allowed dereferencing raw pointers irrespective of alignment
/// during const eval due to the const evaluator at the time not making it easy
/// or cheap to check. Now that it is both, this is not accepted anymore.
///
/// Since it was undefined behaviour to begin with, this breakage does not violate
/// Rust's stability guarantees. Using undefined behaviour can cause arbitrary
/// behaviour, including failure to build.
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub INVALID_ALIGNMENT,
Deny,
"raw pointers must be aligned before dereferencing",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/104616>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
declare_lint! {
/// The `exported_private_dependencies` lint detects private dependencies
/// that are exposed in a public interface.
///
/// ### Example
///
/// ```rust,ignore (needs-dependency)
/// pub fn foo() -> Option<some_private_dependency::Thing> {
/// None
/// }
/// ```
///
/// This will produce:
///
/// ```text
/// warning: type `bar::Thing` from private dependency 'bar' in public interface
/// --> src/lib.rs:3:1
/// |
/// 3 | pub fn foo() -> Option<bar::Thing> {
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/// |
/// = note: `#[warn(exported_private_dependencies)]` on by default
/// ```
///
/// ### Explanation
///
/// Dependencies can be marked as "private" to indicate that they are not
/// exposed in the public interface of a crate. This can be used by Cargo
/// to independently resolve those dependencies because it can assume it
/// does not need to unify them with other packages using that same
/// dependency. This lint is an indication of a violation of that
/// contract.
///
/// To fix this, avoid exposing the dependency in your public interface.
/// Or, switch the dependency to a public dependency.
///
/// Note that support for this is only available on the nightly channel.
/// See [RFC 1977] for more details, as well as the [Cargo documentation].
///
/// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
/// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
pub EXPORTED_PRIVATE_DEPENDENCIES,
Warn,
"public interface leaks type from a private dependency"
}
declare_lint! {
/// The `pub_use_of_private_extern_crate` lint detects a specific
/// situation of re-exporting a private `extern crate`.
///
/// ### Example
///
/// ```rust,compile_fail
/// extern crate core;
/// pub use core as reexported_core;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A public `use` declaration should not be used to publicly re-export a
/// private `extern crate`. `pub extern crate` should be used instead.
///
/// This was historically allowed, but is not the intended behavior
/// according to the visibility rules. This is a [future-incompatible]
/// lint to transition this to a hard error in the future. See [issue
/// #34537] for more details.
///
/// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
Deny,
"detect public re-exports of private extern crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
};
}
declare_lint! {
/// The `invalid_type_param_default` lint detects type parameter defaults
/// erroneously allowed in an invalid location.
///
/// ### Example
///
/// ```rust,compile_fail
/// fn foo<T=i32>(t: T) {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Default type parameters were only intended to be allowed in certain
/// situations, but historically the compiler allowed them everywhere.
/// This is a [future-incompatible] lint to transition this to a hard
/// error in the future. See [issue #36887] for more details.
///
/// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub INVALID_TYPE_PARAM_DEFAULT,
Deny,
"type parameter default erroneously allowed in invalid location",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
};
}
declare_lint! {
/// The `renamed_and_removed_lints` lint detects lints that have been
/// renamed or removed.
///
/// ### Example
///
/// ```rust
/// #![deny(raw_pointer_derive)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// To fix this, either remove the lint or use the new name. This can help
/// avoid confusion about lints that are no longer valid, and help
/// maintain consistency for renamed lints.
pub RENAMED_AND_REMOVED_LINTS,
Warn,
"lints that have been renamed or removed"
}
declare_lint! {
/// The `unaligned_references` lint detects unaligned references to fields
/// of [packed] structs.
///
/// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
///
/// ### Example
///
/// ```rust,compile_fail
/// #[repr(packed)]
/// pub struct Foo {
/// field1: u64,
/// field2: u8,
/// }
///
/// fn main() {
/// unsafe {
/// let foo = Foo { field1: 0, field2: 0 };
/// let _ = &foo.field1;
/// println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
/// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
/// the code should do a copy of the data in the packed field or use raw pointers and unaligned
/// accesses. See [issue #82523] for more information.
///
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
/// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
pub UNALIGNED_REFERENCES,
Deny,
"detects unaligned references to fields of packed structs",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
report_in_external_macro
}
declare_lint! {
/// The `const_item_mutation` lint detects attempts to mutate a `const`
/// item.
///
/// ### Example
///
/// ```rust
/// const FOO: [i32; 1] = [0];
///
/// fn main() {
/// FOO[0] = 1;
/// // This will print "[0]".
/// println!("{:?}", FOO);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Trying to directly mutate a `const` item is almost always a mistake.
/// What is happening in the example above is that a temporary copy of the
/// `const` is mutated, but the original `const` is not. Each time you
/// refer to the `const` by name (such as `FOO` in the example above), a
/// separate copy of the value is inlined at that location.
///
/// This lint checks for writing directly to a field (`FOO.field =
/// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
/// reference to the const item (`&mut FOO`), including through an
/// autoderef (`FOO.some_mut_self_method()`).
///
/// There are various alternatives depending on what you are trying to
/// accomplish:
///
/// * First, always reconsider using mutable globals, as they can be
/// difficult to use correctly, and can make the code more difficult to
/// use or understand.
/// * If you are trying to perform a one-time initialization of a global:
/// * If the value can be computed at compile-time, consider using
/// const-compatible values (see [Constant Evaluation]).
/// * For more complex single-initialization cases, consider using a
/// third-party crate, such as [`lazy_static`] or [`once_cell`].
/// * If you are using the [nightly channel], consider the new
/// [`lazy`] module in the standard library.
/// * If you truly need a mutable global, consider using a [`static`],
/// which has a variety of options:
/// * Simple data types can be directly defined and mutated with an
/// [`atomic`] type.
/// * More complex types can be placed in a synchronization primitive
/// like a [`Mutex`], which can be initialized with one of the options
/// listed above.
/// * A [mutable `static`] is a low-level primitive, requiring unsafe.
/// Typically This should be avoided in preference of something
/// higher-level like one of the above.
///
/// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
/// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
/// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
/// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
/// [`lazy_static`]: https://crates.io/crates/lazy_static
/// [`once_cell`]: https://crates.io/crates/once_cell
/// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
/// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
pub CONST_ITEM_MUTATION,
Warn,
"detects attempts to mutate a `const` item",
}
declare_lint! {
/// The `patterns_in_fns_without_body` lint detects `mut` identifier
/// patterns as a parameter in functions without a body.
///
/// ### Example
///
/// ```rust,compile_fail
/// trait Trait {
/// fn foo(mut arg: u8);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// To fix this, remove `mut` from the parameter in the trait definition;
/// it can be used in the implementation. That is, the following is OK:
///
/// ```rust
/// trait Trait {
/// fn foo(arg: u8); // Removed `mut` here
/// }
///
/// impl Trait for i32 {
/// fn foo(mut arg: u8) { // `mut` here is OK
///
/// }
/// }
/// ```
///
/// Trait definitions can define functions without a body to specify a
/// function that implementors must define. The parameter names in the
/// body-less functions are only allowed to be `_` or an [identifier] for
/// documentation purposes (only the type is relevant). Previous versions
/// of the compiler erroneously allowed [identifier patterns] with the
/// `mut` keyword, but this was not intended to be allowed. This is a
/// [future-incompatible] lint to transition this to a hard error in the
/// future. See [issue #35203] for more details.
///
/// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
/// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
/// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PATTERNS_IN_FNS_WITHOUT_BODY,
Deny,
"patterns in functions without body were erroneously allowed",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
};
}
declare_lint! {
/// The `missing_fragment_specifier` lint is issued when an unused pattern in a
/// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
/// followed by a fragment specifier (e.g. `:expr`).
///
/// This warning can always be fixed by removing the unused pattern in the
/// `macro_rules!` macro definition.
///
/// ### Example
///
/// ```rust,compile_fail
/// macro_rules! foo {
/// () => {};
/// ($name) => { };
/// }
///
/// fn main() {
/// foo!();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
///
/// ```rust
/// macro_rules! foo {
/// () => {};
/// }
/// fn main() {
/// foo!();
/// }
/// ```
pub MISSING_FRAGMENT_SPECIFIER,
Deny,
"detects missing fragment specifiers in unused `macro_rules!` patterns",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
};
}
declare_lint! {
/// The `late_bound_lifetime_arguments` lint detects generic lifetime
/// arguments in path segments with late bound lifetime parameters.
///
/// ### Example
///
/// ```rust
/// struct S;
///
/// impl S {
/// fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
/// }
///
/// fn main() {
/// S.late::<'static>(&0, &0);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is not clear how to provide arguments for early-bound lifetime
/// parameters if they are intermixed with late-bound parameters in the
/// same list. For now, providing any explicit arguments will trigger this
/// lint if late-bound parameters are present, so in the future a solution
/// can be adopted without hitting backward compatibility issues. This is
/// a [future-incompatible] lint to transition this to a hard error in the
/// future. See [issue #42868] for more details, along with a description
/// of the difference between early and late-bound parameters.
///
/// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub LATE_BOUND_LIFETIME_ARGUMENTS,
Warn,
"detects generic lifetime arguments in path segments with late bound lifetime parameters",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
};
}
declare_lint! {
/// The `order_dependent_trait_objects` lint detects a trait coherency
/// violation that would allow creating two trait impls for the same
/// dynamic trait object involving marker traits.
///
/// ### Example
///
/// ```rust,compile_fail
/// pub trait Trait {}
///
/// impl Trait for dyn Send + Sync { }
/// impl Trait for dyn Sync + Send { }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A previous bug caused the compiler to interpret traits with different
/// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
/// when they were intended to be treated the same. This allowed code to
/// define separate trait implementations when there should be a coherence
/// error. This is a [future-incompatible] lint to transition this to a
/// hard error in the future. See [issue #56484] for more details.
///
/// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub ORDER_DEPENDENT_TRAIT_OBJECTS,
Deny,
"trait-object types were treated as different depending on marker-trait order",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
declare_lint! {
/// The `coherence_leak_check` lint detects conflicting implementations of
/// a trait that are only distinguished by the old leak-check code.
///
/// ### Example
///
/// ```rust
/// trait SomeTrait { }
/// impl SomeTrait for for<'a> fn(&'a u8) { }
/// impl<'a> SomeTrait for fn(&'a u8) { }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the past, the compiler would accept trait implementations for
/// identical functions that differed only in where the lifetime binder
/// appeared. Due to a change in the borrow checker implementation to fix
/// several bugs, this is no longer allowed. However, since this affects
/// existing code, this is a [future-incompatible] lint to transition this
/// to a hard error in the future.
///
/// Code relying on this pattern should introduce "[newtypes]",
/// like `struct Foo(for<'a> fn(&'a u8))`.
///
/// See [issue #56105] for more details.
///
/// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
/// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub COHERENCE_LEAK_CHECK,
Warn,
"distinct impls distinguished only by the leak-check code",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
};
}
declare_lint! {
/// The `deprecated` lint detects use of deprecated items.
///
/// ### Example
///
/// ```rust
/// #[deprecated]
/// fn foo() {}
///
/// fn bar() {
/// foo();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Items may be marked "deprecated" with the [`deprecated` attribute] to
/// indicate that they should no longer be used. Usually the attribute
/// should include a note on what to use instead, or check the
/// documentation.
///
/// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
pub DEPRECATED,
Warn,
"detects use of deprecated items",
report_in_external_macro
}
declare_lint! {
/// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
///
/// ### Example
///
/// ```rust
/// unsafe {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// If nothing within the block requires `unsafe`, then remove the
/// `unsafe` marker because it is not required and may cause confusion.
pub UNUSED_UNSAFE,
Warn,
"unnecessary use of an `unsafe` block"
}
declare_lint! {
/// The `unused_mut` lint detects mut variables which don't need to be
/// mutable.
///
/// ### Example
///
/// ```rust
/// let mut x = 5;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The preferred style is to only mark variables as `mut` if it is
/// required.
pub UNUSED_MUT,
Warn,
"detect mut variables which don't need to be mutable"
}
declare_lint! {
/// The `unconditional_recursion` lint detects functions that cannot
/// return without calling themselves.
///
/// ### Example
///
/// ```rust
/// fn foo() {
/// foo();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to have a recursive call that does not have
/// some condition to cause it to terminate. If you really intend to have
/// an infinite loop, using a `loop` expression is recommended.
pub UNCONDITIONAL_RECURSION,
Warn,
"functions that cannot return without calling themselves"
}
declare_lint! {
/// The `single_use_lifetimes` lint detects lifetimes that are only used
/// once.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(single_use_lifetimes)]
///
/// fn foo<'a>(x: &'a u32) {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Specifying an explicit lifetime like `'a` in a function or `impl`
/// should only be used to link together two things. Otherwise, you should
/// just use `'_` to indicate that the lifetime is not linked to anything,
/// or elide the lifetime altogether if possible.
///
/// This lint is "allow" by default because it was introduced at a time
/// when `'_` and elided lifetimes were first being introduced, and this
/// lint would be too noisy. Also, there are some known false positives
/// that it produces. See [RFC 2115] for historical context, and [issue
/// #44752] for more details.
///
/// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
/// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
pub SINGLE_USE_LIFETIMES,
Allow,
"detects lifetime parameters that are only used once"
}
declare_lint! {
/// The `unused_lifetimes` lint detects lifetime parameters that are never
/// used.
///
/// ### Example
///
/// ```rust,compile_fail
/// #[deny(unused_lifetimes)]
///
/// pub fn foo<'a>() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused lifetime parameters may signal a mistake or unfinished code.
/// Consider removing the parameter.
pub UNUSED_LIFETIMES,
Allow,
"detects lifetime parameters that are never used"
}
declare_lint! {
/// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
/// inference variable.
///
/// ### Example
///
/// ```rust,edition2015
/// // edition 2015
/// let data = std::ptr::null();
/// let _ = &data as *const *const ();
///
/// if data.is_null() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This kind of inference was previously allowed, but with the future
/// arrival of [arbitrary self types], this can introduce ambiguity. To
/// resolve this, use an explicit type instead of relying on type
/// inference.
///
/// This is a [future-incompatible] lint to transition this to a hard
/// error in the 2018 edition. See [issue #46906] for more details. This
/// is currently a hard-error on the 2018 edition, and is "warn" by
/// default in the 2015 edition.
///
/// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
/// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub TYVAR_BEHIND_RAW_POINTER,
Warn,
"raw pointer to an inference variable",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
};
}
declare_lint! {
/// The `elided_lifetimes_in_paths` lint detects the use of hidden
/// lifetime parameters.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(elided_lifetimes_in_paths)]
/// struct Foo<'a> {
/// x: &'a u32
/// }
///
/// fn foo(x: &Foo) {
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Elided lifetime parameters can make it difficult to see at a glance
/// that borrowing is occurring. This lint ensures that lifetime
/// parameters are always explicitly stated, even if it is the `'_`
/// [placeholder lifetime].
///
/// This lint is "allow" by default because it has some known issues, and
/// may require a significant transition for old code.
///
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
pub ELIDED_LIFETIMES_IN_PATHS,
Allow,
"hidden lifetime parameters in types are deprecated",
crate_level_only
}
declare_lint! {
/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
/// objects.
///
/// ### Example
///
/// ```rust,edition2018
/// trait Trait { }
///
/// fn takes_trait_object(_: Box<Trait>) {
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Without the `dyn` indicator, it can be ambiguous or confusing when
/// reading code as to whether or not you are looking at a trait object.
/// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
/// with [`impl Trait`].
///
/// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
pub BARE_TRAIT_OBJECTS,
Warn,
"suggest using `dyn Trait` for trait objects",
@future_incompatible = FutureIncompatibleInfo {
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
};
}
declare_lint! {
/// The `absolute_paths_not_starting_with_crate` lint detects fully
/// qualified paths that start with a module name instead of `crate`,
/// `self`, or an extern crate name
///
/// ### Example
///
/// ```rust,edition2015,compile_fail
/// #![deny(absolute_paths_not_starting_with_crate)]
///
/// mod foo {
/// pub fn bar() {}
/// }
///
/// fn main() {
/// ::foo::bar();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Rust [editions] allow the language to evolve without breaking
/// backwards compatibility. This lint catches code that uses absolute
/// paths in the style of the 2015 edition. In the 2015 edition, absolute
/// paths (those starting with `::`) refer to either the crate root or an
/// external crate. In the 2018 edition it was changed so that they only
/// refer to external crates. The path prefix `crate::` should be used
/// instead to reference items from the crate root.
///
/// If you switch the compiler from the 2015 to 2018 edition without
/// updating the code, then it will fail to compile if the old style paths
/// are used. You can manually change the paths to use the `crate::`
/// prefix to transition to the 2018 edition.
///
/// This lint solves the problem automatically. It is "allow" by default
/// because the code is perfectly valid in the 2015 edition. The [`cargo
/// fix`] tool with the `--edition` flag will switch this lint to "warn"
/// and automatically apply the suggested fix from the compiler. This
/// provides a completely automated way to update old code to the 2018
/// edition.
///
/// [editions]: https://doc.rust-lang.org/edition-guide/
/// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
Allow,
"fully qualified paths that start with a module name \
instead of `crate`, `self`, or an extern crate name",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
};
}
declare_lint! {
/// The `illegal_floating_point_literal_pattern` lint detects
/// floating-point literals used in patterns.
///
/// ### Example
///
/// ```rust
/// let x = 42.0;
///
/// match x {
/// 5.0 => {}
/// _ => {}
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of the compiler accepted floating-point literals in
/// patterns, but it was later determined this was a mistake. The
/// semantics of comparing floating-point values may not be clear in a
/// pattern when contrasted with "structural equality". Typically you can
/// work around this by using a [match guard], such as:
///
/// ```rust
/// # let x = 42.0;
///
/// match x {
/// y if y == 5.0 => {}
/// _ => {}
/// }
/// ```
///
/// This is a [future-incompatible] lint to transition this to a hard
/// error in the future. See [issue #41620] for more details.
///
/// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
/// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
Warn,
"floating-point literals cannot be used in patterns",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
};
}
declare_lint! {
/// The `unstable_name_collisions` lint detects that you have used a name
/// that the standard library plans to add in the future.
///
/// ### Example
///
/// ```rust
/// trait MyIterator : Iterator {
/// // is_sorted is an unstable method that already exists on the Iterator trait
/// fn is_sorted(self) -> bool where Self: Sized {true}
/// }
///
/// impl<T: ?Sized> MyIterator for T where T: Iterator { }
///
/// let x = vec![1, 2, 3];
/// let _ = x.iter().is_sorted();
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// When new methods are added to traits in the standard library, they are
/// usually added in an "unstable" form which is only available on the
/// [nightly channel] with a [`feature` attribute]. If there is any
/// pre-existing code which extends a trait to have a method with the same
/// name, then the names will collide. In the future, when the method is
/// stabilized, this will cause an error due to the ambiguity. This lint
/// is an early-warning to let you know that there may be a collision in
/// the future. This can be avoided by adding type annotations to
/// disambiguate which trait method you intend to call, such as
/// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
///
/// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
pub UNSTABLE_NAME_COLLISIONS,
Warn,
"detects name collision with an existing but unstable method",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::Custom(
"once this associated item is added to the standard library, \
the ambiguity may cause an error or change in behavior!"
),
reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
// Note: this item represents future incompatibility of all unstable functions in the
// standard library, and thus should never be removed or changed to an error.
};
}
declare_lint! {
/// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
/// in [`if let`]s, [`while let`]s, and `if let` guards.
///
/// ### Example
///
/// ```rust
/// if let _ = 123 {
/// println!("always runs!");
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// There usually isn't a reason to have an irrefutable pattern in an
/// `if let` or `while let` statement, because the pattern will always match
/// successfully. A [`let`] or [`loop`] statement will suffice. However,
/// when generating code with a macro, forbidding irrefutable patterns
/// would require awkward workarounds in situations where the macro
/// doesn't know if the pattern is refutable or not. This lint allows
/// macros to accept this form, while alerting for a possibly incorrect
/// use in normal code.
///
/// See [RFC 2086] for more details.
///
/// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
/// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
/// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
/// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
/// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
/// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
pub IRREFUTABLE_LET_PATTERNS,
Warn,
"detects irrefutable patterns in `if let` and `while let` statements"
}
declare_lint! {
/// The `unused_labels` lint detects [labels] that are never used.
///
/// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
///
/// ### Example
///
/// ```rust,no_run
/// 'unused_label: loop {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused labels may signal a mistake or unfinished code. To silence the
/// warning for the individual label, prefix it with an underscore such as
/// `'_my_label:`.
pub UNUSED_LABELS,
Warn,
"detects labels that are never used"
}
declare_lint! {
/// The `where_clauses_object_safety` lint detects for [object safety] of
/// [where clauses].
///
/// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
/// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
///
/// ### Example
///
/// ```rust,no_run
/// trait Trait {}
///
/// trait X { fn foo(&self) where Self: Trait; }
///
/// impl X for () { fn foo(&self) {} }
///
/// impl Trait for dyn X {}
///
/// // Segfault at opt-level 0, SIGILL otherwise.
/// pub fn main() { <dyn X as X>::foo(&()); }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler previously allowed these object-unsafe bounds, which was
/// incorrect. This is a [future-incompatible] lint to transition this to
/// a hard error in the future. See [issue #51443] for more details.
///
/// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub WHERE_CLAUSES_OBJECT_SAFETY,
Warn,
"checks the object safety of where clauses",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
};
}
declare_lint! {
/// The `macro_use_extern_crate` lint detects the use of the
/// [`macro_use` attribute].
///
/// ### Example
///
/// ```rust,ignore (needs extern crate)
/// #![deny(macro_use_extern_crate)]
///
/// #[macro_use]
/// extern crate serde_json;
///
/// fn main() {
/// let _ = json!{{}};
/// }
/// ```
///
/// This will produce:
///
/// ```text
/// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
/// --> src/main.rs:3:1
/// |
/// 3 | #[macro_use]
/// | ^^^^^^^^^^^^
/// |
/// note: the lint level is defined here
/// --> src/main.rs:1:9
/// |
/// 1 | #![deny(macro_use_extern_crate)]
/// | ^^^^^^^^^^^^^^^^^^^^^^
/// ```
///
/// ### Explanation
///
/// The [`macro_use` attribute] on an [`extern crate`] item causes
/// macros in that external crate to be brought into the prelude of the
/// crate, making the macros in scope everywhere. As part of the efforts
/// to simplify handling of dependencies in the [2018 edition], the use of
/// `extern crate` is being phased out. To bring macros from extern crates
/// into scope, it is recommended to use a [`use` import].
///
/// This lint is "allow" by default because this is a stylistic choice
/// that has not been settled, see [issue #52043] for more information.
///
/// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
/// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
/// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
pub MACRO_USE_EXTERN_CRATE,
Allow,
"the `#[macro_use]` attribute is now deprecated in favor of using macros \
via the module system"
}
declare_lint! {
/// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
/// detects macro-expanded [`macro_export`] macros from the current crate
/// that cannot be referred to by absolute paths.
///
/// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
///
/// ### Example
///
/// ```rust,compile_fail
/// macro_rules! define_exported {
/// () => {
/// #[macro_export]
/// macro_rules! exported {
/// () => {};
/// }
/// };
/// }
///
/// define_exported!();
///
/// fn main() {
/// crate::exported!();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The intent is that all macros marked with the `#[macro_export]`
/// attribute are made available in the root of the crate. However, when a
/// `macro_rules!` definition is generated by another macro, the macro
/// expansion is unable to uphold this rule. This is a
/// [future-incompatible] lint to transition this to a hard error in the
/// future. See [issue #53495] for more details.
///
/// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
Deny,
"macro-expanded `macro_export` macros from the current crate \
cannot be referred to by absolute paths",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
};
crate_level_only
}
declare_lint! {
/// The `explicit_outlives_requirements` lint detects unnecessary
/// lifetime bounds that can be inferred.
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![allow(unused)]
/// #![deny(explicit_outlives_requirements)]
///
/// struct SharedRef<'a, T>
/// where
/// T: 'a,
/// {
/// data: &'a T,
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// If a `struct` contains a reference, such as `&'a T`, the compiler
/// requires that `T` outlives the lifetime `'a`. This historically
/// required writing an explicit lifetime bound to indicate this
/// requirement. However, this can be overly explicit, causing clutter and
/// unnecessary complexity. The language was changed to automatically
/// infer the bound if it is not specified. Specifically, if the struct
/// contains a reference, directly or indirectly, to `T` with lifetime
/// `'x`, then it will infer that `T: 'x` is a requirement.
///
/// This lint is "allow" by default because it can be noisy for existing
/// code that already had these requirements. This is a stylistic choice,
/// as it is still valid to explicitly state the bound. It also has some
/// false positives that can cause confusion.
///
/// See [RFC 2093] for more details.
///
/// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
pub EXPLICIT_OUTLIVES_REQUIREMENTS,
Allow,
"outlives requirements can be inferred"
}
declare_lint! {
/// The `indirect_structural_match` lint detects a `const` in a pattern
/// that manually implements [`PartialEq`] and [`Eq`].
///
/// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
/// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(indirect_structural_match)]
///
/// struct NoDerive(i32);
/// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
/// impl Eq for NoDerive { }
/// #[derive(PartialEq, Eq)]
/// struct WrapParam<T>(T);
/// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
/// fn main() {
/// match WRAP_INDIRECT_PARAM {
/// WRAP_INDIRECT_PARAM => { }
/// _ => { }
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler unintentionally accepted this form in the past. This is a
/// [future-incompatible] lint to transition this to a hard error in the
/// future. See [issue #62411] for a complete description of the problem,
/// and some possible solutions.
///
/// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub INDIRECT_STRUCTURAL_MATCH,
Warn,
"constant used in pattern contains value of non-structural-match type in a field or a variant",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
};
}
declare_lint! {
/// The `deprecated_in_future` lint is internal to rustc and should not be
/// used by user code.
///
/// This lint is only enabled in the standard library. It works with the
/// use of `#[deprecated]` with a `since` field of a version in the future.
/// This allows something to be marked as deprecated in a future version,
/// and then this lint will ensure that the item is no longer used in the
/// standard library. See the [stability documentation] for more details.
///
/// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
pub DEPRECATED_IN_FUTURE,
Allow,
"detects use of items that will be deprecated in a future version",
report_in_external_macro
}
declare_lint! {
/// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
/// cannot be relied upon across compiler versions and optimization levels.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(pointer_structural_match)]
/// fn foo(a: usize, b: usize) -> usize { a + b }
/// const FOO: fn(usize, usize) -> usize = foo;
/// fn main() {
/// match FOO {
/// FOO => {},
/// _ => {},
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
/// While these work in many cases as expected by users, it is possible that due to
/// optimizations pointers are "not equal to themselves" or pointers to different functions
/// compare as equal during runtime. This is because LLVM optimizations can deduplicate
/// functions if their bodies are the same, thus also making pointers to these functions point
/// to the same location. Additionally functions may get duplicated if they are instantiated
/// in different crates and not deduplicated again via LTO.
pub POINTER_STRUCTURAL_MATCH,
Allow,
"pointers are not structural-match",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
};
}
declare_lint! {
/// The `nontrivial_structural_match` lint detects constants that are used in patterns,
/// whose type is not structural-match and whose initializer body actually uses values
/// that are not structural-match. So `Option<NotStructuralMatch>` is ok if the constant
/// is just `None`.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(nontrivial_structural_match)]
///
/// #[derive(Copy, Clone, Debug)]
/// struct NoDerive(u32);
/// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
/// impl Eq for NoDerive { }
/// fn main() {
/// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
/// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of Rust accepted constants in patterns, even if those constants' types
/// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
/// `PartialEq`, which can report that two constants are not equal even if they are
/// bit-equivalent.
pub NONTRIVIAL_STRUCTURAL_MATCH,
Warn,
"constant used in pattern of non-structural-match type and the constant's initializer \
expression contains values of non-structural-match types",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
};
}
declare_lint! {
/// The `ambiguous_associated_items` lint detects ambiguity between
/// [associated items] and [enum variants].
///
/// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
/// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
///
/// ### Example
///
/// ```rust,compile_fail
/// enum E {
/// V
/// }
///
/// trait Tr {
/// type V;
/// fn foo() -> Self::V;
/// }
///
/// impl Tr for E {
/// type V = u8;
/// // `Self::V` is ambiguous because it may refer to the associated type or
/// // the enum variant.
/// fn foo() -> Self::V { 0 }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous versions of Rust did not allow accessing enum variants
/// through [type aliases]. When this ability was added (see [RFC 2338]), this
/// introduced some situations where it can be ambiguous what a type
/// was referring to.
///
/// To fix this ambiguity, you should use a [qualified path] to explicitly
/// state which type to use. For example, in the above example the
/// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
/// specifically refer to the associated type.
///
/// This is a [future-incompatible] lint to transition this to a hard
/// error in the future. See [issue #57644] for more details.
///
/// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
/// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
/// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
/// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub AMBIGUOUS_ASSOCIATED_ITEMS,
Deny,
"ambiguous associated items",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
};
}
declare_lint! {
/// The `soft_unstable` lint detects unstable features that were
/// unintentionally allowed on stable.
///
/// ### Example
///
/// ```rust,compile_fail
/// #[cfg(test)]
/// extern crate test;
///
/// #[bench]
/// fn name(b: &mut test::Bencher) {
/// b.iter(|| 123)
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The [`bench` attribute] was accidentally allowed to be specified on
/// the [stable release channel]. Turning this to a hard error would have
/// broken some projects. This lint allows those projects to continue to
/// build correctly when [`--cap-lints`] is used, but otherwise signal an
/// error that `#[bench]` should not be used on the stable channel. This
/// is a [future-incompatible] lint to transition this to a hard error in
/// the future. See [issue #64266] for more details.
///
/// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
/// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
/// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
/// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub SOFT_UNSTABLE,
Deny,
"a feature gate that doesn't break dependent crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
};
}
declare_lint! {
/// The `inline_no_sanitize` lint detects incompatible use of
/// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
///
/// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
/// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
///
/// ### Example
///
/// ```rust
/// #![feature(no_sanitize)]
///
/// #[inline(always)]
/// #[no_sanitize(address)]
/// fn x() {}
///
/// fn main() {
/// x()
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The use of the [`#[inline(always)]`][inline] attribute prevents the
/// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
/// Consider temporarily removing `inline` attribute.
pub INLINE_NO_SANITIZE,
Warn,
"detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
}
declare_lint! {
/// The `asm_sub_register` lint detects using only a subset of a register
/// for inline asm inputs.
///
/// ### Example
///
/// ```rust,ignore (fails on non-x86_64)
/// #[cfg(target_arch="x86_64")]
/// use std::arch::asm;
///
/// fn main() {
/// #[cfg(target_arch="x86_64")]
/// unsafe {
/// asm!("mov {0}, {0}", in(reg) 0i16);
/// }
/// }
/// ```
///
/// This will produce:
///
/// ```text
/// warning: formatting may not be suitable for sub-register argument
/// --> src/main.rs:7:19
/// |
/// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
/// | ^^^ ^^^ ---- for this argument
/// |
/// = note: `#[warn(asm_sub_register)]` on by default
/// = help: use the `x` modifier to have the register formatted as `ax`
/// = help: or use the `r` modifier to keep the default formatting of `rax`
/// ```
///
/// ### Explanation
///
/// Registers on some architectures can use different names to refer to a
/// subset of the register. By default, the compiler will use the name for
/// the full register size. To explicitly use a subset of the register,
/// you can override the default by using a modifier on the template
/// string operand to specify when subregister to use. This lint is issued
/// if you pass in a value with a smaller data type than the default
/// register size, to alert you of possibly using the incorrect width. To
/// fix this, add the suggested modifier to the template, or cast the
/// value to the correct size.
///
/// See [register template modifiers] in the reference for more details.
///
/// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
pub ASM_SUB_REGISTER,
Warn,
"using only a subset of a register for inline asm inputs",
}
declare_lint! {
/// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
/// `.att_syntax` directives.
///
/// ### Example
///
/// ```rust,ignore (fails on non-x86_64)
/// #[cfg(target_arch="x86_64")]
/// use std::arch::asm;
///
/// fn main() {
/// #[cfg(target_arch="x86_64")]
/// unsafe {
/// asm!(
/// ".att_syntax",
/// "movq %{0}, %{0}", in(reg) 0usize
/// );
/// }
/// }
/// ```
///
/// This will produce:
///
/// ```text
/// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
/// --> src/main.rs:8:14
/// |
/// 8 | ".att_syntax",
/// | ^^^^^^^^^^^
/// |
/// = note: `#[warn(bad_asm_style)]` on by default
/// ```
///
/// ### Explanation
///
/// On x86, `asm!` uses the intel assembly syntax by default. While this
/// can be switched using assembler directives like `.att_syntax`, using the
/// `att_syntax` option is recommended instead because it will also properly
/// prefix register placeholders with `%` as required by AT&T syntax.
pub BAD_ASM_STYLE,
Warn,
"incorrect use of inline assembly",
}
declare_lint! {
/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
/// functions without an explicit unsafe block.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unsafe_op_in_unsafe_fn)]
///
/// unsafe fn foo() {}
///
/// unsafe fn bar() {
/// foo();
/// }
///
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
/// body. However, this can increase the surface area of code that needs
/// to be scrutinized for proper behavior. The [`unsafe` block] provides a
/// convenient way to make it clear exactly which parts of the code are
/// performing unsafe operations. In the future, it is desired to change
/// it so that unsafe operations cannot be performed in an `unsafe fn`
/// without an `unsafe` block.
///
/// The fix to this is to wrap the unsafe code in an `unsafe` block.
///
/// This lint is "allow" by default since this will affect a large amount
/// of existing code, and the exact plan for increasing the severity is
/// still being considered. See [RFC #2585] and [issue #71668] for more
/// details.
///
/// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
/// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
/// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
/// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
/// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
pub UNSAFE_OP_IN_UNSAFE_FN,
Allow,
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
}
declare_lint! {
/// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
/// `enum` that implements [`Drop`].
///
/// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![allow(unused)]
/// enum E {
/// A,
/// }
///
/// impl Drop for E {
/// fn drop(&mut self) {
/// println!("Drop");
/// }
/// }
///
/// fn main() {
/// let e = E::A;
/// let i = e as u32;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Casting a field-less `enum` that does not implement [`Copy`] to an
/// integer moves the value without calling `drop`. This can result in
/// surprising behavior if it was expected that `drop` should be called.
/// Calling `drop` automatically would be inconsistent with other move
/// operations. Since neither behavior is clear or consistent, it was
/// decided that a cast of this nature will no longer be allowed.
///
/// This is a [future-incompatible] lint to transition this to a hard error
/// in the future. See [issue #73333] for more details.
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
/// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
/// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
pub CENUM_IMPL_DROP_CAST,
Deny,
"a C-like enum implementing Drop is cast",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
declare_lint! {
/// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
/// and a pointer.
///
/// ### Example
///
/// ```rust
/// #![feature(strict_provenance)]
/// #![warn(fuzzy_provenance_casts)]
///
/// fn main() {
/// let _dangling = 16_usize as *const u8;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint is part of the strict provenance effort, see [issue #95228].
/// Casting an integer to a pointer is considered bad style, as a pointer
/// contains, besides the *address* also a *provenance*, indicating what
/// memory the pointer is allowed to read/write. Casting an integer, which
/// doesn't have provenance, to a pointer requires the compiler to assign
/// (guess) provenance. The compiler assigns "all exposed valid" (see the
/// docs of [`ptr::from_exposed_addr`] for more information about this
/// "exposing"). This penalizes the optimiser and is not well suited for
/// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
/// platforms).
///
/// It is much better to use [`ptr::with_addr`] instead to specify the
/// provenance you want. If using this function is not possible because the
/// code relies on exposed provenance then there is as an escape hatch
/// [`ptr::from_exposed_addr`].
///
/// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
/// [`ptr::with_addr`]: https://doc.rust-lang.org/core/ptr/fn.with_addr
/// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr
pub FUZZY_PROVENANCE_CASTS,
Allow,
"a fuzzy integer to pointer cast is used",
@feature_gate = sym::strict_provenance;
}
declare_lint! {
/// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
/// and an integer.
///
/// ### Example
///
/// ```rust
/// #![feature(strict_provenance)]
/// #![warn(lossy_provenance_casts)]
///
/// fn main() {
/// let x: u8 = 37;
/// let _addr: usize = &x as *const u8 as usize;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint is part of the strict provenance effort, see [issue #95228].
/// Casting a pointer to an integer is a lossy operation, because beyond
/// just an *address* a pointer may be associated with a particular
/// *provenance*. This information is used by the optimiser and for dynamic
/// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
///
/// Since this cast is lossy, it is considered good style to use the
/// [`ptr::addr`] method instead, which has a similar effect, but doesn't
/// "expose" the pointer provenance. This improves optimisation potential.
/// See the docs of [`ptr::addr`] and [`ptr::expose_addr`] for more information
/// about exposing pointer provenance.
///
/// If your code can't comply with strict provenance and needs to expose
/// the provenance, then there is [`ptr::expose_addr`] as an escape hatch,
/// which preserves the behaviour of `as usize` casts while being explicit
/// about the semantics.
///
/// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
/// [`ptr::addr`]: https://doc.rust-lang.org/core/ptr/fn.addr
/// [`ptr::expose_addr`]: https://doc.rust-lang.org/core/ptr/fn.expose_addr
pub LOSSY_PROVENANCE_CASTS,
Allow,
"a lossy pointer to integer cast is used",
@feature_gate = sym::strict_provenance;
}
declare_lint! {
/// The `const_evaluatable_unchecked` lint detects a generic constant used
/// in a type.
///
/// ### Example
///
/// ```rust
/// const fn foo<T>() -> usize {
/// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
/// 4
/// } else {
/// 8
/// }
/// }
///
/// fn test<T>() {
/// let _ = [0; foo::<T>()];
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the 1.43 release, some uses of generic parameters in array repeat
/// expressions were accidentally allowed. This is a [future-incompatible]
/// lint to transition this to a hard error in the future. See [issue
/// #76200] for a more detailed description and possible fixes.
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
/// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
pub CONST_EVALUATABLE_UNCHECKED,
Warn,
"detects a generic constant is used in a type without a emitting a warning",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
};
}
declare_lint! {
/// The `function_item_references` lint detects function references that are
/// formatted with [`fmt::Pointer`] or transmuted.
///
/// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
///
/// ### Example
///
/// ```rust
/// fn foo() { }
///
/// fn main() {
/// println!("{:p}", &foo);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Taking a reference to a function may be mistaken as a way to obtain a
/// pointer to that function. This can give unexpected results when
/// formatting the reference as a pointer or transmuting it. This lint is
/// issued when function references are formatted as pointers, passed as
/// arguments bound by [`fmt::Pointer`] or transmuted.
pub FUNCTION_ITEM_REFERENCES,
Warn,
"suggest casting to a function pointer when attempting to take references to function items",
}
declare_lint! {
/// The `uninhabited_static` lint detects uninhabited statics.
///
/// ### Example
///
/// ```rust
/// enum Void {}
/// extern {
/// static EXTERN: Void;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Statics with an uninhabited type can never be initialized, so they are impossible to define.
/// However, this can be side-stepped with an `extern static`, leading to problems later in the
/// compiler which assumes that there are no initialized uninhabited places (such as locals or
/// statics). This was accidentally allowed, but is being phased out.
pub UNINHABITED_STATIC,
Warn,
"uninhabited static",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
};
}
declare_lint! {
/// The `useless_deprecated` lint detects deprecation attributes with no effect.
///
/// ### Example
///
/// ```rust,compile_fail
/// struct X;
///
/// #[deprecated = "message"]
/// impl Default for X {
/// fn default() -> Self {
/// X
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Deprecation attributes have no effect on trait implementations.
pub USELESS_DEPRECATED,
Deny,
"detects deprecation attributes with no effect",
}
declare_lint! {
/// The `undefined_naked_function_abi` lint detects naked function definitions that
/// either do not specify an ABI or specify the Rust ABI.
///
/// ### Example
///
/// ```rust
/// #![feature(asm_experimental_arch, naked_functions)]
///
/// use std::arch::asm;
///
/// #[naked]
/// pub fn default_abi() -> u32 {
/// unsafe { asm!("", options(noreturn)); }
/// }
///
/// #[naked]
/// pub extern "Rust" fn rust_abi() -> u32 {
/// unsafe { asm!("", options(noreturn)); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The Rust ABI is currently undefined. Therefore, naked functions should
/// specify a non-Rust ABI.
pub UNDEFINED_NAKED_FUNCTION_ABI,
Warn,
"undefined naked function ABI"
}
declare_lint! {
/// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![feature(staged_api)]
///
/// #[derive(Clone)]
/// #[stable(feature = "x", since = "1")]
/// struct S {}
///
/// #[unstable(feature = "y", issue = "none")]
/// impl Copy for S {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// `staged_api` does not currently support using a stability attribute on `impl` blocks.
/// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
Deny,
"detects `#[unstable]` on stable trait implementations for stable types"
}
declare_lint! {
/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
/// in macro bodies when the macro is invoked in expression position.
/// This was previous accepted, but is being phased out.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(semicolon_in_expressions_from_macros)]
/// macro_rules! foo {
/// () => { true; }
/// }
///
/// fn main() {
/// let val = match true {
/// true => false,
/// _ => foo!()
/// };
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previous, Rust ignored trailing semicolon in a macro
/// body when a macro was invoked in expression position.
/// However, this makes the treatment of semicolons in the language
/// inconsistent, and could lead to unexpected runtime behavior
/// in some circumstances (e.g. if the macro author expects
/// a value to be dropped).
///
/// This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #79813] for more details.
///
/// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
Warn,
"trailing semicolon in macro body used as expression",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
};
}
declare_lint! {
/// The `legacy_derive_helpers` lint detects derive helper attributes
/// that are used before they are introduced.
///
/// ### Example
///
/// ```rust,ignore (needs extern crate)
/// #[serde(rename_all = "camelCase")]
/// #[derive(Deserialize)]
/// struct S { /* fields */ }
/// ```
///
/// produces:
///
/// ```text
/// warning: derive helper attribute is used before it is introduced
/// --> $DIR/legacy-derive-helpers.rs:1:3
/// |
/// 1 | #[serde(rename_all = "camelCase")]
/// | ^^^^^
/// ...
/// 2 | #[derive(Deserialize)]
/// | ----------- the attribute is introduced here
/// ```
///
/// ### Explanation
///
/// Attributes like this work for historical reasons, but attribute expansion works in
/// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
/// into the future" at not yet expanded part of the item , but such attempts are not always
/// reliable.
///
/// To fix the warning place the helper attribute after its corresponding derive.
/// ```rust,ignore (needs extern crate)
/// #[derive(Deserialize)]
/// #[serde(rename_all = "camelCase")]
/// struct S { /* fields */ }
/// ```
pub LEGACY_DERIVE_HELPERS,
Warn,
"detects derive helper attributes that are used before they are introduced",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
};
}
declare_lint! {
/// The `large_assignments` lint detects when objects of large
/// types are being moved around.
///
/// ### Example
///
/// ```rust,ignore (can crash on some platforms)
/// let x = [0; 50000];
/// let y = x;
/// ```
///
/// produces:
///
/// ```text
/// warning: moving a large value
/// --> $DIR/move-large.rs:1:3
/// let y = x;
/// - Copied large value here
/// ```
///
/// ### Explanation
///
/// When using a large type in a plain assignment or in a function
/// argument, idiomatic code can be inefficient.
/// Ideally appropriate optimizations would resolve this, but such
/// optimizations are only done in a best-effort manner.
/// This lint will trigger on all sites of large moves and thus allow the
/// user to resolve them in code.
pub LARGE_ASSIGNMENTS,
Warn,
"detects large moves or copies",
}
declare_lint! {
/// The `deprecated_cfg_attr_crate_type_name` lint detects uses of the
/// `#![cfg_attr(..., crate_type = "...")]` and
/// `#![cfg_attr(..., crate_name = "...")]` attributes to conditionally
/// specify the crate type and name in the source code.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![cfg_attr(debug_assertions, crate_type = "lib")]
/// ```
///
/// {{produces}}
///
///
/// ### Explanation
///
/// The `#![crate_type]` and `#![crate_name]` attributes require a hack in
/// the compiler to be able to change the used crate type and crate name
/// after macros have been expanded. Neither attribute works in combination
/// with Cargo as it explicitly passes `--crate-type` and `--crate-name` on
/// the commandline. These values must match the value used in the source
/// code to prevent an error.
///
/// To fix the warning use `--crate-type` on the commandline when running
/// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
/// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
Deny,
"detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",
};
}
declare_lint! {
/// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
///
/// ### Example
///
/// ```text
/// rustc --check-cfg 'names()'
/// ```
///
/// ```rust,ignore (needs command line option)
/// #[cfg(widnows)]
/// fn foo() {}
/// ```
///
/// This will produce:
///
/// ```text
/// warning: unknown condition name used
/// --> lint_example.rs:1:7
/// |
/// 1 | #[cfg(widnows)]
/// | ^^^^^^^
/// |
/// = note: `#[warn(unexpected_cfgs)]` on by default
/// ```
///
/// ### Explanation
///
/// This lint is only active when a `--check-cfg='names(...)'` option has been passed
/// to the compiler and triggers whenever an unknown condition name or value is used.
/// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
/// well-knows names and values built into the compiler.
pub UNEXPECTED_CFGS,
Warn,
"detects unexpected names and values in `#[cfg]` conditions",
}
declare_lint! {
/// The `repr_transparent_external_private_fields` lint
/// detects types marked `#[repr(transparent)]` that (transitively)
/// contain an external ZST type marked `#[non_exhaustive]` or containing
/// private fields
///
/// ### Example
///
/// ```rust,ignore (needs external crate)
/// #![deny(repr_transparent_external_private_fields)]
/// use foo::NonExhaustiveZst;
///
/// #[repr(transparent)]
/// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
/// ```
///
/// This will produce:
///
/// ```text
/// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
/// --> src/main.rs:5:28
/// |
/// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
/// | ^^^^^^^^^^^^^^^^
/// |
/// note: the lint level is defined here
/// --> src/main.rs:1:9
/// |
/// 1 | #![deny(repr_transparent_external_private_fields)]
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
/// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
/// = note: this struct contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
/// ```
///
/// ### Explanation
///
/// Previous, Rust accepted fields that contain external private zero-sized types,
/// even though it should not be a breaking change to add a non-zero-sized field to
/// that private type.
///
/// This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #78586] for more details.
///
/// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
Warn,
"transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
};
}
declare_lint! {
/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
/// syntax that is discarded during attribute expansion.
///
/// ### Example
///
/// ```rust
/// #[cfg(FALSE)]
/// macro foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The input to active attributes such as `#[cfg]` or procedural macro
/// attributes is required to be valid syntax. Previously, the compiler only
/// gated the use of unstable syntax features after resolving `#[cfg]` gates
/// and expanding procedural macros.
///
/// To avoid relying on unstable syntax, move the use of unstable syntax
/// into a position where the compiler does not parse the syntax, such as a
/// functionlike macro.
///
/// ```rust
/// # #![deny(unstable_syntax_pre_expansion)]
///
/// macro_rules! identity {
/// ( $($tokens:tt)* ) => { $($tokens)* }
/// }
///
/// #[cfg(FALSE)]
/// identity! {
/// macro foo() {}
/// }
/// ```
///
/// This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #65860] for more details.
///
/// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub UNSTABLE_SYNTAX_PRE_EXPANSION,
Warn,
"unstable syntax can change at any point in the future, causing a hard error!",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
};
}
declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
HardwiredLints => [
FORBIDDEN_LINT_GROUPS,
ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
ARITHMETIC_OVERFLOW,
UNCONDITIONAL_PANIC,
UNUSED_IMPORTS,
UNUSED_EXTERN_CRATES,
UNUSED_CRATE_DEPENDENCIES,
UNUSED_QUALIFICATIONS,
UNKNOWN_LINTS,
UNFULFILLED_LINT_EXPECTATIONS,
UNUSED_VARIABLES,
UNUSED_ASSIGNMENTS,
DEAD_CODE,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
OVERLAPPING_RANGE_ENDPOINTS,
BINDINGS_WITH_VARIANT_NAME,
UNUSED_MACROS,
UNUSED_MACRO_RULES,
WARNINGS,
UNUSED_FEATURES,
STABLE_FEATURES,
UNKNOWN_CRATE_TYPES,
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
PRIVATE_IN_PUBLIC,
EXPORTED_PRIVATE_DEPENDENCIES,
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
INVALID_TYPE_PARAM_DEFAULT,
RENAMED_AND_REMOVED_LINTS,
UNALIGNED_REFERENCES,
CONST_ITEM_MUTATION,
PATTERNS_IN_FNS_WITHOUT_BODY,
MISSING_FRAGMENT_SPECIFIER,
LATE_BOUND_LIFETIME_ARGUMENTS,
ORDER_DEPENDENT_TRAIT_OBJECTS,
COHERENCE_LEAK_CHECK,
DEPRECATED,
UNUSED_UNSAFE,
UNUSED_MUT,
UNCONDITIONAL_RECURSION,
SINGLE_USE_LIFETIMES,
UNUSED_LIFETIMES,
UNUSED_LABELS,
TYVAR_BEHIND_RAW_POINTER,
ELIDED_LIFETIMES_IN_PATHS,
BARE_TRAIT_OBJECTS,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
UNSTABLE_NAME_COLLISIONS,
IRREFUTABLE_LET_PATTERNS,
WHERE_CLAUSES_OBJECT_SAFETY,
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
ILL_FORMED_ATTRIBUTE_INPUT,
CONFLICTING_REPR_HINTS,
META_VARIABLE_MISUSE,
DEPRECATED_IN_FUTURE,
AMBIGUOUS_ASSOCIATED_ITEMS,
INDIRECT_STRUCTURAL_MATCH,
POINTER_STRUCTURAL_MATCH,
NONTRIVIAL_STRUCTURAL_MATCH,
SOFT_UNSTABLE,
UNSTABLE_SYNTAX_PRE_EXPANSION,
INLINE_NO_SANITIZE,
BAD_ASM_STYLE,
ASM_SUB_REGISTER,
UNSAFE_OP_IN_UNSAFE_FN,
INCOMPLETE_INCLUDE,
CENUM_IMPL_DROP_CAST,
FUZZY_PROVENANCE_CASTS,
LOSSY_PROVENANCE_CASTS,
CONST_EVALUATABLE_UNCHECKED,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
MUST_NOT_SUSPEND,
UNINHABITED_STATIC,
FUNCTION_ITEM_REFERENCES,
USELESS_DEPRECATED,
MISSING_ABI,
INVALID_DOC_ATTRIBUTES,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
LEGACY_DERIVE_HELPERS,
PROC_MACRO_BACK_COMPAT,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
LARGE_ASSIGNMENTS,
RUST_2021_PRELUDE_COLLISIONS,
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
UNSUPPORTED_CALLING_CONVENTIONS,
BREAK_WITH_LABEL_AND_LOOP,
UNUSED_ATTRIBUTES,
UNUSED_TUPLE_STRUCT_FIELDS,
NON_EXHAUSTIVE_OMITTED_PATTERNS,
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
DUPLICATE_MACRO_ATTRIBUTES,
SUSPICIOUS_AUTO_TRAIT_IMPLS,
DEPRECATED_WHERE_CLAUSE_LOCATION,
TEST_UNSTABLE_LINT,
FFI_UNWIND_CALLS,
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
NAMED_ARGUMENTS_USED_POSITIONALLY,
]
}
declare_lint! {
/// The `unused_doc_comments` lint detects doc comments that aren't used
/// by `rustdoc`.
///
/// ### Example
///
/// ```rust
/// /// docs for x
/// let x = 12;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// `rustdoc` does not use doc comments in all positions, and so the doc
/// comment will be ignored. Try changing it to a normal comment with `//`
/// to avoid the warning.
pub UNUSED_DOC_COMMENTS,
Warn,
"detects doc comments that aren't used by rustdoc"
}
declare_lint! {
/// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
/// captured in Rust 2021, such that the `Drop` order of their fields may differ between
/// Rust 2018 and 2021.
///
/// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
/// and the field is captured by a closure and used with the assumption that said field implements
/// the same trait as the root variable.
///
/// ### Example of drop reorder
///
/// ```rust,edition2018,compile_fail
/// #![deny(rust_2021_incompatible_closure_captures)]
/// # #![allow(unused)]
///
/// struct FancyInteger(i32);
///
/// impl Drop for FancyInteger {
/// fn drop(&mut self) {
/// println!("Just dropped {}", self.0);
/// }
/// }
///
/// struct Point { x: FancyInteger, y: FancyInteger }
///
/// fn main() {
/// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
///
/// let c = || {
/// let x = p.x;
/// };
///
/// c();
///
/// // ... More code ...
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the above example, `p.y` will be dropped at the end of `f` instead of
/// with `c` in Rust 2021.
///
/// ### Example of auto-trait
///
/// ```rust,edition2018,compile_fail
/// #![deny(rust_2021_incompatible_closure_captures)]
/// use std::thread;
///
/// struct Pointer(*mut i32);
/// unsafe impl Send for Pointer {}
///
/// fn main() {
/// let mut f = 10;
/// let fptr = Pointer(&mut f as *mut i32);
/// thread::spawn(move || unsafe {
/// *fptr.0 = 20;
/// });
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the above example, only `fptr.0` is captured in Rust 2021.
/// The field is of type `*mut i32`, which doesn't implement `Send`,
/// making the code invalid as the field cannot be sent between threads safely.
pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
Allow,
"detects closures affected by Rust 2021 changes",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
explain_reason: false,
};
}
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
declare_lint! {
/// The `missing_abi` lint detects cases where the ABI is omitted from
/// extern declarations.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(missing_abi)]
///
/// extern fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Historically, Rust implicitly selected C as the ABI for extern
/// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
/// though this has not yet happened, and especially with their addition
/// seeing the ABI easily will make code review easier.
pub MISSING_ABI,
Allow,
"No declared ABI for extern declaration"
}
declare_lint! {
/// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
/// misused.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(warnings)]
///
/// pub mod submodule {
/// #![doc(test(no_crate_inject))]
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previously, there were very like checks being performed on `#[doc(..)]`
/// unlike the other attributes. It'll now catch all the issues that it
/// silently ignored previously.
pub INVALID_DOC_ATTRIBUTES,
Warn,
"detects invalid `#[doc(...)]` attributes",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
};
}
declare_lint! {
/// The `proc_macro_back_compat` lint detects uses of old versions of certain
/// proc-macro crates, which have hardcoded workarounds in the compiler.
///
/// ### Example
///
/// ```rust,ignore (needs-dependency)
///
/// use time_macros_impl::impl_macros;
/// struct Foo;
/// impl_macros!(Foo);
/// ```
///
/// This will produce:
///
/// ```text
/// warning: using an old version of `time-macros-impl`
/// ::: $DIR/group-compat-hack.rs:27:5
/// |
/// LL | impl_macros!(Foo);
/// | ------------------ in this macro invocation
/// |
/// = note: `#[warn(proc_macro_back_compat)]` on by default
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
/// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
/// = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
/// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
/// ```
///
/// ### Explanation
///
/// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
/// causing older versions of certain crates to stop compiling.
/// This is a [future-incompatible] lint to ease the transition to an error.
/// See [issue #83125] for more details.
///
/// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PROC_MACRO_BACK_COMPAT,
Deny,
"detects usage of old versions of certain proc-macro crates",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}
declare_lint! {
/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(rust_2021_incompatible_or_patterns)]
///
/// macro_rules! match_any {
/// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
/// match $expr {
/// $(
/// $( $pat => $expr_arm, )+
/// )+
/// }
/// };
/// }
///
/// fn main() {
/// let result: Result<i64, i32> = Err(42);
/// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
/// assert_eq!(int, 42);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
Allow,
"detects usage of old versions of or-patterns",
@future_incompatible = FutureIncompatibleInfo {
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
};
}
declare_lint! {
/// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
/// with traits added to the prelude in future editions.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(rust_2021_prelude_collisions)]
///
/// trait Foo {
/// fn try_into(self) -> Result<String, !>;
/// }
///
/// impl Foo for &str {
/// fn try_into(self) -> Result<String, !> {
/// Ok(String::from(self))
/// }
/// }
///
/// fn main() {
/// let x: String = "3".try_into().unwrap();
/// // ^^^^^^^^
/// // This call to try_into matches both Foo:try_into and TryInto::try_into as
/// // `TryInto` has been added to the Rust prelude in 2021 edition.
/// println!("{x}");
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In Rust 2021, one of the important introductions is the [prelude changes], which add
/// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
/// results in an ambiguity as to which method/function to call when an existing `try_into`
/// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
/// is called directly on a type.
///
/// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
pub RUST_2021_PRELUDE_COLLISIONS,
Allow,
"detects the usage of trait methods which are ambiguous with traits added to the \
prelude in future editions",
@future_incompatible = FutureIncompatibleInfo {
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
};
}
declare_lint! {
/// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
/// prefix instead in Rust 2021.
///
/// ### Example
///
/// ```rust,edition2018,compile_fail
/// #![deny(rust_2021_prefixes_incompatible_syntax)]
///
/// macro_rules! m {
/// (z $x:expr) => ();
/// }
///
/// m!(z"hey");
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
/// followed by the string literal `"hey"`. In Rust 2021, the `z` is
/// considered a prefix for `"hey"`.
///
/// This lint suggests to add whitespace between the `z` and `"hey"` tokens
/// to keep them separated in Rust 2021.
// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
#[allow(rustdoc::invalid_rust_codeblocks)]
pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
Allow,
"identifiers that will be parsed as a prefix in Rust 2021",
@future_incompatible = FutureIncompatibleInfo {
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>",
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
};
crate_level_only
}
declare_lint! {
/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
/// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
/// variants) on targets that cannot meaningfully be supported for the requested target.
///
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
/// code, because this calling convention was never specified for those targets.
///
/// Historically MSVC toolchains have fallen back to the regular C calling convention for
/// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
/// hack across many more targets.
///
/// ### Example
///
/// ```rust,ignore (needs specific targets)
/// extern "stdcall" fn stdcall() {}
/// ```
///
/// This will produce:
///
/// ```text
/// warning: use of calling convention not supported on this target
/// --> $DIR/unsupported.rs:39:1
/// |
/// LL | extern "stdcall" fn stdcall() {}
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/// |
/// = note: `#[warn(unsupported_calling_conventions)]` on by default
/// = warning: this was previously accepted by the compiler but is being phased out;
/// it will become a hard error in a future release!
/// = note: for more information, see issue ...
/// ```
///
/// ### Explanation
///
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
/// defined at all, but was previously accepted due to a bug in the implementation of the
/// compiler.
pub UNSUPPORTED_CALLING_CONVENTIONS,
Warn,
"use of unsupported calling convention",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
};
}
declare_lint! {
/// The `break_with_label_and_loop` lint detects labeled `break` expressions with
/// an unlabeled loop as their value expression.
///
/// ### Example
///
/// ```rust
/// 'label: loop {
/// break 'label loop { break 42; };
/// };
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In Rust, loops can have a label, and `break` expressions can refer to that label to
/// break out of specific loops (and not necessarily the innermost one). `break` expressions
/// can also carry a value expression, which can be another loop. A labeled `break` with an
/// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
/// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
/// around the loop expression to silence this warning. Unlabeled `break` expressions with
/// labeled loops yield a hard error, which can also be silenced by wrapping the expression
/// in parentheses.
pub BREAK_WITH_LABEL_AND_LOOP,
Warn,
"`break` expression with label and unlabeled loop as value expression"
}
declare_lint! {
/// The `non_exhaustive_omitted_patterns` lint detects when a wildcard (`_` or `..`) in a
/// pattern for a `#[non_exhaustive]` struct or enum is reachable.
///
/// ### Example
///
/// ```rust,ignore (needs separate crate)
/// // crate A
/// #[non_exhaustive]
/// pub enum Bar {
/// A,
/// B, // added variant in non breaking change
/// }
///
/// // in crate B
/// #![feature(non_exhaustive_omitted_patterns_lint)]
///
/// match Bar::A {
/// Bar::A => {},
/// #[warn(non_exhaustive_omitted_patterns)]
/// _ => {},
/// }
/// ```
///
/// This will produce:
///
/// ```text
/// warning: reachable patterns not covered of non exhaustive enum
/// --> $DIR/reachable-patterns.rs:70:9
/// |
/// LL | _ => {}
/// | ^ pattern `B` not covered
/// |
/// note: the lint level is defined here
/// --> $DIR/reachable-patterns.rs:69:16
/// |
/// LL | #[warn(non_exhaustive_omitted_patterns)]
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/// = help: ensure that all possible cases are being handled by adding the suggested match arms
/// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
/// ```
///
/// ### Explanation
///
/// Structs and enums tagged with `#[non_exhaustive]` force the user to add a
/// (potentially redundant) wildcard when pattern-matching, to allow for future
/// addition of fields or variants. The `non_exhaustive_omitted_patterns` lint
/// detects when such a wildcard happens to actually catch some fields/variants.
/// In other words, when the match without the wildcard would not be exhaustive.
/// This lets the user be informed if new fields/variants were added.
pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
Allow,
"detect when patterns of types marked `non_exhaustive` are missed",
@feature_gate = sym::non_exhaustive_omitted_patterns_lint;
}
declare_lint! {
/// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
/// change the visual representation of text on screen in a way that does not correspond to
/// their on memory representation.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(text_direction_codepoint_in_comment)]
/// fn main() {
/// println!("{:?}"); // '');
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unicode allows changing the visual flow of text on screen in order to support scripts that
/// are written right-to-left, but a specially crafted comment can make code that will be
/// compiled appear to be part of a comment, depending on the software used to read the code.
/// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
/// their use.
pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
Deny,
"invisible directionality-changing codepoints in comment"
}
declare_lint! {
/// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
/// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
/// and `test_case`.
///
/// ### Example
///
/// ```rust,ignore (needs --test)
/// #[test]
/// #[test]
/// fn foo() {}
/// ```
///
/// This will produce:
///
/// ```text
/// warning: duplicated attribute
/// --> src/lib.rs:2:1
/// |
/// 2 | #[test]
/// | ^^^^^^^
/// |
/// = note: `#[warn(duplicate_macro_attributes)]` on by default
/// ```
///
/// ### Explanation
///
/// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
/// being duplicated may not be obvious or desirable.
///
/// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
/// change to its environment.
///
/// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
pub DUPLICATE_MACRO_ATTRIBUTES,
Warn,
"duplicated attribute"
}
declare_lint! {
/// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
/// implementations of auto traits.
///
/// ### Example
///
/// ```rust
/// struct Foo<T>(T);
///
/// unsafe impl<T> Send for Foo<*const T> {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
/// in two different ways: either by writing an explicit impl or if
/// all fields of the type implement that auto trait.
///
/// The compiler disables the automatic implementation if an explicit one
/// exists for given type constructor. The exact rules governing this
/// are currently unsound, quite subtle, and will be modified in the future.
/// This change will cause the automatic implementation to be disabled in more
/// cases, potentially breaking some code.
pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
Warn,
"the rules governing auto traits will change in the future",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
};
}
declare_lint! {
/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
/// in an associated type.
///
/// ### Example
///
/// ```rust
/// trait Trait {
/// type Assoc<'a> where Self: 'a;
/// }
///
/// impl Trait for () {
/// type Assoc<'a> where Self: 'a = ();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The preferred location for where clauses on associated types in impls
/// is after the type. However, for most of generic associated types development,
/// it was only accepted before the equals. To provide a transition period and
/// further evaluate this change, both are currently accepted. At some point in
/// the future, this may be disallowed at an edition boundary; but, that is
/// undecided currently.
pub DEPRECATED_WHERE_CLAUSE_LOCATION,
Warn,
"deprecated where clause location"
}
declare_lint! {
/// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
///
/// ### Example
///
/// ```rust
/// #![allow(test_unstable_lint)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In order to test the behavior of unstable lints, a permanently-unstable
/// lint is required. This lint can be used to trigger warnings and errors
/// from the compiler related to unstable lints.
pub TEST_UNSTABLE_LINT,
Deny,
"this unstable lint is only for testing",
@feature_gate = sym::test_unstable_lint;
}
declare_lint! {
/// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
/// `C-unwind` or other FFI-unwind ABIs.
///
/// ### Example
///
/// ```rust,ignore (need FFI)
/// #![feature(ffi_unwind_calls)]
/// #![feature(c_unwind)]
///
/// # mod impl {
/// # #[no_mangle]
/// # pub fn "C-unwind" fn foo() {}
/// # }
///
/// extern "C-unwind" {
/// fn foo();
/// }
///
/// fn bar() {
/// unsafe { foo(); }
/// let ptr: unsafe extern "C-unwind" fn() = foo;
/// unsafe { ptr(); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
/// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
/// that desire this ability it is therefore necessary to avoid such calls.
pub FFI_UNWIND_CALLS,
Allow,
"call to foreign functions or function pointers with FFI-unwind ABI",
@feature_gate = sym::c_unwind;
}
declare_lint! {
/// The `named_arguments_used_positionally` lint detects cases where named arguments are only
/// used positionally in format strings. This usage is valid but potentially very confusing.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(named_arguments_used_positionally)]
/// fn main() {
/// let _x = 5;
/// println!("{}", _x = 1); // Prints 1, will trigger lint
///
/// println!("{}", _x); // Prints 5, no lint emitted
/// println!("{_x}", _x = _x); // Prints 5, no lint emitted
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Rust formatting strings can refer to named arguments by their position, but this usage is
/// potentially confusing. In particular, readers can incorrectly assume that the declaration
/// of named arguments is an assignment (which would produce the unit type).
/// For backwards compatibility, this is not a hard error.
pub NAMED_ARGUMENTS_USED_POSITIONALLY,
Warn,
"named arguments in format used positionally"
}