rustc_lint_defs/
builtin.rs

1//! Some lints that are built in to the compiler.
2//!
3//! These are the built-in lints that are emitted direct in the main
4//! compiler code, rather than using their own custom pass. Those
5//! lints are all available in `rustc_lint::builtin`.
6//!
7//! When removing a lint, make sure to also add a call to `register_removed` in
8//! compiler/rustc_lint/src/lib.rs.
9
10use rustc_span::edition::Edition;
11
12use crate::{FutureIncompatibilityReason, declare_lint, declare_lint_pass};
13
14declare_lint_pass! {
15    /// Does nothing as a lint pass, but registers some `Lint`s
16    /// that are used by other parts of the compiler.
17    HardwiredLints => [
18        // tidy-alphabetical-start
19        AARCH64_SOFTFLOAT_NEON,
20        ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
21        AMBIGUOUS_ASSOCIATED_ITEMS,
22        AMBIGUOUS_GLOB_IMPORTS,
23        AMBIGUOUS_GLOB_REEXPORTS,
24        ARITHMETIC_OVERFLOW,
25        ASM_SUB_REGISTER,
26        BAD_ASM_STYLE,
27        BARE_TRAIT_OBJECTS,
28        BINDINGS_WITH_VARIANT_NAME,
29        BREAK_WITH_LABEL_AND_LOOP,
30        COHERENCE_LEAK_CHECK,
31        CONFLICTING_REPR_HINTS,
32        CONST_EVALUATABLE_UNCHECKED,
33        CONST_ITEM_MUTATION,
34        DEAD_CODE,
35        DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
36        DEPRECATED,
37        DEPRECATED_IN_FUTURE,
38        DEPRECATED_SAFE_2024,
39        DEPRECATED_WHERE_CLAUSE_LOCATION,
40        DUPLICATE_MACRO_ATTRIBUTES,
41        ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
42        ELIDED_LIFETIMES_IN_PATHS,
43        EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
44        EXPORTED_PRIVATE_DEPENDENCIES,
45        FFI_UNWIND_CALLS,
46        FORBIDDEN_LINT_GROUPS,
47        FUNCTION_ITEM_REFERENCES,
48        FUZZY_PROVENANCE_CASTS,
49        HIDDEN_GLOB_REEXPORTS,
50        ILL_FORMED_ATTRIBUTE_INPUT,
51        INCOMPLETE_INCLUDE,
52        INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
53        INLINE_NO_SANITIZE,
54        INVALID_DOC_ATTRIBUTES,
55        INVALID_MACRO_EXPORT_ARGUMENTS,
56        INVALID_TYPE_PARAM_DEFAULT,
57        IRREFUTABLE_LET_PATTERNS,
58        LARGE_ASSIGNMENTS,
59        LATE_BOUND_LIFETIME_ARGUMENTS,
60        LEGACY_DERIVE_HELPERS,
61        LINKER_MESSAGES,
62        LONG_RUNNING_CONST_EVAL,
63        LOSSY_PROVENANCE_CASTS,
64        MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
65        MACRO_USE_EXTERN_CRATE,
66        META_VARIABLE_MISUSE,
67        MISSING_ABI,
68        MISSING_UNSAFE_ON_EXTERN,
69        MUST_NOT_SUSPEND,
70        NAMED_ARGUMENTS_USED_POSITIONALLY,
71        NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
72        NON_CONTIGUOUS_RANGE_ENDPOINTS,
73        NON_EXHAUSTIVE_OMITTED_PATTERNS,
74        OUT_OF_SCOPE_MACRO_CALLS,
75        OVERLAPPING_RANGE_ENDPOINTS,
76        PATTERNS_IN_FNS_WITHOUT_BODY,
77        PRIVATE_BOUNDS,
78        PRIVATE_INTERFACES,
79        PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
80        PUB_USE_OF_PRIVATE_EXTERN_CRATE,
81        REDUNDANT_IMPORTS,
82        REDUNDANT_LIFETIMES,
83        REFINING_IMPL_TRAIT_INTERNAL,
84        REFINING_IMPL_TRAIT_REACHABLE,
85        RENAMED_AND_REMOVED_LINTS,
86        REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
87        RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
88        RUST_2021_INCOMPATIBLE_OR_PATTERNS,
89        RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
90        RUST_2021_PRELUDE_COLLISIONS,
91        RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
92        RUST_2024_INCOMPATIBLE_PAT,
93        RUST_2024_PRELUDE_COLLISIONS,
94        SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
95        SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
96        SINGLE_USE_LIFETIMES,
97        SOFT_UNSTABLE,
98        STABLE_FEATURES,
99        SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
100        SUPERTRAIT_ITEM_SHADOWING_USAGE,
101        TAIL_EXPR_DROP_ORDER,
102        TEST_UNSTABLE_LINT,
103        TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
104        TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
105        TRIVIAL_CASTS,
106        TRIVIAL_NUMERIC_CASTS,
107        TYVAR_BEHIND_RAW_POINTER,
108        UNCONDITIONAL_PANIC,
109        UNCONDITIONAL_RECURSION,
110        UNCOVERED_PARAM_IN_PROJECTION,
111        UNEXPECTED_CFGS,
112        UNFULFILLED_LINT_EXPECTATIONS,
113        UNINHABITED_STATIC,
114        UNKNOWN_CRATE_TYPES,
115        UNKNOWN_LINTS,
116        UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
117        UNNAMEABLE_TEST_ITEMS,
118        UNNAMEABLE_TYPES,
119        UNREACHABLE_CODE,
120        UNREACHABLE_PATTERNS,
121        UNSAFE_ATTR_OUTSIDE_UNSAFE,
122        UNSAFE_OP_IN_UNSAFE_FN,
123        UNSTABLE_NAME_COLLISIONS,
124        UNSTABLE_SYNTAX_PRE_EXPANSION,
125        UNUSED_ASSIGNMENTS,
126        UNUSED_ASSOCIATED_TYPE_BOUNDS,
127        UNUSED_ATTRIBUTES,
128        UNUSED_CRATE_DEPENDENCIES,
129        UNUSED_EXTERN_CRATES,
130        UNUSED_FEATURES,
131        UNUSED_IMPORTS,
132        UNUSED_LABELS,
133        UNUSED_LIFETIMES,
134        UNUSED_MACROS,
135        UNUSED_MACRO_RULES,
136        UNUSED_MUT,
137        UNUSED_QUALIFICATIONS,
138        UNUSED_UNSAFE,
139        UNUSED_VARIABLES,
140        USELESS_DEPRECATED,
141        WARNINGS,
142        // tidy-alphabetical-end
143    ]
144}
145
146declare_lint! {
147    /// The `forbidden_lint_groups` lint detects violations of
148    /// `forbid` applied to a lint group. Due to a bug in the compiler,
149    /// these used to be overlooked entirely. They now generate a warning.
150    ///
151    /// ### Example
152    ///
153    /// ```rust
154    /// #![forbid(warnings)]
155    /// #![warn(bad_style)]
156    ///
157    /// fn main() {}
158    /// ```
159    ///
160    /// {{produces}}
161    ///
162    /// ### Recommended fix
163    ///
164    /// If your crate is using `#![forbid(warnings)]`,
165    /// we recommend that you change to `#![deny(warnings)]`.
166    ///
167    /// ### Explanation
168    ///
169    /// Due to a compiler bug, applying `forbid` to lint groups
170    /// previously had no effect. The bug is now fixed but instead of
171    /// enforcing `forbid` we issue this future-compatibility warning
172    /// to avoid breaking existing crates.
173    pub FORBIDDEN_LINT_GROUPS,
174    Warn,
175    "applying forbid to lint-groups",
176    @future_incompatible = FutureIncompatibleInfo {
177        reason: FutureIncompatibilityReason::FutureReleaseError,
178        reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
179        report_in_deps: true,
180    };
181}
182
183declare_lint! {
184    /// The `ill_formed_attribute_input` lint detects ill-formed attribute
185    /// inputs that were previously accepted and used in practice.
186    ///
187    /// ### Example
188    ///
189    /// ```rust,compile_fail
190    /// #[inline = "this is not valid"]
191    /// fn foo() {}
192    /// ```
193    ///
194    /// {{produces}}
195    ///
196    /// ### Explanation
197    ///
198    /// Previously, inputs for many built-in attributes weren't validated and
199    /// nonsensical attribute inputs were accepted. After validation was
200    /// added, it was determined that some existing projects made use of these
201    /// invalid forms. This is a [future-incompatible] lint to transition this
202    /// to a hard error in the future. See [issue #57571] for more details.
203    ///
204    /// Check the [attribute reference] for details on the valid inputs for
205    /// attributes.
206    ///
207    /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
208    /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
209    /// [future-incompatible]: ../index.md#future-incompatible-lints
210    pub ILL_FORMED_ATTRIBUTE_INPUT,
211    Deny,
212    "ill-formed attribute inputs that were previously accepted and used in practice",
213    @future_incompatible = FutureIncompatibleInfo {
214        reason: FutureIncompatibilityReason::FutureReleaseError,
215        reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
216    };
217    crate_level_only
218}
219
220declare_lint! {
221    /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
222    /// conflicting hints.
223    ///
224    /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
225    ///
226    /// ### Example
227    ///
228    /// ```rust,compile_fail
229    /// #[repr(u32, u64)]
230    /// enum Foo {
231    ///     Variant1,
232    /// }
233    /// ```
234    ///
235    /// {{produces}}
236    ///
237    /// ### Explanation
238    ///
239    /// The compiler incorrectly accepted these conflicting representations in
240    /// the past. This is a [future-incompatible] lint to transition this to a
241    /// hard error in the future. See [issue #68585] for more details.
242    ///
243    /// To correct the issue, remove one of the conflicting hints.
244    ///
245    /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
246    /// [future-incompatible]: ../index.md#future-incompatible-lints
247    pub CONFLICTING_REPR_HINTS,
248    Deny,
249    "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
250    @future_incompatible = FutureIncompatibleInfo {
251        reason: FutureIncompatibilityReason::FutureReleaseError,
252        reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
253        report_in_deps: true,
254    };
255}
256
257declare_lint! {
258    /// The `meta_variable_misuse` lint detects possible meta-variable misuse
259    /// in macro definitions.
260    ///
261    /// ### Example
262    ///
263    /// ```rust,compile_fail
264    /// #![deny(meta_variable_misuse)]
265    ///
266    /// macro_rules! foo {
267    ///     () => {};
268    ///     ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
269    /// }
270    ///
271    /// fn main() {
272    ///     foo!();
273    /// }
274    /// ```
275    ///
276    /// {{produces}}
277    ///
278    /// ### Explanation
279    ///
280    /// There are quite a few different ways a [`macro_rules`] macro can be
281    /// improperly defined. Many of these errors were previously only detected
282    /// when the macro was expanded or not at all. This lint is an attempt to
283    /// catch some of these problems when the macro is *defined*.
284    ///
285    /// This lint is "allow" by default because it may have false positives
286    /// and other issues. See [issue #61053] for more details.
287    ///
288    /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
289    /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
290    pub META_VARIABLE_MISUSE,
291    Allow,
292    "possible meta-variable misuse at macro definition"
293}
294
295declare_lint! {
296    /// The `incomplete_include` lint detects the use of the [`include!`]
297    /// macro with a file that contains more than one expression.
298    ///
299    /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
300    ///
301    /// ### Example
302    ///
303    /// ```rust,ignore (needs separate file)
304    /// fn main() {
305    ///     include!("foo.txt");
306    /// }
307    /// ```
308    ///
309    /// where the file `foo.txt` contains:
310    ///
311    /// ```text
312    /// println!("hi!");
313    /// ```
314    ///
315    /// produces:
316    ///
317    /// ```text
318    /// error: include macro expected single expression in source
319    ///  --> foo.txt:1:14
320    ///   |
321    /// 1 | println!("1");
322    ///   |              ^
323    ///   |
324    ///   = note: `#[deny(incomplete_include)]` on by default
325    /// ```
326    ///
327    /// ### Explanation
328    ///
329    /// The [`include!`] macro is currently only intended to be used to
330    /// include a single [expression] or multiple [items]. Historically it
331    /// would ignore any contents after the first expression, but that can be
332    /// confusing. In the example above, the `println!` expression ends just
333    /// before the semicolon, making the semicolon "extra" information that is
334    /// ignored. Perhaps even more surprising, if the included file had
335    /// multiple print statements, the subsequent ones would be ignored!
336    ///
337    /// One workaround is to place the contents in braces to create a [block
338    /// expression]. Also consider alternatives, like using functions to
339    /// encapsulate the expressions, or use [proc-macros].
340    ///
341    /// This is a lint instead of a hard error because existing projects were
342    /// found to hit this error. To be cautious, it is a lint for now. The
343    /// future semantics of the `include!` macro are also uncertain, see
344    /// [issue #35560].
345    ///
346    /// [items]: https://doc.rust-lang.org/reference/items.html
347    /// [expression]: https://doc.rust-lang.org/reference/expressions.html
348    /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
349    /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
350    /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
351    pub INCOMPLETE_INCLUDE,
352    Deny,
353    "trailing content in included file"
354}
355
356declare_lint! {
357    /// The `arithmetic_overflow` lint detects that an arithmetic operation
358    /// will [overflow].
359    ///
360    /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
361    ///
362    /// ### Example
363    ///
364    /// ```rust,compile_fail
365    /// 1_i32 << 32;
366    /// ```
367    ///
368    /// {{produces}}
369    ///
370    /// ### Explanation
371    ///
372    /// It is very likely a mistake to perform an arithmetic operation that
373    /// overflows its value. If the compiler is able to detect these kinds of
374    /// overflows at compile-time, it will trigger this lint. Consider
375    /// adjusting the expression to avoid overflow, or use a data type that
376    /// will not overflow.
377    pub ARITHMETIC_OVERFLOW,
378    Deny,
379    "arithmetic operation overflows",
380    @eval_always = true
381}
382
383declare_lint! {
384    /// The `unconditional_panic` lint detects an operation that will cause a
385    /// panic at runtime.
386    ///
387    /// ### Example
388    ///
389    /// ```rust,compile_fail
390    /// # #![allow(unused)]
391    /// let x = 1 / 0;
392    /// ```
393    ///
394    /// {{produces}}
395    ///
396    /// ### Explanation
397    ///
398    /// This lint detects code that is very likely incorrect because it will
399    /// always panic, such as division by zero and out-of-bounds array
400    /// accesses. Consider adjusting your code if this is a bug, or using the
401    /// `panic!` or `unreachable!` macro instead in case the panic is intended.
402    pub UNCONDITIONAL_PANIC,
403    Deny,
404    "operation will cause a panic at runtime",
405    @eval_always = true
406}
407
408declare_lint! {
409    /// The `unused_imports` lint detects imports that are never used.
410    ///
411    /// ### Example
412    ///
413    /// ```rust
414    /// use std::collections::HashMap;
415    /// ```
416    ///
417    /// {{produces}}
418    ///
419    /// ### Explanation
420    ///
421    /// Unused imports may signal a mistake or unfinished code, and clutter
422    /// the code, and should be removed. If you intended to re-export the item
423    /// to make it available outside of the module, add a visibility modifier
424    /// like `pub`.
425    pub UNUSED_IMPORTS,
426    Warn,
427    "imports that are never used"
428}
429
430declare_lint! {
431    /// The `redundant_imports` lint detects imports that are redundant due to being
432    /// imported already; either through a previous import, or being present in
433    /// the prelude.
434    ///
435    /// ### Example
436    ///
437    /// ```rust,compile_fail
438    /// #![deny(redundant_imports)]
439    /// use std::option::Option::None;
440    /// fn foo() -> Option<i32> { None }
441    /// ```
442    ///
443    /// {{produces}}
444    ///
445    /// ### Explanation
446    ///
447    /// Redundant imports are unnecessary and can be removed to simplify code.
448    /// If you intended to re-export the item to make it available outside of the
449    /// module, add a visibility modifier like `pub`.
450    pub REDUNDANT_IMPORTS,
451    Allow,
452    "imports that are redundant due to being imported already"
453}
454
455declare_lint! {
456    /// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
457    /// (`.await`)
458    ///
459    /// ### Example
460    ///
461    /// ```rust
462    /// #![feature(must_not_suspend)]
463    /// #![warn(must_not_suspend)]
464    ///
465    /// #[must_not_suspend]
466    /// struct SyncThing {}
467    ///
468    /// async fn yield_now() {}
469    ///
470    /// pub async fn uhoh() {
471    ///     let guard = SyncThing {};
472    ///     yield_now().await;
473    ///     let _guard = guard;
474    /// }
475    /// ```
476    ///
477    /// {{produces}}
478    ///
479    /// ### Explanation
480    ///
481    /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
482    /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
483    /// function.
484    ///
485    /// This attribute can be used to mark values that are semantically incorrect across suspends
486    /// (like certain types of timers), values that have async alternatives, and values that
487    /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
488    /// `MutexGuard`'s)
489    ///
490    pub MUST_NOT_SUSPEND,
491    Allow,
492    "use of a `#[must_not_suspend]` value across a yield point",
493    @feature_gate = must_not_suspend;
494}
495
496declare_lint! {
497    /// The `unused_extern_crates` lint guards against `extern crate` items
498    /// that are never used.
499    ///
500    /// ### Example
501    ///
502    /// ```rust,compile_fail
503    /// #![deny(unused_extern_crates)]
504    /// #![deny(warnings)]
505    /// extern crate proc_macro;
506    /// ```
507    ///
508    /// {{produces}}
509    ///
510    /// ### Explanation
511    ///
512    /// `extern crate` items that are unused have no effect and should be
513    /// removed. Note that there are some cases where specifying an `extern
514    /// crate` is desired for the side effect of ensuring the given crate is
515    /// linked, even though it is not otherwise directly referenced. The lint
516    /// can be silenced by aliasing the crate to an underscore, such as
517    /// `extern crate foo as _`. Also note that it is no longer idiomatic to
518    /// use `extern crate` in the [2018 edition], as extern crates are now
519    /// automatically added in scope.
520    ///
521    /// This lint is "allow" by default because it can be noisy, and produce
522    /// false-positives. If a dependency is being removed from a project, it
523    /// is recommended to remove it from the build configuration (such as
524    /// `Cargo.toml`) to ensure stale build entries aren't left behind.
525    ///
526    /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
527    pub UNUSED_EXTERN_CRATES,
528    Allow,
529    "extern crates that are never used"
530}
531
532declare_lint! {
533    /// The `unused_crate_dependencies` lint detects crate dependencies that
534    /// are never used.
535    ///
536    /// ### Example
537    ///
538    /// ```rust,ignore (needs extern crate)
539    /// #![deny(unused_crate_dependencies)]
540    /// ```
541    ///
542    /// This will produce:
543    ///
544    /// ```text
545    /// error: extern crate `regex` is unused in crate `lint_example`
546    ///   |
547    ///   = help: remove the dependency or add `use regex as _;` to the crate root
548    /// note: the lint level is defined here
549    ///  --> src/lib.rs:1:9
550    ///   |
551    /// 1 | #![deny(unused_crate_dependencies)]
552    ///   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
553    /// ```
554    ///
555    /// ### Explanation
556    ///
557    /// After removing the code that uses a dependency, this usually also
558    /// requires removing the dependency from the build configuration.
559    /// However, sometimes that step can be missed, which leads to time wasted
560    /// building dependencies that are no longer used. This lint can be
561    /// enabled to detect dependencies that are never used (more specifically,
562    /// any dependency passed with the `--extern` command-line flag that is
563    /// never referenced via [`use`], [`extern crate`], or in any [path]).
564    ///
565    /// This lint is "allow" by default because it can provide false positives
566    /// depending on how the build system is configured. For example, when
567    /// using Cargo, a "package" consists of multiple crates (such as a
568    /// library and a binary), but the dependencies are defined for the
569    /// package as a whole. If there is a dependency that is only used in the
570    /// binary, but not the library, then the lint will be incorrectly issued
571    /// in the library.
572    ///
573    /// [path]: https://doc.rust-lang.org/reference/paths.html
574    /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
575    /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
576    pub UNUSED_CRATE_DEPENDENCIES,
577    Allow,
578    "crate dependencies that are never used",
579    crate_level_only
580}
581
582declare_lint! {
583    /// The `unused_qualifications` lint detects unnecessarily qualified
584    /// names.
585    ///
586    /// ### Example
587    ///
588    /// ```rust,compile_fail
589    /// #![deny(unused_qualifications)]
590    /// mod foo {
591    ///     pub fn bar() {}
592    /// }
593    ///
594    /// fn main() {
595    ///     use foo::bar;
596    ///     foo::bar();
597    ///     bar();
598    /// }
599    /// ```
600    ///
601    /// {{produces}}
602    ///
603    /// ### Explanation
604    ///
605    /// If an item from another module is already brought into scope, then
606    /// there is no need to qualify it in this case. You can call `bar()`
607    /// directly, without the `foo::`.
608    ///
609    /// This lint is "allow" by default because it is somewhat pedantic, and
610    /// doesn't indicate an actual problem, but rather a stylistic choice, and
611    /// can be noisy when refactoring or moving around code.
612    pub UNUSED_QUALIFICATIONS,
613    Allow,
614    "detects unnecessarily qualified names"
615}
616
617declare_lint! {
618    /// The `unknown_lints` lint detects unrecognized lint attributes.
619    ///
620    /// ### Example
621    ///
622    /// ```rust
623    /// #![allow(not_a_real_lint)]
624    /// ```
625    ///
626    /// {{produces}}
627    ///
628    /// ### Explanation
629    ///
630    /// It is usually a mistake to specify a lint that does not exist. Check
631    /// the spelling, and check the lint listing for the correct name. Also
632    /// consider if you are using an old version of the compiler, and the lint
633    /// is only available in a newer version.
634    pub UNKNOWN_LINTS,
635    Warn,
636    "unrecognized lint attribute",
637    @eval_always = true
638}
639
640declare_lint! {
641    /// The `unfulfilled_lint_expectations` lint detects when a lint expectation is
642    /// unfulfilled.
643    ///
644    /// ### Example
645    ///
646    /// ```rust
647    /// #[expect(unused_variables)]
648    /// let x = 10;
649    /// println!("{}", x);
650    /// ```
651    ///
652    /// {{produces}}
653    ///
654    /// ### Explanation
655    ///
656    /// The `#[expect]` attribute can be used to create a lint expectation. The
657    /// expectation is fulfilled, if a `#[warn]` attribute at the same location
658    /// would result in a lint emission. If the expectation is unfulfilled,
659    /// because no lint was emitted, this lint will be emitted on the attribute.
660    ///
661    pub UNFULFILLED_LINT_EXPECTATIONS,
662    Warn,
663    "unfulfilled lint expectation"
664}
665
666declare_lint! {
667    /// The `unused_variables` lint detects variables which are not used in
668    /// any way.
669    ///
670    /// ### Example
671    ///
672    /// ```rust
673    /// let x = 5;
674    /// ```
675    ///
676    /// {{produces}}
677    ///
678    /// ### Explanation
679    ///
680    /// Unused variables may signal a mistake or unfinished code. To silence
681    /// the warning for the individual variable, prefix it with an underscore
682    /// such as `_x`.
683    pub UNUSED_VARIABLES,
684    Warn,
685    "detect variables which are not used in any way"
686}
687
688declare_lint! {
689    /// The `unused_assignments` lint detects assignments that will never be read.
690    ///
691    /// ### Example
692    ///
693    /// ```rust
694    /// let mut x = 5;
695    /// x = 6;
696    /// ```
697    ///
698    /// {{produces}}
699    ///
700    /// ### Explanation
701    ///
702    /// Unused assignments may signal a mistake or unfinished code. If the
703    /// variable is never used after being assigned, then the assignment can
704    /// be removed. Variables with an underscore prefix such as `_x` will not
705    /// trigger this lint.
706    pub UNUSED_ASSIGNMENTS,
707    Warn,
708    "detect assignments that will never be read"
709}
710
711declare_lint! {
712    /// The `dead_code` lint detects unused, unexported items.
713    ///
714    /// ### Example
715    ///
716    /// ```rust
717    /// fn foo() {}
718    /// ```
719    ///
720    /// {{produces}}
721    ///
722    /// ### Explanation
723    ///
724    /// Dead code may signal a mistake or unfinished code. To silence the
725    /// warning for individual items, prefix the name with an underscore such
726    /// as `_foo`. If it was intended to expose the item outside of the crate,
727    /// consider adding a visibility modifier like `pub`.
728    ///
729    /// To preserve the numbering of tuple structs with unused fields,
730    /// change the unused fields to have unit type or use
731    /// `PhantomData`.
732    ///
733    /// Otherwise consider removing the unused code.
734    ///
735    /// ### Limitations
736    ///
737    /// Removing fields that are only used for side-effects and never
738    /// read will result in behavioral changes. Examples of this
739    /// include:
740    ///
741    /// - If a field's value performs an action when it is dropped.
742    /// - If a field's type does not implement an auto trait
743    ///   (e.g. `Send`, `Sync`, `Unpin`).
744    ///
745    /// For side-effects from dropping field values, this lint should
746    /// be allowed on those fields. For side-effects from containing
747    /// field types, `PhantomData` should be used.
748    pub DEAD_CODE,
749    Warn,
750    "detect unused, unexported items"
751}
752
753declare_lint! {
754    /// The `unused_attributes` lint detects attributes that were not used by
755    /// the compiler.
756    ///
757    /// ### Example
758    ///
759    /// ```rust
760    /// #![ignore]
761    /// ```
762    ///
763    /// {{produces}}
764    ///
765    /// ### Explanation
766    ///
767    /// Unused [attributes] may indicate the attribute is placed in the wrong
768    /// position. Consider removing it, or placing it in the correct position.
769    /// Also consider if you intended to use an _inner attribute_ (with a `!`
770    /// such as `#![allow(unused)]`) which applies to the item the attribute
771    /// is within, or an _outer attribute_ (without a `!` such as
772    /// `#[allow(unused)]`) which applies to the item *following* the
773    /// attribute.
774    ///
775    /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
776    pub UNUSED_ATTRIBUTES,
777    Warn,
778    "detects attributes that were not used by the compiler"
779}
780
781declare_lint! {
782    /// The `unreachable_code` lint detects unreachable code paths.
783    ///
784    /// ### Example
785    ///
786    /// ```rust,no_run
787    /// panic!("we never go past here!");
788    ///
789    /// let x = 5;
790    /// ```
791    ///
792    /// {{produces}}
793    ///
794    /// ### Explanation
795    ///
796    /// Unreachable code may signal a mistake or unfinished code. If the code
797    /// is no longer in use, consider removing it.
798    pub UNREACHABLE_CODE,
799    Warn,
800    "detects unreachable code paths",
801    report_in_external_macro
802}
803
804declare_lint! {
805    /// The `unreachable_patterns` lint detects unreachable patterns.
806    ///
807    /// ### Example
808    ///
809    /// ```rust
810    /// let x = 5;
811    /// match x {
812    ///     y => (),
813    ///     5 => (),
814    /// }
815    /// ```
816    ///
817    /// {{produces}}
818    ///
819    /// ### Explanation
820    ///
821    /// This usually indicates a mistake in how the patterns are specified or
822    /// ordered. In this example, the `y` pattern will always match, so the
823    /// five is impossible to reach. Remember, match arms match in order, you
824    /// probably wanted to put the `5` case above the `y` case.
825    pub UNREACHABLE_PATTERNS,
826    Warn,
827    "detects unreachable patterns"
828}
829
830declare_lint! {
831    /// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
832    /// overlap on their endpoints.
833    ///
834    /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
835    ///
836    /// ### Example
837    ///
838    /// ```rust
839    /// let x = 123u8;
840    /// match x {
841    ///     0..=100 => { println!("small"); }
842    ///     100..=255 => { println!("large"); }
843    /// }
844    /// ```
845    ///
846    /// {{produces}}
847    ///
848    /// ### Explanation
849    ///
850    /// It is likely a mistake to have range patterns in a match expression that overlap in this
851    /// way. Check that the beginning and end values are what you expect, and keep in mind that
852    /// with `..=` the left and right bounds are inclusive.
853    pub OVERLAPPING_RANGE_ENDPOINTS,
854    Warn,
855    "detects range patterns with overlapping endpoints"
856}
857
858declare_lint! {
859    /// The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
860    /// exclusive [range patterns].
861    ///
862    /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
863    ///
864    /// ### Example
865    ///
866    /// ```rust
867    /// let x = 123u32;
868    /// match x {
869    ///     0..100 => { println!("small"); }
870    ///     101..1000 => { println!("large"); }
871    ///     _ => { println!("larger"); }
872    /// }
873    /// ```
874    ///
875    /// {{produces}}
876    ///
877    /// ### Explanation
878    ///
879    /// It is likely a mistake to have range patterns in a match expression that miss out a single
880    /// number. Check that the beginning and end values are what you expect, and keep in mind that
881    /// with `..=` the right bound is inclusive, and with `..` it is exclusive.
882    pub NON_CONTIGUOUS_RANGE_ENDPOINTS,
883    Warn,
884    "detects off-by-one errors with exclusive range patterns"
885}
886
887declare_lint! {
888    /// The `bindings_with_variant_name` lint detects pattern bindings with
889    /// the same name as one of the matched variants.
890    ///
891    /// ### Example
892    ///
893    /// ```rust,compile_fail
894    /// pub enum Enum {
895    ///     Foo,
896    ///     Bar,
897    /// }
898    ///
899    /// pub fn foo(x: Enum) {
900    ///     match x {
901    ///         Foo => {}
902    ///         Bar => {}
903    ///     }
904    /// }
905    /// ```
906    ///
907    /// {{produces}}
908    ///
909    /// ### Explanation
910    ///
911    /// It is usually a mistake to specify an enum variant name as an
912    /// [identifier pattern]. In the example above, the `match` arms are
913    /// specifying a variable name to bind the value of `x` to. The second arm
914    /// is ignored because the first one matches *all* values. The likely
915    /// intent is that the arm was intended to match on the enum variant.
916    ///
917    /// Two possible solutions are:
918    ///
919    /// * Specify the enum variant using a [path pattern], such as
920    ///   `Enum::Foo`.
921    /// * Bring the enum variants into local scope, such as adding `use
922    ///   Enum::*;` to the beginning of the `foo` function in the example
923    ///   above.
924    ///
925    /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
926    /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
927    pub BINDINGS_WITH_VARIANT_NAME,
928    Deny,
929    "detects pattern bindings with the same name as one of the matched variants"
930}
931
932declare_lint! {
933    /// The `unused_macros` lint detects macros that were not used.
934    ///
935    /// Note that this lint is distinct from the `unused_macro_rules` lint,
936    /// which checks for single rules that never match of an otherwise used
937    /// macro, and thus never expand.
938    ///
939    /// ### Example
940    ///
941    /// ```rust
942    /// macro_rules! unused {
943    ///     () => {};
944    /// }
945    ///
946    /// fn main() {
947    /// }
948    /// ```
949    ///
950    /// {{produces}}
951    ///
952    /// ### Explanation
953    ///
954    /// Unused macros may signal a mistake or unfinished code. To silence the
955    /// warning for the individual macro, prefix the name with an underscore
956    /// such as `_my_macro`. If you intended to export the macro to make it
957    /// available outside of the crate, use the [`macro_export` attribute].
958    ///
959    /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
960    pub UNUSED_MACROS,
961    Warn,
962    "detects macros that were not used"
963}
964
965declare_lint! {
966    /// The `unused_macro_rules` lint detects macro rules that were not used.
967    ///
968    /// Note that the lint is distinct from the `unused_macros` lint, which
969    /// fires if the entire macro is never called, while this lint fires for
970    /// single unused rules of the macro that is otherwise used.
971    /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
972    ///
973    /// ### Example
974    ///
975    /// ```rust
976    /// #[warn(unused_macro_rules)]
977    /// macro_rules! unused_empty {
978    ///     (hello) => { println!("Hello, world!") }; // This rule is unused
979    ///     () => { println!("empty") }; // This rule is used
980    /// }
981    ///
982    /// fn main() {
983    ///     unused_empty!(hello);
984    /// }
985    /// ```
986    ///
987    /// {{produces}}
988    ///
989    /// ### Explanation
990    ///
991    /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
992    /// they slow down compilation. Right now, silencing the warning is not
993    /// supported on a single rule level, so you have to add an allow to the
994    /// entire macro definition.
995    ///
996    /// If you intended to export the macro to make it
997    /// available outside of the crate, use the [`macro_export` attribute].
998    ///
999    /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1000    pub UNUSED_MACRO_RULES,
1001    Allow,
1002    "detects macro rules that were not used"
1003}
1004
1005declare_lint! {
1006    /// The `warnings` lint allows you to change the level of other
1007    /// lints which produce warnings.
1008    ///
1009    /// ### Example
1010    ///
1011    /// ```rust
1012    /// #![deny(warnings)]
1013    /// fn foo() {}
1014    /// ```
1015    ///
1016    /// {{produces}}
1017    ///
1018    /// ### Explanation
1019    ///
1020    /// The `warnings` lint is a bit special; by changing its level, you
1021    /// change every other warning that would produce a warning to whatever
1022    /// value you'd like. As such, you won't ever trigger this lint in your
1023    /// code directly.
1024    pub WARNINGS,
1025    Warn,
1026    "mass-change the level for lints which produce warnings"
1027}
1028
1029declare_lint! {
1030    /// The `unused_features` lint detects unused or unknown features found in
1031    /// crate-level [`feature` attributes].
1032    ///
1033    /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1034    ///
1035    /// Note: This lint is currently not functional, see [issue #44232] for
1036    /// more details.
1037    ///
1038    /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
1039    pub UNUSED_FEATURES,
1040    Warn,
1041    "unused features found in crate-level `#[feature]` directives"
1042}
1043
1044declare_lint! {
1045    /// The `stable_features` lint detects a [`feature` attribute] that
1046    /// has since been made stable.
1047    ///
1048    /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1049    ///
1050    /// ### Example
1051    ///
1052    /// ```rust
1053    /// #![feature(test_accepted_feature)]
1054    /// fn main() {}
1055    /// ```
1056    ///
1057    /// {{produces}}
1058    ///
1059    /// ### Explanation
1060    ///
1061    /// When a feature is stabilized, it is no longer necessary to include a
1062    /// `#![feature]` attribute for it. To fix, simply remove the
1063    /// `#![feature]` attribute.
1064    pub STABLE_FEATURES,
1065    Warn,
1066    "stable features found in `#[feature]` directive"
1067}
1068
1069declare_lint! {
1070    /// The `unknown_crate_types` lint detects an unknown crate type found in
1071    /// a [`crate_type` attribute].
1072    ///
1073    /// ### Example
1074    ///
1075    /// ```rust,compile_fail
1076    /// #![crate_type="lol"]
1077    /// fn main() {}
1078    /// ```
1079    ///
1080    /// {{produces}}
1081    ///
1082    /// ### Explanation
1083    ///
1084    /// An unknown value give to the `crate_type` attribute is almost
1085    /// certainly a mistake.
1086    ///
1087    /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
1088    pub UNKNOWN_CRATE_TYPES,
1089    Deny,
1090    "unknown crate type found in `#[crate_type]` directive",
1091    crate_level_only
1092}
1093
1094declare_lint! {
1095    /// The `trivial_casts` lint detects trivial casts which could be replaced
1096    /// with coercion, which may require a temporary variable.
1097    ///
1098    /// ### Example
1099    ///
1100    /// ```rust,compile_fail
1101    /// #![deny(trivial_casts)]
1102    /// let x: &u32 = &42;
1103    /// let y = x as *const u32;
1104    /// ```
1105    ///
1106    /// {{produces}}
1107    ///
1108    /// ### Explanation
1109    ///
1110    /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
1111    /// subtype of `T`. This type of cast is usually unnecessary, as it can be
1112    /// usually be inferred.
1113    ///
1114    /// This lint is "allow" by default because there are situations, such as
1115    /// with FFI interfaces or complex type aliases, where it triggers
1116    /// incorrectly, or in situations where it will be more difficult to
1117    /// clearly express the intent. It may be possible that this will become a
1118    /// warning in the future, possibly with an explicit syntax for coercions
1119    /// providing a convenient way to work around the current issues.
1120    /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1121    /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1122    ///
1123    /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1124    /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1125    /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1126    pub TRIVIAL_CASTS,
1127    Allow,
1128    "detects trivial casts which could be removed"
1129}
1130
1131declare_lint! {
1132    /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
1133    /// which could be removed.
1134    ///
1135    /// ### Example
1136    ///
1137    /// ```rust,compile_fail
1138    /// #![deny(trivial_numeric_casts)]
1139    /// let x = 42_i32 as i32;
1140    /// ```
1141    ///
1142    /// {{produces}}
1143    ///
1144    /// ### Explanation
1145    ///
1146    /// A trivial numeric cast is a cast of a numeric type to the same numeric
1147    /// type. This type of cast is usually unnecessary.
1148    ///
1149    /// This lint is "allow" by default because there are situations, such as
1150    /// with FFI interfaces or complex type aliases, where it triggers
1151    /// incorrectly, or in situations where it will be more difficult to
1152    /// clearly express the intent. It may be possible that this will become a
1153    /// warning in the future, possibly with an explicit syntax for coercions
1154    /// providing a convenient way to work around the current issues.
1155    /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1156    /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1157    ///
1158    /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1159    /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1160    /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1161    pub TRIVIAL_NUMERIC_CASTS,
1162    Allow,
1163    "detects trivial casts of numeric types which could be removed"
1164}
1165
1166declare_lint! {
1167    /// The `exported_private_dependencies` lint detects private dependencies
1168    /// that are exposed in a public interface.
1169    ///
1170    /// ### Example
1171    ///
1172    /// ```rust,ignore (needs-dependency)
1173    /// pub fn foo() -> Option<some_private_dependency::Thing> {
1174    ///     None
1175    /// }
1176    /// ```
1177    ///
1178    /// This will produce:
1179    ///
1180    /// ```text
1181    /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1182    ///  --> src/lib.rs:3:1
1183    ///   |
1184    /// 3 | pub fn foo() -> Option<bar::Thing> {
1185    ///   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1186    ///   |
1187    ///   = note: `#[warn(exported_private_dependencies)]` on by default
1188    /// ```
1189    ///
1190    /// ### Explanation
1191    ///
1192    /// Dependencies can be marked as "private" to indicate that they are not
1193    /// exposed in the public interface of a crate. This can be used by Cargo
1194    /// to independently resolve those dependencies because it can assume it
1195    /// does not need to unify them with other packages using that same
1196    /// dependency. This lint is an indication of a violation of that
1197    /// contract.
1198    ///
1199    /// To fix this, avoid exposing the dependency in your public interface.
1200    /// Or, switch the dependency to a public dependency.
1201    ///
1202    /// Note that support for this is only available on the nightly channel.
1203    /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1204    ///
1205    /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1206    /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1207    pub EXPORTED_PRIVATE_DEPENDENCIES,
1208    Warn,
1209    "public interface leaks type from a private dependency"
1210}
1211
1212declare_lint! {
1213    /// The `pub_use_of_private_extern_crate` lint detects a specific
1214    /// situation of re-exporting a private `extern crate`.
1215    ///
1216    /// ### Example
1217    ///
1218    /// ```rust,compile_fail
1219    /// extern crate core;
1220    /// pub use core as reexported_core;
1221    /// ```
1222    ///
1223    /// {{produces}}
1224    ///
1225    /// ### Explanation
1226    ///
1227    /// A public `use` declaration should not be used to publically re-export a
1228    /// private `extern crate`. `pub extern crate` should be used instead.
1229    ///
1230    /// This was historically allowed, but is not the intended behavior
1231    /// according to the visibility rules. This is a [future-incompatible]
1232    /// lint to transition this to a hard error in the future. See [issue
1233    /// #127909] for more details.
1234    ///
1235    /// [issue #127909]: https://github.com/rust-lang/rust/issues/127909
1236    /// [future-incompatible]: ../index.md#future-incompatible-lints
1237    pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1238    Deny,
1239    "detect public re-exports of private extern crates",
1240    @future_incompatible = FutureIncompatibleInfo {
1241        reason: FutureIncompatibilityReason::FutureReleaseError,
1242        reference: "issue #127909 <https://github.com/rust-lang/rust/issues/127909>",
1243        report_in_deps: true,
1244    };
1245}
1246
1247declare_lint! {
1248    /// The `invalid_type_param_default` lint detects type parameter defaults
1249    /// erroneously allowed in an invalid location.
1250    ///
1251    /// ### Example
1252    ///
1253    /// ```rust,compile_fail
1254    /// fn foo<T=i32>(t: T) {}
1255    /// ```
1256    ///
1257    /// {{produces}}
1258    ///
1259    /// ### Explanation
1260    ///
1261    /// Default type parameters were only intended to be allowed in certain
1262    /// situations, but historically the compiler allowed them everywhere.
1263    /// This is a [future-incompatible] lint to transition this to a hard
1264    /// error in the future. See [issue #36887] for more details.
1265    ///
1266    /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1267    /// [future-incompatible]: ../index.md#future-incompatible-lints
1268    pub INVALID_TYPE_PARAM_DEFAULT,
1269    Deny,
1270    "type parameter default erroneously allowed in invalid location",
1271    @future_incompatible = FutureIncompatibleInfo {
1272        reason: FutureIncompatibilityReason::FutureReleaseError,
1273        reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
1274        report_in_deps: true,
1275    };
1276}
1277
1278declare_lint! {
1279    /// The `renamed_and_removed_lints` lint detects lints that have been
1280    /// renamed or removed.
1281    ///
1282    /// ### Example
1283    ///
1284    /// ```rust
1285    /// #![deny(raw_pointer_derive)]
1286    /// ```
1287    ///
1288    /// {{produces}}
1289    ///
1290    /// ### Explanation
1291    ///
1292    /// To fix this, either remove the lint or use the new name. This can help
1293    /// avoid confusion about lints that are no longer valid, and help
1294    /// maintain consistency for renamed lints.
1295    pub RENAMED_AND_REMOVED_LINTS,
1296    Warn,
1297    "lints that have been renamed or removed"
1298}
1299
1300declare_lint! {
1301    /// The `const_item_mutation` lint detects attempts to mutate a `const`
1302    /// item.
1303    ///
1304    /// ### Example
1305    ///
1306    /// ```rust
1307    /// const FOO: [i32; 1] = [0];
1308    ///
1309    /// fn main() {
1310    ///     FOO[0] = 1;
1311    ///     // This will print "[0]".
1312    ///     println!("{:?}", FOO);
1313    /// }
1314    /// ```
1315    ///
1316    /// {{produces}}
1317    ///
1318    /// ### Explanation
1319    ///
1320    /// Trying to directly mutate a `const` item is almost always a mistake.
1321    /// What is happening in the example above is that a temporary copy of the
1322    /// `const` is mutated, but the original `const` is not. Each time you
1323    /// refer to the `const` by name (such as `FOO` in the example above), a
1324    /// separate copy of the value is inlined at that location.
1325    ///
1326    /// This lint checks for writing directly to a field (`FOO.field =
1327    /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1328    /// reference to the const item (`&mut FOO`), including through an
1329    /// autoderef (`FOO.some_mut_self_method()`).
1330    ///
1331    /// There are various alternatives depending on what you are trying to
1332    /// accomplish:
1333    ///
1334    /// * First, always reconsider using mutable globals, as they can be
1335    ///   difficult to use correctly, and can make the code more difficult to
1336    ///   use or understand.
1337    /// * If you are trying to perform a one-time initialization of a global:
1338    ///     * If the value can be computed at compile-time, consider using
1339    ///       const-compatible values (see [Constant Evaluation]).
1340    ///     * For more complex single-initialization cases, consider using
1341    ///       [`std::sync::LazyLock`].
1342    /// * If you truly need a mutable global, consider using a [`static`],
1343    ///   which has a variety of options:
1344    ///   * Simple data types can be directly defined and mutated with an
1345    ///     [`atomic`] type.
1346    ///   * More complex types can be placed in a synchronization primitive
1347    ///     like a [`Mutex`], which can be initialized with one of the options
1348    ///     listed above.
1349    ///   * A [mutable `static`] is a low-level primitive, requiring unsafe.
1350    ///     Typically This should be avoided in preference of something
1351    ///     higher-level like one of the above.
1352    ///
1353    /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1354    /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1355    /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1356    /// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
1357    /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1358    /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1359    pub CONST_ITEM_MUTATION,
1360    Warn,
1361    "detects attempts to mutate a `const` item",
1362}
1363
1364declare_lint! {
1365    /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1366    /// patterns as a parameter in functions without a body.
1367    ///
1368    /// ### Example
1369    ///
1370    /// ```rust,compile_fail
1371    /// trait Trait {
1372    ///     fn foo(mut arg: u8);
1373    /// }
1374    /// ```
1375    ///
1376    /// {{produces}}
1377    ///
1378    /// ### Explanation
1379    ///
1380    /// To fix this, remove `mut` from the parameter in the trait definition;
1381    /// it can be used in the implementation. That is, the following is OK:
1382    ///
1383    /// ```rust
1384    /// trait Trait {
1385    ///     fn foo(arg: u8); // Removed `mut` here
1386    /// }
1387    ///
1388    /// impl Trait for i32 {
1389    ///     fn foo(mut arg: u8) { // `mut` here is OK
1390    ///
1391    ///     }
1392    /// }
1393    /// ```
1394    ///
1395    /// Trait definitions can define functions without a body to specify a
1396    /// function that implementors must define. The parameter names in the
1397    /// body-less functions are only allowed to be `_` or an [identifier] for
1398    /// documentation purposes (only the type is relevant). Previous versions
1399    /// of the compiler erroneously allowed [identifier patterns] with the
1400    /// `mut` keyword, but this was not intended to be allowed. This is a
1401    /// [future-incompatible] lint to transition this to a hard error in the
1402    /// future. See [issue #35203] for more details.
1403    ///
1404    /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1405    /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1406    /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1407    /// [future-incompatible]: ../index.md#future-incompatible-lints
1408    pub PATTERNS_IN_FNS_WITHOUT_BODY,
1409    Deny,
1410    "patterns in functions without body were erroneously allowed",
1411    @future_incompatible = FutureIncompatibleInfo {
1412        reason: FutureIncompatibilityReason::FutureReleaseError,
1413        reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1414    };
1415}
1416
1417declare_lint! {
1418    /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1419    /// arguments in path segments with late bound lifetime parameters.
1420    ///
1421    /// ### Example
1422    ///
1423    /// ```rust
1424    /// struct S;
1425    ///
1426    /// impl S {
1427    ///     fn late(self, _: &u8, _: &u8) {}
1428    /// }
1429    ///
1430    /// fn main() {
1431    ///     S.late::<'static>(&0, &0);
1432    /// }
1433    /// ```
1434    ///
1435    /// {{produces}}
1436    ///
1437    /// ### Explanation
1438    ///
1439    /// It is not clear how to provide arguments for early-bound lifetime
1440    /// parameters if they are intermixed with late-bound parameters in the
1441    /// same list. For now, providing any explicit arguments will trigger this
1442    /// lint if late-bound parameters are present, so in the future a solution
1443    /// can be adopted without hitting backward compatibility issues. This is
1444    /// a [future-incompatible] lint to transition this to a hard error in the
1445    /// future. See [issue #42868] for more details, along with a description
1446    /// of the difference between early and late-bound parameters.
1447    ///
1448    /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1449    /// [future-incompatible]: ../index.md#future-incompatible-lints
1450    pub LATE_BOUND_LIFETIME_ARGUMENTS,
1451    Warn,
1452    "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1453    @future_incompatible = FutureIncompatibleInfo {
1454        reason: FutureIncompatibilityReason::FutureReleaseError,
1455        reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1456    };
1457}
1458
1459declare_lint! {
1460    /// The `coherence_leak_check` lint detects conflicting implementations of
1461    /// a trait that are only distinguished by the old leak-check code.
1462    ///
1463    /// ### Example
1464    ///
1465    /// ```rust
1466    /// trait SomeTrait { }
1467    /// impl SomeTrait for for<'a> fn(&'a u8) { }
1468    /// impl<'a> SomeTrait for fn(&'a u8) { }
1469    /// ```
1470    ///
1471    /// {{produces}}
1472    ///
1473    /// ### Explanation
1474    ///
1475    /// In the past, the compiler would accept trait implementations for
1476    /// identical functions that differed only in where the lifetime binder
1477    /// appeared. Due to a change in the borrow checker implementation to fix
1478    /// several bugs, this is no longer allowed. However, since this affects
1479    /// existing code, this is a [future-incompatible] lint to transition this
1480    /// to a hard error in the future.
1481    ///
1482    /// Code relying on this pattern should introduce "[newtypes]",
1483    /// like `struct Foo(for<'a> fn(&'a u8))`.
1484    ///
1485    /// See [issue #56105] for more details.
1486    ///
1487    /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1488    /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1489    /// [future-incompatible]: ../index.md#future-incompatible-lints
1490    pub COHERENCE_LEAK_CHECK,
1491    Warn,
1492    "distinct impls distinguished only by the leak-check code",
1493    @future_incompatible = FutureIncompatibleInfo {
1494        reason: FutureIncompatibilityReason::Custom("the behavior may change in a future release"),
1495        reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1496    };
1497}
1498
1499declare_lint! {
1500    /// The `deprecated` lint detects use of deprecated items.
1501    ///
1502    /// ### Example
1503    ///
1504    /// ```rust
1505    /// #[deprecated]
1506    /// fn foo() {}
1507    ///
1508    /// fn bar() {
1509    ///     foo();
1510    /// }
1511    /// ```
1512    ///
1513    /// {{produces}}
1514    ///
1515    /// ### Explanation
1516    ///
1517    /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1518    /// indicate that they should no longer be used. Usually the attribute
1519    /// should include a note on what to use instead, or check the
1520    /// documentation.
1521    ///
1522    /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1523    pub DEPRECATED,
1524    Warn,
1525    "detects use of deprecated items",
1526    report_in_external_macro
1527}
1528
1529declare_lint! {
1530    /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1531    ///
1532    /// ### Example
1533    ///
1534    /// ```rust
1535    /// unsafe {}
1536    /// ```
1537    ///
1538    /// {{produces}}
1539    ///
1540    /// ### Explanation
1541    ///
1542    /// If nothing within the block requires `unsafe`, then remove the
1543    /// `unsafe` marker because it is not required and may cause confusion.
1544    pub UNUSED_UNSAFE,
1545    Warn,
1546    "unnecessary use of an `unsafe` block"
1547}
1548
1549declare_lint! {
1550    /// The `unused_mut` lint detects mut variables which don't need to be
1551    /// mutable.
1552    ///
1553    /// ### Example
1554    ///
1555    /// ```rust
1556    /// let mut x = 5;
1557    /// ```
1558    ///
1559    /// {{produces}}
1560    ///
1561    /// ### Explanation
1562    ///
1563    /// The preferred style is to only mark variables as `mut` if it is
1564    /// required.
1565    pub UNUSED_MUT,
1566    Warn,
1567    "detect mut variables which don't need to be mutable"
1568}
1569
1570declare_lint! {
1571    /// The `rust_2024_incompatible_pat` lint
1572    /// detects patterns whose meaning will change in the Rust 2024 edition.
1573    ///
1574    /// ### Example
1575    ///
1576    /// ```rust,edition2021
1577    /// #![warn(rust_2024_incompatible_pat)]
1578    ///
1579    /// if let Some(&a) = &Some(&0u8) {
1580    ///     let _: u8 = a;
1581    /// }
1582    /// if let Some(mut _a) = &mut Some(0u8) {
1583    ///     _a = 7u8;
1584    /// }
1585    /// ```
1586    ///
1587    /// {{produces}}
1588    ///
1589    /// ### Explanation
1590    ///
1591    /// In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,
1592    /// and nor do `&` or `&mut` patterns. The lint will suggest code that
1593    /// has the same meaning in all editions.
1594    pub RUST_2024_INCOMPATIBLE_PAT,
1595    Allow,
1596    "detects patterns whose meaning will change in Rust 2024",
1597    @future_incompatible = FutureIncompatibleInfo {
1598        reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
1599        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/match-ergonomics.html>",
1600    };
1601}
1602
1603declare_lint! {
1604    /// The `unconditional_recursion` lint detects functions that cannot
1605    /// return without calling themselves.
1606    ///
1607    /// ### Example
1608    ///
1609    /// ```rust
1610    /// fn foo() {
1611    ///     foo();
1612    /// }
1613    /// ```
1614    ///
1615    /// {{produces}}
1616    ///
1617    /// ### Explanation
1618    ///
1619    /// It is usually a mistake to have a recursive call that does not have
1620    /// some condition to cause it to terminate. If you really intend to have
1621    /// an infinite loop, using a `loop` expression is recommended.
1622    pub UNCONDITIONAL_RECURSION,
1623    Warn,
1624    "functions that cannot return without calling themselves"
1625}
1626
1627declare_lint! {
1628    /// The `single_use_lifetimes` lint detects lifetimes that are only used
1629    /// once.
1630    ///
1631    /// ### Example
1632    ///
1633    /// ```rust,compile_fail
1634    /// #![deny(single_use_lifetimes)]
1635    ///
1636    /// fn foo<'a>(x: &'a u32) {}
1637    /// ```
1638    ///
1639    /// {{produces}}
1640    ///
1641    /// ### Explanation
1642    ///
1643    /// Specifying an explicit lifetime like `'a` in a function or `impl`
1644    /// should only be used to link together two things. Otherwise, you should
1645    /// just use `'_` to indicate that the lifetime is not linked to anything,
1646    /// or elide the lifetime altogether if possible.
1647    ///
1648    /// This lint is "allow" by default because it was introduced at a time
1649    /// when `'_` and elided lifetimes were first being introduced, and this
1650    /// lint would be too noisy. Also, there are some known false positives
1651    /// that it produces. See [RFC 2115] for historical context, and [issue
1652    /// #44752] for more details.
1653    ///
1654    /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1655    /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1656    pub SINGLE_USE_LIFETIMES,
1657    Allow,
1658    "detects lifetime parameters that are only used once"
1659}
1660
1661declare_lint! {
1662    /// The `unused_lifetimes` lint detects lifetime parameters that are never
1663    /// used.
1664    ///
1665    /// ### Example
1666    ///
1667    /// ```rust,compile_fail
1668    /// #[deny(unused_lifetimes)]
1669    ///
1670    /// pub fn foo<'a>() {}
1671    /// ```
1672    ///
1673    /// {{produces}}
1674    ///
1675    /// ### Explanation
1676    ///
1677    /// Unused lifetime parameters may signal a mistake or unfinished code.
1678    /// Consider removing the parameter.
1679    pub UNUSED_LIFETIMES,
1680    Allow,
1681    "detects lifetime parameters that are never used"
1682}
1683
1684declare_lint! {
1685    /// The `redundant_lifetimes` lint detects lifetime parameters that are
1686    /// redundant because they are equal to another named lifetime.
1687    ///
1688    /// ### Example
1689    ///
1690    /// ```rust,compile_fail
1691    /// #[deny(redundant_lifetimes)]
1692    ///
1693    /// // `'a = 'static`, so all usages of `'a` can be replaced with `'static`
1694    /// pub fn bar<'a: 'static>() {}
1695    ///
1696    /// // `'a = 'b`, so all usages of `'b` can be replaced with `'a`
1697    /// pub fn bar<'a: 'b, 'b: 'a>() {}
1698    /// ```
1699    ///
1700    /// {{produces}}
1701    ///
1702    /// ### Explanation
1703    ///
1704    /// Unused lifetime parameters may signal a mistake or unfinished code.
1705    /// Consider removing the parameter.
1706    pub REDUNDANT_LIFETIMES,
1707    Allow,
1708    "detects lifetime parameters that are redundant because they are equal to some other named lifetime"
1709}
1710
1711declare_lint! {
1712    /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1713    /// inference variable.
1714    ///
1715    /// ### Example
1716    ///
1717    /// ```rust,edition2015
1718    /// // edition 2015
1719    /// let data = std::ptr::null();
1720    /// let _ = &data as *const *const ();
1721    ///
1722    /// if data.is_null() {}
1723    /// ```
1724    ///
1725    /// {{produces}}
1726    ///
1727    /// ### Explanation
1728    ///
1729    /// This kind of inference was previously allowed, but with the future
1730    /// arrival of [arbitrary self types], this can introduce ambiguity. To
1731    /// resolve this, use an explicit type instead of relying on type
1732    /// inference.
1733    ///
1734    /// This is a [future-incompatible] lint to transition this to a hard
1735    /// error in the 2018 edition. See [issue #46906] for more details. This
1736    /// is currently a hard-error on the 2018 edition, and is "warn" by
1737    /// default in the 2015 edition.
1738    ///
1739    /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1740    /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1741    /// [future-incompatible]: ../index.md#future-incompatible-lints
1742    pub TYVAR_BEHIND_RAW_POINTER,
1743    Warn,
1744    "raw pointer to an inference variable",
1745    @future_incompatible = FutureIncompatibleInfo {
1746        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1747        reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1748    };
1749}
1750
1751declare_lint! {
1752    /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1753    /// lifetime parameters.
1754    ///
1755    /// ### Example
1756    ///
1757    /// ```rust,compile_fail
1758    /// #![deny(elided_lifetimes_in_paths)]
1759    /// #![deny(warnings)]
1760    /// struct Foo<'a> {
1761    ///     x: &'a u32
1762    /// }
1763    ///
1764    /// fn foo(x: &Foo) {
1765    /// }
1766    /// ```
1767    ///
1768    /// {{produces}}
1769    ///
1770    /// ### Explanation
1771    ///
1772    /// Elided lifetime parameters can make it difficult to see at a glance
1773    /// that borrowing is occurring. This lint ensures that lifetime
1774    /// parameters are always explicitly stated, even if it is the `'_`
1775    /// [placeholder lifetime].
1776    ///
1777    /// This lint is "allow" by default because it has some known issues, and
1778    /// may require a significant transition for old code.
1779    ///
1780    /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1781    pub ELIDED_LIFETIMES_IN_PATHS,
1782    Allow,
1783    "hidden lifetime parameters in types are deprecated"
1784}
1785
1786declare_lint! {
1787    /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1788    /// objects.
1789    ///
1790    /// ### Example
1791    ///
1792    /// ```rust,edition2018
1793    /// trait Trait { }
1794    ///
1795    /// fn takes_trait_object(_: Box<Trait>) {
1796    /// }
1797    /// ```
1798    ///
1799    /// {{produces}}
1800    ///
1801    /// ### Explanation
1802    ///
1803    /// Without the `dyn` indicator, it can be ambiguous or confusing when
1804    /// reading code as to whether or not you are looking at a trait object.
1805    /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1806    /// with [`impl Trait`].
1807    ///
1808    /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1809    pub BARE_TRAIT_OBJECTS,
1810    Warn,
1811    "suggest using `dyn Trait` for trait objects",
1812    @future_incompatible = FutureIncompatibleInfo {
1813        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
1814        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
1815    };
1816}
1817
1818declare_lint! {
1819    /// The `absolute_paths_not_starting_with_crate` lint detects fully
1820    /// qualified paths that start with a module name instead of `crate`,
1821    /// `self`, or an extern crate name
1822    ///
1823    /// ### Example
1824    ///
1825    /// ```rust,edition2015,compile_fail
1826    /// #![deny(absolute_paths_not_starting_with_crate)]
1827    ///
1828    /// mod foo {
1829    ///     pub fn bar() {}
1830    /// }
1831    ///
1832    /// fn main() {
1833    ///     ::foo::bar();
1834    /// }
1835    /// ```
1836    ///
1837    /// {{produces}}
1838    ///
1839    /// ### Explanation
1840    ///
1841    /// Rust [editions] allow the language to evolve without breaking
1842    /// backwards compatibility. This lint catches code that uses absolute
1843    /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1844    /// paths (those starting with `::`) refer to either the crate root or an
1845    /// external crate. In the 2018 edition it was changed so that they only
1846    /// refer to external crates. The path prefix `crate::` should be used
1847    /// instead to reference items from the crate root.
1848    ///
1849    /// If you switch the compiler from the 2015 to 2018 edition without
1850    /// updating the code, then it will fail to compile if the old style paths
1851    /// are used. You can manually change the paths to use the `crate::`
1852    /// prefix to transition to the 2018 edition.
1853    ///
1854    /// This lint solves the problem automatically. It is "allow" by default
1855    /// because the code is perfectly valid in the 2015 edition. The [`cargo
1856    /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1857    /// and automatically apply the suggested fix from the compiler. This
1858    /// provides a completely automated way to update old code to the 2018
1859    /// edition.
1860    ///
1861    /// [editions]: https://doc.rust-lang.org/edition-guide/
1862    /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1863    pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1864    Allow,
1865    "fully qualified paths that start with a module name \
1866     instead of `crate`, `self`, or an extern crate name",
1867     @future_incompatible = FutureIncompatibleInfo {
1868        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1869        reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1870     };
1871}
1872
1873declare_lint! {
1874    /// The `unstable_name_collisions` lint detects that you have used a name
1875    /// that the standard library plans to add in the future.
1876    ///
1877    /// ### Example
1878    ///
1879    /// ```rust
1880    /// trait MyIterator : Iterator {
1881    ///     // is_partitioned is an unstable method that already exists on the Iterator trait
1882    ///     fn is_partitioned<P>(self, predicate: P) -> bool
1883    ///     where
1884    ///         Self: Sized,
1885    ///         P: FnMut(Self::Item) -> bool,
1886    ///     {true}
1887    /// }
1888    ///
1889    /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1890    ///
1891    /// let x = vec![1, 2, 3];
1892    /// let _ = x.iter().is_partitioned(|_| true);
1893    /// ```
1894    ///
1895    /// {{produces}}
1896    ///
1897    /// ### Explanation
1898    ///
1899    /// When new methods are added to traits in the standard library, they are
1900    /// usually added in an "unstable" form which is only available on the
1901    /// [nightly channel] with a [`feature` attribute]. If there is any
1902    /// preexisting code which extends a trait to have a method with the same
1903    /// name, then the names will collide. In the future, when the method is
1904    /// stabilized, this will cause an error due to the ambiguity. This lint
1905    /// is an early-warning to let you know that there may be a collision in
1906    /// the future. This can be avoided by adding type annotations to
1907    /// disambiguate which trait method you intend to call, such as
1908    /// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
1909    ///
1910    /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1911    /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1912    pub UNSTABLE_NAME_COLLISIONS,
1913    Warn,
1914    "detects name collision with an existing but unstable method",
1915    @future_incompatible = FutureIncompatibleInfo {
1916        reason: FutureIncompatibilityReason::Custom(
1917            "once this associated item is added to the standard library, \
1918             the ambiguity may cause an error or change in behavior!"
1919        ),
1920        reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1921        // Note: this item represents future incompatibility of all unstable functions in the
1922        //       standard library, and thus should never be removed or changed to an error.
1923    };
1924}
1925
1926declare_lint! {
1927    /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1928    /// in [`if let`]s, [`while let`]s, and `if let` guards.
1929    ///
1930    /// ### Example
1931    ///
1932    /// ```rust
1933    /// if let _ = 123 {
1934    ///     println!("always runs!");
1935    /// }
1936    /// ```
1937    ///
1938    /// {{produces}}
1939    ///
1940    /// ### Explanation
1941    ///
1942    /// There usually isn't a reason to have an irrefutable pattern in an
1943    /// `if let` or `while let` statement, because the pattern will always match
1944    /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1945    /// when generating code with a macro, forbidding irrefutable patterns
1946    /// would require awkward workarounds in situations where the macro
1947    /// doesn't know if the pattern is refutable or not. This lint allows
1948    /// macros to accept this form, while alerting for a possibly incorrect
1949    /// use in normal code.
1950    ///
1951    /// See [RFC 2086] for more details.
1952    ///
1953    /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1954    /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1955    /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1956    /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1957    /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1958    /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1959    pub IRREFUTABLE_LET_PATTERNS,
1960    Warn,
1961    "detects irrefutable patterns in `if let` and `while let` statements"
1962}
1963
1964declare_lint! {
1965    /// The `unused_labels` lint detects [labels] that are never used.
1966    ///
1967    /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1968    ///
1969    /// ### Example
1970    ///
1971    /// ```rust,no_run
1972    /// 'unused_label: loop {}
1973    /// ```
1974    ///
1975    /// {{produces}}
1976    ///
1977    /// ### Explanation
1978    ///
1979    /// Unused labels may signal a mistake or unfinished code. To silence the
1980    /// warning for the individual label, prefix it with an underscore such as
1981    /// `'_my_label:`.
1982    pub UNUSED_LABELS,
1983    Warn,
1984    "detects labels that are never used"
1985}
1986
1987declare_lint! {
1988    /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1989    /// derives using inaccessible names from parent modules.
1990    ///
1991    /// ### Example
1992    ///
1993    /// ```rust,ignore (proc-macro)
1994    /// // foo.rs
1995    /// #![crate_type = "proc-macro"]
1996    ///
1997    /// extern crate proc_macro;
1998    ///
1999    /// use proc_macro::*;
2000    ///
2001    /// #[proc_macro_derive(Foo)]
2002    /// pub fn foo1(a: TokenStream) -> TokenStream {
2003    ///     drop(a);
2004    ///     "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2005    /// }
2006    /// ```
2007    ///
2008    /// ```rust,ignore (needs-dependency)
2009    /// // bar.rs
2010    /// #[macro_use]
2011    /// extern crate foo;
2012    ///
2013    /// struct Something;
2014    ///
2015    /// #[derive(Foo)]
2016    /// struct Another;
2017    ///
2018    /// fn main() {}
2019    /// ```
2020    ///
2021    /// This will produce:
2022    ///
2023    /// ```text
2024    /// warning: cannot find type `Something` in this scope
2025    ///  --> src/main.rs:8:10
2026    ///   |
2027    /// 8 | #[derive(Foo)]
2028    ///   |          ^^^ names from parent modules are not accessible without an explicit import
2029    ///   |
2030    ///   = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2031    ///   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2032    ///   = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2033    /// ```
2034    ///
2035    /// ### Explanation
2036    ///
2037    /// If a proc-macro generates a module, the compiler unintentionally
2038    /// allowed items in that module to refer to items in the crate root
2039    /// without importing them. This is a [future-incompatible] lint to
2040    /// transition this to a hard error in the future. See [issue #50504] for
2041    /// more details.
2042    ///
2043    /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2044    /// [future-incompatible]: ../index.md#future-incompatible-lints
2045    pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2046    Deny,
2047    "detects proc macro derives using inaccessible names from parent modules",
2048    @future_incompatible = FutureIncompatibleInfo {
2049        reason: FutureIncompatibilityReason::FutureReleaseError,
2050        reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
2051        report_in_deps: true,
2052    };
2053}
2054
2055declare_lint! {
2056    /// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
2057    ///
2058    /// ### Example
2059    ///
2060    /// ```rust,ignore (needs extern crate)
2061    /// #![deny(macro_use_extern_crate)]
2062    ///
2063    /// #[macro_use]
2064    /// extern crate serde_json;
2065    ///
2066    /// fn main() {
2067    ///     let _ = json!{{}};
2068    /// }
2069    /// ```
2070    ///
2071    /// This will produce:
2072    ///
2073    /// ```text
2074    /// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
2075    ///  --> src/main.rs:3:1
2076    ///   |
2077    /// 3 | #[macro_use]
2078    ///   | ^^^^^^^^^^^^
2079    ///   |
2080    ///   = help: remove it and import macros at use sites with a `use` item instead
2081    /// note: the lint level is defined here
2082    ///  --> src/main.rs:1:9
2083    ///   |
2084    /// 1 | #![deny(macro_use_extern_crate)]
2085    ///   |         ^^^^^^^^^^^^^^^^^^^^^^
2086    /// ```
2087    ///
2088    /// ### Explanation
2089    ///
2090    /// The [`macro_use` attribute] on an [`extern crate`] item causes
2091    /// macros in that external crate to be brought into the prelude of the
2092    /// crate, making the macros in scope everywhere. As part of the efforts
2093    /// to simplify handling of dependencies in the [2018 edition], the use of
2094    /// `extern crate` is being phased out. To bring macros from extern crates
2095    /// into scope, it is recommended to use a [`use` import].
2096    ///
2097    /// This lint is "allow" by default because this is a stylistic choice
2098    /// that has not been settled, see [issue #52043] for more information.
2099    ///
2100    /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2101    /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2102    /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2103    pub MACRO_USE_EXTERN_CRATE,
2104    Allow,
2105    "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2106     via the module system"
2107}
2108
2109declare_lint! {
2110    /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2111    /// detects macro-expanded [`macro_export`] macros from the current crate
2112    /// that cannot be referred to by absolute paths.
2113    ///
2114    /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2115    ///
2116    /// ### Example
2117    ///
2118    /// ```rust,compile_fail
2119    /// macro_rules! define_exported {
2120    ///     () => {
2121    ///         #[macro_export]
2122    ///         macro_rules! exported {
2123    ///             () => {};
2124    ///         }
2125    ///     };
2126    /// }
2127    ///
2128    /// define_exported!();
2129    ///
2130    /// fn main() {
2131    ///     crate::exported!();
2132    /// }
2133    /// ```
2134    ///
2135    /// {{produces}}
2136    ///
2137    /// ### Explanation
2138    ///
2139    /// The intent is that all macros marked with the `#[macro_export]`
2140    /// attribute are made available in the root of the crate. However, when a
2141    /// `macro_rules!` definition is generated by another macro, the macro
2142    /// expansion is unable to uphold this rule. This is a
2143    /// [future-incompatible] lint to transition this to a hard error in the
2144    /// future. See [issue #53495] for more details.
2145    ///
2146    /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2147    /// [future-incompatible]: ../index.md#future-incompatible-lints
2148    pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2149    Deny,
2150    "macro-expanded `macro_export` macros from the current crate \
2151     cannot be referred to by absolute paths",
2152    @future_incompatible = FutureIncompatibleInfo {
2153        reason: FutureIncompatibilityReason::FutureReleaseError,
2154        reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2155    };
2156    crate_level_only
2157}
2158
2159declare_lint! {
2160    /// The `explicit_outlives_requirements` lint detects unnecessary
2161    /// lifetime bounds that can be inferred.
2162    ///
2163    /// ### Example
2164    ///
2165    /// ```rust,compile_fail
2166    /// # #![allow(unused)]
2167    /// #![deny(explicit_outlives_requirements)]
2168    /// #![deny(warnings)]
2169    ///
2170    /// struct SharedRef<'a, T>
2171    /// where
2172    ///     T: 'a,
2173    /// {
2174    ///     data: &'a T,
2175    /// }
2176    /// ```
2177    ///
2178    /// {{produces}}
2179    ///
2180    /// ### Explanation
2181    ///
2182    /// If a `struct` contains a reference, such as `&'a T`, the compiler
2183    /// requires that `T` outlives the lifetime `'a`. This historically
2184    /// required writing an explicit lifetime bound to indicate this
2185    /// requirement. However, this can be overly explicit, causing clutter and
2186    /// unnecessary complexity. The language was changed to automatically
2187    /// infer the bound if it is not specified. Specifically, if the struct
2188    /// contains a reference, directly or indirectly, to `T` with lifetime
2189    /// `'x`, then it will infer that `T: 'x` is a requirement.
2190    ///
2191    /// This lint is "allow" by default because it can be noisy for existing
2192    /// code that already had these requirements. This is a stylistic choice,
2193    /// as it is still valid to explicitly state the bound. It also has some
2194    /// false positives that can cause confusion.
2195    ///
2196    /// See [RFC 2093] for more details.
2197    ///
2198    /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2199    pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2200    Allow,
2201    "outlives requirements can be inferred"
2202}
2203
2204declare_lint! {
2205    /// The `deprecated_in_future` lint is internal to rustc and should not be
2206    /// used by user code.
2207    ///
2208    /// This lint is only enabled in the standard library. It works with the
2209    /// use of `#[deprecated]` with a `since` field of a version in the future.
2210    /// This allows something to be marked as deprecated in a future version,
2211    /// and then this lint will ensure that the item is no longer used in the
2212    /// standard library. See the [stability documentation] for more details.
2213    ///
2214    /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2215    pub DEPRECATED_IN_FUTURE,
2216    Allow,
2217    "detects use of items that will be deprecated in a future version",
2218    report_in_external_macro
2219}
2220
2221declare_lint! {
2222    /// The `ambiguous_associated_items` lint detects ambiguity between
2223    /// [associated items] and [enum variants].
2224    ///
2225    /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2226    /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2227    ///
2228    /// ### Example
2229    ///
2230    /// ```rust,compile_fail
2231    /// enum E {
2232    ///     V
2233    /// }
2234    ///
2235    /// trait Tr {
2236    ///     type V;
2237    ///     fn foo() -> Self::V;
2238    /// }
2239    ///
2240    /// impl Tr for E {
2241    ///     type V = u8;
2242    ///     // `Self::V` is ambiguous because it may refer to the associated type or
2243    ///     // the enum variant.
2244    ///     fn foo() -> Self::V { 0 }
2245    /// }
2246    /// ```
2247    ///
2248    /// {{produces}}
2249    ///
2250    /// ### Explanation
2251    ///
2252    /// Previous versions of Rust did not allow accessing enum variants
2253    /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2254    /// introduced some situations where it can be ambiguous what a type
2255    /// was referring to.
2256    ///
2257    /// To fix this ambiguity, you should use a [qualified path] to explicitly
2258    /// state which type to use. For example, in the above example the
2259    /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2260    /// specifically refer to the associated type.
2261    ///
2262    /// This is a [future-incompatible] lint to transition this to a hard
2263    /// error in the future. See [issue #57644] for more details.
2264    ///
2265    /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2266    /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2267    /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2268    /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2269    /// [future-incompatible]: ../index.md#future-incompatible-lints
2270    pub AMBIGUOUS_ASSOCIATED_ITEMS,
2271    Deny,
2272    "ambiguous associated items",
2273    @future_incompatible = FutureIncompatibleInfo {
2274        reason: FutureIncompatibilityReason::FutureReleaseError,
2275        reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2276    };
2277}
2278
2279declare_lint! {
2280    /// The `soft_unstable` lint detects unstable features that were unintentionally allowed on
2281    /// stable. This is a [future-incompatible] lint to transition this to a hard error in the
2282    /// future. See [issue #64266] for more details.
2283    ///
2284    /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2285    /// [future-incompatible]: ../index.md#future-incompatible-lints
2286    pub SOFT_UNSTABLE,
2287    Deny,
2288    "a feature gate that doesn't break dependent crates",
2289    @future_incompatible = FutureIncompatibleInfo {
2290        reason: FutureIncompatibilityReason::FutureReleaseError,
2291        reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2292        report_in_deps: true,
2293    };
2294}
2295
2296declare_lint! {
2297    /// The `inline_no_sanitize` lint detects incompatible use of
2298    /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2299    ///
2300    /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2301    /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2302    ///
2303    /// ### Example
2304    ///
2305    /// ```rust
2306    /// #![feature(no_sanitize)]
2307    ///
2308    /// #[inline(always)]
2309    /// #[no_sanitize(address)]
2310    /// fn x() {}
2311    ///
2312    /// fn main() {
2313    ///     x()
2314    /// }
2315    /// ```
2316    ///
2317    /// {{produces}}
2318    ///
2319    /// ### Explanation
2320    ///
2321    /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2322    /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2323    /// Consider temporarily removing `inline` attribute.
2324    pub INLINE_NO_SANITIZE,
2325    Warn,
2326    "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2327}
2328
2329declare_lint! {
2330    /// The `asm_sub_register` lint detects using only a subset of a register
2331    /// for inline asm inputs.
2332    ///
2333    /// ### Example
2334    ///
2335    /// ```rust,ignore (fails on non-x86_64)
2336    /// #[cfg(target_arch="x86_64")]
2337    /// use std::arch::asm;
2338    ///
2339    /// fn main() {
2340    ///     #[cfg(target_arch="x86_64")]
2341    ///     unsafe {
2342    ///         asm!("mov {0}, {0}", in(reg) 0i16);
2343    ///     }
2344    /// }
2345    /// ```
2346    ///
2347    /// This will produce:
2348    ///
2349    /// ```text
2350    /// warning: formatting may not be suitable for sub-register argument
2351    ///  --> src/main.rs:7:19
2352    ///   |
2353    /// 7 |         asm!("mov {0}, {0}", in(reg) 0i16);
2354    ///   |                   ^^^  ^^^           ---- for this argument
2355    ///   |
2356    ///   = note: `#[warn(asm_sub_register)]` on by default
2357    ///   = help: use the `x` modifier to have the register formatted as `ax`
2358    ///   = help: or use the `r` modifier to keep the default formatting of `rax`
2359    /// ```
2360    ///
2361    /// ### Explanation
2362    ///
2363    /// Registers on some architectures can use different names to refer to a
2364    /// subset of the register. By default, the compiler will use the name for
2365    /// the full register size. To explicitly use a subset of the register,
2366    /// you can override the default by using a modifier on the template
2367    /// string operand to specify when subregister to use. This lint is issued
2368    /// if you pass in a value with a smaller data type than the default
2369    /// register size, to alert you of possibly using the incorrect width. To
2370    /// fix this, add the suggested modifier to the template, or cast the
2371    /// value to the correct size.
2372    ///
2373    /// See [register template modifiers] in the reference for more details.
2374    ///
2375    /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2376    pub ASM_SUB_REGISTER,
2377    Warn,
2378    "using only a subset of a register for inline asm inputs",
2379}
2380
2381declare_lint! {
2382    /// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2383    /// `.att_syntax` directives.
2384    ///
2385    /// ### Example
2386    ///
2387    /// ```rust,ignore (fails on non-x86_64)
2388    /// #[cfg(target_arch="x86_64")]
2389    /// use std::arch::asm;
2390    ///
2391    /// fn main() {
2392    ///     #[cfg(target_arch="x86_64")]
2393    ///     unsafe {
2394    ///         asm!(
2395    ///             ".att_syntax",
2396    ///             "movq %{0}, %{0}", in(reg) 0usize
2397    ///         );
2398    ///     }
2399    /// }
2400    /// ```
2401    ///
2402    /// This will produce:
2403    ///
2404    /// ```text
2405    /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2406    ///  --> src/main.rs:8:14
2407    ///   |
2408    /// 8 |             ".att_syntax",
2409    ///   |              ^^^^^^^^^^^
2410    ///   |
2411    ///   = note: `#[warn(bad_asm_style)]` on by default
2412    /// ```
2413    ///
2414    /// ### Explanation
2415    ///
2416    /// On x86, `asm!` uses the intel assembly syntax by default. While this
2417    /// can be switched using assembler directives like `.att_syntax`, using the
2418    /// `att_syntax` option is recommended instead because it will also properly
2419    /// prefix register placeholders with `%` as required by AT&T syntax.
2420    pub BAD_ASM_STYLE,
2421    Warn,
2422    "incorrect use of inline assembly",
2423}
2424
2425declare_lint! {
2426    /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2427    /// functions without an explicit unsafe block.
2428    ///
2429    /// ### Example
2430    ///
2431    /// ```rust,compile_fail
2432    /// #![deny(unsafe_op_in_unsafe_fn)]
2433    ///
2434    /// unsafe fn foo() {}
2435    ///
2436    /// unsafe fn bar() {
2437    ///     foo();
2438    /// }
2439    ///
2440    /// fn main() {}
2441    /// ```
2442    ///
2443    /// {{produces}}
2444    ///
2445    /// ### Explanation
2446    ///
2447    /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2448    /// body. However, this can increase the surface area of code that needs
2449    /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2450    /// convenient way to make it clear exactly which parts of the code are
2451    /// performing unsafe operations. In the future, it is desired to change
2452    /// it so that unsafe operations cannot be performed in an `unsafe fn`
2453    /// without an `unsafe` block.
2454    ///
2455    /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2456    ///
2457    /// This lint is "allow" by default on editions up to 2021, from 2024 it is
2458    /// "warn" by default; the plan for increasing severity further is
2459    /// still being considered. See [RFC #2585] and [issue #71668] for more
2460    /// details.
2461    ///
2462    /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2463    /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2464    /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2465    /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2466    /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2467    pub UNSAFE_OP_IN_UNSAFE_FN,
2468    Allow,
2469    "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2470    @future_incompatible = FutureIncompatibleInfo {
2471        reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
2472        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html>",
2473        explain_reason: false
2474    };
2475    @edition Edition2024 => Warn;
2476}
2477
2478declare_lint! {
2479    /// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
2480    /// and a pointer.
2481    ///
2482    /// ### Example
2483    ///
2484    /// ```rust
2485    /// #![feature(strict_provenance_lints)]
2486    /// #![warn(fuzzy_provenance_casts)]
2487    ///
2488    /// fn main() {
2489    ///     let _dangling = 16_usize as *const u8;
2490    /// }
2491    /// ```
2492    ///
2493    /// {{produces}}
2494    ///
2495    /// ### Explanation
2496    ///
2497    /// This lint is part of the strict provenance effort, see [issue #95228].
2498    /// Casting an integer to a pointer is considered bad style, as a pointer
2499    /// contains, besides the *address* also a *provenance*, indicating what
2500    /// memory the pointer is allowed to read/write. Casting an integer, which
2501    /// doesn't have provenance, to a pointer requires the compiler to assign
2502    /// (guess) provenance. The compiler assigns "all exposed valid" (see the
2503    /// docs of [`ptr::with_exposed_provenance`] for more information about this
2504    /// "exposing"). This penalizes the optimiser and is not well suited for
2505    /// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
2506    /// platforms).
2507    ///
2508    /// It is much better to use [`ptr::with_addr`] instead to specify the
2509    /// provenance you want. If using this function is not possible because the
2510    /// code relies on exposed provenance then there is as an escape hatch
2511    /// [`ptr::with_exposed_provenance`].
2512    ///
2513    /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2514    /// [`ptr::with_addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.with_addr
2515    /// [`ptr::with_exposed_provenance`]: https://doc.rust-lang.org/core/ptr/fn.with_exposed_provenance.html
2516    pub FUZZY_PROVENANCE_CASTS,
2517    Allow,
2518    "a fuzzy integer to pointer cast is used",
2519    @feature_gate = strict_provenance_lints;
2520}
2521
2522declare_lint! {
2523    /// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
2524    /// and an integer.
2525    ///
2526    /// ### Example
2527    ///
2528    /// ```rust
2529    /// #![feature(strict_provenance_lints)]
2530    /// #![warn(lossy_provenance_casts)]
2531    ///
2532    /// fn main() {
2533    ///     let x: u8 = 37;
2534    ///     let _addr: usize = &x as *const u8 as usize;
2535    /// }
2536    /// ```
2537    ///
2538    /// {{produces}}
2539    ///
2540    /// ### Explanation
2541    ///
2542    /// This lint is part of the strict provenance effort, see [issue #95228].
2543    /// Casting a pointer to an integer is a lossy operation, because beyond
2544    /// just an *address* a pointer may be associated with a particular
2545    /// *provenance*. This information is used by the optimiser and for dynamic
2546    /// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
2547    ///
2548    /// Since this cast is lossy, it is considered good style to use the
2549    /// [`ptr::addr`] method instead, which has a similar effect, but doesn't
2550    /// "expose" the pointer provenance. This improves optimisation potential.
2551    /// See the docs of [`ptr::addr`] and [`ptr::expose_provenance`] for more information
2552    /// about exposing pointer provenance.
2553    ///
2554    /// If your code can't comply with strict provenance and needs to expose
2555    /// the provenance, then there is [`ptr::expose_provenance`] as an escape hatch,
2556    /// which preserves the behaviour of `as usize` casts while being explicit
2557    /// about the semantics.
2558    ///
2559    /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2560    /// [`ptr::addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.addr
2561    /// [`ptr::expose_provenance`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.expose_provenance
2562    pub LOSSY_PROVENANCE_CASTS,
2563    Allow,
2564    "a lossy pointer to integer cast is used",
2565    @feature_gate = strict_provenance_lints;
2566}
2567
2568declare_lint! {
2569    /// The `const_evaluatable_unchecked` lint detects a generic constant used
2570    /// in a type.
2571    ///
2572    /// ### Example
2573    ///
2574    /// ```rust
2575    /// const fn foo<T>() -> usize {
2576    ///     if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2577    ///         4
2578    ///     } else {
2579    ///         8
2580    ///     }
2581    /// }
2582    ///
2583    /// fn test<T>() {
2584    ///     let _ = [0; foo::<T>()];
2585    /// }
2586    /// ```
2587    ///
2588    /// {{produces}}
2589    ///
2590    /// ### Explanation
2591    ///
2592    /// In the 1.43 release, some uses of generic parameters in array repeat
2593    /// expressions were accidentally allowed. This is a [future-incompatible]
2594    /// lint to transition this to a hard error in the future. See [issue
2595    /// #76200] for a more detailed description and possible fixes.
2596    ///
2597    /// [future-incompatible]: ../index.md#future-incompatible-lints
2598    /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2599    pub CONST_EVALUATABLE_UNCHECKED,
2600    Warn,
2601    "detects a generic constant is used in a type without a emitting a warning",
2602    @future_incompatible = FutureIncompatibleInfo {
2603        reason: FutureIncompatibilityReason::FutureReleaseError,
2604        reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2605    };
2606}
2607
2608declare_lint! {
2609    /// The `function_item_references` lint detects function references that are
2610    /// formatted with [`fmt::Pointer`] or transmuted.
2611    ///
2612    /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2613    ///
2614    /// ### Example
2615    ///
2616    /// ```rust
2617    /// fn foo() { }
2618    ///
2619    /// fn main() {
2620    ///     println!("{:p}", &foo);
2621    /// }
2622    /// ```
2623    ///
2624    /// {{produces}}
2625    ///
2626    /// ### Explanation
2627    ///
2628    /// Taking a reference to a function may be mistaken as a way to obtain a
2629    /// pointer to that function. This can give unexpected results when
2630    /// formatting the reference as a pointer or transmuting it. This lint is
2631    /// issued when function references are formatted as pointers, passed as
2632    /// arguments bound by [`fmt::Pointer`] or transmuted.
2633    pub FUNCTION_ITEM_REFERENCES,
2634    Warn,
2635    "suggest casting to a function pointer when attempting to take references to function items",
2636}
2637
2638declare_lint! {
2639    /// The `uninhabited_static` lint detects uninhabited statics.
2640    ///
2641    /// ### Example
2642    ///
2643    /// ```rust
2644    /// enum Void {}
2645    /// unsafe extern {
2646    ///     static EXTERN: Void;
2647    /// }
2648    /// ```
2649    ///
2650    /// {{produces}}
2651    ///
2652    /// ### Explanation
2653    ///
2654    /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2655    /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2656    /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2657    /// statics). This was accidentally allowed, but is being phased out.
2658    pub UNINHABITED_STATIC,
2659    Warn,
2660    "uninhabited static",
2661    @future_incompatible = FutureIncompatibleInfo {
2662        reason: FutureIncompatibilityReason::FutureReleaseError,
2663        reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2664    };
2665}
2666
2667declare_lint! {
2668    /// The `unnameable_test_items` lint detects [`#[test]`][test] functions
2669    /// that are not able to be run by the test harness because they are in a
2670    /// position where they are not nameable.
2671    ///
2672    /// [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute
2673    ///
2674    /// ### Example
2675    ///
2676    /// ```rust,test
2677    /// fn main() {
2678    ///     #[test]
2679    ///     fn foo() {
2680    ///         // This test will not fail because it does not run.
2681    ///         assert_eq!(1, 2);
2682    ///     }
2683    /// }
2684    /// ```
2685    ///
2686    /// {{produces}}
2687    ///
2688    /// ### Explanation
2689    ///
2690    /// In order for the test harness to run a test, the test function must be
2691    /// located in a position where it can be accessed from the crate root.
2692    /// This generally means it must be defined in a module, and not anywhere
2693    /// else such as inside another function. The compiler previously allowed
2694    /// this without an error, so a lint was added as an alert that a test is
2695    /// not being used. Whether or not this should be allowed has not yet been
2696    /// decided, see [RFC 2471] and [issue #36629].
2697    ///
2698    /// [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443
2699    /// [issue #36629]: https://github.com/rust-lang/rust/issues/36629
2700    pub UNNAMEABLE_TEST_ITEMS,
2701    Warn,
2702    "detects an item that cannot be named being marked as `#[test_case]`",
2703    report_in_external_macro
2704}
2705
2706declare_lint! {
2707    /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2708    ///
2709    /// ### Example
2710    ///
2711    /// ```rust,compile_fail
2712    /// struct X;
2713    ///
2714    /// #[deprecated = "message"]
2715    /// impl Default for X {
2716    ///     fn default() -> Self {
2717    ///         X
2718    ///     }
2719    /// }
2720    /// ```
2721    ///
2722    /// {{produces}}
2723    ///
2724    /// ### Explanation
2725    ///
2726    /// Deprecation attributes have no effect on trait implementations.
2727    pub USELESS_DEPRECATED,
2728    Deny,
2729    "detects deprecation attributes with no effect",
2730}
2731
2732declare_lint! {
2733    /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2734    ///
2735    /// ### Example
2736    ///
2737    /// ```rust,compile_fail
2738    /// #![feature(staged_api)]
2739    ///
2740    /// #[derive(Clone)]
2741    /// #[stable(feature = "x", since = "1")]
2742    /// struct S {}
2743    ///
2744    /// #[unstable(feature = "y", issue = "none")]
2745    /// impl Copy for S {}
2746    /// ```
2747    ///
2748    /// {{produces}}
2749    ///
2750    /// ### Explanation
2751    ///
2752    /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2753    /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2754    pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2755    Deny,
2756    "detects `#[unstable]` on stable trait implementations for stable types"
2757}
2758
2759declare_lint! {
2760    /// The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor
2761    /// was silently allowed due to a bug in the resolver, and which may produce surprising
2762    /// and unintended behavior.
2763    ///
2764    /// Using a `Self` type alias from an outer item was never intended, but was silently allowed.
2765    /// This is deprecated -- and is a hard error when the `Self` type alias references generics
2766    /// that are not in scope.
2767    ///
2768    /// ### Example
2769    ///
2770    /// ```rust,compile_fail
2771    /// #![deny(self_constructor_from_outer_item)]
2772    ///
2773    /// struct S0(usize);
2774    ///
2775    /// impl S0 {
2776    ///     fn foo() {
2777    ///         const C: S0 = Self(0);
2778    ///         fn bar() -> S0 {
2779    ///             Self(0)
2780    ///         }
2781    ///     }
2782    /// }
2783    /// ```
2784    ///
2785    /// {{produces}}
2786    ///
2787    /// ### Explanation
2788    ///
2789    /// The `Self` type alias should not be reachable because nested items are not associated with
2790    /// the scope of the parameters from the parent item.
2791    pub SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
2792    Warn,
2793    "detect unsupported use of `Self` from outer item",
2794    @future_incompatible = FutureIncompatibleInfo {
2795        reason: FutureIncompatibilityReason::FutureReleaseError,
2796        reference: "issue #124186 <https://github.com/rust-lang/rust/issues/124186>",
2797    };
2798}
2799
2800declare_lint! {
2801    /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2802    /// in macro bodies when the macro is invoked in expression position.
2803    /// This was previous accepted, but is being phased out.
2804    ///
2805    /// ### Example
2806    ///
2807    /// ```rust,compile_fail
2808    /// #![deny(semicolon_in_expressions_from_macros)]
2809    /// macro_rules! foo {
2810    ///     () => { true; }
2811    /// }
2812    ///
2813    /// fn main() {
2814    ///     let val = match true {
2815    ///         true => false,
2816    ///         _ => foo!()
2817    ///     };
2818    /// }
2819    /// ```
2820    ///
2821    /// {{produces}}
2822    ///
2823    /// ### Explanation
2824    ///
2825    /// Previous, Rust ignored trailing semicolon in a macro
2826    /// body when a macro was invoked in expression position.
2827    /// However, this makes the treatment of semicolons in the language
2828    /// inconsistent, and could lead to unexpected runtime behavior
2829    /// in some circumstances (e.g. if the macro author expects
2830    /// a value to be dropped).
2831    ///
2832    /// This is a [future-incompatible] lint to transition this
2833    /// to a hard error in the future. See [issue #79813] for more details.
2834    ///
2835    /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2836    /// [future-incompatible]: ../index.md#future-incompatible-lints
2837    pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2838    Warn,
2839    "trailing semicolon in macro body used as expression",
2840    @future_incompatible = FutureIncompatibleInfo {
2841        reason: FutureIncompatibilityReason::FutureReleaseError,
2842        reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
2843        report_in_deps: true,
2844    };
2845}
2846
2847declare_lint! {
2848    /// The `legacy_derive_helpers` lint detects derive helper attributes
2849    /// that are used before they are introduced.
2850    ///
2851    /// ### Example
2852    ///
2853    /// ```rust,ignore (needs extern crate)
2854    /// #[serde(rename_all = "camelCase")]
2855    /// #[derive(Deserialize)]
2856    /// struct S { /* fields */ }
2857    /// ```
2858    ///
2859    /// produces:
2860    ///
2861    /// ```text
2862    /// warning: derive helper attribute is used before it is introduced
2863    ///   --> $DIR/legacy-derive-helpers.rs:1:3
2864    ///    |
2865    ///  1 | #[serde(rename_all = "camelCase")]
2866    ///    |   ^^^^^
2867    /// ...
2868    ///  2 | #[derive(Deserialize)]
2869    ///    |          ----------- the attribute is introduced here
2870    /// ```
2871    ///
2872    /// ### Explanation
2873    ///
2874    /// Attributes like this work for historical reasons, but attribute expansion works in
2875    /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2876    /// into the future" at not yet expanded part of the item , but such attempts are not always
2877    /// reliable.
2878    ///
2879    /// To fix the warning place the helper attribute after its corresponding derive.
2880    /// ```rust,ignore (needs extern crate)
2881    /// #[derive(Deserialize)]
2882    /// #[serde(rename_all = "camelCase")]
2883    /// struct S { /* fields */ }
2884    /// ```
2885    pub LEGACY_DERIVE_HELPERS,
2886    Warn,
2887    "detects derive helper attributes that are used before they are introduced",
2888    @future_incompatible = FutureIncompatibleInfo {
2889        reason: FutureIncompatibilityReason::FutureReleaseError,
2890        reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
2891    };
2892}
2893
2894declare_lint! {
2895    /// The `large_assignments` lint detects when objects of large
2896    /// types are being moved around.
2897    ///
2898    /// ### Example
2899    ///
2900    /// ```rust,ignore (can crash on some platforms)
2901    /// let x = [0; 50000];
2902    /// let y = x;
2903    /// ```
2904    ///
2905    /// produces:
2906    ///
2907    /// ```text
2908    /// warning: moving a large value
2909    ///   --> $DIR/move-large.rs:1:3
2910    ///   let y = x;
2911    ///           - Copied large value here
2912    /// ```
2913    ///
2914    /// ### Explanation
2915    ///
2916    /// When using a large type in a plain assignment or in a function
2917    /// argument, idiomatic code can be inefficient.
2918    /// Ideally appropriate optimizations would resolve this, but such
2919    /// optimizations are only done in a best-effort manner.
2920    /// This lint will trigger on all sites of large moves and thus allow the
2921    /// user to resolve them in code.
2922    pub LARGE_ASSIGNMENTS,
2923    Warn,
2924    "detects large moves or copies",
2925}
2926
2927declare_lint! {
2928    /// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
2929    ///
2930    /// ### Example
2931    ///
2932    /// ```text
2933    /// rustc --check-cfg 'cfg()'
2934    /// ```
2935    ///
2936    /// ```rust,ignore (needs command line option)
2937    /// #[cfg(widnows)]
2938    /// fn foo() {}
2939    /// ```
2940    ///
2941    /// This will produce:
2942    ///
2943    /// ```text
2944    /// warning: unexpected `cfg` condition name: `widnows`
2945    ///  --> lint_example.rs:1:7
2946    ///   |
2947    /// 1 | #[cfg(widnows)]
2948    ///   |       ^^^^^^^
2949    ///   |
2950    ///   = note: `#[warn(unexpected_cfgs)]` on by default
2951    /// ```
2952    ///
2953    /// ### Explanation
2954    ///
2955    /// This lint is only active when [`--check-cfg`][check-cfg] arguments are being
2956    /// passed to the compiler and triggers whenever an unexpected condition name or value is
2957    /// used.
2958    ///
2959    /// See the [Checking Conditional Configurations][check-cfg] section for more
2960    /// details.
2961    ///
2962    /// See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in
2963    /// `Cargo.toml`.
2964    ///
2965    /// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
2966    /// [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table
2967    pub UNEXPECTED_CFGS,
2968    Warn,
2969    "detects unexpected names and values in `#[cfg]` conditions",
2970    report_in_external_macro
2971}
2972
2973declare_lint! {
2974    /// The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.
2975    ///
2976    /// ### Example
2977    ///
2978    /// ```text
2979    /// rustc --cfg unix
2980    /// ```
2981    ///
2982    /// ```rust,ignore (needs command line option)
2983    /// fn main() {}
2984    /// ```
2985    ///
2986    /// This will produce:
2987    ///
2988    /// ```text
2989    /// error: unexpected `--cfg unix` flag
2990    ///   |
2991    ///   = note: config `unix` is only supposed to be controlled by `--target`
2992    ///   = note: manually setting a built-in cfg can and does create incoherent behaviors
2993    ///   = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
2994    /// ```
2995    ///
2996    /// ### Explanation
2997    ///
2998    /// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
2999    /// the appropriate `rustc` flag that controls the config. For example setting the `windows`
3000    /// cfg but on Linux based target.
3001    pub EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
3002    Deny,
3003    "detects builtin cfgs set via the `--cfg`"
3004}
3005
3006declare_lint! {
3007    /// The `repr_transparent_external_private_fields` lint
3008    /// detects types marked `#[repr(transparent)]` that (transitively)
3009    /// contain an external ZST type marked `#[non_exhaustive]` or containing
3010    /// private fields
3011    ///
3012    /// ### Example
3013    ///
3014    /// ```rust,ignore (needs external crate)
3015    /// #![deny(repr_transparent_external_private_fields)]
3016    /// use foo::NonExhaustiveZst;
3017    ///
3018    /// #[repr(transparent)]
3019    /// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3020    /// ```
3021    ///
3022    /// This will produce:
3023    ///
3024    /// ```text
3025    /// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
3026    ///  --> src/main.rs:5:28
3027    ///   |
3028    /// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3029    ///   |                            ^^^^^^^^^^^^^^^^
3030    ///   |
3031    /// note: the lint level is defined here
3032    ///  --> src/main.rs:1:9
3033    ///   |
3034    /// 1 | #![deny(repr_transparent_external_private_fields)]
3035    ///   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3036    ///   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3037    ///   = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3038    ///   = note: this struct contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
3039    /// ```
3040    ///
3041    /// ### Explanation
3042    ///
3043    /// Previous, Rust accepted fields that contain external private zero-sized types,
3044    /// even though it should not be a breaking change to add a non-zero-sized field to
3045    /// that private type.
3046    ///
3047    /// This is a [future-incompatible] lint to transition this
3048    /// to a hard error in the future. See [issue #78586] for more details.
3049    ///
3050    /// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
3051    /// [future-incompatible]: ../index.md#future-incompatible-lints
3052    pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3053    Warn,
3054    "transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
3055    @future_incompatible = FutureIncompatibleInfo {
3056        reason: FutureIncompatibilityReason::FutureReleaseError,
3057        reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
3058    };
3059}
3060
3061declare_lint! {
3062    /// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3063    /// syntax that is discarded during attribute expansion.
3064    ///
3065    /// ### Example
3066    ///
3067    /// ```rust
3068    /// #[cfg(FALSE)]
3069    /// macro foo() {}
3070    /// ```
3071    ///
3072    /// {{produces}}
3073    ///
3074    /// ### Explanation
3075    ///
3076    /// The input to active attributes such as `#[cfg]` or procedural macro
3077    /// attributes is required to be valid syntax. Previously, the compiler only
3078    /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3079    /// and expanding procedural macros.
3080    ///
3081    /// To avoid relying on unstable syntax, move the use of unstable syntax
3082    /// into a position where the compiler does not parse the syntax, such as a
3083    /// functionlike macro.
3084    ///
3085    /// ```rust
3086    /// # #![deny(unstable_syntax_pre_expansion)]
3087    ///
3088    /// macro_rules! identity {
3089    ///    ( $($tokens:tt)* ) => { $($tokens)* }
3090    /// }
3091    ///
3092    /// #[cfg(FALSE)]
3093    /// identity! {
3094    ///    macro foo() {}
3095    /// }
3096    /// ```
3097    ///
3098    /// This is a [future-incompatible] lint to transition this
3099    /// to a hard error in the future. See [issue #65860] for more details.
3100    ///
3101    /// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
3102    /// [future-incompatible]: ../index.md#future-incompatible-lints
3103    pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3104    Warn,
3105    "unstable syntax can change at any point in the future, causing a hard error!",
3106    @future_incompatible = FutureIncompatibleInfo {
3107        reason: FutureIncompatibilityReason::FutureReleaseError,
3108        reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
3109    };
3110}
3111
3112declare_lint! {
3113    /// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
3114    /// collide. Downstream users trying to use the same name re-exported from multiple globs
3115    /// will receive a warning pointing out redefinition of the same name.
3116    ///
3117    /// ### Example
3118    ///
3119    /// ```rust,compile_fail
3120    /// #![deny(ambiguous_glob_reexports)]
3121    /// pub mod foo {
3122    ///     pub type X = u8;
3123    /// }
3124    ///
3125    /// pub mod bar {
3126    ///     pub type Y = u8;
3127    ///     pub type X = u8;
3128    /// }
3129    ///
3130    /// pub use foo::*;
3131    /// pub use bar::*;
3132    ///
3133    ///
3134    /// pub fn main() {}
3135    /// ```
3136    ///
3137    /// {{produces}}
3138    ///
3139    /// ### Explanation
3140    ///
3141    /// This was previously accepted but it could silently break a crate's downstream users code.
3142    /// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
3143    /// re-exports, down stream users could use `this_crate::X` without problems. However, adding
3144    /// `bar::X` would cause compilation errors in downstream crates because `X` is defined
3145    /// multiple times in the same namespace of `this_crate`.
3146    pub AMBIGUOUS_GLOB_REEXPORTS,
3147    Warn,
3148    "ambiguous glob re-exports",
3149}
3150
3151declare_lint! {
3152    /// The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by
3153    /// private items.
3154    ///
3155    /// ### Example
3156    ///
3157    /// ```rust,compile_fail
3158    /// #![deny(hidden_glob_reexports)]
3159    ///
3160    /// pub mod upstream {
3161    ///     mod inner { pub struct Foo {}; pub struct Bar {}; }
3162    ///     pub use self::inner::*;
3163    ///     struct Foo {} // private item shadows `inner::Foo`
3164    /// }
3165    ///
3166    /// // mod downstream {
3167    /// //     fn test() {
3168    /// //         let _ = crate::upstream::Foo; // inaccessible
3169    /// //     }
3170    /// // }
3171    ///
3172    /// pub fn main() {}
3173    /// ```
3174    ///
3175    /// {{produces}}
3176    ///
3177    /// ### Explanation
3178    ///
3179    /// This was previously accepted without any errors or warnings but it could silently break a
3180    /// crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would
3181    /// silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at
3182    /// the downstream use site.
3183    pub HIDDEN_GLOB_REEXPORTS,
3184    Warn,
3185    "name introduced by a private item shadows a name introduced by a public glob re-export",
3186}
3187
3188declare_lint! {
3189    /// The `long_running_const_eval` lint is emitted when const
3190    /// eval is running for a long time to ensure rustc terminates
3191    /// even if you accidentally wrote an infinite loop.
3192    ///
3193    /// ### Example
3194    ///
3195    /// ```rust,compile_fail
3196    /// const FOO: () = loop {};
3197    /// ```
3198    ///
3199    /// {{produces}}
3200    ///
3201    /// ### Explanation
3202    ///
3203    /// Loops allow const evaluation to compute arbitrary code, but may also
3204    /// cause infinite loops or just very long running computations.
3205    /// Users can enable long running computations by allowing the lint
3206    /// on individual constants or for entire crates.
3207    ///
3208    /// ### Unconditional warnings
3209    ///
3210    /// Note that regardless of whether the lint is allowed or set to warn,
3211    /// the compiler will issue warnings if constant evaluation runs significantly
3212    /// longer than this lint's limit. These warnings are also shown to downstream
3213    /// users from crates.io or similar registries. If you are above the lint's limit,
3214    /// both you and downstream users might be exposed to these warnings.
3215    /// They might also appear on compiler updates, as the compiler makes minor changes
3216    /// about how complexity is measured: staying below the limit ensures that there
3217    /// is enough room, and given that the lint is disabled for people who use your
3218    /// dependency it means you will be the only one to get the warning and can put
3219    /// out an update in your own time.
3220    pub LONG_RUNNING_CONST_EVAL,
3221    Deny,
3222    "detects long const eval operations",
3223    report_in_external_macro
3224}
3225
3226declare_lint! {
3227    /// The `unused_associated_type_bounds` lint is emitted when an
3228    /// associated type bound is added to a trait object, but the associated
3229    /// type has a `where Self: Sized` bound, and is thus unavailable on the
3230    /// trait object anyway.
3231    ///
3232    /// ### Example
3233    ///
3234    /// ```rust
3235    /// trait Foo {
3236    ///     type Bar where Self: Sized;
3237    /// }
3238    /// type Mop = dyn Foo<Bar = ()>;
3239    /// ```
3240    ///
3241    /// {{produces}}
3242    ///
3243    /// ### Explanation
3244    ///
3245    /// Just like methods with `Self: Sized` bounds are unavailable on trait
3246    /// objects, associated types can be removed from the trait object.
3247    pub UNUSED_ASSOCIATED_TYPE_BOUNDS,
3248    Warn,
3249    "detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`"
3250}
3251
3252declare_lint! {
3253    /// The `unused_doc_comments` lint detects doc comments that aren't used
3254    /// by `rustdoc`.
3255    ///
3256    /// ### Example
3257    ///
3258    /// ```rust
3259    /// /// docs for x
3260    /// let x = 12;
3261    /// ```
3262    ///
3263    /// {{produces}}
3264    ///
3265    /// ### Explanation
3266    ///
3267    /// `rustdoc` does not use doc comments in all positions, and so the doc
3268    /// comment will be ignored. Try changing it to a normal comment with `//`
3269    /// to avoid the warning.
3270    pub UNUSED_DOC_COMMENTS,
3271    Warn,
3272    "detects doc comments that aren't used by rustdoc"
3273}
3274
3275declare_lint! {
3276    /// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3277    /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3278    /// Rust 2018 and 2021.
3279    ///
3280    /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3281    /// and the field is captured by a closure and used with the assumption that said field implements
3282    /// the same trait as the root variable.
3283    ///
3284    /// ### Example of drop reorder
3285    ///
3286    /// ```rust,edition2018,compile_fail
3287    /// #![deny(rust_2021_incompatible_closure_captures)]
3288    /// # #![allow(unused)]
3289    ///
3290    /// struct FancyInteger(i32);
3291    ///
3292    /// impl Drop for FancyInteger {
3293    ///     fn drop(&mut self) {
3294    ///         println!("Just dropped {}", self.0);
3295    ///     }
3296    /// }
3297    ///
3298    /// struct Point { x: FancyInteger, y: FancyInteger }
3299    ///
3300    /// fn main() {
3301    ///   let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3302    ///
3303    ///   let c = || {
3304    ///      let x = p.x;
3305    ///   };
3306    ///
3307    ///   c();
3308    ///
3309    ///   // ... More code ...
3310    /// }
3311    /// ```
3312    ///
3313    /// {{produces}}
3314    ///
3315    /// ### Explanation
3316    ///
3317    /// In the above example, `p.y` will be dropped at the end of `f` instead of
3318    /// with `c` in Rust 2021.
3319    ///
3320    /// ### Example of auto-trait
3321    ///
3322    /// ```rust,edition2018,compile_fail
3323    /// #![deny(rust_2021_incompatible_closure_captures)]
3324    /// use std::thread;
3325    ///
3326    /// struct Pointer(*mut i32);
3327    /// unsafe impl Send for Pointer {}
3328    ///
3329    /// fn main() {
3330    ///     let mut f = 10;
3331    ///     let fptr = Pointer(&mut f as *mut i32);
3332    ///     thread::spawn(move || unsafe {
3333    ///         *fptr.0 = 20;
3334    ///     });
3335    /// }
3336    /// ```
3337    ///
3338    /// {{produces}}
3339    ///
3340    /// ### Explanation
3341    ///
3342    /// In the above example, only `fptr.0` is captured in Rust 2021.
3343    /// The field is of type `*mut i32`, which doesn't implement `Send`,
3344    /// making the code invalid as the field cannot be sent between threads safely.
3345    pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3346    Allow,
3347    "detects closures affected by Rust 2021 changes",
3348    @future_incompatible = FutureIncompatibleInfo {
3349        reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
3350        explain_reason: false,
3351    };
3352}
3353
3354declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3355
3356declare_lint! {
3357    /// The `missing_abi` lint detects cases where the ABI is omitted from
3358    /// `extern` declarations.
3359    ///
3360    /// ### Example
3361    ///
3362    /// ```rust,compile_fail
3363    /// #![deny(missing_abi)]
3364    ///
3365    /// extern fn foo() {}
3366    /// ```
3367    ///
3368    /// {{produces}}
3369    ///
3370    /// ### Explanation
3371    ///
3372    /// For historic reasons, Rust implicitly selects `C` as the default ABI for
3373    /// `extern` declarations. [Other ABIs] like `C-unwind` and `system` have
3374    /// been added since then, and especially with their addition seeing the ABI
3375    /// easily makes code review easier.
3376    ///
3377    /// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
3378    pub MISSING_ABI,
3379    Warn,
3380    "No declared ABI for extern declaration"
3381}
3382
3383declare_lint! {
3384    /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3385    /// misused.
3386    ///
3387    /// ### Example
3388    ///
3389    /// ```rust,compile_fail
3390    /// #![deny(warnings)]
3391    ///
3392    /// pub mod submodule {
3393    ///     #![doc(test(no_crate_inject))]
3394    /// }
3395    /// ```
3396    ///
3397    /// {{produces}}
3398    ///
3399    /// ### Explanation
3400    ///
3401    /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
3402    /// being validated. Usually these should be rejected as a hard error,
3403    /// but this lint was introduced to avoid breaking any existing
3404    /// crates which included them.
3405    pub INVALID_DOC_ATTRIBUTES,
3406    Deny,
3407    "detects invalid `#[doc(...)]` attributes",
3408}
3409
3410declare_lint! {
3411    /// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3412    ///
3413    /// ### Example
3414    ///
3415    /// ```rust,edition2018,compile_fail
3416    /// #![deny(rust_2021_incompatible_or_patterns)]
3417    ///
3418    /// macro_rules! match_any {
3419    ///     ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3420    ///         match $expr {
3421    ///             $(
3422    ///                 $( $pat => $expr_arm, )+
3423    ///             )+
3424    ///         }
3425    ///     };
3426    /// }
3427    ///
3428    /// fn main() {
3429    ///     let result: Result<i64, i32> = Err(42);
3430    ///     let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3431    ///     assert_eq!(int, 42);
3432    /// }
3433    /// ```
3434    ///
3435    /// {{produces}}
3436    ///
3437    /// ### Explanation
3438    ///
3439    /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3440    pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3441    Allow,
3442    "detects usage of old versions of or-patterns",
3443    @future_incompatible = FutureIncompatibleInfo {
3444        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3445        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>",
3446    };
3447}
3448
3449declare_lint! {
3450    /// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3451    /// with traits added to the prelude in future editions.
3452    ///
3453    /// ### Example
3454    ///
3455    /// ```rust,edition2018,compile_fail
3456    /// #![deny(rust_2021_prelude_collisions)]
3457    ///
3458    /// trait Foo {
3459    ///     fn try_into(self) -> Result<String, !>;
3460    /// }
3461    ///
3462    /// impl Foo for &str {
3463    ///     fn try_into(self) -> Result<String, !> {
3464    ///         Ok(String::from(self))
3465    ///     }
3466    /// }
3467    ///
3468    /// fn main() {
3469    ///     let x: String = "3".try_into().unwrap();
3470    ///     //                  ^^^^^^^^
3471    ///     // This call to try_into matches both Foo::try_into and TryInto::try_into as
3472    ///     // `TryInto` has been added to the Rust prelude in 2021 edition.
3473    ///     println!("{x}");
3474    /// }
3475    /// ```
3476    ///
3477    /// {{produces}}
3478    ///
3479    /// ### Explanation
3480    ///
3481    /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3482    /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3483    /// results in an ambiguity as to which method/function to call when an existing `try_into`
3484    /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3485    /// is called directly on a type.
3486    ///
3487    /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3488    pub RUST_2021_PRELUDE_COLLISIONS,
3489    Allow,
3490    "detects the usage of trait methods which are ambiguous with traits added to the \
3491        prelude in future editions",
3492    @future_incompatible = FutureIncompatibleInfo {
3493        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3494        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>",
3495    };
3496}
3497
3498declare_lint! {
3499    /// The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3500    /// with traits added to the prelude in future editions.
3501    ///
3502    /// ### Example
3503    ///
3504    /// ```rust,edition2021,compile_fail
3505    /// #![deny(rust_2024_prelude_collisions)]
3506    /// trait Meow {
3507    ///     fn poll(&self) {}
3508    /// }
3509    /// impl<T> Meow for T {}
3510    ///
3511    /// fn main() {
3512    ///     core::pin::pin!(async {}).poll();
3513    ///     //                        ^^^^^^
3514    ///     // This call to try_into matches both Future::poll and Meow::poll as
3515    ///     // `Future` has been added to the Rust prelude in 2024 edition.
3516    /// }
3517    /// ```
3518    ///
3519    /// {{produces}}
3520    ///
3521    /// ### Explanation
3522    ///
3523    /// Rust 2024, introduces two new additions to the standard library's prelude:
3524    /// `Future` and `IntoFuture`. This results in an ambiguity as to which method/function
3525    /// to call when an existing `poll`/`into_future` method is called via dot-call syntax or
3526    /// a `poll`/`into_future` associated function is called directly on a type.
3527    ///
3528    pub RUST_2024_PRELUDE_COLLISIONS,
3529    Allow,
3530    "detects the usage of trait methods which are ambiguous with traits added to the \
3531        prelude in future editions",
3532    @future_incompatible = FutureIncompatibleInfo {
3533        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
3534        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html>",
3535    };
3536}
3537
3538declare_lint! {
3539    /// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3540    /// prefix instead in Rust 2021.
3541    ///
3542    /// ### Example
3543    ///
3544    /// ```rust,edition2018,compile_fail
3545    /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3546    ///
3547    /// macro_rules! m {
3548    ///     (z $x:expr) => ();
3549    /// }
3550    ///
3551    /// m!(z"hey");
3552    /// ```
3553    ///
3554    /// {{produces}}
3555    ///
3556    /// ### Explanation
3557    ///
3558    /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3559    /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3560    /// considered a prefix for `"hey"`.
3561    ///
3562    /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3563    /// to keep them separated in Rust 2021.
3564    // Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3565    #[allow(rustdoc::invalid_rust_codeblocks)]
3566    pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3567    Allow,
3568    "identifiers that will be parsed as a prefix in Rust 2021",
3569    @future_incompatible = FutureIncompatibleInfo {
3570        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3571        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>",
3572    };
3573    crate_level_only
3574}
3575
3576declare_lint! {
3577    /// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3578    /// `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind
3579    /// variants) on targets that cannot meaningfully be supported for the requested target.
3580    ///
3581    /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3582    /// code, because this calling convention was never specified for those targets.
3583    ///
3584    /// Historically MSVC toolchains have fallen back to the regular C calling convention for
3585    /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3586    /// hack across many more targets.
3587    ///
3588    /// ### Example
3589    ///
3590    /// ```rust,ignore (needs specific targets)
3591    /// extern "stdcall" fn stdcall() {}
3592    /// ```
3593    ///
3594    /// This will produce:
3595    ///
3596    /// ```text
3597    /// warning: use of calling convention not supported on this target
3598    ///   --> $DIR/unsupported.rs:39:1
3599    ///    |
3600    /// LL | extern "stdcall" fn stdcall() {}
3601    ///    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3602    ///    |
3603    ///    = note: `#[warn(unsupported_calling_conventions)]` on by default
3604    ///    = warning: this was previously accepted by the compiler but is being phased out;
3605    ///               it will become a hard error in a future release!
3606    ///    = note: for more information, see issue ...
3607    /// ```
3608    ///
3609    /// ### Explanation
3610    ///
3611    /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3612    /// defined at all, but was previously accepted due to a bug in the implementation of the
3613    /// compiler.
3614    pub UNSUPPORTED_CALLING_CONVENTIONS,
3615    Warn,
3616    "use of unsupported calling convention",
3617    @future_incompatible = FutureIncompatibleInfo {
3618        reason: FutureIncompatibilityReason::FutureReleaseError,
3619        report_in_deps: false,
3620        reference: "issue #137018 <https://github.com/rust-lang/rust/issues/137018>",
3621    };
3622}
3623
3624declare_lint! {
3625    /// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
3626    /// a target dependent calling convention on a target that does not support this calling
3627    /// convention on a function pointer.
3628    ///
3629    /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3630    /// code, because this calling convention was never specified for those targets.
3631    ///
3632    /// ### Example
3633    ///
3634    /// ```rust,ignore (needs specific targets)
3635    /// fn stdcall_ptr(f: extern "stdcall" fn ()) {
3636    ///     f()
3637    /// }
3638    /// ```
3639    ///
3640    /// This will produce:
3641    ///
3642    /// ```text
3643    /// warning: the calling convention `"stdcall"` is not supported on this target
3644    ///   --> $DIR/unsupported.rs:34:15
3645    ///    |
3646    /// LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
3647    ///    |               ^^^^^^^^^^^^^^^^^^^^^^^^
3648    ///    |
3649    ///    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3650    ///    = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
3651    ///    = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
3652    /// ```
3653    ///
3654    /// ### Explanation
3655    ///
3656    /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3657    /// defined at all, but was previously accepted due to a bug in the implementation of the
3658    /// compiler.
3659    pub UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
3660    Warn,
3661    "use of unsupported calling convention for function pointer",
3662    @future_incompatible = FutureIncompatibleInfo {
3663        reason: FutureIncompatibilityReason::FutureReleaseError,
3664        reference: "issue #130260 <https://github.com/rust-lang/rust/issues/130260>",
3665        report_in_deps: true,
3666    };
3667}
3668
3669declare_lint! {
3670    /// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3671    /// an unlabeled loop as their value expression.
3672    ///
3673    /// ### Example
3674    ///
3675    /// ```rust
3676    /// 'label: loop {
3677    ///     break 'label loop { break 42; };
3678    /// };
3679    /// ```
3680    ///
3681    /// {{produces}}
3682    ///
3683    /// ### Explanation
3684    ///
3685    /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3686    /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3687    /// can also carry a value expression, which can be another loop. A labeled `break` with an
3688    /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3689    /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3690    /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3691    /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3692    /// in parentheses.
3693    pub BREAK_WITH_LABEL_AND_LOOP,
3694    Warn,
3695    "`break` expression with label and unlabeled loop as value expression"
3696}
3697
3698declare_lint! {
3699    /// The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`
3700    /// struct or enum who want to match all of its fields/variants explicitly.
3701    ///
3702    /// The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness
3703    /// checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy
3704    /// this, this allow-by-default lint warns the user when a match mentions some but not all of
3705    /// the fields/variants of a `#[non_exhaustive]` struct or enum.
3706    ///
3707    /// ### Example
3708    ///
3709    /// ```rust,ignore (needs separate crate)
3710    /// // crate A
3711    /// #[non_exhaustive]
3712    /// pub enum Bar {
3713    ///     A,
3714    ///     B, // added variant in non breaking change
3715    /// }
3716    ///
3717    /// // in crate B
3718    /// #![feature(non_exhaustive_omitted_patterns_lint)]
3719    /// #[warn(non_exhaustive_omitted_patterns)]
3720    /// match Bar::A {
3721    ///     Bar::A => {},
3722    ///     _ => {},
3723    /// }
3724    /// ```
3725    ///
3726    /// This will produce:
3727    ///
3728    /// ```text
3729    /// warning: some variants are not matched explicitly
3730    ///    --> $DIR/reachable-patterns.rs:70:9
3731    ///    |
3732    /// LL |         match Bar::A {
3733    ///    |               ^ pattern `Bar::B` not covered
3734    ///    |
3735    ///  note: the lint level is defined here
3736    ///   --> $DIR/reachable-patterns.rs:69:16
3737    ///    |
3738    /// LL |         #[warn(non_exhaustive_omitted_patterns)]
3739    ///    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3740    ///    = help: ensure that all variants are matched explicitly by adding the suggested match arms
3741    ///    = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3742    /// ```
3743    ///
3744    /// Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or
3745    /// variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against
3746    /// expected semver behavior.
3747    ///
3748    /// ### Explanation
3749    ///
3750    /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially
3751    /// redundant) wildcard when pattern-matching, to allow for future addition of fields or
3752    /// variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to
3753    /// actually catch some fields/variants. In other words, when the match without the wildcard
3754    /// would not be exhaustive. This lets the user be informed if new fields/variants were added.
3755    pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3756    Allow,
3757    "detect when patterns of types marked `non_exhaustive` are missed",
3758    @feature_gate = non_exhaustive_omitted_patterns_lint;
3759}
3760
3761declare_lint! {
3762    /// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3763    /// change the visual representation of text on screen in a way that does not correspond to
3764    /// their on memory representation.
3765    ///
3766    /// ### Example
3767    ///
3768    /// ```rust,compile_fail
3769    /// #![deny(text_direction_codepoint_in_comment)]
3770    /// fn main() {
3771    #[doc = "    println!(\"{:?}\"); // '\u{202E}');"]
3772    /// }
3773    /// ```
3774    ///
3775    /// {{produces}}
3776    ///
3777    /// ### Explanation
3778    ///
3779    /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3780    /// are written right-to-left, but a specially crafted comment can make code that will be
3781    /// compiled appear to be part of a comment, depending on the software used to read the code.
3782    /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3783    /// their use.
3784    pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3785    Deny,
3786    "invisible directionality-changing codepoints in comment",
3787    crate_level_only
3788}
3789
3790declare_lint! {
3791    /// The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the
3792    /// visual representation of text on screen in a way that does not correspond to their on
3793    /// memory representation.
3794    ///
3795    /// ### Explanation
3796    ///
3797    /// The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,
3798    /// `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change
3799    /// its direction on software that supports these codepoints. This makes the text "abc" display
3800    /// as "cba" on screen. By leveraging software that supports these, people can write specially
3801    /// crafted literals that make the surrounding code seem like it's performing one action, when
3802    /// in reality it is performing another. Because of this, we proactively lint against their
3803    /// presence to avoid surprises.
3804    ///
3805    /// ### Example
3806    ///
3807    /// ```rust,compile_fail
3808    /// #![deny(text_direction_codepoint_in_literal)]
3809    /// fn main() {
3810    // ` - convince tidy that backticks match
3811    #[doc = "    println!(\"{:?}\", '\u{202E}');"]
3812    // `
3813    /// }
3814    /// ```
3815    ///
3816    /// {{produces}}
3817    ///
3818    pub TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
3819    Deny,
3820    "detect special Unicode codepoints that affect the visual representation of text on screen, \
3821     changing the direction in which text flows",
3822    crate_level_only
3823}
3824
3825declare_lint! {
3826    /// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3827    /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3828    /// and `test_case`.
3829    ///
3830    /// ### Example
3831    ///
3832    /// ```rust,ignore (needs --test)
3833    /// #[test]
3834    /// #[test]
3835    /// fn foo() {}
3836    /// ```
3837    ///
3838    /// This will produce:
3839    ///
3840    /// ```text
3841    /// warning: duplicated attribute
3842    ///  --> src/lib.rs:2:1
3843    ///   |
3844    /// 2 | #[test]
3845    ///   | ^^^^^^^
3846    ///   |
3847    ///   = note: `#[warn(duplicate_macro_attributes)]` on by default
3848    /// ```
3849    ///
3850    /// ### Explanation
3851    ///
3852    /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3853    /// being duplicated may not be obvious or desirable.
3854    ///
3855    /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3856    /// change to its environment.
3857    ///
3858    /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3859    pub DUPLICATE_MACRO_ATTRIBUTES,
3860    Warn,
3861    "duplicated attribute"
3862}
3863
3864declare_lint! {
3865    /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3866    /// in an associated type.
3867    ///
3868    /// ### Example
3869    ///
3870    /// ```rust
3871    /// trait Trait {
3872    ///   type Assoc<'a> where Self: 'a;
3873    /// }
3874    ///
3875    /// impl Trait for () {
3876    ///   type Assoc<'a> where Self: 'a = ();
3877    /// }
3878    /// ```
3879    ///
3880    /// {{produces}}
3881    ///
3882    /// ### Explanation
3883    ///
3884    /// The preferred location for where clauses on associated types
3885    /// is after the type. However, for most of generic associated types development,
3886    /// it was only accepted before the equals. To provide a transition period and
3887    /// further evaluate this change, both are currently accepted. At some point in
3888    /// the future, this may be disallowed at an edition boundary; but, that is
3889    /// undecided currently.
3890    pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3891    Warn,
3892    "deprecated where clause location"
3893}
3894
3895declare_lint! {
3896    /// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3897    ///
3898    /// ### Example
3899    ///
3900    /// ```rust
3901    /// // This lint is intentionally used to test the compiler's behavior
3902    /// // when an unstable lint is enabled without the corresponding feature gate.
3903    /// #![allow(test_unstable_lint)]
3904    /// ```
3905    ///
3906    /// {{produces}}
3907    ///
3908    /// ### Explanation
3909    ///
3910    /// In order to test the behavior of unstable lints, a permanently-unstable
3911    /// lint is required. This lint can be used to trigger warnings and errors
3912    /// from the compiler related to unstable lints.
3913    pub TEST_UNSTABLE_LINT,
3914    Deny,
3915    "this unstable lint is only for testing",
3916    @feature_gate = test_unstable_lint;
3917}
3918
3919declare_lint! {
3920    /// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3921    /// `C-unwind` or other FFI-unwind ABIs.
3922    ///
3923    /// ### Example
3924    ///
3925    /// ```rust
3926    /// #![warn(ffi_unwind_calls)]
3927    ///
3928    /// unsafe extern "C-unwind" {
3929    ///     fn foo();
3930    /// }
3931    ///
3932    /// fn bar() {
3933    ///     unsafe { foo(); }
3934    ///     let ptr: unsafe extern "C-unwind" fn() = foo;
3935    ///     unsafe { ptr(); }
3936    /// }
3937    /// ```
3938    ///
3939    /// {{produces}}
3940    ///
3941    /// ### Explanation
3942    ///
3943    /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3944    /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3945    /// that desire this ability it is therefore necessary to avoid such calls.
3946    pub FFI_UNWIND_CALLS,
3947    Allow,
3948    "call to foreign functions or function pointers with FFI-unwind ABI"
3949}
3950
3951declare_lint! {
3952    /// The `linker_messages` lint forwards warnings from the linker.
3953    ///
3954    /// ### Example
3955    ///
3956    /// ```rust,ignore (needs CLI args, platform-specific)
3957    /// #[warn(linker_messages)]
3958    /// extern "C" {
3959    ///   fn foo();
3960    /// }
3961    /// fn main () { unsafe { foo(); } }
3962    /// ```
3963    ///
3964    /// On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce
3965    ///
3966    /// ```text
3967    /// warning: linker stderr: rust-lld: undefined symbol: foo
3968    ///          >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
3969    ///          >>>               rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
3970    ///   |
3971    /// note: the lint level is defined here
3972    ///  --> warn.rs:1:9
3973    ///   |
3974    /// 1 | #![warn(linker_messages)]
3975    ///   |         ^^^^^^^^^^^^^^^
3976    /// warning: 1 warning emitted
3977    /// ```
3978    ///
3979    /// ### Explanation
3980    ///
3981    /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
3982    /// advance by the Rust compiler. Such messages are ignored by default for now. While linker
3983    /// warnings could be very useful they have been ignored for many years by essentially all
3984    /// users, so we need to do a bit more work than just surfacing their text to produce a clear
3985    /// and actionable warning of similar quality to our other diagnostics. See this tracking
3986    /// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
3987    pub LINKER_MESSAGES,
3988    Allow,
3989    "warnings emitted at runtime by the target-specific linker program"
3990}
3991
3992declare_lint! {
3993    /// The `named_arguments_used_positionally` lint detects cases where named arguments are only
3994    /// used positionally in format strings. This usage is valid but potentially very confusing.
3995    ///
3996    /// ### Example
3997    ///
3998    /// ```rust,compile_fail
3999    /// #![deny(named_arguments_used_positionally)]
4000    /// fn main() {
4001    ///     let _x = 5;
4002    ///     println!("{}", _x = 1); // Prints 1, will trigger lint
4003    ///
4004    ///     println!("{}", _x); // Prints 5, no lint emitted
4005    ///     println!("{_x}", _x = _x); // Prints 5, no lint emitted
4006    /// }
4007    /// ```
4008    ///
4009    /// {{produces}}
4010    ///
4011    /// ### Explanation
4012    ///
4013    /// Rust formatting strings can refer to named arguments by their position, but this usage is
4014    /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4015    /// of named arguments is an assignment (which would produce the unit type).
4016    /// For backwards compatibility, this is not a hard error.
4017    pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4018    Warn,
4019    "named arguments in format used positionally"
4020}
4021
4022declare_lint! {
4023    /// The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback
4024    /// affects unsafe function calls.
4025    ///
4026    /// ### Never type fallback
4027    ///
4028    /// When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),
4029    /// to allow type check to infer any type:
4030    ///
4031    /// ```ignore (illustrative-and-has-placeholders)
4032    /// // this
4033    /// let x: u8 = panic!();
4034    ///
4035    /// // is (essentially) turned by the compiler into
4036    /// let x: u8 = absurd(panic!());
4037    ///
4038    /// // where absurd is a function with the following signature
4039    /// // (it's sound, because `!` always marks unreachable code):
4040    /// fn absurd<T>(never: !) -> T { ... }
4041    /// ```
4042    ///
4043    /// While it's convenient to be able to use non-diverging code in one of the branches (like
4044    /// `if a { b } else { return }`) this could lead to compilation errors:
4045    ///
4046    /// ```compile_fail
4047    /// // this
4048    /// { panic!() };
4049    ///
4050    /// // gets turned into this
4051    /// { absurd(panic!()) }; // error: can't infer the type of `absurd`
4052    /// ```
4053    ///
4054    /// To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it
4055    /// can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`.
4056    /// This is what is known as "never type fallback".
4057    ///
4058    /// ### Example
4059    ///
4060    /// ```rust,compile_fail
4061    /// #![deny(never_type_fallback_flowing_into_unsafe)]
4062    /// fn main() {
4063    ///     if true {
4064    ///         // return has type `!` which, is some cases, causes never type fallback
4065    ///         return
4066    ///     } else {
4067    ///         // `zeroed` is an unsafe function, which returns an unbounded type
4068    ///         unsafe { std::mem::zeroed() }
4069    ///     };
4070    ///     // depending on the fallback, `zeroed` may create `()` (which is completely sound),
4071    ///     // or `!` (which is instant undefined behavior)
4072    /// }
4073    /// ```
4074    ///
4075    /// {{produces}}
4076    ///
4077    /// ### Explanation
4078    ///
4079    /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4080    /// coerced to `()`. There are plans to change that, but they may make the code such as above
4081    /// unsound. Instead of depending on the fallback, you should specify the type explicitly:
4082    /// ```
4083    /// if true {
4084    ///     return
4085    /// } else {
4086    ///     // type is explicitly specified, fallback can't hurt us no more
4087    ///     unsafe { std::mem::zeroed::<()>() }
4088    /// };
4089    /// ```
4090    ///
4091    /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4092    ///
4093    /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4094    /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4095    pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
4096    Warn,
4097    "never type fallback affecting unsafe function calls",
4098    @future_incompatible = FutureIncompatibleInfo {
4099        reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
4100        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
4101        report_in_deps: true,
4102    };
4103    @edition Edition2024 => Deny;
4104    report_in_external_macro
4105}
4106
4107declare_lint! {
4108    /// The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with
4109    /// [never type fallback] being [`()`], but will stop compiling with fallback being [`!`].
4110    ///
4111    /// [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback
4112    /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4113    /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4114    ///
4115    /// ### Example
4116    ///
4117    /// ```rust,compile_fail,edition2021
4118    /// #![deny(dependency_on_unit_never_type_fallback)]
4119    /// fn main() {
4120    ///     if true {
4121    ///         // return has type `!` which, is some cases, causes never type fallback
4122    ///         return
4123    ///     } else {
4124    ///         // the type produced by this call is not specified explicitly,
4125    ///         // so it will be inferred from the previous branch
4126    ///         Default::default()
4127    ///     };
4128    ///     // depending on the fallback, this may compile (because `()` implements `Default`),
4129    ///     // or it may not (because `!` does not implement `Default`)
4130    /// }
4131    /// ```
4132    ///
4133    /// {{produces}}
4134    ///
4135    /// ### Explanation
4136    ///
4137    /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4138    /// coerced to `()`. There are plans to change that, but they may make the code such as above
4139    /// not compile. Instead of depending on the fallback, you should specify the type explicitly:
4140    /// ```
4141    /// if true {
4142    ///     return
4143    /// } else {
4144    ///     // type is explicitly specified, fallback can't hurt us no more
4145    ///     <() as Default>::default()
4146    /// };
4147    /// ```
4148    ///
4149    /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4150    pub DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
4151    Warn,
4152    "never type fallback affecting unsafe function calls",
4153    @future_incompatible = FutureIncompatibleInfo {
4154        reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
4155        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/never-type-fallback.html>",
4156        report_in_deps: true,
4157    };
4158    report_in_external_macro
4159}
4160
4161declare_lint! {
4162    /// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
4163    ///
4164    /// ### Example
4165    ///
4166    /// ```rust,compile_fail
4167    /// #![deny(invalid_macro_export_arguments)]
4168    ///
4169    /// #[macro_export(invalid_parameter)]
4170    /// macro_rules! myMacro {
4171    ///    () => {
4172    ///         // [...]
4173    ///    }
4174    /// }
4175    ///
4176    /// #[macro_export(too, many, items)]
4177    /// ```
4178    ///
4179    /// {{produces}}
4180    ///
4181    /// ### Explanation
4182    ///
4183    /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
4184    /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
4185    ///
4186    pub INVALID_MACRO_EXPORT_ARGUMENTS,
4187    Warn,
4188    "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
4189}
4190
4191declare_lint! {
4192    /// The `private_interfaces` lint detects types in a primary interface of an item,
4193    /// that are more private than the item itself. Primary interface of an item is all
4194    /// its interface except for bounds on generic parameters and where clauses.
4195    ///
4196    /// ### Example
4197    ///
4198    /// ```rust,compile_fail
4199    /// # #![allow(unused)]
4200    /// #![deny(private_interfaces)]
4201    /// struct SemiPriv;
4202    ///
4203    /// mod m1 {
4204    ///     struct Priv;
4205    ///     impl crate::SemiPriv {
4206    ///         pub fn f(_: Priv) {}
4207    ///     }
4208    /// }
4209    ///
4210    /// # fn main() {}
4211    /// ```
4212    ///
4213    /// {{produces}}
4214    ///
4215    /// ### Explanation
4216    ///
4217    /// Having something private in primary interface guarantees that
4218    /// the item will be unusable from outer modules due to type privacy.
4219    pub PRIVATE_INTERFACES,
4220    Warn,
4221    "private type in primary interface of an item",
4222}
4223
4224declare_lint! {
4225    /// The `private_bounds` lint detects types in a secondary interface of an item,
4226    /// that are more private than the item itself. Secondary interface of an item consists of
4227    /// bounds on generic parameters and where clauses, including supertraits for trait items.
4228    ///
4229    /// ### Example
4230    ///
4231    /// ```rust,compile_fail
4232    /// # #![allow(unused)]
4233    /// #![deny(private_bounds)]
4234    ///
4235    /// struct PrivTy;
4236    /// pub struct S
4237    ///     where PrivTy:
4238    /// {}
4239    /// # fn main() {}
4240    /// ```
4241    ///
4242    /// {{produces}}
4243    ///
4244    /// ### Explanation
4245    ///
4246    /// Having private types or traits in item bounds makes it less clear what interface
4247    /// the item actually provides.
4248    pub PRIVATE_BOUNDS,
4249    Warn,
4250    "private type in secondary interface of an item",
4251}
4252
4253declare_lint! {
4254    /// The `unnameable_types` lint detects types for which you can get objects of that type,
4255    /// but cannot name the type itself.
4256    ///
4257    /// ### Example
4258    ///
4259    /// ```rust,compile_fail
4260    /// # #![allow(unused)]
4261    /// #![deny(unnameable_types)]
4262    /// mod m {
4263    ///     pub struct S;
4264    /// }
4265    ///
4266    /// pub fn get_unnameable() -> m::S { m::S }
4267    /// # fn main() {}
4268    /// ```
4269    ///
4270    /// {{produces}}
4271    ///
4272    /// ### Explanation
4273    ///
4274    /// It is often expected that if you can obtain an object of type `T`, then
4275    /// you can name the type `T` as well; this lint attempts to enforce this rule.
4276    /// The recommended action is to either reexport the type properly to make it nameable,
4277    /// or document that users are not supposed to be able to name it for one reason or another.
4278    ///
4279    /// Besides types, this lint applies to traits because traits can also leak through signatures,
4280    /// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
4281    pub UNNAMEABLE_TYPES,
4282    Allow,
4283    "effective visibility of a type is larger than the area in which it can be named",
4284}
4285
4286declare_lint! {
4287    /// The `unknown_or_malformed_diagnostic_attributes` lint detects unrecognized or otherwise malformed
4288    /// diagnostic attributes.
4289    ///
4290    /// ### Example
4291    ///
4292    /// ```rust
4293    /// #![feature(diagnostic_namespace)]
4294    /// #[diagnostic::does_not_exist]
4295    /// struct Foo;
4296    /// ```
4297    ///
4298    /// {{produces}}
4299    ///
4300    ///
4301    /// ### Explanation
4302    ///
4303    /// It is usually a mistake to specify a diagnostic attribute that does not exist. Check
4304    /// the spelling, and check the diagnostic attribute listing for the correct name. Also
4305    /// consider if you are using an old version of the compiler, and the attribute
4306    /// is only available in a newer version.
4307    pub UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
4308    Warn,
4309    "unrecognized or malformed diagnostic attribute",
4310}
4311
4312declare_lint! {
4313    /// The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity
4314    /// errors, but previously didn't do that due to rustc bugs.
4315    ///
4316    /// ### Example
4317    ///
4318    /// ```rust,compile_fail
4319    /// #![deny(ambiguous_glob_imports)]
4320    /// pub fn foo() -> u32 {
4321    ///     use sub::*;
4322    ///     C
4323    /// }
4324    ///
4325    /// mod sub {
4326    ///     mod mod1 { pub const C: u32 = 1; }
4327    ///     mod mod2 { pub const C: u32 = 2; }
4328    ///
4329    ///     pub use mod1::*;
4330    ///     pub use mod2::*;
4331    /// }
4332    /// ```
4333    ///
4334    /// {{produces}}
4335    ///
4336    /// ### Explanation
4337    ///
4338    /// Previous versions of Rust compile it successfully because it
4339    /// had lost the ambiguity error when resolve `use sub::mod2::*`.
4340    ///
4341    /// This is a [future-incompatible] lint to transition this to a
4342    /// hard error in the future.
4343    ///
4344    /// [future-incompatible]: ../index.md#future-incompatible-lints
4345    pub AMBIGUOUS_GLOB_IMPORTS,
4346    Warn,
4347    "detects certain glob imports that require reporting an ambiguity error",
4348    @future_incompatible = FutureIncompatibleInfo {
4349        reason: FutureIncompatibilityReason::FutureReleaseError,
4350        reference: "issue #114095 <https://github.com/rust-lang/rust/issues/114095>",
4351    };
4352}
4353
4354declare_lint! {
4355    /// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4356    /// types in method signatures that are refined by a publically reachable
4357    /// trait implementation, meaning the implementation adds information about
4358    /// the return type that is not present in the trait.
4359    ///
4360    /// ### Example
4361    ///
4362    /// ```rust,compile_fail
4363    /// #![deny(refining_impl_trait)]
4364    ///
4365    /// use std::fmt::Display;
4366    ///
4367    /// pub trait AsDisplay {
4368    ///     fn as_display(&self) -> impl Display;
4369    /// }
4370    ///
4371    /// impl<'s> AsDisplay for &'s str {
4372    ///     fn as_display(&self) -> Self {
4373    ///         *self
4374    ///     }
4375    /// }
4376    ///
4377    /// fn main() {
4378    ///     // users can observe that the return type of
4379    ///     // `<&str as AsDisplay>::as_display()` is `&str`.
4380    ///     let _x: &str = "".as_display();
4381    /// }
4382    /// ```
4383    ///
4384    /// {{produces}}
4385    ///
4386    /// ### Explanation
4387    ///
4388    /// Callers of methods for types where the implementation is known are
4389    /// able to observe the types written in the impl signature. This may be
4390    /// intended behavior, but may also lead to implementation details being
4391    /// revealed unintentionally. In particular, it may pose a semver hazard
4392    /// for authors of libraries who do not wish to make stronger guarantees
4393    /// about the types than what is written in the trait signature.
4394    ///
4395    /// `refining_impl_trait` is a lint group composed of two lints:
4396    ///
4397    /// * `refining_impl_trait_reachable`, for refinements that are publically
4398    ///   reachable outside a crate, and
4399    /// * `refining_impl_trait_internal`, for refinements that are only visible
4400    ///    within a crate.
4401    ///
4402    /// We are seeking feedback on each of these lints; see issue
4403    /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4404    /// information.
4405    pub REFINING_IMPL_TRAIT_REACHABLE,
4406    Warn,
4407    "impl trait in impl method signature does not match trait method signature",
4408}
4409
4410declare_lint! {
4411    /// The `refining_impl_trait_internal` lint detects `impl Trait` return
4412    /// types in method signatures that are refined by a trait implementation,
4413    /// meaning the implementation adds information about the return type that
4414    /// is not present in the trait.
4415    ///
4416    /// ### Example
4417    ///
4418    /// ```rust,compile_fail
4419    /// #![deny(refining_impl_trait)]
4420    ///
4421    /// use std::fmt::Display;
4422    ///
4423    /// trait AsDisplay {
4424    ///     fn as_display(&self) -> impl Display;
4425    /// }
4426    ///
4427    /// impl<'s> AsDisplay for &'s str {
4428    ///     fn as_display(&self) -> Self {
4429    ///         *self
4430    ///     }
4431    /// }
4432    ///
4433    /// fn main() {
4434    ///     // users can observe that the return type of
4435    ///     // `<&str as AsDisplay>::as_display()` is `&str`.
4436    ///     let _x: &str = "".as_display();
4437    /// }
4438    /// ```
4439    ///
4440    /// {{produces}}
4441    ///
4442    /// ### Explanation
4443    ///
4444    /// Callers of methods for types where the implementation is known are
4445    /// able to observe the types written in the impl signature. This may be
4446    /// intended behavior, but may also lead to implementation details being
4447    /// revealed unintentionally. In particular, it may pose a semver hazard
4448    /// for authors of libraries who do not wish to make stronger guarantees
4449    /// about the types than what is written in the trait signature.
4450    ///
4451    /// `refining_impl_trait` is a lint group composed of two lints:
4452    ///
4453    /// * `refining_impl_trait_reachable`, for refinements that are publically
4454    ///   reachable outside a crate, and
4455    /// * `refining_impl_trait_internal`, for refinements that are only visible
4456    ///    within a crate.
4457    ///
4458    /// We are seeking feedback on each of these lints; see issue
4459    /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4460    /// information.
4461    pub REFINING_IMPL_TRAIT_INTERNAL,
4462    Warn,
4463    "impl trait in impl method signature does not match trait method signature",
4464}
4465
4466declare_lint! {
4467    /// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
4468    /// in associated constants when there are other lifetimes in scope. This was
4469    /// accidentally supported, and this lint was later relaxed to allow eliding
4470    /// lifetimes to `'static` when there are no lifetimes in scope.
4471    ///
4472    /// ### Example
4473    ///
4474    /// ```rust,compile_fail
4475    /// #![deny(elided_lifetimes_in_associated_constant)]
4476    ///
4477    /// struct Foo<'a>(&'a ());
4478    ///
4479    /// impl<'a> Foo<'a> {
4480    ///     const STR: &str = "hello, world";
4481    /// }
4482    /// ```
4483    ///
4484    /// {{produces}}
4485    ///
4486    /// ### Explanation
4487    ///
4488    /// Previous version of Rust
4489    ///
4490    /// Implicit static-in-const behavior was decided [against] for associated
4491    /// constants because of ambiguity. This, however, regressed and the compiler
4492    /// erroneously treats elided lifetimes in associated constants as lifetime
4493    /// parameters on the impl.
4494    ///
4495    /// This is a [future-incompatible] lint to transition this to a
4496    /// hard error in the future.
4497    ///
4498    /// [against]: https://github.com/rust-lang/rust/issues/38831
4499    /// [future-incompatible]: ../index.md#future-incompatible-lints
4500    pub ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
4501    Deny,
4502    "elided lifetimes cannot be used in associated constants in impls",
4503    @future_incompatible = FutureIncompatibleInfo {
4504        reason: FutureIncompatibilityReason::FutureReleaseError,
4505        reference: "issue #115010 <https://github.com/rust-lang/rust/issues/115010>",
4506    };
4507}
4508
4509declare_lint! {
4510    /// The `private_macro_use` lint detects private macros that are imported
4511    /// with `#[macro_use]`.
4512    ///
4513    /// ### Example
4514    ///
4515    /// ```rust,ignore (needs extern crate)
4516    /// // extern_macro.rs
4517    /// macro_rules! foo_ { () => {}; }
4518    /// use foo_ as foo;
4519    ///
4520    /// // code.rs
4521    ///
4522    /// #![deny(private_macro_use)]
4523    ///
4524    /// #[macro_use]
4525    /// extern crate extern_macro;
4526    ///
4527    /// fn main() {
4528    ///     foo!();
4529    /// }
4530    /// ```
4531    ///
4532    /// This will produce:
4533    ///
4534    /// ```text
4535    /// error: cannot find macro `foo` in this scope
4536    /// ```
4537    ///
4538    /// ### Explanation
4539    ///
4540    /// This lint arises from overlooking visibility checks for macros
4541    /// in an external crate.
4542    ///
4543    /// This is a [future-incompatible] lint to transition this to a
4544    /// hard error in the future.
4545    ///
4546    /// [future-incompatible]: ../index.md#future-incompatible-lints
4547    pub PRIVATE_MACRO_USE,
4548    Warn,
4549    "detects certain macro bindings that should not be re-exported",
4550    @future_incompatible = FutureIncompatibleInfo {
4551        reason: FutureIncompatibilityReason::FutureReleaseError,
4552        reference: "issue #120192 <https://github.com/rust-lang/rust/issues/120192>",
4553    };
4554}
4555
4556declare_lint! {
4557    /// The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for
4558    /// foreign trait implementations that concerns the use of type parameters inside trait associated
4559    /// type paths ("projections") whose output may not be a local type that is mistakenly considered
4560    /// to "cover" said parameters which is **unsound** and which may be rejected by a future version
4561    /// of the compiler.
4562    ///
4563    /// Originally reported in [#99554].
4564    ///
4565    /// [#99554]: https://github.com/rust-lang/rust/issues/99554
4566    ///
4567    /// ### Example
4568    ///
4569    /// ```rust,ignore (dependent)
4570    /// // dependency.rs
4571    /// #![crate_type = "lib"]
4572    ///
4573    /// pub trait Trait<T, U> {}
4574    /// ```
4575    ///
4576    /// ```edition2021,ignore (needs dependency)
4577    /// // dependent.rs
4578    /// trait Identity {
4579    ///     type Output;
4580    /// }
4581    ///
4582    /// impl<T> Identity for T {
4583    ///     type Output = T;
4584    /// }
4585    ///
4586    /// struct Local;
4587    ///
4588    /// impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4589    ///
4590    /// fn main() {}
4591    /// ```
4592    ///
4593    /// This will produce:
4594    ///
4595    /// ```text
4596    /// warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4597    ///   --> dependent.rs:11:6
4598    ///    |
4599    /// 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4600    ///    |      ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4601    ///    |
4602    ///    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4603    ///    = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
4604    ///    = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
4605    ///    = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
4606    ///    = note: `#[warn(uncovered_param_in_projection)]` on by default
4607    /// ```
4608    ///
4609    /// ### Explanation
4610    ///
4611    /// FIXME(fmease): Write explainer.
4612    pub UNCOVERED_PARAM_IN_PROJECTION,
4613    Warn,
4614    "impl contains type parameters that are not covered",
4615    @future_incompatible = FutureIncompatibleInfo {
4616        reason: FutureIncompatibilityReason::FutureReleaseError,
4617        reference: "issue #124559 <https://github.com/rust-lang/rust/issues/124559>",
4618    };
4619}
4620
4621declare_lint! {
4622    /// The `deprecated_safe_2024` lint detects unsafe functions being used as
4623    /// safe functions.
4624    ///
4625    /// ### Example
4626    ///
4627    /// ```rust,edition2021,compile_fail
4628    /// #![deny(deprecated_safe)]
4629    /// // edition 2021
4630    /// use std::env;
4631    /// fn enable_backtrace() {
4632    ///     env::set_var("RUST_BACKTRACE", "1");
4633    /// }
4634    /// ```
4635    ///
4636    /// {{produces}}
4637    ///
4638    /// ### Explanation
4639    ///
4640    /// Rust [editions] allow the language to evolve without breaking backward
4641    /// compatibility. This lint catches code that uses `unsafe` functions that
4642    /// were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If
4643    /// you switch the compiler to Rust 2024 without updating the code, then it
4644    /// will fail to compile if you are using a function previously marked as
4645    /// safe.
4646    ///
4647    /// You can audit the code to see if it suffices the preconditions of the
4648    /// `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If
4649    /// you can't fulfill the preconditions, you probably need to switch to a
4650    /// different way of doing what you want to achieve.
4651    ///
4652    /// This lint can automatically wrap the calls in `unsafe` blocks, but this
4653    /// obviously cannot verify that the preconditions of the `unsafe`
4654    /// functions are fulfilled, so that is still up to the user.
4655    ///
4656    /// The lint is currently "allow" by default, but that might change in the
4657    /// future.
4658    ///
4659    /// [editions]: https://doc.rust-lang.org/edition-guide/
4660    pub DEPRECATED_SAFE_2024,
4661    Allow,
4662    "detects unsafe functions being used as safe functions",
4663    @future_incompatible = FutureIncompatibleInfo {
4664        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
4665        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/newly-unsafe-functions.html>",
4666    };
4667}
4668
4669declare_lint! {
4670    /// The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations.
4671    ///
4672    /// ### Example
4673    ///
4674    /// ```rust,edition2021
4675    /// #![warn(missing_unsafe_on_extern)]
4676    /// #![allow(dead_code)]
4677    ///
4678    /// extern "C" {
4679    ///     fn foo(_: i32);
4680    /// }
4681    ///
4682    /// fn main() {}
4683    /// ```
4684    ///
4685    /// {{produces}}
4686    ///
4687    /// ### Explanation
4688    ///
4689    /// Declaring extern items, even without ever using them, can cause Undefined Behavior. We
4690    /// should consider all sources of Undefined Behavior to be unsafe.
4691    ///
4692    /// This is a [future-incompatible] lint to transition this to a
4693    /// hard error in the future.
4694    ///
4695    /// [future-incompatible]: ../index.md#future-incompatible-lints
4696    pub MISSING_UNSAFE_ON_EXTERN,
4697    Allow,
4698    "detects missing unsafe keyword on extern declarations",
4699    @future_incompatible = FutureIncompatibleInfo {
4700        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
4701        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-extern.html>",
4702    };
4703}
4704
4705declare_lint! {
4706    /// The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword
4707    /// on attributes considered unsafe.
4708    ///
4709    /// ### Example
4710    ///
4711    /// ```rust,edition2021
4712    /// #![warn(unsafe_attr_outside_unsafe)]
4713    ///
4714    /// #[no_mangle]
4715    /// extern "C" fn foo() {}
4716    ///
4717    /// fn main() {}
4718    /// ```
4719    ///
4720    /// {{produces}}
4721    ///
4722    /// ### Explanation
4723    ///
4724    /// Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see
4725    /// [issue #82499] for a more complete list) are considered "unsafe" attributes.
4726    /// An unsafe attribute must only be used inside unsafe(...).
4727    ///
4728    /// This lint can automatically wrap the attributes in `unsafe(...)` , but this
4729    /// obviously cannot verify that the preconditions of the `unsafe`
4730    /// attributes are fulfilled, so that is still up to the user.
4731    ///
4732    /// The lint is currently "allow" by default, but that might change in the
4733    /// future.
4734    ///
4735    /// [editions]: https://doc.rust-lang.org/edition-guide/
4736    /// [issue #82499]: https://github.com/rust-lang/rust/issues/82499
4737    pub UNSAFE_ATTR_OUTSIDE_UNSAFE,
4738    Allow,
4739    "detects unsafe attributes outside of unsafe",
4740    @future_incompatible = FutureIncompatibleInfo {
4741        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
4742        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-attributes.html>",
4743    };
4744}
4745
4746declare_lint! {
4747    /// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
4748    /// above their definition, which may happen in key-value attributes.
4749    ///
4750    /// ### Example
4751    ///
4752    /// ```rust
4753    /// #![doc = in_root!()]
4754    ///
4755    /// macro_rules! in_root { () => { "" } }
4756    ///
4757    /// fn main() {}
4758    /// ```
4759    ///
4760    /// {{produces}}
4761    ///
4762    /// ### Explanation
4763    ///
4764    /// The scope in which a `macro_rules` item is visible starts at that item and continues
4765    /// below it. This is more similar to `let` than to other items, which are in scope both above
4766    /// and below their definition.
4767    /// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
4768    /// above their definition. The lint catches such cases.
4769    /// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
4770    /// with `use`.
4771    ///
4772    /// This is a [future-incompatible] lint to transition this to a
4773    /// hard error in the future.
4774    ///
4775    /// [future-incompatible]: ../index.md#future-incompatible-lints
4776    pub OUT_OF_SCOPE_MACRO_CALLS,
4777    Warn,
4778    "detects out of scope calls to `macro_rules` in key-value attributes",
4779    @future_incompatible = FutureIncompatibleInfo {
4780        reason: FutureIncompatibilityReason::FutureReleaseError,
4781        reference: "issue #124535 <https://github.com/rust-lang/rust/issues/124535>",
4782    };
4783}
4784
4785declare_lint! {
4786    /// The `supertrait_item_shadowing_usage` lint detects when the
4787    /// usage of an item that is provided by both a subtrait and supertrait
4788    /// is shadowed, preferring the subtrait.
4789    ///
4790    /// ### Example
4791    ///
4792    /// ```rust,compile_fail
4793    /// #![feature(supertrait_item_shadowing)]
4794    /// #![deny(supertrait_item_shadowing_usage)]
4795    ///
4796    /// trait Upstream {
4797    ///     fn hello(&self) {}
4798    /// }
4799    /// impl<T> Upstream for T {}
4800    ///
4801    /// trait Downstream: Upstream {
4802    ///     fn hello(&self) {}
4803    /// }
4804    /// impl<T> Downstream for T {}
4805    ///
4806    /// struct MyType;
4807    /// MyType.hello();
4808    /// ```
4809    ///
4810    /// {{produces}}
4811    ///
4812    /// ### Explanation
4813    ///
4814    /// RFC 3624 specified a heuristic in which a supertrait item would be
4815    /// shadowed by a subtrait item when ambiguity occurs during item
4816    /// selection. In order to mitigate side-effects of this happening
4817    /// silently, this lint detects these cases when users want to deny them
4818    /// or fix the call sites.
4819    pub SUPERTRAIT_ITEM_SHADOWING_USAGE,
4820    // FIXME(supertrait_item_shadowing): It is not decided if this should
4821    // warn by default at the call site.
4822    Allow,
4823    "detects when a supertrait item is shadowed by a subtrait item",
4824    @feature_gate = supertrait_item_shadowing;
4825}
4826
4827declare_lint! {
4828    /// The `supertrait_item_shadowing_definition` lint detects when the
4829    /// definition of an item that is provided by both a subtrait and
4830    /// supertrait is shadowed, preferring the subtrait.
4831    ///
4832    /// ### Example
4833    ///
4834    /// ```rust,compile_fail
4835    /// #![feature(supertrait_item_shadowing)]
4836    /// #![deny(supertrait_item_shadowing_definition)]
4837    ///
4838    /// trait Upstream {
4839    ///     fn hello(&self) {}
4840    /// }
4841    /// impl<T> Upstream for T {}
4842    ///
4843    /// trait Downstream: Upstream {
4844    ///     fn hello(&self) {}
4845    /// }
4846    /// impl<T> Downstream for T {}
4847    /// ```
4848    ///
4849    /// {{produces}}
4850    ///
4851    /// ### Explanation
4852    ///
4853    /// RFC 3624 specified a heuristic in which a supertrait item would be
4854    /// shadowed by a subtrait item when ambiguity occurs during item
4855    /// selection. In order to mitigate side-effects of this happening
4856    /// silently, this lint detects these cases when users want to deny them
4857    /// or fix their trait definitions.
4858    pub SUPERTRAIT_ITEM_SHADOWING_DEFINITION,
4859    // FIXME(supertrait_item_shadowing): It is not decided if this should
4860    // warn by default at the usage site.
4861    Allow,
4862    "detects when a supertrait item is shadowed by a subtrait item",
4863    @feature_gate = supertrait_item_shadowing;
4864}
4865
4866declare_lint! {
4867    /// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,
4868    /// that runs a custom `Drop` destructor.
4869    /// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior.
4870    /// This lint detects those cases and provides you information on those values and their custom destructor implementations.
4871    /// Your discretion on this information is required.
4872    ///
4873    /// ### Example
4874    /// ```rust,edition2021
4875    /// #![warn(tail_expr_drop_order)]
4876    /// struct Droppy(i32);
4877    /// impl Droppy {
4878    ///     fn get(&self) -> i32 {
4879    ///         self.0
4880    ///     }
4881    /// }
4882    /// impl Drop for Droppy {
4883    ///     fn drop(&mut self) {
4884    ///         // This is a custom destructor and it induces side-effects that is observable
4885    ///         // especially when the drop order at a tail expression changes.
4886    ///         println!("loud drop {}", self.0);
4887    ///     }
4888    /// }
4889    /// fn edition_2021() -> i32 {
4890    ///     let another_droppy = Droppy(0);
4891    ///     Droppy(1).get()
4892    /// }
4893    /// fn main() {
4894    ///     edition_2021();
4895    /// }
4896    /// ```
4897    ///
4898    /// {{produces}}
4899    ///
4900    /// ### Explanation
4901    ///
4902    /// In tail expression of blocks or function bodies,
4903    /// values of type with significant `Drop` implementation has an ill-specified drop order
4904    /// before Edition 2024 so that they are dropped only after dropping local variables.
4905    /// Edition 2024 introduces a new rule with drop orders for them,
4906    /// so that they are dropped first before dropping local variables.
4907    ///
4908    /// A significant `Drop::drop` destructor here refers to an explicit, arbitrary
4909    /// implementation of the `Drop` trait on the type, with exceptions including `Vec`,
4910    /// `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise
4911    /// so long that the generic types have no significant destructor recursively.
4912    /// In other words, a type has a significant drop destructor when it has a `Drop` implementation
4913    /// or its destructor invokes a significant destructor on a type.
4914    /// Since we cannot completely reason about the change by just inspecting the existence of
4915    /// a significant destructor, this lint remains only a suggestion and is set to `allow` by default.
4916    ///
4917    /// This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`
4918    /// does in Edition 2024.
4919    /// No fix will be proposed by this lint.
4920    /// However, the most probable fix is to hoist `Droppy` into its own local variable binding.
4921    /// ```rust
4922    /// struct Droppy(i32);
4923    /// impl Droppy {
4924    ///     fn get(&self) -> i32 {
4925    ///         self.0
4926    ///     }
4927    /// }
4928    /// fn edition_2024() -> i32 {
4929    ///     let value = Droppy(0);
4930    ///     let another_droppy = Droppy(1);
4931    ///     value.get()
4932    /// }
4933    /// ```
4934    pub TAIL_EXPR_DROP_ORDER,
4935    Allow,
4936    "Detect and warn on significant change in drop order in tail expression location",
4937    @future_incompatible = FutureIncompatibleInfo {
4938        reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2024),
4939        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html>",
4940    };
4941}
4942
4943declare_lint! {
4944    /// The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens
4945    /// that will be parsed as part of a guarded string literal in Rust 2024.
4946    ///
4947    /// ### Example
4948    ///
4949    /// ```rust,edition2021,compile_fail
4950    /// #![deny(rust_2024_guarded_string_incompatible_syntax)]
4951    ///
4952    /// macro_rules! m {
4953    ///     (# $x:expr #) => ();
4954    ///     (# $x:expr) => ();
4955    /// }
4956    ///
4957    /// m!(#"hey"#);
4958    /// m!(#"hello");
4959    /// ```
4960    ///
4961    /// {{produces}}
4962    ///
4963    /// ### Explanation
4964    ///
4965    /// Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`
4966    /// followed by the string literal `"hey"` then the final `#`.
4967    /// In Rust 2024, the whole sequence is considered a single token.
4968    ///
4969    /// This lint suggests to add whitespace between the leading `#`
4970    /// and the string to keep them separated in Rust 2024.
4971    // Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
4972    #[allow(rustdoc::invalid_rust_codeblocks)]
4973    pub RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
4974    Allow,
4975    "will be parsed as a guarded string in Rust 2024",
4976    @future_incompatible = FutureIncompatibleInfo {
4977        reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
4978        reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/reserved-syntax.html>",
4979    };
4980    crate_level_only
4981}
4982
4983declare_lint! {
4984    /// The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on
4985    /// softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of
4986    /// function calls, making this attribute unsound to use.
4987    ///
4988    /// ### Example
4989    ///
4990    /// ```rust,ignore (needs aarch64-unknown-none-softfloat)
4991    /// #[target_feature(enable = "neon")]
4992    /// fn with_neon() {}
4993    /// ```
4994    ///
4995    /// This will produce:
4996    ///
4997    /// ```text
4998    /// error: enabling the `neon` target feature on the current target is unsound due to ABI issues
4999    ///   --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
5000    ///    |
5001    ///    | #[target_feature(enable = "neon")]
5002    ///    |                  ^^^^^^^^^^^^^^^
5003    ///    |
5004    ///    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5005    ///    = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
5006    /// ```
5007    ///
5008    /// ### Explanation
5009    ///
5010    /// If a function like `with_neon` above ends up containing calls to LLVM builtins, those will
5011    /// not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with
5012    /// and without the `neon` target feature. The target feature should never have been stabilized
5013    /// on this target due to this issue, but the problem was not known at the time of
5014    /// stabilization.
5015    pub AARCH64_SOFTFLOAT_NEON,
5016    Warn,
5017    "detects code that could be affected by ABI issues on aarch64 softfloat targets",
5018    @future_incompatible = FutureIncompatibleInfo {
5019        reason: FutureIncompatibilityReason::FutureReleaseError,
5020        reference: "issue #134375 <https://github.com/rust-lang/rust/issues/134375>",
5021        report_in_deps: true,
5022    };
5023}