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
4443 lines (4095 loc) · 120 KB
/
errors.rs
File metadata and controls
4443 lines (4095 loc) · 120 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
// ignore-tidy-filelength
use std::borrow::Cow;
use std::path::PathBuf;
use rustc_ast::token::{self, InvisibleOrigin, MetaVarKind, Token};
use rustc_ast::util::parser::ExprPrecedence;
use rustc_ast::{Path, Visibility};
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg,
Level, Subdiagnostic, SuggestionStyle, inline_fluent,
};
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::edition::{Edition, LATEST_STABLE_EDITION};
use rustc_span::{Ident, Span, Symbol};
#[derive(Diagnostic)]
#[diag("ambiguous `+` in a type")]
pub(crate) struct AmbiguousPlus {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub suggestion: AddParen,
}
#[derive(Diagnostic)]
#[diag("expected a path on the left-hand side of `+`", code = E0178)]
pub(crate) struct BadTypePlus {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: BadTypePlusSub,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("try adding parentheses", applicability = "machine-applicable")]
pub(crate) struct AddParen {
#[suggestion_part(code = "(")]
pub lo: Span,
#[suggestion_part(code = ")")]
pub hi: Span,
}
#[derive(Subdiagnostic)]
pub(crate) enum BadTypePlusSub {
AddParen {
#[subdiagnostic]
suggestion: AddParen,
},
#[label("perhaps you forgot parentheses?")]
ForgotParen {
#[primary_span]
span: Span,
},
#[label("expected a path")]
ExpectPath {
#[primary_span]
span: Span,
},
}
#[derive(Diagnostic)]
#[diag("missing angle brackets in associated item path")]
pub(crate) struct BadQPathStage2 {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub wrap: WrapType,
}
#[derive(Diagnostic)]
#[diag("inherent impls cannot be {$modifier_name}")]
#[note("only trait implementations may be annotated with `{$modifier}`")]
pub(crate) struct TraitImplModifierInInherentImpl {
#[primary_span]
pub span: Span,
pub modifier: &'static str,
pub modifier_name: &'static str,
#[label("{$modifier_name} because of this")]
pub modifier_span: Span,
#[label("inherent impl for this type")]
pub self_ty: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"types that don't start with an identifier need to be surrounded with angle brackets in qualified paths",
applicability = "machine-applicable"
)]
pub(crate) struct WrapType {
#[suggestion_part(code = "<")]
pub lo: Span,
#[suggestion_part(code = ">")]
pub hi: Span,
}
#[derive(Diagnostic)]
#[diag("expected item, found `;`")]
pub(crate) struct IncorrectSemicolon<'a> {
#[primary_span]
#[suggestion(
"remove this semicolon",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
#[help("{$name} declarations are not followed by a semicolon")]
pub show_help: bool,
pub name: &'a str,
}
#[derive(Diagnostic)]
#[diag("incorrect use of `await`")]
pub(crate) struct IncorrectUseOfAwait {
#[primary_span]
#[suggestion(
"`await` is not a method call, remove the parentheses",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("incorrect use of `use`")]
pub(crate) struct IncorrectUseOfUse {
#[primary_span]
#[suggestion(
"`use` is not a method call, try removing the parentheses",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("`await` is a postfix operation", applicability = "machine-applicable")]
pub(crate) struct AwaitSuggestion {
#[suggestion_part(code = "")]
pub removal: Span,
#[suggestion_part(code = ".await{question_mark}")]
pub dot_await: Span,
pub question_mark: &'static str,
}
#[derive(Diagnostic)]
#[diag("incorrect use of `await`")]
pub(crate) struct IncorrectAwait {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub suggestion: AwaitSuggestion,
}
#[derive(Diagnostic)]
#[diag("expected iterable, found keyword `in`")]
pub(crate) struct InInTypo {
#[primary_span]
pub span: Span,
#[suggestion(
"remove the duplicated `in`",
code = "",
style = "verbose",
applicability = "machine-applicable"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid variable declaration")]
pub(crate) struct InvalidVariableDeclaration {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: InvalidVariableDeclarationSub,
}
#[derive(Subdiagnostic)]
pub(crate) enum InvalidVariableDeclarationSub {
#[suggestion(
"switch the order of `mut` and `let`",
style = "verbose",
applicability = "maybe-incorrect",
code = "let mut"
)]
SwitchMutLetOrder(#[primary_span] Span),
#[suggestion(
"missing keyword",
applicability = "machine-applicable",
style = "verbose",
code = "let mut"
)]
MissingLet(#[primary_span] Span),
#[suggestion(
"write `let` instead of `auto` to introduce a new variable",
style = "verbose",
applicability = "machine-applicable",
code = "let"
)]
UseLetNotAuto(#[primary_span] Span),
#[suggestion(
"write `let` instead of `var` to introduce a new variable",
style = "verbose",
applicability = "machine-applicable",
code = "let"
)]
UseLetNotVar(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("switch the order of `ref` and `box`")]
pub(crate) struct SwitchRefBoxOrder {
#[primary_span]
#[suggestion(
"swap them",
applicability = "machine-applicable",
style = "verbose",
code = "box ref"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid comparison operator `{$invalid}`")]
pub(crate) struct InvalidComparisonOperator {
#[primary_span]
pub span: Span,
pub invalid: String,
#[subdiagnostic]
pub sub: InvalidComparisonOperatorSub,
}
#[derive(Subdiagnostic)]
pub(crate) enum InvalidComparisonOperatorSub {
#[suggestion(
"`{$invalid}` is not a valid comparison operator, use `{$correct}`",
style = "verbose",
applicability = "machine-applicable",
code = "{correct}"
)]
Correctable {
#[primary_span]
span: Span,
invalid: String,
correct: String,
},
#[label("`<=>` is not a valid comparison operator, use `std::cmp::Ordering`")]
Spaceship(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("`{$incorrect}` is not a logical operator")]
#[note("unlike in e.g., Python and PHP, `&&` and `||` are used for logical operators")]
pub(crate) struct InvalidLogicalOperator {
#[primary_span]
pub span: Span,
pub incorrect: String,
#[subdiagnostic]
pub sub: InvalidLogicalOperatorSub,
}
#[derive(Subdiagnostic)]
pub(crate) enum InvalidLogicalOperatorSub {
#[suggestion(
"use `&&` to perform logical conjunction",
style = "verbose",
applicability = "machine-applicable",
code = "&&"
)]
Conjunction(#[primary_span] Span),
#[suggestion(
"use `||` to perform logical disjunction",
style = "verbose",
applicability = "machine-applicable",
code = "||"
)]
Disjunction(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("`~` cannot be used as a unary operator")]
pub(crate) struct TildeAsUnaryOperator(
#[primary_span]
#[suggestion(
"use `!` to perform bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
)]
pub Span,
);
#[derive(Diagnostic)]
#[diag("unexpected {$negated_desc} after identifier")]
pub(crate) struct NotAsNegationOperator {
#[primary_span]
pub negated: Span,
pub negated_desc: String,
#[subdiagnostic]
pub sub: NotAsNegationOperatorSub,
}
#[derive(Subdiagnostic)]
pub(crate) enum NotAsNegationOperatorSub {
#[suggestion(
"use `!` to perform logical negation or bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
)]
SuggestNotDefault(#[primary_span] Span),
#[suggestion(
"use `!` to perform bitwise not",
style = "verbose",
applicability = "machine-applicable",
code = "!"
)]
SuggestNotBitwise(#[primary_span] Span),
#[suggestion(
"use `!` to perform logical negation",
style = "verbose",
applicability = "machine-applicable",
code = "!"
)]
SuggestNotLogical(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("malformed loop label")]
pub(crate) struct MalformedLoopLabel {
#[primary_span]
pub span: Span,
#[suggestion(
"use the correct loop label format",
applicability = "machine-applicable",
code = "'",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag("borrow expressions cannot be annotated with lifetimes")]
pub(crate) struct LifetimeInBorrowExpression {
#[primary_span]
pub span: Span,
#[suggestion(
"remove the lifetime annotation",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
#[label("annotated with lifetime here")]
pub lifetime_span: Span,
}
#[derive(Diagnostic)]
#[diag("field expressions cannot have generic arguments")]
pub(crate) struct FieldExpressionWithGeneric(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag("macros cannot use qualified paths")]
pub(crate) struct MacroInvocationWithQualifiedPath(#[primary_span] pub Span);
#[derive(Diagnostic)]
#[diag("expected `while`, `for`, `loop` or `{\"{\"}` after a label")]
pub(crate) struct UnexpectedTokenAfterLabel {
#[primary_span]
#[label("expected `while`, `for`, `loop` or `{\"{\"}` after a label")]
pub span: Span,
#[suggestion("consider removing the label", style = "verbose", code = "")]
pub remove_label: Option<Span>,
#[subdiagnostic]
pub enclose_in_block: Option<UnexpectedTokenAfterLabelSugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"consider enclosing expression in a block",
applicability = "machine-applicable"
)]
pub(crate) struct UnexpectedTokenAfterLabelSugg {
#[suggestion_part(code = "{{ ")]
pub left: Span,
#[suggestion_part(code = " }}")]
pub right: Span,
}
#[derive(Diagnostic)]
#[diag("labeled expression must be followed by `:`")]
#[note("labels are used before loops and blocks, allowing e.g., `break 'label` to them")]
pub(crate) struct RequireColonAfterLabeledExpression {
#[primary_span]
pub span: Span,
#[label("the label")]
pub label: Span,
#[suggestion(
"add `:` after the label",
style = "verbose",
applicability = "machine-applicable",
code = ": "
)]
pub label_end: Span,
}
#[derive(Diagnostic)]
#[diag("found removed `do catch` syntax")]
#[note("following RFC #2388, the new non-placeholder syntax is `try`")]
pub(crate) struct DoCatchSyntaxRemoved {
#[primary_span]
#[suggestion(
"replace with the new syntax",
applicability = "machine-applicable",
code = "try",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("float literals must have an integer part")]
pub(crate) struct FloatLiteralRequiresIntegerPart {
#[primary_span]
pub span: Span,
#[suggestion(
"must have an integer part",
applicability = "machine-applicable",
code = "0",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag("expected `;`, found `[`")]
pub(crate) struct MissingSemicolonBeforeArray {
#[primary_span]
pub open_delim: Span,
#[suggestion(
"consider adding `;` here",
style = "verbose",
applicability = "maybe-incorrect",
code = ";"
)]
pub semicolon: Span,
}
#[derive(Diagnostic)]
#[diag("expected `..`, found `...`")]
pub(crate) struct MissingDotDot {
#[primary_span]
pub token_span: Span,
#[suggestion(
"use `..` to fill in the rest of the fields",
applicability = "maybe-incorrect",
code = "..",
style = "verbose"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag("cannot use a `block` macro fragment here")]
pub(crate) struct InvalidBlockMacroSegment {
#[primary_span]
pub span: Span,
#[label("the `block` fragment is within this context")]
pub context: Span,
#[subdiagnostic]
pub wrap: WrapInExplicitBlock,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("wrap this in another block", applicability = "machine-applicable")]
pub(crate) struct WrapInExplicitBlock {
#[suggestion_part(code = "{{ ")]
pub lo: Span,
#[suggestion_part(code = " }}")]
pub hi: Span,
}
#[derive(Diagnostic)]
#[diag("this `if` expression is missing a block after the condition")]
pub(crate) struct IfExpressionMissingThenBlock {
#[primary_span]
pub if_span: Span,
#[subdiagnostic]
pub missing_then_block_sub: IfExpressionMissingThenBlockSub,
#[subdiagnostic]
pub let_else_sub: Option<IfExpressionLetSomeSub>,
}
#[derive(Subdiagnostic)]
pub(crate) enum IfExpressionMissingThenBlockSub {
#[help("this binary operation is possibly unfinished")]
UnfinishedCondition(#[primary_span] Span),
#[help("add a block here")]
AddThenBlock(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("Rust has no ternary operator")]
pub(crate) struct TernaryOperator {
#[primary_span]
pub span: Span,
/// If we have a span for the condition expression, suggest the if/else
#[subdiagnostic]
pub sugg: Option<TernaryOperatorSuggestion>,
/// Otherwise, just print the suggestion message
#[help("use an `if-else` expression instead")]
pub no_sugg: bool,
}
#[derive(Subdiagnostic, Copy, Clone)]
#[multipart_suggestion(
"use an `if-else` expression instead",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct TernaryOperatorSuggestion {
#[suggestion_part(code = "if ")]
pub before_cond: Span,
#[suggestion_part(code = "{{")]
pub question: Span,
#[suggestion_part(code = "}} else {{")]
pub colon: Span,
#[suggestion_part(code = " }}")]
pub end: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
"remove the `if` if you meant to write a `let...else` statement",
applicability = "maybe-incorrect",
code = "",
style = "verbose"
)]
pub(crate) struct IfExpressionLetSomeSub {
#[primary_span]
pub if_span: Span,
}
#[derive(Diagnostic)]
#[diag("missing condition for `if` expression")]
pub(crate) struct IfExpressionMissingCondition {
#[primary_span]
#[label("expected condition here")]
pub if_span: Span,
#[label(
"if this block is the condition of the `if` expression, then it must be followed by another block"
)]
pub block_span: Span,
}
#[derive(Diagnostic)]
#[diag("expected expression, found `let` statement")]
#[note("only supported directly in conditions of `if` and `while` expressions")]
pub(crate) struct ExpectedExpressionFoundLet {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub reason: ForbiddenLetReason,
#[subdiagnostic]
pub missing_let: Option<MaybeMissingLet>,
#[subdiagnostic]
pub comparison: Option<MaybeComparison>,
}
#[derive(Diagnostic)]
#[diag("`||` operators are not supported in let chain conditions")]
pub(crate) struct OrInLetChain {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic, Clone, Copy)]
#[multipart_suggestion(
"you might have meant to continue the let-chain",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct MaybeMissingLet {
#[suggestion_part(code = "let ")]
pub span: Span,
}
#[derive(Subdiagnostic, Clone, Copy)]
#[multipart_suggestion(
"you might have meant to compare for equality",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct MaybeComparison {
#[suggestion_part(code = "=")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("expected `=`, found `==`")]
pub(crate) struct ExpectedEqForLetExpr {
#[primary_span]
pub span: Span,
#[suggestion(
"consider using `=` here",
applicability = "maybe-incorrect",
code = "=",
style = "verbose"
)]
pub sugg_span: Span,
}
#[derive(Diagnostic)]
#[diag("expected `{\"{\"}`, found {$first_tok}")]
pub(crate) struct ExpectedElseBlock {
#[primary_span]
pub first_tok_span: Span,
pub first_tok: String,
#[label("expected an `if` or a block after this `else`")]
pub else_span: Span,
#[suggestion(
"add an `if` if this is the condition of a chained `else if` statement",
applicability = "maybe-incorrect",
code = "if ",
style = "verbose"
)]
pub condition_start: Span,
}
#[derive(Diagnostic)]
#[diag("expected one of `,`, `:`, or `{\"}\"}`, found `{$token}`")]
pub(crate) struct ExpectedStructField {
#[primary_span]
#[label("expected one of `,`, `:`, or `{\"}\"}`")]
pub span: Span,
pub token: Token,
#[label("while parsing this struct field")]
pub ident_span: Span,
}
#[derive(Diagnostic)]
#[diag("outer attributes are not allowed on `if` and `else` branches")]
pub(crate) struct OuterAttributeNotAllowedOnIfElse {
#[primary_span]
pub last: Span,
#[label("the attributes are attached to this branch")]
pub branch_span: Span,
#[label("the branch belongs to this `{$ctx}`")]
pub ctx_span: Span,
pub ctx: String,
#[suggestion(
"remove the attributes",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
pub attributes: Span,
}
#[derive(Diagnostic)]
#[diag("missing `in` in `for` loop")]
pub(crate) struct MissingInInForLoop {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sub: MissingInInForLoopSub,
}
#[derive(Subdiagnostic)]
pub(crate) enum MissingInInForLoopSub {
// User wrote `for pat of expr {}`
// Has been misleading, at least in the past (closed Issue #48492), thus maybe-incorrect
#[suggestion(
"try using `in` here instead",
style = "verbose",
applicability = "maybe-incorrect",
code = "in"
)]
InNotOf(#[primary_span] Span),
// User wrote `for pat = expr {}`
#[suggestion(
"try using `in` here instead",
style = "verbose",
applicability = "maybe-incorrect",
code = "in"
)]
InNotEq(#[primary_span] Span),
#[suggestion(
"try adding `in` here",
style = "verbose",
applicability = "maybe-incorrect",
code = " in "
)]
AddIn(#[primary_span] Span),
}
#[derive(Diagnostic)]
#[diag("missing expression to iterate on in `for` loop")]
pub(crate) struct MissingExpressionInForLoop {
#[primary_span]
#[suggestion(
"try adding an expression to the `for` loop",
code = "/* expression */ ",
applicability = "has-placeholders",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`{$loop_kind}...else` loops are not supported")]
#[note(
"consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run"
)]
pub(crate) struct LoopElseNotSupported {
#[primary_span]
pub span: Span,
pub loop_kind: &'static str,
#[label("`else` is attached to this loop")]
pub loop_kw: Span,
}
#[derive(Diagnostic)]
#[diag("expected `,` following `match` arm")]
pub(crate) struct MissingCommaAfterMatchArm {
#[primary_span]
#[suggestion(
"missing a comma here to end this `match` arm",
applicability = "machine-applicable",
code = ",",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("keyword `catch` cannot follow a `try` block")]
#[help("try using `match` on the result of the `try` block instead")]
pub(crate) struct CatchAfterTry {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("cannot use a comma after the base struct")]
#[note("the base struct must always be the last field")]
pub(crate) struct CommaAfterBaseStruct {
#[primary_span]
pub span: Span,
#[suggestion(
"remove this comma",
style = "verbose",
applicability = "machine-applicable",
code = ""
)]
pub comma: Span,
}
#[derive(Diagnostic)]
#[diag("expected `:`, found `=`")]
pub(crate) struct EqFieldInit {
#[primary_span]
pub span: Span,
#[suggestion(
"replace equals symbol with a colon",
applicability = "machine-applicable",
code = ":",
style = "verbose"
)]
pub eq: Span,
}
#[derive(Diagnostic)]
#[diag("unexpected token: `...`")]
pub(crate) struct DotDotDot {
#[primary_span]
#[suggestion(
"use `..` for an exclusive range",
applicability = "maybe-incorrect",
code = "..",
style = "verbose"
)]
#[suggestion(
"or `..=` for an inclusive range",
applicability = "maybe-incorrect",
code = "..=",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("unexpected token: `<-`")]
pub(crate) struct LeftArrowOperator {
#[primary_span]
#[suggestion(
"if you meant to write a comparison against a negative value, add a space in between `<` and `-`",
applicability = "maybe-incorrect",
code = "< -",
style = "verbose"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("expected pattern, found `let`")]
pub(crate) struct RemoveLet {
#[primary_span]
pub span: Span,
#[suggestion(
"remove the unnecessary `let` keyword",
applicability = "machine-applicable",
code = "",
style = "verbose"
)]
pub suggestion: Span,
}
#[derive(Diagnostic)]
#[diag("unexpected `==`")]
pub(crate) struct UseEqInstead {
#[primary_span]
#[suggestion(
"try using `=` instead",
style = "verbose",
applicability = "machine-applicable",
code = "="
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("expected { \"`{}`\" }, found `;`")]
pub(crate) struct UseEmptyBlockNotSemi {
#[primary_span]
#[suggestion(
r#"try using { "`{}`" } instead"#,
style = "hidden",
applicability = "machine-applicable",
code = "{{}}"
)]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`<` is interpreted as a start of generic arguments for `{$type}`, not a comparison")]
pub(crate) struct ComparisonInterpretedAsGeneric {
#[primary_span]
#[label("not interpreted as comparison")]
pub comparison: Span,
pub r#type: Path,
#[label("interpreted as generic arguments")]
pub args: Span,
#[subdiagnostic]
pub suggestion: ComparisonInterpretedAsGenericSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("try comparing the cast value", applicability = "machine-applicable")]
pub(crate) struct ComparisonInterpretedAsGenericSugg {
#[suggestion_part(code = "(")]
pub left: Span,
#[suggestion_part(code = ")")]
pub right: Span,
}
#[derive(Diagnostic)]
#[diag("`<<` is interpreted as a start of generic arguments for `{$type}`, not a shift")]
pub(crate) struct ShiftInterpretedAsGeneric {
#[primary_span]
#[label("not interpreted as shift")]
pub shift: Span,
pub r#type: Path,
#[label("interpreted as generic arguments")]
pub args: Span,
#[subdiagnostic]
pub suggestion: ShiftInterpretedAsGenericSugg,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("try shifting the cast value", applicability = "machine-applicable")]
pub(crate) struct ShiftInterpretedAsGenericSugg {
#[suggestion_part(code = "(")]
pub left: Span,
#[suggestion_part(code = ")")]
pub right: Span,
}
#[derive(Diagnostic)]
#[diag("expected expression, found `{$token}`")]
pub(crate) struct FoundExprWouldBeStmt {
#[primary_span]
#[label("expected expression")]
pub span: Span,
pub token: Token,
#[subdiagnostic]
pub suggestion: ExprParenthesesNeeded,
}
#[derive(Diagnostic)]
#[diag("extra characters after frontmatter close are not allowed")]
pub(crate) struct FrontmatterExtraCharactersAfterClose {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid infostring for frontmatter")]
#[note("frontmatter infostrings must be a single identifier immediately following the opening")]
pub(crate) struct FrontmatterInvalidInfostring {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid preceding whitespace for frontmatter opening")]
pub(crate) struct FrontmatterInvalidOpeningPrecedingWhitespace {
#[primary_span]
pub span: Span,
#[note("frontmatter opening should not be preceded by whitespace")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag("unclosed frontmatter")]
pub(crate) struct FrontmatterUnclosed {
#[primary_span]
pub span: Span,
#[note("frontmatter opening here was not closed")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag("invalid preceding whitespace for frontmatter close")]
pub(crate) struct FrontmatterInvalidClosingPrecedingWhitespace {
#[primary_span]
pub span: Span,
#[note("frontmatter close should not be preceded by whitespace")]
pub note_span: Span,
}
#[derive(Diagnostic)]
#[diag("frontmatter close does not match the opening")]
pub(crate) struct FrontmatterLengthMismatch {
#[primary_span]
pub span: Span,
#[label("the opening here has {$len_opening} dashes...")]
pub opening: Span,
#[label("...while the close has {$len_close} dashes")]
pub close: Span,
pub len_opening: usize,
pub len_close: usize,
}
#[derive(Diagnostic)]
#[diag(
"too many `-` symbols: frontmatter openings may be delimited by up to 255 `-` symbols, but found {$len_opening}"
)]
pub(crate) struct FrontmatterTooManyDashes {
pub len_opening: usize,
}
#[derive(Diagnostic)]
#[diag("bare CR not allowed in frontmatter")]
pub(crate) struct BareCrFrontmatter {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("leading `+` is not supported")]
pub(crate) struct LeadingPlusNotSupported {
#[primary_span]
#[label("unexpected `+`")]
pub span: Span,
#[suggestion(
"try removing the `+`",
style = "verbose",
code = "",
applicability = "machine-applicable"
)]
pub remove_plus: Option<Span>,
#[subdiagnostic]
pub add_parentheses: Option<ExprParenthesesNeeded>,
}
#[derive(Diagnostic)]
#[diag("invalid `struct` delimiters or `fn` call arguments")]
pub(crate) struct ParenthesesWithStructFields {
#[primary_span]
pub span: Span,