-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Expand file tree
/
Copy patherrors.rs
More file actions
625 lines (562 loc) · 16.6 KB
/
errors.rs
File metadata and controls
625 lines (562 loc) · 16.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
use std::borrow::Cow;
use rustc_ast::ast;
use rustc_errors::codes::*;
use rustc_hir::limit::Limit;
use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
#[derive(Diagnostic)]
#[diag("`#[cfg_attr]` does not expand to any attributes")]
pub(crate) struct CfgAttrNoAttributes;
#[derive(Diagnostic)]
#[diag(
"attempted to repeat an expression containing no syntax variables matched as repeating at this depth"
)]
pub(crate) struct NoSyntaxVarsExprRepeat {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub typo_repeatable: Option<VarTypoSuggestionRepeatable>,
#[subdiagnostic]
pub typo_unrepeatable: Option<VarTypoSuggestionUnrepeatable>,
#[subdiagnostic]
pub typo_unrepeatable_label: Option<VarTypoSuggestionUnrepeatableLabel>,
#[subdiagnostic]
pub var_no_typo: Option<VarNoTypo>,
#[subdiagnostic]
pub no_repeatable_var: Option<NoRepeatableVar>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"there's a macro metavariable with a similar name",
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct VarTypoSuggestionRepeatable {
#[suggestion_part(code = "{name}")]
pub span: Span,
pub name: Symbol,
}
#[derive(Subdiagnostic)]
#[label("argument not found")]
pub(crate) struct VarTypoSuggestionUnrepeatable {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic)]
#[label("this similarly named macro metavariable is unrepeatable")]
pub(crate) struct VarTypoSuggestionUnrepeatableLabel {
#[primary_span]
pub span: Span,
}
#[derive(Subdiagnostic)]
#[label("expected a repeatable metavariable: {$msg}")]
pub(crate) struct VarNoTypo {
#[primary_span]
pub span: Span,
pub msg: String,
}
#[derive(Subdiagnostic)]
#[label(
"this macro metavariable is not repeatable and there are no other repeatable metavariables"
)]
pub(crate) struct NoRepeatableVar {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("this must repeat at least once")]
pub(crate) struct MustRepeatOnce {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`count` can not be placed inside the innermost repetition")]
pub(crate) struct CountRepetitionMisplaced {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MacroVarStillRepeating {
#[primary_span]
pub span: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[derive(Diagnostic)]
#[diag("variable `{$ident}` is still repeating at this depth")]
pub(crate) struct MetaVarStillRepeatingLint {
#[label("expected repetition")]
pub label: Span,
pub ident: MacroRulesNormalizedIdent,
}
#[derive(Diagnostic)]
#[diag("meta-variable repeats with different Kleene operator")]
pub(crate) struct MetaVariableWrongOperator {
#[label("expected repetition")]
pub binder: Span,
#[label("conflicting repetition")]
pub occurrence: Span,
}
#[derive(Diagnostic)]
#[diag("{$msg}")]
pub(crate) struct MetaVarsDifSeqMatchers {
#[primary_span]
pub span: Span,
pub msg: String,
}
#[derive(Diagnostic)]
#[diag("unknown macro variable `{$name}`")]
pub(crate) struct UnknownMacroVariable {
pub name: MacroRulesNormalizedIdent,
}
#[derive(Diagnostic)]
#[diag("cannot resolve relative path in non-file source `{$path}`")]
pub(crate) struct ResolveRelativePath {
#[primary_span]
pub span: Span,
pub path: String,
}
#[derive(Diagnostic)]
#[diag("macros cannot have body stability attributes")]
pub(crate) struct MacroBodyStability {
#[primary_span]
#[label("invalid body stability attribute")]
pub span: Span,
#[label("body stability attribute affects this macro")]
pub head_span: Span,
}
#[derive(Diagnostic)]
#[diag("feature has been removed", code = E0557)]
#[note("removed in {$removed_rustc_version}{$pull_note}")]
pub(crate) struct FeatureRemoved<'a> {
#[primary_span]
#[label("feature has been removed")]
pub span: Span,
#[subdiagnostic]
pub reason: Option<FeatureRemovedReason<'a>>,
pub removed_rustc_version: &'a str,
pub pull_note: String,
}
#[derive(Subdiagnostic)]
#[note("{$reason}")]
pub(crate) struct FeatureRemovedReason<'a> {
pub reason: &'a str,
}
#[derive(Diagnostic)]
#[diag("the feature `{$name}` is not in the list of allowed features", code = E0725)]
pub(crate) struct FeatureNotAllowed {
#[primary_span]
pub span: Span,
pub name: Symbol,
}
#[derive(Diagnostic)]
#[diag("recursion limit reached while expanding `{$descr}`")]
#[help(
"consider increasing the recursion limit by adding a `#![recursion_limit = \"{$suggested_limit}\"]` attribute to your crate (`{$crate_name}`)"
)]
pub(crate) struct RecursionLimitReached {
#[primary_span]
pub span: Span,
pub descr: String,
pub suggested_limit: Limit,
pub crate_name: Symbol,
}
#[derive(Diagnostic)]
#[diag("removing an expression is not supported in this position")]
pub(crate) struct RemoveExprNotSupported {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
pub(crate) enum InvalidCfg {
#[diag("`cfg` is not followed by parentheses")]
NotFollowedByParens {
#[primary_span]
#[suggestion(
"expected syntax is",
code = "cfg(/* predicate */)",
applicability = "has-placeholders"
)]
span: Span,
},
#[diag("`cfg` predicate is not specified")]
NoPredicate {
#[primary_span]
#[suggestion(
"expected syntax is",
code = "cfg(/* predicate */)",
applicability = "has-placeholders"
)]
span: Span,
},
#[diag("multiple `cfg` predicates are specified")]
MultiplePredicates {
#[primary_span]
span: Span,
},
#[diag("`cfg` predicate key cannot be a literal")]
PredicateLiteral {
#[primary_span]
span: Span,
},
}
#[derive(Diagnostic)]
#[diag("non-{$kind} macro in {$kind} position: {$name}")]
pub(crate) struct WrongFragmentKind<'a> {
#[primary_span]
pub span: Span,
pub kind: &'a str,
pub name: &'a ast::Path,
}
#[derive(Diagnostic)]
#[diag("key-value macro attributes are not supported")]
pub(crate) struct UnsupportedKeyValue {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("macro expansion ignores {$descr} and any tokens following")]
#[note("the usage of `{$macro_path}!` is likely invalid in {$kind_name} context")]
pub(crate) struct IncompleteParse<'a> {
#[primary_span]
pub span: Span,
pub descr: String,
#[label("caused by the macro expansion here")]
pub label_span: Span,
pub macro_path: &'a ast::Path,
pub kind_name: &'a str,
#[note("macros cannot expand to match arms")]
pub expands_to_match_arm: bool,
#[suggestion(
"you might be missing a semicolon here",
style = "verbose",
code = ";",
applicability = "maybe-incorrect"
)]
pub add_semicolon: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("removing {$descr} is not supported in this position")]
pub(crate) struct RemoveNodeNotSupported {
#[primary_span]
pub span: Span,
pub descr: &'static str,
}
#[derive(Diagnostic)]
#[diag("circular modules: {$modules}")]
pub(crate) struct ModuleCircular {
#[primary_span]
pub span: Span,
pub modules: String,
}
#[derive(Diagnostic)]
#[diag("cannot declare a file module inside a block unless it has a path attribute")]
#[note("file modules are usually placed outside of blocks, at the top level of the file")]
pub(crate) struct ModuleInBlock {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub name: Option<ModuleInBlockName>,
}
#[derive(Subdiagnostic)]
#[help("maybe `use` the module `{$name}` instead of redeclaring it")]
pub(crate) struct ModuleInBlockName {
#[primary_span]
pub span: Span,
pub name: Ident,
}
#[derive(Diagnostic)]
#[diag("file not found for module `{$name}`", code = E0583)]
#[help("to create the module `{$name}`, create file \"{$default_path}\" or \"{$secondary_path}\"")]
#[note(
"if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead"
)]
pub(crate) struct ModuleFileNotFound {
#[primary_span]
pub span: Span,
pub name: Ident,
pub default_path: String,
pub secondary_path: String,
}
#[derive(Diagnostic)]
#[diag("file for module `{$name}` found at both \"{$default_path}\" and \"{$secondary_path}\"", code = E0761)]
#[help("delete or rename one of them to remove the ambiguity")]
pub(crate) struct ModuleMultipleCandidates {
#[primary_span]
pub span: Span,
pub name: Ident,
pub default_path: String,
pub secondary_path: String,
}
#[derive(Diagnostic)]
#[diag("trace_macro")]
pub(crate) struct TraceMacro {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("proc macro panicked")]
pub(crate) struct ProcMacroPanicked {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<ProcMacroPanickedHelp>,
}
#[derive(Subdiagnostic)]
#[help("message: {$message}")]
pub(crate) struct ProcMacroPanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag("proc-macro derive panicked")]
pub(crate) struct ProcMacroDerivePanicked {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<ProcMacroDerivePanickedHelp>,
}
#[derive(Subdiagnostic)]
#[help("message: {$message}")]
pub(crate) struct ProcMacroDerivePanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag("custom attribute panicked")]
pub(crate) struct CustomAttributePanicked {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<CustomAttributePanickedHelp>,
}
#[derive(Subdiagnostic)]
#[help("message: {$message}")]
pub(crate) struct CustomAttributePanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag("proc-macro derive produced unparsable tokens")]
pub(crate) struct ProcMacroDeriveTokens {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBinding {
#[primary_span]
#[label("duplicate binding")]
pub span: Span,
#[label("previous binding")]
pub prev: Span,
}
#[derive(Diagnostic)]
#[diag("duplicate matcher binding")]
pub(crate) struct DuplicateMatcherBindingLint {
#[label("duplicate binding")]
pub span: Span,
#[label("previous binding")]
pub prev: Span,
}
#[derive(Diagnostic)]
#[diag("missing fragment specifier")]
#[note("fragment specifiers must be provided")]
#[help("{$valid}")]
pub(crate) struct MissingFragmentSpecifier {
#[primary_span]
pub span: Span,
#[suggestion(
"try adding a specifier here",
style = "verbose",
code = ":spec",
applicability = "maybe-incorrect"
)]
pub add_span: Span,
pub valid: &'static str,
#[suggestion("use `:` instead of `;`", code = ":", applicability = "maybe-incorrect")]
pub semi_span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag("invalid fragment specifier `{$fragment}`")]
#[help("{$help}")]
pub(crate) struct InvalidFragmentSpecifier {
#[primary_span]
pub span: Span,
pub fragment: Ident,
pub help: &'static str,
}
#[derive(Diagnostic)]
#[diag("expected `(` or `{\"{\"}`, found `{$token}`")]
pub(crate) struct ExpectedParenOrBrace<'a> {
#[primary_span]
pub span: Span,
pub token: Cow<'a, str>,
}
#[derive(Diagnostic)]
#[diag("empty {$kind} delegation is not supported")]
pub(crate) struct EmptyDelegationMac {
#[primary_span]
pub span: Span,
pub kind: String,
}
#[derive(Diagnostic)]
#[diag("glob delegation is only supported in impls")]
pub(crate) struct GlobDelegationOutsideImpls {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`crate_name` within an `#![cfg_attr]` attribute is forbidden")]
pub(crate) struct CrateNameInCfgAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("`crate_type` within an `#![cfg_attr]` attribute is forbidden")]
pub(crate) struct CrateTypeInCfgAttr {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag("qualified path without a trait in glob delegation")]
pub(crate) struct GlobDelegationTraitlessQpath {
#[primary_span]
pub span: Span,
}
pub(crate) use metavar_exprs::*;
mod metavar_exprs {
use super::*;
#[derive(Diagnostic, Default)]
#[diag("unexpected trailing tokens")]
pub(crate) struct MveExtraTokens {
#[primary_span]
#[suggestion(
"try removing {$extra_count ->
[one] this token
*[other] these tokens
}",
code = "",
applicability = "machine-applicable"
)]
pub span: Span,
#[label("for this metavariable expression")]
pub ident_span: Span,
pub extra_count: usize,
// The rest is only used for specific diagnostics and can be default if neither
// `note` is `Some`.
#[note(
"the `{$name}` metavariable expression takes {$min_or_exact_args ->
[zero] no arguments
[one] a single argument
*[other] {$min_or_exact_args} arguments
}"
)]
pub exact_args_note: Option<()>,
#[note(
"the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments"
)]
pub range_args_note: Option<()>,
pub min_or_exact_args: usize,
pub max_args: usize,
pub name: String,
}
#[derive(Diagnostic)]
#[note("metavariable expressions use function-like parentheses syntax")]
#[diag("expected `(`")]
pub(crate) struct MveMissingParen {
#[primary_span]
#[label("for this this metavariable expression")]
pub ident_span: Span,
#[label("unexpected token")]
pub unexpected_span: Option<Span>,
#[suggestion(
"try adding parentheses",
code = "( /* ... */ )",
applicability = "has-placeholders"
)]
pub insert_span: Option<Span>,
}
#[derive(Diagnostic)]
#[note("valid metavariable expressions are {$valid_expr_list}")]
#[diag("unrecognized metavariable expression")]
pub(crate) struct MveUnrecognizedExpr {
#[primary_span]
#[label("not a valid metavariable expression")]
pub span: Span,
pub valid_expr_list: &'static str,
}
#[derive(Diagnostic)]
#[diag("variable `{$key}` is not recognized in meta-variable expression")]
pub(crate) struct MveUnrecognizedVar {
#[primary_span]
pub span: Span,
pub key: MacroRulesNormalizedIdent,
}
}
#[derive(Diagnostic)]
#[diag("`{$rule_kw}` rule argument matchers require parentheses")]
pub(crate) struct MacroArgsBadDelim {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sugg: MacroArgsBadDelimSugg,
pub rule_kw: Symbol,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
"the delimiters should be `(` and `)`",
applicability = "machine-applicable"
)]
pub(crate) struct MacroArgsBadDelimSugg {
#[suggestion_part(code = "(")]
pub open: Span,
#[suggestion_part(code = ")")]
pub close: Span,
}
#[derive(Diagnostic)]
#[diag("unused doc comment")]
#[help(
"to document an item produced by a macro, the macro must produce the documentation as part of its expansion"
)]
pub(crate) struct MacroCallUnusedDocComment {
#[label("rustdoc does not generate documentation for macro invocations")]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(
"the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro"
)]
pub(crate) struct OrPatternsBackCompat {
#[suggestion(
"use pat_param to preserve semantics",
code = "{suggestion}",
applicability = "machine-applicable"
)]
pub span: Span,
pub suggestion: String,
}
#[derive(Diagnostic)]
#[diag("trailing semicolon in macro used in expression position")]
pub(crate) struct TrailingMacro {
#[note("macro invocations at the end of a block are treated as expressions")]
#[note(
"to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`"
)]
pub is_trailing: bool,
pub name: Ident,
}
#[derive(Diagnostic)]
#[diag("unused attribute `{$attr_name}`")]
pub(crate) struct UnusedBuiltinAttribute {
#[note(
"the built-in attribute `{$attr_name}` will be ignored, since it's applied to the macro invocation `{$macro_name}`"
)]
pub invoc_span: Span,
pub attr_name: Symbol,
pub macro_name: String,
#[suggestion(
"remove the attribute",
code = "",
applicability = "machine-applicable",
style = "tool-only"
)]
pub attr_span: Span,
}