-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Expand file tree
/
Copy patherrors.rs
More file actions
1946 lines (1789 loc) · 61.9 KB
/
errors.rs
File metadata and controls
1946 lines (1789 loc) · 61.9 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
//! Errors emitted by `rustc_hir_analysis`.
use rustc_abi::ExternAbi;
use rustc_errors::codes::*;
use rustc_errors::{
Applicability, Diag, DiagCtxtHandle, DiagSymbolList, Diagnostic, EmissionGuarantee, Level,
MultiSpan, listify, msg,
};
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_middle::ty::{self, Ty};
use rustc_span::{Ident, Span, Symbol};
pub(crate) mod wrong_number_of_generic_args;
mod precise_captures;
pub(crate) use precise_captures::*;
#[derive(Diagnostic)]
#[diag("ambiguous associated {$assoc_kind} `{$assoc_ident}` in bounds of `{$qself}`")]
pub(crate) struct AmbiguousAssocItem<'a> {
#[primary_span]
#[label("ambiguous associated {$assoc_kind} `{$assoc_ident}`")]
pub span: Span,
pub assoc_kind: &'static str,
pub assoc_ident: Ident,
pub qself: &'a str,
}
#[derive(Diagnostic)]
#[diag("expected {$expected}, found {$got}")]
pub(crate) struct AssocKindMismatch {
#[primary_span]
#[label("unexpected {$got}")]
pub span: Span,
pub expected: &'static str,
pub got: &'static str,
#[label("expected a {$expected} because of this associated {$expected}")]
pub expected_because_label: Option<Span>,
pub assoc_kind: &'static str,
#[note("the associated {$assoc_kind} is defined here")]
pub def_span: Span,
#[label("bounds are not allowed on associated constants")]
pub bound_on_assoc_const_label: Option<Span>,
#[subdiagnostic]
pub wrap_in_braces_sugg: Option<AssocKindMismatchWrapInBracesSugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion("consider adding braces here", applicability = "maybe-incorrect")]
pub(crate) struct AssocKindMismatchWrapInBracesSugg {
#[suggestion_part(code = "{{ ")]
pub lo: Span,
#[suggestion_part(code = " }}")]
pub hi: Span,
}
#[derive(Diagnostic)]
#[diag("{$kind} `{$name}` is private", code = E0624)]
pub(crate) struct AssocItemIsPrivate {
#[primary_span]
#[label("private {$kind}")]
pub span: Span,
pub kind: &'static str,
pub name: Ident,
#[label("the {$kind} is defined here")]
pub defined_here_label: Span,
}
#[derive(Diagnostic)]
#[diag("associated {$assoc_kind} `{$assoc_ident}` not found for `{$qself}`", code = E0220)]
pub(crate) struct AssocItemNotFound<'a> {
#[primary_span]
pub span: Span,
pub assoc_ident: Ident,
pub assoc_kind: &'static str,
pub qself: &'a str,
#[subdiagnostic]
pub label: Option<AssocItemNotFoundLabel<'a>>,
#[subdiagnostic]
pub sugg: Option<AssocItemNotFoundSugg<'a>>,
#[label("due to this macro variable")]
pub within_macro_span: Option<Span>,
}
#[derive(Subdiagnostic)]
pub(crate) enum AssocItemNotFoundLabel<'a> {
#[label("associated {$assoc_kind} `{$assoc_ident}` not found")]
NotFound {
#[primary_span]
span: Span,
assoc_ident: Ident,
assoc_kind: &'static str,
},
#[label(
"there is {$identically_named ->
[true] an
*[false] a similarly named
} associated {$assoc_kind} `{$suggested_name}` in the trait `{$trait_name}`"
)]
FoundInOtherTrait {
#[primary_span]
span: Span,
assoc_kind: &'static str,
trait_name: &'a str,
suggested_name: Symbol,
identically_named: bool,
},
}
#[derive(Subdiagnostic)]
pub(crate) enum AssocItemNotFoundSugg<'a> {
#[suggestion(
"there is an associated {$assoc_kind} with a similar name",
code = "{suggested_name}",
applicability = "maybe-incorrect"
)]
Similar {
#[primary_span]
span: Span,
assoc_kind: &'static str,
suggested_name: Symbol,
},
#[suggestion(
"change the associated {$assoc_kind} name to use `{$suggested_name}` from `{$trait_name}`",
code = "{suggested_name}",
style = "verbose",
applicability = "maybe-incorrect"
)]
SimilarInOtherTrait {
#[primary_span]
span: Span,
trait_name: &'a str,
assoc_kind: &'static str,
suggested_name: Symbol,
},
#[multipart_suggestion(
"consider fully qualifying{$identically_named ->
[true] {\"\"}
*[false] {\" \"}and renaming
} the associated {$assoc_kind}",
style = "verbose"
)]
SimilarInOtherTraitQPath {
#[suggestion_part(code = "<")]
lo: Span,
#[suggestion_part(code = " as {trait_ref}>")]
mi: Span,
#[suggestion_part(code = "{suggested_name}")]
hi: Option<Span>,
trait_ref: String,
suggested_name: Symbol,
identically_named: bool,
assoc_kind: &'static str,
#[applicability]
applicability: Applicability,
},
#[suggestion(
"`{$qself}` has the following associated {$assoc_kind}",
code = "{suggested_name}",
applicability = "maybe-incorrect"
)]
Other {
#[primary_span]
span: Span,
qself: &'a str,
assoc_kind: &'static str,
suggested_name: Symbol,
},
}
#[derive(Diagnostic)]
#[diag("intrinsic has wrong number of {$descr} parameters: found {$found}, expected {$expected}", code = E0094)]
pub(crate) struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
#[primary_span]
#[label(
"expected {$expected} {$descr} {$expected ->
[one] parameter
*[other] parameters
}"
)]
pub span: Span,
pub found: usize,
pub expected: usize,
pub descr: &'a str,
}
#[derive(Diagnostic)]
#[diag("unrecognized intrinsic function: `{$name}`", code = E0093)]
#[help("if you're adding an intrinsic, be sure to update `check_intrinsic_type`")]
pub(crate) struct UnrecognizedIntrinsicFunction {
#[primary_span]
#[label("unrecognized intrinsic")]
pub span: Span,
pub name: Symbol,
}
#[derive(Diagnostic)]
#[diag("lifetime parameters or bounds on {$item_kind} `{$ident}` do not match the trait declaration", code = E0195)]
pub(crate) struct LifetimesOrBoundsMismatchOnTrait {
#[primary_span]
#[label("lifetimes do not match {$item_kind} in trait")]
pub span: Span,
#[label("lifetimes in impl do not match this {$item_kind} in trait")]
pub generics_span: Span,
#[label("this `where` clause might not match the one in the trait")]
pub where_span: Option<Span>,
#[label("this bound might be missing in the impl")]
pub bounds_span: Vec<Span>,
pub item_kind: &'static str,
pub ident: Ident,
}
#[derive(Diagnostic)]
#[diag("the `{$trait_}` trait may only be implemented for local structs, enums, and unions", code = E0120)]
pub(crate) struct DropImplOnWrongItem {
#[primary_span]
#[label("must be a struct, enum, or union in the current crate")]
pub span: Span,
pub trait_: Symbol,
}
#[derive(Diagnostic)]
pub(crate) enum FieldAlreadyDeclared {
#[diag("field `{$field_name}` is already declared", code = E0124)]
NotNested {
field_name: Ident,
#[primary_span]
#[label("field already declared")]
span: Span,
#[label("`{$field_name}` first declared here")]
prev_span: Span,
},
#[diag("field `{$field_name}` is already declared")]
CurrentNested {
field_name: Ident,
#[primary_span]
#[label("field `{$field_name}` declared in this unnamed field")]
span: Span,
#[note("field `{$field_name}` declared here")]
nested_field_span: Span,
#[subdiagnostic]
help: FieldAlreadyDeclaredNestedHelp,
#[label("`{$field_name}` first declared here")]
prev_span: Span,
},
#[diag("field `{$field_name}` is already declared")]
PreviousNested {
field_name: Ident,
#[primary_span]
#[label("field already declared")]
span: Span,
#[label("`{$field_name}` first declared here in this unnamed field")]
prev_span: Span,
#[note("field `{$field_name}` first declared here")]
prev_nested_field_span: Span,
#[subdiagnostic]
prev_help: FieldAlreadyDeclaredNestedHelp,
},
#[diag("field `{$field_name}` is already declared")]
BothNested {
field_name: Ident,
#[primary_span]
#[label("field `{$field_name}` declared in this unnamed field")]
span: Span,
#[note("field `{$field_name}` declared here")]
nested_field_span: Span,
#[subdiagnostic]
help: FieldAlreadyDeclaredNestedHelp,
#[label("`{$field_name}` first declared here in this unnamed field")]
prev_span: Span,
#[note("field `{$field_name}` first declared here")]
prev_nested_field_span: Span,
#[subdiagnostic]
prev_help: FieldAlreadyDeclaredNestedHelp,
},
}
#[derive(Subdiagnostic)]
#[help("fields from the type of this unnamed field are considered fields of the outer type")]
pub(crate) struct FieldAlreadyDeclaredNestedHelp {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `Copy` cannot be implemented for this type; the type has a destructor", code = E0184)]
pub(crate) struct CopyImplOnTypeWithDtor {
#[primary_span]
#[label("`Copy` not allowed on types with destructors")]
pub span: Span,
#[note("destructor declared here")]
pub impl_: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `Copy` cannot be implemented for this type", code = E0206)]
pub(crate) struct CopyImplOnNonAdt {
#[primary_span]
#[label("type is not a structure or enumeration")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this type")]
pub(crate) struct ConstParamTyImplOnUnsized {
#[primary_span]
#[label("type is not `Sized`")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this type")]
pub(crate) struct ConstParamTyImplOnNonAdt {
#[primary_span]
#[label("type is not a structure or enumeration")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this type")]
pub(crate) struct ConstParamTyImplOnNonExhaustive {
#[primary_span]
#[label("non exhaustive const params are forbidden")]
pub defn_span: Span,
#[label("caused by this attribute")]
pub attr_span: Span,
}
#[derive(Diagnostic)]
#[diag("the trait `ConstParamTy` may not be implemented for this struct")]
pub(crate) struct ConstParamTyFieldVisMismatch {
#[primary_span]
#[label("struct fields are less visible than the struct")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("at least one trait is required for an object type", code = E0224)]
pub(crate) struct TraitObjectDeclaredWithNoTraits {
#[primary_span]
pub span: Span,
#[label("this alias does not contain a trait")]
pub trait_alias_span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("ambiguous lifetime bound, explicit lifetime bound required", code = E0227)]
pub(crate) struct AmbiguousLifetimeBound {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("associated item constraints are not allowed here", code = E0229)]
pub(crate) struct AssocItemConstraintsNotAllowedHere {
#[primary_span]
#[label("associated item constraint not allowed here")]
pub span: Span,
#[subdiagnostic]
pub fn_trait_expansion: Option<ParenthesizedFnTraitExpansion>,
}
#[derive(Diagnostic)]
#[diag(
"the type of the associated constant `{$assoc_const}` must not depend on {$param_category ->
[self] `Self`
[synthetic] `impl Trait`
*[normal] generic parameters
}"
)]
pub(crate) struct ParamInTyOfAssocConstBinding<'tcx> {
#[primary_span]
#[label(
"its type must not depend on {$param_category ->
[self] `Self`
[synthetic] `impl Trait`
*[normal] the {$param_def_kind} `{$param_name}`
}"
)]
pub span: Span,
pub assoc_const: Ident,
pub param_name: Symbol,
pub param_def_kind: &'static str,
pub param_category: &'static str,
#[label(
"{$param_category ->
[synthetic] the `impl Trait` is specified here
*[normal] the {$param_def_kind} `{$param_name}` is defined here
}"
)]
pub param_defined_here_label: Option<Span>,
#[subdiagnostic]
pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>,
}
#[derive(Subdiagnostic, Clone, Copy)]
#[note("`{$assoc_const}` has type `{$ty}`")]
pub(crate) struct TyOfAssocConstBindingNote<'tcx> {
pub assoc_const: Ident,
pub ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag(
"the type of the associated constant `{$assoc_const}` cannot capture late-bound generic parameters"
)]
pub(crate) struct EscapingBoundVarInTyOfAssocConstBinding<'tcx> {
#[primary_span]
#[label("its type cannot capture the late-bound {$var_def_kind} `{$var_name}`")]
pub span: Span,
pub assoc_const: Ident,
pub var_name: Symbol,
pub var_def_kind: &'static str,
#[label("the late-bound {$var_def_kind} `{$var_name}` is defined here")]
pub var_defined_here_label: Span,
#[subdiagnostic]
pub ty_note: Option<TyOfAssocConstBindingNote<'tcx>>,
}
#[derive(Subdiagnostic)]
#[help("parenthesized trait syntax expands to `{$expanded_type}`")]
pub(crate) struct ParenthesizedFnTraitExpansion {
#[primary_span]
pub span: Span,
pub expanded_type: String,
}
#[derive(Diagnostic)]
#[diag("the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified", code = E0719)]
pub(crate) struct ValueOfAssociatedStructAlreadySpecified {
#[primary_span]
#[label("re-bound here")]
pub span: Span,
#[label("`{$item_name}` bound here first")]
pub prev_span: Span,
pub item_name: Ident,
pub def_path: String,
}
#[derive(Diagnostic)]
#[diag("unconstrained opaque type")]
#[note("`{$name}` must be used in combination with a concrete type within the same {$what}")]
pub(crate) struct UnconstrainedOpaqueType {
#[primary_span]
pub span: Span,
pub name: Ident,
pub what: &'static str,
}
pub(crate) struct MissingGenericParams {
pub span: Span,
pub def_span: Span,
pub span_snippet: Option<String>,
pub missing_generic_params: Vec<(Symbol, ty::GenericParamDefKind)>,
pub empty_generic_args: bool,
}
// FIXME: This doesn't need to be a manual impl!
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for MissingGenericParams {
#[track_caller]
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
let mut err = Diag::new(
dcx,
level,
msg!(
"the {$descr} {$parameterCount ->
[one] parameter
*[other] parameters
} {$parameters} must be explicitly specified"
),
);
err.span(self.span);
err.code(E0393);
err.span_label(
self.def_span,
msg!(
"{$descr} {$parameterCount ->
[one] parameter
*[other] parameters
} {$parameters} must be specified for this"
),
);
enum Descr {
Generic,
Type,
Const,
}
let mut descr = None;
for (_, kind) in &self.missing_generic_params {
descr = match (&descr, kind) {
(None, ty::GenericParamDefKind::Type { .. }) => Some(Descr::Type),
(None, ty::GenericParamDefKind::Const { .. }) => Some(Descr::Const),
(Some(Descr::Type), ty::GenericParamDefKind::Const { .. })
| (Some(Descr::Const), ty::GenericParamDefKind::Type { .. }) => {
Some(Descr::Generic)
}
_ => continue,
}
}
err.arg(
"descr",
match descr.unwrap() {
Descr::Generic => "generic",
Descr::Type => "type",
Descr::Const => "const",
},
);
err.arg("parameterCount", self.missing_generic_params.len());
err.arg(
"parameters",
listify(&self.missing_generic_params, |(n, _)| format!("`{n}`")).unwrap(),
);
let mut suggested = false;
// Don't suggest setting the generic params if there are some already: The order is
// tricky to get right and the user will already know what the syntax is.
if let Some(snippet) = self.span_snippet
&& self.empty_generic_args
{
if snippet.ends_with('>') {
// The user wrote `Trait<'a, T>` or similar. To provide an accurate suggestion
// we would have to preserve the right order. For now, as clearly the user is
// aware of the syntax, we do nothing.
} else {
// The user wrote `Trait`, so we don't have a type we can suggest, but at
// least we can clue them to the correct syntax `Trait</* Term */>`.
err.span_suggestion_verbose(
self.span.shrink_to_hi(),
msg!(
"explicitly specify the {$descr} {$parameterCount ->
[one] parameter
*[other] parameters
}"
),
format!(
"<{}>",
self.missing_generic_params
.iter()
.map(|(n, _)| format!("/* {n} */"))
.collect::<Vec<_>>()
.join(", ")
),
Applicability::HasPlaceholders,
);
suggested = true;
}
}
if !suggested {
err.span_label(
self.span,
msg!(
"missing {$parameterCount ->
[one] reference
*[other] references
} to {$parameters}"
),
);
}
err.note(msg!(
"because the parameter {$parameterCount ->
[one] default references
*[other] defaults reference
} `Self`, the {$parameterCount ->
[one] parameter
*[other] parameters
} must be specified on the trait object type"
));
err
}
}
#[derive(Diagnostic)]
#[diag("manual implementations of `{$trait_name}` are experimental", code = E0183)]
#[help("add `#![feature(unboxed_closures)]` to the crate attributes to enable")]
pub(crate) struct ManualImplementation {
#[primary_span]
#[label("manual implementations of `{$trait_name}` are experimental")]
pub span: Span,
pub trait_name: String,
}
#[derive(Diagnostic)]
#[diag("could not resolve generic parameters on overridden impl")]
pub(crate) struct GenericArgsOnOverriddenImpl {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("const `impl` for trait `{$trait_name}` which is not `const`")]
pub(crate) struct ConstImplForNonConstTrait {
#[primary_span]
#[label("this trait is not `const`")]
pub trait_ref_span: Span,
pub trait_name: String,
#[suggestion(
"{$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations",
applicability = "machine-applicable",
code = "const ",
style = "verbose"
)]
pub suggestion: Option<Span>,
pub suggestion_pre: &'static str,
#[note("marking a trait with `const` ensures all default method bodies are `const`")]
pub marking: (),
#[note("adding a non-const method body in the future would be a breaking change")]
pub adding: (),
}
#[derive(Diagnostic)]
#[diag("`{$modifier}` can only be applied to `const` traits")]
pub(crate) struct ConstBoundForNonConstTrait {
#[primary_span]
#[label("can't be applied to `{$trait_name}`")]
pub span: Span,
pub modifier: &'static str,
#[note("`{$trait_name}` can't be used with `{$modifier}` because it isn't `const`")]
pub def_span: Option<Span>,
#[suggestion(
"{$suggestion_pre}mark `{$trait_name}` as `const` to allow it to have `const` implementations",
applicability = "machine-applicable",
code = "const ",
style = "verbose"
)]
pub suggestion: Option<Span>,
pub suggestion_pre: &'static str,
pub trait_name: String,
}
#[derive(Diagnostic)]
#[diag("`Self` is not valid in the self type of an impl block")]
pub(crate) struct SelfInImplSelf {
#[primary_span]
pub span: MultiSpan,
#[note("replace `Self` with a different type")]
pub note: (),
}
#[derive(Diagnostic)]
#[diag("invalid type for variable with `#[linkage]` attribute", code = E0791)]
pub(crate) struct LinkageType {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
#[diag("reached the recursion limit while auto-dereferencing `{$ty}`", code = E0055)]
pub(crate) struct AutoDerefReachedRecursionLimit<'a> {
#[primary_span]
#[label("deref recursion limit reached")]
pub span: Span,
pub ty: Ty<'a>,
pub suggested_limit: Limit,
pub crate_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("`main` function is not allowed to have a `where` clause", code = E0646)]
pub(crate) struct WhereClauseOnMain {
#[primary_span]
pub span: Span,
#[label("`main` cannot have a `where` clause")]
pub generics_span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("`main` function is not allowed to be `#[track_caller]`")]
pub(crate) struct TrackCallerOnMain {
#[primary_span]
#[suggestion("remove this annotation", applicability = "maybe-incorrect", code = "")]
pub span: Span,
#[label("`main` function is not allowed to be `#[track_caller]`")]
pub annotated: Span,
}
#[derive(Diagnostic)]
#[diag("`main` function is not allowed to have `#[target_feature]`")]
pub(crate) struct TargetFeatureOnMain {
#[primary_span]
#[label("`main` function is not allowed to have `#[target_feature]`")]
pub main: Span,
}
#[derive(Diagnostic)]
#[diag("`main` function return type is not allowed to have generic parameters", code = E0131)]
pub(crate) struct MainFunctionReturnTypeGeneric {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`main` function is not allowed to be `async`", code = E0752)]
pub(crate) struct MainFunctionAsync {
#[primary_span]
pub span: Span,
#[label("`main` function is not allowed to be `async`")]
pub asyncness: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("`main` function is not allowed to have generic parameters", code = E0131)]
pub(crate) struct MainFunctionGenericParameters {
#[primary_span]
pub span: Span,
#[label("`main` cannot have generic parameters")]
pub label_span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("C-variadic functions with the {$convention} calling convention are not supported", code = E0045)]
pub(crate) struct VariadicFunctionCompatibleConvention<'a> {
#[primary_span]
#[label("C-variadic function must have a compatible calling convention")]
pub span: Span,
pub convention: &'a str,
}
#[derive(Diagnostic)]
pub(crate) enum CannotCaptureLateBound {
#[diag("cannot capture late-bound type parameter in {$what}")]
Type {
#[primary_span]
use_span: Span,
#[label("parameter defined here")]
def_span: Span,
what: &'static str,
},
#[diag("cannot capture late-bound const parameter in {$what}")]
Const {
#[primary_span]
use_span: Span,
#[label("parameter defined here")]
def_span: Span,
what: &'static str,
},
#[diag("cannot capture late-bound lifetime in {$what}")]
Lifetime {
#[primary_span]
use_span: Span,
#[label("lifetime defined here")]
def_span: Span,
what: &'static str,
},
}
#[derive(Diagnostic)]
#[diag("{$ty}")]
pub(crate) struct TypeOf<'tcx> {
#[primary_span]
pub span: Span,
pub ty: Ty<'tcx>,
}
#[derive(Diagnostic)]
#[diag("field must implement `Copy` or be wrapped in `ManuallyDrop<...>` to be used in a union", code = E0740)]
pub(crate) struct InvalidUnionField {
#[primary_span]
pub field_span: Span,
#[subdiagnostic]
pub sugg: InvalidUnionFieldSuggestion,
#[note(
"union fields must not have drop side-effects, which is currently enforced via either `Copy` or `ManuallyDrop<...>`"
)]
pub note: (),
}
#[derive(Diagnostic)]
#[diag(
"return type notation used on function that is not `async` and does not return `impl Trait`"
)]
pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> {
#[primary_span]
pub span: Span,
pub ty: Ty<'tcx>,
#[label("this function must be `async` or return `impl Trait`")]
pub fn_span: Option<Span>,
#[note("function returns `{$ty}`, which is not compatible with associated type return bounds")]
pub note: (),
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"wrap the field type in `ManuallyDrop<...>`",
applicability = "machine-applicable"
)]
pub(crate) struct InvalidUnionFieldSuggestion {
#[suggestion_part(code = "std::mem::ManuallyDrop<")]
pub lo: Span,
#[suggestion_part(code = ">")]
pub hi: Span,
}
#[derive(Diagnostic)]
#[diag("return type notation is not allowed to use type equality")]
pub(crate) struct ReturnTypeNotationEqualityBound {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("the placeholder `_` is not allowed within types on item signatures for {$kind}", code = E0121)]
pub(crate) struct PlaceholderNotAllowedItemSignatures {
#[primary_span]
#[label("not allowed in type signatures")]
pub spans: Vec<Span>,
pub kind: String,
}
#[derive(Diagnostic)]
#[diag("cannot use the {$what} of a trait with uninferred generic parameters", code = E0212)]
pub(crate) struct AssociatedItemTraitUninferredGenericParams {
#[primary_span]
pub span: Span,
#[suggestion(
"use a fully qualified path with inferred lifetimes",
style = "verbose",
applicability = "maybe-incorrect",
code = "{bound}"
)]
pub inferred_sugg: Option<Span>,
pub bound: String,
#[subdiagnostic]
pub mpart_sugg: Option<AssociatedItemTraitUninferredGenericParamsMultipartSuggestion>,
pub what: &'static str,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"use a fully qualified path with explicit lifetimes",
applicability = "maybe-incorrect"
)]
pub(crate) struct AssociatedItemTraitUninferredGenericParamsMultipartSuggestion {
#[suggestion_part(code = "{first}")]
pub fspan: Span,
pub first: String,
#[suggestion_part(code = "{second}")]
pub sspan: Span,
pub second: String,
}
#[derive(Diagnostic)]
#[diag("enum discriminant overflowed", code = E0370)]
#[note("explicitly set `{$item_name} = {$wrapped_discr}` if that is desired outcome")]
pub(crate) struct EnumDiscriminantOverflowed {
#[primary_span]
#[label("overflowed on value after {$discr}")]
pub span: Span,
pub discr: String,
pub item_name: Ident,
pub wrapped_discr: String,
}
#[derive(Diagnostic)]
#[diag(
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation"
)]
#[help("add `#![feature(unboxed_closures)]` to the crate attributes to use it")]
pub(crate) struct ParenSugarAttribute {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("use of SIMD type{$snip} in FFI is highly experimental and may result in invalid code")]
#[help("add `#![feature(simd_ffi)]` to the crate attributes to enable")]
pub(crate) struct SIMDFFIHighlyExperimental {
#[primary_span]
pub span: Span,
pub snip: String,
}
#[derive(Diagnostic)]
pub(crate) enum ImplNotMarkedDefault {
#[diag("`{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`", code = E0520)]
#[note("to specialize, `{$ident}` in the parent `impl` must be marked `default`")]
Ok {
#[primary_span]
#[label("cannot specialize default item `{$ident}`")]
span: Span,
#[label("parent `impl` is here")]
ok_label: Span,
ident: Ident,
},
#[diag("`{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`", code = E0520)]
#[note("parent implementation is in crate `{$cname}`")]
Err {
#[primary_span]
span: Span,
cname: Symbol,
ident: Ident,
},
}
#[derive(Diagnostic)]
#[diag("this item cannot be used as its where bounds are not satisfied for the `Self` type")]
pub(crate) struct UselessImplItem;
#[derive(Diagnostic)]
#[diag("cannot override `{$ident}` because it already has a `final` definition in the trait")]
pub(crate) struct OverridingFinalTraitFunction {
#[primary_span]
pub impl_span: Span,
#[note("`{$ident}` is marked final here")]
pub trait_span: Span,
pub ident: Ident,
}
#[derive(Diagnostic)]
#[diag("not all trait items implemented, missing: `{$missing_items_msg}`", code = E0046)]
pub(crate) struct MissingTraitItem {
#[primary_span]
#[label("missing `{$missing_items_msg}` in implementation")]
pub span: Span,
#[subdiagnostic]
pub missing_trait_item_label: Vec<MissingTraitItemLabel>,
#[subdiagnostic]
pub missing_trait_item: Vec<MissingTraitItemSuggestion>,
#[subdiagnostic]
pub missing_trait_item_none: Vec<MissingTraitItemSuggestionNone>,
pub missing_items_msg: String,
}
#[derive(Subdiagnostic)]
#[label("`{$item}` from trait")]
pub(crate) struct MissingTraitItemLabel {
#[primary_span]
pub span: Span,
pub item: Symbol,
}
#[derive(Subdiagnostic)]
#[suggestion(
"implement the missing item: `{$snippet}`",
style = "tool-only",
applicability = "has-placeholders",
code = "{code}"
)]
pub(crate) struct MissingTraitItemSuggestion {
#[primary_span]
pub span: Span,
pub code: String,
pub snippet: String,
}
#[derive(Subdiagnostic)]
#[suggestion(
"implement the missing item: `{$snippet}`",
style = "hidden",
applicability = "has-placeholders",
code = "{code}"
)]
pub(crate) struct MissingTraitItemSuggestionNone {
#[primary_span]
pub span: Span,
pub code: String,
pub snippet: String,
}
#[derive(Diagnostic)]
#[diag("not all trait items implemented, missing one of: `{$missing_items_msg}`", code = E0046)]
pub(crate) struct MissingOneOfTraitItem {
#[primary_span]
#[label("missing one of `{$missing_items_msg}` in implementation")]
pub span: Span,
#[note("required because of this annotation")]
pub note: Option<Span>,
pub missing_items_msg: String,
}
#[derive(Diagnostic)]
#[diag("not all trait items implemented, missing: `{$missing_item_name}`", code = E0046)]
#[note("default implementation of `{$missing_item_name}` is unstable")]
pub(crate) struct MissingTraitItemUnstable {
#[primary_span]
pub span: Span,
#[note("use of unstable library feature `{$feature}`: {$reason}")]
pub some_note: bool,
#[note("use of unstable library feature `{$feature}`")]
pub none_note: bool,
pub missing_item_name: Ident,
pub feature: Symbol,
pub reason: String,
}
#[derive(Diagnostic)]
#[diag("transparent enum needs exactly one variant, but has {$number}", code = E0731)]
pub(crate) struct TransparentEnumVariant {
#[primary_span]
#[label("needs exactly one variant, but has {$number}")]
pub span: Span,