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
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
|
//! Generated file, do not edit by hand, see `xtask/src/codegen`
use crate::completions::attribute::LintCompletion;
pub(super) const FEATURES: &[LintCompletion] = &[
LintCompletion {
label: "plugin_registrar",
description: r##"# `plugin_registrar`
The tracking issue for this feature is: [#29597]
[#29597]: https://github.com/rust-lang/rust/issues/29597
This feature is part of "compiler plugins." It will often be used with the
[`plugin`] and `rustc_private` features as well. For more details, see
their docs.
[`plugin`]: plugin.md
------------------------
"##,
},
LintCompletion {
label: "inline_const",
description: r##"# `inline_const`
The tracking issue for this feature is: [#76001]
------
This feature allows you to use inline constant expressions. For example, you can
turn this code:
```rust
# fn add_one(x: i32) -> i32 { x + 1 }
const MY_COMPUTATION: i32 = 1 + 2 * 3 / 4;
fn main() {
let x = add_one(MY_COMPUTATION);
}
```
into this code:
```rust
#![feature(inline_const)]
# fn add_one(x: i32) -> i32 { x + 1 }
fn main() {
let x = add_one(const { 1 + 2 * 3 / 4 });
}
```
You can also use inline constant expressions in patterns:
```rust
#![feature(inline_const)]
const fn one() -> i32 { 1 }
let some_int = 3;
match some_int {
const { 1 + 2 } => println!("Matched 1 + 2"),
const { one() } => println!("Matched const fn returning 1"),
_ => println!("Didn't match anything :("),
}
```
[#76001]: https://github.com/rust-lang/rust/issues/76001
"##,
},
LintCompletion {
label: "auto_traits",
description: r##"# `auto_traits`
The tracking issue for this feature is [#13231]
[#13231]: https://github.com/rust-lang/rust/issues/13231
----
The `auto_traits` feature gate allows you to define auto traits.
Auto traits, like [`Send`] or [`Sync`] in the standard library, are marker traits
that are automatically implemented for every type, unless the type, or a type it contains,
has explicitly opted out via a negative impl. (Negative impls are separately controlled
by the `negative_impls` feature.)
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
```rust,ignore (partial-example)
impl !Trait for Type {}
```
Example:
```rust
#![feature(negative_impls)]
#![feature(auto_traits)]
auto trait Valid {}
struct True;
struct False;
impl !Valid for False {}
struct MaybeValid<T>(T);
fn must_be_valid<T: Valid>(_t: T) { }
fn main() {
// works
must_be_valid( MaybeValid(True) );
// compiler error - trait bound not satisfied
// must_be_valid( MaybeValid(False) );
}
```
## Automatic trait implementations
When a type is declared as an `auto trait`, we will automatically
create impls for every struct/enum/union, unless an explicit impl is
provided. These automatic impls contain a where clause for each field
of the form `T: AutoTrait`, where `T` is the type of the field and
`AutoTrait` is the auto trait in question. As an example, consider the
struct `List` and the auto trait `Send`:
```rust
struct List<T> {
data: T,
next: Option<Box<List<T>>>,
}
```
Presuming that there is no explicit impl of `Send` for `List`, the
compiler will supply an automatic impl of the form:
```rust
struct List<T> {
data: T,
next: Option<Box<List<T>>>,
}
unsafe impl<T> Send for List<T>
where
T: Send, // from the field `data`
Option<Box<List<T>>>: Send, // from the field `next`
{ }
```
Explicit impls may be either positive or negative. They take the form:
```rust,ignore (partial-example)
impl<...> AutoTrait for StructName<..> { }
impl<...> !AutoTrait for StructName<..> { }
```
## Coinduction: Auto traits permit cyclic matching
Unlike ordinary trait matching, auto traits are **coinductive**. This
means, in short, that cycles which occur in trait matching are
considered ok. As an example, consider the recursive struct `List`
introduced in the previous section. In attempting to determine whether
`List: Send`, we would wind up in a cycle: to apply the impl, we must
show that `Option<Box<List>>: Send`, which will in turn require
`Box<List>: Send` and then finally `List: Send` again. Under ordinary
trait matching, this cycle would be an error, but for an auto trait it
is considered a successful match.
## Items
Auto traits cannot have any trait items, such as methods or associated types. This ensures that we can generate default implementations.
## Supertraits
Auto traits cannot have supertraits. This is for soundness reasons, as the interaction of coinduction with implied bounds is difficult to reconcile.
"##,
},
LintCompletion {
label: "ffi_const",
description: r##"# `ffi_const`
The tracking issue for this feature is: [#58328]
------
The `#[ffi_const]` attribute applies clang's `const` attribute to foreign
functions declarations.
That is, `#[ffi_const]` functions shall have no effects except for its return
value, which can only depend on the values of the function parameters, and is
not affected by changes to the observable state of the program.
Applying the `#[ffi_const]` attribute to a function that violates these
requirements is undefined behaviour.
This attribute enables Rust to perform common optimizations, like sub-expression
elimination, and it can avoid emitting some calls in repeated invocations of the
function with the same argument values regardless of other operations being
performed in between these functions calls (as opposed to `#[ffi_pure]`
functions).
## Pitfalls
A `#[ffi_const]` function can only read global memory that would not affect
its return value for the whole execution of the program (e.g. immutable global
memory). `#[ffi_const]` functions are referentially-transparent and therefore
more strict than `#[ffi_pure]` functions.
A common pitfall involves applying the `#[ffi_const]` attribute to a
function that reads memory through pointer arguments which do not necessarily
point to immutable global memory.
A `#[ffi_const]` function that returns unit has no effect on the abstract
machine's state, and a `#[ffi_const]` function cannot be `#[ffi_pure]`.
A `#[ffi_const]` function must not diverge, neither via a side effect (e.g. a
call to `abort`) nor by infinite loops.
When translating C headers to Rust FFI, it is worth verifying for which targets
the `const` attribute is enabled in those headers, and using the appropriate
`cfg` macros in the Rust side to match those definitions. While the semantics of
`const` are implemented identically by many C and C++ compilers, e.g., clang,
[GCC], [ARM C/C++ compiler], [IBM ILE C/C++], etc. they are not necessarily
implemented in this way on all of them. It is therefore also worth verifying
that the semantics of the C toolchain used to compile the binary being linked
against are compatible with those of the `#[ffi_const]`.
[#58328]: https://github.com/rust-lang/rust/issues/58328
[ARM C/C++ compiler]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/Cacgigch.html
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-const-function-attribute
[IBM ILE C/C++]: https://www.ibm.com/support/knowledgecenter/fr/ssw_ibm_i_71/rzarg/fn_attrib_const.htm
"##,
},
LintCompletion {
label: "external_doc",
description: r##"# `external_doc`
The tracking issue for this feature is: [#44732]
The `external_doc` feature allows the use of the `include` parameter to the `#[doc]` attribute, to
include external files in documentation. Use the attribute in place of, or in addition to, regular
doc comments and `#[doc]` attributes, and `rustdoc` will load the given file when it renders
documentation for your crate.
With the following files in the same directory:
`external-doc.md`:
```markdown
# My Awesome Type
This is the documentation for this spectacular type.
```
`lib.rs`:
```no_run (needs-external-files)
#![feature(external_doc)]
#[doc(include = "external-doc.md")]
pub struct MyAwesomeType;
```
`rustdoc` will load the file `external-doc.md` and use it as the documentation for the `MyAwesomeType`
struct.
When locating files, `rustdoc` will base paths in the `src/` directory, as if they were alongside the
`lib.rs` for your crate. So if you want a `docs/` folder to live alongside the `src/` directory,
start your paths with `../docs/` for `rustdoc` to properly find the file.
This feature was proposed in [RFC #1990] and initially implemented in PR [#44781].
[#44732]: https://github.com/rust-lang/rust/issues/44732
[RFC #1990]: https://github.com/rust-lang/rfcs/pull/1990
[#44781]: https://github.com/rust-lang/rust/pull/44781
"##,
},
LintCompletion {
label: "box_patterns",
description: r##"# `box_patterns`
The tracking issue for this feature is: [#29641]
[#29641]: https://github.com/rust-lang/rust/issues/29641
See also [`box_syntax`](box-syntax.md)
------------------------
Box patterns let you match on `Box<T>`s:
```rust
#![feature(box_patterns)]
fn main() {
let b = Some(Box::new(5));
match b {
Some(box n) if n < 0 => {
println!("Box contains negative number {}", n);
},
Some(box n) if n >= 0 => {
println!("Box contains non-negative number {}", n);
},
None => {
println!("No box");
},
_ => unreachable!()
}
}
```
"##,
},
LintCompletion {
label: "abi_c_cmse_nonsecure_call",
description: r##"# `abi_c_cmse_nonsecure_call`
The tracking issue for this feature is: [#81391]
[#81391]: https://github.com/rust-lang/rust/issues/81391
------------------------
The [TrustZone-M
feature](https://developer.arm.com/documentation/100690/latest/) is available
for targets with the Armv8-M architecture profile (`thumbv8m` in their target
name).
LLVM, the Rust compiler and the linker are providing
[support](https://developer.arm.com/documentation/ecm0359818/latest/) for the
TrustZone-M feature.
One of the things provided, with this unstable feature, is the
`C-cmse-nonsecure-call` function ABI. This ABI is used on function pointers to
non-secure code to mark a non-secure function call (see [section
5.5](https://developer.arm.com/documentation/ecm0359818/latest/) for details).
With this ABI, the compiler will do the following to perform the call:
* save registers needed after the call to Secure memory
* clear all registers that might contain confidential information
* clear the Least Significant Bit of the function address
* branches using the BLXNS instruction
To avoid using the non-secure stack, the compiler will constrain the number and
type of parameters/return value.
The `extern "C-cmse-nonsecure-call"` ABI is otherwise equivalent to the
`extern "C"` ABI.
<!-- NOTE(ignore) this example is specific to thumbv8m targets -->
``` rust,ignore
#![no_std]
#![feature(abi_c_cmse_nonsecure_call)]
#[no_mangle]
pub fn call_nonsecure_function(addr: usize) -> u32 {
let non_secure_function =
unsafe { core::mem::transmute::<usize, extern "C-cmse-nonsecure-call" fn() -> u32>(addr) };
non_secure_function()
}
```
``` text
$ rustc --emit asm --crate-type lib --target thumbv8m.main-none-eabi function.rs
call_nonsecure_function:
.fnstart
.save {r7, lr}
push {r7, lr}
.setfp r7, sp
mov r7, sp
.pad #16
sub sp, #16
str r0, [sp, #12]
ldr r0, [sp, #12]
str r0, [sp, #8]
b .LBB0_1
.LBB0_1:
ldr r0, [sp, #8]
push.w {r4, r5, r6, r7, r8, r9, r10, r11}
bic r0, r0, #1
mov r1, r0
mov r2, r0
mov r3, r0
mov r4, r0
mov r5, r0
mov r6, r0
mov r7, r0
mov r8, r0
mov r9, r0
mov r10, r0
mov r11, r0
mov r12, r0
msr apsr_nzcvq, r0
blxns r0
pop.w {r4, r5, r6, r7, r8, r9, r10, r11}
str r0, [sp, #4]
b .LBB0_2
.LBB0_2:
ldr r0, [sp, #4]
add sp, #16
pop {r7, pc}
```
"##,
},
LintCompletion {
label: "member_constraints",
description: r##"# `member_constraints`
The tracking issue for this feature is: [#61997]
[#61997]: https://github.com/rust-lang/rust/issues/61997
------------------------
The `member_constraints` feature gate lets you use `impl Trait` syntax with
multiple unrelated lifetime parameters.
A simple example is:
```rust
#![feature(member_constraints)]
trait Trait<'a, 'b> { }
impl<T> Trait<'_, '_> for T {}
fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Trait<'a, 'b> {
(x, y)
}
fn main() { }
```
Without the `member_constraints` feature gate, the above example is an
error because both `'a` and `'b` appear in the impl Trait bounds, but
neither outlives the other.
"##,
},
LintCompletion {
label: "allocator_internals",
description: r##"# `allocator_internals`
This feature does not have a tracking issue, it is an unstable implementation
detail of the `global_allocator` feature not intended for use outside the
compiler.
------------------------
"##,
},
LintCompletion {
label: "cfg_sanitize",
description: r##"# `cfg_sanitize`
The tracking issue for this feature is: [#39699]
[#39699]: https://github.com/rust-lang/rust/issues/39699
------------------------
The `cfg_sanitize` feature makes it possible to execute different code
depending on whether a particular sanitizer is enabled or not.
## Examples
```rust
#![feature(cfg_sanitize)]
#[cfg(sanitize = "thread")]
fn a() {
// ...
}
#[cfg(not(sanitize = "thread"))]
fn a() {
// ...
}
fn b() {
if cfg!(sanitize = "leak") {
// ...
} else {
// ...
}
}
```
"##,
},
LintCompletion {
label: "cfg_panic",
description: r##"# `cfg_panic`
The tracking issue for this feature is: [#77443]
[#77443]: https://github.com/rust-lang/rust/issues/77443
------------------------
The `cfg_panic` feature makes it possible to execute different code
depending on the panic strategy.
Possible values at the moment are `"unwind"` or `"abort"`, although
it is possible that new panic strategies may be added to Rust in the
future.
## Examples
```rust
#![feature(cfg_panic)]
#[cfg(panic = "unwind")]
fn a() {
// ...
}
#[cfg(not(panic = "unwind"))]
fn a() {
// ...
}
fn b() {
if cfg!(panic = "abort") {
// ...
} else {
// ...
}
}
```
"##,
},
LintCompletion {
label: "ffi_pure",
description: r##"# `ffi_pure`
The tracking issue for this feature is: [#58329]
------
The `#[ffi_pure]` attribute applies clang's `pure` attribute to foreign
functions declarations.
That is, `#[ffi_pure]` functions shall have no effects except for its return
value, which shall not change across two consecutive function calls with
the same parameters.
Applying the `#[ffi_pure]` attribute to a function that violates these
requirements is undefined behavior.
This attribute enables Rust to perform common optimizations, like sub-expression
elimination and loop optimizations. Some common examples of pure functions are
`strlen` or `memcmp`.
These optimizations are only applicable when the compiler can prove that no
program state observable by the `#[ffi_pure]` function has changed between calls
of the function, which could alter the result. See also the `#[ffi_const]`
attribute, which provides stronger guarantees regarding the allowable behavior
of a function, enabling further optimization.
## Pitfalls
A `#[ffi_pure]` function can read global memory through the function
parameters (e.g. pointers), globals, etc. `#[ffi_pure]` functions are not
referentially-transparent, and are therefore more relaxed than `#[ffi_const]`
functions.
However, accessing global memory through volatile or atomic reads can violate the
requirement that two consecutive function calls shall return the same value.
A `pure` function that returns unit has no effect on the abstract machine's
state.
A `#[ffi_pure]` function must not diverge, neither via a side effect (e.g. a
call to `abort`) nor by infinite loops.
When translating C headers to Rust FFI, it is worth verifying for which targets
the `pure` attribute is enabled in those headers, and using the appropriate
`cfg` macros in the Rust side to match those definitions. While the semantics of
`pure` are implemented identically by many C and C++ compilers, e.g., clang,
[GCC], [ARM C/C++ compiler], [IBM ILE C/C++], etc. they are not necessarily
implemented in this way on all of them. It is therefore also worth verifying
that the semantics of the C toolchain used to compile the binary being linked
against are compatible with those of the `#[ffi_pure]`.
[#58329]: https://github.com/rust-lang/rust/issues/58329
[ARM C/C++ compiler]: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0491c/Cacigdac.html
[GCC]: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute
[IBM ILE C/C++]: https://www.ibm.com/support/knowledgecenter/fr/ssw_ibm_i_71/rzarg/fn_attrib_pure.htm
"##,
},
LintCompletion {
label: "repr128",
description: r##"# `repr128`
The tracking issue for this feature is: [#56071]
[#56071]: https://github.com/rust-lang/rust/issues/56071
------------------------
The `repr128` feature adds support for `#[repr(u128)]` on `enum`s.
```rust
#![feature(repr128)]
#[repr(u128)]
enum Foo {
Bar(u64),
}
```
"##,
},
LintCompletion {
label: "generators",
description: r##"# `generators`
The tracking issue for this feature is: [#43122]
[#43122]: https://github.com/rust-lang/rust/issues/43122
------------------------
The `generators` feature gate in Rust allows you to define generator or
coroutine literals. A generator is a "resumable function" that syntactically
resembles a closure but compiles to much different semantics in the compiler
itself. The primary feature of a generator is that it can be suspended during
execution to be resumed at a later date. Generators use the `yield` keyword to
"return", and then the caller can `resume` a generator to resume execution just
after the `yield` keyword.
Generators are an extra-unstable feature in the compiler right now. Added in
[RFC 2033] they're mostly intended right now as a information/constraint
gathering phase. The intent is that experimentation can happen on the nightly
compiler before actual stabilization. A further RFC will be required to
stabilize generators/coroutines and will likely contain at least a few small
tweaks to the overall design.
[RFC 2033]: https://github.com/rust-lang/rfcs/pull/2033
A syntactical example of a generator is:
```rust
#![feature(generators, generator_trait)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;
fn main() {
let mut generator = || {
yield 1;
return "foo"
};
match Pin::new(&mut generator).resume(()) {
GeneratorState::Yielded(1) => {}
_ => panic!("unexpected value from resume"),
}
match Pin::new(&mut generator).resume(()) {
GeneratorState::Complete("foo") => {}
_ => panic!("unexpected value from resume"),
}
}
```
Generators are closure-like literals which can contain a `yield` statement. The
`yield` statement takes an optional expression of a value to yield out of the
generator. All generator literals implement the `Generator` trait in the
`std::ops` module. The `Generator` trait has one main method, `resume`, which
resumes execution of the generator at the previous suspension point.
An example of the control flow of generators is that the following example
prints all numbers in order:
```rust
#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::pin::Pin;
fn main() {
let mut generator = || {
println!("2");
yield;
println!("4");
};
println!("1");
Pin::new(&mut generator).resume(());
println!("3");
Pin::new(&mut generator).resume(());
println!("5");
}
```
At this time the main intended use case of generators is an implementation
primitive for async/await syntax, but generators will likely be extended to
ergonomic implementations of iterators and other primitives in the future.
Feedback on the design and usage is always appreciated!
### The `Generator` trait
The `Generator` trait in `std::ops` currently looks like:
```rust
# #![feature(arbitrary_self_types, generator_trait)]
# use std::ops::GeneratorState;
# use std::pin::Pin;
pub trait Generator<R = ()> {
type Yield;
type Return;
fn resume(self: Pin<&mut Self>, resume: R) -> GeneratorState<Self::Yield, Self::Return>;
}
```
The `Generator::Yield` type is the type of values that can be yielded with the
`yield` statement. The `Generator::Return` type is the returned type of the
generator. This is typically the last expression in a generator's definition or
any value passed to `return` in a generator. The `resume` function is the entry
point for executing the `Generator` itself.
The return value of `resume`, `GeneratorState`, looks like:
```rust
pub enum GeneratorState<Y, R> {
Yielded(Y),
Complete(R),
}
```
The `Yielded` variant indicates that the generator can later be resumed. This
corresponds to a `yield` point in a generator. The `Complete` variant indicates
that the generator is complete and cannot be resumed again. Calling `resume`
after a generator has returned `Complete` will likely result in a panic of the
program.
### Closure-like semantics
The closure-like syntax for generators alludes to the fact that they also have
closure-like semantics. Namely:
* When created, a generator executes no code. A closure literal does not
actually execute any of the closure's code on construction, and similarly a
generator literal does not execute any code inside the generator when
constructed.
* Generators can capture outer variables by reference or by move, and this can
be tweaked with the `move` keyword at the beginning of the closure. Like
closures all generators will have an implicit environment which is inferred by
the compiler. Outer variables can be moved into a generator for use as the
generator progresses.
* Generator literals produce a value with a unique type which implements the
`std::ops::Generator` trait. This allows actual execution of the generator
through the `Generator::resume` method as well as also naming it in return
types and such.
* Traits like `Send` and `Sync` are automatically implemented for a `Generator`
depending on the captured variables of the environment. Unlike closures,
generators also depend on variables live across suspension points. This means
that although the ambient environment may be `Send` or `Sync`, the generator
itself may not be due to internal variables live across `yield` points being
not-`Send` or not-`Sync`. Note that generators do
not implement traits like `Copy` or `Clone` automatically.
* Whenever a generator is dropped it will drop all captured environment
variables.
### Generators as state machines
In the compiler, generators are currently compiled as state machines. Each
`yield` expression will correspond to a different state that stores all live
variables over that suspension point. Resumption of a generator will dispatch on
the current state and then execute internally until a `yield` is reached, at
which point all state is saved off in the generator and a value is returned.
Let's take a look at an example to see what's going on here:
```rust
#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::pin::Pin;
fn main() {
let ret = "foo";
let mut generator = move || {
yield 1;
return ret
};
Pin::new(&mut generator).resume(());
Pin::new(&mut generator).resume(());
}
```
This generator literal will compile down to something similar to:
```rust
#![feature(arbitrary_self_types, generators, generator_trait)]
use std::ops::{Generator, GeneratorState};
use std::pin::Pin;
fn main() {
let ret = "foo";
let mut generator = {
enum __Generator {
Start(&'static str),
Yield1(&'static str),
Done,
}
impl Generator for __Generator {
type Yield = i32;
type Return = &'static str;
fn resume(mut self: Pin<&mut Self>, resume: ()) -> GeneratorState<i32, &'static str> {
use std::mem;
match mem::replace(&mut *self, __Generator::Done) {
__Generator::Start(s) => {
*self = __Generator::Yield1(s);
GeneratorState::Yielded(1)
}
__Generator::Yield1(s) => {
*self = __Generator::Done;
GeneratorState::Complete(s)
}
__Generator::Done => {
panic!("generator resumed after completion")
}
}
}
}
__Generator::Start(ret)
};
Pin::new(&mut generator).resume(());
Pin::new(&mut generator).resume(());
}
```
Notably here we can see that the compiler is generating a fresh type,
`__Generator` in this case. This type has a number of states (represented here
as an `enum`) corresponding to each of the conceptual states of the generator.
At the beginning we're closing over our outer variable `foo` and then that
variable is also live over the `yield` point, so it's stored in both states.
When the generator starts it'll immediately yield 1, but it saves off its state
just before it does so indicating that it has reached the yield point. Upon
resuming again we'll execute the `return ret` which returns the `Complete`
state.
Here we can also note that the `Done` state, if resumed, panics immediately as
it's invalid to resume a completed generator. It's also worth noting that this
is just a rough desugaring, not a normative specification for what the compiler
does.
"##,
},
LintCompletion {
label: "non_ascii_idents",
description: r##"# `non_ascii_idents`
The tracking issue for this feature is: [#55467]
[#55467]: https://github.com/rust-lang/rust/issues/55467
------------------------
The `non_ascii_idents` feature adds support for non-ASCII identifiers.
## Examples
```rust
#![feature(non_ascii_idents)]
const ε: f64 = 0.00001f64;
const Π: f64 = 3.14f64;
```
## Changes to the language reference
> **<sup>Lexer:<sup>**\
> IDENTIFIER :\
> XID_start XID_continue<sup>\*</sup>\
> | `_` XID_continue<sup>+</sup>
An identifier is any nonempty Unicode string of the following form:
Either
* The first character has property [`XID_start`]
* The remaining characters have property [`XID_continue`]
Or
* The first character is `_`
* The identifier is more than one character, `_` alone is not an identifier
* The remaining characters have property [`XID_continue`]
that does _not_ occur in the set of [strict keywords].
> **Note**: [`XID_start`] and [`XID_continue`] as character properties cover the
> character ranges used to form the more familiar C and Java language-family
> identifiers.
[`XID_start`]: http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5B%3AXID_Start%3A%5D&abb=on&g=&i=
[`XID_continue`]: http://unicode.org/cldr/utility/list-unicodeset.jsp?a=%5B%3AXID_Continue%3A%5D&abb=on&g=&i=
[strict keywords]: ../../reference/keywords.md#strict-keywords
"##,
},
LintCompletion {
label: "compiler_builtins",
description: r##"# `compiler_builtins`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "or_patterns",
description: r##"# `or_patterns`
The tracking issue for this feature is: [#54883]
[#54883]: https://github.com/rust-lang/rust/issues/54883
------------------------
The `or_pattern` language feature allows `|` to be arbitrarily nested within
a pattern, for example, `Some(A(0) | B(1 | 2))` becomes a valid pattern.
## Examples
```rust,no_run
#![feature(or_patterns)]
pub enum Foo {
Bar,
Baz,
Quux,
}
pub fn example(maybe_foo: Option<Foo>) {
match maybe_foo {
Some(Foo::Bar | Foo::Baz) => {
println!("The value contained `Bar` or `Baz`");
}
Some(_) => {
println!("The value did not contain `Bar` or `Baz`");
}
None => {
println!("The value was `None`");
}
}
}
```
"##,
},
LintCompletion {
label: "negative_impls",
description: r##"# `negative_impls`
The tracking issue for this feature is [#68318].
[#68318]: https://github.com/rust-lang/rust/issues/68318
----
With the feature gate `negative_impls`, you can write negative impls as well as positive ones:
```rust
#![feature(negative_impls)]
trait DerefMut { }
impl<T: ?Sized> !DerefMut for &T { }
```
Negative impls indicate a semver guarantee that the given trait will not be implemented for the given types. Negative impls play an additional purpose for auto traits, described below.
Negative impls have the following characteristics:
* They do not have any items.
* They must obey the orphan rules as if they were a positive impl.
* They cannot "overlap" with any positive impls.
## Semver interaction
It is a breaking change to remove a negative impl. Negative impls are a commitment not to implement the given trait for the named types.
## Orphan and overlap rules
Negative impls must obey the same orphan rules as a positive impl. This implies you cannot add a negative impl for types defined in upstream crates and so forth.
Similarly, negative impls cannot overlap with positive impls, again using the same "overlap" check that we ordinarily use to determine if two impls overlap. (Note that positive impls typically cannot overlap with one another either, except as permitted by specialization.)
## Interaction with auto traits
Declaring a negative impl `impl !SomeAutoTrait for SomeType` for an
auto-trait serves two purposes:
* as with any trait, it declares that `SomeType` will never implement `SomeAutoTrait`;
* it disables the automatic `SomeType: SomeAutoTrait` impl that would otherwise have been generated.
Note that, at present, there is no way to indicate that a given type
does not implement an auto trait *but that it may do so in the
future*. For ordinary types, this is done by simply not declaring any
impl at all, but that is not an option for auto traits. A workaround
is that one could embed a marker type as one of the fields, where the
marker type is `!AutoTrait`.
## Immediate uses
Negative impls are used to declare that `&T: !DerefMut` and `&mut T: !Clone`, as required to fix the soundness of `Pin` described in [#66544](https://github.com/rust-lang/rust/issues/66544).
This serves two purposes:
* For proving the correctness of unsafe code, we can use that impl as evidence that no `DerefMut` or `Clone` impl exists.
* It prevents downstream crates from creating such impls.
"##,
},
LintCompletion {
label: "cmse_nonsecure_entry",
description: r##"# `cmse_nonsecure_entry`
The tracking issue for this feature is: [#75835]
[#75835]: https://github.com/rust-lang/rust/issues/75835
------------------------
The [TrustZone-M
feature](https://developer.arm.com/documentation/100690/latest/) is available
for targets with the Armv8-M architecture profile (`thumbv8m` in their target
name).
LLVM, the Rust compiler and the linker are providing
[support](https://developer.arm.com/documentation/ecm0359818/latest/) for the
TrustZone-M feature.
One of the things provided, with this unstable feature, is the
`cmse_nonsecure_entry` attribute. This attribute marks a Secure function as an
entry function (see [section
5.4](https://developer.arm.com/documentation/ecm0359818/latest/) for details).
With this attribute, the compiler will do the following:
* add a special symbol on the function which is the `__acle_se_` prefix and the
standard function name
* constrain the number of parameters to avoid using the Non-Secure stack
* before returning from the function, clear registers that might contain Secure
information
* use the `BXNS` instruction to return
Because the stack can not be used to pass parameters, there will be compilation
errors if:
* the total size of all parameters is too big (for example more than four 32
bits integers)
* the entry function is not using a C ABI
The special symbol `__acle_se_` will be used by the linker to generate a secure
gateway veneer.
<!-- NOTE(ignore) this example is specific to thumbv8m targets -->
``` rust,ignore
#![feature(cmse_nonsecure_entry)]
#[no_mangle]
#[cmse_nonsecure_entry]
pub extern "C" fn entry_function(input: u32) -> u32 {
input + 6
}
```
``` text
$ rustc --emit obj --crate-type lib --target thumbv8m.main-none-eabi function.rs
$ arm-none-eabi-objdump -D function.o
00000000 <entry_function>:
0: b580 push {r7, lr}
2: 466f mov r7, sp
4: b082 sub sp, #8
6: 9001 str r0, [sp, #4]
8: 1d81 adds r1, r0, #6
a: 460a mov r2, r1
c: 4281 cmp r1, r0
e: 9200 str r2, [sp, #0]
10: d30b bcc.n 2a <entry_function+0x2a>
12: e7ff b.n 14 <entry_function+0x14>
14: 9800 ldr r0, [sp, #0]
16: b002 add sp, #8
18: e8bd 4080 ldmia.w sp!, {r7, lr}
1c: 4671 mov r1, lr
1e: 4672 mov r2, lr
20: 4673 mov r3, lr
22: 46f4 mov ip, lr
24: f38e 8800 msr CPSR_f, lr
28: 4774 bxns lr
2a: f240 0000 movw r0, #0
2e: f2c0 0000 movt r0, #0
32: f240 0200 movw r2, #0
36: f2c0 0200 movt r2, #0
3a: 211c movs r1, #28
3c: f7ff fffe bl 0 <_ZN4core9panicking5panic17h5c028258ca2fb3f5E>
40: defe udf #254 ; 0xfe
```
"##,
},
LintCompletion {
label: "plugin",
description: r##"# `plugin`
The tracking issue for this feature is: [#29597]
[#29597]: https://github.com/rust-lang/rust/issues/29597
This feature is part of "compiler plugins." It will often be used with the
[`plugin_registrar`] and `rustc_private` features.
[`plugin_registrar`]: plugin-registrar.md
------------------------
`rustc` can load compiler plugins, which are user-provided libraries that
extend the compiler's behavior with new lint checks, etc.
A plugin is a dynamic library crate with a designated *registrar* function that
registers extensions with `rustc`. Other crates can load these extensions using
the crate attribute `#![plugin(...)]`. See the
`rustc_driver::plugin` documentation for more about the
mechanics of defining and loading a plugin.
In the vast majority of cases, a plugin should *only* be used through
`#![plugin]` and not through an `extern crate` item. Linking a plugin would
pull in all of librustc_ast and librustc as dependencies of your crate. This is
generally unwanted unless you are building another plugin.
The usual practice is to put compiler plugins in their own crate, separate from
any `macro_rules!` macros or ordinary Rust code meant to be used by consumers
of a library.
# Lint plugins
Plugins can extend [Rust's lint
infrastructure](../../reference/attributes/diagnostics.md#lint-check-attributes) with
additional checks for code style, safety, etc. Now let's write a plugin
[`lint-plugin-test.rs`](https://github.com/rust-lang/rust/blob/master/src/test/ui-fulldeps/auxiliary/lint-plugin-test.rs)
that warns about any item named `lintme`.
```rust,ignore (requires-stage-2)
#![feature(plugin_registrar)]
#![feature(box_syntax, rustc_private)]
extern crate rustc_ast;
// Load rustc as a plugin to get macros
extern crate rustc_driver;
#[macro_use]
extern crate rustc_lint;
#[macro_use]
extern crate rustc_session;
use rustc_driver::plugin::Registry;
use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
use rustc_ast::ast;
declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");
declare_lint_pass!(Pass => [TEST_LINT]);
impl EarlyLintPass for Pass {
fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
if it.ident.name.as_str() == "lintme" {
cx.lint(TEST_LINT, |lint| {
lint.build("item is named 'lintme'").set_span(it.span).emit()
});
}
}
}
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.lint_store.register_lints(&[&TEST_LINT]);
reg.lint_store.register_early_pass(|| box Pass);
}
```
Then code like
```rust,ignore (requires-plugin)
#![feature(plugin)]
#![plugin(lint_plugin_test)]
fn lintme() { }
```
will produce a compiler warning:
```txt
foo.rs:4:1: 4:16 warning: item is named 'lintme', #[warn(test_lint)] on by default
foo.rs:4 fn lintme() { }
^~~~~~~~~~~~~~~
```
The components of a lint plugin are:
* one or more `declare_lint!` invocations, which define static `Lint` structs;
* a struct holding any state needed by the lint pass (here, none);
* a `LintPass`
implementation defining how to check each syntax element. A single
`LintPass` may call `span_lint` for several different `Lint`s, but should
register them all through the `get_lints` method.
Lint passes are syntax traversals, but they run at a late stage of compilation
where type information is available. `rustc`'s [built-in
lints](https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs)
mostly use the same infrastructure as lint plugins, and provide examples of how
to access type information.
Lints defined by plugins are controlled by the usual [attributes and compiler
flags](../../reference/attributes/diagnostics.md#lint-check-attributes), e.g.
`#[allow(test_lint)]` or `-A test-lint`. These identifiers are derived from the
first argument to `declare_lint!`, with appropriate case and punctuation
conversion.
You can run `rustc -W help foo.rs` to see a list of lints known to `rustc`,
including those provided by plugins loaded by `foo.rs`.
"##,
},
LintCompletion {
label: "intrinsics",
description: r##"# `intrinsics`
The tracking issue for this feature is: None.
Intrinsics are never intended to be stable directly, but intrinsics are often
exported in some sort of stable manner. Prefer using the stable interfaces to
the intrinsic directly when you can.
------------------------
These are imported as if they were FFI functions, with the special
`rust-intrinsic` ABI. For example, if one was in a freestanding
context, but wished to be able to `transmute` between types, and
perform efficient pointer arithmetic, one would import those functions
via a declaration like
```rust
#![feature(intrinsics)]
# fn main() {}
extern "rust-intrinsic" {
fn transmute<T, U>(x: T) -> U;
fn offset<T>(dst: *const T, offset: isize) -> *const T;
}
```
As with any other FFI functions, these are always `unsafe` to call.
"##,
},
LintCompletion {
label: "rustc_attrs",
description: r##"# `rustc_attrs`
This feature has no tracking issue, and is therefore internal to
the compiler, not being intended for general use.
Note: `rustc_attrs` enables many rustc-internal attributes and this page
only discuss a few of them.
------------------------
The `rustc_attrs` feature allows debugging rustc type layouts by using
`#[rustc_layout(...)]` to debug layout at compile time (it even works
with `cargo check`) as an alternative to `rustc -Z print-type-sizes`
that is way more verbose.
Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `align`,
`abi`. Note that it only works on sized types without generics.
## Examples
```rust,compile_fail
#![feature(rustc_attrs)]
#[rustc_layout(abi, size)]
pub enum X {
Y(u8, u8, u8),
Z(isize),
}
```
When that is compiled, the compiler will error with something like
```text
error: abi: Aggregate { sized: true }
--> src/lib.rs:4:1
|
4 | / pub enum T {
5 | | Y(u8, u8, u8),
6 | | Z(isize),
7 | | }
| |_^
error: size: Size { raw: 16 }
--> src/lib.rs:4:1
|
4 | / pub enum T {
5 | | Y(u8, u8, u8),
6 | | Z(isize),
7 | | }
| |_^
error: aborting due to 2 previous errors
```
"##,
},
LintCompletion {
label: "const_fn",
description: r##"# `const_fn`
The tracking issue for this feature is: [#57563]
[#57563]: https://github.com/rust-lang/rust/issues/57563
------------------------
The `const_fn` feature enables additional functionality not stabilized in the
[minimal subset of `const_fn`](https://github.com/rust-lang/rust/issues/53555)
"##,
},
LintCompletion {
label: "abi_thiscall",
description: r##"# `abi_thiscall`
The tracking issue for this feature is: [#42202]
[#42202]: https://github.com/rust-lang/rust/issues/42202
------------------------
The MSVC ABI on x86 Windows uses the `thiscall` calling convention for C++
instance methods by default; it is identical to the usual (C) calling
convention on x86 Windows except that the first parameter of the method,
the `this` pointer, is passed in the ECX register.
"##,
},
LintCompletion {
label: "trait_alias",
description: r##"# `trait_alias`
The tracking issue for this feature is: [#41517]
[#41517]: https://github.com/rust-lang/rust/issues/41517
------------------------
The `trait_alias` feature adds support for trait aliases. These allow aliases
to be created for one or more traits (currently just a single regular trait plus
any number of auto-traits), and used wherever traits would normally be used as
either bounds or trait objects.
```rust
#![feature(trait_alias)]
trait Foo = std::fmt::Debug + Send;
trait Bar = Foo + Sync;
// Use trait alias as bound on type parameter.
fn foo<T: Foo>(v: &T) {
println!("{:?}", v);
}
pub fn main() {
foo(&1);
// Use trait alias for trait objects.
let a: &Bar = &123;
println!("{:?}", a);
let b = Box::new(456) as Box<dyn Foo>;
println!("{:?}", b);
}
```
"##,
},
LintCompletion {
label: "lang_items",
description: r##"# `lang_items`
The tracking issue for this feature is: None.
------------------------
The `rustc` compiler has certain pluggable operations, that is,
functionality that isn't hard-coded into the language, but is
implemented in libraries, with a special marker to tell the compiler
it exists. The marker is the attribute `#[lang = "..."]` and there are
various different values of `...`, i.e. various different 'lang
items'.
For example, `Box` pointers require two lang items, one for allocation
and one for deallocation. A freestanding program that uses the `Box`
sugar for dynamic allocations via `malloc` and `free`:
```rust,ignore (libc-is-finicky)
#![feature(lang_items, box_syntax, start, libc, core_intrinsics, rustc_private)]
#![no_std]
use core::intrinsics;
use core::panic::PanicInfo;
extern crate libc;
#[lang = "owned_box"]
pub struct Box<T>(*mut T);
#[lang = "exchange_malloc"]
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
let p = libc::malloc(size as libc::size_t) as *mut u8;
// Check if `malloc` failed:
if p as usize == 0 {
intrinsics::abort();
}
p
}
#[lang = "box_free"]
unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
libc::free(ptr as *mut libc::c_void)
}
#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
let _x = box 1;
0
}
#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_impl"] extern fn rust_begin_panic(info: &PanicInfo) -> ! { unsafe { intrinsics::abort() } }
#[no_mangle] pub extern fn rust_eh_register_frames () {}
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}
```
Note the use of `abort`: the `exchange_malloc` lang item is assumed to
return a valid pointer, and so needs to do the check internally.
Other features provided by lang items include:
- overloadable operators via traits: the traits corresponding to the
`==`, `<`, dereferencing (`*`) and `+` (etc.) operators are all
marked with lang items; those specific four are `eq`, `ord`,
`deref`, and `add` respectively.
- stack unwinding and general failure; the `eh_personality`,
`panic` and `panic_bounds_check` lang items.
- the traits in `std::marker` used to indicate types of
various kinds; lang items `send`, `sync` and `copy`.
- the marker types and variance indicators found in
`std::marker`; lang items `covariant_type`,
`contravariant_lifetime`, etc.
Lang items are loaded lazily by the compiler; e.g. if one never uses
`Box` then there is no need to define functions for `exchange_malloc`
and `box_free`. `rustc` will emit an error when an item is needed
but not found in the current crate or any that it depends on.
Most lang items are defined by `libcore`, but if you're trying to build
an executable without the standard library, you'll run into the need
for lang items. The rest of this page focuses on this use-case, even though
lang items are a bit broader than that.
### Using libc
In order to build a `#[no_std]` executable we will need libc as a dependency.
We can specify this using our `Cargo.toml` file:
```toml
[dependencies]
libc = { version = "0.2.14", default-features = false }
```
Note that the default features have been disabled. This is a critical step -
**the default features of libc include the standard library and so must be
disabled.**
### Writing an executable without stdlib
Controlling the entry point is possible in two ways: the `#[start]` attribute,
or overriding the default shim for the C `main` function with your own.
The function marked `#[start]` is passed the command line parameters
in the same format as C:
```rust,ignore (libc-is-finicky)
#![feature(lang_items, core_intrinsics, rustc_private)]
#![feature(start)]
#![no_std]
use core::intrinsics;
use core::panic::PanicInfo;
// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
// Entry point for this program.
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
0
}
// These functions are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.
#[lang = "eh_personality"]
#[no_mangle]
pub extern fn rust_eh_personality() {
}
#[lang = "panic_impl"]
#[no_mangle]
pub extern fn rust_begin_panic(info: &PanicInfo) -> ! {
unsafe { intrinsics::abort() }
}
```
To override the compiler-inserted `main` shim, one has to disable it
with `#![no_main]` and then create the appropriate symbol with the
correct ABI and the correct name, which requires overriding the
compiler's name mangling too:
```rust,ignore (libc-is-finicky)
#![feature(lang_items, core_intrinsics, rustc_private)]
#![feature(start)]
#![no_std]
#![no_main]
use core::intrinsics;
use core::panic::PanicInfo;
// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
// Entry point for this program.
#[no_mangle] // ensure that this symbol is called `main` in the output
pub extern fn main(_argc: i32, _argv: *const *const u8) -> i32 {
0
}
// These functions are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.
#[lang = "eh_personality"]
#[no_mangle]
pub extern fn rust_eh_personality() {
}
#[lang = "panic_impl"]
#[no_mangle]
pub extern fn rust_begin_panic(info: &PanicInfo) -> ! {
unsafe { intrinsics::abort() }
}
```
In many cases, you may need to manually link to the `compiler_builtins` crate
when building a `no_std` binary. You may observe this via linker error messages
such as "```undefined reference to `__rust_probestack'```".
## More about the language items
The compiler currently makes a few assumptions about symbols which are
available in the executable to call. Normally these functions are provided by
the standard library, but without it you must define your own. These symbols
are called "language items", and they each have an internal name, and then a
signature that an implementation must conform to.
The first of these functions, `rust_eh_personality`, is used by the failure
mechanisms of the compiler. This is often mapped to GCC's personality function
(see the [libstd implementation][unwind] for more information), but crates
which do not trigger a panic can be assured that this function is never
called. The language item's name is `eh_personality`.
[unwind]: https://github.com/rust-lang/rust/blob/master/src/libpanic_unwind/gcc.rs
The second function, `rust_begin_panic`, is also used by the failure mechanisms of the
compiler. When a panic happens, this controls the message that's displayed on
the screen. While the language item's name is `panic_impl`, the symbol name is
`rust_begin_panic`.
Finally, a `eh_catch_typeinfo` static is needed for certain targets which
implement Rust panics on top of C++ exceptions.
## List of all language items
This is a list of all language items in Rust along with where they are located in
the source code.
- Primitives
- `i8`: `libcore/num/mod.rs`
- `i16`: `libcore/num/mod.rs`
- `i32`: `libcore/num/mod.rs`
- `i64`: `libcore/num/mod.rs`
- `i128`: `libcore/num/mod.rs`
- `isize`: `libcore/num/mod.rs`
- `u8`: `libcore/num/mod.rs`
- `u16`: `libcore/num/mod.rs`
- `u32`: `libcore/num/mod.rs`
- `u64`: `libcore/num/mod.rs`
- `u128`: `libcore/num/mod.rs`
- `usize`: `libcore/num/mod.rs`
- `f32`: `libstd/f32.rs`
- `f64`: `libstd/f64.rs`
- `char`: `libcore/char.rs`
- `slice`: `liballoc/slice.rs`
- `str`: `liballoc/str.rs`
- `const_ptr`: `libcore/ptr.rs`
- `mut_ptr`: `libcore/ptr.rs`
- `unsafe_cell`: `libcore/cell.rs`
- Runtime
- `start`: `libstd/rt.rs`
- `eh_personality`: `libpanic_unwind/emcc.rs` (EMCC)
- `eh_personality`: `libpanic_unwind/gcc.rs` (GNU)
- `eh_personality`: `libpanic_unwind/seh.rs` (SEH)
- `eh_catch_typeinfo`: `libpanic_unwind/emcc.rs` (EMCC)
- `panic`: `libcore/panicking.rs`
- `panic_bounds_check`: `libcore/panicking.rs`
- `panic_impl`: `libcore/panicking.rs`
- `panic_impl`: `libstd/panicking.rs`
- Allocations
- `owned_box`: `liballoc/boxed.rs`
- `exchange_malloc`: `liballoc/heap.rs`
- `box_free`: `liballoc/heap.rs`
- Operands
- `not`: `libcore/ops/bit.rs`
- `bitand`: `libcore/ops/bit.rs`
- `bitor`: `libcore/ops/bit.rs`
- `bitxor`: `libcore/ops/bit.rs`
- `shl`: `libcore/ops/bit.rs`
- `shr`: `libcore/ops/bit.rs`
- `bitand_assign`: `libcore/ops/bit.rs`
- `bitor_assign`: `libcore/ops/bit.rs`
- `bitxor_assign`: `libcore/ops/bit.rs`
- `shl_assign`: `libcore/ops/bit.rs`
- `shr_assign`: `libcore/ops/bit.rs`
- `deref`: `libcore/ops/deref.rs`
- `deref_mut`: `libcore/ops/deref.rs`
- `index`: `libcore/ops/index.rs`
- `index_mut`: `libcore/ops/index.rs`
- `add`: `libcore/ops/arith.rs`
- `sub`: `libcore/ops/arith.rs`
- `mul`: `libcore/ops/arith.rs`
- `div`: `libcore/ops/arith.rs`
- `rem`: `libcore/ops/arith.rs`
- `neg`: `libcore/ops/arith.rs`
- `add_assign`: `libcore/ops/arith.rs`
- `sub_assign`: `libcore/ops/arith.rs`
- `mul_assign`: `libcore/ops/arith.rs`
- `div_assign`: `libcore/ops/arith.rs`
- `rem_assign`: `libcore/ops/arith.rs`
- `eq`: `libcore/cmp.rs`
- `ord`: `libcore/cmp.rs`
- Functions
- `fn`: `libcore/ops/function.rs`
- `fn_mut`: `libcore/ops/function.rs`
- `fn_once`: `libcore/ops/function.rs`
- `generator_state`: `libcore/ops/generator.rs`
- `generator`: `libcore/ops/generator.rs`
- Other
- `coerce_unsized`: `libcore/ops/unsize.rs`
- `drop`: `libcore/ops/drop.rs`
- `drop_in_place`: `libcore/ptr.rs`
- `clone`: `libcore/clone.rs`
- `copy`: `libcore/marker.rs`
- `send`: `libcore/marker.rs`
- `sized`: `libcore/marker.rs`
- `unsize`: `libcore/marker.rs`
- `sync`: `libcore/marker.rs`
- `phantom_data`: `libcore/marker.rs`
- `discriminant_kind`: `libcore/marker.rs`
- `freeze`: `libcore/marker.rs`
- `debug_trait`: `libcore/fmt/mod.rs`
- `non_zero`: `libcore/nonzero.rs`
- `arc`: `liballoc/sync.rs`
- `rc`: `liballoc/rc.rs`
"##,
},
LintCompletion {
label: "doc_spotlight",
description: r##"# `doc_spotlight`
The tracking issue for this feature is: [#45040]
The `doc_spotlight` feature allows the use of the `spotlight` parameter to the `#[doc]` attribute,
to "spotlight" a specific trait on the return values of functions. Adding a `#[doc(spotlight)]`
attribute to a trait definition will make rustdoc print extra information for functions which return
a type that implements that trait. For example, this attribute is applied to the `Iterator`,
`io::Read`, `io::Write`, and `Future` traits in the standard library.
You can do this on your own traits, like this:
```
#![feature(doc_spotlight)]
#[doc(spotlight)]
pub trait MyTrait {}
pub struct MyStruct;
impl MyTrait for MyStruct {}
/// The docs for this function will have an extra line about `MyStruct` implementing `MyTrait`,
/// without having to write that yourself!
pub fn my_fn() -> MyStruct { MyStruct }
```
This feature was originally implemented in PR [#45039].
[#45040]: https://github.com/rust-lang/rust/issues/45040
[#45039]: https://github.com/rust-lang/rust/pull/45039
"##,
},
LintCompletion {
label: "c_variadic",
description: r##"# `c_variadic`
The tracking issue for this feature is: [#44930]
[#44930]: https://github.com/rust-lang/rust/issues/44930
------------------------
The `c_variadic` language feature enables C-variadic functions to be
defined in Rust. The may be called both from within Rust and via FFI.
## Examples
```rust
#![feature(c_variadic)]
pub unsafe extern "C" fn add(n: usize, mut args: ...) -> usize {
let mut sum = 0;
for _ in 0..n {
sum += args.arg::<usize>();
}
sum
}
```
"##,
},
LintCompletion {
label: "intra_doc_pointers",
description: r##"# `intra-doc-pointers`
The tracking issue for this feature is: [#80896]
[#80896]: https://github.com/rust-lang/rust/issues/80896
------------------------
Rustdoc does not currently allow disambiguating between `*const` and `*mut`, and
raw pointers in intra-doc links are unstable until it does.
```rust
#![feature(intra_doc_pointers)]
//! [pointer::add]
```
"##,
},
LintCompletion {
label: "box_syntax",
description: r##"# `box_syntax`
The tracking issue for this feature is: [#49733]
[#49733]: https://github.com/rust-lang/rust/issues/49733
See also [`box_patterns`](box-patterns.md)
------------------------
Currently the only stable way to create a `Box` is via the `Box::new` method.
Also it is not possible in stable Rust to destructure a `Box` in a match
pattern. The unstable `box` keyword can be used to create a `Box`. An example
usage would be:
```rust
#![feature(box_syntax)]
fn main() {
let b = box 5;
}
```
"##,
},
LintCompletion {
label: "unsized_locals",
description: r##"# `unsized_locals`
The tracking issue for this feature is: [#48055]
[#48055]: https://github.com/rust-lang/rust/issues/48055
------------------------
This implements [RFC1909]. When turned on, you can have unsized arguments and locals:
[RFC1909]: https://github.com/rust-lang/rfcs/blob/master/text/1909-unsized-rvalues.md
```rust
#![allow(incomplete_features)]
#![feature(unsized_locals, unsized_fn_params)]
use std::any::Any;
fn main() {
let x: Box<dyn Any> = Box::new(42);
let x: dyn Any = *x;
// ^ unsized local variable
// ^^ unsized temporary
foo(x);
}
fn foo(_: dyn Any) {}
// ^^^^^^ unsized argument
```
The RFC still forbids the following unsized expressions:
```rust,compile_fail
#![feature(unsized_locals)]
use std::any::Any;
struct MyStruct<T: ?Sized> {
content: T,
}
struct MyTupleStruct<T: ?Sized>(T);
fn answer() -> Box<dyn Any> {
Box::new(42)
}
fn main() {
// You CANNOT have unsized statics.
static X: dyn Any = *answer(); // ERROR
const Y: dyn Any = *answer(); // ERROR
// You CANNOT have struct initialized unsized.
MyStruct { content: *answer() }; // ERROR
MyTupleStruct(*answer()); // ERROR
(42, *answer()); // ERROR
// You CANNOT have unsized return types.
fn my_function() -> dyn Any { *answer() } // ERROR
// You CAN have unsized local variables...
let mut x: dyn Any = *answer(); // OK
// ...but you CANNOT reassign to them.
x = *answer(); // ERROR
// You CANNOT even initialize them separately.
let y: dyn Any; // OK
y = *answer(); // ERROR
// Not mentioned in the RFC, but by-move captured variables are also Sized.
let x: dyn Any = *answer();
(move || { // ERROR
let y = x;
})();
// You CAN create a closure with unsized arguments,
// but you CANNOT call it.
// This is an implementation detail and may be changed in the future.
let f = |x: dyn Any| {};
f(*answer()); // ERROR
}
```
## By-value trait objects
With this feature, you can have by-value `self` arguments without `Self: Sized` bounds.
```rust
#![feature(unsized_fn_params)]
trait Foo {
fn foo(self) {}
}
impl<T: ?Sized> Foo for T {}
fn main() {
let slice: Box<[i32]> = Box::new([1, 2, 3]);
<[i32] as Foo>::foo(*slice);
}
```
And `Foo` will also be object-safe.
```rust
#![feature(unsized_fn_params)]
trait Foo {
fn foo(self) {}
}
impl<T: ?Sized> Foo for T {}
fn main () {
let slice: Box<dyn Foo> = Box::new([1, 2, 3]);
// doesn't compile yet
<dyn Foo as Foo>::foo(*slice);
}
```
One of the objectives of this feature is to allow `Box<dyn FnOnce>`.
## Variable length arrays
The RFC also describes an extension to the array literal syntax: `[e; dyn n]`. In the syntax, `n` isn't necessarily a constant expression. The array is dynamically allocated on the stack and has the type of `[T]`, instead of `[T; n]`.
```rust,ignore (not-yet-implemented)
#![feature(unsized_locals)]
fn mergesort<T: Ord>(a: &mut [T]) {
let mut tmp = [T; dyn a.len()];
// ...
}
fn main() {
let mut a = [3, 1, 5, 6];
mergesort(&mut a);
assert_eq!(a, [1, 3, 5, 6]);
}
```
VLAs are not implemented yet. The syntax isn't final, either. We may need an alternative syntax for Rust 2015 because, in Rust 2015, expressions like `[e; dyn(1)]` would be ambiguous. One possible alternative proposed in the RFC is `[e; n]`: if `n` captures one or more local variables, then it is considered as `[e; dyn n]`.
## Advisory on stack usage
It's advised not to casually use the `#![feature(unsized_locals)]` feature. Typical use-cases are:
- When you need a by-value trait objects.
- When you really need a fast allocation of small temporary arrays.
Another pitfall is repetitive allocation and temporaries. Currently the compiler simply extends the stack frame every time it encounters an unsized assignment. So for example, the code
```rust
#![feature(unsized_locals)]
fn main() {
let x: Box<[i32]> = Box::new([1, 2, 3, 4, 5]);
let _x = {{{{{{{{{{*x}}}}}}}}}};
}
```
and the code
```rust
#![feature(unsized_locals)]
fn main() {
for _ in 0..10 {
let x: Box<[i32]> = Box::new([1, 2, 3, 4, 5]);
let _x = *x;
}
}
```
will unnecessarily extend the stack frame.
"##,
},
LintCompletion {
label: "arbitrary_enum_discriminant",
description: r##"# `arbitrary_enum_discriminant`
The tracking issue for this feature is: [#60553]
[#60553]: https://github.com/rust-lang/rust/issues/60553
------------------------
The `arbitrary_enum_discriminant` feature permits tuple-like and
struct-like enum variants with `#[repr(<int-type>)]` to have explicit discriminants.
## Examples
```rust
#![feature(arbitrary_enum_discriminant)]
#[allow(dead_code)]
#[repr(u8)]
enum Enum {
Unit = 3,
Tuple(u16) = 2,
Struct {
a: u8,
b: u16,
} = 1,
}
impl Enum {
fn tag(&self) -> u8 {
unsafe { *(self as *const Self as *const u8) }
}
}
assert_eq!(3, Enum::Unit.tag());
assert_eq!(2, Enum::Tuple(5).tag());
assert_eq!(1, Enum::Struct{a: 7, b: 11}.tag());
```
"##,
},
LintCompletion {
label: "unboxed_closures",
description: r##"# `unboxed_closures`
The tracking issue for this feature is [#29625]
See Also: [`fn_traits`](../library-features/fn-traits.md)
[#29625]: https://github.com/rust-lang/rust/issues/29625
----
The `unboxed_closures` feature allows you to write functions using the `"rust-call"` ABI,
required for implementing the [`Fn*`] family of traits. `"rust-call"` functions must have
exactly one (non self) argument, a tuple representing the argument list.
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
```rust
#![feature(unboxed_closures)]
extern "rust-call" fn add_args(args: (u32, u32)) -> u32 {
args.0 + args.1
}
fn main() {}
```
"##,
},
LintCompletion {
label: "custom_test_frameworks",
description: r##"# `custom_test_frameworks`
The tracking issue for this feature is: [#50297]
[#50297]: https://github.com/rust-lang/rust/issues/50297
------------------------
The `custom_test_frameworks` feature allows the use of `#[test_case]` and `#![test_runner]`.
Any function, const, or static can be annotated with `#[test_case]` causing it to be aggregated (like `#[test]`)
and be passed to the test runner determined by the `#![test_runner]` crate attribute.
```rust
#![feature(custom_test_frameworks)]
#![test_runner(my_runner)]
fn my_runner(tests: &[&i32]) {
for t in tests {
if **t == 0 {
println!("PASSED");
} else {
println!("FAILED");
}
}
}
#[test_case]
const WILL_PASS: i32 = 0;
#[test_case]
const WILL_FAIL: i32 = 4;
```
"##,
},
LintCompletion {
label: "abi_msp430_interrupt",
description: r##"# `abi_msp430_interrupt`
The tracking issue for this feature is: [#38487]
[#38487]: https://github.com/rust-lang/rust/issues/38487
------------------------
In the MSP430 architecture, interrupt handlers have a special calling
convention. You can use the `"msp430-interrupt"` ABI to make the compiler apply
the right calling convention to the interrupt handlers you define.
<!-- NOTE(ignore) this example is specific to the msp430 target -->
``` rust,ignore
#![feature(abi_msp430_interrupt)]
#![no_std]
// Place the interrupt handler at the appropriate memory address
// (Alternatively, you can use `#[used]` and remove `pub` and `#[no_mangle]`)
#[link_section = "__interrupt_vector_10"]
#[no_mangle]
pub static TIM0_VECTOR: extern "msp430-interrupt" fn() = tim0;
// The interrupt handler
extern "msp430-interrupt" fn tim0() {
// ..
}
```
``` text
$ msp430-elf-objdump -CD ./target/msp430/release/app
Disassembly of section __interrupt_vector_10:
0000fff2 <TIM0_VECTOR>:
fff2: 00 c0 interrupt service routine at 0xc000
Disassembly of section .text:
0000c000 <int::tim0>:
c000: 00 13 reti
```
"##,
},
LintCompletion {
label: "impl_trait_in_bindings",
description: r##"# `impl_trait_in_bindings`
The tracking issue for this feature is: [#63065]
[#63065]: https://github.com/rust-lang/rust/issues/63065
------------------------
The `impl_trait_in_bindings` feature gate lets you use `impl Trait` syntax in
`let`, `static`, and `const` bindings.
A simple example is:
```rust
#![feature(impl_trait_in_bindings)]
use std::fmt::Debug;
fn main() {
let a: impl Debug + Clone = 42;
let b = a.clone();
println!("{:?}", b); // prints `42`
}
```
Note however that because the types of `a` and `b` are opaque in the above
example, calling inherent methods or methods outside of the specified traits
(e.g., `a.abs()` or `b.abs()`) is not allowed, and yields an error.
"##,
},
LintCompletion {
label: "cfg_version",
description: r##"# `cfg_version`
The tracking issue for this feature is: [#64796]
[#64796]: https://github.com/rust-lang/rust/issues/64796
------------------------
The `cfg_version` feature makes it possible to execute different code
depending on the compiler version.
## Examples
```rust
#![feature(cfg_version)]
#[cfg(version("1.42"))]
fn a() {
// ...
}
#[cfg(not(version("1.42")))]
fn a() {
// ...
}
fn b() {
if cfg!(version("1.42")) {
// ...
} else {
// ...
}
}
```
"##,
},
LintCompletion {
label: "link_cfg",
description: r##"# `link_cfg`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "infer_static_outlives_requirements",
description: r##"# `infer_static_outlives_requirements`
The tracking issue for this feature is: [#54185]
[#54185]: https://github.com/rust-lang/rust/issues/54185
------------------------
The `infer_static_outlives_requirements` feature indicates that certain
`'static` outlives requirements can be inferred by the compiler rather than
stating them explicitly.
Note: It is an accompanying feature to `infer_outlives_requirements`,
which must be enabled to infer outlives requirements.
For example, currently generic struct definitions that contain
references, require where-clauses of the form T: 'static. By using
this feature the outlives predicates will be inferred, although
they may still be written explicitly.
```rust,ignore (pseudo-Rust)
struct Foo<U> where U: 'static { // <-- currently required
bar: Bar<U>
}
struct Bar<T: 'static> {
x: T,
}
```
## Examples:
```rust,ignore (pseudo-Rust)
#![feature(infer_outlives_requirements)]
#![feature(infer_static_outlives_requirements)]
#[rustc_outlives]
// Implicitly infer U: 'static
struct Foo<U> {
bar: Bar<U>
}
struct Bar<T: 'static> {
x: T,
}
```
"##,
},
LintCompletion {
label: "marker_trait_attr",
description: r##"# `marker_trait_attr`
The tracking issue for this feature is: [#29864]
[#29864]: https://github.com/rust-lang/rust/issues/29864
------------------------
Normally, Rust keeps you from adding trait implementations that could
overlap with each other, as it would be ambiguous which to use. This
feature, however, carves out an exception to that rule: a trait can
opt-in to having overlapping implementations, at the cost that those
implementations are not allowed to override anything (and thus the
trait itself cannot have any associated items, as they're pointless
when they'd need to do the same thing for every type anyway).
```rust
#![feature(marker_trait_attr)]
#[marker] trait CheapToClone: Clone {}
impl<T: Copy> CheapToClone for T {}
// These could potentially overlap with the blanket implementation above,
// so are only allowed because CheapToClone is a marker trait.
impl<T: CheapToClone, U: CheapToClone> CheapToClone for (T, U) {}
impl<T: CheapToClone> CheapToClone for std::ops::Range<T> {}
fn cheap_clone<T: CheapToClone>(t: T) -> T {
t.clone()
}
```
This is expected to replace the unstable `overlapping_marker_traits`
feature, which applied to all empty traits (without needing an opt-in).
"##,
},
LintCompletion {
label: "doc_masked",
description: r##"# `doc_masked`
The tracking issue for this feature is: [#44027]
-----
The `doc_masked` feature allows a crate to exclude types from a given crate from appearing in lists
of trait implementations. The specifics of the feature are as follows:
1. When rustdoc encounters an `extern crate` statement annotated with a `#[doc(masked)]` attribute,
it marks the crate as being masked.
2. When listing traits a given type implements, rustdoc ensures that traits from masked crates are
not emitted into the documentation.
3. When listing types that implement a given trait, rustdoc ensures that types from masked crates
are not emitted into the documentation.
This feature was introduced in PR [#44026] to ensure that compiler-internal and
implementation-specific types and traits were not included in the standard library's documentation.
Such types would introduce broken links into the documentation.
[#44026]: https://github.com/rust-lang/rust/pull/44026
[#44027]: https://github.com/rust-lang/rust/pull/44027
"##,
},
LintCompletion {
label: "abi_ptx",
description: r##"# `abi_ptx`
The tracking issue for this feature is: [#38788]
[#38788]: https://github.com/rust-lang/rust/issues/38788
------------------------
When emitting PTX code, all vanilla Rust functions (`fn`) get translated to
"device" functions. These functions are *not* callable from the host via the
CUDA API so a crate with only device functions is not too useful!
OTOH, "global" functions *can* be called by the host; you can think of them
as the real public API of your crate. To produce a global function use the
`"ptx-kernel"` ABI.
<!-- NOTE(ignore) this example is specific to the nvptx targets -->
``` rust,ignore
#![feature(abi_ptx)]
#![no_std]
pub unsafe extern "ptx-kernel" fn global_function() {
device_function();
}
pub fn device_function() {
// ..
}
```
``` text
$ xargo rustc --target nvptx64-nvidia-cuda --release -- --emit=asm
$ cat $(find -name '*.s')
//
// Generated by LLVM NVPTX Back-End
//
.version 3.2
.target sm_20
.address_size 64
// .globl _ZN6kernel15global_function17h46111ebe6516b382E
.visible .entry _ZN6kernel15global_function17h46111ebe6516b382E()
{
ret;
}
// .globl _ZN6kernel15device_function17hd6a0e4993bbf3f78E
.visible .func _ZN6kernel15device_function17hd6a0e4993bbf3f78E()
{
ret;
}
```
"##,
},
LintCompletion {
label: "profiler_runtime",
description: r##"# `profiler_runtime`
The tracking issue for this feature is: [#42524](https://github.com/rust-lang/rust/issues/42524).
------------------------
"##,
},
LintCompletion {
label: "crate_visibility_modifier",
description: r##"# `crate_visibility_modifier`
The tracking issue for this feature is: [#53120]
[#53120]: https://github.com/rust-lang/rust/issues/53120
-----
The `crate_visibility_modifier` feature allows the `crate` keyword to be used
as a visibility modifier synonymous to `pub(crate)`, indicating that a type
(function, _&c._) is to be visible to the entire enclosing crate, but not to
other crates.
```rust
#![feature(crate_visibility_modifier)]
crate struct Foo {
bar: usize,
}
```
"##,
},
LintCompletion {
label: "doc_cfg",
description: r##"# `doc_cfg`
The tracking issue for this feature is: [#43781]
------
The `doc_cfg` feature allows an API be documented as only available in some specific platforms.
This attribute has two effects:
1. In the annotated item's documentation, there will be a message saying "This is supported on
(platform) only".
2. The item's doc-tests will only run on the specific platform.
In addition to allowing the use of the `#[doc(cfg)]` attribute, this feature enables the use of a
special conditional compilation flag, `#[cfg(doc)]`, set whenever building documentation on your
crate.
This feature was introduced as part of PR [#43348] to allow the platform-specific parts of the
standard library be documented.
```rust
#![feature(doc_cfg)]
#[cfg(any(windows, doc))]
#[doc(cfg(windows))]
/// The application's icon in the notification area (a.k.a. system tray).
///
/// # Examples
///
/// ```no_run
/// extern crate my_awesome_ui_library;
/// use my_awesome_ui_library::current_app;
/// use my_awesome_ui_library::windows::notification;
///
/// let icon = current_app().get::<notification::Icon>();
/// icon.show();
/// icon.show_message("Hello");
/// ```
pub struct Icon {
// ...
}
```
[#43781]: https://github.com/rust-lang/rust/issues/43781
[#43348]: https://github.com/rust-lang/rust/issues/43348
"##,
},
LintCompletion {
label: "unsized_tuple_coercion",
description: r##"# `unsized_tuple_coercion`
The tracking issue for this feature is: [#42877]
[#42877]: https://github.com/rust-lang/rust/issues/42877
------------------------
This is a part of [RFC0401]. According to the RFC, there should be an implementation like this:
```rust,ignore (partial-example)
impl<..., T, U: ?Sized> Unsized<(..., U)> for (..., T) where T: Unsized<U> {}
```
This implementation is currently gated behind `#[feature(unsized_tuple_coercion)]` to avoid insta-stability. Therefore you can use it like this:
```rust
#![feature(unsized_tuple_coercion)]
fn main() {
let x : ([i32; 3], [i32; 3]) = ([1, 2, 3], [4, 5, 6]);
let y : &([i32; 3], [i32]) = &x;
assert_eq!(y.1[0], 4);
}
```
[RFC0401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
"##,
},
LintCompletion {
label: "no_sanitize",
description: r##"# `no_sanitize`
The tracking issue for this feature is: [#39699]
[#39699]: https://github.com/rust-lang/rust/issues/39699
------------------------
The `no_sanitize` attribute can be used to selectively disable sanitizer
instrumentation in an annotated function. This might be useful to: avoid
instrumentation overhead in a performance critical function, or avoid
instrumenting code that contains constructs unsupported by given sanitizer.
The precise effect of this annotation depends on particular sanitizer in use.
For example, with `no_sanitize(thread)`, the thread sanitizer will no longer
instrument non-atomic store / load operations, but it will instrument atomic
operations to avoid reporting false positives and provide meaning full stack
traces.
## Examples
``` rust
#![feature(no_sanitize)]
#[no_sanitize(address)]
fn foo() {
// ...
}
```
"##,
},
LintCompletion {
label: "try_blocks",
description: r##"# `try_blocks`
The tracking issue for this feature is: [#31436]
[#31436]: https://github.com/rust-lang/rust/issues/31436
------------------------
The `try_blocks` feature adds support for `try` blocks. A `try`
block creates a new scope one can use the `?` operator in.
```rust,edition2018
#![feature(try_blocks)]
use std::num::ParseIntError;
let result: Result<i32, ParseIntError> = try {
"1".parse::<i32>()?
+ "2".parse::<i32>()?
+ "3".parse::<i32>()?
};
assert_eq!(result, Ok(6));
let result: Result<i32, ParseIntError> = try {
"1".parse::<i32>()?
+ "foo".parse::<i32>()?
+ "3".parse::<i32>()?
};
assert!(result.is_err());
```
"##,
},
LintCompletion {
label: "transparent_unions",
description: r##"# `transparent_unions`
The tracking issue for this feature is [#60405]
[#60405]: https://github.com/rust-lang/rust/issues/60405
----
The `transparent_unions` feature allows you mark `union`s as
`#[repr(transparent)]`. A `union` may be `#[repr(transparent)]` in exactly the
same conditions in which a `struct` may be `#[repr(transparent)]` (generally,
this means the `union` must have exactly one non-zero-sized field). Some
concrete illustrations follow.
```rust
#![feature(transparent_unions)]
// This union has the same representation as `f32`.
#[repr(transparent)]
union SingleFieldUnion {
field: f32,
}
// This union has the same representation as `usize`.
#[repr(transparent)]
union MultiFieldUnion {
field: usize,
nothing: (),
}
```
For consistency with transparent `struct`s, `union`s must have exactly one
non-zero-sized field. If all fields are zero-sized, the `union` must not be
`#[repr(transparent)]`:
```rust
#![feature(transparent_unions)]
// This (non-transparent) union is already valid in stable Rust:
pub union GoodUnion {
pub nothing: (),
}
// Error: transparent union needs exactly one non-zero-sized field, but has 0
// #[repr(transparent)]
// pub union BadUnion {
// pub nothing: (),
// }
```
The one exception is if the `union` is generic over `T` and has a field of type
`T`, it may be `#[repr(transparent)]` even if `T` is a zero-sized type:
```rust
#![feature(transparent_unions)]
// This union has the same representation as `T`.
#[repr(transparent)]
pub union GenericUnion<T: Copy> { // Unions with non-`Copy` fields are unstable.
pub field: T,
pub nothing: (),
}
// This is okay even though `()` is a zero-sized type.
pub const THIS_IS_OKAY: GenericUnion<()> = GenericUnion { field: () };
```
Like transarent `struct`s, a transparent `union` of type `U` has the same
layout, size, and ABI as its single non-ZST field. If it is generic over a type
`T`, and all its fields are ZSTs except for exactly one field of type `T`, then
it has the same layout and ABI as `T` (even if `T` is a ZST when monomorphized).
Like transparent `struct`s, transparent `union`s are FFI-safe if and only if
their underlying representation type is also FFI-safe.
A `union` may not be eligible for the same nonnull-style optimizations that a
`struct` or `enum` (with the same fields) are eligible for. Adding
`#[repr(transparent)]` to `union` does not change this. To give a more concrete
example, it is unspecified whether `size_of::<T>()` is equal to
`size_of::<Option<T>>()`, where `T` is a `union` (regardless of whether or not
it is transparent). The Rust compiler is free to perform this optimization if
possible, but is not required to, and different compiler versions may differ in
their application of these optimizations.
"##,
},
LintCompletion {
label: "const_eval_limit",
description: r##"# `const_eval_limit`
The tracking issue for this feature is: [#67217]
[#67217]: https://github.com/rust-lang/rust/issues/67217
The `const_eval_limit` allows someone to limit the evaluation steps the CTFE undertakes to evaluate a `const fn`.
"##,
},
LintCompletion {
label: "link_args",
description: r##"# `link_args`
The tracking issue for this feature is: [#29596]
[#29596]: https://github.com/rust-lang/rust/issues/29596
------------------------
You can tell `rustc` how to customize linking, and that is via the `link_args`
attribute. This attribute is applied to `extern` blocks and specifies raw flags
which need to get passed to the linker when producing an artifact. An example
usage would be:
```rust,no_run
#![feature(link_args)]
#[link_args = "-foo -bar -baz"]
extern "C" {}
# fn main() {}
```
Note that this feature is currently hidden behind the `feature(link_args)` gate
because this is not a sanctioned way of performing linking. Right now `rustc`
shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC), so
it makes sense to provide extra command line arguments, but this will not
always be the case. In the future `rustc` may use LLVM directly to link native
libraries, in which case `link_args` will have no meaning. You can achieve the
same effect as the `link_args` attribute with the `-C link-args` argument to
`rustc`.
It is highly recommended to *not* use this attribute, and rather use the more
formal `#[link(...)]` attribute on `extern` blocks instead.
"##,
},
LintCompletion {
label: "internal_output_capture",
description: r##"# `internal_output_capture`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "windows_handle",
description: r##"# `windows_handle`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "asm",
description: r##"# `asm`
The tracking issue for this feature is: [#72016]
[#72016]: https://github.com/rust-lang/rust/issues/72016
------------------------
For extremely low-level manipulations and performance reasons, one
might wish to control the CPU directly. Rust supports using inline
assembly to do this via the `asm!` macro.
# Guide-level explanation
[guide-level-explanation]: #guide-level-explanation
Rust provides support for inline assembly via the `asm!` macro.
It can be used to embed handwritten assembly in the assembly output generated by the compiler.
Generally this should not be necessary, but might be where the required performance or timing
cannot be otherwise achieved. Accessing low level hardware primitives, e.g. in kernel code, may also demand this functionality.
> **Note**: the examples here are given in x86/x86-64 assembly, but other architectures are also supported.
Inline assembly is currently supported on the following architectures:
- x86 and x86-64
- ARM
- AArch64
- RISC-V
- NVPTX
- Hexagon
- MIPS32r2 and MIPS64r2
- wasm32
## Basic usage
Let us start with the simplest possible example:
```rust,allow_fail
# #![feature(asm)]
unsafe {
asm!("nop");
}
```
This will insert a NOP (no operation) instruction into the assembly generated by the compiler.
Note that all `asm!` invocations have to be inside an `unsafe` block, as they could insert
arbitrary instructions and break various invariants. The instructions to be inserted are listed
in the first argument of the `asm!` macro as a string literal.
## Inputs and outputs
Now inserting an instruction that does nothing is rather boring. Let us do something that
actually acts on data:
```rust,allow_fail
# #![feature(asm)]
let x: u64;
unsafe {
asm!("mov {}, 5", out(reg) x);
}
assert_eq!(x, 5);
```
This will write the value `5` into the `u64` variable `x`.
You can see that the string literal we use to specify instructions is actually a template string.
It is governed by the same rules as Rust [format strings][format-syntax].
The arguments that are inserted into the template however look a bit different then you may
be familiar with. First we need to specify if the variable is an input or an output of the
inline assembly. In this case it is an output. We declared this by writing `out`.
We also need to specify in what kind of register the assembly expects the variable.
In this case we put it in an arbitrary general purpose register by specifying `reg`.
The compiler will choose an appropriate register to insert into
the template and will read the variable from there after the inline assembly finishes executing.
Let us see another example that also uses an input:
```rust,allow_fail
# #![feature(asm)]
let i: u64 = 3;
let o: u64;
unsafe {
asm!(
"mov {0}, {1}",
"add {0}, {number}",
out(reg) o,
in(reg) i,
number = const 5,
);
}
assert_eq!(o, 8);
```
This will add `5` to the input in variable `i` and write the result to variable `o`.
The particular way this assembly does this is first copying the value from `i` to the output,
and then adding `5` to it.
The example shows a few things:
First, we can see that `asm!` allows multiple template string arguments; each
one is treated as a separate line of assembly code, as if they were all joined
together with newlines between them. This makes it easy to format assembly
code.
Second, we can see that inputs are declared by writing `in` instead of `out`.
Third, one of our operands has a type we haven't seen yet, `const`.
This tells the compiler to expand this argument to value directly inside the assembly template.
This is only possible for constants and literals.
Fourth, we can see that we can specify an argument number, or name as in any format string.
For inline assembly templates this is particularly useful as arguments are often used more than once.
For more complex inline assembly using this facility is generally recommended, as it improves
readability, and allows reordering instructions without changing the argument order.
We can further refine the above example to avoid the `mov` instruction:
```rust,allow_fail
# #![feature(asm)]
let mut x: u64 = 3;
unsafe {
asm!("add {0}, {number}", inout(reg) x, number = const 5);
}
assert_eq!(x, 8);
```
We can see that `inout` is used to specify an argument that is both input and output.
This is different from specifying an input and output separately in that it is guaranteed to assign both to the same register.
It is also possible to specify different variables for the input and output parts of an `inout` operand:
```rust,allow_fail
# #![feature(asm)]
let x: u64 = 3;
let y: u64;
unsafe {
asm!("add {0}, {number}", inout(reg) x => y, number = const 5);
}
assert_eq!(y, 8);
```
## Late output operands
The Rust compiler is conservative with its allocation of operands. It is assumed that an `out`
can be written at any time, and can therefore not share its location with any other argument.
However, to guarantee optimal performance it is important to use as few registers as possible,
so they won't have to be saved and reloaded around the inline assembly block.
To achieve this Rust provides a `lateout` specifier. This can be used on any output that is
written only after all inputs have been consumed.
There is also a `inlateout` variant of this specifier.
Here is an example where `inlateout` *cannot* be used:
```rust,allow_fail
# #![feature(asm)]
let mut a: u64 = 4;
let b: u64 = 4;
let c: u64 = 4;
unsafe {
asm!(
"add {0}, {1}",
"add {0}, {2}",
inout(reg) a,
in(reg) b,
in(reg) c,
);
}
assert_eq!(a, 12);
```
Here the compiler is free to allocate the same register for inputs `b` and `c` since it knows they have the same value. However it must allocate a separate register for `a` since it uses `inout` and not `inlateout`. If `inlateout` was used, then `a` and `c` could be allocated to the same register, in which case the first instruction to overwrite the value of `c` and cause the assembly code to produce the wrong result.
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
```rust,allow_fail
# #![feature(asm)]
let mut a: u64 = 4;
let b: u64 = 4;
unsafe {
asm!("add {0}, {1}", inlateout(reg) a, in(reg) b);
}
assert_eq!(a, 8);
```
As you can see, this assembly fragment will still work correctly if `a` and `b` are assigned to the same register.
## Explicit register operands
Some instructions require that the operands be in a specific register.
Therefore, Rust inline assembly provides some more specific constraint specifiers.
While `reg` is generally available on any architecture, these are highly architecture specific. E.g. for x86 the general purpose registers `eax`, `ebx`, `ecx`, `edx`, `ebp`, `esi`, and `edi`
among others can be addressed by their name.
```rust,allow_fail,no_run
# #![feature(asm)]
let cmd = 0xd1;
unsafe {
asm!("out 0x64, eax", in("eax") cmd);
}
```
In this example we call the `out` instruction to output the content of the `cmd` variable
to port `0x64`. Since the `out` instruction only accepts `eax` (and its sub registers) as operand
we had to use the `eax` constraint specifier.
Note that unlike other operand types, explicit register operands cannot be used in the template string: you can't use `{}` and should write the register name directly instead. Also, they must appear at the end of the operand list after all other operand types.
Consider this example which uses the x86 `mul` instruction:
```rust,allow_fail
# #![feature(asm)]
fn mul(a: u64, b: u64) -> u128 {
let lo: u64;
let hi: u64;
unsafe {
asm!(
// The x86 mul instruction takes rax as an implicit input and writes
// the 128-bit result of the multiplication to rax:rdx.
"mul {}",
in(reg) a,
inlateout("rax") b => lo,
lateout("rdx") hi
);
}
((hi as u128) << 64) + lo as u128
}
```
This uses the `mul` instruction to multiply two 64-bit inputs with a 128-bit result.
The only explicit operand is a register, that we fill from the variable `a`.
The second operand is implicit, and must be the `rax` register, which we fill from the variable `b`.
The lower 64 bits of the result are stored in `rax` from which we fill the variable `lo`.
The higher 64 bits are stored in `rdx` from which we fill the variable `hi`.
## Clobbered registers
In many cases inline assembly will modify state that is not needed as an output.
Usually this is either because we have to use a scratch register in the assembly,
or instructions modify state that we don't need to further examine.
This state is generally referred to as being "clobbered".
We need to tell the compiler about this since it may need to save and restore this state
around the inline assembly block.
```rust,allow_fail
# #![feature(asm)]
let ebx: u32;
let ecx: u32;
unsafe {
asm!(
"cpuid",
// EAX 4 selects the "Deterministic Cache Parameters" CPUID leaf
inout("eax") 4 => _,
// ECX 0 selects the L0 cache information.
inout("ecx") 0 => ecx,
lateout("ebx") ebx,
lateout("edx") _,
);
}
println!(
"L1 Cache: {}",
((ebx >> 22) + 1) * (((ebx >> 12) & 0x3ff) + 1) * ((ebx & 0xfff) + 1) * (ecx + 1)
);
```
In the example above we use the `cpuid` instruction to get the L1 cache size.
This instruction writes to `eax`, `ebx`, `ecx`, and `edx`, but for the cache size we only care about the contents of `ebx` and `ecx`.
However we still need to tell the compiler that `eax` and `edx` have been modified so that it can save any values that were in these registers before the asm. This is done by declaring these as outputs but with `_` instead of a variable name, which indicates that the output value is to be discarded.
This can also be used with a general register class (e.g. `reg`) to obtain a scratch register for use inside the asm code:
```rust,allow_fail
# #![feature(asm)]
// Multiply x by 6 using shifts and adds
let mut x: u64 = 4;
unsafe {
asm!(
"mov {tmp}, {x}",
"shl {tmp}, 1",
"shl {x}, 2",
"add {x}, {tmp}",
x = inout(reg) x,
tmp = out(reg) _,
);
}
assert_eq!(x, 4 * 6);
```
## Symbol operands
A special operand type, `sym`, allows you to use the symbol name of a `fn` or `static` in inline assembly code.
This allows you to call a function or access a global variable without needing to keep its address in a register.
```rust,allow_fail
# #![feature(asm)]
extern "C" fn foo(arg: i32) {
println!("arg = {}", arg);
}
fn call_foo(arg: i32) {
unsafe {
asm!(
"call {}",
sym foo,
// 1st argument in rdi, which is caller-saved
inout("rdi") arg => _,
// All caller-saved registers must be marked as clobberred
out("rax") _, out("rcx") _, out("rdx") _, out("rsi") _,
out("r8") _, out("r9") _, out("r10") _, out("r11") _,
out("xmm0") _, out("xmm1") _, out("xmm2") _, out("xmm3") _,
out("xmm4") _, out("xmm5") _, out("xmm6") _, out("xmm7") _,
out("xmm8") _, out("xmm9") _, out("xmm10") _, out("xmm11") _,
out("xmm12") _, out("xmm13") _, out("xmm14") _, out("xmm15") _,
)
}
}
```
Note that the `fn` or `static` item does not need to be public or `#[no_mangle]`:
the compiler will automatically insert the appropriate mangled symbol name into the assembly code.
## Register template modifiers
In some cases, fine control is needed over the way a register name is formatted when inserted into the template string. This is needed when an architecture's assembly language has several names for the same register, each typically being a "view" over a subset of the register (e.g. the low 32 bits of a 64-bit register).
By default the compiler will always choose the name that refers to the full register size (e.g. `rax` on x86-64, `eax` on x86, etc).
This default can be overriden by using modifiers on the template string operands, just like you would with format strings:
```rust,allow_fail
# #![feature(asm)]
let mut x: u16 = 0xab;
unsafe {
asm!("mov {0:h}, {0:l}", inout(reg_abcd) x);
}
assert_eq!(x, 0xabab);
```
In this example, we use the `reg_abcd` register class to restrict the register allocator to the 4 legacy x86 register (`ax`, `bx`, `cx`, `dx`) of which the first two bytes can be addressed independently.
Let us assume that the register allocator has chosen to allocate `x` in the `ax` register.
The `h` modifier will emit the register name for the high byte of that register and the `l` modifier will emit the register name for the low byte. The asm code will therefore be expanded as `mov ah, al` which copies the low byte of the value into the high byte.
If you use a smaller data type (e.g. `u16`) with an operand and forget the use template modifiers, the compiler will emit a warning and suggest the correct modifier to use.
## Memory address operands
Sometimes assembly instructions require operands passed via memory addresses/memory locations.
You have to manually use the memory address syntax specified by the respectively architectures.
For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]`
to indicate they are memory operands:
```rust,allow_fail
# #![feature(asm, llvm_asm)]
# fn load_fpu_control_word(control: u16) {
unsafe {
asm!("fldcw [{}]", in(reg) &control, options(nostack));
// Previously this would have been written with the deprecated `llvm_asm!` like this
llvm_asm!("fldcw $0" :: "m" (control) :: "volatile");
}
# }
```
## Options
By default, an inline assembly block is treated the same way as an external FFI function call with a custom calling convention: it may read/write memory, have observable side effects, etc. However in many cases, it is desirable to give the compiler more information about what the assembly code is actually doing so that it can optimize better.
Let's take our previous example of an `add` instruction:
```rust,allow_fail
# #![feature(asm)]
let mut a: u64 = 4;
let b: u64 = 4;
unsafe {
asm!(
"add {0}, {1}",
inlateout(reg) a, in(reg) b,
options(pure, nomem, nostack),
);
}
assert_eq!(a, 8);
```
Options can be provided as an optional final argument to the `asm!` macro. We specified three options here:
- `pure` means that the asm code has no observable side effects and that its output depends only on its inputs. This allows the compiler optimizer to call the inline asm fewer times or even eliminate it entirely.
- `nomem` means that the asm code does not read or write to memory. By default the compiler will assume that inline assembly can read or write any memory address that is accessible to it (e.g. through a pointer passed as an operand, or a global).
- `nostack` means that the asm code does not push any data onto the stack. This allows the compiler to use optimizations such as the stack red zone on x86-64 to avoid stack pointer adjustments.
These allow the compiler to better optimize code using `asm!`, for example by eliminating pure `asm!` blocks whose outputs are not needed.
See the reference for the full list of available options and their effects.
# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation
Inline assembler is implemented as an unsafe macro `asm!()`.
The first argument to this macro is a template string literal used to build the final assembly.
The following arguments specify input and output operands.
When required, options are specified as the final argument.
The following ABNF specifies the general syntax:
```text
dir_spec := "in" / "out" / "lateout" / "inout" / "inlateout"
reg_spec := <register class> / "<explicit register>"
operand_expr := expr / "_" / expr "=>" expr / expr "=>" "_"
reg_operand := dir_spec "(" reg_spec ")" operand_expr
operand := reg_operand / "const" const_expr / "sym" path
option := "pure" / "nomem" / "readonly" / "preserves_flags" / "noreturn" / "nostack" / "att_syntax"
options := "options(" option *["," option] [","] ")"
asm := "asm!(" format_string *("," format_string) *("," [ident "="] operand) ["," options] [","] ")"
```
The macro will initially be supported only on ARM, AArch64, Hexagon, x86, x86-64 and RISC-V targets. Support for more targets may be added in the future. The compiler will emit an error if `asm!` is used on an unsupported target.
[format-syntax]: https://doc.rust-lang.org/std/fmt/#syntax
## Template string arguments
The assembler template uses the same syntax as [format strings][format-syntax] (i.e. placeholders are specified by curly braces). The corresponding arguments are accessed in order, by index, or by name. However, implicit named arguments (introduced by [RFC #2795][rfc-2795]) are not supported.
An `asm!` invocation may have one or more template string arguments; an `asm!` with multiple template string arguments is treated as if all the strings were concatenated with a `\n` between them. The expected usage is for each template string argument to correspond to a line of assembly code. All template string arguments must appear before any other arguments.
As with format strings, named arguments must appear after positional arguments. Explicit register operands must appear at the end of the operand list, after named arguments if any.
Explicit register operands cannot be used by placeholders in the template string. All other named and positional operands must appear at least once in the template string, otherwise a compiler error is generated.
The exact assembly code syntax is target-specific and opaque to the compiler except for the way operands are substituted into the template string to form the code passed to the assembler.
The 5 targets specified in this RFC (x86, ARM, AArch64, RISC-V, Hexagon) all use the assembly code syntax of the GNU assembler (GAS). On x86, the `.intel_syntax noprefix` mode of GAS is used by default. On ARM, the `.syntax unified` mode is used. These targets impose an additional restriction on the assembly code: any assembler state (e.g. the current section which can be changed with `.section`) must be restored to its original value at the end of the asm string. Assembly code that does not conform to the GAS syntax will result in assembler-specific behavior.
[rfc-2795]: https://github.com/rust-lang/rfcs/pull/2795
## Operand type
Several types of operands are supported:
* `in(<reg>) <expr>`
- `<reg>` can refer to a register class or an explicit register. The allocated register name is substituted into the asm template string.
- The allocated register will contain the value of `<expr>` at the start of the asm code.
- The allocated register must contain the same value at the end of the asm code (except if a `lateout` is allocated to the same register).
* `out(<reg>) <expr>`
- `<reg>` can refer to a register class or an explicit register. The allocated register name is substituted into the asm template string.
- The allocated register will contain an undefined value at the start of the asm code.
- `<expr>` must be a (possibly uninitialized) place expression, to which the contents of the allocated register is written to at the end of the asm code.
- An underscore (`_`) may be specified instead of an expression, which will cause the contents of the register to be discarded at the end of the asm code (effectively acting as a clobber).
* `lateout(<reg>) <expr>`
- Identical to `out` except that the register allocator can reuse a register allocated to an `in`.
- You should only write to the register after all inputs are read, otherwise you may clobber an input.
* `inout(<reg>) <expr>`
- `<reg>` can refer to a register class or an explicit register. The allocated register name is substituted into the asm template string.
- The allocated register will contain the value of `<expr>` at the start of the asm code.
- `<expr>` must be a mutable initialized place expression, to which the contents of the allocated register is written to at the end of the asm code.
* `inout(<reg>) <in expr> => <out expr>`
- Same as `inout` except that the initial value of the register is taken from the value of `<in expr>`.
- `<out expr>` must be a (possibly uninitialized) place expression, to which the contents of the allocated register is written to at the end of the asm code.
- An underscore (`_`) may be specified instead of an expression for `<out expr>`, which will cause the contents of the register to be discarded at the end of the asm code (effectively acting as a clobber).
- `<in expr>` and `<out expr>` may have different types.
* `inlateout(<reg>) <expr>` / `inlateout(<reg>) <in expr> => <out expr>`
- Identical to `inout` except that the register allocator can reuse a register allocated to an `in` (this can happen if the compiler knows the `in` has the same initial value as the `inlateout`).
- You should only write to the register after all inputs are read, otherwise you may clobber an input.
* `const <expr>`
- `<expr>` must be an integer or floating-point constant expression.
- The value of the expression is formatted as a string and substituted directly into the asm template string.
* `sym <path>`
- `<path>` must refer to a `fn` or `static`.
- A mangled symbol name referring to the item is substituted into the asm template string.
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
- `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.
Operand expressions are evaluated from left to right, just like function call arguments. After the `asm!` has executed, outputs are written to in left to right order. This is significant if two outputs point to the same place: that place will contain the value of the rightmost output.
## Register operands
Input and output operands can be specified either as an explicit register or as a register class from which the register allocator can select a register. Explicit registers are specified as string literals (e.g. `"eax"`) while register classes are specified as identifiers (e.g. `reg`). Using string literals for register names enables support for architectures that use special characters in register names, such as MIPS (`$0`, `$1`, etc).
Note that explicit registers treat register aliases (e.g. `r14` vs `lr` on ARM) and smaller views of a register (e.g. `eax` vs `rax`) as equivalent to the base register. It is a compile-time error to use the same explicit register for two input operands or two output operands. Additionally, it is also a compile-time error to use overlapping registers (e.g. ARM VFP) in input operands or in output operands.
Only the following types are allowed as operands for inline assembly:
- Integers (signed and unsigned)
- Floating-point numbers
- Pointers (thin only)
- Function pointers
- SIMD vectors (structs defined with `#[repr(simd)]` and which implement `Copy`). This includes architecture-specific vector types defined in `std::arch` such as `__m128` (x86) or `int8x16_t` (ARM).
Here is the list of currently supported register classes:
| Architecture | Register class | Registers | LLVM constraint code |
| ------------ | -------------- | --------- | -------------------- |
| x86 | `reg` | `ax`, `bx`, `cx`, `dx`, `si`, `di`, `r[8-15]` (x86-64 only) | `r` |
| x86 | `reg_abcd` | `ax`, `bx`, `cx`, `dx` | `Q` |
| x86-32 | `reg_byte` | `al`, `bl`, `cl`, `dl`, `ah`, `bh`, `ch`, `dh` | `q` |
| x86-64 | `reg_byte` | `al`, `bl`, `cl`, `dl`, `sil`, `dil`, `r[8-15]b`, `ah`\*, `bh`\*, `ch`\*, `dh`\* | `q` |
| x86 | `xmm_reg` | `xmm[0-7]` (x86) `xmm[0-15]` (x86-64) | `x` |
| x86 | `ymm_reg` | `ymm[0-7]` (x86) `ymm[0-15]` (x86-64) | `x` |
| x86 | `zmm_reg` | `zmm[0-7]` (x86) `zmm[0-31]` (x86-64) | `v` |
| x86 | `kreg` | `k[1-7]` | `Yk` |
| AArch64 | `reg` | `x[0-28]`, `x30` | `r` |
| AArch64 | `vreg` | `v[0-31]` | `w` |
| AArch64 | `vreg_low16` | `v[0-15]` | `x` |
| ARM | `reg` | `r[0-5]` `r7`\*, `r[8-10]`, `r11`\*, `r12`, `r14` | `r` |
| ARM (Thumb) | `reg_thumb` | `r[0-r7]` | `l` |
| ARM (ARM) | `reg_thumb` | `r[0-r10]`, `r12`, `r14` | `l` |
| ARM | `sreg` | `s[0-31]` | `t` |
| ARM | `sreg_low16` | `s[0-15]` | `x` |
| ARM | `dreg` | `d[0-31]` | `w` |
| ARM | `dreg_low16` | `d[0-15]` | `t` |
| ARM | `dreg_low8` | `d[0-8]` | `x` |
| ARM | `qreg` | `q[0-15]` | `w` |
| ARM | `qreg_low8` | `q[0-7]` | `t` |
| ARM | `qreg_low4` | `q[0-3]` | `x` |
| MIPS | `reg` | `$[2-25]` | `r` |
| MIPS | `freg` | `$f[0-31]` | `f` |
| NVPTX | `reg16` | None\* | `h` |
| NVPTX | `reg32` | None\* | `r` |
| NVPTX | `reg64` | None\* | `l` |
| RISC-V | `reg` | `x1`, `x[5-7]`, `x[9-15]`, `x[16-31]` (non-RV32E) | `r` |
| RISC-V | `freg` | `f[0-31]` | `f` |
| Hexagon | `reg` | `r[0-28]` | `r` |
| wasm32 | `local` | None\* | `r` |
> **Note**: On x86 we treat `reg_byte` differently from `reg` because the compiler can allocate `al` and `ah` separately whereas `reg` reserves the whole register.
>
> Note #2: On x86-64 the high byte registers (e.g. `ah`) are only available when used as an explicit register. Specifying the `reg_byte` register class for an operand will always allocate a low byte register.
>
> Note #3: NVPTX doesn't have a fixed register set, so named registers are not supported.
>
> Note #4: On ARM the frame pointer is either `r7` or `r11` depending on the platform.
>
> Note #5: WebAssembly doesn't have registers, so named registers are not supported.
Additional register classes may be added in the future based on demand (e.g. MMX, x87, etc).
Each register class has constraints on which value types they can be used with. This is necessary because the way a value is loaded into a register depends on its type. For example, on big-endian systems, loading a `i32x4` and a `i8x16` into a SIMD register may result in different register contents even if the byte-wise memory representation of both values is identical. The availability of supported types for a particular register class may depend on what target features are currently enabled.
| Architecture | Register class | Target feature | Allowed types |
| ------------ | -------------- | -------------- | ------------- |
| x86-32 | `reg` | None | `i16`, `i32`, `f32` |
| x86-64 | `reg` | None | `i16`, `i32`, `f32`, `i64`, `f64` |
| x86 | `reg_byte` | None | `i8` |
| x86 | `xmm_reg` | `sse` | `i32`, `f32`, `i64`, `f64`, <br> `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` |
| x86 | `ymm_reg` | `avx` | `i32`, `f32`, `i64`, `f64`, <br> `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` <br> `i8x32`, `i16x16`, `i32x8`, `i64x4`, `f32x8`, `f64x4` |
| x86 | `zmm_reg` | `avx512f` | `i32`, `f32`, `i64`, `f64`, <br> `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` <br> `i8x32`, `i16x16`, `i32x8`, `i64x4`, `f32x8`, `f64x4` <br> `i8x64`, `i16x32`, `i32x16`, `i64x8`, `f32x16`, `f64x8` |
| x86 | `kreg` | `axv512f` | `i8`, `i16` |
| x86 | `kreg` | `axv512bw` | `i32`, `i64` |
| AArch64 | `reg` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
| AArch64 | `vreg` | `fp` | `i8`, `i16`, `i32`, `f32`, `i64`, `f64`, <br> `i8x8`, `i16x4`, `i32x2`, `i64x1`, `f32x2`, `f64x1`, <br> `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` |
| ARM | `reg` | None | `i8`, `i16`, `i32`, `f32` |
| ARM | `sreg` | `vfp2` | `i32`, `f32` |
| ARM | `dreg` | `vfp2` | `i64`, `f64`, `i8x8`, `i16x4`, `i32x2`, `i64x1`, `f32x2` |
| ARM | `qreg` | `neon` | `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4` |
| MIPS32 | `reg` | None | `i8`, `i16`, `i32`, `f32` |
| MIPS32 | `freg` | None | `f32`, `f64` |
| MIPS64 | `reg` | None | `i8`, `i16`, `i32`, `i64`, `f32`, `f64` |
| MIPS64 | `freg` | None | `f32`, `f64` |
| NVPTX | `reg16` | None | `i8`, `i16` |
| NVPTX | `reg32` | None | `i8`, `i16`, `i32`, `f32` |
| NVPTX | `reg64` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
| RISC-V32 | `reg` | None | `i8`, `i16`, `i32`, `f32` |
| RISC-V64 | `reg` | None | `i8`, `i16`, `i32`, `f32`, `i64`, `f64` |
| RISC-V | `freg` | `f` | `f32` |
| RISC-V | `freg` | `d` | `f64` |
| Hexagon | `reg` | None | `i8`, `i16`, `i32`, `f32` |
| wasm32 | `local` | None | `i8` `i16` `i32` `i64` `f32` `f64` |
> **Note**: For the purposes of the above table pointers, function pointers and `isize`/`usize` are treated as the equivalent integer type (`i16`/`i32`/`i64` depending on the target).
If a value is of a smaller size than the register it is allocated in then the upper bits of that register will have an undefined value for inputs and will be ignored for outputs. The only exception is the `freg` register class on RISC-V where `f32` values are NaN-boxed in a `f64` as required by the RISC-V architecture.
When separate input and output expressions are specified for an `inout` operand, both expressions must have the same type. The only exception is if both operands are pointers or integers, in which case they are only required to have the same size. This restriction exists because the register allocators in LLVM and GCC sometimes cannot handle tied operands with different types.
## Register names
Some registers have multiple names. These are all treated by the compiler as identical to the base register name. Here is the list of all supported register aliases:
| Architecture | Base register | Aliases |
| ------------ | ------------- | ------- |
| x86 | `ax` | `eax`, `rax` |
| x86 | `bx` | `ebx`, `rbx` |
| x86 | `cx` | `ecx`, `rcx` |
| x86 | `dx` | `edx`, `rdx` |
| x86 | `si` | `esi`, `rsi` |
| x86 | `di` | `edi`, `rdi` |
| x86 | `bp` | `bpl`, `ebp`, `rbp` |
| x86 | `sp` | `spl`, `esp`, `rsp` |
| x86 | `ip` | `eip`, `rip` |
| x86 | `st(0)` | `st` |
| x86 | `r[8-15]` | `r[8-15]b`, `r[8-15]w`, `r[8-15]d` |
| x86 | `xmm[0-31]` | `ymm[0-31]`, `zmm[0-31]` |
| AArch64 | `x[0-30]` | `w[0-30]` |
| AArch64 | `x29` | `fp` |
| AArch64 | `x30` | `lr` |
| AArch64 | `sp` | `wsp` |
| AArch64 | `xzr` | `wzr` |
| AArch64 | `v[0-31]` | `b[0-31]`, `h[0-31]`, `s[0-31]`, `d[0-31]`, `q[0-31]` |
| ARM | `r[0-3]` | `a[1-4]` |
| ARM | `r[4-9]` | `v[1-6]` |
| ARM | `r9` | `rfp` |
| ARM | `r10` | `sl` |
| ARM | `r11` | `fp` |
| ARM | `r12` | `ip` |
| ARM | `r13` | `sp` |
| ARM | `r14` | `lr` |
| ARM | `r15` | `pc` |
| RISC-V | `x0` | `zero` |
| RISC-V | `x1` | `ra` |
| RISC-V | `x2` | `sp` |
| RISC-V | `x3` | `gp` |
| RISC-V | `x4` | `tp` |
| RISC-V | `x[5-7]` | `t[0-2]` |
| RISC-V | `x8` | `fp`, `s0` |
| RISC-V | `x9` | `s1` |
| RISC-V | `x[10-17]` | `a[0-7]` |
| RISC-V | `x[18-27]` | `s[2-11]` |
| RISC-V | `x[28-31]` | `t[3-6]` |
| RISC-V | `f[0-7]` | `ft[0-7]` |
| RISC-V | `f[8-9]` | `fs[0-1]` |
| RISC-V | `f[10-17]` | `fa[0-7]` |
| RISC-V | `f[18-27]` | `fs[2-11]` |
| RISC-V | `f[28-31]` | `ft[8-11]` |
| Hexagon | `r29` | `sp` |
| Hexagon | `r30` | `fr` |
| Hexagon | `r31` | `lr` |
Some registers cannot be used for input or output operands:
| Architecture | Unsupported register | Reason |
| ------------ | -------------------- | ------ |
| All | `sp` | The stack pointer must be restored to its original value at the end of an asm code block. |
| All | `bp` (x86), `x29` (AArch64), `x8` (RISC-V), `fr` (Hexagon), `$fp` (MIPS) | The frame pointer cannot be used as an input or output. |
| ARM | `r7` or `r11` | On ARM the frame pointer can be either `r7` or `r11` depending on the target. The frame pointer cannot be used as an input or output. |
| ARM | `r6` | `r6` is used internally by LLVM as a base pointer and therefore cannot be used as an input or output. |
| x86 | `k0` | This is a constant zero register which can't be modified. |
| x86 | `ip` | This is the program counter, not a real register. |
| x86 | `mm[0-7]` | MMX registers are not currently supported (but may be in the future). |
| x86 | `st([0-7])` | x87 registers are not currently supported (but may be in the future). |
| AArch64 | `xzr` | This is a constant zero register which can't be modified. |
| ARM | `pc` | This is the program counter, not a real register. |
| MIPS | `$0` or `$zero` | This is a constant zero register which can't be modified. |
| MIPS | `$1` or `$at` | Reserved for assembler. |
| MIPS | `$26`/`$k0`, `$27`/`$k1` | OS-reserved registers. |
| MIPS | `$28`/`$gp` | Global pointer cannot be used as inputs or outputs. |
| MIPS | `$ra` | Return address cannot be used as inputs or outputs. |
| RISC-V | `x0` | This is a constant zero register which can't be modified. |
| RISC-V | `gp`, `tp` | These registers are reserved and cannot be used as inputs or outputs. |
| Hexagon | `lr` | This is the link register which cannot be used as an input or output. |
In some cases LLVM will allocate a "reserved register" for `reg` operands even though this register cannot be explicitly specified. Assembly code making use of reserved registers should be careful since `reg` operands may alias with those registers. Reserved registers are:
- The frame pointer on all architectures.
- `r6` on ARM.
## Template modifiers
The placeholders can be augmented by modifiers which are specified after the `:` in the curly braces. These modifiers do not affect register allocation, but change the way operands are formatted when inserted into the template string. Only one modifier is allowed per template placeholder.
The supported modifiers are a subset of LLVM's (and GCC's) [asm template argument modifiers][llvm-argmod], but do not use the same letter codes.
| Architecture | Register class | Modifier | Example output | LLVM modifier |
| ------------ | -------------- | -------- | -------------- | ------------- |
| x86-32 | `reg` | None | `eax` | `k` |
| x86-64 | `reg` | None | `rax` | `q` |
| x86-32 | `reg_abcd` | `l` | `al` | `b` |
| x86-64 | `reg` | `l` | `al` | `b` |
| x86 | `reg_abcd` | `h` | `ah` | `h` |
| x86 | `reg` | `x` | `ax` | `w` |
| x86 | `reg` | `e` | `eax` | `k` |
| x86-64 | `reg` | `r` | `rax` | `q` |
| x86 | `reg_byte` | None | `al` / `ah` | None |
| x86 | `xmm_reg` | None | `xmm0` | `x` |
| x86 | `ymm_reg` | None | `ymm0` | `t` |
| x86 | `zmm_reg` | None | `zmm0` | `g` |
| x86 | `*mm_reg` | `x` | `xmm0` | `x` |
| x86 | `*mm_reg` | `y` | `ymm0` | `t` |
| x86 | `*mm_reg` | `z` | `zmm0` | `g` |
| x86 | `kreg` | None | `k1` | None |
| AArch64 | `reg` | None | `x0` | `x` |
| AArch64 | `reg` | `w` | `w0` | `w` |
| AArch64 | `reg` | `x` | `x0` | `x` |
| AArch64 | `vreg` | None | `v0` | None |
| AArch64 | `vreg` | `v` | `v0` | None |
| AArch64 | `vreg` | `b` | `b0` | `b` |
| AArch64 | `vreg` | `h` | `h0` | `h` |
| AArch64 | `vreg` | `s` | `s0` | `s` |
| AArch64 | `vreg` | `d` | `d0` | `d` |
| AArch64 | `vreg` | `q` | `q0` | `q` |
| ARM | `reg` | None | `r0` | None |
| ARM | `sreg` | None | `s0` | None |
| ARM | `dreg` | None | `d0` | `P` |
| ARM | `qreg` | None | `q0` | `q` |
| ARM | `qreg` | `e` / `f` | `d0` / `d1` | `e` / `f` |
| MIPS | `reg` | None | `$2` | None |
| MIPS | `freg` | None | `$f0` | None |
| NVPTX | `reg16` | None | `rs0` | None |
| NVPTX | `reg32` | None | `r0` | None |
| NVPTX | `reg64` | None | `rd0` | None |
| RISC-V | `reg` | None | `x1` | None |
| RISC-V | `freg` | None | `f0` | None |
| Hexagon | `reg` | None | `r0` | None |
> Notes:
> - on ARM `e` / `f`: this prints the low or high doubleword register name of a NEON quad (128-bit) register.
> - on x86: our behavior for `reg` with no modifiers differs from what GCC does. GCC will infer the modifier based on the operand value type, while we default to the full register size.
> - on x86 `xmm_reg`: the `x`, `t` and `g` LLVM modifiers are not yet implemented in LLVM (they are supported by GCC only), but this should be a simple change.
As stated in the previous section, passing an input value smaller than the register width will result in the upper bits of the register containing undefined values. This is not a problem if the inline asm only accesses the lower bits of the register, which can be done by using a template modifier to use a subregister name in the asm code (e.g. `ax` instead of `rax`). Since this an easy pitfall, the compiler will suggest a template modifier to use where appropriate given the input type. If all references to an operand already have modifiers then the warning is suppressed for that operand.
[llvm-argmod]: http://llvm.org/docs/LangRef.html#asm-template-argument-modifiers
## Options
Flags are used to further influence the behavior of the inline assembly block.
Currently the following options are defined:
- `pure`: The `asm` block has no side effects, and its outputs depend only on its direct inputs (i.e. the values themselves, not what they point to) or values read from memory (unless the `nomem` options is also set). This allows the compiler to execute the `asm` block fewer times than specified in the program (e.g. by hoisting it out of a loop) or even eliminate it entirely if the outputs are not used.
- `nomem`: The `asm` blocks does not read or write to any memory. This allows the compiler to cache the values of modified global variables in registers across the `asm` block since it knows that they are not read or written to by the `asm`.
- `readonly`: The `asm` block does not write to any memory. This allows the compiler to cache the values of unmodified global variables in registers across the `asm` block since it knows that they are not written to by the `asm`.
- `preserves_flags`: The `asm` block does not modify the flags register (defined in the rules below). This allows the compiler to avoid recomputing the condition flags after the `asm` block.
- `noreturn`: The `asm` block never returns, and its return type is defined as `!` (never). Behavior is undefined if execution falls through past the end of the asm code. A `noreturn` asm block behaves just like a function which doesn't return; notably, local variables in scope are not dropped before it is invoked.
- `nostack`: The `asm` block does not push data to the stack, or write to the stack red-zone (if supported by the target). If this option is *not* used then the stack pointer is guaranteed to be suitably aligned (according to the target ABI) for a function call.
- `att_syntax`: This option is only valid on x86, and causes the assembler to use the `.att_syntax prefix` mode of the GNU assembler. Register operands are substituted in with a leading `%`.
The compiler performs some additional checks on options:
- The `nomem` and `readonly` options are mutually exclusive: it is a compile-time error to specify both.
- The `pure` option must be combined with either the `nomem` or `readonly` options, otherwise a compile-time error is emitted.
- It is a compile-time error to specify `pure` on an asm block with no outputs or only discarded outputs (`_`).
- It is a compile-time error to specify `noreturn` on an asm block with outputs.
## Rules for inline assembly
- Any registers not specified as inputs will contain an undefined value on entry to the asm block.
- An "undefined value" in the context of inline assembly means that the register can (non-deterministically) have any one of the possible values allowed by the architecture. Notably it is not the same as an LLVM `undef` which can have a different value every time you read it (since such a concept does not exist in assembly code).
- Any registers not specified as outputs must have the same value upon exiting the asm block as they had on entry, otherwise behavior is undefined.
- This only applies to registers which can be specified as an input or output. Other registers follow target-specific rules.
- Note that a `lateout` may be allocated to the same register as an `in`, in which case this rule does not apply. Code should not rely on this however since it depends on the results of register allocation.
- Behavior is undefined if execution unwinds out of an asm block.
- This also applies if the assembly code calls a function which then unwinds.
- The set of memory locations that assembly code is allowed the read and write are the same as those allowed for an FFI function.
- Refer to the unsafe code guidelines for the exact rules.
- If the `readonly` option is set, then only memory reads are allowed.
- If the `nomem` option is set then no reads or writes to memory are allowed.
- These rules do not apply to memory which is private to the asm code, such as stack space allocated within the asm block.
- The compiler cannot assume that the instructions in the asm are the ones that will actually end up executed.
- This effectively means that the compiler must treat the `asm!` as a black box and only take the interface specification into account, not the instructions themselves.
- Runtime code patching is allowed, via target-specific mechanisms (outside the scope of this RFC).
- Unless the `nostack` option is set, asm code is allowed to use stack space below the stack pointer.
- On entry to the asm block the stack pointer is guaranteed to be suitably aligned (according to the target ABI) for a function call.
- You are responsible for making sure you don't overflow the stack (e.g. use stack probing to ensure you hit a guard page).
- You should adjust the stack pointer when allocating stack memory as required by the target ABI.
- The stack pointer must be restored to its original value before leaving the asm block.
- If the `noreturn` option is set then behavior is undefined if execution falls through to the end of the asm block.
- If the `pure` option is set then behavior is undefined if the `asm` has side-effects other than its direct outputs. Behavior is also undefined if two executions of the `asm` code with the same inputs result in different outputs.
- When used with the `nomem` option, "inputs" are just the direct inputs of the `asm!`.
- When used with the `readonly` option, "inputs" comprise the direct inputs of the `asm!` and any memory that the `asm!` block is allowed to read.
- These flags registers must be restored upon exiting the asm block if the `preserves_flags` option is set:
- x86
- Status flags in `EFLAGS` (CF, PF, AF, ZF, SF, OF).
- Floating-point status word (all).
- Floating-point exception flags in `MXCSR` (PE, UE, OE, ZE, DE, IE).
- ARM
- Condition flags in `CPSR` (N, Z, C, V)
- Saturation flag in `CPSR` (Q)
- Greater than or equal flags in `CPSR` (GE).
- Condition flags in `FPSCR` (N, Z, C, V)
- Saturation flag in `FPSCR` (QC)
- Floating-point exception flags in `FPSCR` (IDC, IXC, UFC, OFC, DZC, IOC).
- AArch64
- Condition flags (`NZCV` register).
- Floating-point status (`FPSR` register).
- RISC-V
- Floating-point exception flags in `fcsr` (`fflags`).
- On x86, the direction flag (DF in `EFLAGS`) is clear on entry to an asm block and must be clear on exit.
- Behavior is undefined if the direction flag is set on exiting an asm block.
- The requirement of restoring the stack pointer and non-output registers to their original value only applies when exiting an `asm!` block.
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
- When returning to a different `asm!` block than you entered (e.g. for context switching), these registers must contain the value they had upon entering the `asm!` block that you are *exiting*.
- You cannot exit an `asm!` block that has not been entered. Neither can you exit an `asm!` block that has already been exited.
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
- You cannot assume that an `asm!` block will appear exactly once in the output binary. The compiler is allowed to instantiate multiple copies of the `asm!` block, for example when the function containing it is inlined in multiple places.
- As a consequence, you should only use [local labels] inside inline assembly code. Defining symbols in assembly code may lead to assembler and/or linker errors due to duplicate symbol definitions.
> **Note**: As a general rule, the flags covered by `preserves_flags` are those which are *not* preserved when performing a function call.
[local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
"##,
},
LintCompletion {
label: "flt2dec",
description: r##"# `flt2dec`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "global_asm",
description: r##"# `global_asm`
The tracking issue for this feature is: [#35119]
[#35119]: https://github.com/rust-lang/rust/issues/35119
------------------------
The `global_asm!` macro allows the programmer to write arbitrary
assembly outside the scope of a function body, passing it through
`rustc` and `llvm` to the assembler. The macro is a no-frills
interface to LLVM's concept of [module-level inline assembly]. That is,
all caveats applicable to LLVM's module-level inline assembly apply
to `global_asm!`.
[module-level inline assembly]: http://llvm.org/docs/LangRef.html#module-level-inline-assembly
`global_asm!` fills a role not currently satisfied by either `asm!`
or `#[naked]` functions. The programmer has _all_ features of the
assembler at their disposal. The linker will expect to resolve any
symbols defined in the inline assembly, modulo any symbols marked as
external. It also means syntax for directives and assembly follow the
conventions of the assembler in your toolchain.
A simple usage looks like this:
```rust,ignore (requires-external-file)
#![feature(global_asm)]
# // you also need relevant target_arch cfgs
global_asm!(include_str!("something_neato.s"));
```
And a more complicated usage looks like this:
```rust,no_run
#![feature(global_asm)]
# #[cfg(any(target_arch="x86", target_arch="x86_64"))]
# mod x86 {
pub mod sally {
global_asm!(r#"
.global foo
foo:
jmp baz
"#);
#[no_mangle]
pub unsafe extern "C" fn baz() {}
}
// the symbols `foo` and `bar` are global, no matter where
// `global_asm!` was used.
extern "C" {
fn foo();
fn bar();
}
pub mod harry {
global_asm!(r#"
.global bar
bar:
jmp quux
"#);
#[no_mangle]
pub unsafe extern "C" fn quux() {}
}
# }
```
You may use `global_asm!` multiple times, anywhere in your crate, in
whatever way suits you. The effect is as if you concatenated all
usages and placed the larger, single usage in the crate root.
------------------------
If you don't need quite as much power and flexibility as
`global_asm!` provides, and you don't mind restricting your inline
assembly to `fn` bodies only, you might try the
[asm](asm.md) feature instead.
"##,
},
LintCompletion {
label: "derive_eq",
description: r##"# `derive_eq`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "default_free_fn",
description: r##"# `default_free_fn`
The tracking issue for this feature is: [#73014]
[#73014]: https://github.com/rust-lang/rust/issues/73014
------------------------
Adds a free `default()` function to the `std::default` module. This function
just forwards to [`Default::default()`], but may remove repetition of the word
"default" from the call site.
[`Default::default()`]: https://doc.rust-lang.org/nightly/std/default/trait.Default.html#tymethod.default
Here is an example:
```rust
#![feature(default_free_fn)]
use std::default::default;
#[derive(Default)]
struct AppConfig {
foo: FooConfig,
bar: BarConfig,
}
#[derive(Default)]
struct FooConfig {
foo: i32,
}
#[derive(Default)]
struct BarConfig {
bar: f32,
baz: u8,
}
fn main() {
let options = AppConfig {
foo: default(),
bar: BarConfig {
bar: 10.1,
..default()
},
};
}
```
"##,
},
LintCompletion {
label: "char_error_internals",
description: r##"# `char_error_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "libstd_sys_internals",
description: r##"# `libstd_sys_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "is_sorted",
description: r##"# `is_sorted`
The tracking issue for this feature is: [#53485]
[#53485]: https://github.com/rust-lang/rust/issues/53485
------------------------
Add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to `[T]`;
add the methods `is_sorted`, `is_sorted_by` and `is_sorted_by_key` to
`Iterator`.
"##,
},
LintCompletion {
label: "c_void_variant",
description: r##"# `c_void_variant`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "concat_idents",
description: r##"# `concat_idents`
The tracking issue for this feature is: [#29599]
[#29599]: https://github.com/rust-lang/rust/issues/29599
------------------------
The `concat_idents` feature adds a macro for concatenating multiple identifiers
into one identifier.
## Examples
```rust
#![feature(concat_idents)]
fn main() {
fn foobar() -> u32 { 23 }
let f = concat_idents!(foo, bar);
assert_eq!(f(), 23);
}
```
"##,
},
LintCompletion {
label: "format_args_capture",
description: r##"# `format_args_capture`
The tracking issue for this feature is: [#67984]
[#67984]: https://github.com/rust-lang/rust/issues/67984
------------------------
Enables `format_args!` (and macros which use `format_args!` in their implementation, such
as `format!`, `print!` and `panic!`) to capture variables from the surrounding scope.
This avoids the need to pass named parameters when the binding in question
already exists in scope.
```rust
#![feature(format_args_capture)]
let (person, species, name) = ("Charlie Brown", "dog", "Snoopy");
// captures named argument `person`
print!("Hello {person}");
// captures named arguments `species` and `name`
format!("The {species}'s name is {name}.");
```
This also works for formatting parameters such as width and precision:
```rust
#![feature(format_args_capture)]
let precision = 2;
let s = format!("{:.precision$}", 1.324223);
assert_eq!(&s, "1.32");
```
A non-exhaustive list of macros which benefit from this functionality include:
- `format!`
- `print!` and `println!`
- `eprint!` and `eprintln!`
- `write!` and `writeln!`
- `panic!`
- `unreachable!`
- `unimplemented!`
- `todo!`
- `assert!` and similar
- macros in many thirdparty crates, such as `log`
"##,
},
LintCompletion {
label: "print_internals",
description: r##"# `print_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "llvm_asm",
description: r##"# `llvm_asm`
The tracking issue for this feature is: [#70173]
[#70173]: https://github.com/rust-lang/rust/issues/70173
------------------------
For extremely low-level manipulations and performance reasons, one
might wish to control the CPU directly. Rust supports using inline
assembly to do this via the `llvm_asm!` macro.
```rust,ignore (pseudo-code)
llvm_asm!(assembly template
: output operands
: input operands
: clobbers
: options
);
```
Any use of `llvm_asm` is feature gated (requires `#![feature(llvm_asm)]` on the
crate to allow) and of course requires an `unsafe` block.
> **Note**: the examples here are given in x86/x86-64 assembly, but
> all platforms are supported.
## Assembly template
The `assembly template` is the only required parameter and must be a
literal string (i.e. `""`)
```rust
#![feature(llvm_asm)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn foo() {
unsafe {
llvm_asm!("NOP");
}
}
// Other platforms:
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
fn foo() { /* ... */ }
fn main() {
// ...
foo();
// ...
}
```
(The `feature(llvm_asm)` and `#[cfg]`s are omitted from now on.)
Output operands, input operands, clobbers and options are all optional
but you must add the right number of `:` if you skip them:
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
# fn main() { unsafe {
llvm_asm!("xor %eax, %eax"
:
:
: "eax"
);
# } }
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn main() {}
```
Whitespace also doesn't matter:
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
# fn main() { unsafe {
llvm_asm!("xor %eax, %eax" ::: "eax");
# } }
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn main() {}
```
## Operands
Input and output operands follow the same format: `:
"constraints1"(expr1), "constraints2"(expr2), ..."`. Output operand
expressions must be mutable place, or not yet assigned:
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn add(a: i32, b: i32) -> i32 {
let c: i32;
unsafe {
llvm_asm!("add $2, $0"
: "=r"(c)
: "0"(a), "r"(b)
);
}
c
}
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn add(a: i32, b: i32) -> i32 { a + b }
fn main() {
assert_eq!(add(3, 14159), 14162)
}
```
If you would like to use real operands in this position, however,
you are required to put curly braces `{}` around the register that
you want, and you are required to put the specific size of the
operand. This is useful for very low level programming, where
which register you use is important:
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
# unsafe fn read_byte_in(port: u16) -> u8 {
let result: u8;
llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port));
result
# }
```
## Clobbers
Some instructions modify registers which might otherwise have held
different values so we use the clobbers list to indicate to the
compiler not to assume any values loaded into those registers will
stay valid.
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
# fn main() { unsafe {
// Put the value 0x200 in eax:
llvm_asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
# } }
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn main() {}
```
Input and output registers need not be listed since that information
is already communicated by the given constraints. Otherwise, any other
registers used either implicitly or explicitly should be listed.
If the assembly changes the condition code register `cc` should be
specified as one of the clobbers. Similarly, if the assembly modifies
memory, `memory` should also be specified.
## Options
The last section, `options` is specific to Rust. The format is comma
separated literal strings (i.e. `:"foo", "bar", "baz"`). It's used to
specify some extra info about the inline assembly:
Current valid options are:
1. `volatile` - specifying this is analogous to
`__asm__ __volatile__ (...)` in gcc/clang.
2. `alignstack` - certain instructions expect the stack to be
aligned a certain way (i.e. SSE) and specifying this indicates to
the compiler to insert its usual stack alignment code
3. `intel` - use intel syntax instead of the default AT&T.
```rust
# #![feature(llvm_asm)]
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
# fn main() {
let result: i32;
unsafe {
llvm_asm!("mov eax, 2" : "={eax}"(result) : : : "intel")
}
println!("eax is currently {}", result);
# }
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
# fn main() {}
```
## More Information
The current implementation of the `llvm_asm!` macro is a direct binding to [LLVM's
inline assembler expressions][llvm-docs], so be sure to check out [their
documentation as well][llvm-docs] for more information about clobbers,
constraints, etc.
[llvm-docs]: http://llvm.org/docs/LangRef.html#inline-assembler-expressions
If you need more power and don't mind losing some of the niceties of
`llvm_asm!`, check out [global_asm](global-asm.md).
"##,
},
LintCompletion {
label: "core_intrinsics",
description: r##"# `core_intrinsics`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "trace_macros",
description: r##"# `trace_macros`
The tracking issue for this feature is [#29598].
[#29598]: https://github.com/rust-lang/rust/issues/29598
------------------------
With `trace_macros` you can trace the expansion of macros in your code.
## Examples
```rust
#![feature(trace_macros)]
fn main() {
trace_macros!(true);
println!("Hello, Rust!");
trace_macros!(false);
}
```
The `cargo build` output:
```txt
note: trace_macro
--> src/main.rs:5:5
|
5 | println!("Hello, Rust!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expanding `println! { "Hello, Rust!" }`
= note: to `print ! ( concat ! ( "Hello, Rust!" , "\n" ) )`
= note: expanding `print! { concat ! ( "Hello, Rust!" , "\n" ) }`
= note: to `$crate :: io :: _print ( format_args ! ( concat ! ( "Hello, Rust!" , "\n" ) )
)`
Finished dev [unoptimized + debuginfo] target(s) in 0.60 secs
```
"##,
},
LintCompletion {
label: "update_panic_count",
description: r##"# `update_panic_count`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "core_private_bignum",
description: r##"# `core_private_bignum`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "sort_internals",
description: r##"# `sort_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "windows_net",
description: r##"# `windows_net`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "c_variadic",
description: r##"# `c_variadic`
The tracking issue for this feature is: [#44930]
[#44930]: https://github.com/rust-lang/rust/issues/44930
------------------------
The `c_variadic` library feature exposes the `VaList` structure,
Rust's analogue of C's `va_list` type.
## Examples
```rust
#![feature(c_variadic)]
use std::ffi::VaList;
pub unsafe extern "C" fn vadd(n: usize, mut args: VaList) -> usize {
let mut sum = 0;
for _ in 0..n {
sum += args.arg::<usize>();
}
sum
}
```
"##,
},
LintCompletion {
label: "core_private_diy_float",
description: r##"# `core_private_diy_float`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "profiler_runtime_lib",
description: r##"# `profiler_runtime_lib`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "thread_local_internals",
description: r##"# `thread_local_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "int_error_internals",
description: r##"# `int_error_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "windows_stdio",
description: r##"# `windows_stdio`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "fmt_internals",
description: r##"# `fmt_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "fd_read",
description: r##"# `fd_read`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "str_internals",
description: r##"# `str_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "test",
description: r##"# `test`
The tracking issue for this feature is: None.
------------------------
The internals of the `test` crate are unstable, behind the `test` flag. The
most widely used part of the `test` crate are benchmark tests, which can test
the performance of your code. Let's make our `src/lib.rs` look like this
(comments elided):
```rust,no_run
#![feature(test)]
extern crate test;
pub fn add_two(a: i32) -> i32 {
a + 2
}
#[cfg(test)]
mod tests {
use super::*;
use test::Bencher;
#[test]
fn it_works() {
assert_eq!(4, add_two(2));
}
#[bench]
fn bench_add_two(b: &mut Bencher) {
b.iter(|| add_two(2));
}
}
```
Note the `test` feature gate, which enables this unstable feature.
We've imported the `test` crate, which contains our benchmarking support.
We have a new function as well, with the `bench` attribute. Unlike regular
tests, which take no arguments, benchmark tests take a `&mut Bencher`. This
`Bencher` provides an `iter` method, which takes a closure. This closure
contains the code we'd like to benchmark.
We can run benchmark tests with `cargo bench`:
```bash
$ cargo bench
Compiling adder v0.0.1 (file:///home/steve/tmp/adder)
Running target/release/adder-91b3e234d4ed382a
running 2 tests
test tests::it_works ... ignored
test tests::bench_add_two ... bench: 1 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 1 ignored; 1 measured
```
Our non-benchmark test was ignored. You may have noticed that `cargo bench`
takes a bit longer than `cargo test`. This is because Rust runs our benchmark
a number of times, and then takes the average. Because we're doing so little
work in this example, we have a `1 ns/iter (+/- 0)`, but this would show
the variance if there was one.
Advice on writing benchmarks:
* Move setup code outside the `iter` loop; only put the part you want to measure inside
* Make the code do "the same thing" on each iteration; do not accumulate or change state
* Make the outer function idempotent too; the benchmark runner is likely to run
it many times
* Make the inner `iter` loop short and fast so benchmark runs are fast and the
calibrator can adjust the run-length at fine resolution
* Make the code in the `iter` loop do something simple, to assist in pinpointing
performance improvements (or regressions)
## Gotcha: optimizations
There's another tricky part to writing benchmarks: benchmarks compiled with
optimizations activated can be dramatically changed by the optimizer so that
the benchmark is no longer benchmarking what one expects. For example, the
compiler might recognize that some calculation has no external effects and
remove it entirely.
```rust,no_run
#![feature(test)]
extern crate test;
use test::Bencher;
#[bench]
fn bench_xor_1000_ints(b: &mut Bencher) {
b.iter(|| {
(0..1000).fold(0, |old, new| old ^ new);
});
}
```
gives the following results
```text
running 1 test
test bench_xor_1000_ints ... bench: 0 ns/iter (+/- 0)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
```
The benchmarking runner offers two ways to avoid this. Either, the closure that
the `iter` method receives can return an arbitrary value which forces the
optimizer to consider the result used and ensures it cannot remove the
computation entirely. This could be done for the example above by adjusting the
`b.iter` call to
```rust
# struct X;
# impl X { fn iter<T, F>(&self, _: F) where F: FnMut() -> T {} } let b = X;
b.iter(|| {
// Note lack of `;` (could also use an explicit `return`).
(0..1000).fold(0, |old, new| old ^ new)
});
```
Or, the other option is to call the generic `test::black_box` function, which
is an opaque "black box" to the optimizer and so forces it to consider any
argument as used.
```rust
#![feature(test)]
extern crate test;
# fn main() {
# struct X;
# impl X { fn iter<T, F>(&self, _: F) where F: FnMut() -> T {} } let b = X;
b.iter(|| {
let n = test::black_box(1000);
(0..n).fold(0, |a, b| a ^ b)
})
# }
```
Neither of these read or modify the value, and are very cheap for small values.
Larger values can be passed indirectly to reduce overhead (e.g.
`black_box(&huge_struct)`).
Performing either of the above changes gives the following benchmarking results
```text
running 1 test
test bench_xor_1000_ints ... bench: 131 ns/iter (+/- 3)
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
```
However, the optimizer can still modify a testcase in an undesirable manner
even when using either of the above.
"##,
},
LintCompletion {
label: "windows_c",
description: r##"# `windows_c`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "dec2flt",
description: r##"# `dec2flt`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "derive_clone_copy",
description: r##"# `derive_clone_copy`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "allocator_api",
description: r##"# `allocator_api`
The tracking issue for this feature is [#32838]
[#32838]: https://github.com/rust-lang/rust/issues/32838
------------------------
Sometimes you want the memory for one collection to use a different
allocator than the memory for another collection. In this case,
replacing the global allocator is not a workable option. Instead,
you need to pass in an instance of an `AllocRef` to each collection
for which you want a custom allocator.
TBD
"##,
},
LintCompletion {
label: "core_panic",
description: r##"# `core_panic`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "fn_traits",
description: r##"# `fn_traits`
The tracking issue for this feature is [#29625]
See Also: [`unboxed_closures`](../language-features/unboxed-closures.md)
[#29625]: https://github.com/rust-lang/rust/issues/29625
----
The `fn_traits` feature allows for implementation of the [`Fn*`] traits
for creating custom closure-like types.
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
```rust
#![feature(unboxed_closures)]
#![feature(fn_traits)]
struct Adder {
a: u32
}
impl FnOnce<(u32, )> for Adder {
type Output = u32;
extern "rust-call" fn call_once(self, b: (u32, )) -> Self::Output {
self.a + b.0
}
}
fn main() {
let adder = Adder { a: 3 };
assert_eq!(adder(2), 5);
}
```
"##,
},
LintCompletion {
label: "try_trait",
description: r##"# `try_trait`
The tracking issue for this feature is: [#42327]
[#42327]: https://github.com/rust-lang/rust/issues/42327
------------------------
This introduces a new trait `Try` for extending the `?` operator to types
other than `Result` (a part of [RFC 1859]). The trait provides the canonical
way to _view_ a type in terms of a success/failure dichotomy. This will
allow `?` to supplant the `try_opt!` macro on `Option` and the `try_ready!`
macro on `Poll`, among other things.
[RFC 1859]: https://github.com/rust-lang/rfcs/pull/1859
Here's an example implementation of the trait:
```rust,ignore (cannot-reimpl-Try)
/// A distinct type to represent the `None` value of an `Option`.
///
/// This enables using the `?` operator on `Option`; it's rarely useful alone.
#[derive(Debug)]
#[unstable(feature = "try_trait", issue = "42327")]
pub struct None { _priv: () }
#[unstable(feature = "try_trait", issue = "42327")]
impl<T> ops::Try for Option<T> {
type Ok = T;
type Error = None;
fn into_result(self) -> Result<T, None> {
self.ok_or(None { _priv: () })
}
fn from_ok(v: T) -> Self {
Some(v)
}
fn from_error(_: None) -> Self {
None
}
}
```
Note the `Error` associated type here is a new marker. The `?` operator
allows interconversion between different `Try` implementers only when
the error type can be converted `Into` the error type of the enclosing
function (or catch block). Having a distinct error type (as opposed to
just `()`, or similar) restricts this to where it's semantically meaningful.
"##,
},
LintCompletion {
label: "rt",
description: r##"# `rt`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "fd",
description: r##"# `fd`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
LintCompletion {
label: "libstd_thread_internals",
description: r##"# `libstd_thread_internals`
This feature is internal to the Rust compiler and is not intended for general use.
------------------------
"##,
},
];
pub(super) const CLIPPY_LINTS: &[LintCompletion] = &[
LintCompletion {
label: "clippy::absurd_extreme_comparisons",
description: r##"Checks for comparisons where one side of the relation is\neither the minimum or maximum value for its type and warns if it involves a\ncase that is always true or always false. Only integer and boolean types are\nchecked."##,
},
LintCompletion {
label: "clippy::almost_swapped",
description: r##"Checks for `foo = bar; bar = foo` sequences."##,
},
LintCompletion {
label: "clippy::approx_constant",
description: r##"Checks for floating point literals that approximate\nconstants which are defined in\n[`std::f32::consts`](https://doc.rust-lang.org/stable/std/f32/consts/#constants)\nor\n[`std::f64::consts`](https://doc.rust-lang.org/stable/std/f64/consts/#constants),\nrespectively, suggesting to use the predefined constant."##,
},
LintCompletion {
label: "clippy::as_conversions",
description: r##"Checks for usage of `as` conversions.\n\nNote that this lint is specialized in linting *every single* use of `as`\nregardless of whether good alternatives exist or not.\nIf you want more precise lints for `as`, please consider using these separate lints:\n`unnecessary_cast`, `cast_lossless/possible_truncation/possible_wrap/precision_loss/sign_loss`,\n`fn_to_numeric_cast(_with_truncation)`, `char_lit_as_u8`, `ref_to_mut` and `ptr_as_ptr`.\nThere is a good explanation the reason why this lint should work in this way and how it is useful\n[in this issue](https://github.com/rust-lang/rust-clippy/issues/5122)."##,
},
LintCompletion {
label: "clippy::assertions_on_constants",
description: r##"Checks for `assert!(true)` and `assert!(false)` calls."##,
},
LintCompletion {
label: "clippy::assign_op_pattern",
description: r##"Checks for `a = a op b` or `a = b commutative_op a`\npatterns."##,
},
LintCompletion {
label: "clippy::assign_ops",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::async_yields_async",
description: r##"Checks for async blocks that yield values of types\nthat can themselves be awaited."##,
},
LintCompletion {
label: "clippy::await_holding_lock",
description: r##"Checks for calls to await while holding a\nnon-async-aware MutexGuard."##,
},
LintCompletion {
label: "clippy::await_holding_refcell_ref",
description: r##"Checks for calls to await while holding a\n`RefCell` `Ref` or `RefMut`."##,
},
LintCompletion {
label: "clippy::bad_bit_mask",
description: r##"Checks for incompatible bit masks in comparisons.\n\nThe formula for detecting if an expression of the type `_ <bit_op> m\n<cmp_op> c` (where `<bit_op>` is one of {`&`, `|`} and `<cmp_op>` is one of\n{`!=`, `>=`, `>`, `!=`, `>=`, `>`}) can be determined from the following\ntable:\n\n|Comparison |Bit Op|Example |is always|Formula |\n|------------|------|------------|---------|----------------------|\n|`==` or `!=`| `&` |`x & 2 == 3`|`false` |`c & m != c` |\n|`<` or `>=`| `&` |`x & 2 < 3` |`true` |`m < c` |\n|`>` or `<=`| `&` |`x & 1 > 1` |`false` |`m <= c` |\n|`==` or `!=`| `|` |`x | 1 == 0`|`false` |`c | m != c` |\n|`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` |\n|`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` |"##,
},
LintCompletion {
label: "clippy::bind_instead_of_map",
description: r##"Checks for usage of `_.and_then(|x| Some(y))`, `_.and_then(|x| Ok(y))` or\n`_.or_else(|x| Err(y))`."##,
},
LintCompletion {
label: "clippy::blacklisted_name",
description: r##"Checks for usage of blacklisted names for variables, such\nas `foo`."##,
},
LintCompletion {
label: "clippy::blanket_clippy_restriction_lints",
description: r##"Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category."##,
},
LintCompletion {
label: "clippy::blocks_in_if_conditions",
description: r##"Checks for `if` conditions that use blocks containing an\nexpression, statements or conditions that use closures with blocks."##,
},
LintCompletion {
label: "clippy::bool_comparison",
description: r##"Checks for expressions of the form `x == true`,\n`x != true` and order comparisons such as `x < true` (or vice versa) and\nsuggest using the variable directly."##,
},
LintCompletion {
label: "clippy::borrow_interior_mutable_const",
description: r##"Checks if `const` items which is interior mutable (e.g.,\ncontains a `Cell`, `Mutex`, `AtomicXxxx`, etc.) has been borrowed directly."##,
},
LintCompletion {
label: "clippy::borrowed_box",
description: r##"Checks for use of `&Box<T>` anywhere in the code.\nCheck the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information."##,
},
LintCompletion {
label: "clippy::box_vec",
description: r##"Checks for use of `Box<Vec<_>>` anywhere in the code.\nCheck the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information."##,
},
LintCompletion {
label: "clippy::boxed_local",
description: r##"Checks for usage of `Box<T>` where an unboxed `T` would\nwork fine."##,
},
LintCompletion {
label: "clippy::builtin_type_shadow",
description: r##"Warns if a generic shadows a built-in type."##,
},
LintCompletion {
label: "clippy::bytes_nth",
description: r##"Checks for the use of `.bytes().nth()`."##,
},
LintCompletion {
label: "clippy::cargo_common_metadata",
description: r##"Checks to see if all common metadata is defined in\n`Cargo.toml`. See: https://rust-lang-nursery.github.io/api-guidelines/documentation.html#cargotoml-includes-all-common-metadata-c-metadata"##,
},
LintCompletion {
label: "clippy::case_sensitive_file_extension_comparisons",
description: r##"Checks for calls to `ends_with` with possible file extensions\nand suggests to use a case-insensitive approach instead."##,
},
LintCompletion {
label: "clippy::cast_lossless",
description: r##"Checks for casts between numerical types that may\nbe replaced by safe conversion functions."##,
},
LintCompletion {
label: "clippy::cast_possible_truncation",
description: r##"Checks for casts between numerical types that may\ntruncate large values. This is expected behavior, so the cast is `Allow` by\ndefault."##,
},
LintCompletion {
label: "clippy::cast_possible_wrap",
description: r##"Checks for casts from an unsigned type to a signed type of\nthe same size. Performing such a cast is a 'no-op' for the compiler,\ni.e., nothing is changed at the bit level, and the binary representation of\nthe value is reinterpreted. This can cause wrapping if the value is too big\nfor the target signed type. However, the cast works as defined, so this lint\nis `Allow` by default."##,
},
LintCompletion {
label: "clippy::cast_precision_loss",
description: r##"Checks for casts from any numerical to a float type where\nthe receiving type cannot store all values from the original type without\nrounding errors. This possible rounding is to be expected, so this lint is\n`Allow` by default.\n\nBasically, this warns on casting any integer with 32 or more bits to `f32`\nor any 64-bit integer to `f64`."##,
},
LintCompletion {
label: "clippy::cast_ptr_alignment",
description: r##"Checks for casts, using `as` or `pointer::cast`,\nfrom a less-strictly-aligned pointer to a more-strictly-aligned pointer"##,
},
LintCompletion {
label: "clippy::cast_ref_to_mut",
description: r##"Checks for casts of `&T` to `&mut T` anywhere in the code."##,
},
LintCompletion {
label: "clippy::cast_sign_loss",
description: r##"Checks for casts from a signed to an unsigned numerical\ntype. In this case, negative values wrap around to large positive values,\nwhich can be quite surprising in practice. However, as the cast works as\ndefined, this lint is `Allow` by default."##,
},
LintCompletion {
label: "clippy::char_lit_as_u8",
description: r##"Checks for expressions where a character literal is cast\nto `u8` and suggests using a byte literal instead."##,
},
LintCompletion {
label: "clippy::chars_last_cmp",
description: r##"Checks for usage of `_.chars().last()` or\n`_.chars().next_back()` on a `str` to check if it ends with a given char."##,
},
LintCompletion {
label: "clippy::chars_next_cmp",
description: r##"Checks for usage of `.chars().next()` on a `str` to check\nif it starts with a given char."##,
},
LintCompletion {
label: "clippy::checked_conversions",
description: r##"Checks for explicit bounds checking when casting."##,
},
LintCompletion {
label: "clippy::clone_double_ref",
description: r##"Checks for usage of `.clone()` on an `&&T`."##,
},
LintCompletion {
label: "clippy::clone_on_copy",
description: r##"Checks for usage of `.clone()` on a `Copy` type."##,
},
LintCompletion {
label: "clippy::clone_on_ref_ptr",
description: r##"Checks for usage of `.clone()` on a ref-counted pointer,\n(`Rc`, `Arc`, `rc::Weak`, or `sync::Weak`), and suggests calling Clone via unified\nfunction syntax instead (e.g., `Rc::clone(foo)`)."##,
},
LintCompletion { label: "clippy::cmp_nan", description: r##"Checks for comparisons to NaN."## },
LintCompletion {
label: "clippy::cmp_null",
description: r##"This lint checks for equality comparisons with `ptr::null`"##,
},
LintCompletion {
label: "clippy::cmp_owned",
description: r##"Checks for conversions to owned values just for the sake\nof a comparison."##,
},
LintCompletion {
label: "clippy::cognitive_complexity",
description: r##"Checks for methods with high cognitive complexity."##,
},
LintCompletion {
label: "clippy::collapsible_else_if",
description: r##"Checks for collapsible `else { if ... }` expressions\nthat can be collapsed to `else if ...`."##,
},
LintCompletion {
label: "clippy::collapsible_if",
description: r##"Checks for nested `if` statements which can be collapsed\nby `&&`-combining their conditions."##,
},
LintCompletion {
label: "clippy::collapsible_match",
description: r##"Finds nested `match` or `if let` expressions where the patterns may be \"collapsed\" together\nwithout adding any branches.\n\nNote that this lint is not intended to find _all_ cases where nested match patterns can be merged, but only\ncases where merging would most likely make the code more readable."##,
},
LintCompletion {
label: "clippy::comparison_chain",
description: r##"Checks comparison chains written with `if` that can be\nrewritten with `match` and `cmp`."##,
},
LintCompletion {
label: "clippy::comparison_to_empty",
description: r##"Checks for comparing to an empty slice such as `\"\"` or `[]`,\nand suggests using `.is_empty()` where applicable."##,
},
LintCompletion {
label: "clippy::copy_iterator",
description: r##"Checks for types that implement `Copy` as well as\n`Iterator`."##,
},
LintCompletion {
label: "clippy::create_dir",
description: r##"Checks usage of `std::fs::create_dir` and suggest using `std::fs::create_dir_all` instead."##,
},
LintCompletion {
label: "clippy::crosspointer_transmute",
description: r##"Checks for transmutes between a type `T` and `*T`."##,
},
LintCompletion {
label: "clippy::dbg_macro",
description: r##"Checks for usage of dbg!() macro."##,
},
LintCompletion {
label: "clippy::debug_assert_with_mut_call",
description: r##"Checks for function/method calls with a mutable\nparameter in `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!` macros."##,
},
LintCompletion {
label: "clippy::decimal_literal_representation",
description: r##"Warns if there is a better representation for a numeric literal."##,
},
LintCompletion {
label: "clippy::declare_interior_mutable_const",
description: r##"Checks for declaration of `const` items which is interior\nmutable (e.g., contains a `Cell`, `Mutex`, `AtomicXxxx`, etc.)."##,
},
LintCompletion {
label: "clippy::default_numeric_fallback",
description: r##"Checks for usage of unconstrained numeric literals which may cause default numeric fallback in type\ninference.\n\nDefault numeric fallback means that if numeric types have not yet been bound to concrete\ntypes at the end of type inference, then integer type is bound to `i32`, and similarly\nfloating type is bound to `f64`.\n\nSee [RFC0212](https://github.com/rust-lang/rfcs/blob/master/text/0212-restore-int-fallback.md) for more information about the fallback."##,
},
LintCompletion {
label: "clippy::default_trait_access",
description: r##"Checks for literal calls to `Default::default()`."##,
},
LintCompletion {
label: "clippy::deprecated_cfg_attr",
description: r##"Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it\nwith `#[rustfmt::skip]`."##,
},
LintCompletion {
label: "clippy::deprecated_semver",
description: r##"Checks for `#[deprecated]` annotations with a `since`\nfield that is not a valid semantic version."##,
},
LintCompletion {
label: "clippy::deref_addrof",
description: r##"Checks for usage of `*&` and `*&mut` in expressions."##,
},
LintCompletion {
label: "clippy::derive_hash_xor_eq",
description: r##"Checks for deriving `Hash` but implementing `PartialEq`\nexplicitly or vice versa."##,
},
LintCompletion {
label: "clippy::derive_ord_xor_partial_ord",
description: r##"Checks for deriving `Ord` but implementing `PartialOrd`\nexplicitly or vice versa."##,
},
LintCompletion {
label: "clippy::disallowed_method",
description: r##"Denies the configured methods and functions in clippy.toml"##,
},
LintCompletion {
label: "clippy::diverging_sub_expression",
description: r##"Checks for diverging calls that are not match arms or\nstatements."##,
},
LintCompletion {
label: "clippy::doc_markdown",
description: r##"Checks for the presence of `_`, `::` or camel-case words\noutside ticks in documentation."##,
},
LintCompletion {
label: "clippy::double_comparisons",
description: r##"Checks for double comparisons that could be simplified to a single expression."##,
},
LintCompletion {
label: "clippy::double_must_use",
description: r##"Checks for a [`#[must_use]`] attribute without\nfurther information on functions and methods that return a type already\nmarked as `#[must_use]`.\n\n[`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"##,
},
LintCompletion {
label: "clippy::double_neg",
description: r##"Detects expressions of the form `--x`."##,
},
LintCompletion {
label: "clippy::double_parens",
description: r##"Checks for unnecessary double parentheses."##,
},
LintCompletion {
label: "clippy::drop_bounds",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::drop_copy",
description: r##"Checks for calls to `std::mem::drop` with a value\nthat derives the Copy trait"##,
},
LintCompletion {
label: "clippy::drop_ref",
description: r##"Checks for calls to `std::mem::drop` with a reference\ninstead of an owned value."##,
},
LintCompletion {
label: "clippy::duplicate_underscore_argument",
description: r##"Checks for function arguments having the similar names\ndiffering by an underscore."##,
},
LintCompletion {
label: "clippy::duration_subsec",
description: r##"Checks for calculation of subsecond microseconds or milliseconds\nfrom other `Duration` methods."##,
},
LintCompletion {
label: "clippy::else_if_without_else",
description: r##"Checks for usage of if expressions with an `else if` branch,\nbut without a final `else` branch."##,
},
LintCompletion {
label: "clippy::empty_enum",
description: r##"Checks for `enum`s with no variants.\n\nAs of this writing, the `never_type` is still a\nnightly-only experimental API. Therefore, this lint is only triggered\nif the `never_type` is enabled."##,
},
LintCompletion {
label: "clippy::empty_line_after_outer_attr",
description: r##"Checks for empty lines after outer attributes"##,
},
LintCompletion {
label: "clippy::empty_loop",
description: r##"Checks for empty `loop` expressions."##,
},
LintCompletion {
label: "clippy::enum_clike_unportable_variant",
description: r##"Checks for C-like enumerations that are\n`repr(isize/usize)` and have values that don't fit into an `i32`."##,
},
LintCompletion {
label: "clippy::enum_glob_use",
description: r##"Checks for `use Enum::*`."##,
},
LintCompletion {
label: "clippy::enum_variant_names",
description: r##"Detects enumeration variants that are prefixed or suffixed\nby the same characters."##,
},
LintCompletion {
label: "clippy::eq_op",
description: r##"Checks for equal operands to comparison, logical and\nbitwise, difference and division binary operators (`==`, `>`, etc., `&&`,\n`||`, `&`, `|`, `^`, `-` and `/`)."##,
},
LintCompletion {
label: "clippy::erasing_op",
description: r##"Checks for erasing operations, e.g., `x * 0`."##,
},
LintCompletion {
label: "clippy::eval_order_dependence",
description: r##"Checks for a read and a write to the same variable where\nwhether the read occurs before or after the write depends on the evaluation\norder of sub-expressions."##,
},
LintCompletion {
label: "clippy::excessive_precision",
description: r##"Checks for float literals with a precision greater\nthan that supported by the underlying type."##,
},
LintCompletion {
label: "clippy::exhaustive_enums",
description: r##"Warns on any exported `enum`s that are not tagged `#[non_exhaustive]`"##,
},
LintCompletion {
label: "clippy::exhaustive_structs",
description: r##"Warns on any exported `structs`s that are not tagged `#[non_exhaustive]`"##,
},
LintCompletion {
label: "clippy::exit",
description: r##"`exit()` terminates the program and doesn't provide a\nstack trace."##,
},
LintCompletion {
label: "clippy::expect_fun_call",
description: r##"Checks for calls to `.expect(&format!(...))`, `.expect(foo(..))`,\netc., and suggests to use `unwrap_or_else` instead"##,
},
LintCompletion {
label: "clippy::expect_used",
description: r##"Checks for `.expect()` calls on `Option`s and `Result`s."##,
},
LintCompletion {
label: "clippy::expl_impl_clone_on_copy",
description: r##"Checks for explicit `Clone` implementations for `Copy`\ntypes."##,
},
LintCompletion {
label: "clippy::explicit_counter_loop",
description: r##"Checks `for` loops over slices with an explicit counter\nand suggests the use of `.enumerate()`."##,
},
LintCompletion {
label: "clippy::explicit_deref_methods",
description: r##"Checks for explicit `deref()` or `deref_mut()` method calls."##,
},
LintCompletion {
label: "clippy::explicit_into_iter_loop",
description: r##"Checks for loops on `y.into_iter()` where `y` will do, and\nsuggests the latter."##,
},
LintCompletion {
label: "clippy::explicit_iter_loop",
description: r##"Checks for loops on `x.iter()` where `&x` will do, and\nsuggests the latter."##,
},
LintCompletion {
label: "clippy::explicit_write",
description: r##"Checks for usage of `write!()` / `writeln()!` which can be\nreplaced with `(e)print!()` / `(e)println!()`"##,
},
LintCompletion {
label: "clippy::extend_from_slice",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::extra_unused_lifetimes",
description: r##"Checks for lifetimes in generics that are never used\nanywhere else."##,
},
LintCompletion {
label: "clippy::fallible_impl_from",
description: r##"Checks for impls of `From<..>` that contain `panic!()` or `unwrap()`"##,
},
LintCompletion {
label: "clippy::field_reassign_with_default",
description: r##"Checks for immediate reassignment of fields initialized\nwith Default::default()."##,
},
LintCompletion {
label: "clippy::filetype_is_file",
description: r##"Checks for `FileType::is_file()`."##,
},
LintCompletion {
label: "clippy::filter_map",
description: r##"Checks for usage of `_.filter(_).map(_)`,\n`_.filter(_).flat_map(_)`, `_.filter_map(_).flat_map(_)` and similar."##,
},
LintCompletion {
label: "clippy::filter_map_identity",
description: r##"Checks for usage of `filter_map(|x| x)`."##,
},
LintCompletion {
label: "clippy::filter_map_next",
description: r##"Checks for usage of `_.filter_map(_).next()`."##,
},
LintCompletion {
label: "clippy::filter_next",
description: r##"Checks for usage of `_.filter(_).next()`."##,
},
LintCompletion {
label: "clippy::find_map",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::flat_map_identity",
description: r##"Checks for usage of `flat_map(|x| x)`."##,
},
LintCompletion {
label: "clippy::float_arithmetic",
description: r##"Checks for float arithmetic."##,
},
LintCompletion {
label: "clippy::float_cmp",
description: r##"Checks for (in-)equality comparisons on floating-point\nvalues (apart from zero), except in functions called `*eq*` (which probably\nimplement equality for a type involving floats)."##,
},
LintCompletion {
label: "clippy::float_cmp_const",
description: r##"Checks for (in-)equality comparisons on floating-point\nvalue and constant, except in functions called `*eq*` (which probably\nimplement equality for a type involving floats)."##,
},
LintCompletion {
label: "clippy::float_equality_without_abs",
description: r##"Checks for statements of the form `(a - b) < f32::EPSILON` or\n`(a - b) < f64::EPSILON`. Notes the missing `.abs()`."##,
},
LintCompletion {
label: "clippy::fn_address_comparisons",
description: r##"Checks for comparisons with an address of a function item."##,
},
LintCompletion {
label: "clippy::fn_params_excessive_bools",
description: r##"Checks for excessive use of\nbools in function definitions."##,
},
LintCompletion {
label: "clippy::fn_to_numeric_cast",
description: r##"Checks for casts of function pointers to something other than usize"##,
},
LintCompletion {
label: "clippy::fn_to_numeric_cast_with_truncation",
description: r##"Checks for casts of a function pointer to a numeric type not wide enough to\nstore address."##,
},
LintCompletion {
label: "clippy::for_kv_map",
description: r##"Checks for iterating a map (`HashMap` or `BTreeMap`) and\nignoring either the keys or values."##,
},
LintCompletion {
label: "clippy::for_loops_over_fallibles",
description: r##"Checks for `for` loops over `Option` or `Result` values."##,
},
LintCompletion {
label: "clippy::forget_copy",
description: r##"Checks for calls to `std::mem::forget` with a value that\nderives the Copy trait"##,
},
LintCompletion {
label: "clippy::forget_ref",
description: r##"Checks for calls to `std::mem::forget` with a reference\ninstead of an owned value."##,
},
LintCompletion {
label: "clippy::from_iter_instead_of_collect",
description: r##"Checks for `from_iter()` function calls on types that implement the `FromIterator`\ntrait."##,
},
LintCompletion {
label: "clippy::from_over_into",
description: r##"Searches for implementations of the `Into<..>` trait and suggests to implement `From<..>` instead."##,
},
LintCompletion {
label: "clippy::from_str_radix_10",
description: r##"Checks for function invocations of the form `primitive::from_str_radix(s, 10)`"##,
},
LintCompletion {
label: "clippy::future_not_send",
description: r##"This lint requires Future implementations returned from\nfunctions and methods to implement the `Send` marker trait. It is mostly\nused by library authors (public and internal) that target an audience where\nmultithreaded executors are likely to be used for running these Futures."##,
},
LintCompletion {
label: "clippy::get_last_with_len",
description: r##"Checks for using `x.get(x.len() - 1)` instead of\n`x.last()`."##,
},
LintCompletion {
label: "clippy::get_unwrap",
description: r##"Checks for use of `.get().unwrap()` (or\n`.get_mut().unwrap`) on a standard library type which implements `Index`"##,
},
LintCompletion {
label: "clippy::identity_op",
description: r##"Checks for identity operations, e.g., `x + 0`."##,
},
LintCompletion {
label: "clippy::if_let_mutex",
description: r##"Checks for `Mutex::lock` calls in `if let` expression\nwith lock calls in any of the else blocks."##,
},
LintCompletion {
label: "clippy::if_let_redundant_pattern_matching",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::if_let_some_result",
description: r##"* Checks for unnecessary `ok()` in if let."##,
},
LintCompletion {
label: "clippy::if_not_else",
description: r##"Checks for usage of `!` or `!=` in an if condition with an\nelse branch."##,
},
LintCompletion {
label: "clippy::if_same_then_else",
description: r##"Checks for `if/else` with the same body as the *then* part\nand the *else* part."##,
},
LintCompletion {
label: "clippy::ifs_same_cond",
description: r##"Checks for consecutive `if`s with the same condition."##,
},
LintCompletion {
label: "clippy::implicit_clone",
description: r##"Checks for the usage of `_.to_owned()`, `vec.to_vec()`, or similar when calling `_.clone()` would be clearer."##,
},
LintCompletion {
label: "clippy::implicit_hasher",
description: r##"Checks for public `impl` or `fn` missing generalization\nover different hashers and implicitly defaulting to the default hashing\nalgorithm (`SipHash`)."##,
},
LintCompletion {
label: "clippy::implicit_return",
description: r##"Checks for missing return statements at the end of a block."##,
},
LintCompletion {
label: "clippy::implicit_saturating_sub",
description: r##"Checks for implicit saturating subtraction."##,
},
LintCompletion {
label: "clippy::imprecise_flops",
description: r##"Looks for floating-point expressions that\ncan be expressed using built-in methods to improve accuracy\nat the cost of performance."##,
},
LintCompletion {
label: "clippy::inconsistent_digit_grouping",
description: r##"Warns if an integral or floating-point constant is\ngrouped inconsistently with underscores."##,
},
LintCompletion {
label: "clippy::inconsistent_struct_constructor",
description: r##"Checks for struct constructors where the order of the field init\nshorthand in the constructor is inconsistent with the order in the struct definition."##,
},
LintCompletion {
label: "clippy::indexing_slicing",
description: r##"Checks for usage of indexing or slicing. Arrays are special cases, this lint\ndoes report on arrays if we can tell that slicing operations are in bounds and does not\nlint on constant `usize` indexing on arrays because that is handled by rustc's `const_err` lint."##,
},
LintCompletion {
label: "clippy::ineffective_bit_mask",
description: r##"Checks for bit masks in comparisons which can be removed\nwithout changing the outcome. The basic structure can be seen in the\nfollowing table:\n\n|Comparison| Bit Op |Example |equals |\n|----------|---------|-----------|-------|\n|`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`|\n|`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`|"##,
},
LintCompletion {
label: "clippy::inefficient_to_string",
description: r##"Checks for usage of `.to_string()` on an `&&T` where\n`T` implements `ToString` directly (like `&&str` or `&&String`)."##,
},
LintCompletion {
label: "clippy::infallible_destructuring_match",
description: r##"Checks for matches being used to destructure a single-variant enum\nor tuple struct where a `let` will suffice."##,
},
LintCompletion {
label: "clippy::infinite_iter",
description: r##"Checks for iteration that is guaranteed to be infinite."##,
},
LintCompletion {
label: "clippy::inherent_to_string",
description: r##"Checks for the definition of inherent methods with a signature of `to_string(&self) -> String`."##,
},
LintCompletion {
label: "clippy::inherent_to_string_shadow_display",
description: r##"Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait."##,
},
LintCompletion {
label: "clippy::inline_always",
description: r##"Checks for items annotated with `#[inline(always)]`,\nunless the annotated function is empty or simply panics."##,
},
LintCompletion {
label: "clippy::inline_asm_x86_att_syntax",
description: r##"Checks for usage of AT&T x86 assembly syntax."##,
},
LintCompletion {
label: "clippy::inline_asm_x86_intel_syntax",
description: r##"Checks for usage of Intel x86 assembly syntax."##,
},
LintCompletion {
label: "clippy::inline_fn_without_body",
description: r##"Checks for `#[inline]` on trait methods without bodies"##,
},
LintCompletion {
label: "clippy::inspect_for_each",
description: r##"Checks for usage of `inspect().for_each()`."##,
},
LintCompletion {
label: "clippy::int_plus_one",
description: r##"Checks for usage of `x >= y + 1` or `x - 1 >= y` (and `<=`) in a block"##,
},
LintCompletion {
label: "clippy::integer_arithmetic",
description: r##"Checks for integer arithmetic operations which could overflow or panic.\n\nSpecifically, checks for any operators (`+`, `-`, `*`, `<<`, etc) which are capable\nof overflowing according to the [Rust\nReference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow),\nor which can panic (`/`, `%`). No bounds analysis or sophisticated reasoning is\nattempted."##,
},
LintCompletion {
label: "clippy::integer_division",
description: r##"Checks for division of integers"##,
},
LintCompletion {
label: "clippy::into_iter_on_array",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::into_iter_on_ref",
description: r##"Checks for `into_iter` calls on references which should be replaced by `iter`\nor `iter_mut`."##,
},
LintCompletion {
label: "clippy::invalid_atomic_ordering",
description: r##"Checks for usage of invalid atomic\nordering in atomic loads/stores/exchanges/updates and\nmemory fences."##,
},
LintCompletion {
label: "clippy::invalid_ref",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::invalid_regex",
description: r##"Checks [regex](https://crates.io/crates/regex) creation\n(with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`) for correct\nregex syntax."##,
},
LintCompletion {
label: "clippy::invalid_upcast_comparisons",
description: r##"Checks for comparisons where the relation is always either\ntrue or false, but where one side has been upcast so that the comparison is\nnecessary. Only integer types are checked."##,
},
LintCompletion {
label: "clippy::invisible_characters",
description: r##"Checks for invisible Unicode characters in the code."##,
},
LintCompletion {
label: "clippy::items_after_statements",
description: r##"Checks for items declared after some statement in a block."##,
},
LintCompletion {
label: "clippy::iter_cloned_collect",
description: r##"Checks for the use of `.cloned().collect()` on slice to\ncreate a `Vec`."##,
},
LintCompletion {
label: "clippy::iter_next_loop",
description: r##"Checks for loops on `x.next()`."##,
},
LintCompletion {
label: "clippy::iter_next_slice",
description: r##"Checks for usage of `iter().next()` on a Slice or an Array"##,
},
LintCompletion {
label: "clippy::iter_nth",
description: r##"Checks for use of `.iter().nth()` (and the related\n`.iter_mut().nth()`) on standard library types with O(1) element access."##,
},
LintCompletion {
label: "clippy::iter_nth_zero",
description: r##"Checks for the use of `iter.nth(0)`."##,
},
LintCompletion {
label: "clippy::iter_skip_next",
description: r##"Checks for use of `.skip(x).next()` on iterators."##,
},
LintCompletion {
label: "clippy::iterator_step_by_zero",
description: r##"Checks for calling `.step_by(0)` on iterators which panics."##,
},
LintCompletion {
label: "clippy::just_underscores_and_digits",
description: r##"Checks if you have variables whose name consists of just\nunderscores and digits."##,
},
LintCompletion {
label: "clippy::large_const_arrays",
description: r##"Checks for large `const` arrays that should\nbe defined as `static` instead."##,
},
LintCompletion {
label: "clippy::large_digit_groups",
description: r##"Warns if the digits of an integral or floating-point\nconstant are grouped into groups that\nare too large."##,
},
LintCompletion {
label: "clippy::large_enum_variant",
description: r##"Checks for large size differences between variants on\n`enum`s."##,
},
LintCompletion {
label: "clippy::large_stack_arrays",
description: r##"Checks for local arrays that may be too large."##,
},
LintCompletion {
label: "clippy::large_types_passed_by_value",
description: r##"Checks for functions taking arguments by value, where\nthe argument type is `Copy` and large enough to be worth considering\npassing by reference. Does not trigger if the function is being exported,\nbecause that might induce API breakage, if the parameter is declared as mutable,\nor if the argument is a `self`."##,
},
LintCompletion {
label: "clippy::len_without_is_empty",
description: r##"Checks for items that implement `.len()` but not\n`.is_empty()`."##,
},
LintCompletion {
label: "clippy::len_zero",
description: r##"Checks for getting the length of something via `.len()`\njust to compare to zero, and suggests using `.is_empty()` where applicable."##,
},
LintCompletion {
label: "clippy::let_and_return",
description: r##"Checks for `let`-bindings, which are subsequently\nreturned."##,
},
LintCompletion {
label: "clippy::let_underscore_drop",
description: r##"Checks for `let _ = <expr>`\nwhere expr has a type that implements `Drop`"##,
},
LintCompletion {
label: "clippy::let_underscore_lock",
description: r##"Checks for `let _ = sync_lock`"##,
},
LintCompletion {
label: "clippy::let_underscore_must_use",
description: r##"Checks for `let _ = <expr>`\nwhere expr is #[must_use]"##,
},
LintCompletion {
label: "clippy::let_unit_value",
description: r##"Checks for binding a unit value."##,
},
LintCompletion {
label: "clippy::linkedlist",
description: r##"Checks for usage of any `LinkedList`, suggesting to use a\n`Vec` or a `VecDeque` (formerly called `RingBuf`)."##,
},
LintCompletion {
label: "clippy::logic_bug",
description: r##"Checks for boolean expressions that contain terminals that\ncan be eliminated."##,
},
LintCompletion {
label: "clippy::lossy_float_literal",
description: r##"Checks for whole number float literals that\ncannot be represented as the underlying type without loss."##,
},
LintCompletion {
label: "clippy::macro_use_imports",
description: r##"Checks for `#[macro_use] use...`."##,
},
LintCompletion {
label: "clippy::main_recursion",
description: r##"Checks for recursion using the entrypoint."##,
},
LintCompletion {
label: "clippy::manual_async_fn",
description: r##"It checks for manual implementations of `async` functions."##,
},
LintCompletion {
label: "clippy::manual_filter_map",
description: r##"Checks for usage of `_.filter(_).map(_)` that can be written more simply\nas `filter_map(_)`."##,
},
LintCompletion {
label: "clippy::manual_find_map",
description: r##"Checks for usage of `_.find(_).map(_)` that can be written more simply\nas `find_map(_)`."##,
},
LintCompletion {
label: "clippy::manual_flatten",
description: r##"Check for unnecessary `if let` usage in a for loop\nwhere only the `Some` or `Ok` variant of the iterator element is used."##,
},
LintCompletion {
label: "clippy::manual_map",
description: r##"Checks for usages of `match` which could be implemented using `map`"##,
},
LintCompletion {
label: "clippy::manual_memcpy",
description: r##"Checks for for-loops that manually copy items between\nslices that could be optimized by having a memcpy."##,
},
LintCompletion {
label: "clippy::manual_non_exhaustive",
description: r##"Checks for manual implementations of the non-exhaustive pattern."##,
},
LintCompletion {
label: "clippy::manual_ok_or",
description: r##"Finds patterns that reimplement `Option::ok_or`."##,
},
LintCompletion {
label: "clippy::manual_range_contains",
description: r##"Checks for expressions like `x >= 3 && x < 8` that could\nbe more readably expressed as `(3..8).contains(x)`."##,
},
LintCompletion {
label: "clippy::manual_saturating_arithmetic",
description: r##"Checks for `.checked_add/sub(x).unwrap_or(MAX/MIN)`."##,
},
LintCompletion {
label: "clippy::manual_strip",
description: r##"Suggests using `strip_{prefix,suffix}` over `str::{starts,ends}_with` and slicing using\nthe pattern's length."##,
},
LintCompletion {
label: "clippy::manual_swap",
description: r##"Checks for manual swapping."##,
},
LintCompletion {
label: "clippy::manual_unwrap_or",
description: r##"Finds patterns that reimplement `Option::unwrap_or` or `Result::unwrap_or`."##,
},
LintCompletion {
label: "clippy::many_single_char_names",
description: r##"Checks for too many variables whose name consists of a\nsingle character."##,
},
LintCompletion {
label: "clippy::map_clone",
description: r##"Checks for usage of `map(|x| x.clone())` or\ndereferencing closures for `Copy` types, on `Iterator` or `Option`,\nand suggests `cloned()` or `copied()` instead"##,
},
LintCompletion {
label: "clippy::map_collect_result_unit",
description: r##"Checks for usage of `_.map(_).collect::<Result<(), _>()`."##,
},
LintCompletion {
label: "clippy::map_entry",
description: r##"Checks for uses of `contains_key` + `insert` on `HashMap`\nor `BTreeMap`."##,
},
LintCompletion {
label: "clippy::map_err_ignore",
description: r##"Checks for instances of `map_err(|_| Some::Enum)`"##,
},
LintCompletion {
label: "clippy::map_flatten",
description: r##"Checks for usage of `_.map(_).flatten(_)`,"##,
},
LintCompletion {
label: "clippy::map_identity",
description: r##"Checks for instances of `map(f)` where `f` is the identity function."##,
},
LintCompletion {
label: "clippy::map_unwrap_or",
description: r##"Checks for usage of `option.map(_).unwrap_or(_)` or `option.map(_).unwrap_or_else(_)` or\n`result.map(_).unwrap_or_else(_)`."##,
},
LintCompletion {
label: "clippy::match_as_ref",
description: r##"Checks for match which is used to add a reference to an\n`Option` value."##,
},
LintCompletion {
label: "clippy::match_bool",
description: r##"Checks for matches where match expression is a `bool`. It\nsuggests to replace the expression with an `if...else` block."##,
},
LintCompletion {
label: "clippy::match_like_matches_macro",
description: r##"Checks for `match` or `if let` expressions producing a\n`bool` that could be written using `matches!`"##,
},
LintCompletion {
label: "clippy::match_on_vec_items",
description: r##"Checks for `match vec[idx]` or `match vec[n..m]`."##,
},
LintCompletion {
label: "clippy::match_overlapping_arm",
description: r##"Checks for overlapping match arms."##,
},
LintCompletion {
label: "clippy::match_ref_pats",
description: r##"Checks for matches where all arms match a reference,\nsuggesting to remove the reference and deref the matched expression\ninstead. It also checks for `if let &foo = bar` blocks."##,
},
LintCompletion {
label: "clippy::match_same_arms",
description: r##"Checks for `match` with identical arm bodies."##,
},
LintCompletion {
label: "clippy::match_single_binding",
description: r##"Checks for useless match that binds to only one value."##,
},
LintCompletion {
label: "clippy::match_wild_err_arm",
description: r##"Checks for arm which matches all errors with `Err(_)`\nand take drastic actions like `panic!`."##,
},
LintCompletion {
label: "clippy::match_wildcard_for_single_variants",
description: r##"Checks for wildcard enum matches for a single variant."##,
},
LintCompletion {
label: "clippy::maybe_infinite_iter",
description: r##"Checks for iteration that may be infinite."##,
},
LintCompletion {
label: "clippy::mem_discriminant_non_enum",
description: r##"Checks for calls of `mem::discriminant()` on a non-enum type."##,
},
LintCompletion {
label: "clippy::mem_forget",
description: r##"Checks for usage of `std::mem::forget(t)` where `t` is\n`Drop`."##,
},
LintCompletion {
label: "clippy::mem_replace_option_with_none",
description: r##"Checks for `mem::replace()` on an `Option` with\n`None`."##,
},
LintCompletion {
label: "clippy::mem_replace_with_default",
description: r##"Checks for `std::mem::replace` on a value of type\n`T` with `T::default()`."##,
},
LintCompletion {
label: "clippy::mem_replace_with_uninit",
description: r##"Checks for `mem::replace(&mut _, mem::uninitialized())`\nand `mem::replace(&mut _, mem::zeroed())`."##,
},
LintCompletion {
label: "clippy::min_max",
description: r##"Checks for expressions where `std::cmp::min` and `max` are\nused to clamp values, but switched so that the result is constant."##,
},
LintCompletion {
label: "clippy::misaligned_transmute",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::mismatched_target_os",
description: r##"Checks for cfg attributes having operating systems used in target family position."##,
},
LintCompletion {
label: "clippy::misrefactored_assign_op",
description: r##"Checks for `a op= a op b` or `a op= b op a` patterns."##,
},
LintCompletion {
label: "clippy::missing_const_for_fn",
description: r##"Suggests the use of `const` in functions and methods where possible."##,
},
LintCompletion {
label: "clippy::missing_docs_in_private_items",
description: r##"Warns if there is missing doc for any documentable item\n(public or private)."##,
},
LintCompletion {
label: "clippy::missing_errors_doc",
description: r##"Checks the doc comments of publicly visible functions that\nreturn a `Result` type and warns if there is no `# Errors` section."##,
},
LintCompletion {
label: "clippy::missing_inline_in_public_items",
description: r##"it lints if an exported function, method, trait method with default impl,\nor trait method impl is not `#[inline]`."##,
},
LintCompletion {
label: "clippy::missing_panics_doc",
description: r##"Checks the doc comments of publicly visible functions that\nmay panic and warns if there is no `# Panics` section."##,
},
LintCompletion {
label: "clippy::missing_safety_doc",
description: r##"Checks for the doc comments of publicly visible\nunsafe functions and warns if there is no `# Safety` section."##,
},
LintCompletion {
label: "clippy::mistyped_literal_suffixes",
description: r##"Warns for mistyped suffix in literals"##,
},
LintCompletion {
label: "clippy::mixed_case_hex_literals",
description: r##"Warns on hexadecimal literals with mixed-case letter\ndigits."##,
},
LintCompletion {
label: "clippy::module_inception",
description: r##"Checks for modules that have the same name as their\nparent module"##,
},
LintCompletion {
label: "clippy::module_name_repetitions",
description: r##"Detects type names that are prefixed or suffixed by the\ncontaining module's name."##,
},
LintCompletion {
label: "clippy::modulo_arithmetic",
description: r##"Checks for modulo arithmetic."##,
},
LintCompletion {
label: "clippy::modulo_one",
description: r##"Checks for getting the remainder of a division by one or minus\none."##,
},
LintCompletion {
label: "clippy::multiple_crate_versions",
description: r##"Checks to see if multiple versions of a crate are being\nused."##,
},
LintCompletion {
label: "clippy::multiple_inherent_impl",
description: r##"Checks for multiple inherent implementations of a struct"##,
},
LintCompletion {
label: "clippy::must_use_candidate",
description: r##"Checks for public functions that have no\n[`#[must_use]`] attribute, but return something not already marked\nmust-use, have no mutable arg and mutate no statics.\n\n[`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"##,
},
LintCompletion {
label: "clippy::must_use_unit",
description: r##"Checks for a [`#[must_use]`] attribute on\nunit-returning functions and methods.\n\n[`#[must_use]`]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"##,
},
LintCompletion {
label: "clippy::mut_from_ref",
description: r##"This lint checks for functions that take immutable\nreferences and return mutable ones."##,
},
LintCompletion {
label: "clippy::mut_mut",
description: r##"Checks for instances of `mut mut` references."##,
},
LintCompletion {
label: "clippy::mut_mutex_lock",
description: r##"Checks for `&mut Mutex::lock` calls"##,
},
LintCompletion {
label: "clippy::mut_range_bound",
description: r##"Checks for loops which have a range bound that is a mutable variable"##,
},
LintCompletion {
label: "clippy::mutable_key_type",
description: r##"Checks for sets/maps with mutable key types."##,
},
LintCompletion {
label: "clippy::mutex_atomic",
description: r##"Checks for usages of `Mutex<X>` where an atomic will do."##,
},
LintCompletion {
label: "clippy::mutex_integer",
description: r##"Checks for usages of `Mutex<X>` where `X` is an integral\ntype."##,
},
LintCompletion {
label: "clippy::naive_bytecount",
description: r##"Checks for naive byte counts"##,
},
LintCompletion {
label: "clippy::needless_arbitrary_self_type",
description: r##"The lint checks for `self` in fn parameters that\nspecify the `Self`-type explicitly"##,
},
LintCompletion {
label: "clippy::needless_bool",
description: r##"Checks for expressions of the form `if c { true } else {\nfalse }` (or vice versa) and suggests using the condition directly."##,
},
LintCompletion {
label: "clippy::needless_borrow",
description: r##"Checks for address of operations (`&`) that are going to\nbe dereferenced immediately by the compiler."##,
},
LintCompletion {
label: "clippy::needless_borrowed_reference",
description: r##"Checks for useless borrowed references."##,
},
LintCompletion {
label: "clippy::needless_collect",
description: r##"Checks for functions collecting an iterator when collect\nis not needed."##,
},
LintCompletion {
label: "clippy::needless_continue",
description: r##"The lint checks for `if`-statements appearing in loops\nthat contain a `continue` statement in either their main blocks or their\n`else`-blocks, when omitting the `else`-block possibly with some\nrearrangement of code can make the code easier to understand."##,
},
LintCompletion {
label: "clippy::needless_doctest_main",
description: r##"Checks for `fn main() { .. }` in doctests"##,
},
LintCompletion {
label: "clippy::needless_lifetimes",
description: r##"Checks for lifetime annotations which can be removed by\nrelying on lifetime elision."##,
},
LintCompletion {
label: "clippy::needless_pass_by_value",
description: r##"Checks for functions taking arguments by value, but not\nconsuming them in its\nbody."##,
},
LintCompletion {
label: "clippy::needless_question_mark",
description: r##"Suggests alternatives for useless applications of `?` in terminating expressions"##,
},
LintCompletion {
label: "clippy::needless_range_loop",
description: r##"Checks for looping over the range of `0..len` of some\ncollection just to get the values by index."##,
},
LintCompletion {
label: "clippy::needless_return",
description: r##"Checks for return statements at the end of a block."##,
},
LintCompletion {
label: "clippy::needless_update",
description: r##"Checks for needlessly including a base struct on update\nwhen all fields are changed anyway.\n\nThis lint is not applied to structs marked with\n[non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html)."##,
},
LintCompletion {
label: "clippy::neg_cmp_op_on_partial_ord",
description: r##"Checks for the usage of negated comparison operators on types which only implement\n`PartialOrd` (e.g., `f64`)."##,
},
LintCompletion {
label: "clippy::neg_multiply",
description: r##"Checks for multiplication by -1 as a form of negation."##,
},
LintCompletion {
label: "clippy::never_loop",
description: r##"Checks for loops that will always `break`, `return` or\n`continue` an outer loop."##,
},
LintCompletion {
label: "clippy::new_ret_no_self",
description: r##"Checks for `new` not returning a type that contains `Self`."##,
},
LintCompletion {
label: "clippy::new_without_default",
description: r##"Checks for types with a `fn new() -> Self` method and no\nimplementation of\n[`Default`](https://doc.rust-lang.org/std/default/trait.Default.html)."##,
},
LintCompletion {
label: "clippy::no_effect",
description: r##"Checks for statements which have no effect."##,
},
LintCompletion {
label: "clippy::non_ascii_literal",
description: r##"Checks for non-ASCII characters in string literals."##,
},
LintCompletion {
label: "clippy::nonminimal_bool",
description: r##"Checks for boolean expressions that can be written more\nconcisely."##,
},
LintCompletion {
label: "clippy::nonsensical_open_options",
description: r##"Checks for duplicate open options as well as combinations\nthat make no sense."##,
},
LintCompletion {
label: "clippy::not_unsafe_ptr_arg_deref",
description: r##"Checks for public functions that dereference raw pointer\narguments but are not marked unsafe."##,
},
LintCompletion {
label: "clippy::ok_expect",
description: r##"Checks for usage of `ok().expect(..)`."##,
},
LintCompletion {
label: "clippy::op_ref",
description: r##"Checks for arguments to `==` which have their address\ntaken to satisfy a bound\nand suggests to dereference the other argument instead"##,
},
LintCompletion {
label: "clippy::option_as_ref_deref",
description: r##"Checks for usage of `_.as_ref().map(Deref::deref)` or it's aliases (such as String::as_str)."##,
},
LintCompletion {
label: "clippy::option_env_unwrap",
description: r##"Checks for usage of `option_env!(...).unwrap()` and\nsuggests usage of the `env!` macro."##,
},
LintCompletion {
label: "clippy::option_if_let_else",
description: r##"Lints usage of `if let Some(v) = ... { y } else { x }` which is more\nidiomatically done with `Option::map_or` (if the else bit is a pure\nexpression) or `Option::map_or_else` (if the else bit is an impure\nexpression)."##,
},
LintCompletion {
label: "clippy::option_map_or_none",
description: r##"Checks for usage of `_.map_or(None, _)`."##,
},
LintCompletion {
label: "clippy::option_map_unit_fn",
description: r##"Checks for usage of `option.map(f)` where f is a function\nor closure that returns the unit type `()`."##,
},
LintCompletion {
label: "clippy::option_option",
description: r##"Checks for use of `Option<Option<_>>` in function signatures and type\ndefinitions"##,
},
LintCompletion {
label: "clippy::or_fun_call",
description: r##"Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`,\netc., and suggests to use `or_else`, `unwrap_or_else`, etc., or\n`unwrap_or_default` instead."##,
},
LintCompletion {
label: "clippy::out_of_bounds_indexing",
description: r##"Checks for out of bounds array indexing with a constant\nindex."##,
},
LintCompletion {
label: "clippy::overflow_check_conditional",
description: r##"Detects classic underflow/overflow checks."##,
},
LintCompletion { label: "clippy::panic", description: r##"Checks for usage of `panic!`."## },
LintCompletion {
label: "clippy::panic_in_result_fn",
description: r##"Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result."##,
},
LintCompletion {
label: "clippy::panic_params",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::panicking_unwrap",
description: r##"Checks for calls of `unwrap[_err]()` that will always fail."##,
},
LintCompletion {
label: "clippy::partialeq_ne_impl",
description: r##"Checks for manual re-implementations of `PartialEq::ne`."##,
},
LintCompletion {
label: "clippy::path_buf_push_overwrite",
description: r##"* Checks for [push](https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.push)\ncalls on `PathBuf` that can cause overwrites."##,
},
LintCompletion {
label: "clippy::pattern_type_mismatch",
description: r##"Checks for patterns that aren't exact representations of the types\nthey are applied to.\n\nTo satisfy this lint, you will have to adjust either the expression that is matched\nagainst or the pattern itself, as well as the bindings that are introduced by the\nadjusted patterns. For matching you will have to either dereference the expression\nwith the `*` operator, or amend the patterns to explicitly match against `&<pattern>`\nor `&mut <pattern>` depending on the reference mutability. For the bindings you need\nto use the inverse. You can leave them as plain bindings if you wish for the value\nto be copied, but you must use `ref mut <variable>` or `ref <variable>` to construct\na reference into the matched structure.\n\nIf you are looking for a way to learn about ownership semantics in more detail, it\nis recommended to look at IDE options available to you to highlight types, lifetimes\nand reference semantics in your code. The available tooling would expose these things\nin a general way even outside of the various pattern matching mechanics. Of course\nthis lint can still be used to highlight areas of interest and ensure a good understanding\nof ownership semantics."##,
},
LintCompletion {
label: "clippy::possible_missing_comma",
description: r##"Checks for possible missing comma in an array. It lints if\nan array element is a binary operator expression and it lies on two lines."##,
},
LintCompletion {
label: "clippy::precedence",
description: r##"Checks for operations where precedence may be unclear\nand suggests to add parentheses. Currently it catches the following:\n* mixed usage of arithmetic and bit shifting/combining operators without\nparentheses\n* a \"negative\" numeric literal (which is really a unary `-` followed by a\nnumeric literal)\n followed by a method call"##,
},
LintCompletion {
label: "clippy::print_literal",
description: r##"This lint warns about the use of literals as `print!`/`println!` args."##,
},
LintCompletion {
label: "clippy::print_stderr",
description: r##"Checks for printing on *stderr*. The purpose of this lint\nis to catch debugging remnants."##,
},
LintCompletion {
label: "clippy::print_stdout",
description: r##"Checks for printing on *stdout*. The purpose of this lint\nis to catch debugging remnants."##,
},
LintCompletion {
label: "clippy::print_with_newline",
description: r##"This lint warns when you use `print!()` with a format\nstring that ends in a newline."##,
},
LintCompletion {
label: "clippy::println_empty_string",
description: r##"This lint warns when you use `println!(\"\")` to\nprint a newline."##,
},
LintCompletion {
label: "clippy::ptr_arg",
description: r##"This lint checks for function arguments of type `&String`\nor `&Vec` unless the references are mutable. It will also suggest you\nreplace `.clone()` calls with the appropriate `.to_owned()`/`to_string()`\ncalls."##,
},
LintCompletion {
label: "clippy::ptr_as_ptr",
description: r##"Checks for `as` casts between raw pointers without changing its mutability,\nnamely `*const T` to `*const U` and `*mut T` to `*mut U`."##,
},
LintCompletion {
label: "clippy::ptr_eq",
description: r##"Use `std::ptr::eq` when applicable"##,
},
LintCompletion {
label: "clippy::ptr_offset_with_cast",
description: r##"Checks for usage of the `offset` pointer method with a `usize` casted to an\n`isize`."##,
},
LintCompletion {
label: "clippy::pub_enum_variant_names",
description: r##"Detects public enumeration variants that are\nprefixed or suffixed by the same characters."##,
},
LintCompletion {
label: "clippy::question_mark",
description: r##"Checks for expressions that could be replaced by the question mark operator."##,
},
LintCompletion {
label: "clippy::range_minus_one",
description: r##"Checks for inclusive ranges where 1 is subtracted from\nthe upper bound, e.g., `x..=(y-1)`."##,
},
LintCompletion {
label: "clippy::range_plus_one",
description: r##"Checks for exclusive ranges where 1 is added to the\nupper bound, e.g., `x..(y+1)`."##,
},
LintCompletion {
label: "clippy::range_step_by_zero",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::range_zip_with_len",
description: r##"Checks for zipping a collection with the range of\n`0.._.len()`."##,
},
LintCompletion {
label: "clippy::rc_buffer",
description: r##"Checks for `Rc<T>` and `Arc<T>` when `T` is a mutable buffer type such as `String` or `Vec`."##,
},
LintCompletion {
label: "clippy::redundant_allocation",
description: r##"Checks for use of redundant allocations anywhere in the code."##,
},
LintCompletion {
label: "clippy::redundant_clone",
description: r##"Checks for a redundant `clone()` (and its relatives) which clones an owned\nvalue that is going to be dropped without further use."##,
},
LintCompletion {
label: "clippy::redundant_closure",
description: r##"Checks for closures which just call another function where\nthe function can be called directly. `unsafe` functions or calls where types\nget adjusted are ignored."##,
},
LintCompletion {
label: "clippy::redundant_closure_call",
description: r##"Detects closures called in the same expression where they\nare defined."##,
},
LintCompletion {
label: "clippy::redundant_closure_for_method_calls",
description: r##"Checks for closures which only invoke a method on the closure\nargument and can be replaced by referencing the method directly."##,
},
LintCompletion {
label: "clippy::redundant_else",
description: r##"Checks for `else` blocks that can be removed without changing semantics."##,
},
LintCompletion {
label: "clippy::redundant_field_names",
description: r##"Checks for fields in struct literals where shorthands\ncould be used."##,
},
LintCompletion {
label: "clippy::redundant_pattern",
description: r##"Checks for patterns in the form `name @ _`."##,
},
LintCompletion {
label: "clippy::redundant_pattern_matching",
description: r##"Lint for redundant pattern matching over `Result`, `Option`,\n`std::task::Poll` or `std::net::IpAddr`"##,
},
LintCompletion {
label: "clippy::redundant_pub_crate",
description: r##"Checks for items declared `pub(crate)` that are not crate visible because they\nare inside a private module."##,
},
LintCompletion {
label: "clippy::redundant_slicing",
description: r##"Checks for redundant slicing expressions which use the full range, and\ndo not change the type."##,
},
LintCompletion {
label: "clippy::redundant_static_lifetimes",
description: r##"Checks for constants and statics with an explicit `'static` lifetime."##,
},
LintCompletion {
label: "clippy::ref_in_deref",
description: r##"Checks for references in expressions that use\nauto dereference."##,
},
LintCompletion {
label: "clippy::ref_option_ref",
description: r##"Checks for usage of `&Option<&T>`."##,
},
LintCompletion {
label: "clippy::regex_macro",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::repeat_once",
description: r##"Checks for usage of `.repeat(1)` and suggest the following method for each types.\n- `.to_string()` for `str`\n- `.clone()` for `String`\n- `.to_vec()` for `slice`"##,
},
LintCompletion {
label: "clippy::replace_consts",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::rest_pat_in_fully_bound_structs",
description: r##"Checks for unnecessary '..' pattern binding on struct when all fields are explicitly matched."##,
},
LintCompletion {
label: "clippy::result_map_or_into_option",
description: r##"Checks for usage of `_.map_or(None, Some)`."##,
},
LintCompletion {
label: "clippy::result_map_unit_fn",
description: r##"Checks for usage of `result.map(f)` where f is a function\nor closure that returns the unit type `()`."##,
},
LintCompletion {
label: "clippy::result_unit_err",
description: r##"Checks for public functions that return a `Result`\nwith an `Err` type of `()`. It suggests using a custom type that\nimplements [`std::error::Error`]."##,
},
LintCompletion {
label: "clippy::reversed_empty_ranges",
description: r##"Checks for range expressions `x..y` where both `x` and `y`\nare constant and `x` is greater or equal to `y`."##,
},
LintCompletion {
label: "clippy::same_functions_in_if_condition",
description: r##"Checks for consecutive `if`s with the same function call."##,
},
LintCompletion {
label: "clippy::same_item_push",
description: r##"Checks whether a for loop is being used to push a constant\nvalue into a Vec."##,
},
LintCompletion {
label: "clippy::search_is_some",
description: r##"Checks for an iterator or string search (such as `find()`,\n`position()`, or `rposition()`) followed by a call to `is_some()`."##,
},
LintCompletion {
label: "clippy::self_assignment",
description: r##"Checks for explicit self-assignments."##,
},
LintCompletion {
label: "clippy::semicolon_if_nothing_returned",
description: r##"Looks for blocks of expressions and fires if the last expression returns `()`\nbut is not followed by a semicolon."##,
},
LintCompletion {
label: "clippy::serde_api_misuse",
description: r##"Checks for mis-uses of the serde API."##,
},
LintCompletion {
label: "clippy::shadow_reuse",
description: r##"Checks for bindings that shadow other bindings already in\nscope, while reusing the original value."##,
},
LintCompletion {
label: "clippy::shadow_same",
description: r##"Checks for bindings that shadow other bindings already in\nscope, while just changing reference level or mutability."##,
},
LintCompletion {
label: "clippy::shadow_unrelated",
description: r##"Checks for bindings that shadow other bindings already in\nscope, either without a initialization or with one that does not even use\nthe original value."##,
},
LintCompletion {
label: "clippy::short_circuit_statement",
description: r##"Checks for the use of short circuit boolean conditions as\na\nstatement."##,
},
LintCompletion {
label: "clippy::should_assert_eq",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::should_implement_trait",
description: r##"Checks for methods that should live in a trait\nimplementation of a `std` trait (see [llogiq's blog\npost](http://llogiq.github.io/2015/07/30/traits.html) for further\ninformation) instead of an inherent implementation."##,
},
LintCompletion {
label: "clippy::similar_names",
description: r##"Checks for names that are very similar and thus confusing."##,
},
LintCompletion {
label: "clippy::single_char_add_str",
description: r##"Warns when using `push_str`/`insert_str` with a single-character string literal\nwhere `push`/`insert` with a `char` would work fine."##,
},
LintCompletion {
label: "clippy::single_char_pattern",
description: r##"Checks for string methods that receive a single-character\n`str` as an argument, e.g., `_.split(\"x\")`."##,
},
LintCompletion {
label: "clippy::single_component_path_imports",
description: r##"Checking for imports with single component use path."##,
},
LintCompletion {
label: "clippy::single_element_loop",
description: r##"Checks whether a for loop has a single element."##,
},
LintCompletion {
label: "clippy::single_match",
description: r##"Checks for matches with a single arm where an `if let`\nwill usually suffice."##,
},
LintCompletion {
label: "clippy::single_match_else",
description: r##"Checks for matches with two arms where an `if let else` will\nusually suffice."##,
},
LintCompletion {
label: "clippy::size_of_in_element_count",
description: r##"Detects expressions where\n`size_of::<T>` or `size_of_val::<T>` is used as a\ncount of elements of type `T`"##,
},
LintCompletion {
label: "clippy::skip_while_next",
description: r##"Checks for usage of `_.skip_while(condition).next()`."##,
},
LintCompletion {
label: "clippy::slow_vector_initialization",
description: r##"Checks slow zero-filled vector initialization"##,
},
LintCompletion {
label: "clippy::stable_sort_primitive",
description: r##"When sorting primitive values (integers, bools, chars, as well\nas arrays, slices, and tuples of such items), it is better to\nuse an unstable sort than a stable sort."##,
},
LintCompletion {
label: "clippy::str_to_string",
description: r##"This lint checks for `.to_string()` method calls on values of type `&str`."##,
},
LintCompletion {
label: "clippy::string_add",
description: r##"Checks for all instances of `x + _` where `x` is of type\n`String`, but only if [`string_add_assign`](#string_add_assign) does *not*\nmatch."##,
},
LintCompletion {
label: "clippy::string_add_assign",
description: r##"Checks for string appends of the form `x = x + y` (without\n`let`!)."##,
},
LintCompletion {
label: "clippy::string_extend_chars",
description: r##"Checks for the use of `.extend(s.chars())` where s is a\n`&str` or `String`."##,
},
LintCompletion {
label: "clippy::string_from_utf8_as_bytes",
description: r##"Check if the string is transformed to byte array and casted back to string."##,
},
LintCompletion {
label: "clippy::string_lit_as_bytes",
description: r##"Checks for the `as_bytes` method called on string literals\nthat contain only ASCII characters."##,
},
LintCompletion {
label: "clippy::string_to_string",
description: r##"This lint checks for `.to_string()` method calls on values of type `String`."##,
},
LintCompletion {
label: "clippy::struct_excessive_bools",
description: r##"Checks for excessive\nuse of bools in structs."##,
},
LintCompletion {
label: "clippy::suboptimal_flops",
description: r##"Looks for floating-point expressions that\ncan be expressed using built-in methods to improve both\naccuracy and performance."##,
},
LintCompletion {
label: "clippy::suspicious_arithmetic_impl",
description: r##"Lints for suspicious operations in impls of arithmetic operators, e.g.\nsubtracting elements in an Add impl."##,
},
LintCompletion {
label: "clippy::suspicious_assignment_formatting",
description: r##"Checks for use of the non-existent `=*`, `=!` and `=-`\noperators."##,
},
LintCompletion {
label: "clippy::suspicious_else_formatting",
description: r##"Checks for formatting of `else`. It lints if the `else`\nis followed immediately by a newline or the `else` seems to be missing."##,
},
LintCompletion {
label: "clippy::suspicious_map",
description: r##"Checks for calls to `map` followed by a `count`."##,
},
LintCompletion {
label: "clippy::suspicious_op_assign_impl",
description: r##"Lints for suspicious operations in impls of OpAssign, e.g.\nsubtracting elements in an AddAssign impl."##,
},
LintCompletion {
label: "clippy::suspicious_operation_groupings",
description: r##"Checks for unlikely usages of binary operators that are almost\ncertainly typos and/or copy/paste errors, given the other usages\nof binary operators nearby."##,
},
LintCompletion {
label: "clippy::suspicious_unary_op_formatting",
description: r##"Checks the formatting of a unary operator on the right hand side\nof a binary operator. It lints if there is no space between the binary and unary operators,\nbut there is a space between the unary and its operand."##,
},
LintCompletion {
label: "clippy::tabs_in_doc_comments",
description: r##"Checks doc comments for usage of tab characters."##,
},
LintCompletion {
label: "clippy::temporary_assignment",
description: r##"Checks for construction of a structure or tuple just to\nassign a value in it."##,
},
LintCompletion {
label: "clippy::temporary_cstring_as_ptr",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::to_digit_is_some",
description: r##"Checks for `.to_digit(..).is_some()` on `char`s."##,
},
LintCompletion {
label: "clippy::to_string_in_display",
description: r##"Checks for uses of `to_string()` in `Display` traits."##,
},
LintCompletion { label: "clippy::todo", description: r##"Checks for usage of `todo!`."## },
LintCompletion {
label: "clippy::too_many_arguments",
description: r##"Checks for functions with too many parameters."##,
},
LintCompletion {
label: "clippy::too_many_lines",
description: r##"Checks for functions with a large amount of lines."##,
},
LintCompletion {
label: "clippy::toplevel_ref_arg",
description: r##"Checks for function arguments and let bindings denoted as\n`ref`."##,
},
LintCompletion {
label: "clippy::trait_duplication_in_bounds",
description: r##"Checks for cases where generics are being used and multiple\nsyntax specifications for trait bounds are used simultaneously."##,
},
LintCompletion {
label: "clippy::transmute_bytes_to_str",
description: r##"Checks for transmutes from a `&[u8]` to a `&str`."##,
},
LintCompletion {
label: "clippy::transmute_float_to_int",
description: r##"Checks for transmutes from a float to an integer."##,
},
LintCompletion {
label: "clippy::transmute_int_to_bool",
description: r##"Checks for transmutes from an integer to a `bool`."##,
},
LintCompletion {
label: "clippy::transmute_int_to_char",
description: r##"Checks for transmutes from an integer to a `char`."##,
},
LintCompletion {
label: "clippy::transmute_int_to_float",
description: r##"Checks for transmutes from an integer to a float."##,
},
LintCompletion {
label: "clippy::transmute_ptr_to_ptr",
description: r##"Checks for transmutes from a pointer to a pointer, or\nfrom a reference to a reference."##,
},
LintCompletion {
label: "clippy::transmute_ptr_to_ref",
description: r##"Checks for transmutes from a pointer to a reference."##,
},
LintCompletion {
label: "clippy::transmutes_expressible_as_ptr_casts",
description: r##"Checks for transmutes that could be a pointer cast."##,
},
LintCompletion {
label: "clippy::transmuting_null",
description: r##"Checks for transmute calls which would receive a null pointer."##,
},
LintCompletion {
label: "clippy::trivial_regex",
description: r##"Checks for trivial [regex](https://crates.io/crates/regex)\ncreation (with `Regex::new`, `RegexBuilder::new`, or `RegexSet::new`)."##,
},
LintCompletion {
label: "clippy::trivially_copy_pass_by_ref",
description: r##"Checks for functions taking arguments by reference, where\nthe argument type is `Copy` and small enough to be more efficient to always\npass by value."##,
},
LintCompletion {
label: "clippy::try_err",
description: r##"Checks for usages of `Err(x)?`."##,
},
LintCompletion {
label: "clippy::type_complexity",
description: r##"Checks for types used in structs, parameters and `let`\ndeclarations above a certain complexity threshold."##,
},
LintCompletion {
label: "clippy::type_repetition_in_bounds",
description: r##"This lint warns about unnecessary type repetitions in trait bounds"##,
},
LintCompletion {
label: "clippy::undropped_manually_drops",
description: r##"Prevents the safe `std::mem::drop` function from being called on `std::mem::ManuallyDrop`."##,
},
LintCompletion {
label: "clippy::unicode_not_nfc",
description: r##"Checks for string literals that contain Unicode in a form\nthat is not equal to its\n[NFC-recomposition](http://www.unicode.org/reports/tr15/#Norm_Forms)."##,
},
LintCompletion {
label: "clippy::unimplemented",
description: r##"Checks for usage of `unimplemented!`."##,
},
LintCompletion {
label: "clippy::uninit_assumed_init",
description: r##"Checks for `MaybeUninit::uninit().assume_init()`."##,
},
LintCompletion {
label: "clippy::unit_arg",
description: r##"Checks for passing a unit value as an argument to a function without using a\nunit literal (`()`)."##,
},
LintCompletion {
label: "clippy::unit_cmp",
description: r##"Checks for comparisons to unit. This includes all binary\ncomparisons (like `==` and `<`) and asserts."##,
},
LintCompletion {
label: "clippy::unit_return_expecting_ord",
description: r##"Checks for functions that expect closures of type\nFn(...) -> Ord where the implemented closure returns the unit type.\nThe lint also suggests to remove the semi-colon at the end of the statement if present."##,
},
LintCompletion {
label: "clippy::unknown_clippy_lints",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unnecessary_cast",
description: r##"Checks for casts to the same type, casts of int literals to integer types\nand casts of float literals to float types."##,
},
LintCompletion {
label: "clippy::unnecessary_filter_map",
description: r##"Checks for `filter_map` calls which could be replaced by `filter` or `map`.\nMore specifically it checks if the closure provided is only performing one of the\nfilter or map operations and suggests the appropriate option."##,
},
LintCompletion {
label: "clippy::unnecessary_fold",
description: r##"Checks for using `fold` when a more succinct alternative exists.\nSpecifically, this checks for `fold`s which could be replaced by `any`, `all`,\n`sum` or `product`."##,
},
LintCompletion {
label: "clippy::unnecessary_lazy_evaluations",
description: r##"As the counterpart to `or_fun_call`, this lint looks for unnecessary\nlazily evaluated closures on `Option` and `Result`.\n\nThis lint suggests changing the following functions, when eager evaluation results in\nsimpler code:\n - `unwrap_or_else` to `unwrap_or`\n - `and_then` to `and`\n - `or_else` to `or`\n - `get_or_insert_with` to `get_or_insert`\n - `ok_or_else` to `ok_or`"##,
},
LintCompletion {
label: "clippy::unnecessary_mut_passed",
description: r##"Detects passing a mutable reference to a function that only\nrequires an immutable reference."##,
},
LintCompletion {
label: "clippy::unnecessary_operation",
description: r##"Checks for expression statements that can be reduced to a\nsub-expression."##,
},
LintCompletion {
label: "clippy::unnecessary_sort_by",
description: r##"Detects uses of `Vec::sort_by` passing in a closure\nwhich compares the two arguments, either directly or indirectly."##,
},
LintCompletion {
label: "clippy::unnecessary_unwrap",
description: r##"Checks for calls of `unwrap[_err]()` that cannot fail."##,
},
LintCompletion {
label: "clippy::unnecessary_wraps",
description: r##"Checks for private functions that only return `Ok` or `Some`."##,
},
LintCompletion {
label: "clippy::unneeded_field_pattern",
description: r##"Checks for structure field patterns bound to wildcards."##,
},
LintCompletion {
label: "clippy::unneeded_wildcard_pattern",
description: r##"Checks for tuple patterns with a wildcard\npattern (`_`) is next to a rest pattern (`..`).\n\n_NOTE_: While `_, ..` means there is at least one element left, `..`\nmeans there are 0 or more elements left. This can make a difference\nwhen refactoring, but shouldn't result in errors in the refactored code,\nsince the wildcard pattern isn't used anyway."##,
},
LintCompletion {
label: "clippy::unnested_or_patterns",
description: r##"Checks for unnested or-patterns, e.g., `Some(0) | Some(2)` and\nsuggests replacing the pattern with a nested one, `Some(0 | 2)`.\n\nAnother way to think of this is that it rewrites patterns in\n*disjunctive normal form (DNF)* into *conjunctive normal form (CNF)*."##,
},
LintCompletion {
label: "clippy::unreachable",
description: r##"Checks for usage of `unreachable!`."##,
},
LintCompletion {
label: "clippy::unreadable_literal",
description: r##"Warns if a long integral or floating-point constant does\nnot contain underscores."##,
},
LintCompletion {
label: "clippy::unsafe_derive_deserialize",
description: r##"Checks for deriving `serde::Deserialize` on a type that\nhas methods using `unsafe`."##,
},
LintCompletion {
label: "clippy::unsafe_removed_from_name",
description: r##"Checks for imports that remove \"unsafe\" from an item's\nname."##,
},
LintCompletion {
label: "clippy::unsafe_vector_initialization",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unseparated_literal_suffix",
description: r##"Warns if literal suffixes are not separated by an\nunderscore."##,
},
LintCompletion {
label: "clippy::unsound_collection_transmute",
description: r##"Checks for transmutes between collections whose\ntypes have different ABI, size or alignment."##,
},
LintCompletion {
label: "clippy::unstable_as_mut_slice",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unstable_as_slice",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unused_collect",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unused_io_amount",
description: r##"Checks for unused written/read amount."##,
},
LintCompletion {
label: "clippy::unused_label",
description: r##"Nothing. This lint has been deprecated."##,
},
LintCompletion {
label: "clippy::unused_self",
description: r##"Checks methods that contain a `self` argument but don't use it"##,
},
LintCompletion {
label: "clippy::unused_unit",
description: r##"Checks for unit (`()`) expressions that can be removed."##,
},
LintCompletion {
label: "clippy::unusual_byte_groupings",
description: r##"Warns if hexadecimal or binary literals are not grouped\nby nibble or byte."##,
},
LintCompletion {
label: "clippy::unwrap_in_result",
description: r##"Checks for functions of type Result that contain `expect()` or `unwrap()`"##,
},
LintCompletion {
label: "clippy::unwrap_used",
description: r##"Checks for `.unwrap()` calls on `Option`s and on `Result`s."##,
},
LintCompletion {
label: "clippy::upper_case_acronyms",
description: r##"Checks for fully capitalized names and optionally names containing a capitalized acronym."##,
},
LintCompletion {
label: "clippy::use_debug",
description: r##"Checks for use of `Debug` formatting. The purpose of this\nlint is to catch debugging remnants."##,
},
LintCompletion {
label: "clippy::use_self",
description: r##"Checks for unnecessary repetition of structure name when a\nreplacement with `Self` is applicable."##,
},
LintCompletion {
label: "clippy::used_underscore_binding",
description: r##"Checks for the use of bindings with a single leading\nunderscore."##,
},
LintCompletion {
label: "clippy::useless_asref",
description: r##"Checks for usage of `.as_ref()` or `.as_mut()` where the\ntypes before and after the call are the same."##,
},
LintCompletion {
label: "clippy::useless_attribute",
description: r##"Checks for `extern crate` and `use` items annotated with\nlint attributes.\n\nThis lint permits `#[allow(unused_imports)]`, `#[allow(deprecated)]`,\n`#[allow(unreachable_pub)]`, `#[allow(clippy::wildcard_imports)]` and\n`#[allow(clippy::enum_glob_use)]` on `use` items and `#[allow(unused_imports)]` on\n`extern crate` items with a `#[macro_use]` attribute."##,
},
LintCompletion {
label: "clippy::useless_conversion",
description: r##"Checks for `Into`, `TryInto`, `From`, `TryFrom`, or `IntoIter` calls\nwhich uselessly convert to the same type."##,
},
LintCompletion {
label: "clippy::useless_format",
description: r##"Checks for the use of `format!(\"string literal with no\nargument\")` and `format!(\"{}\", foo)` where `foo` is a string."##,
},
LintCompletion {
label: "clippy::useless_let_if_seq",
description: r##"Checks for variable declarations immediately followed by a\nconditional affectation."##,
},
LintCompletion {
label: "clippy::useless_transmute",
description: r##"Checks for transmutes to the original type of the object\nand transmutes that could be a cast."##,
},
LintCompletion {
label: "clippy::useless_vec",
description: r##"Checks for usage of `&vec![..]` when using `&[..]` would\nbe possible."##,
},
LintCompletion {
label: "clippy::vec_box",
description: r##"Checks for use of `Vec<Box<T>>` where T: Sized anywhere in the code.\nCheck the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information."##,
},
LintCompletion {
label: "clippy::vec_init_then_push",
description: r##"Checks for calls to `push` immediately after creating a new `Vec`."##,
},
LintCompletion {
label: "clippy::vec_resize_to_zero",
description: r##"Finds occurrences of `Vec::resize(0, an_int)`"##,
},
LintCompletion {
label: "clippy::verbose_bit_mask",
description: r##"Checks for bit masks that can be replaced by a call\nto `trailing_zeros`"##,
},
LintCompletion {
label: "clippy::verbose_file_reads",
description: r##"Checks for use of File::read_to_end and File::read_to_string."##,
},
LintCompletion {
label: "clippy::vtable_address_comparisons",
description: r##"Checks for comparisons with an address of a trait vtable."##,
},
LintCompletion {
label: "clippy::while_immutable_condition",
description: r##"Checks whether variables used within while loop condition\ncan be (and are) mutated in the body."##,
},
LintCompletion {
label: "clippy::while_let_loop",
description: r##"Detects `loop + match` combinations that are easier\nwritten as a `while let` loop."##,
},
LintCompletion {
label: "clippy::while_let_on_iterator",
description: r##"Checks for `while let` expressions on iterators."##,
},
LintCompletion {
label: "clippy::wildcard_dependencies",
description: r##"Checks for wildcard dependencies in the `Cargo.toml`."##,
},
LintCompletion {
label: "clippy::wildcard_enum_match_arm",
description: r##"Checks for wildcard enum matches using `_`."##,
},
LintCompletion {
label: "clippy::wildcard_imports",
description: r##"Checks for wildcard imports `use _::*`."##,
},
LintCompletion {
label: "clippy::wildcard_in_or_patterns",
description: r##"Checks for wildcard pattern used with others patterns in same match arm."##,
},
LintCompletion {
label: "clippy::write_literal",
description: r##"This lint warns about the use of literals as `write!`/`writeln!` args."##,
},
LintCompletion {
label: "clippy::write_with_newline",
description: r##"This lint warns when you use `write!()` with a format\nstring that\nends in a newline."##,
},
LintCompletion {
label: "clippy::writeln_empty_string",
description: r##"This lint warns when you use `writeln!(buf, \"\")` to\nprint a newline."##,
},
LintCompletion {
label: "clippy::wrong_pub_self_convention",
description: r##"This is the same as\n[`wrong_self_convention`](#wrong_self_convention), but for public items."##,
},
LintCompletion {
label: "clippy::wrong_self_convention",
description: r##"Checks for methods with certain name prefixes and which\ndoesn't match how self is taken. The actual rules are:\n\n|Prefix |`self` taken |\n|-------|----------------------|\n|`as_` |`&self` or `&mut self`|\n|`from_`| none |\n|`into_`|`self` |\n|`is_` |`&self` or none |\n|`to_` |`&self` |"##,
},
LintCompletion {
label: "clippy::wrong_transmute",
description: r##"Checks for transmutes that can't ever be correct on any\narchitecture."##,
},
LintCompletion {
label: "clippy::zero_divided_by_zero",
description: r##"Checks for `0.0 / 0.0`."##,
},
LintCompletion {
label: "clippy::zero_prefixed_literal",
description: r##"Warns if an integral constant literal starts with `0`."##,
},
LintCompletion {
label: "clippy::zero_ptr",
description: r##"Catch casts from `0` to some pointer type"##,
},
LintCompletion {
label: "clippy::zero_sized_map_values",
description: r##"Checks for maps with zero-sized value types anywhere in the code."##,
},
LintCompletion {
label: "clippy::zst_offset",
description: r##"Checks for `offset(_)`, `wrapping_`{`add`, `sub`}, etc. on raw pointers to\nzero-sized types"##,
},
];
|