-
Notifications
You must be signed in to change notification settings - Fork 13k
/
Copy pathbuiltin.rs
4135 lines (4023 loc) · 140 KB
/
builtin.rs
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
//! Some lints that are built in to the compiler.
//!
//! These are the built-in lints that are emitted direct in the main
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
use rustc_span::edition::Edition;
use rustc_span::symbol::sym;
declare_lint! {
/// The `forbidden_lint_groups` lint detects violations of
/// `forbid` applied to a lint group. Due to a bug in the compiler,
/// these used to be overlooked entirely. They now generate a warning.
///
/// ### Example
///
/// ```rust
/// #![forbid(warnings)]
/// #![deny(bad_style)]
///
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Recommended fix
///
/// If your crate is using `#![forbid(warnings)]`,
/// we recommend that you change to `#![deny(warnings)]`.
///
/// ### Explanation
///
/// Due to a compiler bug, applying `forbid` to lint groups
/// previously had no effect. The bug is now fixed but instead of
/// enforcing `forbid` we issue this future-compatibility warning
/// to avoid breaking existing crates.
pub FORBIDDEN_LINT_GROUPS,
Warn,
"applying forbid to lint-groups",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
};
}
declare_lint! {
/// The `ill_formed_attribute_input` lint detects ill-formed attribute
/// inputs that were previously accepted and used in practice.
///
/// ### Example
///
/// ```rust,compile_fail
/// #[inline = "this is not valid"]
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Previously, inputs for many built-in attributes weren't validated and
/// nonsensical attribute inputs were accepted. After validation was
/// added, it was determined that some existing projects made use of these
/// invalid forms. This is a [future-incompatible] lint to transition this
/// to a hard error in the future. See [issue #57571] for more details.
///
/// Check the [attribute reference] for details on the valid inputs for
/// attributes.
///
/// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
/// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub ILL_FORMED_ATTRIBUTE_INPUT,
Deny,
"ill-formed attribute inputs that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
};
crate_level_only
}
declare_lint! {
/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
/// conflicting hints.
///
/// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
///
/// ### Example
///
/// ```rust,compile_fail
/// #[repr(u32, u64)]
/// enum Foo {
/// Variant1,
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The compiler incorrectly accepted these conflicting representations in
/// the past. This is a [future-incompatible] lint to transition this to a
/// hard error in the future. See [issue #68585] for more details.
///
/// To correct the issue, remove one of the conflicting hints.
///
/// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub CONFLICTING_REPR_HINTS,
Deny,
"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
};
}
declare_lint! {
/// The `meta_variable_misuse` lint detects possible meta-variable misuse
/// in macro definitions.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(meta_variable_misuse)]
///
/// macro_rules! foo {
/// () => {};
/// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
/// }
///
/// fn main() {
/// foo!();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// There are quite a few different ways a [`macro_rules`] macro can be
/// improperly defined. Many of these errors were previously only detected
/// when the macro was expanded or not at all. This lint is an attempt to
/// catch some of these problems when the macro is *defined*.
///
/// This lint is "allow" by default because it may have false positives
/// and other issues. See [issue #61053] for more details.
///
/// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
/// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
pub META_VARIABLE_MISUSE,
Allow,
"possible meta-variable misuse at macro definition"
}
declare_lint! {
/// The `incomplete_include` lint detects the use of the [`include!`]
/// macro with a file that contains more than one expression.
///
/// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
///
/// ### Example
///
/// ```rust,ignore (needs separate file)
/// fn main() {
/// include!("foo.txt");
/// }
/// ```
///
/// where the file `foo.txt` contains:
///
/// ```text
/// println!("hi!");
/// ```
///
/// produces:
///
/// ```text
/// error: include macro expected single expression in source
/// --> foo.txt:1:14
/// |
/// 1 | println!("1");
/// | ^
/// |
/// = note: `#[deny(incomplete_include)]` on by default
/// ```
///
/// ### Explanation
///
/// The [`include!`] macro is currently only intended to be used to
/// include a single [expression] or multiple [items]. Historically it
/// would ignore any contents after the first expression, but that can be
/// confusing. In the example above, the `println!` expression ends just
/// before the semicolon, making the semicolon "extra" information that is
/// ignored. Perhaps even more surprising, if the included file had
/// multiple print statements, the subsequent ones would be ignored!
///
/// One workaround is to place the contents in braces to create a [block
/// expression]. Also consider alternatives, like using functions to
/// encapsulate the expressions, or use [proc-macros].
///
/// This is a lint instead of a hard error because existing projects were
/// found to hit this error. To be cautious, it is a lint for now. The
/// future semantics of the `include!` macro are also uncertain, see
/// [issue #35560].
///
/// [items]: https://doc.rust-lang.org/reference/items.html
/// [expression]: https://doc.rust-lang.org/reference/expressions.html
/// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
/// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
/// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
pub INCOMPLETE_INCLUDE,
Deny,
"trailing content in included file"
}
declare_lint! {
/// The `arithmetic_overflow` lint detects that an arithmetic operation
/// will [overflow].
///
/// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
///
/// ### Example
///
/// ```rust,compile_fail
/// 1_i32 << 32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is very likely a mistake to perform an arithmetic operation that
/// overflows its value. If the compiler is able to detect these kinds of
/// overflows at compile-time, it will trigger this lint. Consider
/// adjusting the expression to avoid overflow, or use a data type that
/// will not overflow.
pub ARITHMETIC_OVERFLOW,
Deny,
"arithmetic operation overflows"
}
declare_lint! {
/// The `unconditional_panic` lint detects an operation that will cause a
/// panic at runtime.
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![allow(unused)]
/// let x = 1 / 0;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This lint detects code that is very likely incorrect because it will
/// always panic, such as division by zero and out-of-bounds array
/// accesses. Consider adjusting your code if this is a bug, or using the
/// `panic!` or `unreachable!` macro instead in case the panic is intended.
pub UNCONDITIONAL_PANIC,
Deny,
"operation will cause a panic at runtime"
}
declare_lint! {
/// The `unused_imports` lint detects imports that are never used.
///
/// ### Example
///
/// ```rust
/// use std::collections::HashMap;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused imports may signal a mistake or unfinished code, and clutter
/// the code, and should be removed. If you intended to re-export the item
/// to make it available outside of the module, add a visibility modifier
/// like `pub`.
pub UNUSED_IMPORTS,
Warn,
"imports that are never used"
}
declare_lint! {
/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
/// (`.await`)
///
/// ### Example
///
/// ```rust
/// #![feature(must_not_suspend)]
/// #![warn(must_not_suspend)]
///
/// #[must_not_suspend]
/// struct SyncThing {}
///
/// async fn yield_now() {}
///
/// pub async fn uhoh() {
/// let guard = SyncThing {};
/// yield_now().await;
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
/// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
/// function.
///
/// This attribute can be used to mark values that are semantically incorrect across suspends
/// (like certain types of timers), values that have async alternatives, and values that
/// regularly cause problems with the `Send`-ness of async fn's returned futures (like
/// `MutexGuard`'s)
///
pub MUST_NOT_SUSPEND,
Allow,
"use of a `#[must_not_suspend]` value across a yield point",
@feature_gate = rustc_span::symbol::sym::must_not_suspend;
}
declare_lint! {
/// The `unused_extern_crates` lint guards against `extern crate` items
/// that are never used.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unused_extern_crates)]
/// extern crate proc_macro;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// `extern crate` items that are unused have no effect and should be
/// removed. Note that there are some cases where specifying an `extern
/// crate` is desired for the side effect of ensuring the given crate is
/// linked, even though it is not otherwise directly referenced. The lint
/// can be silenced by aliasing the crate to an underscore, such as
/// `extern crate foo as _`. Also note that it is no longer idiomatic to
/// use `extern crate` in the [2018 edition], as extern crates are now
/// automatically added in scope.
///
/// This lint is "allow" by default because it can be noisy, and produce
/// false-positives. If a dependency is being removed from a project, it
/// is recommended to remove it from the build configuration (such as
/// `Cargo.toml`) to ensure stale build entries aren't left behind.
///
/// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
pub UNUSED_EXTERN_CRATES,
Allow,
"extern crates that are never used"
}
declare_lint! {
/// The `unused_crate_dependencies` lint detects crate dependencies that
/// are never used.
///
/// ### Example
///
/// ```rust,ignore (needs extern crate)
/// #![deny(unused_crate_dependencies)]
/// ```
///
/// This will produce:
///
/// ```text
/// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
/// |
/// note: the lint level is defined here
/// --> src/lib.rs:1:9
/// |
/// 1 | #![deny(unused_crate_dependencies)]
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^
/// ```
///
/// ### Explanation
///
/// After removing the code that uses a dependency, this usually also
/// requires removing the dependency from the build configuration.
/// However, sometimes that step can be missed, which leads to time wasted
/// building dependencies that are no longer used. This lint can be
/// enabled to detect dependencies that are never used (more specifically,
/// any dependency passed with the `--extern` command-line flag that is
/// never referenced via [`use`], [`extern crate`], or in any [path]).
///
/// This lint is "allow" by default because it can provide false positives
/// depending on how the build system is configured. For example, when
/// using Cargo, a "package" consists of multiple crates (such as a
/// library and a binary), but the dependencies are defined for the
/// package as a whole. If there is a dependency that is only used in the
/// binary, but not the library, then the lint will be incorrectly issued
/// in the library.
///
/// [path]: https://doc.rust-lang.org/reference/paths.html
/// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
/// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
pub UNUSED_CRATE_DEPENDENCIES,
Allow,
"crate dependencies that are never used",
crate_level_only
}
declare_lint! {
/// The `unused_qualifications` lint detects unnecessarily qualified
/// names.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(unused_qualifications)]
/// mod foo {
/// pub fn bar() {}
/// }
///
/// fn main() {
/// use foo::bar;
/// foo::bar();
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// If an item from another module is already brought into scope, then
/// there is no need to qualify it in this case. You can call `bar()`
/// directly, without the `foo::`.
///
/// This lint is "allow" by default because it is somewhat pedantic, and
/// doesn't indicate an actual problem, but rather a stylistic choice, and
/// can be noisy when refactoring or moving around code.
pub UNUSED_QUALIFICATIONS,
Allow,
"detects unnecessarily qualified names"
}
declare_lint! {
/// The `unknown_lints` lint detects unrecognized lint attributes.
///
/// ### Example
///
/// ```rust
/// #![allow(not_a_real_lint)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to specify a lint that does not exist. Check
/// the spelling, and check the lint listing for the correct name. Also
/// consider if you are using an old version of the compiler, and the lint
/// is only available in a newer version.
pub UNKNOWN_LINTS,
Warn,
"unrecognized lint attribute"
}
declare_lint! {
/// The `unfulfilled_lint_expectations` lint detects lint trigger expectations
/// that have not been fulfilled.
///
/// ### Example
///
/// ```rust
/// #![feature(lint_reasons)]
///
/// #[expect(unused_variables)]
/// let x = 10;
/// println!("{}", x);
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It was expected that the marked code would emit a lint. This expectation
/// has not been fulfilled.
///
/// The `expect` attribute can be removed if this is intended behavior otherwise
/// it should be investigated why the expected lint is no longer issued.
///
/// In rare cases, the expectation might be emitted at a different location than
/// shown in the shown code snippet. In most cases, the `#[expect]` attribute
/// works when added to the outer scope. A few lints can only be expected
/// on a crate level.
///
/// Part of RFC 2383. The progress is being tracked in [#54503]
///
/// [#54503]: https://github.com/rust-lang/rust/issues/54503
pub UNFULFILLED_LINT_EXPECTATIONS,
Warn,
"unfulfilled lint expectation",
@feature_gate = rustc_span::sym::lint_reasons;
}
declare_lint! {
/// The `unused_variables` lint detects variables which are not used in
/// any way.
///
/// ### Example
///
/// ```rust
/// let x = 5;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused variables may signal a mistake or unfinished code. To silence
/// the warning for the individual variable, prefix it with an underscore
/// such as `_x`.
pub UNUSED_VARIABLES,
Warn,
"detect variables which are not used in any way"
}
declare_lint! {
/// The `unused_assignments` lint detects assignments that will never be read.
///
/// ### Example
///
/// ```rust
/// let mut x = 5;
/// x = 6;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused assignments may signal a mistake or unfinished code. If the
/// variable is never used after being assigned, then the assignment can
/// be removed. Variables with an underscore prefix such as `_x` will not
/// trigger this lint.
pub UNUSED_ASSIGNMENTS,
Warn,
"detect assignments that will never be read"
}
declare_lint! {
/// The `dead_code` lint detects unused, unexported items.
///
/// ### Example
///
/// ```rust
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Dead code may signal a mistake or unfinished code. To silence the
/// warning for individual items, prefix the name with an underscore such
/// as `_foo`. If it was intended to expose the item outside of the crate,
/// consider adding a visibility modifier like `pub`. Otherwise consider
/// removing the unused code.
pub DEAD_CODE,
Warn,
"detect unused, unexported items"
}
declare_lint! {
/// The `unused_attributes` lint detects attributes that were not used by
/// the compiler.
///
/// ### Example
///
/// ```rust
/// #![ignore]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused [attributes] may indicate the attribute is placed in the wrong
/// position. Consider removing it, or placing it in the correct position.
/// Also consider if you intended to use an _inner attribute_ (with a `!`
/// such as `#![allow(unused)]`) which applies to the item the attribute
/// is within, or an _outer attribute_ (without a `!` such as
/// `#[allow(unused)]`) which applies to the item *following* the
/// attribute.
///
/// [attributes]: https://doc.rust-lang.org/reference/attributes.html
pub UNUSED_ATTRIBUTES,
Warn,
"detects attributes that were not used by the compiler"
}
declare_lint! {
/// The `unused_tuple_struct_fields` lint detects fields of tuple structs
/// that are never read.
///
/// ### Example
///
/// ```rust
/// #[warn(unused_tuple_struct_fields)]
/// struct S(i32, i32, i32);
/// let s = S(1, 2, 3);
/// let _ = (s.0, s.2);
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Tuple struct fields that are never read anywhere may indicate a
/// mistake or unfinished code. To silence this warning, consider
/// removing the unused field(s) or, to preserve the numbering of the
/// remaining fields, change the unused field(s) to have unit type.
pub UNUSED_TUPLE_STRUCT_FIELDS,
Allow,
"detects tuple struct fields that are never read"
}
declare_lint! {
/// The `unreachable_code` lint detects unreachable code paths.
///
/// ### Example
///
/// ```rust,no_run
/// panic!("we never go past here!");
///
/// let x = 5;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unreachable code may signal a mistake or unfinished code. If the code
/// is no longer in use, consider removing it.
pub UNREACHABLE_CODE,
Warn,
"detects unreachable code paths",
report_in_external_macro
}
declare_lint! {
/// The `unreachable_patterns` lint detects unreachable patterns.
///
/// ### Example
///
/// ```rust
/// let x = 5;
/// match x {
/// y => (),
/// 5 => (),
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This usually indicates a mistake in how the patterns are specified or
/// ordered. In this example, the `y` pattern will always match, so the
/// five is impossible to reach. Remember, match arms match in order, you
/// probably wanted to put the `5` case above the `y` case.
pub UNREACHABLE_PATTERNS,
Warn,
"detects unreachable patterns"
}
declare_lint! {
/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
/// overlap on their endpoints.
///
/// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
///
/// ### Example
///
/// ```rust
/// let x = 123u8;
/// match x {
/// 0..=100 => { println!("small"); }
/// 100..=255 => { println!("large"); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is likely a mistake to have range patterns in a match expression that overlap in this
/// way. Check that the beginning and end values are what you expect, and keep in mind that
/// with `..=` the left and right bounds are inclusive.
pub OVERLAPPING_RANGE_ENDPOINTS,
Warn,
"detects range patterns with overlapping endpoints"
}
declare_lint! {
/// The `bindings_with_variant_name` lint detects pattern bindings with
/// the same name as one of the matched variants.
///
/// ### Example
///
/// ```rust,compile_fail
/// pub enum Enum {
/// Foo,
/// Bar,
/// }
///
/// pub fn foo(x: Enum) {
/// match x {
/// Foo => {}
/// Bar => {}
/// }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to specify an enum variant name as an
/// [identifier pattern]. In the example above, the `match` arms are
/// specifying a variable name to bind the value of `x` to. The second arm
/// is ignored because the first one matches *all* values. The likely
/// intent is that the arm was intended to match on the enum variant.
///
/// Two possible solutions are:
///
/// * Specify the enum variant using a [path pattern], such as
/// `Enum::Foo`.
/// * Bring the enum variants into local scope, such as adding `use
/// Enum::*;` to the beginning of the `foo` function in the example
/// above.
///
/// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
/// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
pub BINDINGS_WITH_VARIANT_NAME,
Deny,
"detects pattern bindings with the same name as one of the matched variants"
}
declare_lint! {
/// The `unused_macros` lint detects macros that were not used.
///
/// Note that this lint is distinct from the `unused_macro_rules` lint,
/// which checks for single rules that never match of an otherwise used
/// macro, and thus never expand.
///
/// ### Example
///
/// ```rust
/// macro_rules! unused {
/// () => {};
/// }
///
/// fn main() {
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused macros may signal a mistake or unfinished code. To silence the
/// warning for the individual macro, prefix the name with an underscore
/// such as `_my_macro`. If you intended to export the macro to make it
/// available outside of the crate, use the [`macro_export` attribute].
///
/// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
pub UNUSED_MACROS,
Warn,
"detects macros that were not used"
}
declare_lint! {
/// The `unused_macro_rules` lint detects macro rules that were not used.
///
/// Note that the lint is distinct from the `unused_macros` lint, which
/// fires if the entire macro is never called, while this lint fires for
/// single unused rules of the macro that is otherwise used.
/// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
///
/// ### Example
///
/// ```rust
/// #[warn(unused_macro_rules)]
/// macro_rules! unused_empty {
/// (hello) => { println!("Hello, world!") }; // This rule is unused
/// () => { println!("empty") }; // This rule is used
/// }
///
/// fn main() {
/// unused_empty!(hello);
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Unused macro rules may signal a mistake or unfinished code. Furthermore,
/// they slow down compilation. Right now, silencing the warning is not
/// supported on a single rule level, so you have to add an allow to the
/// entire macro definition.
///
/// If you intended to export the macro to make it
/// available outside of the crate, use the [`macro_export` attribute].
///
/// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
pub UNUSED_MACRO_RULES,
Allow,
"detects macro rules that were not used"
}
declare_lint! {
/// The `warnings` lint allows you to change the level of other
/// lints which produce warnings.
///
/// ### Example
///
/// ```rust
/// #![deny(warnings)]
/// fn foo() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The `warnings` lint is a bit special; by changing its level, you
/// change every other warning that would produce a warning to whatever
/// value you'd like. As such, you won't ever trigger this lint in your
/// code directly.
pub WARNINGS,
Warn,
"mass-change the level for lints which produce warnings"
}
declare_lint! {
/// The `unused_features` lint detects unused or unknown features found in
/// crate-level [`feature` attributes].
///
/// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// Note: This lint is currently not functional, see [issue #44232] for
/// more details.
///
/// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
pub UNUSED_FEATURES,
Warn,
"unused features found in crate-level `#[feature]` directives"
}
declare_lint! {
/// The `stable_features` lint detects a [`feature` attribute] that
/// has since been made stable.
///
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// ### Example
///
/// ```rust
/// #![feature(test_accepted_feature)]
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// When a feature is stabilized, it is no longer necessary to include a
/// `#![feature]` attribute for it. To fix, simply remove the
/// `#![feature]` attribute.
pub STABLE_FEATURES,
Warn,
"stable features found in `#[feature]` directive"
}
declare_lint! {
/// The `unknown_crate_types` lint detects an unknown crate type found in
/// a [`crate_type` attribute].
///
/// ### Example
///
/// ```rust,compile_fail
/// #![crate_type="lol"]
/// fn main() {}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// An unknown value give to the `crate_type` attribute is almost
/// certainly a mistake.
///
/// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
pub UNKNOWN_CRATE_TYPES,
Deny,
"unknown crate type found in `#[crate_type]` directive",
crate_level_only
}
declare_lint! {
/// The `trivial_casts` lint detects trivial casts which could be replaced
/// with coercion, which may require a temporary variable.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(trivial_casts)]
/// let x: &u32 = &42;
/// let y = x as *const u32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
/// subtype of `T`. This type of cast is usually unnecessary, as it can be
/// usually be inferred.
///
/// This lint is "allow" by default because there are situations, such as
/// with FFI interfaces or complex type aliases, where it triggers
/// incorrectly, or in situations where it will be more difficult to
/// clearly express the intent. It may be possible that this will become a
/// warning in the future, possibly with an explicit syntax for coercions
/// providing a convenient way to work around the current issues.
/// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
/// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
///
/// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
/// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
/// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
pub TRIVIAL_CASTS,
Allow,
"detects trivial casts which could be removed"
}
declare_lint! {
/// The `trivial_numeric_casts` lint detects trivial numeric casts of types
/// which could be removed.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(trivial_numeric_casts)]
/// let x = 42_i32 as i32;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// A trivial numeric cast is a cast of a numeric type to the same numeric
/// type. This type of cast is usually unnecessary.
///
/// This lint is "allow" by default because there are situations, such as
/// with FFI interfaces or complex type aliases, where it triggers
/// incorrectly, or in situations where it will be more difficult to
/// clearly express the intent. It may be possible that this will become a
/// warning in the future, possibly with an explicit syntax for coercions
/// providing a convenient way to work around the current issues.
/// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
/// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
///
/// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
/// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
/// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
pub TRIVIAL_NUMERIC_CASTS,
Allow,
"detects trivial casts of numeric types which could be removed"
}
declare_lint! {
/// The `private_in_public` lint detects private items in public
/// interfaces not caught by the old implementation.
///
/// ### Example
///
/// ```rust
/// # #![allow(unused)]
/// struct SemiPriv;
///
/// mod m1 {
/// struct Priv;
/// impl super::SemiPriv {
/// pub fn f(_: Priv) {}
/// }
/// }
/// # fn main() {}