rustc_lint_defs/
builtin.rs

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