summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Errors/Types.hs
blob: 4f0d961a3db6d3419a54039972bb29b7da0f7b73 (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
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
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE UndecidableInstances #-}

module GHC.Tc.Errors.Types (
  -- * Main types
    TcRnMessage(..)
  , mkTcRnUnknownMessage
  , TcRnMessageDetailed(..)
  , TypeDataForbids(..)
  , ErrInfo(..)
  , FixedRuntimeRepProvenance(..)
  , pprFixedRuntimeRepProvenance
  , ShadowedNameProvenance(..)
  , RecordFieldPart(..)
  , IllegalNewtypeReason(..)
  , BadRecordUpdateReason(..)
  , InjectivityErrReason(..)
  , HasKinds(..)
  , hasKinds
  , SuggestUndecidableInstances(..)
  , suggestUndecidableInstances
  , SuggestUnliftedTypes(..)
  , DataSort(..), ppDataSort
  , AllowedDataResKind(..)
  , NotClosedReason(..)
  , SuggestPartialTypeSignatures(..)
  , suggestPartialTypeSignatures
  , DeriveInstanceErrReason(..)
  , UsingGeneralizedNewtypeDeriving(..)
  , usingGeneralizedNewtypeDeriving
  , DeriveAnyClassEnabled(..)
  , deriveAnyClassEnabled
  , DeriveInstanceBadConstructor(..)
  , HasWildcard(..)
  , hasWildcard
  , BadAnonWildcardContext(..)
  , SoleExtraConstraintWildcardAllowed(..)
  , DeriveGenericsErrReason(..)
  , HasAssociatedDataFamInsts(..)
  , hasAssociatedDataFamInsts
  , AssociatedTyLastVarInKind(..)
  , associatedTyLastVarInKind
  , AssociatedTyNotParamOverLastTyVar(..)
  , associatedTyNotParamOverLastTyVar
  , MissingSignature(..)
  , Exported(..)
  , HsDocContext(..)
  , FixedRuntimeRepErrorInfo(..)

  , ErrorItem(..), errorItemOrigin, errorItemEqRel, errorItemPred, errorItemCtLoc

  , SolverReport(..), SolverReportSupplementary(..)
  , SolverReportWithCtxt(..)
  , SolverReportErrCtxt(..)
  , getUserGivens, discardProvCtxtGivens
  , TcSolverReportMsg(..)
  , CannotUnifyVariableReason(..)
  , MismatchMsg(..)
  , MismatchEA(..)
  , mkPlainMismatchMsg, mkBasicMismatchMsg
  , WhenMatching(..)
  , ExpectedActualInfo(..)
  , TyVarInfo(..), SameOccInfo(..)
  , AmbiguityInfo(..)
  , CND_Extra(..)
  , FitsMbSuppressed(..)
  , ValidHoleFits(..), noValidHoleFits
  , HoleFitDispConfig(..)
  , RelevantBindings(..), pprRelevantBindings
  , PromotionErr(..), pprPECategory, peCategory
  , NotInScopeError(..), mkTcRnNotInScope
  , ImportError(..)
  , HoleError(..)
  , CoercibleMsg(..)
  , PotentialInstances(..)
  , UnsupportedCallConvention(..)
  , ExpectedBackends
  , ArgOrResult(..)
  , MatchArgsContext(..), MatchArgBadMatches(..)
  , ConversionFailReason(..)
  , UnrepresentableTypeDescr(..)
  , LookupTHInstNameErrReason(..)
  , SplicePhase(..)
  , THDeclDescriptor(..)
  , RunSpliceFailReason(..)
  , ThingBeingConverted(..)
  , IllegalDecls(..)
  , EmptyStatementGroupErrReason(..)
  , UnexpectedStatement(..)
  , DeclSort(..)
  , NonStandardGuards(..)
  , RuleLhsErrReason(..)
  , HsigShapeMismatchReason(..)
  , WrongThingSort(..)
  , StageCheckReason(..)
  , UninferrableTyVarCtx(..)
  , PatSynInvalidRhsReason(..)
  , BadFieldAnnotationReason(..)
  , SuperclassCycle(..)
  , SuperclassCycleDetail(..)
  , RoleValidationFailedReason(..)
  , DisabledClassExtension(..)
  , TyFamsDisabledReason(..)
  , HsTypeOrSigType(..)
  , HsTyVarBndrExistentialFlag(..)
  , TySynCycleTyCons
  , BadImportKind(..)
  , DodgyImportsReason (..)
  , ImportLookupReason (..)
  , UnusedImportReason (..)
  , UnusedImportName (..)
  , NestedForallsContextsIn(..)
  , UnusedNameProv(..)
  , NonCanonicalDefinition(..)
  , NonCanonical_Monoid(..)
  , NonCanonical_Monad(..)

    -- * Errors for hs-boot and signature files
  , BadBootDecls(..)
  , MissingBootThing(..), missingBootThing
  , BootMismatch(..)
  , BootMismatchWhat(..)
  , BootTyConMismatch(..)
  , BootAxiomBranchMismatch(..)
  , BootClassMismatch(..)
  , BootMethodMismatch(..)
  , BootATMismatch(..)
  , BootDataMismatch(..)
  , BootDataConMismatch(..)
  , SynAbstractDataError(..)
  , BootListMismatch(..), BootListMismatches
  ) where

import GHC.Prelude

import GHC.Hs
import {-# SOURCE #-} GHC.Tc.Types (TcIdSigInfo, TcTyThing)
import {-# SOURCE #-} GHC.Tc.Errors.Hole.FitTypes (HoleFit)
import GHC.Tc.Types.Constraint
import GHC.Tc.Types.Evidence (EvBindsVar)
import GHC.Tc.Types.Origin ( CtOrigin (ProvCtxtOrigin), SkolemInfoAnon (SigSkol)
                           , UserTypeCtxt (PatSynCtxt), TyVarBndrs, TypedThing
                           , FixedRuntimeRepOrigin(..), InstanceWhat )
import GHC.Tc.Types.Rank (Rank)
import GHC.Tc.Utils.TcType (IllegalForeignTypeReason, TcType, TcSigmaType, TcPredType)
import GHC.Types.Basic
import GHC.Types.Error
import GHC.Types.Avail
import GHC.Types.Hint (UntickedPromotedThing(..))
import GHC.Types.ForeignCall (CLabelString)
import GHC.Types.Id.Info ( RecSelParent(..) )
import GHC.Types.Name (Name, OccName, getSrcLoc, getSrcSpan)
import qualified GHC.Types.Name.Occurrence as OccName
import GHC.Types.Name.Reader
import GHC.Types.SourceFile (HsBootOrSig(..))
import GHC.Types.SrcLoc
import GHC.Types.TyThing (TyThing)
import GHC.Types.Var (Id, TyCoVar, TyVar, TcTyVar, CoVar, Specificity)
import GHC.Types.Var.Env (TidyEnv)
import GHC.Types.Var.Set (TyVarSet, VarSet)
import GHC.Unit.Types (Module)
import GHC.Utils.Outputable
import GHC.Core.Class (Class, ClassMinimalDef, ClassOpItem, ClassATItem)
import GHC.Core.Coercion (Coercion)
import GHC.Core.Coercion.Axiom (CoAxBranch)
import GHC.Core.ConLike (ConLike)
import GHC.Core.DataCon (DataCon, FieldLabel)
import GHC.Core.FamInstEnv (FamInst)
import GHC.Core.InstEnv (LookupInstanceErrReason, ClsInst, DFunId)
import GHC.Core.PatSyn (PatSyn)
import GHC.Core.Predicate (EqRel, predTypeEqRel)
import GHC.Core.TyCon (TyCon, Role, FamTyConFlav, AlgTyConRhs)
import GHC.Core.Type (Kind, Type, ThetaType, PredType, ErrorMsgType)
import GHC.Driver.Backend (Backend)
import GHC.Unit.State (UnitState)
import GHC.Utils.Misc (capitalise, filterOut)
import qualified GHC.LanguageExtensions as LangExt
import GHC.Data.FastString (FastString)
import GHC.Exception.Type (SomeException)

import Language.Haskell.Syntax.Basic (FieldLabelString(..))

import qualified Data.List.NonEmpty as NE
import           Data.Typeable (Typeable)
import GHC.Unit.Module.Warnings (WarningCategory, WarningTxt)
import qualified Language.Haskell.TH.Syntax as TH
import GHC.Unit.Module.ModIface

import GHC.Generics ( Generic )
import GHC.Types.Name.Env (NameEnv)
import GHC.Iface.Errors.Types

{-
Note [Migrating TcM Messages]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As part of #18516, we are slowly migrating the diagnostic messages emitted
and reported in the TcM from SDoc to TcRnMessage. Historically, GHC emitted
some diagnostics in 3 pieces, i.e. there were lots of error-reporting functions
that accepted 3 SDocs an input: one for the important part of the message,
one for the context and one for any supplementary information. Consider the following:

    • Couldn't match expected type ‘Int’ with actual type ‘Char’
    • In the expression: x4
      In a stmt of a 'do' block: return (x2, x4)
      In the expression:

Under the hood, the reporting functions in Tc.Utils.Monad were emitting "Couldn't match"
as the important part, "In the expression" as the context and "In a stmt..In the expression"
as the supplementary, with the context and supplementary usually smashed together so that
the final message would be composed only by two SDoc (which would then be bulleted like in
the example).

In order for us to smooth out the migration to the new diagnostic infrastructure, we
introduce the 'ErrInfo' and 'TcRnMessageDetailed' types, which serve exactly the purpose
of bridging the two worlds together without breaking the external API or the existing
format of messages reported by GHC.

Using 'ErrInfo' and 'TcRnMessageDetailed' also allows us to move away from the SDoc-ridden
diagnostic API inside Tc.Utils.Monad, enabling further refactorings.

In the future, once the conversion will be complete and we will successfully eradicate
any use of SDoc in the diagnostic reporting of GHC, we can surely revisit the usage and
existence of these two types, which for now remain a "necessary evil".

-}

-- The majority of TcRn messages come with extra context about the error,
-- and this newtype captures it. See Note [Migrating TcM Messages].
data ErrInfo = ErrInfo {
    errInfoContext :: !SDoc
    -- ^ Extra context associated to the error.
  , errInfoSupplementary :: !SDoc
    -- ^ Extra supplementary info associated to the error.
  }


-- | 'TcRnMessageDetailed' is an \"internal\" type (used only inside
-- 'GHC.Tc.Utils.Monad' that wraps a 'TcRnMessage' while also providing
-- any extra info needed to correctly pretty-print this diagnostic later on.
data TcRnMessageDetailed
  = TcRnMessageDetailed !ErrInfo
                        -- ^ Extra info associated with the message
                        !TcRnMessage
  deriving Generic

mkTcRnUnknownMessage :: (Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts)
                     => a -> TcRnMessage
mkTcRnUnknownMessage diag = TcRnUnknownMessage (UnknownDiagnostic diag)

-- | An error which might arise during typechecking/renaming.
data TcRnMessage where
  {-| Simply wraps an unknown 'Diagnostic' message @a@. It can be used by plugins
      to provide custom diagnostic messages originated during typechecking/renaming.
  -}
  TcRnUnknownMessage :: UnknownDiagnostic -> TcRnMessage

  {-| Wrap an 'IfaceMessage' to a 'TcRnMessage' for when we attempt to load interface
      files during typechecking but encounter an error. -}

  TcRnInterfaceError :: !IfaceMessage -> TcRnMessage

  {-| TcRnMessageWithInfo is a constructor which is used when extra information is needed
      to be provided in order to qualify a diagnostic and where it was originated (and why).
      It carries an extra 'UnitState' which can be used to pretty-print some names
      and it wraps a 'TcRnMessageDetailed', which includes any extra context associated
      with this diagnostic.
  -}
  TcRnMessageWithInfo :: !UnitState
                      -- ^ The 'UnitState' will allow us to pretty-print
                      -- some diagnostics with more detail.
                      -> !TcRnMessageDetailed
                      -> TcRnMessage

  {-| TcRnWithHsDocContext annotates an error message with the context in which
      it originated.
  -}
  TcRnWithHsDocContext :: !HsDocContext
                       -> !TcRnMessage
                       -> TcRnMessage

  {-| TcRnSolverReport is the constructor used to report unsolved constraints
      after constraint solving, as well as other errors such as hole fit errors.

      See the documentation of the 'TcSolverReportMsg' datatype for an overview
      of the different errors.
  -}
  TcRnSolverReport :: SolverReportWithCtxt
                   -> DiagnosticReason
                   -> [GhcHint]
                   -> TcRnMessage
    -- TODO: split up TcRnSolverReport into several components,
    -- so that we can compute the reason and hints, as opposed
    -- to having to pass them here.

  {-| TcRnRedundantConstraints is a warning that is emitted when a binding
      has a user-written type signature which contains superfluous constraints.

      Example:

        f :: (Eq a, Ord a) => a -> a -> a
        f x y = (x < y) || x == y
          -- `Eq a` is superfluous: the `Ord a` constraint suffices.

      Test cases: T9939, T10632, T18036a, T20602, PluralS, T19296.
  -}
  TcRnRedundantConstraints :: [Id]
                           -> (SkolemInfoAnon, Bool)
                              -- ^ The contextual skolem info.
                              -- The boolean controls whether we
                              -- want to show it in the user message.
                              -- (Nice to keep track of the info in either case,
                              -- for other users of the GHC API.)
                           -> TcRnMessage

  {-| TcRnInaccessibleCode is a warning that is emitted when the RHS of a pattern
      match is inaccessible, because the constraint solver has detected a contradiction.

      Example:

        data B a where { MkTrue :: B True; MkFalse :: B False }

        foo :: B False -> Bool
        foo MkFalse = False
        foo MkTrue  = True -- Inaccessible: requires True ~ False

    Test cases: T7293, T7294, T15558, T17646, T18572, T18610, tcfail167.
  -}
  TcRnInaccessibleCode :: Implication          -- ^ The implication containing a contradiction.
                       -> SolverReportWithCtxt -- ^ The contradiction.
                       -> TcRnMessage

  {-| A type which was expected to have a fixed runtime representation
      does not have a fixed runtime representation.

      Example:

        data D (a :: TYPE r) = MkD a

      Test cases: T11724, T18534,
                  RepPolyPatSynArg, RepPolyPatSynUnliftedNewtype,
                  RepPolyPatSynRes, T20423
  -}
  TcRnTypeDoesNotHaveFixedRuntimeRep :: !Type
                                     -> !FixedRuntimeRepProvenance
                                     -> !ErrInfo -- Extra info accumulated in the TcM monad
                                     -> TcRnMessage

  {-| TcRnImplicitLift is a warning (controlled with -Wimplicit-lift) that occurs when
      a Template Haskell quote implicitly uses 'lift'.

     Example:
       warning1 :: Lift t => t -> Q Exp
       warning1 x = [| x |]

     Test cases: th/T17804
  -}
  TcRnImplicitLift :: Name -> !ErrInfo -> TcRnMessage

  {-| TcRnUnusedPatternBinds is a warning (controlled with -Wunused-pattern-binds)
      that occurs if a pattern binding binds no variables at all, unless it is a
      lone wild-card pattern, or a banged pattern.

     Example:
        Just _ = rhs3    -- Warning: unused pattern binding
        (_, _) = rhs4    -- Warning: unused pattern binding
        _  = rhs3        -- No warning: lone wild-card pattern
        !() = rhs4       -- No warning: banged pattern; behaves like seq

     Test cases: rename/{T13646,T17c,T17e,T7085}
  -}
  TcRnUnusedPatternBinds :: HsBind GhcRn -> TcRnMessage

  {-| TcRnUnusedQuantifiedTypeVar is a warning that occurs if there are unused
      quantified type variables.

      Examples:
        f :: forall a. Int -> Char

      Test cases: rename/should_compile/ExplicitForAllRules1
                  rename/should_compile/T5331
  -}
  TcRnUnusedQuantifiedTypeVar
    :: HsDocContext
    -> HsTyVarBndrExistentialFlag -- ^ tyVar binder.
    -> TcRnMessage

  {-| TcRnDodgyImports is a group of warnings (controlled with -Wdodgy-imports).

      See 'DodgyImportsReason' for the different warnings.
  -}
  TcRnDodgyImports :: !DodgyImportsReason -> TcRnMessage
  {-| TcRnDodgyExports is a warning (controlled by -Wdodgy-exports) that occurs when
      an export of the form 'T(..)' for a type constructor 'T' does not actually export anything
      beside 'T' itself.

     Example:
       module Foo (
           T(..)  -- Warning: T is a type synonym
         , A(..)  -- Warning: A is a type family
         , C(..)  -- Warning: C is a data family
         ) where

       type T = Int
       type family A :: * -> *
       data family C :: * -> *

     Test cases: warnings/should_compile/DodgyExports01
  -}
  TcRnDodgyExports :: GlobalRdrElt -> TcRnMessage
  {-| TcRnMissingImportList is a warning (controlled by -Wmissing-import-lists) that occurs when
      an import declaration does not explicitly list all the names brought into scope.

     Test cases: rename/should_compile/T4489
  -}
  TcRnMissingImportList :: IE GhcPs -> TcRnMessage
  {-| When a module marked trustworthy or unsafe (using -XTrustworthy or -XUnsafe) is compiled
      with a plugin, the TcRnUnsafeDueToPlugin warning (controlled by -Wunsafe) is used as the
      reason the module was inferred to be unsafe. This warning is not raised if the
      -fplugin-trustworthy flag is passed.

     Test cases: plugins/T19926
  -}
  TcRnUnsafeDueToPlugin :: TcRnMessage
  {-| TcRnModMissingRealSrcSpan is an error that occurs when compiling a module that lacks
      an associated 'RealSrcSpan'.

     Test cases: None
  -}
  TcRnModMissingRealSrcSpan :: Module -> TcRnMessage
  {-| TcRnIdNotExportedFromModuleSig is an error pertaining to backpack that occurs
      when an identifier required by a signature is not exported by the module
      or signature that is being used as a substitution for that signature.

      Example(s): None

     Test cases: backpack/should_fail/bkpfail36
  -}
  TcRnIdNotExportedFromModuleSig :: Name -> Module -> TcRnMessage
  {-| TcRnIdNotExportedFromLocalSig is an error pertaining to backpack that
      occurs when an identifier which is necessary for implementing a module
      signature is not exported from that signature.

      Example(s): None

     Test cases: backpack/should_fail/bkpfail30
                 backpack/should_fail/bkpfail31
                 backpack/should_fail/bkpfail34
  -}
  TcRnIdNotExportedFromLocalSig :: Name -> TcRnMessage

  {-| TcRnShadowedName is a warning (controlled by -Wname-shadowing) that occurs whenever
      an inner-scope value has the same name as an outer-scope value, i.e. the inner
      value shadows the outer one. This can catch typographical errors that turn into
      hard-to-find bugs. The warning is suppressed for names beginning with an underscore.

      Examples(s):
        f = ... let f = id in ... f ...  -- NOT OK, 'f' is shadowed
        f x = do { _ignore <- this; _ignore <- that; return (the other) } -- suppressed via underscore

     Test cases: typecheck/should_compile/T10971a
                 rename/should_compile/rn039
                 rename/should_compile/rn064
                 rename/should_compile/T1972
                 rename/should_fail/T2723
                 rename/should_compile/T3262
                 driver/werror
  -}
  TcRnShadowedName :: OccName -> ShadowedNameProvenance -> TcRnMessage

  {-| TcRnInvalidWarningCategory is an error that occurs when a warning is declared
      with a category name that is not the special category "deprecations", and
      either does not begin with the prefix "x-" indicating a user-defined
      category, or contains characters not valid in category names.  See Note
      [Warning categories] in GHC.Unit.Module.Warnings

      Examples(s):
        module M {-# WARNING in "invalid" "Oops" #-} where

        {-# WARNING in "x- spaces not allowed" foo "Oops" #-}

     Test cases: warnings/should_fail/WarningCategoryInvalid
  -}
  TcRnInvalidWarningCategory :: !WarningCategory -> TcRnMessage


  {-| TcRnDuplicateWarningDecls is an error that occurs whenever
      a warning is declared twice.

      Examples(s):
        None.

     Test cases:
        None.
  -}
  TcRnDuplicateWarningDecls :: !(LocatedN RdrName) -> !RdrName -> TcRnMessage

  {-| TcRnSimplifierTooManyIterations is an error that occurs whenever
      the constraint solver in the simplifier hits the iterations' limit.

      Examples(s):
        None.

     Test cases:
        None.
  -}
  TcRnSimplifierTooManyIterations :: Cts
                                  -> !IntWithInf
                                  -- ^ The limit.
                                  -> WantedConstraints
                                  -> TcRnMessage

  {-| TcRnIllegalPatSynDecl is an error that occurs whenever
      there is an illegal pattern synonym declaration.

      Examples(s):

      varWithLocalPatSyn x = case x of
          P -> ()
        where
          pattern P = ()   -- not valid, it can't be local, it must be defined at top-level.

     Test cases: patsyn/should_fail/local
  -}
  TcRnIllegalPatSynDecl :: !(LIdP GhcPs) -> TcRnMessage

  {-| TcRnLinearPatSyn is an error that occurs whenever a pattern
      synonym signature uses a field that is not unrestricted.

      Example(s): None

     Test cases: linear/should_fail/LinearPatSyn2
  -}
  TcRnLinearPatSyn :: !Type -> TcRnMessage

  {-| TcRnEmptyRecordUpdate is an error that occurs whenever
      a record is updated without specifying any field.

      Examples(s):

      $(deriveJSON defaultOptions{} ''Bad) -- not ok, no fields selected for update of defaultOptions

     Test cases: th/T12788
  -}
  TcRnEmptyRecordUpdate :: TcRnMessage

  {-| TcRnIllegalFieldPunning is an error that occurs whenever
      field punning is used without the 'NamedFieldPuns' extension enabled.

      Examples(s):

      data Foo = Foo { a :: Int }

      foo :: Foo -> Int
      foo Foo{a} = a  -- Not ok, punning used without extension.

     Test cases: parser/should_fail/RecordDotSyntaxFail12
  -}
  TcRnIllegalFieldPunning :: !(Located RdrName) -> TcRnMessage

  {-| TcRnIllegalWildcardsInRecord is an error that occurs whenever
      wildcards (..) are used in a record without the relevant
      extension being enabled.

      Examples(s):

      data Foo = Foo { a :: Int }

      foo :: Foo -> Int
      foo Foo{..} = a  -- Not ok, wildcards used without extension.

     Test cases: parser/should_fail/RecordWildCardsFail
  -}
  TcRnIllegalWildcardsInRecord :: !RecordFieldPart -> TcRnMessage

  {-| TcRnIllegalWildcardInType is an error that occurs
      when a wildcard appears in a type in a location in which
      wildcards aren't allowed.

      Examples:

        Type synonyms:

          type T = _

        Class declarations and instances:

          class C _
          instance C _

        Standalone kind signatures:

          type D :: _
          data D

      Test cases:
        ExtraConstraintsWildcardInTypeSplice2
        ExtraConstraintsWildcardInTypeSpliceUsed
        ExtraConstraintsWildcardNotLast
        ExtraConstraintsWildcardTwice
        NestedExtraConstraintsWildcard
        NestedNamedExtraConstraintsWildcard
        PartialClassMethodSignature
        PartialClassMethodSignature2
        T12039
        T13324_fail1
        UnnamedConstraintWildcard1
        UnnamedConstraintWildcard2
        WildcardInADT1
        WildcardInADT2
        WildcardInADT3
        WildcardInADTContext1
        WildcardInDefault
        WildcardInDefaultSignature
        WildcardInDeriving
        WildcardInForeignExport
        WildcardInForeignImport
        WildcardInGADT1
        WildcardInGADT2
        WildcardInInstanceHead
        WildcardInInstanceSig
        WildcardInNewtype
        WildcardInPatSynSig
        WildcardInStandaloneDeriving
        WildcardInTypeFamilyInstanceRHS
        WildcardInTypeSynonymRHS
        saks_fail003
        T15433a
  -}

  TcRnIllegalWildcardInType
    :: Maybe Name
        -- ^ the wildcard name, or 'Nothing' for an anonymous wildcard
    -> !BadAnonWildcardContext
    -> TcRnMessage

  {-| TcRnDuplicateFieldName is an error that occurs whenever
      there are duplicate field names in a single record.

      Examples(s):

        data R = MkR { x :: Int, x :: Bool }
        f r = r { x = 3, x = 4 }

     Test cases: T21959.
  -}
  TcRnDuplicateFieldName :: !RecordFieldPart -> NE.NonEmpty RdrName -> TcRnMessage

  {-| TcRnIllegalViewPattern is an error that occurs whenever
      the ViewPatterns syntax is used but the ViewPatterns language extension
      is not enabled.

      Examples(s):
      data Foo = Foo { a :: Int }

      foo :: Foo -> Int
      foo (a -> l) = l -- not OK, the 'ViewPattern' extension is not enabled.

     Test cases: parser/should_fail/ViewPatternsFail
  -}
  TcRnIllegalViewPattern :: !(Pat GhcPs) -> TcRnMessage

  {-| TcRnCharLiteralOutOfRange is an error that occurs whenever
      a character is out of range.

      Examples(s): None

     Test cases: None
  -}
  TcRnCharLiteralOutOfRange :: !Char -> TcRnMessage

  {-| TcRnNegativeNumTypeLiteral is an error that occurs whenever
      a type-level number literal is negative.

      type Neg = -1

     Test cases: th/T8412
                 typecheck/should_fail/T8306
  -}
  TcRnNegativeNumTypeLiteral :: HsType GhcPs -> TcRnMessage

  {-| TcRnIllegalWildcardsInConstructor is an error that occurs whenever
      the record wildcards '..' are used inside a constructor without labeled fields.

      Examples(s): None

     Test cases:
       rename/should_fail/T9815.hs
       rename/should_fail/T9815b.hs
       rename/should_fail/T9815ghci.hs
       rename/should_fail/T9815bghci.hs
  -}
  TcRnIllegalWildcardsInConstructor :: !Name -> TcRnMessage

  {-| TcRnIgnoringAnnotations is a warning that occurs when the source code
      contains annotation pragmas but the platform in use does not support an
      external interpreter such as GHCi and therefore the annotations are ignored.

      Example(s): None

     Test cases: None
  -}
  TcRnIgnoringAnnotations :: [LAnnDecl GhcRn] -> TcRnMessage

  {-| TcRnAnnotationInSafeHaskell is an error that occurs if annotation pragmas
      are used in conjunction with Safe Haskell.

      Example(s): None

     Test cases: annotations/should_fail/T10826
  -}
  TcRnAnnotationInSafeHaskell :: TcRnMessage

  {-| TcRnInvalidTypeApplication is an error that occurs when a visible type application
      is used with an expression that does not accept "specified" type arguments.

      Example(s):
      foo :: forall {a}. a -> a
      foo x = x
      bar :: ()
      bar = let x = foo @Int 42
            in ()

     Test cases: overloadedrecflds/should_fail/overloadedlabelsfail03
                 typecheck/should_fail/ExplicitSpecificity1
                 typecheck/should_fail/ExplicitSpecificity10
                 typecheck/should_fail/ExplicitSpecificity2
                 typecheck/should_fail/T17173
                 typecheck/should_fail/VtaFail
  -}
  TcRnInvalidTypeApplication :: Type -> LHsWcType GhcRn -> TcRnMessage

  {-| TcRnTagToEnumMissingValArg is an error that occurs when the 'tagToEnum#'
      function is not applied to a single value argument.

      Example(s):
      tagToEnum# 1 2

     Test cases: None
  -}
  TcRnTagToEnumMissingValArg :: TcRnMessage

  {-| TcRnTagToEnumUnspecifiedResTy is an error that occurs when the 'tagToEnum#'
      function is not given a concrete result type.

      Example(s):
      foo :: forall a. a
      foo = tagToEnum# 0#

     Test cases: typecheck/should_fail/tcfail164
  -}
  TcRnTagToEnumUnspecifiedResTy :: Type -> TcRnMessage

  {-| TcRnTagToEnumResTyNotAnEnum is an error that occurs when the 'tagToEnum#'
      function is given a result type that is not an enumeration type.

      Example(s):
      foo :: Int -- not an enumeration TyCon
      foo = tagToEnum# 0#

     Test cases: typecheck/should_fail/tcfail164
  -}
  TcRnTagToEnumResTyNotAnEnum :: Type -> TcRnMessage

  {-| TcRnTagToEnumResTyTypeData is an error that occurs when the 'tagToEnum#'
      function is given a result type that is headed by a @type data@ type, as
      the data constructors of a @type data@ do not exist at the term level.

      Example(s):
      type data Letter = A | B | C

      foo :: Letter
      foo = tagToEnum# 0#

     Test cases: type-data/should_fail/TDTagToEnum.hs
  -}
  TcRnTagToEnumResTyTypeData :: Type -> TcRnMessage

  {-| TcRnArrowIfThenElsePredDependsOnResultTy is an error that occurs when the
      predicate type of an ifThenElse expression in arrow notation depends on
      the type of the result.

      Example(s): None

     Test cases: None
  -}
  TcRnArrowIfThenElsePredDependsOnResultTy :: TcRnMessage

  {-| TcRnIllegalHsBootOrSigDecl is an error that occurs when an hs-boot file
      contains declarations that are not allowed, such as bindings.

      Examples:

        -- A.hs-boot
        f :: Int -> Int
        f x = 2 * x -- binding not allowed

        -- B.hs-boot
        type family F a where { F Int = Bool }
          -- type family equations not allowed

        -- C.hsig
        bar :: Int -> Int
        {-# RULES forall x. bar x = x #-} -- RULES not allowed


     Test cases:

       - bindings: T19781
       - class instance body: none
       - type family instance: HsBootFam
       - splice: none
       - foreign declaration: none
       - default declaration: none
       - RULEs: none
  -}
  TcRnIllegalHsBootOrSigDecl :: !HsBootOrSig -> !BadBootDecls -> TcRnMessage

  {-| TcRnBootMismatch is a family of errors that occur when there is a
      mismatch between the hs-boot and hs files.

     Examples:

       -- A.hs-boot
       foo :: Int -> Bool
       data D = MkD

       -- A.hs
       foo :: Int -> Char
       foo = chr

       data D = MkD Int

      Test cases:

        - missing export: bkpcabal06, bkpfail{01,05,09,16,35}, rnfail{047,055}
        - missing definition: none
        - missing instance: T14075
        - mismatch in exports: bkpfail{03,19}
        - conflicting definitions: bkpcabal02,
           bkpfail{04,06,07,10,12,133,14,15,17,22,23,25,26,27,41,42,45,47,50,52,53,54},
           T19244{a,b}, T23344, ClosedFam3, rnfail055
  -}
  TcRnBootMismatch :: !HsBootOrSig -> !BootMismatch -> TcRnMessage

  {-| TcRnRecursivePatternSynonym is an error that occurs when a pattern synonym
      is defined in terms of itself, either directly or indirectly.

      Example(s):
      pattern A = B
      pattern B = A

     Test cases: patsyn/should_fail/T16900
  -}
  TcRnRecursivePatternSynonym :: LHsBinds GhcRn -> TcRnMessage

  {-| TcRnPartialTypeSigTyVarMismatch is an error that occurs when a partial type signature
      attempts to unify two different types.

      Example(s):
      f :: a -> b -> _
      f x y = [x, y]

     Test cases: partial-sigs/should_fail/T14449
  -}
  TcRnPartialTypeSigTyVarMismatch
    :: Name -- ^ first type variable
    -> Name -- ^ second type variable
    -> Name -- ^ function name
    -> LHsSigWcType GhcRn -> TcRnMessage

  {-| TcRnPartialTypeSigBadQuantifier is an error that occurs when a type variable
      being quantified over in the partial type signature of a function gets unified
      with a type that is free in that function's context.

      Example(s):
      foo :: Num a => a -> a
      foo xxx = g xxx
        where
          g :: forall b. Num b => _ -> b
          g y = xxx + y

     Test cases: partial-sig/should_fail/T14479
  -}
  TcRnPartialTypeSigBadQuantifier
    :: Name   -- ^ user-written name of type variable being quantified
    -> Name   -- ^ function name
    -> Maybe Type   -- ^ type the variable unified with, if known
    -> LHsSigWcType GhcRn  -- ^ partial type signature
    -> TcRnMessage

  {-| TcRnMissingSignature is a warning that occurs when a top-level binding
      or a pattern synonym does not have a type signature.

      Controlled by the flags:
        -Wmissing-signatures
        -Wmissing-exported-signatures
        -Wmissing-pattern-synonym-signatures
        -Wmissing-exported-pattern-synonym-signatures
        -Wmissing-kind-signatures

      Test cases:
        T11077 (top-level bindings)
        T12484 (pattern synonyms)
        T19564 (kind signatures)
  -}
  TcRnMissingSignature :: MissingSignature
                       -> Exported
                       -> Bool -- ^ True: -Wmissing-signatures overrides -Wmissing-exported-signatures,
                               --     or -Wmissing-pattern-synonym-signatures overrides -Wmissing-exported-pattern-synonym-signatures
                       -> TcRnMessage

  {-| TcRnPolymorphicBinderMissingSig is a warning controlled by -Wmissing-local-signatures
      that occurs when a local polymorphic binding lacks a type signature.

      Example(s):
      id a = a

     Test cases: warnings/should_compile/T12574
  -}
  TcRnPolymorphicBinderMissingSig :: Name -> Type -> TcRnMessage

  {-| TcRnOverloadedSig is an error that occurs when a binding group conflicts
      with the monomorphism restriction.

      Example(s):
      data T a = T a
      mono = ... where
        x :: Applicative f => f a
        T x = ...

     Test cases: typecheck/should_compile/T11339
  -}
  TcRnOverloadedSig :: TcIdSigInfo -> TcRnMessage

  {-| TcRnTupleConstraintInst is an error that occurs whenever an instance
      for a tuple constraint is specified.

      Examples(s):
        class C m a
        class D m a
        f :: (forall a. Eq a => (C m a, D m a)) => m a
        f = undefined

      Test cases: quantified-constraints/T15334
  -}
  TcRnTupleConstraintInst :: !Class -> TcRnMessage

  {-| TcRnAbstractClassInst is an error that occurs whenever an instance
      of an abstract class is specified.

      Examples(s):
        -- A.hs-boot
        module A where
        class C a

        -- B.hs
        module B where
        import {-# SOURCE #-} A
        instance C Int where

        -- A.hs
        module A where
        import B
        class C a where
          f :: a

        -- Main.hs
        import A
        main = print (f :: Int)

      Test cases: typecheck/should_fail/T13068
  -}
  TcRnAbstractClassInst :: !Class -> TcRnMessage

  {-| TcRnNoClassInstHead is an error that occurs whenever an instance
      head is not headed by a class.

      Examples(s):
        instance c

      Test cases: typecheck/rename/T5513
                  typecheck/rename/T16385
  -}
  TcRnNoClassInstHead :: !Type -> TcRnMessage

  {-| TcRnUserTypeError is an error that occurs due to a user's custom type error,
      which can be triggered by adding a `TypeError` constraint in a type signature
      or typeclass instance.

      Examples(s):
        f :: TypeError (Text "This is a type error")
        f = undefined

      Test cases: typecheck/should_fail/CustomTypeErrors02
                  typecheck/should_fail/CustomTypeErrors03
  -}
  TcRnUserTypeError :: !Type -> TcRnMessage

  {-| TcRnConstraintInKind is an error that occurs whenever a constraint is specified
      in a kind.

      Examples(s):
        data Q :: Eq a => Type where {}

      Test cases: dependent/should_fail/T13895
                  polykinds/T16263
                  saks/should_fail/saks_fail004
                  typecheck/should_fail/T16059a
                  typecheck/should_fail/T18714
  -}
  TcRnConstraintInKind :: !Type -> TcRnMessage

  {-| TcRnUnboxedTupleTypeFuncArg is an error that occurs whenever an unboxed tuple
      or unboxed sum type is specified as a function argument, when the appropriate
      extension (`-XUnboxedTuples` or `-XUnboxedSums`) isn't enabled.

      Examples(s):
        -- T15073.hs
        import T15073a
        newtype Foo a = MkFoo a
          deriving P

        -- T15073a.hs
        class P a where
          p :: a -> (# a #)

      Test cases: deriving/should_fail/T15073.hs
                  deriving/should_fail/T15073a.hs
                  typecheck/should_fail/T16059d
  -}
  TcRnUnboxedTupleOrSumTypeFuncArg
    :: UnboxedTupleOrSum -- ^ whether this is an unboxed tuple or an unboxed sum
    -> !Type
    -> TcRnMessage

  {-| TcRnLinearFuncInKind is an error that occurs whenever a linear function is
      specified in a kind.

      Examples(s):
        data A :: * %1 -> *

      Test cases: linear/should_fail/LinearKind
                  linear/should_fail/LinearKind2
                  linear/should_fail/LinearKind3
  -}
  TcRnLinearFuncInKind :: !Type -> TcRnMessage

  {-| TcRnForAllEscapeError is an error that occurs whenever a quantified type's kind
      mentions quantified type variable.

      Examples(s):
        type T :: TYPE (BoxedRep l)
        data T = MkT

      Test cases: unlifted-datatypes/should_fail/UnlDataNullaryPoly
  -}
  TcRnForAllEscapeError :: !Type -> !Kind -> TcRnMessage

  {-| TcRnVDQInTermType is an error that occurs whenever a visible dependent quantification
      is specified in the type of a term.

      Examples(s):
        a = (undefined :: forall k -> k -> Type) @Int

      Test cases: dependent/should_fail/T15859
                  dependent/should_fail/T16326_Fail1
                  dependent/should_fail/T16326_Fail2
                  dependent/should_fail/T16326_Fail3
                  dependent/should_fail/T16326_Fail4
                  dependent/should_fail/T16326_Fail5
                  dependent/should_fail/T16326_Fail6
                  dependent/should_fail/T16326_Fail7
                  dependent/should_fail/T16326_Fail8
                  dependent/should_fail/T16326_Fail9
                  dependent/should_fail/T16326_Fail10
                  dependent/should_fail/T16326_Fail11
                  dependent/should_fail/T16326_Fail12
                  dependent/should_fail/T17687
                  dependent/should_fail/T18271
  -}
  TcRnVDQInTermType :: !(Maybe Type) -> TcRnMessage

  {-| TcRnBadQuantPredHead is an error that occurs whenever a quantified predicate
      lacks a class or type variable head.

      Examples(s):
        class (forall a. A t a => A t [a]) => B t where
          type A t a :: Constraint

      Test cases: quantified-constraints/T16474
  -}
  TcRnBadQuantPredHead :: !Type -> TcRnMessage

  {-| TcRnIllegalTupleConstraint is an error that occurs whenever an illegal tuple
      constraint is specified.

      Examples(s):
        g :: ((Show a, Num a), Eq a) => a -> a
        g = undefined

      Test cases: typecheck/should_fail/tcfail209a
  -}
  TcRnIllegalTupleConstraint :: !Type -> TcRnMessage

  {-| TcRnNonTypeVarArgInConstraint is an error that occurs whenever a non type-variable
      argument is specified in a constraint.

      Examples(s):
        data T
        instance Eq Int => Eq T

      Test cases: ghci/scripts/T13202
                  ghci/scripts/T13202a
                  polykinds/T12055a
                  typecheck/should_fail/T10351
                  typecheck/should_fail/T19187
                  typecheck/should_fail/T6022
                  typecheck/should_fail/T8883
  -}
  TcRnNonTypeVarArgInConstraint :: !Type -> TcRnMessage

  {-| TcRnIllegalImplicitParam is an error that occurs whenever an illegal implicit
      parameter is specified.

      Examples(s):
        type Bla = ?x::Int
        data T = T
        instance Bla => Eq T

      Test cases: polykinds/T11466
                  typecheck/should_fail/T8912
                  typecheck/should_fail/tcfail041
                  typecheck/should_fail/tcfail211
                  typecheck/should_fail/tcrun045
  -}
  TcRnIllegalImplicitParam :: !Type -> TcRnMessage

  {-| TcRnIllegalConstraintSynonymOfKind is an error that occurs whenever an illegal constraint
      synonym of kind is specified.

      Examples(s):
        type Showish = Show
        f :: (Showish a) => a -> a
        f = undefined

      Test cases: typecheck/should_fail/tcfail209
  -}
  TcRnIllegalConstraintSynonymOfKind :: !Type -> TcRnMessage

  {-| TcRnIllegalClassInst is an error that occurs whenever a class instance is specified
      for a non-class.

      Examples(s):
        type C1 a = (Show (a -> Bool))
        instance C1 Int where

      Test cases: polykinds/T13267
  -}
  TcRnIllegalClassInst :: !(TyConFlavour TyCon) -> TcRnMessage

  {-| TcRnOversaturatedVisibleKindArg is an error that occurs whenever an illegal oversaturated
      visible kind argument is specified.

      Examples(s):
        type family
          F2 :: forall (a :: Type). Type where
          F2 @a = Maybe a

      Test cases: typecheck/should_fail/T15793
                  typecheck/should_fail/T16255
  -}
  TcRnOversaturatedVisibleKindArg :: !Type -> TcRnMessage

  {-| TcRnBadAssociatedType is an error that occurs whenever a class doesn't have an
      associated type.

      Examples(s):
        $(do d <- instanceD (cxt []) (conT ''Eq `appT` conT ''Foo)
                    [tySynInstD $ tySynEqn Nothing (conT ''Rep `appT` conT ''Foo) (conT ''Maybe)]
             return [d])
        ======>
        instance Eq Foo where
          type Rep Foo = Maybe

      Test cases: th/T12387a
  -}
  TcRnBadAssociatedType :: {-Class-} !Name -> {-TyCon-} !Name -> TcRnMessage

  {-| TcRnForAllRankErr is an error that occurs whenever an illegal ranked type
      is specified.

      Examples(s):
        foo :: (a,b) -> (a~b => t) -> (a,b)
        foo p x = p

      Test cases:
        - ghci/should_run/T15806
        - indexed-types/should_fail/SimpleFail15
        - typecheck/should_fail/T11355
        - typecheck/should_fail/T12083a
        - typecheck/should_fail/T12083b
        - typecheck/should_fail/T16059c
        - typecheck/should_fail/T16059e
        - typecheck/should_fail/T17213
        - typecheck/should_fail/T18939_Fail
        - typecheck/should_fail/T2538
        - typecheck/should_fail/T5957
        - typecheck/should_fail/T7019
        - typecheck/should_fail/T7019a
        - typecheck/should_fail/T7809
        - typecheck/should_fail/T9196
        - typecheck/should_fail/tcfail127
        - typecheck/should_fail/tcfail184
        - typecheck/should_fail/tcfail196
        - typecheck/should_fail/tcfail197
  -}
  TcRnForAllRankErr :: !Rank -> !Type -> TcRnMessage

  {-| TcRnMonomorphicBindings is a warning (controlled by -Wmonomorphism-restriction)
      that arise when the monomorphism restriction applies to the given bindings.

      Examples(s):
        {-# OPTIONS_GHC -Wmonomorphism-restriction #-}

        bar = 10

        foo :: Int
        foo = bar

        main :: IO ()
        main = print foo

      The example above emits the warning (for 'bar'), because without monomorphism
      restriction the inferred type for 'bar' is 'bar :: Num p => p'. This warning tells us
      that /if/ we were to enable '-XMonomorphismRestriction' we would make 'bar'
      less polymorphic, as its type would become 'bar :: Int', so GHC warns us about that.

      Test cases: typecheck/should_compile/T13785
  -}
  TcRnMonomorphicBindings :: [Name] -> TcRnMessage

  {-| TcRnOrphanInstance is a warning (controlled by -Worphans) that arises when
      a typeclass instance or family instance is an \"orphan\", i.e. if it
      appears in a module in which neither the class/family nor the type being
      instanced are declared in the same module.

      Examples(s): None

      Test cases: warnings/should_compile/T9178
                  typecheck/should_compile/T4912
  -}
  TcRnOrphanInstance :: Either ClsInst FamInst -> TcRnMessage

  {-| TcRnFunDepConflict is an error that occurs when there are functional dependencies
      conflicts between instance declarations.

      Examples(s): None

      Test cases: typecheck/should_fail/T2307
                  typecheck/should_fail/tcfail096
                  typecheck/should_fail/tcfail202
  -}
  TcRnFunDepConflict :: !UnitState -> NE.NonEmpty ClsInst -> TcRnMessage

  {-| TcRnDupInstanceDecls is an error that occurs when there are duplicate instance
      declarations.

      Examples(s):
        class Foo a where
          foo :: a -> Int

        instance Foo Int where
          foo = id

        instance Foo Int where
          foo = const 42

      Test cases: cabal/T12733/T12733
                  typecheck/should_fail/tcfail035
                  typecheck/should_fail/tcfail023
                  backpack/should_fail/bkpfail18
                  typecheck/should_fail/TcNullaryTCFail
                  typecheck/should_fail/tcfail036
                  typecheck/should_fail/tcfail073
                  module/mod51
                  module/mod52
                  module/mod44
  -}
  TcRnDupInstanceDecls :: !UnitState -> NE.NonEmpty ClsInst -> TcRnMessage

  {-| TcRnConflictingFamInstDecls is an error that occurs when there are conflicting
      family instance declarations.

      Examples(s): None.

      Test cases: indexed-types/should_fail/ExplicitForAllFams4b
                  indexed-types/should_fail/NoGood
                  indexed-types/should_fail/Over
                  indexed-types/should_fail/OverDirectThisMod
                  indexed-types/should_fail/OverIndirectThisMod
                  indexed-types/should_fail/SimpleFail11a
                  indexed-types/should_fail/SimpleFail11b
                  indexed-types/should_fail/SimpleFail11c
                  indexed-types/should_fail/SimpleFail11d
                  indexed-types/should_fail/SimpleFail2a
                  indexed-types/should_fail/SimpleFail2b
                  indexed-types/should_fail/T13092/T13092
                  indexed-types/should_fail/T13092c/T13092c
                  indexed-types/should_fail/T14179
                  indexed-types/should_fail/T2334A
                  indexed-types/should_fail/T2677
                  indexed-types/should_fail/T3330b
                  indexed-types/should_fail/T4246
                  indexed-types/should_fail/T7102a
                  indexed-types/should_fail/T9371
                  polykinds/T7524
                  typecheck/should_fail/UnliftedNewtypesOverlap
  -}
  TcRnConflictingFamInstDecls :: NE.NonEmpty FamInst -> TcRnMessage

  TcRnFamInstNotInjective :: InjectivityErrReason -> TyCon -> NE.NonEmpty CoAxBranch -> TcRnMessage

  {-| TcRnBangOnUnliftedType is a warning (controlled by -Wredundant-strictness-flags) that
      occurs when a strictness annotation is applied to an unlifted type.

      Example(s):
      data T = MkT !Int# -- Strictness flag has no effect on unlifted types

     Test cases: typecheck/should_compile/T20187a
                 typecheck/should_compile/T20187b
  -}
  TcRnBangOnUnliftedType :: !Type -> TcRnMessage

  {-| TcRnLazyBangOnUnliftedType is a warning (controlled by -Wredundant-strictness-flags) that
      occurs when a lazy annotation is applied to an unlifted type.

      Example(s):
      data T = MkT ~Int# -- Lazy flag has no effect on unlifted types

     Test cases: typecheck/should_compile/T21951a
                 typecheck/should_compile/T21951b
  -}
  TcRnLazyBangOnUnliftedType :: !Type -> TcRnMessage

  {-| TcRnMultipleDefaultDeclarations is an error that occurs when a module has
      more than one default declaration.

      Example:
      default (Integer, Int)
      default (Double, Float) -- 2nd default declaration not allowed

     Text cases: module/mod58
  -}
  TcRnMultipleDefaultDeclarations :: [LDefaultDecl GhcRn] -> TcRnMessage

  {-| TcRnBadDefaultType is an error that occurs when a type used in a default
      declaration does not have an instance for any of the applicable classes.

      Example(s):
      data Foo
      default (Foo)

     Test cases: typecheck/should_fail/T11974b
  -}
  TcRnBadDefaultType :: Type -> [Class] -> TcRnMessage

  {-| TcRnPatSynBundledWithNonDataCon is an error that occurs when a module's
      export list bundles a pattern synonym with a type that is not a proper
      `data` or `newtype` construction.

      Example(s):
      module Foo (MyClass(.., P)) where
      pattern P = Nothing
      class MyClass a where
        foo :: a -> Int

     Test cases: patsyn/should_fail/export-class
  -}
  TcRnPatSynBundledWithNonDataCon :: TcRnMessage

  {-| TcRnPatSynBundledWithWrongType is an error that occurs when the export list
      of a module has a pattern synonym bundled with a type that does not match
      the type of the pattern synonym.

      Example(s):
      module Foo (R(P,x)) where
      data Q = Q Int
      data R = R
      pattern P{x} = Q x

     Text cases: patsyn/should_fail/export-ps-rec-sel
                 patsyn/should_fail/export-type-synonym
                 patsyn/should_fail/export-type
  -}
  TcRnPatSynBundledWithWrongType :: Type -> Type -> TcRnMessage

  {-| TcRnDupeModuleExport is a warning controlled by @-Wduplicate-exports@ that
      occurs when a module appears more than once in an export list.

      Example(s):
      module Foo (module Bar, module Bar)
      import Bar

     Text cases: None
  -}
  TcRnDupeModuleExport :: ModuleName -> TcRnMessage

  {-| TcRnExportedModNotImported is an error that occurs when an export list
      contains a module that is not imported.

      Example(s): None

     Text cases: module/mod135
                 module/mod8
                 rename/should_fail/rnfail028
                 backpack/should_fail/bkpfail48
  -}
  TcRnExportedModNotImported :: ModuleName -> TcRnMessage

  {-| TcRnNullExportedModule is a warning controlled by -Wdodgy-exports that occurs
      when an export list contains a module that has no exports.

      Example(s):
      module Foo (module Bar) where
      import Bar ()

     Test cases: None
  -}
  TcRnNullExportedModule :: ModuleName -> TcRnMessage

  {-| TcRnMissingExportList is a warning controlled by -Wmissing-export-lists that
      occurs when a module does not have an explicit export list.

      Example(s): None

     Test cases: typecheck/should_fail/MissingExportList03
  -}
  TcRnMissingExportList :: ModuleName -> TcRnMessage

  {-| TcRnExportHiddenComponents is an error that occurs when an export contains
      constructor or class methods that are not visible.

      Example(s): None

     Test cases: None
  -}
  TcRnExportHiddenComponents :: IE GhcPs -> TcRnMessage

  {-| TcRnDuplicateExport is a warning (controlled by -Wduplicate-exports) that occurs
      when an identifier appears in an export list more than once.

      Example(s): None

     Test cases: module/MultiExport
                 module/mod128
                 module/mod14
                 module/mod5
                 overloadedrecflds/should_fail/DuplicateExports
                 patsyn/should_compile/T11959
  -}
  TcRnDuplicateExport :: GlobalRdrElt -> IE GhcPs -> IE GhcPs -> TcRnMessage

  {-| TcRnExportedParentChildMismatch is an error that occurs when an export is
      bundled with a parent that it does not belong to

      Example(s):
      module Foo (T(a)) where
      data T
      a = True

     Test cases: module/T11970
                 module/T11970B
                 module/mod17
                 module/mod3
                 overloadedrecflds/should_fail/NoParent
  -}
  TcRnExportedParentChildMismatch :: Name -- ^ parent
                                  -> TyThing
                                  -> GlobalRdrElt -- ^ child
                                  -> [Name] -> TcRnMessage

  {-| TcRnConflictingExports is an error that occurs when different identifiers that
      have the same name are being exported by a module.

      Example(s):
      module Foo (Bar.f, module Baz) where
      import qualified Bar (f)
      import Baz (f)

     Test cases: module/mod131
                 module/mod142
                 module/mod143
                 module/mod144
                 module/mod145
                 module/mod146
                 module/mod150
                 module/mod155
                 overloadedrecflds/should_fail/T14953
                 overloadedrecflds/should_fail/overloadedrecfldsfail10
                 rename/should_fail/rnfail029
                 rename/should_fail/rnfail040
                 typecheck/should_fail/T16453E2
                 typecheck/should_fail/tcfail025
                 typecheck/should_fail/tcfail026
  -}
  TcRnConflictingExports
    :: OccName      -- ^ Occurrence name shared by both exports
    -> GlobalRdrElt -- ^ First export
    -> IE GhcPs     -- ^ Export decl of first export
    -> GlobalRdrElt -- ^ Second export
    -> IE GhcPs     -- ^ Export decl of second export
    -> TcRnMessage

  {-| TcRnDuplicateFieldExport is an error that occurs when a module exports
      multiple record fields with the same name, without enabling
      DuplicateRecordFields.

      Example:

      module M1 where
        data D1 = MkD1 { foo :: Int }
      module M2 where
        data D2 = MkD2 { foo :: Int }
      module M ( D1(..), D2(..) ) where
        import module M1
        import module M2

     Test case: overloadedrecflds/should_fail/overloadedrecfldsfail10
  -}
  TcRnDuplicateFieldExport
    :: (GlobalRdrElt, IE GhcPs)
    -> NE.NonEmpty (GlobalRdrElt, IE GhcPs)
    -> TcRnMessage

  {-| TcRnAmbiguousRecordUpdate is a warning, controlled by -Wambiguous-fields,
      which occurs when a user relies on the type-directed disambiguation
      mechanism to disambiguate a record update. This will not be supported by
      -XDuplicateRecordFields in future releases.

      Example(s):

        data Person  = MkPerson  { personId :: Int, name :: String }
        data Address = MkAddress { personId :: Int, address :: String }
        bad1 x = x { personId = 4 } :: Person -- ambiguous
        bad2 (x :: Person) = x { personId = 4 } -- ambiguous
        good x = (x :: Person) { personId = 4 } -- not ambiguous

     Test cases: overloadedrecflds/should_fail/overloadedrecfldsfail06
  -}
  TcRnAmbiguousRecordUpdate
    :: HsExpr GhcRn -- ^ Field update
    -> TyCon -- ^ Record type
    -> TcRnMessage

  {-| TcRnMissingFields is a warning controlled by -Wmissing-fields occurring
      when the intialisation of a record is missing one or more (lazy) fields.

      Example(s):
      data Rec = Rec { a :: Int, b :: String, c :: Bool }
      x = Rec { a = 1, b = "two" } -- missing field 'c'

     Test cases: deSugar/should_compile/T13870
                 deSugar/should_compile/ds041
                 patsyn/should_compile/T11283
                 rename/should_compile/T5334
                 rename/should_compile/T12229
                 rename/should_compile/T5892a
                 warnings/should_fail/WerrorFail2
  -}
  TcRnMissingFields :: ConLike -> [(FieldLabelString, TcType)] -> TcRnMessage

  {-| TcRnFieldUpdateInvalidType is an error occurring when an updated field's
      type mentions something that is outside the universally quantified variables
      of the data constructor, such as an existentially quantified type.

      Example(s):
      data X = forall a. MkX { f :: a }
      x = (MkX ()) { f = False }

      Test cases: patsyn/should_fail/records-exquant
                  typecheck/should_fail/T3323
  -}
  TcRnFieldUpdateInvalidType :: [(FieldLabelString,TcType)] -> TcRnMessage

  {-| TcRnMissingStrictFields is an error occurring when a record field marked
     as strict is omitted when constructing said record.

     Example(s):
     data R = R { strictField :: !Bool, nonStrict :: Int }
     x = R { nonStrict = 1 }

    Test cases: typecheck/should_fail/T18869
                typecheck/should_fail/tcfail085
                typecheck/should_fail/tcfail112
  -}
  TcRnMissingStrictFields :: ConLike -> [(FieldLabelString, TcType)] -> TcRnMessage

  {-| TcRnAmbiguousFieldInUpdate is an error that occurs when a field in a
      record update clashes with another field or top-level function of the
      same name, and the user hasn't enabled -XDisambiguateRecordFields.

      Example:

        {-# LANGUAGE NoFieldSelectors #-}
        {-# LANGUAGE NoDisambiguateRecordFields #-}
        module M where

          data A = MkA { fld :: Int }

          fld :: Bool
          fld = False

          f r = r { fld = 3 }

  -}
  TcRnAmbiguousFieldInUpdate :: (GlobalRdrElt, GlobalRdrElt, [GlobalRdrElt])
                                -> TcRnMessage

  {-| TcRnBadRecordUpdate is an error when a regular (non-overloaded)
     record update cannot be pinned down to any one parent.

     The problem with the record update is stored in the 'BadRecordUpdateReason'
     field.

     Example(s):

       data R1 = R1 { x :: Int }
       data R2 = R2 { x :: Int }
       update r = r { x = 1 }
         -- ambiguous

       data R1 = R1 { x :: Int, y :: Int }
       data R2 = R2 { y :: Int, z :: Int }
       update r = r { x = 1, y = 2, z = 3 }
         -- no parent has all the fields

    Test cases: overloadedrecflds/should_fail/overloadedrecfldsfail01
                overloadedrecflds/should_fail/overloadedrecfldsfail01
                overloadedrecflds/should_fail/overloadedrecfldsfail14
  -}
  TcRnBadRecordUpdate :: [RdrName]
                         -- ^ the fields of the record update
                      -> BadRecordUpdateReason
                         -- ^ the reason this record update was rejected
                      -> TcRnMessage

  {-| TcRnStaticFormNotClosed is an error pertaining to terms that are marked static
     using the -XStaticPointers extension but which are not closed terms.

     Example(s):
     f x = static x

    Test cases: rename/should_fail/RnStaticPointersFail01
                rename/should_fail/RnStaticPointersFail03
  -}
  TcRnStaticFormNotClosed :: Name -> NotClosedReason -> TcRnMessage
  {-| TcRnSpecialClassInst is an error that occurs when a user
      attempts to define an instance for a built-in typeclass such as
      'Coercible', 'Typeable', or 'KnownNat', outside of a signature file.

     Test cases: deriving/should_fail/T9687
                 deriving/should_fail/T14916
                 polykinds/T8132
                 typecheck/should_fail/TcCoercibleFail2
                 typecheck/should_fail/T12837
                 typecheck/should_fail/T14390

  -}
  TcRnSpecialClassInst :: !Class
                       -> !Bool -- ^ Whether the error is due to Safe Haskell being enabled
                       -> TcRnMessage

  {-| TcRnUselessTypeable is a warning (controlled by -Wderiving-typeable) that
      occurs when trying to derive an instance of the 'Typeable' class. Deriving
      'Typeable' is no longer necessary (hence the \"useless\") as all types
      automatically derive 'Typeable' in modern GHC versions.

      Example(s): None.

     Test cases: warnings/should_compile/DerivingTypeable
  -}
  TcRnUselessTypeable :: TcRnMessage

  {-| TcRnDerivingDefaults is a warning (controlled by -Wderiving-defaults) that
      occurs when both 'DeriveAnyClass' and 'GeneralizedNewtypeDeriving' are
      enabled, and therefore GHC defaults to 'DeriveAnyClass', which might not
      be what the user wants.

      Example(s): None.

     Test cases: typecheck/should_compile/T15839a
                 deriving/should_compile/T16179
  -}
  TcRnDerivingDefaults :: !Class -> TcRnMessage

  {-| TcRnNonUnaryTypeclassConstraint is an error that occurs when GHC
      encounters a non-unary constraint when trying to derive a typeclass.

      Example(s):
        class A
        deriving instance A
        data B deriving A  -- We cannot derive A, is not unary (i.e. 'class A a').

     Test cases: deriving/should_fail/T7959
                 deriving/should_fail/drvfail005
                 deriving/should_fail/drvfail009
                 deriving/should_fail/drvfail006
  -}
  TcRnNonUnaryTypeclassConstraint :: !(LHsSigType GhcRn) -> TcRnMessage

  {-| TcRnPartialTypeSignatures is a warning (controlled by -Wpartial-type-signatures)
      that occurs when a wildcard '_' is found in place of a type in a signature or a
      type class derivation

      Example(s):
        foo :: _ -> Int
        foo = ...

        deriving instance _ => Eq (Foo a)

     Test cases: dependent/should_compile/T11241
                 dependent/should_compile/T15076
                 dependent/should_compile/T14880-2
                 typecheck/should_compile/T17024
                 typecheck/should_compile/T10072
                 partial-sigs/should_fail/TidyClash2
                 partial-sigs/should_fail/Defaulting1MROff
                 partial-sigs/should_fail/WildcardsInPatternAndExprSig
                 partial-sigs/should_fail/T10615
                 partial-sigs/should_fail/T14584a
                 partial-sigs/should_fail/TidyClash
                 partial-sigs/should_fail/T11122
                 partial-sigs/should_fail/T14584
                 partial-sigs/should_fail/T10045
                 partial-sigs/should_fail/PartialTypeSignaturesDisabled
                 partial-sigs/should_fail/T10999
                 partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature
                 partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSplice
                 partial-sigs/should_fail/WildcardInstantiations
                 partial-sigs/should_run/T15415
                 partial-sigs/should_compile/T10463
                 partial-sigs/should_compile/T15039a
                 partial-sigs/should_compile/T16728b
                 partial-sigs/should_compile/T15039c
                 partial-sigs/should_compile/T10438
                 partial-sigs/should_compile/SplicesUsed
                 partial-sigs/should_compile/T18008
                 partial-sigs/should_compile/ExprSigLocal
                 partial-sigs/should_compile/T11339a
                 partial-sigs/should_compile/T11670
                 partial-sigs/should_compile/WarningWildcardInstantiations
                 partial-sigs/should_compile/T16728
                 partial-sigs/should_compile/T12033
                 partial-sigs/should_compile/T15039b
                 partial-sigs/should_compile/T10403
                 partial-sigs/should_compile/T11192
                 partial-sigs/should_compile/T16728a
                 partial-sigs/should_compile/TypedSplice
                 partial-sigs/should_compile/T15039d
                 partial-sigs/should_compile/T11016
                 partial-sigs/should_compile/T13324_compile2
                 linear/should_fail/LinearPartialSig
                 polykinds/T14265
                 polykinds/T14172
  -}
  TcRnPartialTypeSignatures :: !SuggestPartialTypeSignatures -> !ThetaType -> TcRnMessage

  {-| TcRnCannotDeriveInstance is an error that occurs every time a typeclass instance
      can't be derived. The 'DeriveInstanceErrReason' will contain the specific reason
      this error arose.

      Example(s): None.

      Test cases: generics/T10604/T10604_no_PolyKinds
                  deriving/should_fail/drvfail009
                  deriving/should_fail/drvfail-functor2
                  deriving/should_fail/T10598_fail3
                  deriving/should_fail/deriving-via-fail2
                  deriving/should_fail/deriving-via-fail
                  deriving/should_fail/T16181
  -}
  TcRnCannotDeriveInstance :: !Class
                           -- ^ The typeclass we are trying to derive
                           -- an instance for
                           -> [Type]
                           -- ^ The typeclass arguments, if any.
                           -> !(Maybe (DerivStrategy GhcTc))
                           -- ^ The derivation strategy, if any.
                           -> !UsingGeneralizedNewtypeDeriving
                           -- ^ Is '-XGeneralizedNewtypeDeriving' enabled?
                           -> !DeriveInstanceErrReason
                           -- ^ The specific reason why we couldn't derive
                           -- an instance for the class.
                           -> TcRnMessage

  {-| TcRnLazyGADTPattern is an error that occurs when a user writes a nested
      GADT pattern match inside a lazy (~) pattern.

      Test case: gadt/lazypat
  -}
  TcRnLazyGADTPattern :: TcRnMessage

  {-| TcRnArrowProcGADTPattern is an error that occurs when a user writes a
      GADT pattern inside arrow proc notation.

      Test case: arrows/should_fail/arrowfail004.
  -}
  TcRnArrowProcGADTPattern :: TcRnMessage

  {-| TcRnForallIdentifier is a warning (controlled with -Wforall-identifier) that occurs
     when a definition uses 'forall' as an identifier.

     Example:
       forall x = ()
       g forall = ()

     Test cases: T20609 T20609a T20609b T20609c T20609d
  -}
  TcRnForallIdentifier :: RdrName -> TcRnMessage

  {-| TcRnCapturedTermName is a warning (controlled by -Wterm-variable-capture) that occurs
    when an implicitly quantified type variable's name is already used for a term.
    Example:
      a = 10
      f :: a -> a

    Test cases: T22513a T22513b T22513c T22513d T22513e T22513f T22513g T22513h T22513i
 -}
  TcRnCapturedTermName :: RdrName -> Either [GlobalRdrElt] Name -> TcRnMessage

  {-| TcRnTypeMultipleOccurenceOfBindVar is an error that occurs if a bound
      type variable's name is already in use.
    Example:
      f :: forall a. ...
      f (MkT @a ...) = ...

    Test cases: TyAppPat_ScopedTyVarConflict TyAppPat_NonlinearMultiPat TyAppPat_NonlinearMultiAppPat
  -}
  TcRnBindVarAlreadyInScope :: [LocatedN RdrName] -> TcRnMessage

  {-| TcRnBindMultipleVariables is an error that occurs in the case of
    multiple occurrences of a bound variable.
    Example:
      foo (MkFoo @(a,a) ...) = ...

    Test case: typecheck/should_fail/TyAppPat_NonlinearSinglePat
  -}
  TcRnBindMultipleVariables :: HsDocContext -> LocatedN RdrName -> TcRnMessage

  {-| TcRnTypeEqualityOutOfScope is a warning (controlled by -Wtype-equality-out-of-scope)
      that occurs when the type equality (a ~ b) is not in scope.

      Test case: warnings/should_compile/T18862b
  -}
  TcRnTypeEqualityOutOfScope :: TcRnMessage

  {-| TcRnTypeEqualityRequiresOperators is a warning (controlled by -Wtype-equality-requires-operators)
      that occurs when the type equality (a ~ b) is used without the TypeOperators extension.

      Example:
        {-# LANGUAGE NoTypeOperators #-}
        f :: (a ~ b) => a -> b

      Test case: T18862a
  -}
  TcRnTypeEqualityRequiresOperators :: TcRnMessage

  {-| TcRnIllegalTypeOperator is an error that occurs when a type operator
      is used without the TypeOperators extension.

      Example:
        {-# LANGUAGE NoTypeOperators #-}
        f :: Vec a n -> Vec a m -> Vec a (n + m)

      Test case: T12811
  -}
  TcRnIllegalTypeOperator :: !SDoc -> !RdrName -> TcRnMessage

  {-| TcRnIllegalTypeOperatorDecl is an error that occurs when a type or class
      operator is declared without the TypeOperators extension.

      See Note [Type and class operator definitions]

      Example:
        {-# LANGUAGE Haskell2010 #-}
        {-# LANGUAGE MultiParamTypeClasses #-}

        module T3265 where

        data a :+: b = Left a | Right b

        class a :*: b where {}


      Test cases: T3265, tcfail173
  -}
  TcRnIllegalTypeOperatorDecl :: !RdrName -> TcRnMessage


  {-| TcRnGADTMonoLocalBinds is a warning controlled by -Wgadt-mono-local-binds
      that occurs when pattern matching on a GADT when -XMonoLocalBinds is off.

      Example(s): None

      Test cases: T20485, T20485a
  -}
  TcRnGADTMonoLocalBinds :: TcRnMessage
  {-| The TcRnNotInScope constructor is used for various not-in-scope errors.
      See 'NotInScopeError' for more details. -}
  TcRnNotInScope :: NotInScopeError  -- ^ what the problem is
                 -> RdrName          -- ^ the name that is not in scope
                 -> [ImportError]    -- ^ import errors that are relevant
                 -> [GhcHint]        -- ^ hints, e.g. enable DataKinds to refer to a promoted data constructor
                 -> TcRnMessage
  TcRnTermNameInType :: RdrName -> [GhcHint] -> TcRnMessage

  {-| TcRnUntickedPromotedThing is a warning (controlled with -Wunticked-promoted-constructors)
      that is triggered by an unticked occurrence of a promoted data constructor.

      Examples:

        data A = MkA
        type family F (a :: A) where { F MkA = Bool }

        type B = [ Int, Bool ]

      Test cases: T9778, T19984.
  -}
  TcRnUntickedPromotedThing :: UntickedPromotedThing
                            -> TcRnMessage

  {-| TcRnIllegalBuiltinSyntax is an error that occurs when built-in syntax appears
      in an unexpected location, e.g. as a data constructor or in a fixity declaration.

      Examples:

        infixl 5 :

        data P = (,)

      Test cases: rnfail042, T14907b, T15124, T15233.
  -}
  TcRnIllegalBuiltinSyntax :: SDoc -- ^ what kind of thing this is (a binding, fixity declaration, ...)
                           -> RdrName
                           -> TcRnMessage
    -- TODO: remove the SDoc argument.

  {-| TcRnWarnDefaulting is a warning (controlled by -Wtype-defaults)
      that is triggered whenever a Wanted typeclass constraint
      is solving through the defaulting of a type variable.

      Example:

        one = show 1
        -- We get Wanteds Show a0, Num a0, and default a0 to Integer.

      Test cases:
        none (which are really specific to defaulting),
        but see e.g. tcfail204.
   -}
  TcRnWarnDefaulting :: [Ct] -- ^ Wanted constraints in which defaulting occurred
                     -> Maybe TyVar -- ^ The type variable being defaulted
                     -> Type -- ^ The default type
                     -> TcRnMessage

  {-| TcRnIncorrectNameSpace is an error that occurs when a 'Name'
      is used in the incorrect 'NameSpace', e.g. a type constructor
      or class used in a term, or a term variable used in a type.

      Example:

        f x = Int

      Test cases: T18740a, T20884.
  -}
  TcRnIncorrectNameSpace :: Name
                         -> Bool -- ^ whether the error is happening
                                 -- in a Template Haskell tick
                                 -- (so we should give a Template Haskell hint)
                         -> TcRnMessage

  {-| TcRnForeignImportPrimExtNotSet is an error occurring when a foreign import
     is declared using the @prim@ calling convention without having turned on
     the -XGHCForeignImportPrim extension.

     Example(s):
     foreign import prim "foo" foo :: ByteArray# -> (# Int#, Int# #)

    Test cases: ffi/should_fail/T20116
  -}
  TcRnForeignImportPrimExtNotSet :: ForeignImport GhcRn -> TcRnMessage

  {-| TcRnForeignImportPrimSafeAnn is an error declaring that the safe/unsafe
     annotation should not be used with @prim@ foreign imports.

     Example(s):
     foreign import prim unsafe "my_primop_cmm" :: ...

    Test cases: None
  -}
  TcRnForeignImportPrimSafeAnn :: ForeignImport GhcRn -> TcRnMessage

  {-| TcRnForeignFunctionImportAsValue is an error explaining that foreign @value@
     imports cannot have function types.

     Example(s):
     foreign import capi "math.h value sqrt" f :: CInt -> CInt

    Test cases: ffi/should_fail/capi_value_function
  -}
  TcRnForeignFunctionImportAsValue :: ForeignImport GhcRn -> TcRnMessage

  {-| TcRnFunPtrImportWithoutAmpersand is a warning controlled by @-Wdodgy-foreign-imports@
     that informs the user of a possible missing @&@ in the declaration of a
     foreign import with a 'FunPtr' return type.

     Example(s):
     foreign import ccall "f" f :: FunPtr (Int -> IO ())

    Test cases: ffi/should_compile/T1357
  -}
  TcRnFunPtrImportWithoutAmpersand :: ForeignImport GhcRn -> TcRnMessage

  {-| TcRnIllegalForeignDeclBackend is an error occurring when a foreign import declaration
     is not compatible with the code generation backend being used.

     Example(s): None

    Test cases: None
  -}
  TcRnIllegalForeignDeclBackend
    :: Either (ForeignExport GhcRn) (ForeignImport GhcRn)
    -> Backend
    -> ExpectedBackends
    -> TcRnMessage

  {-| TcRnUnsupportedCallConv informs the user that the calling convention specified
     for a foreign export declaration is not compatible with the target platform.
     It is a warning controlled by @-Wunsupported-calling-conventions@ in the case of
     @stdcall@ but is otherwise considered an error.

     Example(s): None

    Test cases: None
  -}
  TcRnUnsupportedCallConv :: Either (ForeignExport GhcRn) (ForeignImport GhcRn)
                          -> UnsupportedCallConvention
                          -> TcRnMessage

  {-| TcRnIllegalForeignType is an error for when a type appears in a foreign
     function signature that is not compatible with the FFI.

     Example(s): None

    Test cases: ffi/should_fail/T3066
                ffi/should_fail/ccfail004
                ffi/should_fail/T10461
                ffi/should_fail/T7506
                ffi/should_fail/T5664
                safeHaskell/ghci/p6
                safeHaskell/safeLanguage/SafeLang08
                ffi/should_fail/T16702
                linear/should_fail/LinearFFI
                ffi/should_fail/T7243
  -}
  TcRnIllegalForeignType :: !(Maybe ArgOrResult) -> !IllegalForeignTypeReason -> TcRnMessage

  {-| TcRnInvalidCIdentifier indicates a C identifier that is not valid.

     Example(s):
     foreign import prim safe "not valid" cmm_test2 :: Int# -> Int#

    Test cases: th/T10638
  -}
  TcRnInvalidCIdentifier :: !CLabelString -> TcRnMessage

  {-| TcRnExpectedValueId is an error occurring when something that is not a
      value identifier is used where one is expected.

     Example(s): none

    Test cases: none
  -}
  TcRnExpectedValueId :: !TcTyThing -> TcRnMessage

  {-| TcRnRecSelectorEscapedTyVar is an error indicating that a record field selector
     containing an existential type variable is used as a function rather than in
     a pattern match.

     Example(s):
     data Rec = forall a. Rec { field :: a }
     field (Rec True)

    Test cases: patsyn/should_fail/records-exquant
                typecheck/should_fail/T3176
  -}
  TcRnRecSelectorEscapedTyVar :: !OccName -> TcRnMessage

  {-| TcRnPatSynNotBidirectional is an error for when a non-bidirectional pattern
     synonym is used as a constructor.

     Example(s):
     pattern Five :: Int
     pattern Five <- 5
     five = Five

    Test cases: patsyn/should_fail/records-no-uni-update
                patsyn/should_fail/records-no-uni-update2
  -}
  TcRnPatSynNotBidirectional :: !Name -> TcRnMessage

  {-| TcRnSplicePolymorphicLocalVar is the error that occurs when the expression
     inside typed template haskell brackets is a polymorphic local variable.

     Example(s):
     x = \(y :: forall a. a -> a) -> [|| y ||]

    Test cases: quotes/T10384
  -}
  TcRnSplicePolymorphicLocalVar :: !Id -> TcRnMessage

  {-| TcRnIllegalDerivingItem is an error for when something other than a type class
     appears in a deriving statement.

     Example(s):
     data X = X deriving Int

    Test cases: deriving/should_fail/T5922
  -}
  TcRnIllegalDerivingItem :: !(LHsSigType GhcRn) -> TcRnMessage

  {-| TcRnUnexpectedAnnotation indicates the erroroneous use of an annotation such
     as strictness, laziness, or unpacking.

     Example(s):
     data T = T { t :: Maybe {-# UNPACK #-} Int }
     data C = C { f :: !IntMap Int }

    Test cases: parser/should_fail/unpack_inside_type
                typecheck/should_fail/T7210
  -}
  TcRnUnexpectedAnnotation :: !(HsType GhcRn) -> !HsSrcBang -> TcRnMessage

  {-| TcRnIllegalRecordSyntax is an error indicating an illegal use of record syntax.

     Example(s):
     data T = T Int { field :: Int }

    Test cases: rename/should_fail/T7943
                rename/should_fail/T9077
  -}
  TcRnIllegalRecordSyntax :: Either (HsType GhcPs) (HsType GhcRn) -> TcRnMessage

  {-| TcRnUnexpectedTypeSplice is an error for a typed Template Haskell splice
     appearing unexpectedly.

     Example(s): none

    Test cases: none
  -}
  TcRnUnexpectedTypeSplice :: !(HsType GhcRn) -> TcRnMessage

  {-| TcRnUnexpectedDeclarationSplice is an error that occurs when a Template Haskell
      splice appears inside top-level declarations added with 'addTopDecls'.

      Example(s): none

      Test cases: none
  -}
  TcRnUnexpectedDeclarationSplice :: TcRnMessage

  {-| TcRnInvalidVisibleKindArgument is an error for a kind application on a
     target type that cannot accept it.

     Example(s):
     bad :: Int @Type
     bad = 1
     type Foo :: forall a {b}. a -> b -> b
     type Foo x y = y
     type Bar = Foo @Bool @Int True 42

    Test cases: indexed-types/should_fail/T16356_Fail3
                typecheck/should_fail/ExplicitSpecificity7
                typecheck/should_fail/T12045b
                typecheck/should_fail/T12045c
                typecheck/should_fail/T15592a
                typecheck/should_fail/T15816
  -}
  TcRnInvalidVisibleKindArgument
    :: !(LHsType GhcRn) -- ^ The visible kind argument
    -> !Type -- ^ Target of the kind application
    -> TcRnMessage

  {-| TcRnTooManyBinders is an error for a type constructor that is declared with
     more arguments then its kind specifies.

     Example(s):
     type T :: Type -> (Type -> Type) -> Type
     data T a (b :: Type -> Type) x1 (x2 :: Type -> Type)

    Test cases: saks/should_fail/saks_fail008
  -}
  TcRnTooManyBinders :: !Kind -> ![LHsTyVarBndr () GhcRn] -> TcRnMessage

  {-| TcRnDifferentNamesForTyVar is an error that indicates different names being
     used for the same type variable.

     Example(s):
     data SameKind :: k -> k -> *
     data Q (a :: k1) (b :: k2) c = MkQ (SameKind a b)

    Test cases: polykinds/T11203
                polykinds/T11821a
                saks/should_fail/T20916
                typecheck/should_fail/T17566b
                typecheck/should_fail/T17566c
  -}
  TcRnDifferentNamesForTyVar :: !Name -> !Name -> TcRnMessage

  {-| TcRnInvalidReturnKind is an error for a data declaration that has a kind signature
     with an invalid result kind.

     Example(s):
     data family Foo :: Constraint

    Test cases: typecheck/should_fail/T14048b
                typecheck/should_fail/UnliftedNewtypesConstraintFamily
                typecheck/should_fail/T12729
                typecheck/should_fail/T15883
                typecheck/should_fail/T16829a
                typecheck/should_fail/T16829b
                typecheck/should_fail/UnliftedNewtypesNotEnabled
                typecheck/should_fail/tcfail079
  -}
  TcRnInvalidReturnKind
    :: !DataSort -- ^ classification of thing being returned
    -> !AllowedDataResKind -- ^ allowed kind
    -> !Kind -- ^ the return kind
    -> !(Maybe SuggestUnliftedTypes) -- ^ suggested extension
    -> TcRnMessage

  {-| TcRnUnexpectedKindVar is an error that occurs when the user
      tries to use kind variables without -XPolyKinds.

      Example:
        f :: forall k a. Proxy (a :: k)

      Test cases: polykinds/BadKindVar
                  polykinds/T14710
                  saks/should_fail/T16722
  -}
  TcRnUnexpectedKindVar :: RdrName -> TcRnMessage

  {-| TcRnIllegalKind is used for a various illegal kinds errors including

      Example:
        type T :: forall k. Type -- without emabled -XPolyKinds

      Test cases: polykinds/T16762b
  -}
  TcRnIllegalKind
    :: HsTypeOrSigType GhcPs
            -- ^ The illegal kind
    -> Bool -- ^ Whether enabling -XPolyKinds should be suggested
    -> TcRnMessage

  {-| TcRnClassKindNotConstraint is an error for a type class that has a kind that
     is not equivalent to Constraint.

     Example(s):
     type C :: Type -> Type
     class C a

    Test cases: saks/should_fail/T16826
  -}
  TcRnClassKindNotConstraint :: !Kind -> TcRnMessage

  {-| TcRnUnpromotableThing is an error that occurs when the user attempts to
     use the promoted version of something which is not promotable.

     Example(s):
     data T :: T -> *
     data X a where
       MkX :: Show a => a -> X a
     foo :: Proxy ('MkX 'True)
     foo = Proxy

    Test cases: dependent/should_fail/PromotedClass
                dependent/should_fail/T14845_fail1
                dependent/should_fail/T14845_fail2
                dependent/should_fail/T15215
                dependent/should_fail/T13780c
                dependent/should_fail/T15245
                polykinds/T5716
                polykinds/T5716a
                polykinds/T6129
                polykinds/T7433
                patsyn/should_fail/T11265
                patsyn/should_fail/T9161-1
                patsyn/should_fail/T9161-2
                dependent/should_fail/SelfDep
                polykinds/PolyKinds06
                polykinds/PolyKinds07
                polykinds/T13625
                polykinds/T15116
                polykinds/T15116a
                saks/should_fail/T16727a
                saks/should_fail/T16727b
                rename/should_fail/T12686
  -}
  TcRnUnpromotableThing :: !Name -> !PromotionErr -> TcRnMessage

  {-| TcRnMatchesHaveDiffNumArgs is an error occurring when something has matches
     that have different numbers of arguments

     Example(s):
     foo x = True
     foo x y = False

    Test cases: rename/should_fail/rnfail045
                typecheck/should_fail/T20768_fail
  -}
  TcRnMatchesHaveDiffNumArgs
    :: !(HsMatchContext GhcTc) -- ^ Pattern match specifics
    -> !MatchArgBadMatches
    -> TcRnMessage

  {-| TcRnUnexpectedPatSigType is an error occurring when there is
      a type signature in a pattern without -XScopedTypeVariables extension

      Examples:
        f (a :: Bool) = ...

      Test case: rename/should_fail/T11663
  -}
  TcRnUnexpectedPatSigType :: HsPatSigType GhcPs -> TcRnMessage

  {-| TcRnIllegalKindSignature is an error occuring when there is
      a kind signature without -XKindSignatures extension

      Examples:
        data Foo (a :: Nat) = ....

      Test case: parser/should_fail/readFail036
  -}
  TcRnIllegalKindSignature :: HsType GhcPs -> TcRnMessage

  {-| TcRnDataKindsError is an error occurring when there is
      an illegal type or kind, probably required -XDataKinds
      and is used without the enabled extension.

      Examples:

        type Foo = [Nat, Char]

        type Bar = [Int, String]

      Test cases: linear/should_fail/T18888
                  polykinds/T7151
                  th/TH_Promoted1Tuple
                  typecheck/should_fail/tcfail094
  -}
  TcRnDataKindsError :: TypeOrKind -> HsType GhcPs -> TcRnMessage

  {-| TcRnCannotBindScopedTyVarInPatSig is an error stating that scoped type
     variables cannot be used in pattern bindings.

     Example(s):
     let (x :: a) = 5

     Test cases: typecheck/should_compile/tc141
  -}
  TcRnCannotBindScopedTyVarInPatSig :: !(NE.NonEmpty (Name, TcTyVar)) -> TcRnMessage

  {-| TcRnCannotBindTyVarsInPatBind is an error for when type
     variables are introduced in a pattern binding

     Example(s):
     Just @a x = Just True

    Test cases: typecheck/should_fail/TyAppPat_PatternBinding
                typecheck/should_fail/TyAppPat_PatternBindingExistential
  -}
  TcRnCannotBindTyVarsInPatBind :: !(NE.NonEmpty (Name, TcTyVar)) -> TcRnMessage

  {-| TcRnTooManyTyArgsInConPattern is an error occurring when a constructor pattern
     has more than the expected number of type arguments

     Example(s):
     f (Just @Int @Bool x) = x

    Test cases: typecheck/should_fail/TyAppPat_TooMany
                typecheck/should_fail/T20443b
  -}
  TcRnTooManyTyArgsInConPattern
    :: !ConLike
    -> !Int -- ^ Expected number of args
    -> !Int -- ^ Actual number of args
    -> TcRnMessage

  {-| TcRnMultipleInlinePragmas is a warning signifying that multiple inline pragmas
     reference the same definition.

     Example(s):
     {-# INLINE foo #-}
     {-# INLINE foo #-}
     foo :: Bool -> Bool
     foo = id

    Test cases: none
  -}
  TcRnMultipleInlinePragmas
    :: !Id -- ^ Target of the pragmas
    -> !(LocatedA InlinePragma) -- ^ The first pragma
    -> !(NE.NonEmpty (LocatedA InlinePragma)) -- ^ Other pragmas
    -> TcRnMessage

  {-| TcRnUnexpectedPragmas is a warning that occurs when unexpected pragmas appear
     in the source.

     Example(s):

    Test cases: none
  -}
  TcRnUnexpectedPragmas :: !Id -> !(NE.NonEmpty (LSig GhcRn)) -> TcRnMessage

  {-| TcRnNonOverloadedSpecialisePragma is a warning for a specialise pragma being
     placed on a definition that is not overloaded.

     Example(s):
     {-# SPECIALISE foo :: Bool -> Bool #-}
     foo :: Bool -> Bool
     foo = id

    Test cases: simplCore/should_compile/T8537
                typecheck/should_compile/T10504
  -}
  TcRnNonOverloadedSpecialisePragma :: !(LIdP GhcRn) -> TcRnMessage

  {-| TcRnSpecialiseNotVisible is a warning that occurs when the subject of a
     SPECIALISE pragma has a definition that is not visible from the current module.

     Example(s): none

    Test cases: none
  -}
  TcRnSpecialiseNotVisible :: !Name -> TcRnMessage

  {-| TcRnPragmaWarning is a warning that can happen when usage of something
     is warned or deprecated by pragma.

    Test cases:
      DeprU
      T5281
      T5867
      rn050
      rn066 (here is a warning, not deprecation)
      T3303
  -}
  TcRnPragmaWarning :: {
    pragma_warning_occ :: OccName,
    pragma_warning_msg :: WarningTxt GhcRn,
    pragma_warning_import_mod :: ModuleName,
    pragma_warning_defined_mod :: ModuleName
  } -> TcRnMessage


  {-| TcRnIllegalHsigDefaultMethods is an error that occurs when a binding for
     a class default method is provided in a Backpack signature file.

    Test case:
      bkpfail40
  -}
  TcRnIllegalHsigDefaultMethods :: !Name -- ^ 'Name' of the class
                                -> NE.NonEmpty (LHsBind GhcRn) -- ^ default methods
                                -> TcRnMessage

  {-| TcRnHsigFixityMismatch is an error indicating that the fixity decl in a
    Backpack signature file differs from the one in the source file for the same
    operator.

    Test cases:
      bkpfail37, bkpfail38
  -}
  TcRnHsigFixityMismatch :: !TyThing -- ^ The operator whose fixity is defined
                         -> !Fixity -- ^ the fixity used in the source file
                         -> !Fixity -- ^ the fixity used in the signature
                         -> TcRnMessage

  {-| TcRnHsigShapeMismatch is a group of errors related to mismatches between
    backpack signatures.
  -}
  TcRnHsigShapeMismatch :: !HsigShapeMismatchReason
                         -> TcRnMessage

  {-| TcRnHsigMissingModuleExport is an error indicating that a module doesn't
    export a name exported by its signature.

    Test cases:
      bkpfail01, bkpfail05, bkpfail09, bkpfail16, bkpfail35, bkpcabal06
  -}
  TcRnHsigMissingModuleExport :: !OccName -- ^ The missing name
                              -> !UnitState -- ^ The module's unit state
                              -> !Module -- ^ The implementation module
                              -> TcRnMessage

  {-| TcRnBadGenericMethod
     This test ensures that if you provide a "more specific" type signatures
     for the default method, you must also provide a binding.

     Example:
     {-# LANGUAGE DefaultSignatures #-}

     class C a where
       meth :: a
       default meth :: Num a => a
       meth = 0

    Test case:
      testsuite/tests/typecheck/should_fail/MissingDefaultMethodBinding.hs
  -}
  TcRnBadGenericMethod :: !Name   -- ^ 'Name' of the class
                       -> !Name   -- ^ Problematic method
                       -> TcRnMessage

  {-| TcRnWarningMinimalDefIncomplete is a warning that one must
      specify which methods must be implemented by all instances.

     Example:
       class Cheater a where  -- WARNING LINE
       cheater :: a
       {-# MINIMAL #-} -- warning!

     Test case:
       testsuite/tests/warnings/minimal/WarnMinimal.hs:
  -}
  TcRnWarningMinimalDefIncomplete :: ClassMinimalDef -> TcRnMessage

  {-| TcRnDefaultMethodForPragmaLacksBinding is an error that occurs when
      a default method pragma is missing an accompanying binding.

    Test cases:
      testsuite/tests/typecheck/should_fail/T5084.hs
      testsuite/tests/typecheck/should_fail/T2354.hs
  -}
  TcRnDefaultMethodForPragmaLacksBinding
            :: Id             -- ^ method
            -> Sig GhcRn      -- ^ the pragma
            -> TcRnMessage
  {-| TcRnIgnoreSpecialisePragmaOnDefMethod is a warning that occurs when
      a specialise pragma is put on a default method.

    Test cases: none
  -}
  TcRnIgnoreSpecialisePragmaOnDefMethod
            :: !Name
            -> TcRnMessage
  {-| TcRnBadMethodErr is an error that happens when one attempts to provide a method
     in a class instance, when the class doesn't have a method by that name.

     Test case:
       testsuite/tests/th/T12387
  -}
  TcRnBadMethodErr
    :: { badMethodErrClassName  :: !Name
       , badMethodErrMethodName :: !Name
       } -> TcRnMessage
  {-| TcRnNoExplicitAssocTypeOrDefaultDeclaration is an error that occurs
      when a class instance does not provide an expected associated type
      or default declaration.

    Test cases:
      testsuite/tests/deriving/should_compile/T14094
      testsuite/tests/indexed-types/should_compile/Simple2
      testsuite/tests/typecheck/should_compile/tc254
  -}
  TcRnNoExplicitAssocTypeOrDefaultDeclaration
            :: Name
            -> TcRnMessage
  {-| TcRnIllegalNewtype is an error that occurs when a newtype:

      * Does not have exactly one field, or
      * is non-linear, or
      * is a GADT, or
      * has a context in its constructor's type, or
      * has existential type variables in its constructor's type, or
      * has strictness annotations.

    Test cases:
      testsuite/tests/gadt/T14719
      testsuite/tests/indexed-types/should_fail/T14033
      testsuite/tests/indexed-types/should_fail/T2334A
      testsuite/tests/linear/should_fail/LinearGADTNewtype
      testsuite/tests/parser/should_fail/readFail008
      testsuite/tests/polykinds/T11459
      testsuite/tests/typecheck/should_fail/T15523
      testsuite/tests/typecheck/should_fail/T15796
      testsuite/tests/typecheck/should_fail/T17955
      testsuite/tests/typecheck/should_fail/T18891a
      testsuite/tests/typecheck/should_fail/T21447
      testsuite/tests/typecheck/should_fail/tcfail156
  -}
  TcRnIllegalNewtype
            :: DataCon
            -> Bool -- ^ True if linear types enabled
            -> IllegalNewtypeReason
            -> TcRnMessage

  {-| TcRnIllegalTypeData is an error that occurs when a @type data@
      declaration occurs without the TypeOperators extension.

      See Note [Type data declarations]

     Test case:
       testsuite/tests/type-data/should_fail/TDNoPragma
  -}
  TcRnIllegalTypeData :: TcRnMessage

  {-| TcRnTypeDataForbids is an error that occurs when a @type data@
      declaration contains @data@ declaration features that are
      forbidden in a @type data@ declaration.

      See Note [Type data declarations]

     Test cases:
       testsuite/tests/type-data/should_fail/TDDeriving
       testsuite/tests/type-data/should_fail/TDRecordsGADT
       testsuite/tests/type-data/should_fail/TDRecordsH98
       testsuite/tests/type-data/should_fail/TDStrictnessGADT
       testsuite/tests/type-data/should_fail/TDStrictnessH98
  -}
  TcRnTypeDataForbids :: !TypeDataForbids -> TcRnMessage

  {-| TcRnTypedTHWithPolyType is an error that signifies the illegal use
      of a polytype in a typed template haskell expression.

      Example(s):
      bad :: (forall a. a -> a) -> ()
      bad = $$( [|| \_ -> () ||] )

     Test cases: th/T11452
  -}
  TcRnTypedTHWithPolyType :: !TcType -> TcRnMessage

  {-| TcRnSpliceThrewException is an error that occurrs when running a template
      haskell splice throws an exception.

      Example(s):

     Test cases: annotations/should_fail/annfail12
                 perf/compiler/MultiLayerModulesTH_Make
                 perf/compiler/MultiLayerModulesTH_OneShot
                 th/T10796b
                 th/T19470
                 th/T19709d
                 th/T5358
                 th/T5976
                 th/T7276a
                 th/T8987
                 th/TH_exn1
                 th/TH_exn2
                 th/TH_runIO
  -}
  TcRnSpliceThrewException
    :: !SplicePhase
    -> !SomeException
    -> !String -- ^ Result of showing the exception (cannot be done safely outside IO)
    -> !(LHsExpr GhcTc)
    -> !Bool -- True <=> Print the expression
    -> TcRnMessage

  {-| TcRnInvalidTopDecl is a template haskell error occurring when one of the 'Dec's passed to
      'addTopDecls' is not a function, value, annotation, or foreign import declaration.

      Example(s):

     Test cases:
  -}
  TcRnInvalidTopDecl :: !(HsDecl GhcPs) -> TcRnMessage

  {-| TcRnNonExactName is a template haskell error for when a declaration being
      added is bound to a name that is not fully known.

      Example(s):

     Test cases:
  -}
  TcRnNonExactName :: !RdrName -> TcRnMessage

  {-| TcRnAddInvalidCorePlugin is a template haskell error indicating that a
      core plugin being added has an invalid module due to being in the current package.

      Example(s):

     Test cases:
  -}
  TcRnAddInvalidCorePlugin
    :: !String -- ^ Module name
    -> TcRnMessage

  {-| TcRnAddDocToNonLocalDefn is a template haskell error for documentation being added to a
      definition which is not in the current module.

      Example(s):

     Test cases: showIface/should_fail/THPutDocExternal
  -}
  TcRnAddDocToNonLocalDefn :: !TH.DocLoc -> TcRnMessage

  {-| TcRnFailedToLookupThInstName is a template haskell error that occurrs when looking up an
      instance fails.

      Example(s):

     Test cases: showIface/should_fail/THPutDocNonExistent
  -}
  TcRnFailedToLookupThInstName :: !TH.Type -> !LookupTHInstNameErrReason -> TcRnMessage

  {-| TcRnCannotReifyInstance is a template haskell error for when an instance being reified
      via `reifyInstances` is not a class constraint or type family application.

      Example(s):

     Test cases:
  -}
  TcRnCannotReifyInstance :: !Type -> TcRnMessage

  {-| TcRnCannotReifyOutOfScopeThing is a template haskell error indicating
      that the given name is not in scope and therefore cannot be reified.

      Example(s):

     Test cases: th/T16976f
  -}
  TcRnCannotReifyOutOfScopeThing :: !TH.Name -> TcRnMessage

  {-| TcRnCannotReifyThingNotInTypeEnv is a template haskell error occurring
      when the given name is not in the type environment and therefore cannot be reified.

      Example(s):

     Test cases:
  -}
  TcRnCannotReifyThingNotInTypeEnv :: !Name -> TcRnMessage

  {-| TcRnNoRolesAssociatedWithName is a template haskell error for when the user
      tries to reify the roles of a given name but it is not something that has
      roles associated with it.

      Example(s):

     Test cases:
  -}
  TcRnNoRolesAssociatedWithThing :: !TcTyThing -> TcRnMessage

  {-| TcRnCannotRepresentThing is a template haskell error indicating that a
      type cannot be reified because it does not have a representation in template haskell.

      Example(s):

     Test cases:
  -}
  TcRnCannotRepresentType :: !UnrepresentableTypeDescr -> !Type -> TcRnMessage

  {-| TcRnRunSpliceFailure is an error indicating that a Template Haskell splice
      failed to be converted into a valid expression.

      Example(s):

     Test cases: th/T10828a
                 th/T10828b
                 th/T12478_4
                 th/T15270A
                 th/T15270B
                 th/T16895a
                 th/T16895b
                 th/T16895c
                 th/T16895d
                 th/T16895e
                 th/T18740d
                 th/T2597b
                 th/T2674
                 th/T3395
                 th/T7484
                 th/T7667a
                 th/TH_implicitParamsErr1
                 th/TH_implicitParamsErr2
                 th/TH_implicitParamsErr3
                 th/TH_invalid_add_top_decl
  -}
  TcRnRunSpliceFailure
    :: !(Maybe String) -- ^ Name of the function used to run the splice
    -> !RunSpliceFailReason
    -> TcRnMessage

  {-| TcRnUserErrReported is an error or warning thrown using 'qReport' from
      the 'Quasi' instance of 'TcM'.

      Example(s):

     Test cases:
  -}
  TcRnReportCustomQuasiError
    :: !Bool -- True => Error, False => Warning
    -> !String -- Error body
    -> TcRnMessage

  {-| TcRnUnsatisfiedMinimalDef is a warning that occurs when a class instance
       is missing methods that are required by the minimal definition.

       Example:
          class C a where
            foo :: a -> a
          instance C ()        -- | foo needs to be defined here

       Test cases:
         testsuite/tests/typecheck/prog001/typecheck.prog001
         testsuite/tests/typecheck/should_compile/tc126
         testsuite/tests/typecheck/should_compile/T7903
         testsuite/tests/typecheck/should_compile/tc116
         testsuite/tests/typecheck/should_compile/tc175
         testsuite/tests/typecheck/should_compile/HasKey
         testsuite/tests/typecheck/should_compile/tc125
         testsuite/tests/typecheck/should_compile/tc078
         testsuite/tests/typecheck/should_compile/tc161
         testsuite/tests/typecheck/should_fail/T5051
         testsuite/tests/typecheck/should_compile/T21583
         testsuite/tests/backpack/should_compile/bkp47
         testsuite/tests/backpack/should_fail/bkpfail25
         testsuite/tests/parser/should_compile/T2245
         testsuite/tests/parser/should_compile/read014
         testsuite/tests/indexed-types/should_compile/Class3
         testsuite/tests/indexed-types/should_compile/Simple2
         testsuite/tests/indexed-types/should_fail/T7862
         testsuite/tests/deriving/should_compile/deriving-1935
         testsuite/tests/deriving/should_compile/T9968a
         testsuite/tests/deriving/should_compile/drv003
         testsuite/tests/deriving/should_compile/T4966
         testsuite/tests/deriving/should_compile/T14094
         testsuite/tests/perf/compiler/T15304
         testsuite/tests/warnings/minimal/WarnMinimal
         testsuite/tests/simplCore/should_compile/simpl020
         testsuite/tests/deSugar/should_compile/T14546d
         testsuite/tests/ghci/scripts/T5820
         testsuite/tests/ghci/scripts/ghci019
  -}
  TcRnUnsatisfiedMinimalDef :: ClassMinimalDef -> TcRnMessage

  {-| 'TcRnMisplacedInstSig' is an error that happens when a method in
       a class instance is given a type signature, but the user has not
       enabled the @InstanceSigs@ extension.

       Test case:
       testsuite/tests/module/mod45
  -}
  TcRnMisplacedInstSig :: Name -> (LHsSigType GhcRn) -> TcRnMessage
  {-| 'TcRnIllegalFamilyInstance' is an error that occurs when an associated
       type or data family is given a top-level instance.

       Test case:
       testsuite/tests/indexed-types/should_fail/T3092
  -}
  TcRnIllegalFamilyInstance :: TyCon -> TcRnMessage
  {-| 'TcRnMissingClassAssoc' is an error that occurs when a class instance
       for a class with an associated type or data family is missing a corresponding
       family instance declaration.

       Test case:
       testsuite/tests/indexed-types/should_fail/SimpleFail7
  -}
  TcRnMissingClassAssoc :: TyCon -> TcRnMessage
  {-| 'TcRnNotOpenFamily' is an error that is triggered by attempting to give
       a top-level (open) type family instance for a closed type family.

       Test cases:
         testsuite/tests/indexed-types/should_fail/Overlap7
         testsuite/tests/indexed-types/should_fail/Overlap3
  -}
  TcRnNotOpenFamily :: TyCon -> TcRnMessage
  {-| TcRnNoRebindableSyntaxRecordDot is an error triggered by an overloaded record update
      without RebindableSyntax enabled.

      Example(s):

     Test cases: parser/should_fail/RecordDotSyntaxFail5
  -}
  TcRnNoRebindableSyntaxRecordDot :: TcRnMessage

  {-| TcRnNoFieldPunsRecordDot is an error triggered by the use of record field puns
      in an overloaded record update without enabling NamedFieldPuns.

      Example(s):
      print $ a{ foo.bar.baz.quux }

     Test cases: parser/should_fail/RecordDotSyntaxFail12
  -}
  TcRnNoFieldPunsRecordDot :: TcRnMessage

  {-| TcRnIllegalStaticExpression is an error thrown when user creates a static
      pointer via TemplateHaskell without enabling the StaticPointers extension.

      Example(s):

     Test cases: th/T14204
  -}
  TcRnIllegalStaticExpression :: HsExpr GhcPs -> TcRnMessage

  {-| TcRnIllegalStaticFormInSplice is an error when a user attempts to define
      a static pointer in a Template Haskell splice.

      Example(s):

     Test cases: th/TH_StaticPointers02
  -}
  TcRnIllegalStaticFormInSplice :: HsExpr GhcPs -> TcRnMessage

  {-| TcRnListComprehensionDuplicateBinding is an error triggered by duplicate
      let-bindings in a list comprehension.

      Example(s):
      [ () | let a = 13 | let a = 17 ]

     Test cases: typecheck/should_fail/tcfail092
  -}
  TcRnListComprehensionDuplicateBinding :: Name -> TcRnMessage

  {-| TcRnEmptyStmtsGroup is an error triggered by an empty list of statements
      in a statement block. For more information, see 'EmptyStatementGroupErrReason'

      Example(s):

        [() | then ()]

        do

        proc () -> do

     Test cases: rename/should_fail/RnEmptyStatementGroup1
  -}
  TcRnEmptyStmtsGroup:: EmptyStatementGroupErrReason -> TcRnMessage

  {-| TcRnLastStmtNotExpr is an error caused by the last statement
      in a statement block not being an expression.

      Example(s):

        do x <- pure ()

        do let x = 5

     Test cases: rename/should_fail/T6060
                 parser/should_fail/T3811g
                 parser/should_fail/readFail028
  -}
  TcRnLastStmtNotExpr
    :: HsStmtContext GhcRn
    -> UnexpectedStatement
    -> TcRnMessage

  {-| TcRnUnexpectedStatementInContext is an error when a statement appears
      in an unexpected context (e.g. an arrow statement appears in a list comprehension).

      Example(s):

     Test cases: parser/should_fail/readFail042
                 parser/should_fail/readFail038
                 parser/should_fail/readFail043
  -}
  TcRnUnexpectedStatementInContext
    :: HsStmtContext GhcRn
    -> UnexpectedStatement
    -> Maybe LangExt.Extension
    -> TcRnMessage

  {-| TcRnIllegalTupleSection is an error triggered by usage of a tuple section
      without enabling the TupleSections extension.

      Example(s):
        (5,)

     Test cases: rename/should_fail/rnfail056
  -}
  TcRnIllegalTupleSection :: TcRnMessage

  {-| TcRnIllegalImplicitParameterBindings is an error triggered by binding
      an implicit parameter in an mdo block.

      Example(s):
      mdo { let { ?x = 5 }; () }

     Test cases: rename/should_fail/RnImplicitBindInMdoNotation
  -}
  TcRnIllegalImplicitParameterBindings
    :: Either (HsLocalBindsLR GhcPs GhcPs) (HsLocalBindsLR GhcRn GhcPs)
    -> TcRnMessage

  {-| TcRnSectionWithoutParentheses is an error triggered by attempting to
      use an operator section without parentheses.

      Example(s):
      (`head` x, ())

     Test cases: rename/should_fail/T2490
                 rename/should_fail/T5657
  -}
  TcRnSectionWithoutParentheses :: HsExpr GhcPs -> TcRnMessage

  {-| TcRnBindingOfExistingName is an error triggered by an attempt to rebind
     built-in syntax, punned list or tuple syntax, or a name quoted via Template Haskell.

     Examples:

       data []
       data (->)
       $(pure [ValD (VarP 'succ) (NormalB (ConE 'True)) []])

     Test cases: rename/should_fail/T14907b
                 rename/should_fail/T22839
                 rename/should_fail/rnfail042
                 th/T13968
  -}
  TcRnBindingOfExistingName :: RdrName -> TcRnMessage
  {-| TcRnMultipleFixityDecls is an error triggered by multiple
      fixity declarations for the same operator.

     Example(s):

       infixr 6 $$
       infixl 4 $$

     Test cases: rename/should_fail/RnMultipleFixityFail
  -}
  TcRnMultipleFixityDecls :: SrcSpan -> RdrName -> TcRnMessage

  {-| TcRnIllegalPatternSynonymDecl is an error thrown when a user
      defines a pattern synonyms without enabling the PatternSynonyms extension.

     Example:

       pattern O :: Int
       pattern O = 0

     Test cases: rename/should_fail/RnPatternSynonymFail
  -}
  TcRnIllegalPatternSynonymDecl :: TcRnMessage

  {-| TcRnIllegalClassBinding is an error triggered by a binding
      in a class or instance declaration of an illegal form.

     Examples:

        class ZeroOne a where
          zero :: a
          one :: a
        instance ZeroOne Int where
          (zero,one) = (0,1)

        class C a where
           pattern P = ()

     Test cases: module/mod48
                 patsyn/should_fail/T9705-1
                 patsyn/should_fail/T9705-2
                 typecheck/should_fail/tcfail021

  -}
  TcRnIllegalClassBinding :: DeclSort -> HsBindLR GhcPs GhcPs -> TcRnMessage

  {-| TcRnOrphanCompletePragma is an error triggered by a {-# COMPLETE #-}
      pragma which does not mention any data constructors or pattern synonyms
      defined in the current module.

     Test cases: patsyn/should_fail/T13349
  -}
  TcRnOrphanCompletePragma :: TcRnMessage

  {-| TcRnEmptyCase is an error thrown when a user uses
      a case expression with an empty list of alternatives without
      enabling the EmptyCase extension.

     Example(s):

       case () of

     Test cases: rename/should_fail/RnEmptyCaseFail
  -}
  TcRnEmptyCase :: HsMatchContext GhcRn -> TcRnMessage

  {-| TcRnNonStdGuards is a warning thrown when a user uses
      non-standard guards (e.g. patterns in guards) without
      enabling the PatternGuards extension.
      More realistically: the user has explicitly disabled PatternGuards,
      as it is enabled by default with `-XHaskell2010`.

     Example(s):

       f | 5 <- 2 + 3 = ...

     Test cases: rename/should_compile/rn049
  -}
  TcRnNonStdGuards :: NonStandardGuards -> TcRnMessage

  {-| TcRnDuplicateSigDecl is an error triggered by two or more
      signatures for one entity.

     Examples:

       f :: Int -> Bool
       f :: Int -> Bool
       f _ = True

       g x = x
       {-# INLINE g #-}
       {-# NOINLINE g #-}

       pattern P = ()
       {-# COMPLETE P #-}
       {-# COMPLETE P #-}

     Test cases: module/mod68
                 parser/should_fail/OpaqueParseFail4
                 patsyn/should_fail/T12165
                 rename/should_fail/rnfail048
                 rename/should_fail/T5589
                 rename/should_fail/T7338
                 rename/should_fail/T7338a
  -}
  TcRnDuplicateSigDecl :: NE.NonEmpty (LocatedN RdrName, Sig GhcPs) -> TcRnMessage

  {-| TcRnMisplacedSigDecl is an error triggered by the pragma application
      in the wrong context, like `MINIMAL` applied to a function or
      `SPECIALIZE` to an instance.

     Example:

       f x = x
       {-# MINIMAL f #-}

     Test cases: rename/should_fail/T18138
                 warnings/minimal/WarnMinimalFail1
  -}
  TcRnMisplacedSigDecl :: Sig GhcRn -> TcRnMessage

  {-| TcRnUnexpectedDefaultSig is an error thrown when a user uses
      default signatures without enabling the DefaultSignatures extension.

     Example:

       class C a where
         m :: a
         default m :: Num a => a
         m = 0

     Test cases: rename/should_fail/RnDefaultSigFail
  -}
  TcRnUnexpectedDefaultSig :: Sig GhcPs -> TcRnMessage

  {-| TcRnDuplicateMinimalSig is an error triggered by two or more minimal
      signatures for one type class.

     Example:

       class C where
         f :: ()
         {-# MINIMAL f #-}
         {-# MINIMAL f #-}

     Test cases: rename/should_fail/RnMultipleMinimalPragmaFail
  -}
  TcRnDuplicateMinimalSig :: LSig GhcPs -> LSig GhcPs -> [LSig GhcPs] -> TcRnMessage

  {-| TcRnLoopySuperclassSolve is a warning, controlled by @-Wloopy-superclass-solve@,
      that is triggered when GHC solves a constraint in a possibly-loopy way,
      violating the class instance termination rules described in the section
      "Undecidable instances and loopy superclasses" of the user's guide.

      Example:

        class Foo f
        class Foo f => Bar f g
        instance Bar f f => Bar f (h k)

      Test cases: T20666, T20666{a,b}, T22891, T22912.
  -}
  TcRnLoopySuperclassSolve :: CtLoc    -- ^ Wanted 'CtLoc'
                           -> PredType -- ^ Wanted 'PredType'
                           -> TcRnMessage

  {-| TcRnIllegalInstanceHeadDecl is an error triggered by malformed head of
      type class instance

      Examples:

        instance 42

        instance !Show D

      Test cases: parser/should_fail/T3811c
                  rename/should_fail/T18240a
  -}
  TcRnIllegalInstanceHeadDecl :: LHsType GhcRn -> TcRnMessage

  {-| TcRnUnexpectedStandaloneDerivingDecl is an error thrown when a user uses
      standalone deriving without enabling the StandaloneDeriving extension.

      Example:

        deriving instance Eq Foo

      Test cases: rename/should_fail/RnUnexpectedStandaloneDeriving
  -}
  TcRnUnexpectedStandaloneDerivingDecl :: TcRnMessage

  {-| TcRnUnusedVariableInRuleDecl is an error triggered by forall'd variable in
      rewrite rule that does not appear on left-hand side

      Example:

        {-# RULES "rule" forall a. id = id #-}

      Test cases: rename/should_fail/ExplicitForAllRules2
  -}
  TcRnUnusedVariableInRuleDecl :: FastString -> Name -> TcRnMessage

  {-| TcRnUnexpectedStandaloneKindSig is an error thrown when a user uses standalone
      kind signature without enabling the StandaloneKindSignatures extension.

      Example:

        type D :: Type
        data D = D

      Test cases: saks/should_fail/saks_fail001
  -}
  TcRnUnexpectedStandaloneKindSig :: TcRnMessage

  {-| TcRnIllegalRuleLhs is an error triggered by malformed left-hand side
      of rewrite rule

      Examples:

        {-# RULES "test" forall x. f x = x #-}

        {-# RULES "test" forall x. case x of = x #-}

      Test cases: rename/should_fail/T15659
  -}
  TcRnIllegalRuleLhs
    :: RuleLhsErrReason
    -> FastString -- Rule name
    -> LHsExpr GhcRn -- Full expression
    -> HsExpr GhcRn -- Bad expression
    -> TcRnMessage

  {-| TcRnBadAssocRhs is an error triggered by out-of-scope type variables
      occurred in right-hand side of an associated type declaration

      Example:

        instance forall a. C Int where
          data instance D Int = MkD1 a

       cases: indexed-types/should_fail/T5515
                  polykinds/T9574
                  rename/should_fail/T18021
  -}
  TcRnBadAssocRhs :: [Name] -> TcRnMessage

  {-| TcRnDuplicateRoleAnnot is an error triggered by two or more role
      annotations for one type

      Example:

        data D a
        type role D phantom
        type role D phantom

      Test cases: roles/should_fail/Roles8
  -}
  TcRnDuplicateRoleAnnot :: NE.NonEmpty (LRoleAnnotDecl GhcPs) -> TcRnMessage

  {-| TcRnDuplicateKindSig is an error triggered by two or more standalone
      kind signatures for one type

      Example:

        type D :: Type
        type D :: Type
        data D

      Test cases: saks/should_fail/saks_fail002
  -}
  TcRnDuplicateKindSig :: NE.NonEmpty (LStandaloneKindSig GhcPs) -> TcRnMessage

  {-| TcRnIllegalDerivStrategy  is an error thrown when a user uses deriving
      strategy without enabling the DerivingStrategies extension or uses deriving
      via without enabling the DerivingVia extension.

      Examples:

        data T = T deriving stock Eq

        data T = T deriving via Eq T

      Test cases: deriving/should_fail/deriving-via-fail3
                  deriving/should_fail/T10598_fail4
  -}
  TcRnIllegalDerivStrategy :: DerivStrategy GhcPs -> TcRnMessage

  {-| TcRnIllegalMultipleDerivClauses is an error thrown when a user uses two or more
      deriving clauses without enabling the DerivingStrategies extension.

      Example:

        data T = T
          deriving Eq
          deriving Ord

      Test cases: deriving/should_fail/T10598_fail5
  -}
  TcRnIllegalMultipleDerivClauses :: TcRnMessage

  {-| TcRnNoDerivStratSpecified is a warning implied by -Wmissing-deriving-strategies
      and triggered by deriving clause without specified deriving strategy.

      Example:

        data T = T
          deriving Eq

      Test cases: rename/should_compile/T15798a
                  rename/should_compile/T15798b
                  rename/should_compile/T15798c
  -}
  TcRnNoDerivStratSpecified
    :: Bool -- True if DerivingStrategies is enabled
    -> TcRnMessage

  {-| TcRnStupidThetaInGadt is an error triggered by data contexts in GADT-style
      data declaration

      Example:

        data (Eq a) => D a where
          MkD :: D Int

      Test cases: rename/should_fail/RnStupidThetaInGadt
  -}
  TcRnStupidThetaInGadt :: HsDocContext -> TcRnMessage

  {-| TcRnBadImplicitSplice is an error thrown when a user uses top-level implicit
      TH-splice without enabling the TemplateHaskell extension.

      Example:

        pure [] -- on top-level

      Test cases: ghci/prog019/prog019
                  ghci/scripts/T1914
                  ghci/scripts/T6106
                  rename/should_fail/T4042
                  rename/should_fail/T12146
  -}
  TcRnBadImplicitSplice :: TcRnMessage

  {-| TcRnShadowedTyVarNameInFamResult is an error triggered by type variable in
      type family result that shadows type variable from left hand side

      Example:

        type family F a b c = b

      Test cases: ghci/scripts/T6018ghcirnfail
                  rename/should_fail/T6018rnfail
  -}
  TcRnShadowedTyVarNameInFamResult :: IdP GhcPs -> TcRnMessage

  {-| TcRnIncorrectTyVarOnRhsOfInjCond is an error caused by a situation where the
      left-hand side of an injectivity condition of a type family is not a variable
      referring to the type family result.
      See Note [Renaming injectivity annotation] for more details.

      Example:

        type family F a = r | a -> a

      Test cases: ghci/scripts/T6018ghcirnfail
                  rename/should_fail/T6018rnfail
  -}
  TcRnIncorrectTyVarOnLhsOfInjCond
    :: IdP GhcRn -- Expected
    -> LIdP GhcPs -- Actual
    -> TcRnMessage

  {-| TcRnUnknownTyVarsOnRhsOfInjCond is an error triggered by out-of-scope type
      variables on the right-hand side of a of an injectivity condition of a type family

      Example:

        type family F a = res | res -> b

      Test cases: ghci/scripts/T6018ghcirnfail
                  rename/should_fail/T6018rnfail
  -}
  TcRnUnknownTyVarsOnRhsOfInjCond :: [Name] -> TcRnMessage

  {-| TcRnLookupInstance groups several errors emitted when looking up class instances.

    Test cases:
      none
  -}
  TcRnLookupInstance
    :: !Class
    -> ![Type]
    -> !LookupInstanceErrReason
    -> TcRnMessage

  {-| TcRnBadlyStaged is an error that occurs when a TH binding is used in an
    invalid stage.

    Test cases:
      T17820d
  -}
  TcRnBadlyStaged
    :: !StageCheckReason -- ^ The binding being spliced.
    -> !Int -- ^ The binding stage.
    -> !Int -- ^ The stage at which the binding is used.
    -> TcRnMessage

  {-| TcRnStageRestriction is an error that occurs when a top level splice refers to
    a local name.

    Test cases:
      T17820, T21547, T5795, qq00[1-4], annfail0{3,4,6,9}
  -}
  TcRnStageRestriction
    :: !StageCheckReason -- ^ The binding being spliced.
    -> TcRnMessage

  {-| TcRnTyThingUsedWrong is an error that occurs when a thing is used where another
    thing was expected.

    Test cases:
      none
  -}
  TcRnTyThingUsedWrong
    :: !WrongThingSort -- ^ Expected thing.
    -> !TcTyThing -- ^ Thing used wrongly.
    -> !Name -- ^ Name of the thing used wrongly.
    -> TcRnMessage

  {-| TcRnCannotDefaultKindVar is an error that occurs when attempting to use
    unconstrained kind variables whose type isn't @Type@, without -XPolyKinds.

    Test cases:
      T11334b
  -}
  TcRnCannotDefaultKindVar
    :: !TyVar -- ^ The unconstrained variable.
    -> !Kind -- ^ Kind of the variable.
    -> TcRnMessage

  {-| TcRnUninferrableTyVar is an error that occurs when metavariables
    in a type could not be defaulted.

    Test cases:
      T17301, T17562, T17567, T17567StupidTheta, T15474, T21479
  -}
  TcRnUninferrableTyVar
    :: ![TyCoVar] -- ^ The variables that could not be defaulted.
    -> !UninferrableTyVarCtx -- ^ Description of the surrounding context.
    -> TcRnMessage

  {-| TcRnSkolemEscape is an error that occurs when type variables from an
    outer scope is used in a context where they should be locally scoped.

    Test cases:
      T15076, T15076b, T14880-2, T15825, T14880, T15807, T16946, T14350,
      T14040A, T15795, T15795a, T14552
  -}
  TcRnSkolemEscape
    :: ![TcTyVar] -- ^ The variables that would escape.
    -> !TcTyVar -- ^ The variable that is being quantified.
    -> !Type -- ^ The type in which they occur.
    -> TcRnMessage

  {-| TcRnPatSynEscapedCoercion is an error indicating that a coercion escaped from
    a pattern synonym into a type.
    See Note [Coercions that escape] in GHC.Tc.TyCl.PatSyn

    Test cases:
      T14507
  -}
  TcRnPatSynEscapedCoercion :: !Id -- ^ The pattern-bound variable
                            -> !(NE.NonEmpty CoVar) -- ^ The escaped coercions
                            -> TcRnMessage

  {-| TcRnPatSynExistentialInResult is an error indicating that the result type
    of a pattern synonym mentions an existential type variable.

    Test cases:
      PatSynExistential
  -}
  TcRnPatSynExistentialInResult :: !Name -- ^ The name of the pattern synonym
                                -> !TcSigmaType -- ^ The result type
                                -> ![TyVar] -- ^ The escaped existential variables
                                -> TcRnMessage

  {-| TcRnPatSynArityMismatch is an error indicating that the number of arguments in a
    pattern synonym's equation differs from the number of parameters in its
    signature.

    Test cases:
      PatSynArity
  -}
  TcRnPatSynArityMismatch :: !Name -- ^ The name of the pattern synonym
                          -> !Arity -- ^ The number of equation arguments
                          -> !Arity -- ^ The difference
                          -> TcRnMessage

  {-| TcRnPatSynInvalidRhs is an error group indicating that the pattern on the
    right hand side of a pattern synonym is invalid.

    Test cases:
      unidir, T14112
  -}
  TcRnPatSynInvalidRhs :: !Name -- ^ The name of the pattern synonym
                       -> !(LPat GhcRn) -- ^ The pattern
                       -> ![LIdP GhcRn] -- ^ The LHS args
                       -> !PatSynInvalidRhsReason -- ^ The number of equation arguments
                       -> TcRnMessage
  {-| TcRnCannotDefaultConcrete is an error occurring when a concrete
    type variable cannot be defaulted.

    Test cases:
      T23153
  -}
  TcRnCannotDefaultConcrete
    :: !FixedRuntimeRepOrigin
    -> TcRnMessage

  {-| TcRnMultiAssocTyFamDefaults is an error indicating that multiple default
    declarations were specified for an associated type family.

    Test cases:
      none
  -}
  TcRnMultiAssocTyFamDefaults :: !(IdP GhcRn) -- ^ Name of the associated type
                              -> TcRnMessage

  {-| TcRnTyFamDepsDisabled is an error indicating that a type family injectivity
    annotation was used without enabling the extension TypeFamilyDependencies.

    Test cases:
      T11381
  -}
  TcRnTyFamDepsDisabled :: TcRnMessage

  {-| TcRnAbstractClosedTyFamDecl is an error indicating that an abstract closed
    type family was declared in a regular source file, while it is only allowed
    in hs-boot files.

    Test cases:
      ClosedFam4
  -}
  TcRnAbstractClosedTyFamDecl :: TcRnMessage

  {-| TcRnPartialFieldSelector is a warning indicating that a record selector
    was not defined for all constructors of a data type.

    Test cases:
      DRFPartialFields, T7169
  -}
  TcRnPartialFieldSelector :: !FieldLabel -- ^ The selector
                           -> TcRnMessage

  {-| TcRnBadFieldAnnotation is an error/warning group indicating that a
    strictness/unpack related data type field annotation is invalid.
  -}
  TcRnBadFieldAnnotation :: !Int -- ^ The index of the field
                         -> !DataCon -- ^ The constructor in which the field is defined
                         -> !BadFieldAnnotationReason -- ^ The error specifics
                         -> TcRnMessage

  {-| TcRnSuperclassCycle is an error indicating that a class has a superclass
    cycle.

    Test cases:
      mod40, tcfail027, tcfail213, tcfail216, tcfail217, T9415, T9739
  -}
  TcRnSuperclassCycle :: !SuperclassCycle -- ^ The details of the cycle
                      -> TcRnMessage

  {-| TcRnDefaultSigMismatch is an error indicating that a default method
    signature doesn't match the regular method signature.

    Test cases:
      T7437, T12918a, T12918b, T12151
  -}
  TcRnDefaultSigMismatch :: !Id -- ^ The name of the method
                         -> !Type -- ^ The type of the default signature
                         -> TcRnMessage

  {-| TcRnTyFamsDisabled is an error indicating that a type family or instance
    was declared while the extension TypeFamilies was disabled.

    Test cases:
      TyFamsDisabled
  -}
  TcRnTyFamsDisabled :: !TyFamsDisabledReason -- ^ The name of the family or instance
                     -> TcRnMessage

  {-| TcRnTyFamResultDisabled is an error indicating that a result variable
    was used on a type family while the extension TypeFamilyDependencies was
    disabled.

    Test cases:
      T13571, T13571a
  -}
  TcRnTyFamResultDisabled :: !Name -- ^ The name of the type family
                          -> !(LHsTyVarBndr () GhcRn) -- ^ Name of the result variable
                          -> TcRnMessage

  {-| TcRnRoleValidationFailed is an error indicating that a variable was
    assigned an invalid role by the inference algorithm.
    This is only performed with -dcore-lint.
  -}
  TcRnRoleValidationFailed :: !Role -- ^ The validated role
                           -> !RoleValidationFailedReason -- ^ The failure reason
                           -> TcRnMessage

  {-| TcRnCommonFieldResultTypeMismatch is an error indicating that a sum type
    declares the same field name in multiple constructors, but the constructors'
    result types differ.

    Test cases:
      CommonFieldResultTypeMismatch
  -}
  TcRnCommonFieldResultTypeMismatch :: !DataCon -- ^ First constructor
                                    -> !DataCon -- ^ Second constructor
                                    -> !FieldLabelString -- ^ Field name
                                    -> TcRnMessage

  {-| TcRnCommonFieldTypeMismatch is an error indicating that a sum type
    declares the same field name in multiple constructors, but their types
    differ.

    Test cases:
      CommonFieldTypeMismatch
  -}
  TcRnCommonFieldTypeMismatch :: !DataCon -- ^ First constructor
                              -> !DataCon -- ^ Second constructor
                              -> !FieldLabelString -- ^ Field name
                              -> TcRnMessage

  {-| TcRnClassExtensionDisabled is an error indicating that a class
    was declared with an extension feature while the extension was disabled.
  -}
  TcRnClassExtensionDisabled :: !Class -- ^ The class
                             -> !DisabledClassExtension -- ^ The extension
                             -> TcRnMessage

  {-| TcRnAssocNoClassTyVar is an error indicating that no class parameters
    are used in an associated type family.

    Test cases:
      T2888, T9167, T12867
  -}
  TcRnAssocNoClassTyVar :: !Class -- ^ The class
                        -> !TyCon -- ^ The associated family
                        -> TcRnMessage

  {-| TcRnDataConParentTypeMismatch is an error indicating that a data
    constructor was declared with a type that doesn't match its type
    constructor (i.e. a GADT result type and its data name).

    Test cases:
      T7175, T13300, T14719, T18357, T18357b, gadt11, tcfail155, tcfail176
  -}
  TcRnDataConParentTypeMismatch :: !DataCon -- ^ The data constructor
                                -> !Type -- ^ The parent type
                                -> TcRnMessage

  {-| TcRnGADTsDisabled is an error indicating that a GADT was declared
    while the extension GADTs was disabled.

    Test cases:
      ghci057, T9293
  -}
  TcRnGADTsDisabled :: !Name -- ^ The name of the GADT
                    -> TcRnMessage

  {-| TcRnExistentialQuantificationDisabled is an error indicating that
    a data constructor was declared with existential features while the
    extension ExistentialQuantification was disabled.

    Test cases:
      ghci057, T9293, gadtSyntaxFail001, gadtSyntaxFail002, gadtSyntaxFail003,
      prog006, rnfail053, T12083a
  -}
  TcRnExistentialQuantificationDisabled :: !DataCon -- ^ The constructor
                                        -> TcRnMessage

  {-| TcRnGADTDataContext is an error indicating that a GADT was declared with a
    data type context.
    This error is emitted in the tc, but it is also caught in the renamer.
  -}
  TcRnGADTDataContext :: !Name -- ^ The data type name
                      -> TcRnMessage

  {-| TcRnMultipleConForNewtype is an error indicating that a newtype was
    declared with multiple constructors.
    This error is caught by the parser.
  -}
  TcRnMultipleConForNewtype :: !Name -- ^ The newtype name
                            -> !Int -- ^ The number of constructors
                            -> TcRnMessage

  {-| TcRnKindSignaturesDisabled is an error indicating that a kind signature
    was used in a data type declaration while the extension KindSignatures was
    disabled.

    Test cases:
      T20873c, readFail036
  -}
  TcRnKindSignaturesDisabled :: !(Either (HsType GhcPs) (Name, HsType GhcRn))
                                -- ^ The data type name
                             -> TcRnMessage

  {-| TcRnEmptyDataDeclsDisabled is an error indicating that a data type
    was declared with no constructors while the extension EmptyDataDecls was
    disabled.

    Test cases:
      readFail035
  -}
  TcRnEmptyDataDeclsDisabled :: !Name -- ^ The data type name
                             -> TcRnMessage

  {-| TcRnFamilyCategoryMismatch is an error indicating that a family instance
    was declared for a family of a different kind, i.e. data vs type family.

    Test cases:
      T9896, SimpleFail3a
  -}
  TcRnFamilyCategoryMismatch :: !TyCon -- ^ The family tycon
                             -> TcRnMessage

  {-| TcRnFamilyArityMismatch is an error indicating that a family instance
    was declared with a different number of arguments than the family.
    See Note [Oversaturated type family equations] in "GHC.Tc.Validity".

    Test cases:
      TyFamArity1, TyFamArity2, T11136, Overlap4, AssocTyDef05, AssocTyDef06,
      T14110
  -}
  TcRnFamilyArityMismatch :: !TyCon -- ^ The family tycon
                          -> !Arity -- ^ The right number of parameters
                          -> TcRnMessage

  {-| TcRnRoleMismatch is an error indicating that the role specified
    in an annotation differs from its inferred role.

    Test cases:
      T7253, Roles11
  -}
  TcRnRoleMismatch :: !Name -- ^ The type variable
                   -> !Role -- ^ The annotated role
                   -> !Role -- ^ The inferred role
                   -> TcRnMessage

  {-| TcRnRoleCountMismatch is an error indicating that the number of
    roles in an annotation doesn't match the number of type parameters.

    Test cases:
      Roles6
  -}
  TcRnRoleCountMismatch :: !Int -- ^ The number of type variables
                        -> !(LRoleAnnotDecl GhcRn) -- ^ The role annotation
                        -> TcRnMessage

  {-| TcRnIllegalRoleAnnotation is an error indicating that a role
    annotation was attached to a decl that doesn't allow it.

    Test cases:
      Roles5
  -}
  TcRnIllegalRoleAnnotation :: !(RoleAnnotDecl GhcRn) -- ^ The role annotation
                            -> TcRnMessage

  {-| TcRnRoleAnnotationsDisabled is an error indicating that a role
    annotation was declared while the extension RoleAnnotations was disabled.

    Test cases:
      Roles5, TH_Roles1
  -}
  TcRnRoleAnnotationsDisabled :: !TyCon -- ^ The annotated type
                              -> TcRnMessage

  {-| TcRnIncoherentRoles is an error indicating that a role
    annotation for a class parameter was declared as not nominal.

    Test cases:
      T8773
  -}
  TcRnIncoherentRoles :: !TyCon -- ^ The class tycon
                      -> TcRnMessage

  {-| TcRnIncoherentRoles is an error indicating that a type family equation
    used a different name than the family.

    Test cases:
      Overlap5, T15362, T16002, T20260, T11623
  -}
  TcRnTyFamNameMismatch :: !Name -- ^ The family name
                        -> !Name -- ^ The name used in the equation
                        -> TcRnMessage

  {-| TcRnPrecedenceParsingError is an error caused by attempting to
      use operators with the same precedence in one infix expression.

      Example:
        eq :: (a ~ b ~ c) :~: ()

      Test cases: module/mod61
                  parser/should_fail/readFail016
                  rename/should_fail/rnfail017
                  rename/should_fail/T9077
                  typecheck/should_fail/T18252a
  -}
  TcRnPrecedenceParsingError
    :: (OpName, Fixity) -- ^ first operator's name and fixity
    -> (OpName, Fixity) -- ^ second operator's name and fixity
    -> TcRnMessage

  {-| TcRnPrecedenceParsingError is an error caused by attempting to
      use an operator with higher precedence than the operand.

      Example:
        k = (-3 **)
          where
                (**) = const
                infixl 7 **

      Test cases: overloadedrecflds/should_fail/T13132_duplicaterecflds
                  parser/should_fail/readFail023
                  rename/should_fail/rnfail019
                  th/TH_unresolvedInfix2
  -}
  TcRnSectionPrecedenceError
    :: (OpName, Fixity) -- ^ first operator's name and fixity
    -> (OpName, Fixity) -- ^ argument operator
    -> HsExpr GhcPs -- ^ Section
    -> TcRnMessage

  {-| TcRnTypeSynonymCycle is an error indicating that a cycle between type
    synonyms has occurred.

    Test cases:
      mod27, ghc-e-fail2, bkpfail29
  -}
  TcRnTypeSynonymCycle :: !TySynCycleTyCons -- ^ The tycons involved in the cycle
                       -> TcRnMessage

  {-| TcRnSelfImport is an error indicating that a module contains an
    import of itself.

    Test cases:
      T9032
  -}
  TcRnSelfImport :: !ModuleName -- ^ The module
                 -> TcRnMessage

  {-| TcRnNoExplicitImportList is a warning indicating that an import
      statement did not include an explicit import list.

    Test cases:
      T1789, T4489
  -}
  TcRnNoExplicitImportList :: !ModuleName -- ^ The imported module
                           -> TcRnMessage

  {-| TcRnSafeImportsDisabled is an error indicating that an import was
    declared using the @safe@ keyword while SafeHaskell wasn't active.

    Test cases:
      Mixed01
  -}
  TcRnSafeImportsDisabled :: !ModuleName -- ^ The imported module
                           -> TcRnMessage

  {-| TcRnDeprecatedModule is a warning indicating that an imported module
    is annotated with a warning or deprecation pragma.

    Test cases:
      DeprU
  -}
  TcRnDeprecatedModule :: !ModuleName -- ^ The imported module
                       -> !(WarningTxt GhcRn) -- ^ The pragma data
                       -> TcRnMessage

  {-| TcRnCompatUnqualifiedImport is a warning indicating that a special
    module (right now only Data.List) was imported unqualified without
    import list, for compatibility reasons.

    Test cases:
      T17244A
  -}
  TcRnCompatUnqualifiedImport :: !(ImportDecl GhcPs) -- ^ The import
                              -> TcRnMessage

  {-| TcRnRedundantSourceImport is a warning indicating that a {-# SOURCE #-}
    import was used when there is no import cycle.

    Test cases:
      none
  -}
  TcRnRedundantSourceImport :: !ModuleName -- ^ The imported module
                            -> TcRnMessage

  {-| TcRnImportLookup is a group of errors about bad imported names.
  -}
  TcRnImportLookup :: !ImportLookupReason -- ^ Details about the error
                   -> TcRnMessage

  {-| TcRnUnusedImport is a group of errors about unused imports.
  -}
  TcRnUnusedImport :: !(ImportDecl GhcRn) -- ^ The import
                   -> !UnusedImportReason -- ^ Details about the error
                   -> TcRnMessage

  {-| TcRnDuplicateDecls is an error indicating that the same name was used for
    multiple declarations.

    Test cases:
      FieldSelectors, overloadedrecfldsfail03, T17965, NFSDuplicate, T9975a,
      TDMultiple01, mod19, mod38, mod21, mod66, mod20, TDPunning, mod18, mod22,
      TDMultiple02, T4127a, ghci048, T8932, rnfail015, rnfail010, rnfail011,
      rnfail013, rnfail002, rnfail003, rn_dup, rnfail009, T7164, rnfail043,
      TH_dupdecl, rnfail012
  -}
  TcRnDuplicateDecls :: !OccName -- ^ The name of the declarations
                     -> !(NE.NonEmpty Name) -- ^ The individual declarations
                     -> TcRnMessage

  {-| TcRnPackageImportsDisabled is an error indicating that an import uses
    a package qualifier while the extension PackageImports was disabled.

    Test cases:
      PackageImportsDisabled
  -}
  TcRnPackageImportsDisabled :: TcRnMessage

  {-| TcRnIllegalDataCon is an error indicating that a data constructor was
    defined using a lowercase name, or a symbolic name in prefix position.
    Mostly caught by PsErrNotADataCon.

    Test cases:
      None
  -}
  TcRnIllegalDataCon :: !RdrName -- ^ The constructor name
                     -> TcRnMessage

  {-| TcRnNestedForallsContexts is an error indicating that multiple foralls or
    contexts are nested/curried where this is not supported,
    like @∀ x. ∀ y.@ instead of @∀ x y.@.

    Test cases:
      T12087, T14320, T16114, T16394, T16427, T18191, T18240a, T18240b, T18455, T5951
  -}
  TcRnNestedForallsContexts :: !NestedForallsContextsIn -> TcRnMessage

  {-| TcRnRedundantRecordWildcard is a warning indicating that a pattern uses
    a record wildcard even though all of the record's fields are bound explicitly.

    Test cases:
      T15957_Fail
  -}
  TcRnRedundantRecordWildcard :: TcRnMessage

  {-| TcRnUnusedRecordWildcard is a warning indicating that a pattern uses
    a record wildcard while none of the fields bound by it are used.

    Test cases:
      T15957_Fail
  -}
  TcRnUnusedRecordWildcard :: ![Name] -- ^ The names bound by the wildcard
                           -> TcRnMessage

  {-| TcRnUnusedName is a warning indicating that a defined or imported name
    is not used in the module.

    Test cases:
      ds053, mc10, overloadedrecfldsfail05, overloadedrecfldsfail06, prog018,
      read014, rn040, rn041, rn047, rn063, T13839, T13839a, T13919, T17171b,
      T17a, T17b, T17d, T17e, T18470, T1972, t22391, t22391j, T2497, T3371,
      T3449, T7145b, T7336, TH_recover_warns, unused_haddock, WarningGroups,
      werror
  -}
  TcRnUnusedName :: !OccName -- ^ The unused name
                 -> !UnusedNameProv -- ^ The provenance of the name
                 -> TcRnMessage

  {-| TcRnQualifiedBinder is an error indicating that a qualified name
    was used in binding position.

    Test cases:
      mod62, rnfail021, rnfail034, rnfail039, rnfail046
  -}
  TcRnQualifiedBinder :: !RdrName -- ^ The name used as a binder
                      -> TcRnMessage

  {-| TcRnTypeApplicationsDisabled is an error indicating that a type
    application was used while the extension TypeApplications was disabled.

    Test cases:
      T12411, T12446, T15527, T16133, T18251c
  -}
  TcRnTypeApplicationsDisabled :: !TypeOrKind -- ^ Type or kind application
                               -> !(HsType GhcPs) -- ^ The type being applied
                               -> TcRnMessage

  {-| TcRnInvalidRecordField is an error indicating that a record field was
    used that doesn't exist in a constructor.

    Test cases:
      T13644, T13847, T17469, T8448, T8570, tcfail083, tcfail084
  -}
  TcRnInvalidRecordField :: !Name -- ^ The constructor name
                         -> !FieldLabelString -- ^ The name of the field
                         -> TcRnMessage

  {-| TcRnTupleTooLarge is an error indicating that the arity of a tuple
    exceeds mAX_TUPLE_SIZE.

    Test cases:
      T18723a, T18723b, T18723c, T6148a, T6148b, T6148c, T6148d
  -}
  TcRnTupleTooLarge :: !Int -- ^ The arity of the tuple
                    -> TcRnMessage

  {-| TcRnCTupleTooLarge is an error indicating that the arity of a constraint
    tuple exceeds mAX_CTUPLE_SIZE.

    Test cases:
      T10451
  -}
  TcRnCTupleTooLarge :: !Int -- ^ The arity of the constraint tuple
                     -> TcRnMessage

  {-| TcRnIllegalInferredTyVars is an error indicating that some type variables
    were quantified as inferred (like @∀ {a}.@) in a place where this is not
    allowed, like in an instance declaration.

    Test cases:
      ExplicitSpecificity5, ExplicitSpecificity6, ExplicitSpecificity8,
      ExplicitSpecificity9
  -}
  TcRnIllegalInferredTyVars :: !(NE.NonEmpty (HsTyVarBndr Specificity GhcPs))
                              -- ^ The offending type variables
                           -> TcRnMessage

  {-| TcRnAmbiguousName is an error indicating that an unbound name
    might refer to multiple names in scope.

    Test cases:
      BootFldReexport, DRFUnused, duplicaterecfldsghci01, GHCiDRF, mod110,
      mod151, mod152, mod153, mod164, mod165, NoFieldSelectorsFail,
      overloadedrecfldsfail02, overloadedrecfldsfail04, overloadedrecfldsfail11,
      overloadedrecfldsfail12, overloadedrecfldsfail13,
      overloadedrecfldswasrunnowfail06, rnfail044, T11167_ambig,
      T11167_ambiguous_fixity, T13132_duplicaterecflds, T15487, T16745, T17420,
      T18999_NoDisambiguateRecordFields, T19397E1, T19397E2, T23010_fail,
      tcfail037
  -}
  TcRnAmbiguousName :: !GlobalRdrEnv
                    -> !RdrName -- ^ The name
                    -> !(NE.NonEmpty GlobalRdrElt) -- ^ The possible matches
                    -> TcRnMessage

  {-| TcRnBindingNameConflict is an error indicating that multiple local or
    top-level bindings have the same name.

    Test cases:
      dsrun006, mdofail002, mdofail003, mod23, mod24, qq006, rnfail001,
      rnfail004, SimpleFail6, T14114, T16110_Fail1, tcfail038, TH_spliceD1
  -}
  TcRnBindingNameConflict :: !RdrName -- ^ The conflicting name
                          -> !(NE.NonEmpty SrcSpan)
                             -- ^ The locations of the duplicates
                          -> TcRnMessage

  {-| TcRnNonCanonicalDefinition is a warning indicating that an instance
    defines an implementation for a method that should not be defined in a way
    that deviates from its default implementation, for example because it has
    been scheduled to be absorbed into another method, like @pure@ making
    @return@ obsolete.

    Test cases:
      WCompatWarningsOn, WCompatWarningsOff, WCompatWarningsOnOff
  -}
  TcRnNonCanonicalDefinition :: !NonCanonicalDefinition -- ^ Specifics
                             -> !(LHsSigType GhcRn) -- ^ The instance type
                             -> TcRnMessage
  {-| TcRnImplicitImportOfPrelude is a warning, controlled by @Wimplicit-prelude@,
      that is triggered upon an implicit import of the @Prelude@ module.

      Example:

        {-# OPTIONS_GHC -fwarn-implicit-prelude #-}
        module M where {}

      Test case: rn055

  -}
  TcRnImplicitImportOfPrelude :: TcRnMessage

  {-| TcRnMissingMain is an error that occurs when a Main module does
      not define a main function (named @main@ by default, but overridable
      with the @main-is@ command line flag).

      Example:

        module Main where {}

      Test cases:
        T414, T7765, readFail021, rnfail007, T13839b, T17171a, T16453E1, tcfail030,
        T19397E3, T19397E4

  -}
  TcRnMissingMain
    :: !Bool -- ^ whether the module has an explicit export list
    -> !Module
    -> !OccName -- ^ the expected name of the main function
    -> TcRnMessage

  {-| TcRnGhciUnliftedBind is an error that occurs when a user attempts to
      bind an unlifted value in GHCi.

      Example (in GHCi):

        let a = (# 1#, 3# #)

      Test cases: T9140, T19035b
  -}
  TcRnGhciUnliftedBind :: !Id -> TcRnMessage

  {-| TcRnGhciMonadLookupFail is an error that occurs when the user sets
      the GHCi monad, using the GHC API 'setGHCiMonad' function, but GHC
      can't find which monad the user is referring to.

      Example:

        import GHC ( setGHCiMonad )

        ... setGHCiMonad "NoSuchThing"

      Test cases: none
  -}
  TcRnGhciMonadLookupFail
    :: String -- ^ the textual name of the monad requested by the user
    -> Maybe [GlobalRdrElt] -- ^ lookup result
    -> TcRnMessage

  deriving Generic

-- | Things forbidden in @type data@ declarations.
-- See Note [Type data declarations]
data TypeDataForbids
  = TypeDataForbidsDatatypeContexts
  | TypeDataForbidsLabelledFields
  | TypeDataForbidsStrictnessAnnotations
  | TypeDataForbidsDerivingClauses
  deriving Generic

instance Outputable TypeDataForbids where
  ppr TypeDataForbidsDatatypeContexts      = text "Data type contexts"
  ppr TypeDataForbidsLabelledFields        = text "Labelled fields"
  ppr TypeDataForbidsStrictnessAnnotations = text "Strictness flags"
  ppr TypeDataForbidsDerivingClauses       = text "Deriving clauses"

data RunSpliceFailReason
  = ConversionFail !ThingBeingConverted !ConversionFailReason
  deriving Generic

-- | Identifies the TH splice attempting to be converted
data ThingBeingConverted
  = ConvDec !TH.Dec
  | ConvExp !TH.Exp
  | ConvPat !TH.Pat
  | ConvType !TH.Type

-- | The reason a TH splice could not be converted to a Haskell expression
data ConversionFailReason
  = IllegalOccName !OccName.NameSpace !String
  | SumAltArityExceeded !TH.SumAlt !TH.SumArity
  | IllegalSumAlt !TH.SumAlt
  | IllegalSumArity !TH.SumArity
  | MalformedType !TypeOrKind !TH.Type
  | IllegalLastStatement !HsDoFlavour !(LStmt GhcPs (LHsExpr GhcPs))
  | KindSigsOnlyAllowedOnGADTs
  | IllegalDeclaration !THDeclDescriptor !IllegalDecls
  | CannotMixGADTConsWith98Cons
  | EmptyStmtListInDoBlock
  | NonVarInInfixExpr
  | MultiWayIfWithoutAlts
  | CasesExprWithoutAlts
  | ImplicitParamsWithOtherBinds
  | InvalidCCallImpent !String -- ^ Source
  | RecGadtNoCons
  | GadtNoCons
  | InvalidTypeInstanceHeader !TH.Type
  | InvalidTyFamInstLHS !TH.Type
  | InvalidImplicitParamBinding
  | DefaultDataInstDecl ![LDataFamInstDecl GhcPs]
  | FunBindLacksEquations !TH.Name
  deriving Generic

data IllegalDecls
  = IllegalDecls    !(NE.NonEmpty (LHsDecl GhcPs))
  | IllegalFamDecls !(NE.NonEmpty (LFamilyDecl GhcPs))

-- | Label for a TH declaration
data THDeclDescriptor
  = InstanceDecl
  | WhereClause
  | LetBinding
  | LetExpression
  | ClssDecl

-- | Specifies which back ends can handle a requested foreign import or export
type ExpectedBackends = [Backend]

-- | Specifies which calling convention is unsupported on the current platform
data UnsupportedCallConvention
  = StdCallConvUnsupported
  | PrimCallConvUnsupported
  | JavaScriptCallConvUnsupported
  deriving Eq

-- | Whether the error pertains to a function argument or a result.
data ArgOrResult
  = Arg | Result

-- | Which parts of a record field are affected by a particular error or warning.
data RecordFieldPart
  = RecordFieldDecl !Name
  | RecordFieldConstructor !Name
  | RecordFieldPattern !Name
  | RecordFieldUpdate

-- | Why did we reject a record update?
data BadRecordUpdateReason
   -- | No constructor has all of the required fields.
   = NoConstructorHasAllFields
       { conflictingFields :: [FieldLabelString] }

   -- | There are several possible parents which have all of the required fields,
   -- and we weren't able to disambiguate in any way.
   | MultiplePossibleParents
       (RecSelParent, RecSelParent, [RecSelParent])
         -- ^ The possible parents (at least 2)

   -- | We used type-directed disambiguation, but this resulted in
   -- an invalid parent (the type-directed parent is not among the
   -- parents we computed from the field labels alone).
   | InvalidTyConParent TyCon (NE.NonEmpty RecSelParent)

  deriving Generic

-- | Where a shadowed name comes from
data ShadowedNameProvenance
  = ShadowedNameProvenanceLocal !SrcLoc
    -- ^ The shadowed name is local to the module
  | ShadowedNameProvenanceGlobal [GlobalRdrElt]
    -- ^ The shadowed name is global, typically imported from elsewhere.

-- | In what context did we require a type to have a fixed runtime representation?
--
-- Used by 'GHC.Tc.Utils.TcMType.checkTypeHasFixedRuntimeRep' for throwing
-- representation polymorphism errors when validity checking.
--
-- See Note [Representation polymorphism checking] in GHC.Tc.Utils.Concrete
data FixedRuntimeRepProvenance
  -- | Data constructor fields must have a fixed runtime representation.
  --
  -- Tests: T11734, T18534.
  = FixedRuntimeRepDataConField

  -- | Pattern synonym signature arguments must have a fixed runtime representation.
  --
  -- Test: RepPolyPatSynArg.
  | FixedRuntimeRepPatSynSigArg

  -- | Pattern synonym signature scrutinee must have a fixed runtime representation.
  --
  -- Test: RepPolyPatSynRes.
  | FixedRuntimeRepPatSynSigRes

pprFixedRuntimeRepProvenance :: FixedRuntimeRepProvenance -> SDoc
pprFixedRuntimeRepProvenance FixedRuntimeRepDataConField = text "data constructor field"
pprFixedRuntimeRepProvenance FixedRuntimeRepPatSynSigArg = text "pattern synonym argument"
pprFixedRuntimeRepProvenance FixedRuntimeRepPatSynSigRes = text "pattern synonym scrutinee"

-- | Why the particular illegal newtype error arose together with more
-- information, if any.
data IllegalNewtypeReason
  = DoesNotHaveSingleField !Int
  | IsNonLinear
  | IsGADT
  | HasConstructorContext
  | HasExistentialTyVar
  | HasStrictnessAnnotation
  deriving Generic

-- | Why the particular injectivity error arose together with more information,
-- if any.
data InjectivityErrReason
  = InjErrRhsBareTyVar [Type]
  | InjErrRhsCannotBeATypeFam
  | InjErrRhsOverlap
  | InjErrCannotInferFromRhs !TyVarSet !HasKinds !SuggestUndecidableInstances

data HasKinds
  = YesHasKinds
  | NoHasKinds
  deriving (Show, Eq)

hasKinds :: Bool -> HasKinds
hasKinds True  = YesHasKinds
hasKinds False = NoHasKinds

data SuggestUndecidableInstances
  = YesSuggestUndecidableInstaces
  | NoSuggestUndecidableInstaces
  deriving (Show, Eq)

suggestUndecidableInstances :: Bool -> SuggestUndecidableInstances
suggestUndecidableInstances True  = YesSuggestUndecidableInstaces
suggestUndecidableInstances False = NoSuggestUndecidableInstaces

data SuggestUnliftedTypes
  = SuggestUnliftedNewtypes
  | SuggestUnliftedDatatypes

-- | A description of whether something is a
--
-- * @data@ or @newtype@ ('DataDeclSort')
--
-- * @data instance@ or @newtype instance@ ('DataInstanceSort')
--
-- * @data family@ ('DataFamilySort')
--
-- At present, this data type is only consumed by 'checkDataKindSig'.
data DataSort
  = DataDeclSort     NewOrData
  | DataInstanceSort NewOrData
  | DataFamilySort

ppDataSort :: DataSort -> SDoc
ppDataSort data_sort = text $
  case data_sort of
    DataDeclSort     DataType -> "Data type"
    DataDeclSort     NewType  -> "Newtype"
    DataInstanceSort DataType -> "Data instance"
    DataInstanceSort NewType  -> "Newtype instance"
    DataFamilySort            -> "Data family"

-- | Helper type used in 'checkDataKindSig'.
--
-- Superficially similar to 'ContextKind', but it lacks 'AnyKind'
-- and 'AnyBoxedKind', and instead of @'TheKind' liftedTypeKind@
-- provides 'LiftedKind', which is much simpler to match on and
-- handle in 'isAllowedDataResKind'.
data AllowedDataResKind
  = AnyTYPEKind
  | AnyBoxedKind
  | LiftedKind

-- | A data type to describe why a variable is not closed.
-- See Note [Not-closed error messages] in GHC.Tc.Gen.Expr
data NotClosedReason = NotLetBoundReason
                     | NotTypeClosed VarSet
                     | NotClosed Name NotClosedReason

data SuggestPartialTypeSignatures
  = YesSuggestPartialTypeSignatures
  | NoSuggestPartialTypeSignatures
  deriving (Show, Eq)

suggestPartialTypeSignatures :: Bool -> SuggestPartialTypeSignatures
suggestPartialTypeSignatures True  = YesSuggestPartialTypeSignatures
suggestPartialTypeSignatures False = NoSuggestPartialTypeSignatures

data UsingGeneralizedNewtypeDeriving
  = YesGeneralizedNewtypeDeriving
  | NoGeneralizedNewtypeDeriving
  deriving Eq

usingGeneralizedNewtypeDeriving :: Bool -> UsingGeneralizedNewtypeDeriving
usingGeneralizedNewtypeDeriving True  = YesGeneralizedNewtypeDeriving
usingGeneralizedNewtypeDeriving False = NoGeneralizedNewtypeDeriving

data DeriveAnyClassEnabled
  = YesDeriveAnyClassEnabled
  | NoDeriveAnyClassEnabled
  deriving Eq

deriveAnyClassEnabled :: Bool -> DeriveAnyClassEnabled
deriveAnyClassEnabled True  = YesDeriveAnyClassEnabled
deriveAnyClassEnabled False = NoDeriveAnyClassEnabled

-- | Why a particular typeclass instance couldn't be derived.
data DeriveInstanceErrReason
  =
    -- | The typeclass instance is not well-kinded.
    DerivErrNotWellKinded !TyCon
                          -- ^ The type constructor that occurs in
                          -- the typeclass instance declaration.
                          !Kind
                          -- ^ The typeclass kind.
                          !Int
                          -- ^ The number of typeclass arguments that GHC
                          -- kept. See Note [tc_args and tycon arity] in
                          -- GHC.Tc.Deriv.
  -- | Generic instances can only be derived using the stock strategy
  -- in Safe Haskell.
  | DerivErrSafeHaskellGenericInst
  | DerivErrDerivingViaWrongKind !Kind !Type !Kind
  | DerivErrNoEtaReduce !Type
                        -- ^ The instance type
  -- | We cannot derive instances in boot files
  | DerivErrBootFileFound
  | DerivErrDataConsNotAllInScope !TyCon
  -- | We cannot use GND on non-newtype types
  | DerivErrGNDUsedOnData
  -- | We cannot derive instances of nullary classes
  | DerivErrNullaryClasses
  -- | Last arg must be newtype or data application
  | DerivErrLastArgMustBeApp
  | DerivErrNoFamilyInstance !TyCon [Type]
  | DerivErrNotStockDeriveable !DeriveAnyClassEnabled
  | DerivErrHasAssociatedDatatypes !HasAssociatedDataFamInsts
                                   !AssociatedTyLastVarInKind
                                   !AssociatedTyNotParamOverLastTyVar
  | DerivErrNewtypeNonDeriveableClass
  | DerivErrCannotEtaReduceEnough !Bool -- Is eta-reduction OK?
  | DerivErrOnlyAnyClassDeriveable !TyCon
                                   -- ^ Type constructor for which the instance
                                   -- is requested
                                   !DeriveAnyClassEnabled
                                   -- ^ Whether or not -XDeriveAnyClass is enabled
                                   -- already.
  -- | Stock deriving won't work, but perhaps DeriveAnyClass will.
  | DerivErrNotDeriveable !DeriveAnyClassEnabled
  -- | The given 'PredType' is not a class.
  | DerivErrNotAClass !PredType
  -- | The given (representation of the) 'TyCon' has no
  -- data constructors.
  | DerivErrNoConstructors !TyCon
  | DerivErrLangExtRequired !LangExt.Extension
  -- | GHC simply doesn't how to how derive the input 'Class' for the given
  -- 'Type'.
  | DerivErrDunnoHowToDeriveForType !Type
  -- | The given 'TyCon' must be an enumeration.
  -- See Note [Enumeration types] in GHC.Core.TyCon
  | DerivErrMustBeEnumType !TyCon
  -- | The given 'TyCon' must have /precisely/ one constructor.
  | DerivErrMustHaveExactlyOneConstructor !TyCon
  -- | The given data type must have some parameters.
  | DerivErrMustHaveSomeParameters !TyCon
  -- | The given data type must not have a class context.
  | DerivErrMustNotHaveClassContext !TyCon !ThetaType
  -- | We couldn't derive an instance for a particular data constructor
  -- for a variety of reasons.
  | DerivErrBadConstructor !(Maybe HasWildcard) [DeriveInstanceBadConstructor]
  -- | We couldn't derive a 'Generic' instance for the given type for a
  -- variety of reasons
  | DerivErrGenerics [DeriveGenericsErrReason]
  -- | We couldn't derive an instance either because the type was not an
  -- enum type or because it did have more than one constructor.
  | DerivErrEnumOrProduct !DeriveInstanceErrReason !DeriveInstanceErrReason
  deriving Generic

data DeriveInstanceBadConstructor
  =
  -- | The given 'DataCon' must be truly polymorphic in the
  -- last argument of the data type.
    DerivErrBadConExistential !DataCon
  -- | The given 'DataCon' must not use the type variable in a function argument"
  | DerivErrBadConCovariant !DataCon
  -- | The given 'DataCon' must not contain function types
  | DerivErrBadConFunTypes !DataCon
  -- | The given 'DataCon' must use the type variable only
  -- as the last argument of a data type
  | DerivErrBadConWrongArg !DataCon
  -- | The given 'DataCon' is a GADT so we cannot directly
  -- derive an istance for it.
  | DerivErrBadConIsGADT !DataCon
  -- | The given 'DataCon' has existentials type vars in its type.
  | DerivErrBadConHasExistentials !DataCon
  -- | The given 'DataCon' has constraints in its type.
  | DerivErrBadConHasConstraints !DataCon
  -- | The given 'DataCon' has a higher-rank type.
  | DerivErrBadConHasHigherRankType !DataCon

data DeriveGenericsErrReason
  = -- | The type must not have some datatype context.
    DerivErrGenericsMustNotHaveDatatypeContext !TyCon
    -- | The data constructor must not have exotic unlifted
    -- or polymorphic arguments.
  | DerivErrGenericsMustNotHaveExoticArgs !DataCon
    -- | The data constructor must be a vanilla constructor.
  | DerivErrGenericsMustBeVanillaDataCon  !DataCon
    -- | The type must have some type parameters.
    -- check (d) from Note [Requirements for deriving Generic and Rep]
    -- in GHC.Tc.Deriv.Generics.
  | DerivErrGenericsMustHaveSomeTypeParams !TyCon
    -- | The data constructor must not have existential arguments.
  | DerivErrGenericsMustNotHaveExistentials !DataCon
    -- | The derivation applies a type to an argument involving
    -- the last parameter but the applied type is not of kind * -> *.
  | DerivErrGenericsWrongArgKind !DataCon

data HasWildcard
  = YesHasWildcard
  | NoHasWildcard
  deriving Eq

hasWildcard :: Bool -> HasWildcard
hasWildcard True  = YesHasWildcard
hasWildcard False = NoHasWildcard

-- | A context in which we don't allow anonymous wildcards.
data BadAnonWildcardContext
  = WildcardNotLastInConstraint
  | ExtraConstraintWildcardNotAllowed
      SoleExtraConstraintWildcardAllowed
  | WildcardsNotAllowedAtAll

-- | Whether a sole extra-constraint wildcard is allowed,
-- e.g. @_ => ..@ as opposed to @( .., _ ) => ..@.
data SoleExtraConstraintWildcardAllowed
  = SoleExtraConstraintWildcardNotAllowed
  | SoleExtraConstraintWildcardAllowed

-- | A type representing whether or not the input type has associated data family instances.
data HasAssociatedDataFamInsts
  = YesHasAdfs
  | NoHasAdfs
  deriving Eq

hasAssociatedDataFamInsts :: Bool -> HasAssociatedDataFamInsts
hasAssociatedDataFamInsts True = YesHasAdfs
hasAssociatedDataFamInsts False = NoHasAdfs

-- | If 'YesAssocTyLastVarInKind', the associated type of a typeclass
-- contains the last type variable of the class in a kind, which is not (yet) allowed
-- by GHC.
data AssociatedTyLastVarInKind
  = YesAssocTyLastVarInKind !TyCon -- ^ The associated type family of the class
  | NoAssocTyLastVarInKind
  deriving Eq

associatedTyLastVarInKind :: Maybe TyCon -> AssociatedTyLastVarInKind
associatedTyLastVarInKind (Just tc) = YesAssocTyLastVarInKind tc
associatedTyLastVarInKind Nothing   = NoAssocTyLastVarInKind

-- | If 'NoAssociatedTyNotParamOverLastTyVar', the associated type of a
-- typeclass is not parameterized over the last type variable of the class
data AssociatedTyNotParamOverLastTyVar
  = YesAssociatedTyNotParamOverLastTyVar !TyCon -- ^ The associated type family of the class
  | NoAssociatedTyNotParamOverLastTyVar
  deriving Eq

associatedTyNotParamOverLastTyVar :: Maybe TyCon -> AssociatedTyNotParamOverLastTyVar
associatedTyNotParamOverLastTyVar (Just tc) = YesAssociatedTyNotParamOverLastTyVar tc
associatedTyNotParamOverLastTyVar Nothing   = NoAssociatedTyNotParamOverLastTyVar

-- | What kind of thing is missing a type signature?
--
-- Used for reporting @"missing signature"@ warnings, see
-- 'tcRnMissingSignature'.
data MissingSignature
  = MissingTopLevelBindingSig Name Type
  | MissingPatSynSig PatSyn
  | MissingTyConKindSig
      TyCon
      Bool -- ^ whether -XCUSKs is enabled

-- | Is the object we are dealing with exported or not?
--
-- Used for reporting @"missing signature"@ warnings, see
-- 'TcRnMissingSignature'.
data Exported
  = IsNotExported
  | IsExported

instance Outputable Exported where
  ppr IsNotExported = text "IsNotExported"
  ppr IsExported    = text "IsExported"

-- | What declarations were not allowed in an hs-boot or hsig file?
data BadBootDecls
  = BootBindsPs      !(NE.NonEmpty (LHsBindLR GhcRn GhcPs))
  | BootBindsRn      !(NE.NonEmpty (LHsBindLR GhcRn GhcRn))
  | BootInstanceSigs !(NE.NonEmpty (LSig GhcRn))
  | BootFamInst      !TyCon
  | BootSpliceDecls  !(NE.NonEmpty (LocatedA (HsUntypedSplice GhcPs)))
  | BootForeignDecls !(NE.NonEmpty (LForeignDecl GhcRn))
  | BootDefaultDecls !(NE.NonEmpty (LDefaultDecl GhcRn))
  | BootRuleDecls    !(NE.NonEmpty (LRuleDecls GhcRn))

-- | A mismatch between an hs-boot or signature file and its implementing module.
data BootMismatch
  -- | Something defined or exported by an hs-boot or signature file
  -- is missing from the implementing module.
  = MissingBootThing !Name !MissingBootThing

  -- | A typeclass instance is declared in the hs-boot file but
  -- it is not present in the implementing module.
  | MissingBootInstance !DFunId -- ^ the boot instance 'DFunId'
    -- NB: we never trigger this for hsig files, as in that case we do
    -- a full round of constraint solving, and a missing instance gets reported
    -- as an unsolved Wanted constraint with a 'InstProvidedOrigin' 'CtOrigin'.
    -- See GHC.Tc.Utils.Backpack.check_inst.

  -- | A mismatch between an hsig file and its implementing module
  -- in the 'Name' that a particular re-export refers to.
  | BadReexportedBootThing !Name !Name

  -- | A mismatch between the declaration of something in the hs-boot or
  -- signature file and its implementation, e.g. a type mismatch or
  -- a type family implemented as a class.
  | BootMismatch
      !TyThing -- ^ boot thing
      !TyThing -- ^ real thing
      !BootMismatchWhat
  deriving Generic

-- | Something from the hs-boot or signature file is missing from the
-- implementing module.
data MissingBootThing
  -- | Something defined in the hs-boot or signature file is not defined in the
  -- implementing module.
  = MissingBootDefinition
  -- | Something exported by the hs-boot or signature file is not exported by the
  -- implementing module.
  | MissingBootExport
  deriving Generic

missingBootThing :: HsBootOrSig -> Name -> MissingBootThing -> TcRnMessage
missingBootThing src nm thing =
  TcRnBootMismatch src (MissingBootThing nm thing)

-- | A mismatch of two 'TyThing's between an hs-boot or signature file
-- and its implementing module.
data BootMismatchWhat
  -- | The 'Id's have different types.
  = BootMismatchedIdTypes !Id -- ^ boot 'Id'
                          !Id -- ^ real 'Id'
  -- | Two 'TyCon's aren't compatible.
  | BootMismatchedTyCons !TyCon -- ^ boot 'TyCon'
                         !TyCon -- ^ real 'TyCon'
                         !(NE.NonEmpty BootTyConMismatch)
  deriving Generic

-- | An error in the implementation of an abstract datatype using
-- a type synonym.
data SynAbstractDataError
  -- | The type synony was not nullary.
  = SynAbsDataTySynNotNullary
  -- | The type synonym RHS contained invalid types, e.g.
  -- a type family or a forall.
  | SynAbstractDataInvalidRHS !(NE.NonEmpty Type)

-- | Mismatched implementation of a 'TyCon' in an hs-boot or signature file.
data BootTyConMismatch
  -- | The 'TyCon' kinds differ.
  = TyConKindMismatch
  -- | The 'TyCon' 'Role's aren't compatible.
  | TyConRoleMismatch !Bool -- ^ True <=> role subtype check
  -- | Two type synonyms have different RHSs.
  | TyConSynonymMismatch !Kind !Kind
  -- | The two 'TyCon's are of a different flavour, e.g. one is
  -- a data family and the other is a type family.
  | TyConFlavourMismatch !FamTyConFlav !FamTyConFlav
  -- | The equations of a type family don't match.
  | TyConAxiomMismatch !(BootListMismatches CoAxBranch BootAxiomBranchMismatch)
  -- | The type family injectivity annotations don't match.
  | TyConInjectivityMismatch
  -- | The 'TyCon's are both datatype 'TyCon's, but they have diferent 'DataCon's.
  | TyConMismatchedData !AlgTyConRhs !AlgTyConRhs !BootDataMismatch
  -- | The 'TyCon's are both 'Class' 'TyCon's, but the classes don't match.
  | TyConMismatchedClasses !Class !Class !BootClassMismatch
  -- | The 'TyCon's are something completely different.
  | TyConsVeryDifferent
  -- | An abstract 'TyCon' is implemented using a type synonym in an invalid
  -- manner. See 'SynAbstractDataError'.
  | SynAbstractData !SynAbstractDataError


-- | Utility datatype to record errors when checking compatibity
-- between two lists of things, e.g. class methods, associated types,
-- type family equations, etc.
data BootListMismatch item err
  -- | Different number of items.
  = MismatchedLength
  -- | The item at the given position in the list differs.
  | MismatchedThing !Int !item !item !err

type BootListMismatches item err =
  NE.NonEmpty (BootListMismatch item err)

data BootAxiomBranchMismatch
  -- | The quantified variables in an equation don't match.
  --
  -- Example: the quantification of @a@ in
  --
  --   @type family F a where { forall a. F a = Maybe a }@
  = MismatchedAxiomBinders
  -- | The LHSs of an equation don't match.
  | MismatchedAxiomLHS
  -- | The RHSs of an equation don't match.
  | MismatchedAxiomRHS

-- | A mismatch in a class, between its declaration in an hs-boot or signature
-- file, and its implementation in a source Haskell file.
data BootClassMismatch
  -- | The class methods don't match.
  = MismatchedMethods !(BootListMismatches ClassOpItem BootMethodMismatch)
  -- | The associated types don't match.
  | MismatchedATs !(BootListMismatches ClassATItem BootATMismatch)
  -- | The functional dependencies don't match.
  | MismatchedFunDeps
  -- | The superclasses don't match.
  | MismatchedSuperclasses
  -- | The @MINIMAL@ pragmas are not compatible.
  | MismatchedMinimalPragmas

-- | A mismatch in a class method, between its declaration in an hs-boot or signature
-- file, and its implementation in a source Haskell file.
data BootMethodMismatch
  -- | The class method names are different.
  = MismatchedMethodNames
  -- | The types of a class method are different.
  | MismatchedMethodTypes !Type !Type
  -- | The default method types are not compatible.
  | MismatchedDefaultMethods !Bool -- ^ True <=> subtype check

-- | A mismatch in an associated type of a class, between its declaration
-- in an hs-boot or signature file, and its implementation in a source Haskell file.
data BootATMismatch
  -- | Two associated types don't match.
  = MismatchedTyConAT !BootTyConMismatch
  -- | Two associated type defaults don't match.
  | MismatchedATDefaultType

-- | A mismatch in a datatype declaration, between an hs-boot file or signature
-- file and its implementing module.
data BootDataMismatch
  -- | A datatype is implemented as a newtype or vice-versa.
  = MismatchedNewtypeVsData
  -- | The constructors don't match.
  | MismatchedConstructors !(BootListMismatches DataCon BootDataConMismatch)
  -- | The datatype contexts differ.
  | MismatchedDatatypeContexts

-- | A mismatch in a data constrcutor, between its declaration in an hs-boot
-- file or signature file, and its implementation in a source Haskell module.
data BootDataConMismatch
  -- | The 'Name's of the 'DataCon's differ.
  = MismatchedDataConNames
  -- | The fixities of the 'DataCon's differ.
  | MismatchedDataConFixities
  -- | The strictness annotations of the 'DataCon's differ.
  | MismatchedDataConBangs
  -- | The 'DataCon's have different field labels.
  | MismatchedDataConFieldLabels
  -- | The 'DataCon's have incompatible types.
  | MismatchedDataConTypes

--------------------------------------------------------------------------------
--
--     Errors used in GHC.Tc.Errors
--
--------------------------------------------------------------------------------

{- Note [Error report]
~~~~~~~~~~~~~~~~~~~~~~
The idea is that error msgs are divided into three parts: the main msg, the
context block ("In the second argument of ..."), and the relevant bindings
block, which are displayed in that order, with a mark to divide them. The
the main msg ('report_important') varies depending on the error
in question, but context and relevant bindings are always the same, which
should simplify visual parsing.

See 'GHC.Tc.Errors.Types.SolverReport' and 'GHC.Tc.Errors.mkErrorReport'.
-}

-- | A collection of main error messages and supplementary information.
--
-- In practice, we will:
--  - display the important messages first,
--  - then the error context (e.g. by way of a call to 'GHC.Tc.Errors.mkErrorReport'),
--  - then the supplementary information (e.g. relevant bindings, valid hole fits),
--  - then the hints ("Possible fix: ...").
--
-- So this is mostly just a way of making sure that the error context appears
-- early on rather than at the end of the message.
--
-- See Note [Error report] for details.
data SolverReport
  = SolverReport
  { sr_important_msg :: SolverReportWithCtxt
  , sr_supplementary :: [SolverReportSupplementary]
  , sr_hints         :: [GhcHint]
  }

-- | Additional information to print in a 'SolverReport', after the
-- important messages and after the error context.
--
-- See Note [Error report].
data SolverReportSupplementary
  = SupplementaryBindings RelevantBindings
  | SupplementaryHoleFits ValidHoleFits
  | SupplementaryCts      [(PredType, RealSrcSpan)]

-- | A 'TcSolverReportMsg', together with context (e.g. enclosing implication constraints)
-- that are needed in order to report it.
data SolverReportWithCtxt =
  SolverReportWithCtxt
    { reportContext :: SolverReportErrCtxt
       -- ^ Context for what we wish to report.
       -- This can change as we enter implications, so is
       -- stored alongside the content.
    , reportContent :: TcSolverReportMsg
      -- ^ The content of the message to report.
    }
  deriving Generic

-- | Context needed when reporting a 'TcSolverReportMsg', such as
-- the enclosing implication constraints or whether we are deferring type errors.
data SolverReportErrCtxt
    = CEC { cec_encl :: [Implication]  -- ^ Enclosing implications
                                       --   (innermost first)
                                       -- ic_skols and givens are tidied, rest are not
          , cec_tidy  :: TidyEnv

          , cec_binds :: EvBindsVar    -- ^ We make some errors (depending on cec_defer)
                                       -- into warnings, and emit evidence bindings
                                       -- into 'cec_binds' for unsolved constraints

          , cec_defer_type_errors :: DiagnosticReason -- ^ Whether to defer type errors until runtime

          -- We might throw a warning on an error when encountering a hole,
          -- depending on the type of hole (expression hole, type hole, out of scope hole).
          -- We store the reasons for reporting a diagnostic for each type of hole.
          , cec_expr_holes :: DiagnosticReason -- ^ Reason for reporting holes in expressions.
          , cec_type_holes :: DiagnosticReason -- ^ Reason for reporting holes in types.
          , cec_out_of_scope_holes :: DiagnosticReason -- ^ Reason for reporting out of scope holes.

          , cec_warn_redundant :: Bool    -- ^ True <=> -Wredundant-constraints
          , cec_expand_syns    :: Bool    -- ^ True <=> -fprint-expanded-synonyms

          , cec_suppress :: Bool    -- ^ True <=> More important errors have occurred,
                                    --            so create bindings if need be, but
                                    --            don't issue any more errors/warnings
                                    -- See Note [Suppressing error messages]
      }

getUserGivens :: SolverReportErrCtxt -> [UserGiven]
-- One item for each enclosing implication
getUserGivens (CEC {cec_encl = implics}) = getUserGivensFromImplics implics

----------------------------------------------------------------------------
--
--   ErrorItem
--
----------------------------------------------------------------------------

-- | A predicate with its arising location; used to encapsulate a constraint
-- that will give rise to a diagnostic.
data ErrorItem
-- We could perhaps use Ct here (and indeed used to do exactly that), but
-- having a separate type gives to denote errors-in-formation gives us
-- a nice place to do pre-processing, such as calculating ei_suppress.
-- Perhaps some day, an ErrorItem could eventually evolve to contain
-- the error text (or some representation of it), so we can then have all
-- the errors together when deciding which to report.
  = EI { ei_pred     :: PredType         -- report about this
         -- The ei_pred field will never be an unboxed equality with
         -- a (casted) tyvar on the right; this is guaranteed by the solver
       , ei_evdest   :: Maybe TcEvDest   -- for Wanteds, where to put evidence
       , ei_flavour  :: CtFlavour
       , ei_loc      :: CtLoc
       , ei_m_reason :: Maybe CtIrredReason  -- if this ErrorItem was made from a
                                             -- CtIrred, this stores the reason
       , ei_suppress :: Bool    -- Suppress because of Note [Wanteds rewrite Wanteds]
                                -- in GHC.Tc.Constraint
       }

instance Outputable ErrorItem where
  ppr (EI { ei_pred     = pred
          , ei_evdest   = m_evdest
          , ei_flavour  = flav
          , ei_suppress = supp })
    = pp_supp <+> ppr flav <+> pp_dest m_evdest <+> ppr pred
    where
      pp_dest Nothing   = empty
      pp_dest (Just ev) = ppr ev <+> dcolon

      pp_supp = if supp then text "suppress:" else empty

errorItemOrigin :: ErrorItem -> CtOrigin
errorItemOrigin = ctLocOrigin . ei_loc

errorItemEqRel :: ErrorItem -> EqRel
errorItemEqRel = predTypeEqRel . ei_pred

errorItemCtLoc :: ErrorItem -> CtLoc
errorItemCtLoc = ei_loc

errorItemPred :: ErrorItem -> PredType
errorItemPred = ei_pred

{- Note [discardProvCtxtGivens]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In most situations we call all enclosing implications "useful". There is one
exception, and that is when the constraint that causes the error is from the
"provided" context of a pattern synonym declaration:

  pattern Pat :: (Num a, Eq a) => Show a   => a -> Maybe a
             --  required      => provided => type
  pattern Pat x <- (Just x, 4)

When checking the pattern RHS we must check that it does actually bind all
the claimed "provided" constraints; in this case, does the pattern (Just x, 4)
bind the (Show a) constraint.  Answer: no!

But the implication we generate for this will look like
   forall a. (Num a, Eq a) => [W] Show a
because when checking the pattern we must make the required
constraints available, since they are needed to match the pattern (in
this case the literal '4' needs (Num a, Eq a)).

BUT we don't want to suggest adding (Show a) to the "required" constraints
of the pattern synonym, thus:
  pattern Pat :: (Num a, Eq a, Show a) => Show a => a -> Maybe a
It would then typecheck but it's silly.  We want the /pattern/ to bind
the alleged "provided" constraints, Show a.

So we suppress that Implication in discardProvCtxtGivens.  It's
painfully ad-hoc but the truth is that adding it to the "required"
constraints would work.  Suppressing it solves two problems.  First,
we never tell the user that we could not deduce a "provided"
constraint from the "required" context. Second, we never give a
possible fix that suggests to add a "provided" constraint to the
"required" context.

For example, without this distinction the above code gives a bad error
message (showing both problems):

  error: Could not deduce (Show a) ... from the context: (Eq a)
         ... Possible fix: add (Show a) to the context of
         the signature for pattern synonym `Pat' ...
-}


discardProvCtxtGivens :: CtOrigin -> [UserGiven] -> [UserGiven]
discardProvCtxtGivens orig givens  -- See Note [discardProvCtxtGivens]
  | ProvCtxtOrigin (PSB {psb_id = L _ name}) <- orig
  = filterOut (discard name) givens
  | otherwise
  = givens
  where
    discard n (Implic { ic_info = SigSkol (PatSynCtxt n') _ _ }) = n == n'
    discard _ _                                                  = False


-- | An error reported after constraint solving.
-- This is usually, some sort of unsolved constraint error,
-- but we try to be specific about the precise problem we encountered.
data TcSolverReportMsg
  -- | Quantified variables appear out of dependency order.
  --
  -- Example:
  --
  --   forall (a :: k) k. ...
  --
  -- Test cases: BadTelescope2, T16418, T16247, T16726, T18451.
  = BadTelescope TyVarBndrs [TyCoVar]

  -- | We came across a custom type error and we have decided to report it.
  --
  -- Example:
  --
  --   type family F a where
  --     F a = TypeError (Text "error")
  --
  --   err :: F ()
  --   err = ()
  --
  -- Test cases: CustomTypeErrors0{1,2,3,4,5}, T12104.
  | UserTypeError ErrorMsgType -- ^ the message to report

  -- | Report a Wanted constraint of the form "Unsatisfiable msg".
  | UnsatisfiableError ErrorMsgType -- ^ the message to report

  -- | We want to report an out of scope variable or a typed hole.
  -- See 'HoleError'.
  | ReportHoleError Hole HoleError

  -- | Trying to unify an untouchable variable, e.g. a variable from an outer scope.
  --
  -- Test case: Simple14
  | UntouchableVariable
    { untouchableTyVar :: TyVar
    , untouchableTyVarImplication :: Implication
    }

  -- | Cannot unify a variable, because of a type mismatch.
  | CannotUnifyVariable
    { mismatchMsg         :: MismatchMsg
    , cannotUnifyReason   :: CannotUnifyVariableReason }

  -- | A mismatch between two types.
  | Mismatch
     { mismatchMsg           :: MismatchMsg
     , mismatchTyVarInfo     :: Maybe TyVarInfo
     , mismatchAmbiguityInfo :: [AmbiguityInfo]
     , mismatchCoercibleInfo :: Maybe CoercibleMsg }

   -- | A violation of the representation-polymorphism invariants.
   --
   -- See 'FixedRuntimeRepErrorInfo' and 'FixedRuntimeRepContext' for more information.
  | FixedRuntimeRepError [FixedRuntimeRepErrorInfo]

  -- | An equality between two types is blocked on a kind equality
  -- between their kinds.
  --
  -- Test cases: none.
  | BlockedEquality ErrorItem
    -- These are for the "blocked" equalities, as described in
    -- Note [Equalities with incompatible kinds] in GHC.Tc.Solver.Canonical,
    -- wrinkle (EIK2). There should always be another unsolved wanted around,
    -- which will ordinarily suppress this message. But this can still be printed out
    -- with -fdefer-type-errors (sigh), so we must produce a message.

  -- | Something was not applied to sufficiently many arguments.
  --
  --  Example:
  --
  --    instance Eq Maybe where {..}
  --
  -- Test case: T11563.
  | ExpectingMoreArguments Int TypedThing

  -- | Trying to use an unbound implicit parameter.
  --
  -- Example:
  --
  --    foo :: Int
  --    foo = ?param
  --
  -- Test case: tcfail130.
  | UnboundImplicitParams
      (NE.NonEmpty ErrorItem)

  -- | A constraint couldn't be solved because it contains
  -- ambiguous type variables.
  --
  -- Example:
  --
  --   class C a b where
  --     f :: (a,b)
  --
  --   x = fst f
  --
  --
  -- Test case: T4921.
  | AmbiguityPreventsSolvingCt
      ErrorItem -- ^ always a class constraint
      ([TyVar], [TyVar]) -- ^ ambiguous kind and type variables, respectively

  -- | Could not solve a constraint; there were several unifying candidate instances
  -- but no matching instances. This is used to report as much useful information
  -- as possible about why we couldn't choose any instance, e.g. because of
  -- ambiguous type variables.
  | CannotResolveInstance
    { cannotResolve_item         :: ErrorItem
    , cannotResolve_unifiers     :: [ClsInst]
    , cannotResolve_candidates   :: [ClsInst]
    , cannotResolve_importErrors :: [ImportError]
    , cannotResolve_suggestions  :: [GhcHint]
    , cannotResolve_relevant_bindings :: RelevantBindings }
      -- TODO: remove the fields of type [GhcHint] and RelevantBindings,
      -- in order to handle them uniformly with other diagnostic messages.

  -- | Could not solve a constraint using available instances
  -- because the instances overlap.
  --
  -- Test cases: tcfail118, tcfail121, tcfail218.
  | OverlappingInstances
    { overlappingInstances_item     :: ErrorItem
    , overlappingInstances_matches  :: NE.NonEmpty ClsInst
    , overlappingInstances_unifiers :: [ClsInst] }

  -- | Could not solve a constraint from instances because
  -- instances declared in a Safe module cannot overlap instances
  -- from other modules (with -XSafeHaskell).
  --
  -- Test cases: SH_Overlap{1,2,5,6,7,11}.
  | UnsafeOverlap
    { unsafeOverlap_item    :: ErrorItem
    , unsafeOverlap_match   :: ClsInst
    , unsafeOverlapped      :: NE.NonEmpty ClsInst }

  deriving Generic

data MismatchMsg
  =  -- | Couldn't unify two types or kinds.
  --
  --  Example:
  --
  --    3 + 3# -- can't match a lifted type with an unlifted type
  --
  --  Test cases: T1396, T8263, ...
    BasicMismatch
      { mismatch_ea           :: MismatchEA  -- ^ Should this be phrased in terms of expected vs actual?
      , mismatch_item         :: ErrorItem   -- ^ The constraint in which the mismatch originated.
      , mismatch_ty1          :: Type        -- ^ First type (the expected type if if mismatch_ea is True)
      , mismatch_ty2          :: Type        -- ^ Second type (the actual type if mismatch_ea is True)
      , mismatch_whenMatching :: Maybe WhenMatching
      , mismatch_mb_same_occ  :: Maybe SameOccInfo
      }

  -- | A type has an unexpected kind.
  --
  -- Test cases: T2994, T7609, ...
  | KindMismatch
      { kmismatch_what     :: TypedThing -- ^ What thing is 'kmismatch_actual' the kind of?
      , kmismatch_expected :: Type
      , kmismatch_actual   :: Type
      }
    -- TODO: combine with 'BasicMismatch'.

  -- | A mismatch between two types, which arose from a type equality.
  --
  -- Test cases: T1470, tcfail212.
  | TypeEqMismatch
      { teq_mismatch_ppr_explicit_kinds :: Bool
      , teq_mismatch_item     :: ErrorItem
      , teq_mismatch_ty1      :: Type
      , teq_mismatch_ty2      :: Type
      , teq_mismatch_expected :: Type -- ^ The overall expected type
      , teq_mismatch_actual   :: Type -- ^ The overall actual type
      , teq_mismatch_what     :: Maybe TypedThing -- ^ What thing is 'teq_mismatch_actual' the kind of?
      , teq_mb_same_occ       :: Maybe SameOccInfo
      }
    -- TODO: combine with 'BasicMismatch'.

  -- | Couldn't solve some Wanted constraints using the Givens.
  -- Used for messages such as @"No instance for ..."@ and
  -- @"Could not deduce ... from"@.
  | CouldNotDeduce
     { cnd_user_givens :: [Implication]
        -- | The Wanted constraints we couldn't solve.
        --
        -- N.B.: the 'ErrorItem' at the head of the list has been tidied,
        -- perhaps not the others.
     , cnd_wanted      :: NE.NonEmpty ErrorItem

       -- | Some additional info consumed by 'mk_supplementary_ea_msg'.
     , cnd_extra       :: Maybe CND_Extra
     }
  deriving Generic

-- | Construct a basic mismatch message between two types.
--
-- See 'pprMismatchMsg' for how such a message is displayed to users.
mkBasicMismatchMsg :: MismatchEA -> ErrorItem -> Type -> Type -> MismatchMsg
mkBasicMismatchMsg ea item ty1 ty2
  = BasicMismatch
      { mismatch_ea           = ea
      , mismatch_item         = item
      , mismatch_ty1          = ty1
      , mismatch_ty2          = ty2
      , mismatch_whenMatching = Nothing
      , mismatch_mb_same_occ  = Nothing
      }

-- | Whether to use expected/actual in a type mismatch message.
data MismatchEA
  -- | Don't use expected/actual.
  = NoEA
  -- | Use expected/actual.
  | EA
  { mismatch_mbEA :: Maybe ExpectedActualInfo
    -- ^ Whether to also mention type synonym expansion.
  }

data CannotUnifyVariableReason
  =  -- | A type equality between a type variable and a polytype.
    --
    -- Test cases: T12427a, T2846b, T10194, ...
    CannotUnifyWithPolytype ErrorItem TyVar Type (Maybe TyVarInfo)

  -- | An occurs check.
  | OccursCheck
    { occursCheckInterestingTyVars :: [TyVar]
    , occursCheckAmbiguityInfos    :: [AmbiguityInfo] }

  -- | A skolem type variable escapes its scope.
  --
  -- Example:
  --
  --   data Ex where { MkEx :: a -> MkEx }
  --   foo (MkEx x) = x
  --
  -- Test cases: TypeSkolEscape, T11142.
  | SkolemEscape ErrorItem Implication [TyVar]

  -- | Can't unify the type variable with the other type
  -- due to the kind of type variable it is.
  --
  -- For example, trying to unify a 'SkolemTv' with the
  -- type Int, or with a 'TyVarTv'.
  | DifferentTyVars TyVarInfo
  | RepresentationalEq TyVarInfo (Maybe CoercibleMsg)
  deriving Generic

-- | Report a mismatch error without any extra
-- information.
mkPlainMismatchMsg :: MismatchMsg -> TcSolverReportMsg
mkPlainMismatchMsg msg
  = Mismatch
     { mismatchMsg           = msg
     , mismatchTyVarInfo     = Nothing
     , mismatchAmbiguityInfo = []
     , mismatchCoercibleInfo = Nothing }

-- | Additional information to be given in a 'CouldNotDeduce' message,
-- which is then passed on to 'mk_supplementary_ea_msg'.
data CND_Extra = CND_Extra TypeOrKind Type Type

-- | A cue to print out information about type variables,
-- e.g. where they were bound, when there is a mismatch @tv1 ~ ty2@.
data TyVarInfo =
  TyVarInfo { thisTyVar :: TyVar
            , thisTyVarIsUntouchable :: Maybe Implication
            , otherTy   :: Maybe TyVar }

-- | Add some information to disambiguate errors in which
-- two 'Names' would otherwise appear to be identical.
--
-- See Note [Disambiguating (X ~ X) errors].
data SameOccInfo
  = SameOcc
    { sameOcc_same_pkg :: Bool -- ^ Whether the two 'Name's also came from the same package.
    , sameOcc_lhs :: Name
    , sameOcc_rhs :: Name }

-- | Add some information about ambiguity
data AmbiguityInfo

  -- | Some type variables remained ambiguous: print them to the user.
  = Ambiguity
    { lead_with_ambig_msg :: Bool -- ^ True <=> start the message with "Ambiguous type variable ..."
                                  --  False <=> create a message of the form "The type variable is ambiguous."
    , ambig_tyvars        :: ([TyVar], [TyVar]) -- ^ Ambiguous kind and type variables, respectively.
                                                -- Guaranteed to not both be empty.
    }

  -- | Remind the user that a particular type family is not injective.
  | NonInjectiveTyFam TyCon

-- | Expected/actual information.
data ExpectedActualInfo
  -- | Display the expected and actual types.
  = ExpectedActual
     { ea_expected, ea_actual :: Type }

  -- | Display the expected and actual types, after expanding type synonyms.
  | ExpectedActualAfterTySynExpansion
     { ea_expanded_expected, ea_expanded_actual :: Type }

-- | Explain how a kind equality originated.
data WhenMatching

  = WhenMatching TcType TcType CtOrigin (Maybe TypeOrKind)
  deriving Generic

data BadImportKind
  -- | Module does not export...
  = BadImportNotExported
  -- | Missing @type@ keyword when importing a type.
  | BadImportAvailTyCon
  -- | Trying to import a data constructor directly, e.g.
  -- @import Data.Maybe (Just)@ instead of @import Data.Maybe (Maybe(Just))@
  | BadImportAvailDataCon OccName
  -- | The parent does not export the given children.
  | BadImportNotExportedSubordinates [OccName]
  -- | Incorrect @type@ keyword when importing something which isn't a type.
  | BadImportAvailVar
  deriving Generic

-- | Some form of @"not in scope"@ error. See also the 'OutOfScopeHole'
-- constructor of 'HoleError'.
data NotInScopeError

  -- | A run-of-the-mill @"not in scope"@ error.
  = NotInScope

  -- | Something used in record syntax, but it isn't a record field.
  | NotARecordField
    -- TODO: this could be folded into NotInScope were there
    -- a separate namespace for record fields.

  -- | An exact 'Name' was not in scope.
  --
  -- This usually indicates a problem with a Template Haskell splice.
  --
  -- Test cases: T5971, T18263.
  | NoExactName Name

  -- The same exact 'Name' occurs in multiple name-spaces.
  --
  -- This usually indicates a problem with a Template Haskell splice.
  --
  -- Test case: T7241.
  | SameName [GlobalRdrElt] -- ^ always at least 2 elements

  -- A type signature, fixity declaration, pragma, standalone kind signature...
  -- is missing an associated binding.
  | MissingBinding SDoc [GhcHint]
    -- TODO: remove the SDoc argument.

  -- | Couldn't find a top-level binding.
  --
  -- Happens when specifying an annotation for something that
  -- is not in scope.
  --
  -- Test cases: annfail01, annfail02, annfail11.
  | NoTopLevelBinding

  -- | A class doesn't have a method with this name,
  -- or, a class doesn't have an associated type with this name,
  -- or, a record doesn't have a record field with this name.
  | UnknownSubordinate SDoc

  -- | A name is not in scope during type checking but passed the renamer.
  --
  -- Test cases:
  --   none
  | NotInScopeTc (NameEnv TcTyThing)
  deriving Generic

-- | Create a @"not in scope"@ error message for the given 'RdrName'.
mkTcRnNotInScope :: RdrName -> NotInScopeError -> TcRnMessage
mkTcRnNotInScope rdr err = TcRnNotInScope err rdr [] noHints

-- | Configuration for pretty-printing valid hole fits.
data HoleFitDispConfig =
  HFDC { showWrap, showWrapVars, showType, showProv, showMatches
          :: Bool }

-- | Report an error involving a 'Hole'.
--
-- This could be an out of scope data constructor or variable,
-- a typed hole, or a wildcard in a type.
data HoleError
  -- | Report an out-of-scope data constructor or variable
  -- masquerading as an expression hole.
  --
  -- See Note [Insoluble holes] in GHC.Tc.Types.Constraint.
  -- See 'NotInScopeError' for other not-in-scope errors.
  --
  -- Test cases: T9177a.
  = OutOfScopeHole [ImportError]
  -- | Report a typed hole, or wildcard, with additional information.
  | HoleError HoleSort
              [TcTyVar]                     -- Other type variables which get computed on the way.
              [(SkolemInfoAnon, [TcTyVar])] -- Zonked and grouped skolems for the type of the hole.

-- | A message that aims to explain why two types couldn't be seen
-- to be representationally equal.
data CoercibleMsg
  -- | Not knowing the role of a type constructor prevents us from
  -- concluding that two types are representationally equal.
  --
  -- Example:
  --
  --   foo :: Applicative m => m (Sum Int)
  --   foo = coerce (pure $ 1 :: Int)
  --
  -- We don't know what role `m` has, so we can't coerce `m Int` to `m (Sum Int)`.
  --
  -- Test cases: T8984, TcCoercibleFail.
  = UnknownRoles Type

  -- | The fact that a 'TyCon' is abstract prevents us from decomposing
  -- a 'TyConApp' and deducing that two types are representationally equal.
  --
  -- Test cases: none.
  | TyConIsAbstract TyCon

  -- | We can't unwrap a newtype whose constructor is not in scope.
  --
  -- Example:
  --
  --   import Data.Ord (Down) -- NB: not importing the constructor
  --   foo :: Int -> Down Int
  --   foo = coerce
  --
  -- Test cases: TcCoercibleFail.
  | OutOfScopeNewtypeConstructor TyCon DataCon

-- | Explain a problem with an import.
data ImportError
  -- | Couldn't find a module with the requested name.
  = MissingModule ModuleName
  -- | The imported modules don't export what we're looking for.
  | ModulesDoNotExport (NE.NonEmpty Module) OccName

-- | This datatype collates instances that match or unifier,
-- in order to report an error message for an unsolved typeclass constraint.
data PotentialInstances
  = PotentialInstances
  { matches  :: [ClsInst]
  , unifiers :: [ClsInst]
  }

-- | A collection of valid hole fits or refinement fits,
-- in which some fits might have been suppressed.
data FitsMbSuppressed
  = Fits
    { fits           :: [HoleFit]
    , fitsSuppressed :: Bool  -- ^ Whether we have suppressed any fits because there were too many.
    }

-- | A collection of hole fits and refinement fits.
data ValidHoleFits
  = ValidHoleFits
    { holeFits       :: FitsMbSuppressed
    , refinementFits :: FitsMbSuppressed
    }

noValidHoleFits :: ValidHoleFits
noValidHoleFits = ValidHoleFits (Fits [] False) (Fits [] False)

data RelevantBindings
  = RelevantBindings
    { relevantBindingNamesAndTys :: [(Name, Type)]
    , ranOutOfFuel               :: Bool -- ^ Whether we ran out of fuel generating the bindings.
    }

-- | Display some relevant bindings.
pprRelevantBindings :: RelevantBindings -> SDoc
-- This function should be in "GHC.Tc.Errors.Ppr",
-- but it's here for the moment as it's needed in "GHC.Tc.Errors".
pprRelevantBindings (RelevantBindings bds ran_out_of_fuel) =
  ppUnless (null rel_bds) $
    hang (text "Relevant bindings include")
       2 (vcat (map ppr_binding rel_bds) $$ ppWhen ran_out_of_fuel discardMsg)
  where
    ppr_binding (nm, tidy_ty) =
      sep [ pprPrefixOcc nm <+> dcolon <+> ppr tidy_ty
          , nest 2 (parens (text "bound at"
               <+> ppr (getSrcLoc nm)))]
    rel_bds = filter (not . isGeneratedSrcSpan . getSrcSpan . fst) bds

discardMsg :: SDoc
discardMsg = text "(Some bindings suppressed;" <+>
             text "use -fmax-relevant-binds=N or -fno-max-relevant-binds)"

data PromotionErr
  = TyConPE          -- TyCon used in a kind before we are ready
                     --     data T :: T -> * where ...
  | ClassPE          -- Ditto Class

  | FamDataConPE     -- Data constructor for a data family
                     -- See Note [AFamDataCon: not promoting data family constructors]
                     -- in GHC.Tc.Utils.Env.
  | ConstrainedDataConPE ThetaType -- Data constructor with a context
                                   -- See Note [No constraints in kinds] in GHC.Tc.Validity
  | PatSynPE         -- Pattern synonyms
                     -- See Note [Don't promote pattern synonyms] in GHC.Tc.Utils.Env

  | RecDataConPE     -- Data constructor in a recursive loop
                     -- See Note [Recursion and promoting data constructors] in GHC.Tc.TyCl
  | TermVariablePE   -- See Note [Promoted variables in types]
  | NoDataKindsDC    -- -XDataKinds not enabled (for a datacon)

instance Outputable PromotionErr where
  ppr ClassPE              = text "ClassPE"
  ppr TyConPE              = text "TyConPE"
  ppr PatSynPE             = text "PatSynPE"
  ppr FamDataConPE         = text "FamDataConPE"
  ppr (ConstrainedDataConPE theta) = text "ConstrainedDataConPE" <+> parens (ppr theta)
  ppr RecDataConPE         = text "RecDataConPE"
  ppr NoDataKindsDC        = text "NoDataKindsDC"
  ppr TermVariablePE       = text "TermVariablePE"

pprPECategory :: PromotionErr -> SDoc
pprPECategory = text . capitalise . peCategory

peCategory :: PromotionErr -> String
peCategory ClassPE              = "class"
peCategory TyConPE              = "type constructor"
peCategory PatSynPE             = "pattern synonym"
peCategory FamDataConPE         = "data constructor"
peCategory ConstrainedDataConPE{} = "data constructor"
peCategory RecDataConPE         = "data constructor"
peCategory NoDataKindsDC        = "data constructor"
peCategory TermVariablePE       = "term variable"

-- | Stores the information to be reported in a representation-polymorphism
-- error message.
data FixedRuntimeRepErrorInfo
  = FRR_Info
  { frr_info_origin       :: FixedRuntimeRepOrigin
      -- ^ What is the original type we checked for
      -- representation-polymorphism, and what specific
      -- check did we perform?
  , frr_info_not_concrete :: Maybe (TcTyVar, TcType)
      -- ^ Which non-concrete type did we try to
      -- unify this concrete type variable with?
  }

{-
************************************************************************
*                                                                      *
\subsection{Contexts for renaming errors}
*                                                                      *
************************************************************************
-}

-- AZ:TODO: Change these all to be Name instead of RdrName.
--          Merge TcType.UserTypeContext in to it.
data HsDocContext
  = TypeSigCtx SDoc
  | StandaloneKindSigCtx SDoc
  | PatCtx
  | SpecInstSigCtx
  | DefaultDeclCtx
  | ForeignDeclCtx (LocatedN RdrName)
  | DerivDeclCtx
  | RuleCtx FastString
  | TyDataCtx (LocatedN RdrName)
  | TySynCtx (LocatedN RdrName)
  | TyFamilyCtx (LocatedN RdrName)
  | FamPatCtx (LocatedN RdrName)    -- The patterns of a type/data family instance
  | ConDeclCtx [LocatedN Name]
  | ClassDeclCtx (LocatedN RdrName)
  | ExprWithTySigCtx
  | TypBrCtx
  | HsTypeCtx
  | HsTypePatCtx
  | GHCiCtx
  | SpliceTypeCtx (LHsType GhcPs)
  | ClassInstanceCtx
  | GenericCtx SDoc

-- | Context for a mismatch in the number of arguments
data MatchArgsContext
  = EquationArgs
      !Name -- ^ Name of the function
  | PatternArgs
      !(HsMatchContext GhcTc) -- ^ Pattern match specifics

-- | The information necessary to report mismatched
-- numbers of arguments in a match group.
data MatchArgBadMatches where
  MatchArgMatches
    ::  { matchArgFirstMatch :: LocatedA (Match GhcRn body)
        , matchArgBadMatches :: NE.NonEmpty (LocatedA (Match GhcRn body)) }
    -> MatchArgBadMatches

-- | The phase in which an exception was encountered when dealing with a TH splice
data SplicePhase
  = SplicePhase_Run
  | SplicePhase_CompileAndLink

data LookupTHInstNameErrReason
  = NoMatchesFound
  | CouldNotDetermineInstance

data UnrepresentableTypeDescr
  = LinearInvisibleArgument
  | CoercionsInTypes

-- | The context for an "empty statement group" error.
data EmptyStatementGroupErrReason
  = EmptyStmtsGroupInParallelComp
  -- ^ Empty statement group in a parallel list comprehension
  | EmptyStmtsGroupInTransformListComp
  -- ^ Empty statement group in a transform list comprehension
  --
  --   Example:
  --   [() | then ()]
  | EmptyStmtsGroupInDoNotation HsDoFlavour
  -- ^ Empty statement group in do notation
  --
  --   Example:
  --   do
  | EmptyStmtsGroupInArrowNotation
  -- ^ Empty statement group in arrow notation
  --
  --   Example:
  --   proc () -> do

  deriving (Generic)

-- | An existential wrapper around @'StmtLR' GhcPs GhcPs body@.
data UnexpectedStatement where
  UnexpectedStatement
    :: Outputable (StmtLR GhcPs GhcPs body)
    => StmtLR GhcPs GhcPs body
    -> UnexpectedStatement

data DeclSort = ClassDeclSort | InstanceDeclSort

data NonStandardGuards where
  NonStandardGuards
    :: (Outputable body,
        Anno (Stmt GhcRn body) ~ SrcSpanAnnA)
    => [LStmtLR GhcRn GhcRn body]
    -> NonStandardGuards

data RuleLhsErrReason
  = UnboundVariable RdrName NotInScopeError
  | IllegalExpression

data HsigShapeMismatchReason =
  {-| HsigShapeSortMismatch is an error indicating that an item in the
    export list of a signature doesn't match the item of the same name in
    another signature when merging the two – one is a type while the other is a
    plain identifier.

    Test cases:
      none
  -}
  HsigShapeSortMismatch !AvailInfo !AvailInfo
  |
  {-| HsigShapeNotUnifiable is an error indicating that a name in the
    export list of a signature cannot be unified with a name of the same name in
    another signature when merging the two.

    Test cases:
      bkpfail20, bkpfail21
  -}
  HsigShapeNotUnifiable !Name !Name !Bool
  deriving (Generic)

data WrongThingSort
  = WrongThingType
  | WrongThingDataCon
  | WrongThingPatSyn
  | WrongThingConLike
  | WrongThingClass
  | WrongThingTyCon
  | WrongThingAxiom

data StageCheckReason
  = StageCheckInstance !InstanceWhat !PredType
  | StageCheckSplice !Name

data UninferrableTyVarCtx
  = UninfTyCtx_ClassContext [TcType]
  | UninfTyCtx_DataContext [TcType]
  | UninfTyCtx_ProvidedContext [TcType]
  | UninfTyCtx_TyFamRhs TcType
  | UninfTyCtx_TySynRhs TcType
  | UninfTyCtx_Sig TcType (LHsSigType GhcRn)

data PatSynInvalidRhsReason
  = PatSynNotInvertible !(Pat GhcRn)
  | PatSynUnboundVar !Name
  deriving (Generic)

data BadFieldAnnotationReason where
  {-| A lazy data type field annotation (~) was used without enabling the
    extension StrictData.

    Test cases:
    LazyFieldsDisabled
  -}
  LazyFieldsDisabled :: BadFieldAnnotationReason
  {-| An UNPACK pragma was applied to a field without strictness annotation (!).

    Test cases:
    T14761a, T7562
  -}
  UnpackWithoutStrictness :: BadFieldAnnotationReason
  {-| An UNPACK pragma was applied to an abstract type in an indefinite package
    in Backpack.

    Test cases:
    unpack_sums_5, T3966, T7050
  -}
  BackpackUnpackAbstractType :: BadFieldAnnotationReason
  deriving (Generic)

data SuperclassCycle =
  MkSuperclassCycle { cls :: Class, definite :: Bool, reasons :: [SuperclassCycleDetail] }

data SuperclassCycleDetail
  = SCD_HeadTyVar !PredType
  | SCD_HeadTyFam !PredType
  | SCD_Superclass !Class

data RoleValidationFailedReason
  = TyVarRoleMismatch !TyVar !Role
  | TyVarMissingInEnv !TyVar
  | BadCoercionRole !Coercion
  deriving (Generic)

data DisabledClassExtension where
  {-| MultiParamTypeClasses is required.

    Test cases:
    readFail037, TcNoNullaryTC
  -}
  MultiParamDisabled :: !Int -- ^ The arity
                     -> DisabledClassExtension
  {-| FunctionalDependencies is required.

    Test cases:
    readFail041
  -}
  FunDepsDisabled :: DisabledClassExtension
  {-| ConstrainedClassMethods is required.

    Test cases:
    mod39, tcfail150
  -}
  ConstrainedClassMethodsDisabled :: !Id
                                  -> !TcPredType
                                  -> DisabledClassExtension
  deriving (Generic)

data TyFamsDisabledReason
  = TyFamsDisabledFamily !Name
  | TyFamsDisabledInstance !TyCon
  deriving (Generic)

-- | Either `HsType p` or `HsSigType p`.
--
-- Used for reporting errors in `TcRnIllegalKind`.
data HsTypeOrSigType p
  = HsType    (HsType p)
  | HsSigType (HsSigType p)

instance OutputableBndrId p => Outputable (HsTypeOrSigType (GhcPass p)) where
  ppr (HsType ty) = ppr ty
  ppr (HsSigType sig_ty) = ppr sig_ty

-- | A wrapper around HsTyVarBndr.
-- Used for reporting errors in `TcRnUnusedQuantifiedTypeVar`.
data HsTyVarBndrExistentialFlag = forall flag. OutputableBndrFlag flag 'Renamed =>
  HsTyVarBndrExistentialFlag (HsTyVarBndr flag GhcRn)

instance Outputable HsTyVarBndrExistentialFlag where
  ppr (HsTyVarBndrExistentialFlag hsTyVarBndr) = ppr hsTyVarBndr

type TySynCycleTyCons =
  [Either TyCon (LTyClDecl GhcRn)]

-- | Different types of warnings for dodgy imports.
data DodgyImportsReason =
  {-| An import of the form 'T(..)' or 'f(..)' does not actually import anything beside
      'T'/'f' itself.

    Test cases:
      DodgyImports
  -}
  DodgyImportsEmptyParent !GlobalRdrElt
  |
  {-| A 'hiding' clause contains something that would be reported as an error in a
    regular import, but is relaxed to a warning.

    Test cases:
      DodgyImports_hiding
  -}
  DodgyImportsHiding !ImportLookupReason
  deriving (Generic)

-- | Different types of errors for import lookup.
data ImportLookupReason where
  {-| An item in an import statement is not exported by the corresponding
    module.

    Test cases:
      T21826, recomp001, retc001, mod79, mod80, mod81, mod91, T6007, T7167,
      T9006, T11071, T9905fail2, T5385, T10668
  -}
  ImportLookupBad :: BadImportKind
                  -> ModIface
                  -> ImpDeclSpec
                  -> IE GhcPs
                  -> Bool -- ^ whether @-XPatternSynonyms@ was enabled
                  -> ImportLookupReason
  {-| A name is specified with a qualifying module.

    Test cases:
      T3792
  -}
  ImportLookupQualified :: !RdrName -- ^ The name extracted from the import item
                        -> ImportLookupReason

  {-| Something completely unexpected is in an import list, like @module Foo@.

    Test cases:
      ImportLookupIllegal
  -}
  ImportLookupIllegal :: ImportLookupReason
  {-| An item in an import list matches multiple names exported from that module.

    Test cases:
      None
  -}
  ImportLookupAmbiguous :: !RdrName -- ^ The name extracted from the import item
                        -> ![GlobalRdrElt] -- ^ The potential matches
                        -> ImportLookupReason
  deriving (Generic)

-- | Distinguish record fields from other names for pretty-printing.
data UnusedImportName where
  UnusedImportNameRecField :: !Parent -> !OccName -> UnusedImportName
  UnusedImportNameRegular :: !Name -> UnusedImportName

-- | Different types of errors for unused imports.
data UnusedImportReason where
  {-| No names in the import list are used in the module.

    Test cases:
      overloadedrecfldsfail06, T10890_2, t22391, t22391j, T1074, prog018,
      mod177, rn046, rn037, T5211
  -}
  UnusedImportNone :: UnusedImportReason
  {-| A set of names in the import list are not used in the module.

    Test cases:
      overloadedrecfldsfail06, T17324, mod176, T11970A, rn046, T14881,
      T7454, T8149, T13064
  -}
  UnusedImportSome :: ![UnusedImportName] -- ^ The unsed names
                   -> UnusedImportReason
  deriving (Generic)

-- | Different places in which a nested foralls/contexts error might occur.
data NestedForallsContextsIn
  -- | Nested forall in @SPECIALISE instance@
  = NFC_Specialize
  -- | Nested forall in @deriving via@ (via-type)
  | NFC_ViaType
  -- | Nested forall in the type of a GADT constructor
  | NFC_GadtConSig
  -- | Nested forall in an instance head
  | NFC_InstanceHead
  -- | Nested forall in a standalone deriving instance head
  | NFC_StandaloneDerivedInstanceHead
  -- | Nested forall in deriving class type
  | NFC_DerivedClassType

-- | Provenance of an unused name.
data UnusedNameProv
  = UnusedNameTopDecl
  | UnusedNameImported !ModuleName
  | UnusedNameTypePattern
  | UnusedNameMatch
  | UnusedNameLocalBind

-- | Different reasons for TcRnNonCanonicalDefinition.
data NonCanonicalDefinition =
  -- | Related to @(<>)@ and @mappend@.
  NonCanonicalMonoid NonCanonical_Monoid
  |
  -- | Related to @(*>)@/@(>>)@ and @pure@/@return@.
  NonCanonicalMonad NonCanonical_Monad
  deriving (Generic)

-- | Possible cases for the -Wnoncanonical-monoid-instances.
data NonCanonical_Monoid =
  -- | @(<>) = mappend@ was defined.
  NonCanonical_Sappend
  |
  -- | @mappend@ was defined as something other than @(<>)@.
  NonCanonical_Mappend

-- | Possible cases for the -Wnoncanonical-monad-instances.
data NonCanonical_Monad =
  -- | @pure = return@ was defined.
  NonCanonical_Pure
  |
  -- | @(*>) = (>>)@ was defined.
  NonCanonical_ThenA
  |
  -- | @return@ was defined as something other than @pure@.
  NonCanonical_Return
  |
  -- | @(>>)@ was defined as something other than @(*>)@.
  NonCanonical_ThenM