summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs
blob: 146145523b242d3098232ad0f92176937b000630 (plain)
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
use expect_test::expect;

use super::{check, check_infer, check_no_mismatches, check_types};

#[test]
fn infer_box() {
    check_types(
        r#"
//- /main.rs crate:main deps:std
fn test() {
    let x = box 1;
    let t = (x, box x, box &1, box [1]);
    t;
} //^ (Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32; 1]>)

//- /std.rs crate:std
#[prelude_import] use prelude::*;
mod prelude {}

mod boxed {
    #[lang = "owned_box"]
    pub struct Box<T: ?Sized> {
        inner: *mut T,
    }
}
"#,
    );
}

#[test]
fn infer_box_with_allocator() {
    check_types(
        r#"
//- /main.rs crate:main deps:std
fn test() {
    let x = box 1;
    let t = (x, box x, box &1, box [1]);
    t;
} //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; 1], {unknown}>)

//- /std.rs crate:std
#[prelude_import] use prelude::*;
mod boxed {
    #[lang = "owned_box"]
    pub struct Box<T: ?Sized, A: Allocator> {
        inner: *mut T,
        allocator: A,
    }
}
"#,
    );
}

#[test]
fn infer_adt_self() {
    check_types(
        r#"
enum Nat { Succ(Self), Demo(Nat), Zero }

fn test() {
    let foo: Nat = Nat::Zero;
    if let Nat::Succ(x) = foo {
        x;
    } //^ Nat
}
"#,
    );
}

#[test]
fn self_in_struct_lit() {
    check_infer(
        r#"
        //- /main.rs
        struct S<T> { x: T }

        impl S<u32> {
            fn foo() {
                Self { x: 1 };
            }
        }
        "#,
        expect![[r#"
            49..79 '{     ...     }': ()
            59..72 'Self { x: 1 }': S<u32>
            69..70 '1': u32
        "#]],
    );
}

#[test]
fn type_alias_in_struct_lit() {
    check_infer(
        r#"
        //- /main.rs
        struct S<T> { x: T }

        type SS = S<u32>;

        fn foo() {
            SS { x: 1 };
        }
        "#,
        expect![[r#"
            50..70 '{     ...1 }; }': ()
            56..67 'SS { x: 1 }': S<u32>
            64..65 '1': u32
        "#]],
    );
}

#[test]
fn infer_ranges() {
    check_types(
        r#"
//- minicore: range
fn test() {
    let a = ..;
    let b = 1..;
    let c = ..2u32;
    let d = 1..2usize;
    let e = ..=10;
    let f = 'a'..='z';

    let t = (a, b, c, d, e, f);
    t;
} //^ (RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)
"#,
    );
}

#[test]
fn infer_while_let() {
    check_types(
        r#"
enum Option<T> { Some(T), None }

fn test() {
    let foo: Option<f32> = None;
    while let Option::Some(x) = foo {
        x;
    } //^ f32
}
"#,
    );
}

#[test]
fn infer_basics() {
    check_infer(
        r#"
fn test(a: u32, b: isize, c: !, d: &str) {
    a;
    b;
    c;
    d;
    1usize;
    1isize;
    "test";
    1.0f32;
}
"#,
        expect![[r#"
            8..9 'a': u32
            16..17 'b': isize
            26..27 'c': !
            32..33 'd': &str
            41..120 '{     ...f32; }': ()
            47..48 'a': u32
            54..55 'b': isize
            61..62 'c': !
            68..69 'd': &str
            75..81 '1usize': usize
            87..93 '1isize': isize
            99..105 '"test"': &str
            111..117 '1.0f32': f32
        "#]],
    );
}

#[test]
fn infer_let() {
    check_infer(
        r#"
fn test() {
    let a = 1isize;
    let b: usize = 1;
    let c = b;
    let d: u32;
    let e;
    let f: i32 = e;
}
"#,
        expect![[r#"
            10..117 '{     ...= e; }': ()
            20..21 'a': isize
            24..30 '1isize': isize
            40..41 'b': usize
            51..52 '1': usize
            62..63 'c': usize
            66..67 'b': usize
            77..78 'd': u32
            93..94 'e': i32
            104..105 'f': i32
            113..114 'e': i32
        "#]],
    );
}

#[test]
fn infer_paths() {
    check_infer(
        r#"
fn a() -> u32 { 1 }

mod b {
    pub fn c() -> u32 { 1 }
}

fn test() {
    a();
    b::c();
}
"#,
        expect![[r#"
            14..19 '{ 1 }': u32
            16..17 '1': u32
            51..56 '{ 1 }': u32
            53..54 '1': u32
            70..94 '{     ...c(); }': ()
            76..77 'a': fn a() -> u32
            76..79 'a()': u32
            85..89 'b::c': fn c() -> u32
            85..91 'b::c()': u32
        "#]],
    );
}

#[test]
fn infer_path_type() {
    check_infer(
        r#"
struct S;

impl S {
    fn foo() -> i32 { 1 }
}

fn test() {
    S::foo();
    <S>::foo();
}
"#,
        expect![[r#"
            40..45 '{ 1 }': i32
            42..43 '1': i32
            59..92 '{     ...o(); }': ()
            65..71 'S::foo': fn foo() -> i32
            65..73 'S::foo()': i32
            79..87 '<S>::foo': fn foo() -> i32
            79..89 '<S>::foo()': i32
        "#]],
    );
}

#[test]
fn infer_struct() {
    check_infer(
        r#"
struct A {
    b: B,
    c: C,
}
struct B;
struct C(usize);

fn test() {
    let c = C(1);
    B;
    let a: A = A { b: B, c: C(1) };
    a.b;
    a.c;
}
"#,
        expect![[r#"
            71..153 '{     ...a.c; }': ()
            81..82 'c': C
            85..86 'C': C(usize) -> C
            85..89 'C(1)': C
            87..88 '1': usize
            95..96 'B': B
            106..107 'a': A
            113..132 'A { b:...C(1) }': A
            120..121 'B': B
            126..127 'C': C(usize) -> C
            126..130 'C(1)': C
            128..129 '1': usize
            138..139 'a': A
            138..141 'a.b': B
            147..148 'a': A
            147..150 'a.c': C
        "#]],
    );
}

#[test]
fn infer_enum() {
    check_infer(
        r#"
enum E {
    V1 { field: u32 },
    V2
}
fn test() {
    E::V1 { field: 1 };
    E::V2;
}
"#,
        expect![[r#"
            51..89 '{     ...:V2; }': ()
            57..75 'E::V1 ...d: 1 }': E
            72..73 '1': u32
            81..86 'E::V2': E
        "#]],
    );
}

#[test]
fn infer_union() {
    check_infer(
        r#"
union MyUnion {
    foo: u32,
    bar: f32,
}

fn test() {
    let u = MyUnion { foo: 0 };
    unsafe { baz(u); }
    let u = MyUnion { bar: 0.0 };
    unsafe { baz(u); }
}

unsafe fn baz(u: MyUnion) {
    let inner = u.foo;
    let inner = u.bar;
}
"#,
        expect![[r#"
            57..172 '{     ...); } }': ()
            67..68 'u': MyUnion
            71..89 'MyUnio...o: 0 }': MyUnion
            86..87 '0': u32
            95..113 'unsafe...(u); }': ()
            95..113 'unsafe...(u); }': ()
            104..107 'baz': fn baz(MyUnion)
            104..110 'baz(u)': ()
            108..109 'u': MyUnion
            122..123 'u': MyUnion
            126..146 'MyUnio... 0.0 }': MyUnion
            141..144 '0.0': f32
            152..170 'unsafe...(u); }': ()
            152..170 'unsafe...(u); }': ()
            161..164 'baz': fn baz(MyUnion)
            161..167 'baz(u)': ()
            165..166 'u': MyUnion
            188..189 'u': MyUnion
            200..249 '{     ...bar; }': ()
            210..215 'inner': u32
            218..219 'u': MyUnion
            218..223 'u.foo': u32
            233..238 'inner': f32
            241..242 'u': MyUnion
            241..246 'u.bar': f32
        "#]],
    );
}

#[test]
fn infer_refs() {
    check_infer(
        r#"
fn test(a: &u32, b: &mut u32, c: *const u32, d: *mut u32) {
    a;
    *a;
    &a;
    &mut a;
    b;
    *b;
    &b;
    c;
    *c;
    d;
    *d;
}
        "#,
        expect![[r#"
            8..9 'a': &u32
            17..18 'b': &mut u32
            30..31 'c': *const u32
            45..46 'd': *mut u32
            58..149 '{     ... *d; }': ()
            64..65 'a': &u32
            71..73 '*a': u32
            72..73 'a': &u32
            79..81 '&a': &&u32
            80..81 'a': &u32
            87..93 '&mut a': &mut &u32
            92..93 'a': &u32
            99..100 'b': &mut u32
            106..108 '*b': u32
            107..108 'b': &mut u32
            114..116 '&b': &&mut u32
            115..116 'b': &mut u32
            122..123 'c': *const u32
            129..131 '*c': u32
            130..131 'c': *const u32
            137..138 'd': *mut u32
            144..146 '*d': u32
            145..146 'd': *mut u32
        "#]],
    );
}

#[test]
fn infer_raw_ref() {
    check_infer(
        r#"
fn test(a: i32) {
    &raw mut a;
    &raw const a;
}
"#,
        expect![[r#"
            8..9 'a': i32
            16..53 '{     ...t a; }': ()
            22..32 '&raw mut a': *mut i32
            31..32 'a': i32
            38..50 '&raw const a': *const i32
            49..50 'a': i32
        "#]],
    );
}

#[test]
fn infer_literals() {
    check_infer(
        r##"
        fn test() {
            5i32;
            5f32;
            5f64;
            "hello";
            b"bytes";
            'c';
            b'b';
            3.14;
            5000;
            false;
            true;
            r#"
                //! doc
                // non-doc
                mod foo {}
            "#;
            br#"yolo"#;
            let a = b"a\x20b\
            c";
            let b = br"g\
h";
            let c = br#"x"\"yb"#;
        }
        "##,
        expect![[r##"
            18..478 '{     ...     }': ()
            32..36 '5i32': i32
            50..54 '5f32': f32
            68..72 '5f64': f64
            86..93 '"hello"': &str
            107..115 'b"bytes"': &[u8; 5]
            129..132 ''c'': char
            146..150 'b'b'': u8
            164..168 '3.14': f64
            182..186 '5000': i32
            200..205 'false': bool
            219..223 'true': bool
            237..333 'r#"   ...    "#': &str
            347..357 'br#"yolo"#': &[u8; 4]
            375..376 'a': &[u8; 4]
            379..403 'b"a\x2...    c"': &[u8; 4]
            421..422 'b': &[u8; 4]
            425..433 'br"g\ h"': &[u8; 4]
            451..452 'c': &[u8; 6]
            455..467 'br#"x"\"yb"#': &[u8; 6]
        "##]],
    );
}

#[test]
fn infer_unary_op() {
    check_infer(
        r#"
enum SomeType {}

fn test(x: SomeType) {
    let b = false;
    let c = !b;
    let a = 100;
    let d: i128 = -a;
    let e = -100;
    let f = !!!true;
    let g = !42;
    let h = !10u32;
    let j = !a;
    -3.14;
    !3;
    -x;
    !x;
    -"hello";
    !"hello";
}
"#,
        expect![[r#"
            26..27 'x': SomeType
            39..271 '{     ...lo"; }': ()
            49..50 'b': bool
            53..58 'false': bool
            68..69 'c': bool
            72..74 '!b': bool
            73..74 'b': bool
            84..85 'a': i128
            88..91 '100': i128
            101..102 'd': i128
            111..113 '-a': i128
            112..113 'a': i128
            123..124 'e': i32
            127..131 '-100': i32
            128..131 '100': i32
            141..142 'f': bool
            145..152 '!!!true': bool
            146..152 '!!true': bool
            147..152 '!true': bool
            148..152 'true': bool
            162..163 'g': i32
            166..169 '!42': i32
            167..169 '42': i32
            179..180 'h': u32
            183..189 '!10u32': u32
            184..189 '10u32': u32
            199..200 'j': i128
            203..205 '!a': i128
            204..205 'a': i128
            211..216 '-3.14': f64
            212..216 '3.14': f64
            222..224 '!3': i32
            223..224 '3': i32
            230..232 '-x': {unknown}
            231..232 'x': SomeType
            238..240 '!x': {unknown}
            239..240 'x': SomeType
            246..254 '-"hello"': {unknown}
            247..254 '"hello"': &str
            260..268 '!"hello"': {unknown}
            261..268 '"hello"': &str
        "#]],
    );
}

#[test]
fn infer_backwards() {
    check_infer(
        r#"
fn takes_u32(x: u32) {}

struct S { i32_field: i32 }

fn test() -> &mut &f64 {
    let a = unknown_function();
    takes_u32(a);
    let b = unknown_function();
    S { i32_field: b };
    let c = unknown_function();
    &mut &c
}
"#,
        expect![[r#"
            13..14 'x': u32
            21..23 '{}': ()
            77..230 '{     ...t &c }': &mut &f64
            87..88 'a': u32
            91..107 'unknow...nction': {unknown}
            91..109 'unknow...tion()': u32
            115..124 'takes_u32': fn takes_u32(u32)
            115..127 'takes_u32(a)': ()
            125..126 'a': u32
            137..138 'b': i32
            141..157 'unknow...nction': {unknown}
            141..159 'unknow...tion()': i32
            165..183 'S { i3...d: b }': S
            180..181 'b': i32
            193..194 'c': f64
            197..213 'unknow...nction': {unknown}
            197..215 'unknow...tion()': f64
            221..228 '&mut &c': &mut &f64
            226..228 '&c': &f64
            227..228 'c': f64
        "#]],
    );
}

#[test]
fn infer_self() {
    check_infer(
        r#"
struct S;

impl S {
    fn test(&self) {
        self;
    }
    fn test2(self: &Self) {
        self;
    }
    fn test3() -> Self {
        S {}
    }
    fn test4() -> Self {
        Self {}
    }
}
"#,
        expect![[r#"
            33..37 'self': &S
            39..60 '{     ...     }': ()
            49..53 'self': &S
            74..78 'self': &S
            87..108 '{     ...     }': ()
            97..101 'self': &S
            132..152 '{     ...     }': S
            142..146 'S {}': S
            176..199 '{     ...     }': S
            186..193 'Self {}': S
        "#]],
    );
}

#[test]
fn infer_self_as_path() {
    check_infer(
        r#"
struct S1;
struct S2(isize);
enum E {
    V1,
    V2(u32),
}

impl S1 {
    fn test() {
        Self;
    }
}
impl S2 {
    fn test() {
        Self(1);
    }
}
impl E {
    fn test() {
        Self::V1;
        Self::V2(1);
    }
}
"#,
        expect![[r#"
            86..107 '{     ...     }': ()
            96..100 'Self': S1
            134..158 '{     ...     }': ()
            144..148 'Self': S2(isize) -> S2
            144..151 'Self(1)': S2
            149..150 '1': isize
            184..230 '{     ...     }': ()
            194..202 'Self::V1': E
            212..220 'Self::V2': V2(u32) -> E
            212..223 'Self::V2(1)': E
            221..222 '1': u32
        "#]],
    );
}

#[test]
fn infer_binary_op() {
    check_infer(
        r#"
fn f(x: bool) -> i32 {
    0i32
}

fn test() -> bool {
    let x = a && b;
    let y = true || false;
    let z = x == y;
    let t = x != y;
    let minus_forty: isize = -40isize;
    let h = minus_forty <= CONST_2;
    let c = f(z || y) + 5;
    let d = b;
    let g = minus_forty ^= i;
    let ten: usize = 10;
    let ten_is_eleven = ten == some_num;

    ten < 3
}
"#,
        expect![[r#"
            5..6 'x': bool
            21..33 '{     0i32 }': i32
            27..31 '0i32': i32
            53..369 '{     ... < 3 }': bool
            63..64 'x': bool
            67..68 'a': bool
            67..73 'a && b': bool
            72..73 'b': bool
            83..84 'y': bool
            87..91 'true': bool
            87..100 'true || false': bool
            95..100 'false': bool
            110..111 'z': bool
            114..115 'x': bool
            114..120 'x == y': bool
            119..120 'y': bool
            130..131 't': bool
            134..135 'x': bool
            134..140 'x != y': bool
            139..140 'y': bool
            150..161 'minus_forty': isize
            171..179 '-40isize': isize
            172..179 '40isize': isize
            189..190 'h': bool
            193..204 'minus_forty': isize
            193..215 'minus_...ONST_2': bool
            208..215 'CONST_2': isize
            225..226 'c': i32
            229..230 'f': fn f(bool) -> i32
            229..238 'f(z || y)': i32
            229..242 'f(z || y) + 5': i32
            231..232 'z': bool
            231..237 'z || y': bool
            236..237 'y': bool
            241..242 '5': i32
            252..253 'd': {unknown}
            256..257 'b': {unknown}
            267..268 'g': ()
            271..282 'minus_forty': isize
            271..287 'minus_...y ^= i': ()
            286..287 'i': isize
            297..300 'ten': usize
            310..312 '10': usize
            322..335 'ten_is_eleven': bool
            338..341 'ten': usize
            338..353 'ten == some_num': bool
            345..353 'some_num': usize
            360..363 'ten': usize
            360..367 'ten < 3': bool
            366..367 '3': usize
        "#]],
    );
}

#[test]
fn infer_shift_op() {
    check_infer(
        r#"
fn test() {
    1u32 << 5u8;
    1u32 >> 5u8;
}
"#,
        expect![[r#"
            10..47 '{     ...5u8; }': ()
            16..20 '1u32': u32
            16..27 '1u32 << 5u8': u32
            24..27 '5u8': u8
            33..37 '1u32': u32
            33..44 '1u32 >> 5u8': u32
            41..44 '5u8': u8
        "#]],
    );
}

#[test]
fn infer_field_autoderef() {
    check_infer(
        r#"
struct A {
    b: B,
}
struct B;

fn test1(a: A) {
    let a1 = a;
    a1.b;
    let a2 = &a;
    a2.b;
    let a3 = &mut a;
    a3.b;
    let a4 = &&&&&&&a;
    a4.b;
    let a5 = &mut &&mut &&mut a;
    a5.b;
}

fn test2(a1: *const A, a2: *mut A) {
    a1.b;
    a2.b;
}
"#,
        expect![[r#"
            43..44 'a': A
            49..212 '{     ...5.b; }': ()
            59..61 'a1': A
            64..65 'a': A
            71..73 'a1': A
            71..75 'a1.b': B
            85..87 'a2': &A
            90..92 '&a': &A
            91..92 'a': A
            98..100 'a2': &A
            98..102 'a2.b': B
            112..114 'a3': &mut A
            117..123 '&mut a': &mut A
            122..123 'a': A
            129..131 'a3': &mut A
            129..133 'a3.b': B
            143..145 'a4': &&&&&&&A
            148..156 '&&&&&&&a': &&&&&&&A
            149..156 '&&&&&&a': &&&&&&A
            150..156 '&&&&&a': &&&&&A
            151..156 '&&&&a': &&&&A
            152..156 '&&&a': &&&A
            153..156 '&&a': &&A
            154..156 '&a': &A
            155..156 'a': A
            162..164 'a4': &&&&&&&A
            162..166 'a4.b': B
            176..178 'a5': &mut &&mut &&mut A
            181..199 '&mut &...&mut a': &mut &&mut &&mut A
            186..199 '&&mut &&mut a': &&mut &&mut A
            187..199 '&mut &&mut a': &mut &&mut A
            192..199 '&&mut a': &&mut A
            193..199 '&mut a': &mut A
            198..199 'a': A
            205..207 'a5': &mut &&mut &&mut A
            205..209 'a5.b': B
            223..225 'a1': *const A
            237..239 'a2': *mut A
            249..272 '{     ...2.b; }': ()
            255..257 'a1': *const A
            255..259 'a1.b': B
            265..267 'a2': *mut A
            265..269 'a2.b': B
        "#]],
    );
}

#[test]
fn infer_argument_autoderef() {
    check_infer(
        r#"
//- minicore: deref
use core::ops::Deref;
struct A<T>(T);

impl<T> A<T> {
    fn foo(&self) -> &T {
        &self.0
    }
}

struct B<T>(T);

impl<T> Deref for B<T> {
    type Target = T;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn test() {
    let t = A::foo(&&B(B(A(42))));
}
"#,
        expect![[r#"
            66..70 'self': &A<T>
            78..101 '{     ...     }': &T
            88..95 '&self.0': &T
            89..93 'self': &A<T>
            89..95 'self.0': T
            182..186 'self': &B<T>
            205..228 '{     ...     }': &T
            215..222 '&self.0': &T
            216..220 'self': &B<T>
            216..222 'self.0': T
            242..280 '{     ...))); }': ()
            252..253 't': &i32
            256..262 'A::foo': fn foo<i32>(&A<i32>) -> &i32
            256..277 'A::foo...42))))': &i32
            263..276 '&&B(B(A(42)))': &&B<B<A<i32>>>
            264..276 '&B(B(A(42)))': &B<B<A<i32>>>
            265..266 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
            265..276 'B(B(A(42)))': B<B<A<i32>>>
            267..268 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
            267..275 'B(A(42))': B<A<i32>>
            269..270 'A': A<i32>(i32) -> A<i32>
            269..274 'A(42)': A<i32>
            271..273 '42': i32
        "#]],
    );
}

#[test]
fn infer_method_argument_autoderef() {
    check_infer(
        r#"
//- minicore: deref
use core::ops::Deref;
struct A<T>(*mut T);

impl<T> A<T> {
    fn foo(&self, x: &A<T>) -> &T {
        &*x.0
    }
}

struct B<T>(T);

impl<T> Deref for B<T> {
    type Target = T;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

fn test(a: A<i32>) {
    let t = A(0 as *mut _).foo(&&B(B(a)));
}
"#,
        expect![[r#"
            71..75 'self': &A<T>
            77..78 'x': &A<T>
            93..114 '{     ...     }': &T
            103..108 '&*x.0': &T
            104..108 '*x.0': T
            105..106 'x': &A<T>
            105..108 'x.0': *mut T
            195..199 'self': &B<T>
            218..241 '{     ...     }': &T
            228..235 '&self.0': &T
            229..233 'self': &B<T>
            229..235 'self.0': T
            253..254 'a': A<i32>
            264..310 '{     ...))); }': ()
            274..275 't': &i32
            278..279 'A': A<i32>(*mut i32) -> A<i32>
            278..292 'A(0 as *mut _)': A<i32>
            278..307 'A(0 as...B(a)))': &i32
            280..281 '0': i32
            280..291 '0 as *mut _': *mut i32
            297..306 '&&B(B(a))': &&B<B<A<i32>>>
            298..306 '&B(B(a))': &B<B<A<i32>>>
            299..300 'B': B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
            299..306 'B(B(a))': B<B<A<i32>>>
            301..302 'B': B<A<i32>>(A<i32>) -> B<A<i32>>
            301..305 'B(a)': B<A<i32>>
            303..304 'a': A<i32>
        "#]],
    );
}

#[test]
fn infer_in_elseif() {
    check_infer(
        r#"
struct Foo { field: i32 }
fn main(foo: Foo) {
    if true {

    } else if false {
        foo.field
    }
}
"#,
        expect![[r#"
            34..37 'foo': Foo
            44..108 '{     ...   } }': ()
            50..106 'if tru...     }': ()
            53..57 'true': bool
            58..66 '{      }': ()
            72..106 'if fal...     }': ()
            75..80 'false': bool
            81..106 '{     ...     }': ()
            91..94 'foo': Foo
            91..100 'foo.field': i32
        "#]],
    )
}

#[test]
fn infer_if_match_with_return() {
    check_infer(
        r#"
fn foo() {
    let _x1 = if true {
        1
    } else {
        return;
    };
    let _x2 = if true {
        2
    } else {
        return
    };
    let _x3 = match true {
        true => 3,
        _ => {
            return;
        }
    };
    let _x4 = match true {
        true => 4,
        _ => return
    };
}
"#,
        expect![[r#"
            9..322 '{     ...  }; }': ()
            19..22 '_x1': i32
            25..79 'if tru...     }': i32
            28..32 'true': bool
            33..50 '{     ...     }': i32
            43..44 '1': i32
            56..79 '{     ...     }': i32
            66..72 'return': !
            89..92 '_x2': i32
            95..148 'if tru...     }': i32
            98..102 'true': bool
            103..120 '{     ...     }': i32
            113..114 '2': i32
            126..148 '{     ...     }': !
            136..142 'return': !
            158..161 '_x3': i32
            164..246 'match ...     }': i32
            170..174 'true': bool
            185..189 'true': bool
            185..189 'true': bool
            193..194 '3': i32
            204..205 '_': bool
            209..240 '{     ...     }': i32
            223..229 'return': !
            256..259 '_x4': i32
            262..319 'match ...     }': i32
            268..272 'true': bool
            283..287 'true': bool
            283..287 'true': bool
            291..292 '4': i32
            302..303 '_': bool
            307..313 'return': !
        "#]],
    )
}

#[test]
fn infer_inherent_method() {
    check_infer(
        r#"
        struct A;

        impl A {
            fn foo(self, x: u32) -> i32 {}
        }

        mod b {
            impl super::A {
                pub fn bar(&self, x: u64) -> i64 {}
            }
        }

        fn test(a: A) {
            a.foo(1);
            (&a).bar(1);
            a.bar(1);
        }
        "#,
        expect![[r#"
            31..35 'self': A
            37..38 'x': u32
            52..54 '{}': i32
            106..110 'self': &A
            112..113 'x': u64
            127..129 '{}': i64
            147..148 'a': A
            153..201 '{     ...(1); }': ()
            159..160 'a': A
            159..167 'a.foo(1)': i32
            165..166 '1': u32
            173..184 '(&a).bar(1)': i64
            174..176 '&a': &A
            175..176 'a': A
            182..183 '1': u64
            190..191 'a': A
            190..198 'a.bar(1)': i64
            196..197 '1': u64
        "#]],
    );
}

#[test]
fn infer_inherent_method_str() {
    check_infer(
        r#"
        #[lang = "str"]
        impl str {
            fn foo(&self) -> i32 {}
        }

        fn test() {
            "foo".foo();
        }
        "#,
        expect![[r#"
            39..43 'self': &str
            52..54 '{}': i32
            68..88 '{     ...o(); }': ()
            74..79 '"foo"': &str
            74..85 '"foo".foo()': i32
        "#]],
    );
}

#[test]
fn infer_tuple() {
    check_infer(
        r#"
        fn test(x: &str, y: isize) {
            let a: (u32, &str) = (1, "a");
            let b = (a, x);
            let c = (y, x);
            let d = (c, x);
            let e = (1, "e");
            let f = (e, "d");
        }
        "#,
        expect![[r#"
            8..9 'x': &str
            17..18 'y': isize
            27..169 '{     ...d"); }': ()
            37..38 'a': (u32, &str)
            54..62 '(1, "a")': (u32, &str)
            55..56 '1': u32
            58..61 '"a"': &str
            72..73 'b': ((u32, &str), &str)
            76..82 '(a, x)': ((u32, &str), &str)
            77..78 'a': (u32, &str)
            80..81 'x': &str
            92..93 'c': (isize, &str)
            96..102 '(y, x)': (isize, &str)
            97..98 'y': isize
            100..101 'x': &str
            112..113 'd': ((isize, &str), &str)
            116..122 '(c, x)': ((isize, &str), &str)
            117..118 'c': (isize, &str)
            120..121 'x': &str
            132..133 'e': (i32, &str)
            136..144 '(1, "e")': (i32, &str)
            137..138 '1': i32
            140..143 '"e"': &str
            154..155 'f': ((i32, &str), &str)
            158..166 '(e, "d")': ((i32, &str), &str)
            159..160 'e': (i32, &str)
            162..165 '"d"': &str
        "#]],
    );
}

#[test]
fn infer_array() {
    check_infer(
        r#"
        fn test(x: &str, y: isize) {
            let a = [x];
            let b = [a, a];
            let c = [b, b];

            let d = [y, 1, 2, 3];
            let d = [1, y, 2, 3];
            let e = [y];
            let f = [d, d];
            let g = [e, e];

            let h = [1, 2];
            let i = ["a", "b"];

            let b = [a, ["b"]];
            let x: [u8; 0] = [];
            let y: [u8; 2+2] = [1,2,3,4];
        }
        "#,
        expect![[r#"
            8..9 'x': &str
            17..18 'y': isize
            27..326 '{     ...,4]; }': ()
            37..38 'a': [&str; 1]
            41..44 '[x]': [&str; 1]
            42..43 'x': &str
            54..55 'b': [[&str; 1]; 2]
            58..64 '[a, a]': [[&str; 1]; 2]
            59..60 'a': [&str; 1]
            62..63 'a': [&str; 1]
            74..75 'c': [[[&str; 1]; 2]; 2]
            78..84 '[b, b]': [[[&str; 1]; 2]; 2]
            79..80 'b': [[&str; 1]; 2]
            82..83 'b': [[&str; 1]; 2]
            95..96 'd': [isize; 4]
            99..111 '[y, 1, 2, 3]': [isize; 4]
            100..101 'y': isize
            103..104 '1': isize
            106..107 '2': isize
            109..110 '3': isize
            121..122 'd': [isize; 4]
            125..137 '[1, y, 2, 3]': [isize; 4]
            126..127 '1': isize
            129..130 'y': isize
            132..133 '2': isize
            135..136 '3': isize
            147..148 'e': [isize; 1]
            151..154 '[y]': [isize; 1]
            152..153 'y': isize
            164..165 'f': [[isize; 4]; 2]
            168..174 '[d, d]': [[isize; 4]; 2]
            169..170 'd': [isize; 4]
            172..173 'd': [isize; 4]
            184..185 'g': [[isize; 1]; 2]
            188..194 '[e, e]': [[isize; 1]; 2]
            189..190 'e': [isize; 1]
            192..193 'e': [isize; 1]
            205..206 'h': [i32; 2]
            209..215 '[1, 2]': [i32; 2]
            210..211 '1': i32
            213..214 '2': i32
            225..226 'i': [&str; 2]
            229..239 '["a", "b"]': [&str; 2]
            230..233 '"a"': &str
            235..238 '"b"': &str
            250..251 'b': [[&str; 1]; 2]
            254..264 '[a, ["b"]]': [[&str; 1]; 2]
            255..256 'a': [&str; 1]
            258..263 '["b"]': [&str; 1]
            259..262 '"b"': &str
            274..275 'x': [u8; 0]
            287..289 '[]': [u8; 0]
            299..300 'y': [u8; 4]
            314..323 '[1,2,3,4]': [u8; 4]
            315..316 '1': u8
            317..318 '2': u8
            319..320 '3': u8
            321..322 '4': u8
        "#]],
    );
}

#[test]
fn infer_struct_generics() {
    check_infer(
        r#"
        struct A<T> {
            x: T,
        }

        fn test(a1: A<u32>, i: i32) {
            a1.x;
            let a2 = A { x: i };
            a2.x;
            let a3 = A::<i128> { x: 1 };
            a3.x;
        }
        "#,
        expect![[r#"
            35..37 'a1': A<u32>
            47..48 'i': i32
            55..146 '{     ...3.x; }': ()
            61..63 'a1': A<u32>
            61..65 'a1.x': u32
            75..77 'a2': A<i32>
            80..90 'A { x: i }': A<i32>
            87..88 'i': i32
            96..98 'a2': A<i32>
            96..100 'a2.x': i32
            110..112 'a3': A<i128>
            115..133 'A::<i1...x: 1 }': A<i128>
            130..131 '1': i128
            139..141 'a3': A<i128>
            139..143 'a3.x': i128
        "#]],
    );
}

#[test]
fn infer_tuple_struct_generics() {
    check_infer(
        r#"
        struct A<T>(T);
        enum Option<T> { Some(T), None }
        use Option::*;

        fn test() {
            A(42);
            A(42u128);
            Some("x");
            Option::Some("x");
            None;
            let x: Option<i64> = None;
        }
        "#,
        expect![[r#"
            75..183 '{     ...one; }': ()
            81..82 'A': A<i32>(i32) -> A<i32>
            81..86 'A(42)': A<i32>
            83..85 '42': i32
            92..93 'A': A<u128>(u128) -> A<u128>
            92..101 'A(42u128)': A<u128>
            94..100 '42u128': u128
            107..111 'Some': Some<&str>(&str) -> Option<&str>
            107..116 'Some("x")': Option<&str>
            112..115 '"x"': &str
            122..134 'Option::Some': Some<&str>(&str) -> Option<&str>
            122..139 'Option...e("x")': Option<&str>
            135..138 '"x"': &str
            145..149 'None': Option<{unknown}>
            159..160 'x': Option<i64>
            176..180 'None': Option<i64>
        "#]],
    );
}

#[test]
fn infer_function_generics() {
    check_infer(
        r#"
        fn id<T>(t: T) -> T { t }

        fn test() {
            id(1u32);
            id::<i128>(1);
            let x: u64 = id(1);
        }
        "#,
        expect![[r#"
            9..10 't': T
            20..25 '{ t }': T
            22..23 't': T
            37..97 '{     ...(1); }': ()
            43..45 'id': fn id<u32>(u32) -> u32
            43..51 'id(1u32)': u32
            46..50 '1u32': u32
            57..67 'id::<i128>': fn id<i128>(i128) -> i128
            57..70 'id::<i128>(1)': i128
            68..69 '1': i128
            80..81 'x': u64
            89..91 'id': fn id<u64>(u64) -> u64
            89..94 'id(1)': u64
            92..93 '1': u64
        "#]],
    );
}

#[test]
fn infer_impl_generics_basic() {
    check_infer(
        r#"
        struct A<T1, T2> {
            x: T1,
            y: T2,
        }
        impl<Y, X> A<X, Y> {
            fn x(self) -> X {
                self.x
            }
            fn y(self) -> Y {
                self.y
            }
            fn z<T>(self, t: T) -> (X, Y, T) {
                (self.x, self.y, t)
            }
        }

        fn test() -> i128 {
            let a = A { x: 1u64, y: 1i64 };
            a.x();
            a.y();
            a.z(1i128);
            a.z::<u128>(1);
        }
        "#,
        expect![[r#"
            73..77 'self': A<X, Y>
            84..106 '{     ...     }': X
            94..98 'self': A<X, Y>
            94..100 'self.x': X
            116..120 'self': A<X, Y>
            127..149 '{     ...     }': Y
            137..141 'self': A<X, Y>
            137..143 'self.y': Y
            162..166 'self': A<X, Y>
            168..169 't': T
            187..222 '{     ...     }': (X, Y, T)
            197..216 '(self.....y, t)': (X, Y, T)
            198..202 'self': A<X, Y>
            198..204 'self.x': X
            206..210 'self': A<X, Y>
            206..212 'self.y': Y
            214..215 't': T
            244..341 '{     ...(1); }': i128
            254..255 'a': A<u64, i64>
            258..280 'A { x:...1i64 }': A<u64, i64>
            265..269 '1u64': u64
            274..278 '1i64': i64
            286..287 'a': A<u64, i64>
            286..291 'a.x()': u64
            297..298 'a': A<u64, i64>
            297..302 'a.y()': i64
            308..309 'a': A<u64, i64>
            308..318 'a.z(1i128)': (u64, i64, i128)
            312..317 '1i128': i128
            324..325 'a': A<u64, i64>
            324..338 'a.z::<u128>(1)': (u64, i64, u128)
            336..337 '1': u128
        "#]],
    );
}

#[test]
fn infer_impl_generics_with_autoderef() {
    check_infer(
        r#"
        enum Option<T> {
            Some(T),
            None,
        }
        impl<T> Option<T> {
            fn as_ref(&self) -> Option<&T> {}
        }
        fn test(o: Option<u32>) {
            (&o).as_ref();
            o.as_ref();
        }
        "#,
        expect![[r#"
            77..81 'self': &Option<T>
            97..99 '{}': Option<&T>
            110..111 'o': Option<u32>
            126..164 '{     ...f(); }': ()
            132..145 '(&o).as_ref()': Option<&u32>
            133..135 '&o': &Option<u32>
            134..135 'o': Option<u32>
            151..152 'o': Option<u32>
            151..161 'o.as_ref()': Option<&u32>
        "#]],
    );
}

#[test]
fn infer_generic_chain() {
    check_infer(
        r#"
        struct A<T> {
            x: T,
        }
        impl<T2> A<T2> {
            fn x(self) -> T2 {
                self.x
            }
        }
        fn id<T>(t: T) -> T { t }

        fn test() -> i128 {
            let x = 1;
            let y = id(x);
            let a = A { x: id(y) };
            let z = id(a.x);
            let b = A { x: z };
            b.x()
        }
        "#,
        expect![[r#"
            52..56 'self': A<T2>
            64..86 '{     ...     }': T2
            74..78 'self': A<T2>
            74..80 'self.x': T2
            98..99 't': T
            109..114 '{ t }': T
            111..112 't': T
            134..254 '{     ....x() }': i128
            144..145 'x': i128
            148..149 '1': i128
            159..160 'y': i128
            163..165 'id': fn id<i128>(i128) -> i128
            163..168 'id(x)': i128
            166..167 'x': i128
            178..179 'a': A<i128>
            182..196 'A { x: id(y) }': A<i128>
            189..191 'id': fn id<i128>(i128) -> i128
            189..194 'id(y)': i128
            192..193 'y': i128
            206..207 'z': i128
            210..212 'id': fn id<i128>(i128) -> i128
            210..217 'id(a.x)': i128
            213..214 'a': A<i128>
            213..216 'a.x': i128
            227..228 'b': A<i128>
            231..241 'A { x: z }': A<i128>
            238..239 'z': i128
            247..248 'b': A<i128>
            247..252 'b.x()': i128
        "#]],
    );
}

#[test]
fn infer_associated_const() {
    check_infer(
        r#"
        struct Struct;

        impl Struct {
            const FOO: u32 = 1;
        }

        enum Enum {}

        impl Enum {
            const BAR: u32 = 2;
        }

        trait Trait {
            const ID: u32;
        }

        struct TraitTest;

        impl Trait for TraitTest {
            const ID: u32 = 5;
        }

        fn test() {
            let x = Struct::FOO;
            let y = Enum::BAR;
            let z = TraitTest::ID;
        }
        "#,
        expect![[r#"
            51..52 '1': u32
            104..105 '2': u32
            212..213 '5': u32
            228..306 '{     ...:ID; }': ()
            238..239 'x': u32
            242..253 'Struct::FOO': u32
            263..264 'y': u32
            267..276 'Enum::BAR': u32
            286..287 'z': u32
            290..303 'TraitTest::ID': u32
        "#]],
    );
}

#[test]
fn infer_type_alias() {
    check_infer(
        r#"
        struct A<X, Y> { x: X, y: Y }
        type Foo = A<u32, i128>;
        type Bar<T> = A<T, u128>;
        type Baz<U, V> = A<V, U>;
        fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) {
            x.x;
            x.y;
            y.x;
            y.y;
            z.x;
            z.y;
        }
        mod m {
            pub enum Enum {
                Foo(u8),
            }
            pub type Alias = Enum;
        }
        fn f() {
            let e = m::Alias::Foo(0);
            let m::Alias::Foo(x) = &e;
        }
        "#,
        expect![[r#"
            115..116 'x': A<u32, i128>
            123..124 'y': A<&str, u128>
            137..138 'z': A<u8, i8>
            153..210 '{     ...z.y; }': ()
            159..160 'x': A<u32, i128>
            159..162 'x.x': u32
            168..169 'x': A<u32, i128>
            168..171 'x.y': i128
            177..178 'y': A<&str, u128>
            177..180 'y.x': &str
            186..187 'y': A<&str, u128>
            186..189 'y.y': u128
            195..196 'z': A<u8, i8>
            195..198 'z.x': u8
            204..205 'z': A<u8, i8>
            204..207 'z.y': i8
            298..362 '{     ... &e; }': ()
            308..309 'e': Enum
            312..325 'm::Alias::Foo': Foo(u8) -> Enum
            312..328 'm::Ali...Foo(0)': Enum
            326..327 '0': u8
            338..354 'm::Ali...Foo(x)': Enum
            352..353 'x': &u8
            357..359 '&e': &Enum
            358..359 'e': Enum
        "#]],
    )
}

#[test]
fn recursive_type_alias() {
    check_infer(
        r#"
        struct A<X> {}
        type Foo = Foo;
        type Bar = A<Bar>;
        fn test(x: Foo) {}
        "#,
        expect![[r#"
            58..59 'x': {unknown}
            66..68 '{}': ()
        "#]],
    )
}

#[test]
fn infer_type_param() {
    check_infer(
        r#"
        fn id<T>(x: T) -> T {
            x
        }

        fn clone<T>(x: &T) -> T {
            *x
        }

        fn test() {
            let y = 10u32;
            id(y);
            let x: bool = clone(z);
            id::<i128>(1);
        }
        "#,
        expect![[r#"
            9..10 'x': T
            20..29 '{     x }': T
            26..27 'x': T
            43..44 'x': &T
            55..65 '{     *x }': T
            61..63 '*x': T
            62..63 'x': &T
            77..157 '{     ...(1); }': ()
            87..88 'y': u32
            91..96 '10u32': u32
            102..104 'id': fn id<u32>(u32) -> u32
            102..107 'id(y)': u32
            105..106 'y': u32
            117..118 'x': bool
            127..132 'clone': fn clone<bool>(&bool) -> bool
            127..135 'clone(z)': bool
            133..134 'z': &bool
            141..151 'id::<i128>': fn id<i128>(i128) -> i128
            141..154 'id::<i128>(1)': i128
            152..153 '1': i128
        "#]],
    );
}

#[test]
fn infer_const() {
    check_infer(
        r#"
struct Foo;
impl Foo { const ASSOC_CONST: u32 = 0; }
const GLOBAL_CONST: u32 = 101;
fn test() {
    const LOCAL_CONST: u32 = 99;
    let x = LOCAL_CONST;
    let z = GLOBAL_CONST;
    let id = Foo::ASSOC_CONST;
}
"#,
        expect![[r#"
            48..49 '0': u32
            79..82 '101': u32
            94..212 '{     ...NST; }': ()
            137..138 'x': u32
            141..152 'LOCAL_CONST': u32
            162..163 'z': u32
            166..178 'GLOBAL_CONST': u32
            188..190 'id': u32
            193..209 'Foo::A..._CONST': u32
            125..127 '99': u32
        "#]],
    );
}

#[test]
fn infer_static() {
    check_infer(
        r#"
static GLOBAL_STATIC: u32 = 101;
static mut GLOBAL_STATIC_MUT: u32 = 101;
fn test() {
    static LOCAL_STATIC: u32 = 99;
    static mut LOCAL_STATIC_MUT: u32 = 99;
    let x = LOCAL_STATIC;
    let y = LOCAL_STATIC_MUT;
    let z = GLOBAL_STATIC;
    let w = GLOBAL_STATIC_MUT;
}
"#,
        expect![[r#"
            28..31 '101': u32
            69..72 '101': u32
            84..279 '{     ...MUT; }': ()
            172..173 'x': u32
            176..188 'LOCAL_STATIC': u32
            198..199 'y': u32
            202..218 'LOCAL_...IC_MUT': u32
            228..229 'z': u32
            232..245 'GLOBAL_STATIC': u32
            255..256 'w': u32
            259..276 'GLOBAL...IC_MUT': u32
            117..119 '99': u32
            160..162 '99': u32
        "#]],
    );
}

#[test]
fn infer_enum_variant() {
    check_infer(
        r#"
enum Foo {
    A = 15,
    B = Foo::A as isize + 1
}
"#,
        expect![[r#"
            19..21 '15': isize
            31..37 'Foo::A': Foo
            31..46 'Foo::A as isize': isize
            31..50 'Foo::A...ze + 1': isize
            49..50 '1': isize
        "#]],
    );
    check_infer(
        r#"
#[repr(u32)]
enum Foo {
    A = 15,
    B = Foo::A as u32 + 1
}
"#,
        expect![[r#"
            32..34 '15': u32
            44..50 'Foo::A': Foo
            44..57 'Foo::A as u32': u32
            44..61 'Foo::A...32 + 1': u32
            60..61 '1': u32
        "#]],
    );
}

#[test]
fn shadowing_primitive() {
    check_types(
        r#"
struct i32;
struct Foo;

impl i32 { fn foo(&self) -> Foo { Foo } }

fn main() {
    let x: i32 = i32;
    x.foo();
  //^^^^^^^ Foo
}"#,
    );
}

#[test]
fn const_eval_array_repeat_expr() {
    check_types(
        r#"
fn main() {
    const X: usize = 6 - 1;
    let t = [(); X + 2];
      //^ [(); 7]
}"#,
    );
}

#[test]
fn shadowing_primitive_with_inner_items() {
    check_types(
        r#"
struct i32;
struct Foo;

impl i32 { fn foo(&self) -> Foo { Foo } }

fn main() {
    fn inner() {}
    let x: i32 = i32;
    x.foo();
  //^^^^^^^ Foo
}"#,
    );
}

#[test]
fn not_shadowing_primitive_by_module() {
    check_types(
        r#"
//- /str.rs
fn foo() {}

//- /main.rs
mod str;
fn foo() -> &'static str { "" }

fn main() {
    foo();
  //^^^^^ &str
}"#,
    );
}

#[test]
fn not_shadowing_module_by_primitive() {
    check_types(
        r#"
//- /str.rs
pub fn foo() -> u32 {0}

//- /main.rs
mod str;
fn foo() -> &'static str { "" }

fn main() {
    str::foo();
  //^^^^^^^^^^ u32
}"#,
    );
}

// This test is actually testing the shadowing behavior within hir_def. It
// lives here because the testing infrastructure in hir_def isn't currently
// capable of asserting the necessary conditions.
#[test]
fn should_be_shadowing_imports() {
    check_types(
        r#"
mod a {
    pub fn foo() -> i8 {0}
    pub struct foo { a: i8 }
}
mod b { pub fn foo () -> u8 {0} }
mod c { pub struct foo { a: u8 } }
mod d {
    pub use super::a::*;
    pub use super::c::foo;
    pub use super::b::foo;
}

fn main() {
    d::foo();
  //^^^^^^^^ u8
    d::foo{a:0};
  //^^^^^^^^^^^ foo
}"#,
    );
}

#[test]
fn closure_return() {
    check_infer(
        r#"
        fn foo() -> u32 {
            let x = || -> usize { return 1; };
        }
        "#,
        expect![[r#"
            16..58 '{     ...; }; }': u32
            26..27 'x': || -> usize
            30..55 '|| -> ...n 1; }': || -> usize
            42..55 '{ return 1; }': usize
            44..52 'return 1': !
            51..52 '1': usize
        "#]],
    );
}

#[test]
fn closure_return_unit() {
    check_infer(
        r#"
        fn foo() -> u32 {
            let x = || { return; };
        }
        "#,
        expect![[r#"
            16..47 '{     ...; }; }': u32
            26..27 'x': || -> ()
            30..44 '|| { return; }': || -> ()
            33..44 '{ return; }': ()
            35..41 'return': !
        "#]],
    );
}

#[test]
fn closure_return_inferred() {
    check_infer(
        r#"
        fn foo() -> u32 {
            let x = || { "test" };
        }
        "#,
        expect![[r#"
            16..46 '{     ..." }; }': u32
            26..27 'x': || -> &str
            30..43 '|| { "test" }': || -> &str
            33..43 '{ "test" }': &str
            35..41 '"test"': &str
        "#]],
    );
}

#[test]
fn generator_types_inferred() {
    check_infer(
        r#"
//- minicore: generator, deref
use core::ops::{Generator, GeneratorState};
use core::pin::Pin;

fn f(v: i64) {}
fn test() {
    let mut g = |r| {
        let a = yield 0;
        let a = yield 1;
        let a = yield 2;
        "return value"
    };

    match Pin::new(&mut g).resume(0usize) {
        GeneratorState::Yielded(y) => { f(y); }
        GeneratorState::Complete(r) => {}
    }
}
        "#,
        expect![[r#"
            70..71 'v': i64
            78..80 '{}': ()
            91..362 '{     ...   } }': ()
            101..106 'mut g': |usize| yields i64 -> &str
            109..218 '|r| { ...     }': |usize| yields i64 -> &str
            110..111 'r': usize
            113..218 '{     ...     }': &str
            127..128 'a': usize
            131..138 'yield 0': usize
            137..138 '0': i64
            152..153 'a': usize
            156..163 'yield 1': usize
            162..163 '1': i64
            177..178 'a': usize
            181..188 'yield 2': usize
            187..188 '2': i64
            198..212 '"return value"': &str
            225..360 'match ...     }': ()
            231..239 'Pin::new': fn new<&mut |usize| yields i64 -> &str>(&mut |usize| yields i64 -> &str) -> Pin<&mut |usize| yields i64 -> &str>
            231..247 'Pin::n...mut g)': Pin<&mut |usize| yields i64 -> &str>
            231..262 'Pin::n...usize)': GeneratorState<i64, &str>
            240..246 '&mut g': &mut |usize| yields i64 -> &str
            245..246 'g': |usize| yields i64 -> &str
            255..261 '0usize': usize
            273..299 'Genera...ded(y)': GeneratorState<i64, &str>
            297..298 'y': i64
            303..312 '{ f(y); }': ()
            305..306 'f': fn f(i64)
            305..309 'f(y)': ()
            307..308 'y': i64
            321..348 'Genera...ete(r)': GeneratorState<i64, &str>
            346..347 'r': &str
            352..354 '{}': ()
        "#]],
    );
}

#[test]
fn generator_resume_yield_return_unit() {
    check_no_mismatches(
        r#"
//- minicore: generator, deref
use core::ops::{Generator, GeneratorState};
use core::pin::Pin;
fn test() {
    let mut g = || {
        let () = yield;
    };

    match Pin::new(&mut g).resume(()) {
        GeneratorState::Yielded(()) => {}
        GeneratorState::Complete(()) => {}
    }
}
        "#,
    );
}

#[test]
fn fn_pointer_return() {
    check_infer(
        r#"
        struct Vtable {
            method: fn(),
        }

        fn main() {
            let vtable = Vtable { method: || {} };
            let m = vtable.method;
        }
        "#,
        expect![[r#"
            47..120 '{     ...hod; }': ()
            57..63 'vtable': Vtable
            66..90 'Vtable...| {} }': Vtable
            83..88 '|| {}': || -> ()
            86..88 '{}': ()
            100..101 'm': fn()
            104..110 'vtable': Vtable
            104..117 'vtable.method': fn()
        "#]],
    );
}

#[test]
fn block_modifiers_smoke_test() {
    check_infer(
        r#"
//- minicore: future, try
async fn main() {
    let x = unsafe { 92 };
    let y = async { async { () }.await };
    let z: core::ops::ControlFlow<(), _> = try { () };
    let w = const { 92 };
    let t = 'a: { 92 };
}
        "#,
        expect![[r#"
            16..193 '{     ...2 }; }': ()
            26..27 'x': i32
            30..43 'unsafe { 92 }': i32
            30..43 'unsafe { 92 }': i32
            39..41 '92': i32
            53..54 'y': impl Future<Output = ()>
            57..85 'async ...wait }': ()
            57..85 'async ...wait }': impl Future<Output = ()>
            65..77 'async { () }': ()
            65..77 'async { () }': impl Future<Output = ()>
            65..83 'async ....await': ()
            73..75 '()': ()
            95..96 'z': ControlFlow<(), ()>
            130..140 'try { () }': ()
            130..140 'try { () }': ControlFlow<(), ()>
            136..138 '()': ()
            150..151 'w': i32
            154..166 'const { 92 }': i32
            154..166 'const { 92 }': i32
            162..164 '92': i32
            176..177 't': i32
            180..190 ''a: { 92 }': i32
            186..188 '92': i32
        "#]],
    )
}
#[test]
fn async_block_early_return() {
    check_infer(
        r#"
//- minicore: future, result, fn
fn test<I, E, F: FnMut() -> Fut, Fut: core::future::Future<Output = Result<I, E>>>(f: F) {}

fn main() {
    async {
        return Err(());
        Ok(())
    };
    test(|| async {
        return Err(());
        Ok(())
    });
}
        "#,
        expect![[r#"
            83..84 'f': F
            89..91 '{}': ()
            103..231 '{     ... }); }': ()
            109..161 'async ...     }': Result<(), ()>
            109..161 'async ...     }': impl Future<Output = Result<(), ()>>
            125..139 'return Err(())': !
            132..135 'Err': Err<(), ()>(()) -> Result<(), ()>
            132..139 'Err(())': Result<(), ()>
            136..138 '()': ()
            149..151 'Ok': Ok<(), ()>(()) -> Result<(), ()>
            149..155 'Ok(())': Result<(), ()>
            152..154 '()': ()
            167..171 'test': fn test<(), (), || -> impl Future<Output = Result<(), ()>>, impl Future<Output = Result<(), ()>>>(|| -> impl Future<Output = Result<(), ()>>)
            167..228 'test(|...    })': ()
            172..227 '|| asy...     }': || -> impl Future<Output = Result<(), ()>>
            175..227 'async ...     }': Result<(), ()>
            175..227 'async ...     }': impl Future<Output = Result<(), ()>>
            191..205 'return Err(())': !
            198..201 'Err': Err<(), ()>(()) -> Result<(), ()>
            198..205 'Err(())': Result<(), ()>
            202..204 '()': ()
            215..217 'Ok': Ok<(), ()>(()) -> Result<(), ()>
            215..221 'Ok(())': Result<(), ()>
            218..220 '()': ()
        "#]],
    )
}

#[test]
fn infer_generic_from_later_assignment() {
    check_infer(
        r#"
        enum Option<T> { Some(T), None }
        use Option::*;

        fn test() {
            let mut end = None;
            loop {
                end = Some(true);
            }
        }
        "#,
        expect![[r#"
            59..129 '{     ...   } }': ()
            69..76 'mut end': Option<bool>
            79..83 'None': Option<bool>
            89..127 'loop {...     }': !
            94..127 '{     ...     }': ()
            104..107 'end': Option<bool>
            104..120 'end = ...(true)': ()
            110..114 'Some': Some<bool>(bool) -> Option<bool>
            110..120 'Some(true)': Option<bool>
            115..119 'true': bool
        "#]],
    );
}

#[test]
fn infer_loop_break_with_val() {
    check_infer(
        r#"
        enum Option<T> { Some(T), None }
        use Option::*;

        fn test() {
            let x = loop {
                if false {
                    break None;
                }

                break Some(true);
            };
        }
        "#,
        expect![[r#"
            59..168 '{     ...  }; }': ()
            69..70 'x': Option<bool>
            73..165 'loop {...     }': Option<bool>
            78..165 '{     ...     }': ()
            88..132 'if fal...     }': ()
            91..96 'false': bool
            97..132 '{     ...     }': ()
            111..121 'break None': !
            117..121 'None': Option<bool>
            142..158 'break ...(true)': !
            148..152 'Some': Some<bool>(bool) -> Option<bool>
            148..158 'Some(true)': Option<bool>
            153..157 'true': bool
        "#]],
    );
}

#[test]
fn infer_loop_break_without_val() {
    check_infer(
        r#"
        enum Option<T> { Some(T), None }
        use Option::*;

        fn test() {
            let x = loop {
                if false {
                    break;
                }
            };
        }
        "#,
        expect![[r#"
            59..136 '{     ...  }; }': ()
            69..70 'x': ()
            73..133 'loop {...     }': ()
            78..133 '{     ...     }': ()
            88..127 'if fal...     }': ()
            91..96 'false': bool
            97..127 '{     ...     }': ()
            111..116 'break': !
        "#]],
    );
}

#[test]
fn infer_labelled_break_with_val() {
    check_infer(
        r#"
        fn foo() {
            let _x = || 'outer: loop {
                let inner = 'inner: loop {
                    let i = Default::default();
                    if (break 'outer i) {
                        loop { break 'inner 5i8; };
                    } else if true {
                        break 'inner 6;
                    }
                    break 7;
                };
                break inner < 8;
            };
        }
        "#,
        expect![[r#"
            9..335 '{     ...  }; }': ()
            19..21 '_x': || -> bool
            24..332 '|| 'ou...     }': || -> bool
            27..332 ''outer...     }': bool
            40..332 '{     ...     }': ()
            54..59 'inner': i8
            62..300 ''inner...     }': i8
            75..300 '{     ...     }': ()
            93..94 'i': bool
            97..113 'Defaul...efault': {unknown}
            97..115 'Defaul...ault()': bool
            129..269 'if (br...     }': ()
            133..147 'break 'outer i': !
            146..147 'i': bool
            149..208 '{     ...     }': ()
            167..193 'loop {...5i8; }': !
            172..193 '{ brea...5i8; }': ()
            174..190 'break ...er 5i8': !
            187..190 '5i8': i8
            214..269 'if tru...     }': ()
            217..221 'true': bool
            222..269 '{     ...     }': ()
            240..254 'break 'inner 6': !
            253..254 '6': i8
            282..289 'break 7': !
            288..289 '7': i8
            310..325 'break inner < 8': !
            316..321 'inner': i8
            316..325 'inner < 8': bool
            324..325 '8': i8
        "#]],
    );
}

#[test]
fn infer_labelled_block_break_with_val() {
    check_infer(
        r#"
fn default<T>() -> T { loop {} }
fn foo() {
    let _x = 'outer: {
        let inner = 'inner: {
            let i = default();
            if (break 'outer i) {
                break 'inner 5i8;
            } else if true {
                break 'inner 6;
            }
            break 'inner 'innermost: { 0 };
            42
        };
        break 'outer inner < 8;
    };
}
"#,
        expect![[r#"
            21..32 '{ loop {} }': T
            23..30 'loop {}': !
            28..30 '{}': ()
            42..381 '{     ...  }; }': ()
            52..54 '_x': bool
            57..378 ''outer...     }': bool
            79..84 'inner': i8
            87..339 ''inner...     }': i8
            113..114 'i': bool
            117..124 'default': fn default<bool>() -> bool
            117..126 'default()': bool
            140..270 'if (br...     }': ()
            144..158 'break 'outer i': !
            157..158 'i': bool
            160..209 '{     ...     }': ()
            178..194 'break ...er 5i8': !
            191..194 '5i8': i8
            215..270 'if tru...     }': ()
            218..222 'true': bool
            223..270 '{     ...     }': ()
            241..255 'break 'inner 6': !
            254..255 '6': i8
            283..313 'break ... { 0 }': !
            296..313 ''inner... { 0 }': i8
            310..311 '0': i8
            327..329 '42': i8
            349..371 'break ...er < 8': !
            362..367 'inner': i8
            362..371 'inner < 8': bool
            370..371 '8': i8
        "#]],
    );
}

#[test]
fn generic_default() {
    check_infer(
        r#"
        struct Thing<T = ()> { t: T }
        enum OtherThing<T = ()> {
            One { t: T },
            Two(T),
        }

        fn test(t1: Thing, t2: OtherThing, t3: Thing<i32>, t4: OtherThing<i32>) {
            t1.t;
            t3.t;
            match t2 {
                OtherThing::One { t } => { t; },
                OtherThing::Two(t) => { t; },
            }
            match t4 {
                OtherThing::One { t } => { t; },
                OtherThing::Two(t) => { t; },
            }
        }
        "#,
        expect![[r#"
            97..99 't1': Thing<()>
            108..110 't2': OtherThing<()>
            124..126 't3': Thing<i32>
            140..142 't4': OtherThing<i32>
            161..384 '{     ...   } }': ()
            167..169 't1': Thing<()>
            167..171 't1.t': ()
            177..179 't3': Thing<i32>
            177..181 't3.t': i32
            187..282 'match ...     }': ()
            193..195 't2': OtherThing<()>
            206..227 'OtherT... { t }': OtherThing<()>
            224..225 't': ()
            231..237 '{ t; }': ()
            233..234 't': ()
            247..265 'OtherT...Two(t)': OtherThing<()>
            263..264 't': ()
            269..275 '{ t; }': ()
            271..272 't': ()
            287..382 'match ...     }': ()
            293..295 't4': OtherThing<i32>
            306..327 'OtherT... { t }': OtherThing<i32>
            324..325 't': i32
            331..337 '{ t; }': ()
            333..334 't': i32
            347..365 'OtherT...Two(t)': OtherThing<i32>
            363..364 't': i32
            369..375 '{ t; }': ()
            371..372 't': i32
        "#]],
    );
}

#[test]
fn generic_default_in_struct_literal() {
    check_infer(
        r#"
        struct Thing<T = ()> { t: T }
        enum OtherThing<T = ()> {
            One { t: T },
            Two(T),
        }

        fn test() {
            let x = Thing { t: loop {} };
            let y = Thing { t: () };
            let z = Thing { t: 1i32 };
            if let Thing { t } = z {
                t;
            }

            let a = OtherThing::One { t: 1i32 };
            let b = OtherThing::Two(1i32);
        }
        "#,
        expect![[r#"
            99..319 '{     ...32); }': ()
            109..110 'x': Thing<!>
            113..133 'Thing ...p {} }': Thing<!>
            124..131 'loop {}': !
            129..131 '{}': ()
            143..144 'y': Thing<()>
            147..162 'Thing { t: () }': Thing<()>
            158..160 '()': ()
            172..173 'z': Thing<i32>
            176..193 'Thing ...1i32 }': Thing<i32>
            187..191 '1i32': i32
            199..240 'if let...     }': ()
            202..221 'let Th... } = z': bool
            206..217 'Thing { t }': Thing<i32>
            214..215 't': i32
            220..221 'z': Thing<i32>
            222..240 '{     ...     }': ()
            232..233 't': i32
            250..251 'a': OtherThing<i32>
            254..281 'OtherT...1i32 }': OtherThing<i32>
            275..279 '1i32': i32
            291..292 'b': OtherThing<i32>
            295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
            295..316 'OtherT...(1i32)': OtherThing<i32>
            311..315 '1i32': i32
        "#]],
    );
}

#[test]
fn generic_default_depending_on_other_type_arg() {
    // FIXME: the {unknown} is a bug
    check_infer(
        r#"
        struct Thing<T = u128, F = fn() -> T> { t: T }

        fn test(t1: Thing<u32>, t2: Thing) {
            t1;
            t2;
            Thing::<_> { t: 1u32 };
        }
        "#,
        expect![[r#"
            56..58 't1': Thing<u32, fn() -> u32>
            72..74 't2': Thing<u128, fn() -> u128>
            83..130 '{     ...2 }; }': ()
            89..91 't1': Thing<u32, fn() -> u32>
            97..99 't2': Thing<u128, fn() -> u128>
            105..127 'Thing:...1u32 }': Thing<u32, fn() -> {unknown}>
            121..125 '1u32': u32
        "#]],
    );
}

#[test]
fn generic_default_depending_on_other_type_arg_forward() {
    // the {unknown} here is intentional, as defaults are not allowed to
    // refer to type parameters coming later
    check_infer(
        r#"
        struct Thing<F = fn() -> T, T = u128> { t: T }

        fn test(t1: Thing) {
            t1;
        }
        "#,
        expect![[r#"
            56..58 't1': Thing<fn() -> {unknown}, u128>
            67..78 '{     t1; }': ()
            73..75 't1': Thing<fn() -> {unknown}, u128>
        "#]],
    );
}

#[test]
fn infer_operator_overload() {
    check_types(
        r#"
//- minicore: add
struct V2([f32; 2]);

impl core::ops::Add<V2> for V2 {
    type Output = V2;
}

fn test() {
    let va = V2([0.0, 1.0]);
    let vb = V2([0.0, 1.0]);

    let r = va + vb;
    //      ^^^^^^^ V2
}

        "#,
    );
}

#[test]
fn infer_const_params() {
    check_infer(
        r#"
        fn foo<const FOO: usize>() {
            let bar = FOO;
        }
        "#,
        expect![[r#"
            27..49 '{     ...FOO; }': ()
            37..40 'bar': usize
            43..46 'FOO': usize
        "#]],
    );
}

#[test]
fn infer_inner_type() {
    check_infer(
        r#"
        fn foo() {
            struct S { field: u32 }
            let s = S { field: 0 };
            let f = s.field;
        }
    "#,
        expect![[r#"
            9..89 '{     ...eld; }': ()
            47..48 's': S
            51..65 'S { field: 0 }': S
            62..63 '0': u32
            75..76 'f': u32
            79..80 's': S
            79..86 's.field': u32
        "#]],
    );
}

#[test]
fn infer_nested_inner_type() {
    check_infer(
        r#"
        fn foo() {
            {
                let s = S { field: 0 };
                let f = s.field;
            }
            struct S { field: u32 }
        }
    "#,
        expect![[r#"
            9..109 '{     ...32 } }': ()
            15..79 '{     ...     }': ()
            29..30 's': S
            33..47 'S { field: 0 }': S
            44..45 '0': u32
            61..62 'f': u32
            65..66 's': S
            65..72 's.field': u32
        "#]],
    );
}

#[test]
fn inner_use_enum_rename() {
    check_infer(
        r#"
        enum Request {
            Info
        }

        fn f() {
            use Request as R;

            let r = R::Info;
            match r {
                R::Info => {}
            }
        }
    "#,
        expect![[r#"
            34..123 '{     ...   } }': ()
            67..68 'r': Request
            71..78 'R::Info': Request
            84..121 'match ...     }': ()
            90..91 'r': Request
            102..109 'R::Info': Request
            113..115 '{}': ()
        "#]],
    )
}

#[test]
fn box_into_vec() {
    check_infer(
        r#"
#[lang = "sized"]
pub trait Sized {}

#[lang = "unsize"]
pub trait Unsize<T: ?Sized> {}

#[lang = "coerce_unsized"]
pub trait CoerceUnsized<T> {}

pub unsafe trait Allocator {}

pub struct Global;
unsafe impl Allocator for Global {}

#[lang = "owned_box"]
#[fundamental]
pub struct Box<T: ?Sized, A: Allocator = Global>;

impl<T: ?Sized + Unsize<U>, U: ?Sized, A: Allocator> CoerceUnsized<Box<U, A>> for Box<T, A> {}

pub struct Vec<T, A: Allocator = Global> {}

#[lang = "slice"]
impl<T> [T] {}

#[lang = "slice_alloc"]
impl<T> [T] {
    pub fn into_vec<A: Allocator>(self: Box<Self, A>) -> Vec<T, A> {
        unimplemented!()
    }
}

fn test() {
    let vec = <[_]>::into_vec(box [1i32]);
    let v: Vec<Box<dyn B>> = <[_]> :: into_vec(box [box Astruct]);
}

trait B{}
struct Astruct;
impl B for Astruct {}
"#,
        expect![[r#"
            569..573 'self': Box<[T], A>
            602..634 '{     ...     }': Vec<T, A>
            648..761 '{     ...t]); }': ()
            658..661 'vec': Vec<i32, Global>
            664..679 '<[_]>::into_vec': fn into_vec<i32, Global>(Box<[i32], Global>) -> Vec<i32, Global>
            664..691 '<[_]>:...1i32])': Vec<i32, Global>
            680..690 'box [1i32]': Box<[i32; 1], Global>
            684..690 '[1i32]': [i32; 1]
            685..689 '1i32': i32
            701..702 'v': Vec<Box<dyn B, Global>, Global>
            722..739 '<[_]> ...to_vec': fn into_vec<Box<dyn B, Global>, Global>(Box<[Box<dyn B, Global>], Global>) -> Vec<Box<dyn B, Global>, Global>
            722..758 '<[_]> ...ruct])': Vec<Box<dyn B, Global>, Global>
            740..757 'box [b...truct]': Box<[Box<dyn B, Global>; 1], Global>
            744..757 '[box Astruct]': [Box<dyn B, Global>; 1]
            745..756 'box Astruct': Box<Astruct, Global>
            749..756 'Astruct': Astruct
        "#]],
    )
}

#[test]
fn cfgd_out_assoc_items() {
    check_types(
        r#"
struct S;

impl S {
    #[cfg(FALSE)]
    const C: S = S;
}

fn f() {
    S::C;
  //^^^^ {unknown}
}
    "#,
    )
}

#[test]
fn infer_missing_type() {
    check_types(
        r#"
struct S;

fn f() {
    let s: = S;
      //^ S
}
    "#,
    );
}

#[test]
fn infer_type_alias_variant() {
    check_infer(
        r#"
type Qux = Foo;
enum Foo {
    Bar(i32),
    Baz { baz: f32 }
}

fn f() {
    match Foo::Bar(3) {
        Qux::Bar(bar) => (),
        Qux::Baz { baz } => (),
    }
}
    "#,
        expect![[r#"
            72..166 '{     ...   } }': ()
            78..164 'match ...     }': ()
            84..92 'Foo::Bar': Bar(i32) -> Foo
            84..95 'Foo::Bar(3)': Foo
            93..94 '3': i32
            106..119 'Qux::Bar(bar)': Foo
            115..118 'bar': i32
            123..125 '()': ()
            135..151 'Qux::B... baz }': Foo
            146..149 'baz': f32
            155..157 '()': ()
        "#]],
    )
}

#[test]
fn infer_boxed_self_receiver() {
    check_infer(
        r#"
//- minicore: deref
use core::ops::Deref;

struct Box<T>(T);

impl<T> Deref for Box<T> {
    type Target = T;
    fn deref(&self) -> &Self::Target;
}

struct Foo<T>(T);

impl<T> Foo<T> {
    fn get_inner<'a>(self: &'a Box<Self>) -> &'a T {}

    fn get_self<'a>(self: &'a Box<Self>) -> &'a Self {}

    fn into_inner(self: Box<Self>) -> Self {}
}

fn main() {
    let boxed = Box(Foo(0_i32));

    let bad1 = boxed.get_inner();
    let good1 = Foo::get_inner(&boxed);

    let bad2 = boxed.get_self();
    let good2 = Foo::get_self(&boxed);

    let inner = boxed.into_inner();
}
        "#,
        expect![[r#"
            104..108 'self': &Box<T>
            188..192 'self': &Box<Foo<T>>
            218..220 '{}': &T
            242..246 'self': &Box<Foo<T>>
            275..277 '{}': &Foo<T>
            297..301 'self': Box<Foo<T>>
            322..324 '{}': Foo<T>
            338..559 '{     ...r(); }': ()
            348..353 'boxed': Box<Foo<i32>>
            356..359 'Box': Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
            356..371 'Box(Foo(0_i32))': Box<Foo<i32>>
            360..363 'Foo': Foo<i32>(i32) -> Foo<i32>
            360..370 'Foo(0_i32)': Foo<i32>
            364..369 '0_i32': i32
            382..386 'bad1': &i32
            389..394 'boxed': Box<Foo<i32>>
            389..406 'boxed....nner()': &i32
            416..421 'good1': &i32
            424..438 'Foo::get_inner': fn get_inner<i32>(&Box<Foo<i32>>) -> &i32
            424..446 'Foo::g...boxed)': &i32
            439..445 '&boxed': &Box<Foo<i32>>
            440..445 'boxed': Box<Foo<i32>>
            457..461 'bad2': &Foo<i32>
            464..469 'boxed': Box<Foo<i32>>
            464..480 'boxed....self()': &Foo<i32>
            490..495 'good2': &Foo<i32>
            498..511 'Foo::get_self': fn get_self<i32>(&Box<Foo<i32>>) -> &Foo<i32>
            498..519 'Foo::g...boxed)': &Foo<i32>
            512..518 '&boxed': &Box<Foo<i32>>
            513..518 'boxed': Box<Foo<i32>>
            530..535 'inner': Foo<i32>
            538..543 'boxed': Box<Foo<i32>>
            538..556 'boxed....nner()': Foo<i32>
        "#]],
    );
}

#[test]
fn prelude_2015() {
    check_types(
        r#"
//- /main.rs edition:2015 crate:main deps:core
fn f() {
    Rust;
  //^^^^ Rust
}

//- /core.rs crate:core
pub mod prelude {
    pub mod rust_2015 {
        pub struct Rust;
    }
}
    "#,
    );
}

#[test]
fn legacy_const_generics() {
    check_no_mismatches(
        r#"
#[rustc_legacy_const_generics(1, 3)]
fn mixed<const N1: &'static str, const N2: bool>(
    a: u8,
    b: i8,
) {}

fn f() {
    mixed(0, "", -1, true);
    mixed::<"", true>(0, -1);
}
    "#,
    );
}

#[test]
fn destructuring_assignment_slice() {
    check_types(
        r#"
fn main() {
    let a;
      //^usize
    [a,] = [0usize];

    let a;
      //^usize
    [a, ..] = [0usize; 5];

    let a;
      //^usize
    [.., a] = [0usize; 5];

    let a;
      //^usize
    [.., a, _] = [0usize; 5];

    let a;
      //^usize
    [_, a, ..] = [0usize; 5];

    let a: &mut i64 = &mut 0;
    [*a, ..] = [1, 2, 3];

    let a: usize;
    let b;
      //^usize
    [a, _, b] = [3, 4, 5];
      //^usize

    let a;
      //^i64
    let b;
      //^i64
    [[a, ..], .., [.., b]] = [[1, 2], [3i64, 4], [5, 6], [7, 8]];
}
        "#,
    );
}

#[test]
fn destructuring_assignment_tuple() {
    check_types(
        r#"
fn main() {
    let a;
      //^char
    let b;
      //^i64
    (a, b) = ('c', 0i64);

    let a;
      //^char
    (a, ..) = ('c', 0i64);

    let a;
      //^i64
    (.., a) = ('c', 0i64);

    let a;
      //^char
    let b;
      //^i64
    (a, .., b) = ('c', 0i64);

    let a;
      //^char
    let b;
      //^bool
    (a, .., b) = ('c', 0i64, true);

    let a;
      //^i64
    let b;
      //^bool
    (_, a, .., b) = ('c', 0i64, true);

    let a;
      //^i64
    let b;
      //^usize
    (_, a, .., b) = ('c', 0i64, true, 0usize);

    let mut a = 1;
      //^^^^^i64
    let mut b: i64 = 0;
    (a, b) = (b, a);
}
        "#,
    );
}

#[test]
fn destructuring_assignment_tuple_struct() {
    check_types(
        r#"
struct S2(char, i64);
struct S3(char, i64, bool);
struct S4(char, i64, bool usize);
fn main() {
    let a;
      //^char
    let b;
      //^i64
    S2(a, b) = S2('c', 0i64);

    let a;
      //^char
    let b;
      //^i64
    S2(a, .., b) = S2('c', 0i64);

    let a;
      //^char
    let b;
      //^bool
    S3(a, .., b) = S3('c', 0i64, true);

    let a;
      //^i64
    let b;
      //^bool
    S3(_, a, .., b) = S3('c', 0i64, true);

    let a;
      //^i64
    let b;
      //^usize
    S4(_, a, .., b) = S4('c', 0i64, true, 0usize);

    struct Swap(i64, i64);

    let mut a = 1;
      //^^^^^i64
    let mut b = 0;
      //^^^^^i64
    Swap(a, b) = Swap(b, a);
}
        "#,
    );
}

#[test]
fn destructuring_assignment_struct() {
    check_types(
        r#"
struct S {
    a: usize,
    b: char,
}
struct T {
    s: S,
    t: i64,
}

fn main() {
    let a;
      //^usize
    let c;
      //^char
    S { a, b: c } = S { a: 3, b: 'b' };

    let a;
      //^char
    S { b: a, .. } = S { a: 3, b: 'b' };

    let a;
      //^char
    S { b: a, _ } = S { a: 3, b: 'b' };

    let a;
      //^usize
    let c;
      //^char
    let t;
      //^i64
    T { s: S { a, b: c }, t } = T { s: S { a: 3, b: 'b' }, t: 0 };
}
        "#,
    );
}

#[test]
fn destructuring_assignment_nested() {
    check_types(
        r#"
struct S {
    a: TS,
    b: [char; 3],
}
struct TS(usize, i64);

fn main() {
    let a;
      //^i32
    let b;
      //^bool
    ([.., a], .., b, _) = ([0, 1, 2], true, 'c');

    let a;
      //^i32
    let b;
      //^i32
    [(.., a, _), .., (b, ..)] = [(1, 2); 5];

    let a;
      //^usize
    let b;
      //^char
    S { a: TS(a, ..), b: [_, b, ..] } = S { a: TS(0, 0), b: ['a'; 3] };
}
        "#,
    );
}

#[test]
fn destructuring_assignment_unit_struct() {
    // taken from rustc; see https://github.com/rust-lang/rust/pull/95380
    check_no_mismatches(
        r#"
struct S;
enum E { V, }
type A = E;

fn main() {
    let mut a;

    (S, a) = (S, ());

    (E::V, a) = (E::V, ());

    (<E>::V, a) = (E::V, ());
    (A::V, a) = (E::V, ());
}

impl S {
    fn check() {
        let a;
        (Self, a) = (S, ());
    }
}

impl E {
    fn check() {
        let a;
        (Self::V, a) = (E::V, ());
    }
}
        "#,
    );
}

#[test]
fn destructuring_assignment_no_default_binding_mode() {
    check(
        r#"
struct S { a: usize }
struct TS(usize);
fn main() {
    let x;
    [x,] = &[1,];
  //^^^^expected &[i32; 1], got [{unknown}; _]

    // FIXME we only want the outermost error, but this matches the current
    // behavior of slice patterns
    let x;
    [(x,),] = &[(1,),];
  // ^^^^expected {unknown}, got ({unknown},)
  //^^^^^^^expected &[(i32,); 1], got [{unknown}; _]

    let x;
    ((x,),) = &((1,),);
  //^^^^^^^expected &((i32,),), got (({unknown},),)

    let x;
    (x,) = &(1,);
  //^^^^expected &(i32,), got ({unknown},)

    let x;
    (S { a: x },) = &(S { a: 42 },);
  //^^^^^^^^^^^^^expected &(S,), got (S,)

    let x;
    S { a: x } = &S { a: 42 };
  //^^^^^^^^^^expected &S, got S

    let x;
    TS(x) = &TS(42);
  //^^^^^expected &TS, got TS
}
        "#,
    );
}

#[test]
fn destructuring_assignment_type_mismatch_on_identifier() {
    check(
        r#"
struct S { v: i64 }
struct TS(i64);
fn main() {
    let mut a: usize = 0;
    (a,) = (0i64,);
   //^expected i64, got usize

    let mut a: usize = 0;
    [a,] = [0i64,];
   //^expected i64, got usize

    let mut a: usize = 0;
    S { v: a } = S { v: 0 };
         //^expected i64, got usize

    let mut a: usize = 0;
    TS(a) = TS(0);
     //^expected i64, got usize
}
        "#,
    );
}

#[test]
fn nested_break() {
    check_no_mismatches(
        r#"
fn func() {
    let int = loop {
        break 0;
        break (break 0);
    };
}
    "#,
    );
}