-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
builtin.rs
5179 lines (5044 loc) · 177 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`.
//!
//! When removing a lint, make sure to also add a call to `register_removed` in
//! compiler/rustc_lint/src/lib.rs.
use rustc_span::edition::Edition;
use crate::{FutureIncompatibilityReason, declare_lint, declare_lint_pass};
declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
HardwiredLints => [
// tidy-alphabetical-start
ABI_UNSUPPORTED_VECTOR_TYPES,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS,
AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS,
ARITHMETIC_OVERFLOW,
ASM_SUB_REGISTER,
BAD_ASM_STYLE,
BARE_TRAIT_OBJECTS,
BINDINGS_WITH_VARIANT_NAME,
BREAK_WITH_LABEL_AND_LOOP,
CENUM_IMPL_DROP_CAST,
COHERENCE_LEAK_CHECK,
CONFLICTING_REPR_HINTS,
CONST_EVALUATABLE_UNCHECKED,
CONST_ITEM_MUTATION,
DEAD_CODE,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
DEPRECATED,
DEPRECATED_IN_FUTURE,
DEPRECATED_SAFE_2024,
DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS,
ELIDED_NAMED_LIFETIMES,
EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES,
FFI_UNWIND_CALLS,
FORBIDDEN_LINT_GROUPS,
FUNCTION_ITEM_REFERENCES,
FUZZY_PROVENANCE_CASTS,
HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT,
INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
INLINE_NO_SANITIZE,
INVALID_DOC_ATTRIBUTES,
INVALID_MACRO_EXPORT_ARGUMENTS,
INVALID_TYPE_PARAM_DEFAULT,
IRREFUTABLE_LET_PATTERNS,
LARGE_ASSIGNMENTS,
LATE_BOUND_LIFETIME_ARGUMENTS,
LEGACY_DERIVE_HELPERS,
LONG_RUNNING_CONST_EVAL,
LOSSY_PROVENANCE_CASTS,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
MACRO_USE_EXTERN_CRATE,
META_VARIABLE_MISUSE,
MISSING_ABI,
MISSING_FRAGMENT_SPECIFIER,
MISSING_UNSAFE_ON_EXTERN,
MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
NON_CONTIGUOUS_RANGE_ENDPOINTS,
NON_EXHAUSTIVE_OMITTED_PATTERNS,
ORDER_DEPENDENT_TRAIT_OBJECTS,
OUT_OF_SCOPE_MACRO_CALLS,
OVERLAPPING_RANGE_ENDPOINTS,
PATTERNS_IN_FNS_WITHOUT_BODY,
PRIVATE_BOUNDS,
PRIVATE_INTERFACES,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
PTR_CAST_ADD_AUTO_TO_OBJECT,
PTR_TO_INTEGER_TRANSMUTE_IN_CONSTS,
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
REDUNDANT_IMPORTS,
REDUNDANT_LIFETIMES,
REFINING_IMPL_TRAIT_INTERNAL,
REFINING_IMPL_TRAIT_REACHABLE,
RENAMED_AND_REMOVED_LINTS,
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
RUST_2021_PRELUDE_COLLISIONS,
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
RUST_2024_INCOMPATIBLE_PAT,
RUST_2024_PRELUDE_COLLISIONS,
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
SINGLE_USE_LIFETIMES,
SOFT_UNSTABLE,
STABLE_FEATURES,
TAIL_EXPR_DROP_ORDER,
TEST_UNSTABLE_LINT,
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
TYVAR_BEHIND_RAW_POINTER,
UNCONDITIONAL_PANIC,
UNCONDITIONAL_RECURSION,
UNCOVERED_PARAM_IN_PROJECTION,
UNDEFINED_NAKED_FUNCTION_ABI,
UNEXPECTED_CFGS,
UNFULFILLED_LINT_EXPECTATIONS,
UNINHABITED_STATIC,
UNKNOWN_CRATE_TYPES,
UNKNOWN_LINTS,
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
UNNAMEABLE_TEST_ITEMS,
UNNAMEABLE_TYPES,
UNREACHABLE_CODE,
UNREACHABLE_PATTERNS,
UNSAFE_ATTR_OUTSIDE_UNSAFE,
UNSAFE_OP_IN_UNSAFE_FN,
UNSTABLE_NAME_COLLISIONS,
UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
UNUSED_ASSIGNMENTS,
UNUSED_ASSOCIATED_TYPE_BOUNDS,
UNUSED_ATTRIBUTES,
UNUSED_CRATE_DEPENDENCIES,
UNUSED_EXTERN_CRATES,
UNUSED_FEATURES,
UNUSED_IMPORTS,
UNUSED_LABELS,
UNUSED_LIFETIMES,
UNUSED_MACRO_RULES,
UNUSED_MACROS,
UNUSED_MUT,
UNUSED_QUALIFICATIONS,
UNUSED_UNSAFE,
UNUSED_VARIABLES,
USELESS_DEPRECATED,
WARNINGS,
WASM_C_ABI,
// tidy-alphabetical-end
]
}
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)]
/// #![warn(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 {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
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 {
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
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 {
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
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",
@eval_always = true
}
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",
@eval_always = true
}
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 `redundant_imports` lint detects imports that are redundant due to being
/// imported already; either through a previous import, or being present in
/// the prelude.
///
/// ### Example
///
/// ```rust,compile_fail
/// #![deny(redundant_imports)]
/// use std::option::Option::None;
/// fn foo() -> Option<i32> { None }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// Redundant imports are unnecessary and can be removed to simplify code.
/// If you intended to re-export the item to make it available outside of the
/// module, add a visibility modifier like `pub`.
pub REDUNDANT_IMPORTS,
Allow,
"imports that are redundant due to being imported already"
}
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;
/// let _guard = guard;
/// }
/// ```
///
/// {{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 = 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)]
/// #![deny(warnings)]
/// 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: extern crate `regex` is unused in crate `lint_example`
/// |
/// = help: remove the dependency or add `use regex as _;` to the crate root
/// 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();
/// 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",
@eval_always = true
}
declare_lint! {
/// The `unfulfilled_lint_expectations` lint detects when a lint expectation is
/// unfulfilled.
///
/// ### Example
///
/// ```rust
/// #[expect(unused_variables)]
/// let x = 10;
/// println!("{}", x);
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// The `#[expect]` attribute can be used to create a lint expectation. The
/// expectation is fulfilled, if a `#[warn]` attribute at the same location
/// would result in a lint emission. If the expectation is unfulfilled,
/// because no lint was emitted, this lint will be emitted on the attribute.
///
pub UNFULFILLED_LINT_EXPECTATIONS,
Warn,
"unfulfilled lint expectation"
}
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`.
///
/// To preserve the numbering of tuple structs with unused fields,
/// change the unused fields to have unit type or use
/// `PhantomData`.
///
/// Otherwise consider removing the unused code.
///
/// ### Limitations
///
/// Removing fields that are only used for side-effects and never
/// read will result in behavioral changes. Examples of this
/// include:
///
/// - If a field's value performs an action when it is dropped.
/// - If a field's type does not implement an auto trait
/// (e.g. `Send`, `Sync`, `Unpin`).
///
/// For side-effects from dropping field values, this lint should
/// be allowed on those fields. For side-effects from containing
/// field types, `PhantomData` should be used.
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 `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 `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
/// exclusive [range patterns].
///
/// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
///
/// ### Example
///
/// ```rust
/// let x = 123u32;
/// match x {
/// 0..100 => { println!("small"); }
/// 101..1000 => { println!("large"); }
/// _ => { println!("larger"); }
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is likely a mistake to have range patterns in a match expression that miss out a single
/// number. Check that the beginning and end values are what you expect, and keep in mind that
/// with `..=` the right bound is inclusive, and with `..` it is exclusive.
pub NON_CONTIGUOUS_RANGE_ENDPOINTS,
Warn,
"detects off-by-one errors with exclusive range patterns"
}
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].