forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.rs
More file actions
1570 lines (1421 loc) · 45.6 KB
/
errors.rs
File metadata and controls
1570 lines (1421 loc) · 45.6 KB
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
use rustc_errors::codes::*;
use rustc_errors::formatting::DiagMessageAddArg;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, Diagnostic, ElidedLifetimeInPathSubdiag,
EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
};
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Spanned, Symbol};
use crate::Res;
use crate::late::PatternSource;
#[derive(Diagnostic)]
#[diag("can't use {$is_self ->
[true] `Self`
*[false] generic parameters
} from outer item", code = E0401)]
#[note(
"nested items are independent from their parent item for everything except for privacy and name resolution"
)]
pub(crate) struct GenericParamsFromOuterItem {
#[primary_span]
#[label(
"use of {$is_self ->
[true] `Self`
*[false] generic parameter
} from outer item"
)]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) label: Option<GenericParamsFromOuterItemLabel>,
#[subdiagnostic]
pub(crate) refer_to_type_directly: Option<UseTypeDirectly>,
#[subdiagnostic]
pub(crate) sugg: Option<GenericParamsFromOuterItemSugg>,
#[subdiagnostic]
pub(crate) static_or_const: Option<GenericParamsFromOuterItemStaticOrConst>,
pub(crate) is_self: bool,
#[subdiagnostic]
pub(crate) item: Option<GenericParamsFromOuterItemInnerItem>,
}
#[derive(Subdiagnostic)]
#[label(
"{$is_self ->
[true] `Self`
*[false] generic parameter
} used in this inner {$descr}"
)]
pub(crate) struct GenericParamsFromOuterItemInnerItem {
#[primary_span]
pub(crate) span: Span,
pub(crate) descr: String,
pub(crate) is_self: bool,
}
#[derive(Subdiagnostic)]
pub(crate) enum GenericParamsFromOuterItemStaticOrConst {
#[note("a `static` is a separate item from the item that contains it")]
Static,
#[note("a `const` is a separate item from the item that contains it")]
Const,
}
#[derive(Subdiagnostic)]
pub(crate) enum GenericParamsFromOuterItemLabel {
#[label("can't use `Self` here")]
SelfTyParam(#[primary_span] Span),
#[label("`Self` type implicitly declared here, by this `impl`")]
SelfTyAlias(#[primary_span] Span),
#[label("type parameter from outer item")]
TyParam(#[primary_span] Span),
#[label("const parameter from outer item")]
ConstParam(#[primary_span] Span),
}
#[derive(Subdiagnostic)]
#[suggestion(
"try introducing a local generic parameter here",
code = "{snippet}",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct GenericParamsFromOuterItemSugg {
#[primary_span]
pub(crate) span: Span,
pub(crate) snippet: String,
}
#[derive(Subdiagnostic)]
#[suggestion(
"refer to the type directly here instead",
code = "{snippet}",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct UseTypeDirectly {
#[primary_span]
pub(crate) span: Span,
pub(crate) snippet: String,
}
#[derive(Diagnostic)]
#[diag("the name `{$name}` is already used for a generic parameter in this item's generic parameters", code = E0403)]
pub(crate) struct NameAlreadyUsedInParameterList {
#[primary_span]
#[label("already used")]
pub(crate) span: Span,
#[label("first use of `{$name}`")]
pub(crate) first_use_span: Span,
pub(crate) name: Ident,
}
#[derive(Diagnostic)]
#[diag("method `{$method}` is not a member of trait `{$trait_}`", code = E0407)]
pub(crate) struct MethodNotMemberOfTrait {
#[primary_span]
#[label("not a member of trait `{$trait_}`")]
pub(crate) span: Span,
pub(crate) method: Ident,
pub(crate) trait_: String,
#[subdiagnostic]
pub(crate) sub: Option<AssociatedFnWithSimilarNameExists>,
}
#[derive(Subdiagnostic)]
#[suggestion(
"there is an associated function with a similar name",
code = "{candidate}",
applicability = "maybe-incorrect"
)]
pub(crate) struct AssociatedFnWithSimilarNameExists {
#[primary_span]
pub(crate) span: Span,
pub(crate) candidate: Symbol,
}
#[derive(Diagnostic)]
#[diag("type `{$type_}` is not a member of trait `{$trait_}`", code = E0437)]
pub(crate) struct TypeNotMemberOfTrait {
#[primary_span]
#[label("not a member of trait `{$trait_}`")]
pub(crate) span: Span,
pub(crate) type_: Ident,
pub(crate) trait_: String,
#[subdiagnostic]
pub(crate) sub: Option<AssociatedTypeWithSimilarNameExists>,
}
#[derive(Subdiagnostic)]
#[suggestion(
"there is an associated type with a similar name",
code = "{candidate}",
applicability = "maybe-incorrect"
)]
pub(crate) struct AssociatedTypeWithSimilarNameExists {
#[primary_span]
pub(crate) span: Span,
pub(crate) candidate: Symbol,
}
#[derive(Diagnostic)]
#[diag("const `{$const_}` is not a member of trait `{$trait_}`", code = E0438)]
pub(crate) struct ConstNotMemberOfTrait {
#[primary_span]
#[label("not a member of trait `{$trait_}`")]
pub(crate) span: Span,
pub(crate) const_: Ident,
pub(crate) trait_: String,
#[subdiagnostic]
pub(crate) sub: Option<AssociatedConstWithSimilarNameExists>,
}
#[derive(Subdiagnostic)]
#[suggestion(
"there is an associated constant with a similar name",
code = "{candidate}",
applicability = "maybe-incorrect"
)]
pub(crate) struct AssociatedConstWithSimilarNameExists {
#[primary_span]
pub(crate) span: Span,
pub(crate) candidate: Symbol,
}
#[derive(Diagnostic)]
#[diag("variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`", code = E0409)]
pub(crate) struct VariableBoundWithDifferentMode {
#[primary_span]
#[label("bound in different ways")]
pub(crate) span: Span,
#[label("first binding")]
pub(crate) first_binding_span: Span,
pub(crate) variable_name: Ident,
}
#[derive(Diagnostic)]
#[diag("identifier `{$identifier}` is bound more than once in this parameter list", code = E0415)]
pub(crate) struct IdentifierBoundMoreThanOnceInParameterList {
#[primary_span]
#[label("used as parameter more than once")]
pub(crate) span: Span,
pub(crate) identifier: Ident,
}
#[derive(Diagnostic)]
#[diag("identifier `{$identifier}` is bound more than once in the same pattern", code = E0416)]
pub(crate) struct IdentifierBoundMoreThanOnceInSamePattern {
#[primary_span]
#[label("used in a pattern more than once")]
pub(crate) span: Span,
pub(crate) identifier: Ident,
}
#[derive(Diagnostic)]
#[diag("use of undeclared label `{$name}`", code = E0426)]
pub(crate) struct UndeclaredLabel {
#[primary_span]
#[label("undeclared label `{$name}`")]
pub(crate) span: Span,
pub(crate) name: Symbol,
#[subdiagnostic]
pub(crate) sub_reachable: Option<LabelWithSimilarNameReachable>,
#[subdiagnostic]
pub(crate) sub_reachable_suggestion: Option<TryUsingSimilarlyNamedLabel>,
#[subdiagnostic]
pub(crate) sub_unreachable: Option<UnreachableLabelWithSimilarNameExists>,
}
#[derive(Subdiagnostic)]
#[label("a label with a similar name is reachable")]
pub(crate) struct LabelWithSimilarNameReachable(#[primary_span] pub(crate) Span);
#[derive(Subdiagnostic)]
#[suggestion(
"try using similarly named label",
code = "{ident_name}",
applicability = "maybe-incorrect"
)]
pub(crate) struct TryUsingSimilarlyNamedLabel {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident_name: Symbol,
}
#[derive(Subdiagnostic)]
#[label("a label with a similar name exists but is unreachable")]
pub(crate) struct UnreachableLabelWithSimilarNameExists {
#[primary_span]
pub(crate) ident_span: Span,
}
#[derive(Diagnostic)]
#[diag("can't capture dynamic environment in a fn item", code = E0434)]
#[help("use the `|| {\"{\"} ... {\"}\"}` closure form instead")]
pub(crate) struct CannotCaptureDynamicEnvironmentInFnItem {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("attempt to use a non-constant value in a constant", code = E0435)]
pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> {
#[primary_span]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) with: Option<AttemptToUseNonConstantValueInConstantWithSuggestion<'a>>,
#[subdiagnostic]
pub(crate) with_label: Option<AttemptToUseNonConstantValueInConstantLabelWithSuggestion>,
#[subdiagnostic]
pub(crate) without: Option<AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a>>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"consider using `{$suggestion}` instead of `{$current}`",
style = "verbose",
applicability = "has-placeholders"
)]
pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> {
// #[primary_span]
#[suggestion_part(code = "{suggestion} ")]
pub(crate) span: Span,
pub(crate) suggestion: &'a str,
#[suggestion_part(code = ": /* Type */")]
pub(crate) type_span: Option<Span>,
pub(crate) current: &'a str,
}
#[derive(Subdiagnostic)]
#[label("non-constant value")]
pub(crate) struct AttemptToUseNonConstantValueInConstantLabelWithSuggestion {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[label("this would need to be a `{$suggestion}`")]
pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> {
#[primary_span]
pub(crate) ident_span: Span,
pub(crate) suggestion: &'a str,
}
#[derive(Diagnostic)]
#[diag("`self` imports are only allowed within a {\"{\"} {\"}\"} list", code = E0429)]
pub(crate) struct SelfImportsOnlyAllowedWithin {
#[primary_span]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) suggestion: Option<SelfImportsOnlyAllowedWithinSuggestion>,
#[subdiagnostic]
pub(crate) mpart_suggestion: Option<SelfImportsOnlyAllowedWithinMultipartSuggestion>,
}
#[derive(Subdiagnostic)]
#[suggestion(
"consider importing the module directly",
code = "",
applicability = "machine-applicable"
)]
pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"alternatively, use the multi-path `use` syntax to import `self`",
applicability = "machine-applicable"
)]
pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion {
#[suggestion_part(code = "{{")]
pub(crate) multipart_start: Span,
#[suggestion_part(code = "}}")]
pub(crate) multipart_end: Span,
}
#[derive(Diagnostic)]
#[diag("{$shadowing_binding}s cannot shadow {$shadowed_binding}s", code = E0530)]
pub(crate) struct BindingShadowsSomethingUnacceptable<'a> {
#[primary_span]
#[label("cannot be named the same as {$article} {$shadowed_binding}")]
pub(crate) span: Span,
pub(crate) shadowing_binding: PatternSource,
pub(crate) shadowed_binding: Res,
pub(crate) article: &'a str,
#[subdiagnostic]
pub(crate) sub_suggestion: Option<BindingShadowsSomethingUnacceptableSuggestion>,
#[label("the {$shadowed_binding} `{$name}` is {$participle} here")]
pub(crate) shadowed_binding_span: Span,
pub(crate) participle: &'a str,
pub(crate) name: Symbol,
}
#[derive(Subdiagnostic)]
#[suggestion(
"try specify the pattern arguments",
code = "{name}(..)",
applicability = "unspecified"
)]
pub(crate) struct BindingShadowsSomethingUnacceptableSuggestion {
#[primary_span]
pub(crate) span: Span,
pub(crate) name: Symbol,
}
#[derive(Diagnostic)]
#[diag("generic parameter defaults cannot reference parameters before they are declared", code = E0128)]
pub(crate) struct ForwardDeclaredGenericParam {
#[primary_span]
#[label("cannot reference `{$param}` before it is declared")]
pub(crate) span: Span,
pub(crate) param: Symbol,
}
#[derive(Diagnostic)]
#[diag("const parameter types cannot reference parameters before they are declared")]
pub(crate) struct ForwardDeclaredGenericInConstParamTy {
#[primary_span]
#[label("const parameter type cannot reference `{$param}` before it is declared")]
pub(crate) span: Span,
pub(crate) param: Symbol,
}
#[derive(Diagnostic)]
#[diag("the type of const parameters must not depend on other generic parameters", code = E0770)]
pub(crate) struct ParamInTyOfConstParam {
#[primary_span]
#[label("the type must not depend on the parameter `{$name}`")]
pub(crate) span: Span,
pub(crate) name: Symbol,
}
#[derive(Diagnostic)]
#[diag("generic parameters cannot use `Self` in their defaults", code = E0735)]
pub(crate) struct SelfInGenericParamDefault {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("cannot use `Self` in const parameter type")]
pub(crate) struct SelfInConstGenericTy {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag(
"{$is_ogca ->
[true] generic parameters in const blocks are only allowed as the direct value of a `type const`
*[false] generic parameters may not be used in const operations
}"
)]
pub(crate) struct ParamInNonTrivialAnonConst {
#[primary_span]
#[label("cannot perform const operation using `{$name}`")]
pub(crate) span: Span,
pub(crate) name: Symbol,
#[subdiagnostic]
pub(crate) param_kind: ParamKindInNonTrivialAnonConst,
#[help("add `#![feature(generic_const_exprs)]` to allow generic const expressions")]
pub(crate) help: bool,
pub(crate) is_ogca: bool,
#[help(
"consider factoring the expression into a `type const` item and use it as the const argument instead"
)]
pub(crate) help_ogca: bool,
}
#[derive(Debug)]
#[derive(Subdiagnostic)]
pub(crate) enum ParamKindInNonTrivialAnonConst {
#[note("type parameters may not be used in const expressions")]
Type,
#[help("const parameters may only be used as standalone arguments here, i.e. `{$name}`")]
Const { name: Symbol },
#[note("lifetime parameters may not be used in const expressions")]
Lifetime,
}
#[derive(Diagnostic)]
#[diag("use of unreachable label `{$name}`", code = E0767)]
#[note("labels are unreachable through functions, closures, async blocks and modules")]
pub(crate) struct UnreachableLabel {
#[primary_span]
#[label("unreachable label `{$name}`")]
pub(crate) span: Span,
pub(crate) name: Symbol,
#[label("unreachable label defined here")]
pub(crate) definition_span: Span,
#[subdiagnostic]
pub(crate) sub_suggestion: Option<UnreachableLabelSubSuggestion>,
#[subdiagnostic]
pub(crate) sub_suggestion_label: Option<UnreachableLabelSubLabel>,
#[subdiagnostic]
pub(crate) sub_unreachable_label: Option<UnreachableLabelSubLabelUnreachable>,
}
#[derive(Subdiagnostic)]
#[suggestion(
"try using similarly named label",
code = "{ident_name}",
applicability = "maybe-incorrect"
)]
pub(crate) struct UnreachableLabelSubSuggestion {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident_name: Symbol,
}
#[derive(Subdiagnostic)]
#[label("a label with a similar name is reachable")]
pub(crate) struct UnreachableLabelSubLabel {
#[primary_span]
pub(crate) ident_span: Span,
}
#[derive(Subdiagnostic)]
#[label("a label with a similar name exists but is also unreachable")]
pub(crate) struct UnreachableLabelSubLabelUnreachable {
#[primary_span]
pub(crate) ident_span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid `sym` operand")]
#[help("`sym` operands must refer to either a function or a static")]
pub(crate) struct InvalidAsmSym {
#[primary_span]
#[label("is a local variable")]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("attempt to use a non-constant value in a constant")]
pub(crate) struct LowercaseSelf {
#[primary_span]
#[suggestion(
"try using `Self`",
code = "Self",
applicability = "maybe-incorrect",
style = "short"
)]
pub(crate) span: Span,
}
#[derive(Debug)]
#[derive(Diagnostic)]
#[diag("never patterns cannot contain variable bindings")]
pub(crate) struct BindingInNeverPattern {
#[primary_span]
#[suggestion(
"use a wildcard `_` instead",
code = "_",
applicability = "machine-applicable",
style = "short"
)]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("duplicate definitions with name `{$name}`:", code = E0201)]
pub(crate) struct TraitImplDuplicate {
#[primary_span]
#[label("duplicate definition")]
pub(crate) span: Span,
#[label("previous definition here")]
pub(crate) old_span: Span,
#[label("item in trait")]
pub(crate) trait_item_span: Span,
pub(crate) name: Ident,
}
#[derive(Diagnostic)]
#[diag("relative paths are not supported in visibilities in 2018 edition or later")]
pub(crate) struct Relative2018 {
#[primary_span]
pub(crate) span: Span,
#[suggestion("try", code = "crate::{path_str}", applicability = "maybe-incorrect")]
pub(crate) path_span: Span,
pub(crate) path_str: String,
}
#[derive(Diagnostic)]
#[diag("visibilities can only be restricted to ancestor modules", code = E0742)]
pub(crate) struct AncestorOnly(#[primary_span] pub(crate) Span);
#[derive(Diagnostic)]
#[diag("expected module, found {$res} `{$path_str}`", code = E0577)]
pub(crate) struct ExpectedModuleFound {
#[primary_span]
#[label("not a module")]
pub(crate) span: Span,
pub(crate) res: Res,
pub(crate) path_str: String,
}
#[derive(Diagnostic)]
#[diag("cannot determine resolution for the visibility", code = E0578)]
pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span);
#[derive(Diagnostic)]
#[diag("trait implementation can only be restricted to ancestor modules")]
pub(crate) struct RestrictionAncestorOnly(#[primary_span] pub(crate) Span);
#[derive(Diagnostic)]
#[diag("cannot use a tool module through an import")]
pub(crate) struct ToolModuleImported {
#[primary_span]
pub(crate) span: Span,
#[note("the tool module imported here")]
pub(crate) import: Span,
}
#[derive(Diagnostic)]
#[diag("visibility must resolve to a module")]
pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span);
#[derive(Diagnostic)]
#[diag("expected {$expected}, found {$found} `{$macro_path}`")]
pub(crate) struct MacroExpectedFound<'a> {
#[primary_span]
#[label("not {$article} {$expected}")]
pub(crate) span: Span,
pub(crate) found: &'a str,
pub(crate) article: &'static str,
pub(crate) expected: &'a str,
pub(crate) macro_path: &'a str,
#[subdiagnostic]
pub(crate) remove_surrounding_derive: Option<RemoveSurroundingDerive>,
#[subdiagnostic]
pub(crate) add_as_non_derive: Option<AddAsNonDerive<'a>>,
}
#[derive(Subdiagnostic)]
#[help("remove from the surrounding `derive()`")]
pub(crate) struct RemoveSurroundingDerive {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[help(
"
add as non-Derive macro
`#[{$macro_path}]`"
)]
pub(crate) struct AddAsNonDerive<'a> {
pub(crate) macro_path: &'a str,
}
#[derive(Diagnostic)]
#[diag("can't use a procedural macro from the same crate that defines it")]
pub(crate) struct ProcMacroSameCrate {
#[primary_span]
pub(crate) span: Span,
#[help("you can define integration tests in a directory named `tests`")]
pub(crate) is_test: bool,
}
#[derive(Diagnostic)]
#[diag("cannot find {$ns_descr} `{$ident}` in this scope")]
pub(crate) struct ProcMacroDeriveResolutionFallback {
#[label("names from parent modules are not accessible without an explicit import")]
pub span: Span,
pub ns_descr: &'static str,
pub ident: Symbol,
}
#[derive(Diagnostic)]
#[diag(
"macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths"
)]
pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
#[note("the macro is defined here")]
pub definition: Span,
}
#[derive(Diagnostic)]
#[diag("`#[macro_use]` is not supported on `extern crate self`")]
pub(crate) struct MacroUseExternCrateSelf {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("not sure whether the path is accessible or not")]
#[note("the type may have associated items, but we are currently not checking them")]
pub(crate) struct CfgAccessibleUnsure {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Debug)]
#[derive(Diagnostic)]
#[diag("generic parameters may not be used in enum discriminant values")]
pub(crate) struct ParamInEnumDiscriminant {
#[primary_span]
#[label("cannot perform const operation using `{$name}`")]
pub(crate) span: Span,
pub(crate) name: Symbol,
#[subdiagnostic]
pub(crate) param_kind: ParamKindInEnumDiscriminant,
}
#[derive(Debug)]
#[derive(Subdiagnostic)]
pub(crate) enum ParamKindInEnumDiscriminant {
#[note("type parameters may not be used in enum discriminant values")]
Type,
#[note("const parameters may not be used in enum discriminant values")]
Const,
#[note("lifetime parameters may not be used in enum discriminant values")]
Lifetime,
}
#[derive(Subdiagnostic)]
#[label("you can use `as` to change the binding name of the import")]
pub(crate) struct ChangeImportBinding {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
"you can use `as` to change the binding name of the import",
code = "{suggestion}",
applicability = "maybe-incorrect"
)]
pub(crate) struct ChangeImportBindingSuggestion {
#[primary_span]
pub(crate) span: Span,
pub(crate) suggestion: String,
}
#[derive(Diagnostic)]
#[diag("imports cannot refer to {$what}")]
pub(crate) struct ImportsCannotReferTo<'a> {
#[primary_span]
pub(crate) span: Span,
pub(crate) what: &'a str,
}
#[derive(Diagnostic)]
#[diag("cannot find {$expected} `{$ident}` in this scope")]
pub(crate) struct CannotFindIdentInThisScope<'a> {
#[primary_span]
pub(crate) span: Span,
pub(crate) expected: &'a str,
pub(crate) ident: Ident,
}
#[derive(Subdiagnostic)]
#[note("unsafe traits like `{$ident}` should be implemented explicitly")]
pub(crate) struct ExplicitUnsafeTraits {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Subdiagnostic)]
#[note("a macro with the same name exists, but it appears later")]
pub(crate) struct MacroDefinedLater {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[label("consider moving the definition of `{$ident}` before this call")]
pub(crate) struct MacroSuggMovePosition {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Subdiagnostic)]
pub(crate) enum MacroRulesNot {
#[label("`{$ident}` exists, but has no rules for function-like invocation")]
Func {
#[primary_span]
span: Span,
ident: Ident,
},
#[label("`{$ident}` exists, but has no `attr` rules")]
Attr {
#[primary_span]
span: Span,
ident: Ident,
},
#[label("`{$ident}` exists, but has no `derive` rules")]
Derive {
#[primary_span]
span: Span,
ident: Ident,
},
}
#[derive(Subdiagnostic)]
#[note("maybe you have forgotten to define a name for this `macro_rules!`")]
pub(crate) struct MaybeMissingMacroRulesName {
#[primary_span]
pub(crate) spans: MultiSpan,
}
#[derive(Subdiagnostic)]
#[help("have you added the `#[macro_use]` on the module/import?")]
pub(crate) struct AddedMacroUse;
#[derive(Subdiagnostic)]
#[suggestion("consider adding a derive", code = "{suggestion}", applicability = "maybe-incorrect")]
pub(crate) struct ConsiderAddingADerive {
#[primary_span]
pub(crate) span: Span,
pub(crate) suggestion: String,
}
#[derive(Diagnostic)]
#[diag("cannot determine resolution for the import")]
pub(crate) struct CannotDetermineImportResolution {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("cannot determine resolution for the {$kind} `{$path}`")]
#[note("import resolution is stuck, try simplifying macro imports")]
pub(crate) struct CannotDetermineMacroResolution {
#[primary_span]
pub(crate) span: Span,
pub(crate) kind: &'static str,
pub(crate) path: String,
}
#[derive(Diagnostic)]
#[diag("`{$ident}` is private, and cannot be re-exported", code = E0364)]
pub(crate) struct CannotBeReexportedPrivate {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("`{$ident}` is only public within the crate, and cannot be re-exported outside", code = E0364)]
pub(crate) struct CannotBeReexportedCratePublic {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("`{$ident}` is private, and cannot be re-exported", code = E0365)]
#[note("consider declaring type or module `{$ident}` with `pub`")]
pub(crate) struct CannotBeReexportedPrivateNS {
#[primary_span]
#[label("re-export of private `{$ident}`")]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("`{$ident}` is only public within the crate, and cannot be re-exported outside", code = E0365)]
#[note("consider declaring type or module `{$ident}` with `pub`")]
pub(crate) struct CannotBeReexportedCratePublicNS {
#[primary_span]
#[label("re-export of crate public `{$ident}`")]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("extern crate `{$ident}` is private and cannot be re-exported", code = E0365)]
pub(crate) struct PrivateExternCrateReexport {
pub ident: Ident,
#[suggestion(
"consider making the `extern crate` item publicly accessible",
code = "pub ",
style = "verbose",
applicability = "maybe-incorrect"
)]
pub sugg: Span,
}
#[derive(Subdiagnostic)]
#[help("consider adding a `#[macro_export]` to the macro in the imported module")]
pub(crate) struct ConsiderAddingMacroExport {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
"in case you want to use the macro within this crate only, reduce the visibility to `pub(crate)`",
code = "pub(crate)",
applicability = "maybe-incorrect"
)]
pub(crate) struct ConsiderMarkingAsPubCrate {
#[primary_span]
pub(crate) vis_span: Span,
}
#[derive(Subdiagnostic)]
#[note("consider marking `{$ident}` as `pub` in the imported module")]
pub(crate) struct ConsiderMarkingAsPub {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("cannot glob-import all possible crates")]
pub(crate) struct CannotGlobImportAllCrates {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
"you might have meant to write a const parameter here",
code = "const ",
style = "verbose"
)]
pub(crate) struct UnexpectedResChangeTyToConstParamSugg {
#[primary_span]
pub span: Span,
#[applicability]
pub applicability: Applicability,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"you might have meant to write a const parameter here",
applicability = "has-placeholders",
style = "verbose"
)]
pub(crate) struct UnexpectedResChangeTyParamToConstParamSugg {
#[suggestion_part(code = "const ")]
pub before: Span,
#[suggestion_part(code = ": /* Type */")]
pub after: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
"if you meant to collect the rest of the slice in `{$ident}`, use the at operator",
code = "{snippet}",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct UnexpectedResUseAtOpInSlicePatWithRangeSugg {
#[primary_span]
pub span: Span,
pub ident: Ident,
pub snippet: String,
}
#[derive(Diagnostic)]
#[diag("an `extern crate` loading macros must be at the crate root", code = E0468)]
pub(crate) struct ExternCrateLoadingMacroNotAtCrateRoot {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("`extern crate self;` requires renaming")]
pub(crate) struct ExternCrateSelfRequiresRenaming {
#[primary_span]
#[suggestion(
"rename the `self` crate to be able to import it",
code = "extern crate self as name;",
applicability = "has-placeholders"
)]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("`{$name}` is already in scope")]
#[note("macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)")]
pub(crate) struct MacroUseNameAlreadyInUse {
#[primary_span]
pub(crate) span: Span,
pub(crate) name: Symbol,
}
#[derive(Diagnostic)]
#[diag("imported macro not found", code = E0469)]
pub(crate) struct ImportedMacroNotFound {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("`#[macro_escape]` is a deprecated synonym for `#[macro_use]`")]
pub(crate) struct MacroExternDeprecated {
#[primary_span]
pub(crate) span: Span,
#[help("try an outer attribute: `#[macro_use]`")]
pub inner_attribute: bool,
}
#[derive(Diagnostic)]
#[diag("arguments to `macro_use` are not allowed here")]
pub(crate) struct ArgumentsMacroUseNotAllowed {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"try renaming it with a name",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct UnnamedImportSugg {
#[suggestion_part(code = "{ident} as name")]
pub(crate) span: Span,
pub(crate) ident: Ident,
}
#[derive(Diagnostic)]
#[diag("imports need to be explicitly named")]
pub(crate) struct UnnamedImport {
#[primary_span]
pub(crate) span: Span,
#[subdiagnostic]
pub(crate) sugg: Option<UnnamedImportSugg>,
}
#[derive(Diagnostic)]
#[diag("macro-expanded `extern crate` items cannot shadow names passed with `--extern`")]
pub(crate) struct MacroExpandedExternCrateCannotShadowExternArguments {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Diagnostic)]
#[diag("`&` without an explicit lifetime name cannot be used here", code = E0637)]
pub(crate) struct ElidedAnonymousLifetimeReportError {
#[primary_span]
#[label("explicit lifetime name needed here")]