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