]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_lint_defs/src/builtin.rs
Auto merge of #102755 - pcc:data-local-tmp, r=Mark-Simulacrum
[rust.git] / compiler / rustc_lint_defs / src / 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 use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
8 use rustc_span::edition::Edition;
9 use rustc_span::symbol::sym;
10
11 declare_lint! {
12     /// The `forbidden_lint_groups` lint detects violations of
13     /// `forbid` applied to a lint group. Due to a bug in the compiler,
14     /// these used to be overlooked entirely. They now generate a warning.
15     ///
16     /// ### Example
17     ///
18     /// ```rust
19     /// #![forbid(warnings)]
20     /// #![deny(bad_style)]
21     ///
22     /// fn main() {}
23     /// ```
24     ///
25     /// {{produces}}
26     ///
27     /// ### Recommended fix
28     ///
29     /// If your crate is using `#![forbid(warnings)]`,
30     /// we recommend that you change to `#![deny(warnings)]`.
31     ///
32     /// ### Explanation
33     ///
34     /// Due to a compiler bug, applying `forbid` to lint groups
35     /// previously had no effect. The bug is now fixed but instead of
36     /// enforcing `forbid` we issue this future-compatibility warning
37     /// to avoid breaking existing crates.
38     pub FORBIDDEN_LINT_GROUPS,
39     Warn,
40     "applying forbid to lint-groups",
41     @future_incompatible = FutureIncompatibleInfo {
42         reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
43     };
44 }
45
46 declare_lint! {
47     /// The `ill_formed_attribute_input` lint detects ill-formed attribute
48     /// inputs that were previously accepted and used in practice.
49     ///
50     /// ### Example
51     ///
52     /// ```rust,compile_fail
53     /// #[inline = "this is not valid"]
54     /// fn foo() {}
55     /// ```
56     ///
57     /// {{produces}}
58     ///
59     /// ### Explanation
60     ///
61     /// Previously, inputs for many built-in attributes weren't validated and
62     /// nonsensical attribute inputs were accepted. After validation was
63     /// added, it was determined that some existing projects made use of these
64     /// invalid forms. This is a [future-incompatible] lint to transition this
65     /// to a hard error in the future. See [issue #57571] for more details.
66     ///
67     /// Check the [attribute reference] for details on the valid inputs for
68     /// attributes.
69     ///
70     /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
71     /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
72     /// [future-incompatible]: ../index.md#future-incompatible-lints
73     pub ILL_FORMED_ATTRIBUTE_INPUT,
74     Deny,
75     "ill-formed attribute inputs that were previously accepted and used in practice",
76     @future_incompatible = FutureIncompatibleInfo {
77         reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
78     };
79     crate_level_only
80 }
81
82 declare_lint! {
83     /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
84     /// conflicting hints.
85     ///
86     /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
87     ///
88     /// ### Example
89     ///
90     /// ```rust,compile_fail
91     /// #[repr(u32, u64)]
92     /// enum Foo {
93     ///     Variant1,
94     /// }
95     /// ```
96     ///
97     /// {{produces}}
98     ///
99     /// ### Explanation
100     ///
101     /// The compiler incorrectly accepted these conflicting representations in
102     /// the past. This is a [future-incompatible] lint to transition this to a
103     /// hard error in the future. See [issue #68585] for more details.
104     ///
105     /// To correct the issue, remove one of the conflicting hints.
106     ///
107     /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
108     /// [future-incompatible]: ../index.md#future-incompatible-lints
109     pub CONFLICTING_REPR_HINTS,
110     Deny,
111     "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
112     @future_incompatible = FutureIncompatibleInfo {
113         reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
114     };
115 }
116
117 declare_lint! {
118     /// The `meta_variable_misuse` lint detects possible meta-variable misuse
119     /// in macro definitions.
120     ///
121     /// ### Example
122     ///
123     /// ```rust,compile_fail
124     /// #![deny(meta_variable_misuse)]
125     ///
126     /// macro_rules! foo {
127     ///     () => {};
128     ///     ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
129     /// }
130     ///
131     /// fn main() {
132     ///     foo!();
133     /// }
134     /// ```
135     ///
136     /// {{produces}}
137     ///
138     /// ### Explanation
139     ///
140     /// There are quite a few different ways a [`macro_rules`] macro can be
141     /// improperly defined. Many of these errors were previously only detected
142     /// when the macro was expanded or not at all. This lint is an attempt to
143     /// catch some of these problems when the macro is *defined*.
144     ///
145     /// This lint is "allow" by default because it may have false positives
146     /// and other issues. See [issue #61053] for more details.
147     ///
148     /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
149     /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
150     pub META_VARIABLE_MISUSE,
151     Allow,
152     "possible meta-variable misuse at macro definition"
153 }
154
155 declare_lint! {
156     /// The `incomplete_include` lint detects the use of the [`include!`]
157     /// macro with a file that contains more than one expression.
158     ///
159     /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
160     ///
161     /// ### Example
162     ///
163     /// ```rust,ignore (needs separate file)
164     /// fn main() {
165     ///     include!("foo.txt");
166     /// }
167     /// ```
168     ///
169     /// where the file `foo.txt` contains:
170     ///
171     /// ```text
172     /// println!("hi!");
173     /// ```
174     ///
175     /// produces:
176     ///
177     /// ```text
178     /// error: include macro expected single expression in source
179     ///  --> foo.txt:1:14
180     ///   |
181     /// 1 | println!("1");
182     ///   |              ^
183     ///   |
184     ///   = note: `#[deny(incomplete_include)]` on by default
185     /// ```
186     ///
187     /// ### Explanation
188     ///
189     /// The [`include!`] macro is currently only intended to be used to
190     /// include a single [expression] or multiple [items]. Historically it
191     /// would ignore any contents after the first expression, but that can be
192     /// confusing. In the example above, the `println!` expression ends just
193     /// before the semicolon, making the semicolon "extra" information that is
194     /// ignored. Perhaps even more surprising, if the included file had
195     /// multiple print statements, the subsequent ones would be ignored!
196     ///
197     /// One workaround is to place the contents in braces to create a [block
198     /// expression]. Also consider alternatives, like using functions to
199     /// encapsulate the expressions, or use [proc-macros].
200     ///
201     /// This is a lint instead of a hard error because existing projects were
202     /// found to hit this error. To be cautious, it is a lint for now. The
203     /// future semantics of the `include!` macro are also uncertain, see
204     /// [issue #35560].
205     ///
206     /// [items]: https://doc.rust-lang.org/reference/items.html
207     /// [expression]: https://doc.rust-lang.org/reference/expressions.html
208     /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
209     /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
210     /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
211     pub INCOMPLETE_INCLUDE,
212     Deny,
213     "trailing content in included file"
214 }
215
216 declare_lint! {
217     /// The `arithmetic_overflow` lint detects that an arithmetic operation
218     /// will [overflow].
219     ///
220     /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
221     ///
222     /// ### Example
223     ///
224     /// ```rust,compile_fail
225     /// 1_i32 << 32;
226     /// ```
227     ///
228     /// {{produces}}
229     ///
230     /// ### Explanation
231     ///
232     /// It is very likely a mistake to perform an arithmetic operation that
233     /// overflows its value. If the compiler is able to detect these kinds of
234     /// overflows at compile-time, it will trigger this lint. Consider
235     /// adjusting the expression to avoid overflow, or use a data type that
236     /// will not overflow.
237     pub ARITHMETIC_OVERFLOW,
238     Deny,
239     "arithmetic operation overflows"
240 }
241
242 declare_lint! {
243     /// The `unconditional_panic` lint detects an operation that will cause a
244     /// panic at runtime.
245     ///
246     /// ### Example
247     ///
248     /// ```rust,compile_fail
249     /// # #![allow(unused)]
250     /// let x = 1 / 0;
251     /// ```
252     ///
253     /// {{produces}}
254     ///
255     /// ### Explanation
256     ///
257     /// This lint detects code that is very likely incorrect because it will
258     /// always panic, such as division by zero and out-of-bounds array
259     /// accesses. Consider adjusting your code if this is a bug, or using the
260     /// `panic!` or `unreachable!` macro instead in case the panic is intended.
261     pub UNCONDITIONAL_PANIC,
262     Deny,
263     "operation will cause a panic at runtime"
264 }
265
266 declare_lint! {
267     /// The `unused_imports` lint detects imports that are never used.
268     ///
269     /// ### Example
270     ///
271     /// ```rust
272     /// use std::collections::HashMap;
273     /// ```
274     ///
275     /// {{produces}}
276     ///
277     /// ### Explanation
278     ///
279     /// Unused imports may signal a mistake or unfinished code, and clutter
280     /// the code, and should be removed. If you intended to re-export the item
281     /// to make it available outside of the module, add a visibility modifier
282     /// like `pub`.
283     pub UNUSED_IMPORTS,
284     Warn,
285     "imports that are never used"
286 }
287
288 declare_lint! {
289     /// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
290     /// (`.await`)
291     ///
292     /// ### Example
293     ///
294     /// ```rust
295     /// #![feature(must_not_suspend)]
296     /// #![warn(must_not_suspend)]
297     ///
298     /// #[must_not_suspend]
299     /// struct SyncThing {}
300     ///
301     /// async fn yield_now() {}
302     ///
303     /// pub async fn uhoh() {
304     ///     let guard = SyncThing {};
305     ///     yield_now().await;
306     /// }
307     /// ```
308     ///
309     /// {{produces}}
310     ///
311     /// ### Explanation
312     ///
313     /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
314     /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
315     /// function.
316     ///
317     /// This attribute can be used to mark values that are semantically incorrect across suspends
318     /// (like certain types of timers), values that have async alternatives, and values that
319     /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
320     /// `MutexGuard`'s)
321     ///
322     pub MUST_NOT_SUSPEND,
323     Allow,
324     "use of a `#[must_not_suspend]` value across a yield point",
325     @feature_gate = rustc_span::symbol::sym::must_not_suspend;
326 }
327
328 declare_lint! {
329     /// The `unused_extern_crates` lint guards against `extern crate` items
330     /// that are never used.
331     ///
332     /// ### Example
333     ///
334     /// ```rust,compile_fail
335     /// #![deny(unused_extern_crates)]
336     /// extern crate proc_macro;
337     /// ```
338     ///
339     /// {{produces}}
340     ///
341     /// ### Explanation
342     ///
343     /// `extern crate` items that are unused have no effect and should be
344     /// removed. Note that there are some cases where specifying an `extern
345     /// crate` is desired for the side effect of ensuring the given crate is
346     /// linked, even though it is not otherwise directly referenced. The lint
347     /// can be silenced by aliasing the crate to an underscore, such as
348     /// `extern crate foo as _`. Also note that it is no longer idiomatic to
349     /// use `extern crate` in the [2018 edition], as extern crates are now
350     /// automatically added in scope.
351     ///
352     /// This lint is "allow" by default because it can be noisy, and produce
353     /// false-positives. If a dependency is being removed from a project, it
354     /// is recommended to remove it from the build configuration (such as
355     /// `Cargo.toml`) to ensure stale build entries aren't left behind.
356     ///
357     /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
358     pub UNUSED_EXTERN_CRATES,
359     Allow,
360     "extern crates that are never used"
361 }
362
363 declare_lint! {
364     /// The `unused_crate_dependencies` lint detects crate dependencies that
365     /// are never used.
366     ///
367     /// ### Example
368     ///
369     /// ```rust,ignore (needs extern crate)
370     /// #![deny(unused_crate_dependencies)]
371     /// ```
372     ///
373     /// This will produce:
374     ///
375     /// ```text
376     /// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
377     ///   |
378     /// note: the lint level is defined here
379     ///  --> src/lib.rs:1:9
380     ///   |
381     /// 1 | #![deny(unused_crate_dependencies)]
382     ///   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
383     /// ```
384     ///
385     /// ### Explanation
386     ///
387     /// After removing the code that uses a dependency, this usually also
388     /// requires removing the dependency from the build configuration.
389     /// However, sometimes that step can be missed, which leads to time wasted
390     /// building dependencies that are no longer used. This lint can be
391     /// enabled to detect dependencies that are never used (more specifically,
392     /// any dependency passed with the `--extern` command-line flag that is
393     /// never referenced via [`use`], [`extern crate`], or in any [path]).
394     ///
395     /// This lint is "allow" by default because it can provide false positives
396     /// depending on how the build system is configured. For example, when
397     /// using Cargo, a "package" consists of multiple crates (such as a
398     /// library and a binary), but the dependencies are defined for the
399     /// package as a whole. If there is a dependency that is only used in the
400     /// binary, but not the library, then the lint will be incorrectly issued
401     /// in the library.
402     ///
403     /// [path]: https://doc.rust-lang.org/reference/paths.html
404     /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
405     /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
406     pub UNUSED_CRATE_DEPENDENCIES,
407     Allow,
408     "crate dependencies that are never used",
409     crate_level_only
410 }
411
412 declare_lint! {
413     /// The `unused_qualifications` lint detects unnecessarily qualified
414     /// names.
415     ///
416     /// ### Example
417     ///
418     /// ```rust,compile_fail
419     /// #![deny(unused_qualifications)]
420     /// mod foo {
421     ///     pub fn bar() {}
422     /// }
423     ///
424     /// fn main() {
425     ///     use foo::bar;
426     ///     foo::bar();
427     /// }
428     /// ```
429     ///
430     /// {{produces}}
431     ///
432     /// ### Explanation
433     ///
434     /// If an item from another module is already brought into scope, then
435     /// there is no need to qualify it in this case. You can call `bar()`
436     /// directly, without the `foo::`.
437     ///
438     /// This lint is "allow" by default because it is somewhat pedantic, and
439     /// doesn't indicate an actual problem, but rather a stylistic choice, and
440     /// can be noisy when refactoring or moving around code.
441     pub UNUSED_QUALIFICATIONS,
442     Allow,
443     "detects unnecessarily qualified names"
444 }
445
446 declare_lint! {
447     /// The `unknown_lints` lint detects unrecognized lint attributes.
448     ///
449     /// ### Example
450     ///
451     /// ```rust
452     /// #![allow(not_a_real_lint)]
453     /// ```
454     ///
455     /// {{produces}}
456     ///
457     /// ### Explanation
458     ///
459     /// It is usually a mistake to specify a lint that does not exist. Check
460     /// the spelling, and check the lint listing for the correct name. Also
461     /// consider if you are using an old version of the compiler, and the lint
462     /// is only available in a newer version.
463     pub UNKNOWN_LINTS,
464     Warn,
465     "unrecognized lint attribute"
466 }
467
468 declare_lint! {
469     /// The `unfulfilled_lint_expectations` lint detects lint trigger expectations
470     /// that have not been fulfilled.
471     ///
472     /// ### Example
473     ///
474     /// ```rust
475     /// #![feature(lint_reasons)]
476     ///
477     /// #[expect(unused_variables)]
478     /// let x = 10;
479     /// println!("{}", x);
480     /// ```
481     ///
482     /// {{produces}}
483     ///
484     /// ### Explanation
485     ///
486     /// It was expected that the marked code would emit a lint. This expectation
487     /// has not been fulfilled.
488     ///
489     /// The `expect` attribute can be removed if this is intended behavior otherwise
490     /// it should be investigated why the expected lint is no longer issued.
491     ///
492     /// In rare cases, the expectation might be emitted at a different location than
493     /// shown in the shown code snippet. In most cases, the `#[expect]` attribute
494     /// works when added to the outer scope. A few lints can only be expected
495     /// on a crate level.
496     ///
497     /// Part of RFC 2383. The progress is being tracked in [#54503]
498     ///
499     /// [#54503]: https://github.com/rust-lang/rust/issues/54503
500     pub UNFULFILLED_LINT_EXPECTATIONS,
501     Warn,
502     "unfulfilled lint expectation",
503     @feature_gate = rustc_span::sym::lint_reasons;
504 }
505
506 declare_lint! {
507     /// The `unused_variables` lint detects variables which are not used in
508     /// any way.
509     ///
510     /// ### Example
511     ///
512     /// ```rust
513     /// let x = 5;
514     /// ```
515     ///
516     /// {{produces}}
517     ///
518     /// ### Explanation
519     ///
520     /// Unused variables may signal a mistake or unfinished code. To silence
521     /// the warning for the individual variable, prefix it with an underscore
522     /// such as `_x`.
523     pub UNUSED_VARIABLES,
524     Warn,
525     "detect variables which are not used in any way"
526 }
527
528 declare_lint! {
529     /// The `unused_assignments` lint detects assignments that will never be read.
530     ///
531     /// ### Example
532     ///
533     /// ```rust
534     /// let mut x = 5;
535     /// x = 6;
536     /// ```
537     ///
538     /// {{produces}}
539     ///
540     /// ### Explanation
541     ///
542     /// Unused assignments may signal a mistake or unfinished code. If the
543     /// variable is never used after being assigned, then the assignment can
544     /// be removed. Variables with an underscore prefix such as `_x` will not
545     /// trigger this lint.
546     pub UNUSED_ASSIGNMENTS,
547     Warn,
548     "detect assignments that will never be read"
549 }
550
551 declare_lint! {
552     /// The `dead_code` lint detects unused, unexported items.
553     ///
554     /// ### Example
555     ///
556     /// ```rust
557     /// fn foo() {}
558     /// ```
559     ///
560     /// {{produces}}
561     ///
562     /// ### Explanation
563     ///
564     /// Dead code may signal a mistake or unfinished code. To silence the
565     /// warning for individual items, prefix the name with an underscore such
566     /// as `_foo`. If it was intended to expose the item outside of the crate,
567     /// consider adding a visibility modifier like `pub`. Otherwise consider
568     /// removing the unused code.
569     pub DEAD_CODE,
570     Warn,
571     "detect unused, unexported items"
572 }
573
574 declare_lint! {
575     /// The `unused_attributes` lint detects attributes that were not used by
576     /// the compiler.
577     ///
578     /// ### Example
579     ///
580     /// ```rust
581     /// #![ignore]
582     /// ```
583     ///
584     /// {{produces}}
585     ///
586     /// ### Explanation
587     ///
588     /// Unused [attributes] may indicate the attribute is placed in the wrong
589     /// position. Consider removing it, or placing it in the correct position.
590     /// Also consider if you intended to use an _inner attribute_ (with a `!`
591     /// such as `#![allow(unused)]`) which applies to the item the attribute
592     /// is within, or an _outer attribute_ (without a `!` such as
593     /// `#[allow(unused)]`) which applies to the item *following* the
594     /// attribute.
595     ///
596     /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
597     pub UNUSED_ATTRIBUTES,
598     Warn,
599     "detects attributes that were not used by the compiler"
600 }
601
602 declare_lint! {
603     /// The `unused_tuple_struct_fields` lint detects fields of tuple structs
604     /// that are never read.
605     ///
606     /// ### Example
607     ///
608     /// ```
609     /// #[warn(unused_tuple_struct_fields)]
610     /// struct S(i32, i32, i32);
611     /// let s = S(1, 2, 3);
612     /// let _ = (s.0, s.2);
613     /// ```
614     ///
615     /// {{produces}}
616     ///
617     /// ### Explanation
618     ///
619     /// Tuple struct fields that are never read anywhere may indicate a
620     /// mistake or unfinished code. To silence this warning, consider
621     /// removing the unused field(s) or, to preserve the numbering of the
622     /// remaining fields, change the unused field(s) to have unit type.
623     pub UNUSED_TUPLE_STRUCT_FIELDS,
624     Allow,
625     "detects tuple struct fields that are never read"
626 }
627
628 declare_lint! {
629     /// The `unreachable_code` lint detects unreachable code paths.
630     ///
631     /// ### Example
632     ///
633     /// ```rust,no_run
634     /// panic!("we never go past here!");
635     ///
636     /// let x = 5;
637     /// ```
638     ///
639     /// {{produces}}
640     ///
641     /// ### Explanation
642     ///
643     /// Unreachable code may signal a mistake or unfinished code. If the code
644     /// is no longer in use, consider removing it.
645     pub UNREACHABLE_CODE,
646     Warn,
647     "detects unreachable code paths",
648     report_in_external_macro
649 }
650
651 declare_lint! {
652     /// The `unreachable_patterns` lint detects unreachable patterns.
653     ///
654     /// ### Example
655     ///
656     /// ```rust
657     /// let x = 5;
658     /// match x {
659     ///     y => (),
660     ///     5 => (),
661     /// }
662     /// ```
663     ///
664     /// {{produces}}
665     ///
666     /// ### Explanation
667     ///
668     /// This usually indicates a mistake in how the patterns are specified or
669     /// ordered. In this example, the `y` pattern will always match, so the
670     /// five is impossible to reach. Remember, match arms match in order, you
671     /// probably wanted to put the `5` case above the `y` case.
672     pub UNREACHABLE_PATTERNS,
673     Warn,
674     "detects unreachable patterns"
675 }
676
677 declare_lint! {
678     /// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
679     /// overlap on their endpoints.
680     ///
681     /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
682     ///
683     /// ### Example
684     ///
685     /// ```rust
686     /// let x = 123u8;
687     /// match x {
688     ///     0..=100 => { println!("small"); }
689     ///     100..=255 => { println!("large"); }
690     /// }
691     /// ```
692     ///
693     /// {{produces}}
694     ///
695     /// ### Explanation
696     ///
697     /// It is likely a mistake to have range patterns in a match expression that overlap in this
698     /// way. Check that the beginning and end values are what you expect, and keep in mind that
699     /// with `..=` the left and right bounds are inclusive.
700     pub OVERLAPPING_RANGE_ENDPOINTS,
701     Warn,
702     "detects range patterns with overlapping endpoints"
703 }
704
705 declare_lint! {
706     /// The `bindings_with_variant_name` lint detects pattern bindings with
707     /// the same name as one of the matched variants.
708     ///
709     /// ### Example
710     ///
711     /// ```rust
712     /// pub enum Enum {
713     ///     Foo,
714     ///     Bar,
715     /// }
716     ///
717     /// pub fn foo(x: Enum) {
718     ///     match x {
719     ///         Foo => {}
720     ///         Bar => {}
721     ///     }
722     /// }
723     /// ```
724     ///
725     /// {{produces}}
726     ///
727     /// ### Explanation
728     ///
729     /// It is usually a mistake to specify an enum variant name as an
730     /// [identifier pattern]. In the example above, the `match` arms are
731     /// specifying a variable name to bind the value of `x` to. The second arm
732     /// is ignored because the first one matches *all* values. The likely
733     /// intent is that the arm was intended to match on the enum variant.
734     ///
735     /// Two possible solutions are:
736     ///
737     /// * Specify the enum variant using a [path pattern], such as
738     ///   `Enum::Foo`.
739     /// * Bring the enum variants into local scope, such as adding `use
740     ///   Enum::*;` to the beginning of the `foo` function in the example
741     ///   above.
742     ///
743     /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
744     /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
745     pub BINDINGS_WITH_VARIANT_NAME,
746     Warn,
747     "detects pattern bindings with the same name as one of the matched variants"
748 }
749
750 declare_lint! {
751     /// The `unused_macros` lint detects macros that were not used.
752     ///
753     /// Note that this lint is distinct from the `unused_macro_rules` lint,
754     /// which checks for single rules that never match of an otherwise used
755     /// macro, and thus never expand.
756     ///
757     /// ### Example
758     ///
759     /// ```rust
760     /// macro_rules! unused {
761     ///     () => {};
762     /// }
763     ///
764     /// fn main() {
765     /// }
766     /// ```
767     ///
768     /// {{produces}}
769     ///
770     /// ### Explanation
771     ///
772     /// Unused macros may signal a mistake or unfinished code. To silence the
773     /// warning for the individual macro, prefix the name with an underscore
774     /// such as `_my_macro`. If you intended to export the macro to make it
775     /// available outside of the crate, use the [`macro_export` attribute].
776     ///
777     /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
778     pub UNUSED_MACROS,
779     Warn,
780     "detects macros that were not used"
781 }
782
783 declare_lint! {
784     /// The `unused_macro_rules` lint detects macro rules that were not used.
785     ///
786     /// Note that the lint is distinct from the `unused_macros` lint, which
787     /// fires if the entire macro is never called, while this lint fires for
788     /// single unused rules of the macro that is otherwise used.
789     /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
790     ///
791     /// ### Example
792     ///
793     /// ```rust
794     /// #[warn(unused_macro_rules)]
795     /// macro_rules! unused_empty {
796     ///     (hello) => { println!("Hello, world!") }; // This rule is unused
797     ///     () => { println!("empty") }; // This rule is used
798     /// }
799     ///
800     /// fn main() {
801     ///     unused_empty!(hello);
802     /// }
803     /// ```
804     ///
805     /// {{produces}}
806     ///
807     /// ### Explanation
808     ///
809     /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
810     /// they slow down compilation. Right now, silencing the warning is not
811     /// supported on a single rule level, so you have to add an allow to the
812     /// entire macro definition.
813     ///
814     /// If you intended to export the macro to make it
815     /// available outside of the crate, use the [`macro_export` attribute].
816     ///
817     /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
818     pub UNUSED_MACRO_RULES,
819     Allow,
820     "detects macro rules that were not used"
821 }
822
823 declare_lint! {
824     /// The `warnings` lint allows you to change the level of other
825     /// lints which produce warnings.
826     ///
827     /// ### Example
828     ///
829     /// ```rust
830     /// #![deny(warnings)]
831     /// fn foo() {}
832     /// ```
833     ///
834     /// {{produces}}
835     ///
836     /// ### Explanation
837     ///
838     /// The `warnings` lint is a bit special; by changing its level, you
839     /// change every other warning that would produce a warning to whatever
840     /// value you'd like. As such, you won't ever trigger this lint in your
841     /// code directly.
842     pub WARNINGS,
843     Warn,
844     "mass-change the level for lints which produce warnings"
845 }
846
847 declare_lint! {
848     /// The `unused_features` lint detects unused or unknown features found in
849     /// crate-level [`feature` attributes].
850     ///
851     /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
852     ///
853     /// Note: This lint is currently not functional, see [issue #44232] for
854     /// more details.
855     ///
856     /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
857     pub UNUSED_FEATURES,
858     Warn,
859     "unused features found in crate-level `#[feature]` directives"
860 }
861
862 declare_lint! {
863     /// The `stable_features` lint detects a [`feature` attribute] that
864     /// has since been made stable.
865     ///
866     /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
867     ///
868     /// ### Example
869     ///
870     /// ```rust
871     /// #![feature(test_accepted_feature)]
872     /// fn main() {}
873     /// ```
874     ///
875     /// {{produces}}
876     ///
877     /// ### Explanation
878     ///
879     /// When a feature is stabilized, it is no longer necessary to include a
880     /// `#![feature]` attribute for it. To fix, simply remove the
881     /// `#![feature]` attribute.
882     pub STABLE_FEATURES,
883     Warn,
884     "stable features found in `#[feature]` directive"
885 }
886
887 declare_lint! {
888     /// The `unknown_crate_types` lint detects an unknown crate type found in
889     /// a [`crate_type` attribute].
890     ///
891     /// ### Example
892     ///
893     /// ```rust,compile_fail
894     /// #![crate_type="lol"]
895     /// fn main() {}
896     /// ```
897     ///
898     /// {{produces}}
899     ///
900     /// ### Explanation
901     ///
902     /// An unknown value give to the `crate_type` attribute is almost
903     /// certainly a mistake.
904     ///
905     /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
906     pub UNKNOWN_CRATE_TYPES,
907     Deny,
908     "unknown crate type found in `#[crate_type]` directive",
909     crate_level_only
910 }
911
912 declare_lint! {
913     /// The `trivial_casts` lint detects trivial casts which could be replaced
914     /// with coercion, which may require [type ascription] or a temporary
915     /// variable.
916     ///
917     /// ### Example
918     ///
919     /// ```rust,compile_fail
920     /// #![deny(trivial_casts)]
921     /// let x: &u32 = &42;
922     /// let y = x as *const u32;
923     /// ```
924     ///
925     /// {{produces}}
926     ///
927     /// ### Explanation
928     ///
929     /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
930     /// subtype of `T`. This type of cast is usually unnecessary, as it can be
931     /// usually be inferred.
932     ///
933     /// This lint is "allow" by default because there are situations, such as
934     /// with FFI interfaces or complex type aliases, where it triggers
935     /// incorrectly, or in situations where it will be more difficult to
936     /// clearly express the intent. It may be possible that this will become a
937     /// warning in the future, possibly with [type ascription] providing a
938     /// convenient way to work around the current issues. See [RFC 401] for
939     /// historical context.
940     ///
941     /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
942     /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
943     pub TRIVIAL_CASTS,
944     Allow,
945     "detects trivial casts which could be removed"
946 }
947
948 declare_lint! {
949     /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
950     /// which could be removed.
951     ///
952     /// ### Example
953     ///
954     /// ```rust,compile_fail
955     /// #![deny(trivial_numeric_casts)]
956     /// let x = 42_i32 as i32;
957     /// ```
958     ///
959     /// {{produces}}
960     ///
961     /// ### Explanation
962     ///
963     /// A trivial numeric cast is a cast of a numeric type to the same numeric
964     /// type. This type of cast is usually unnecessary.
965     ///
966     /// This lint is "allow" by default because there are situations, such as
967     /// with FFI interfaces or complex type aliases, where it triggers
968     /// incorrectly, or in situations where it will be more difficult to
969     /// clearly express the intent. It may be possible that this will become a
970     /// warning in the future, possibly with [type ascription] providing a
971     /// convenient way to work around the current issues. See [RFC 401] for
972     /// historical context.
973     ///
974     /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
975     /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
976     pub TRIVIAL_NUMERIC_CASTS,
977     Allow,
978     "detects trivial casts of numeric types which could be removed"
979 }
980
981 declare_lint! {
982     /// The `private_in_public` lint detects private items in public
983     /// interfaces not caught by the old implementation.
984     ///
985     /// ### Example
986     ///
987     /// ```rust
988     /// # #![allow(unused)]
989     /// struct SemiPriv;
990     ///
991     /// mod m1 {
992     ///     struct Priv;
993     ///     impl super::SemiPriv {
994     ///         pub fn f(_: Priv) {}
995     ///     }
996     /// }
997     /// # fn main() {}
998     /// ```
999     ///
1000     /// {{produces}}
1001     ///
1002     /// ### Explanation
1003     ///
1004     /// The visibility rules are intended to prevent exposing private items in
1005     /// public interfaces. This is a [future-incompatible] lint to transition
1006     /// this to a hard error in the future. See [issue #34537] for more
1007     /// details.
1008     ///
1009     /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1010     /// [future-incompatible]: ../index.md#future-incompatible-lints
1011     pub PRIVATE_IN_PUBLIC,
1012     Warn,
1013     "detect private items in public interfaces not caught by the old implementation",
1014     @future_incompatible = FutureIncompatibleInfo {
1015         reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1016     };
1017 }
1018
1019 declare_lint! {
1020     /// The `exported_private_dependencies` lint detects private dependencies
1021     /// that are exposed in a public interface.
1022     ///
1023     /// ### Example
1024     ///
1025     /// ```rust,ignore (needs-dependency)
1026     /// pub fn foo() -> Option<some_private_dependency::Thing> {
1027     ///     None
1028     /// }
1029     /// ```
1030     ///
1031     /// This will produce:
1032     ///
1033     /// ```text
1034     /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1035     ///  --> src/lib.rs:3:1
1036     ///   |
1037     /// 3 | pub fn foo() -> Option<bar::Thing> {
1038     ///   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1039     ///   |
1040     ///   = note: `#[warn(exported_private_dependencies)]` on by default
1041     /// ```
1042     ///
1043     /// ### Explanation
1044     ///
1045     /// Dependencies can be marked as "private" to indicate that they are not
1046     /// exposed in the public interface of a crate. This can be used by Cargo
1047     /// to independently resolve those dependencies because it can assume it
1048     /// does not need to unify them with other packages using that same
1049     /// dependency. This lint is an indication of a violation of that
1050     /// contract.
1051     ///
1052     /// To fix this, avoid exposing the dependency in your public interface.
1053     /// Or, switch the dependency to a public dependency.
1054     ///
1055     /// Note that support for this is only available on the nightly channel.
1056     /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1057     ///
1058     /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1059     /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1060     pub EXPORTED_PRIVATE_DEPENDENCIES,
1061     Warn,
1062     "public interface leaks type from a private dependency"
1063 }
1064
1065 declare_lint! {
1066     /// The `pub_use_of_private_extern_crate` lint detects a specific
1067     /// situation of re-exporting a private `extern crate`.
1068     ///
1069     /// ### Example
1070     ///
1071     /// ```rust,compile_fail
1072     /// extern crate core;
1073     /// pub use core as reexported_core;
1074     /// ```
1075     ///
1076     /// {{produces}}
1077     ///
1078     /// ### Explanation
1079     ///
1080     /// A public `use` declaration should not be used to publicly re-export a
1081     /// private `extern crate`. `pub extern crate` should be used instead.
1082     ///
1083     /// This was historically allowed, but is not the intended behavior
1084     /// according to the visibility rules. This is a [future-incompatible]
1085     /// lint to transition this to a hard error in the future. See [issue
1086     /// #34537] for more details.
1087     ///
1088     /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1089     /// [future-incompatible]: ../index.md#future-incompatible-lints
1090     pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1091     Deny,
1092     "detect public re-exports of private extern crates",
1093     @future_incompatible = FutureIncompatibleInfo {
1094         reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1095     };
1096 }
1097
1098 declare_lint! {
1099     /// The `invalid_type_param_default` lint detects type parameter defaults
1100     /// erroneously allowed in an invalid location.
1101     ///
1102     /// ### Example
1103     ///
1104     /// ```rust,compile_fail
1105     /// fn foo<T=i32>(t: T) {}
1106     /// ```
1107     ///
1108     /// {{produces}}
1109     ///
1110     /// ### Explanation
1111     ///
1112     /// Default type parameters were only intended to be allowed in certain
1113     /// situations, but historically the compiler allowed them everywhere.
1114     /// This is a [future-incompatible] lint to transition this to a hard
1115     /// error in the future. See [issue #36887] for more details.
1116     ///
1117     /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1118     /// [future-incompatible]: ../index.md#future-incompatible-lints
1119     pub INVALID_TYPE_PARAM_DEFAULT,
1120     Deny,
1121     "type parameter default erroneously allowed in invalid location",
1122     @future_incompatible = FutureIncompatibleInfo {
1123         reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
1124     };
1125 }
1126
1127 declare_lint! {
1128     /// The `renamed_and_removed_lints` lint detects lints that have been
1129     /// renamed or removed.
1130     ///
1131     /// ### Example
1132     ///
1133     /// ```rust
1134     /// #![deny(raw_pointer_derive)]
1135     /// ```
1136     ///
1137     /// {{produces}}
1138     ///
1139     /// ### Explanation
1140     ///
1141     /// To fix this, either remove the lint or use the new name. This can help
1142     /// avoid confusion about lints that are no longer valid, and help
1143     /// maintain consistency for renamed lints.
1144     pub RENAMED_AND_REMOVED_LINTS,
1145     Warn,
1146     "lints that have been renamed or removed"
1147 }
1148
1149 declare_lint! {
1150     /// The `unaligned_references` lint detects unaligned references to fields
1151     /// of [packed] structs.
1152     ///
1153     /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1154     ///
1155     /// ### Example
1156     ///
1157     /// ```compile_fail
1158     /// #[repr(packed)]
1159     /// pub struct Foo {
1160     ///     field1: u64,
1161     ///     field2: u8,
1162     /// }
1163     ///
1164     /// fn main() {
1165     ///     unsafe {
1166     ///         let foo = Foo { field1: 0, field2: 0 };
1167     ///         let _ = &foo.field1;
1168     ///         println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
1169     ///     }
1170     /// }
1171     /// ```
1172     ///
1173     /// {{produces}}
1174     ///
1175     /// ### Explanation
1176     ///
1177     /// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
1178     /// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
1179     /// the code should do a copy of the data in the packed field or use raw pointers and unaligned
1180     /// accesses. See [issue #82523] for more information.
1181     ///
1182     /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1183     /// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
1184     pub UNALIGNED_REFERENCES,
1185     Deny,
1186     "detects unaligned references to fields of packed structs",
1187     @future_incompatible = FutureIncompatibleInfo {
1188         reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
1189         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1190     };
1191     report_in_external_macro
1192 }
1193
1194 declare_lint! {
1195     /// The `const_item_mutation` lint detects attempts to mutate a `const`
1196     /// item.
1197     ///
1198     /// ### Example
1199     ///
1200     /// ```rust
1201     /// const FOO: [i32; 1] = [0];
1202     ///
1203     /// fn main() {
1204     ///     FOO[0] = 1;
1205     ///     // This will print "[0]".
1206     ///     println!("{:?}", FOO);
1207     /// }
1208     /// ```
1209     ///
1210     /// {{produces}}
1211     ///
1212     /// ### Explanation
1213     ///
1214     /// Trying to directly mutate a `const` item is almost always a mistake.
1215     /// What is happening in the example above is that a temporary copy of the
1216     /// `const` is mutated, but the original `const` is not. Each time you
1217     /// refer to the `const` by name (such as `FOO` in the example above), a
1218     /// separate copy of the value is inlined at that location.
1219     ///
1220     /// This lint checks for writing directly to a field (`FOO.field =
1221     /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1222     /// reference to the const item (`&mut FOO`), including through an
1223     /// autoderef (`FOO.some_mut_self_method()`).
1224     ///
1225     /// There are various alternatives depending on what you are trying to
1226     /// accomplish:
1227     ///
1228     /// * First, always reconsider using mutable globals, as they can be
1229     ///   difficult to use correctly, and can make the code more difficult to
1230     ///   use or understand.
1231     /// * If you are trying to perform a one-time initialization of a global:
1232     ///     * If the value can be computed at compile-time, consider using
1233     ///       const-compatible values (see [Constant Evaluation]).
1234     ///     * For more complex single-initialization cases, consider using a
1235     ///       third-party crate, such as [`lazy_static`] or [`once_cell`].
1236     ///     * If you are using the [nightly channel], consider the new
1237     ///       [`lazy`] module in the standard library.
1238     /// * If you truly need a mutable global, consider using a [`static`],
1239     ///   which has a variety of options:
1240     ///   * Simple data types can be directly defined and mutated with an
1241     ///     [`atomic`] type.
1242     ///   * More complex types can be placed in a synchronization primitive
1243     ///     like a [`Mutex`], which can be initialized with one of the options
1244     ///     listed above.
1245     ///   * A [mutable `static`] is a low-level primitive, requiring unsafe.
1246     ///     Typically This should be avoided in preference of something
1247     ///     higher-level like one of the above.
1248     ///
1249     /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1250     /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1251     /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1252     /// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
1253     /// [`lazy_static`]: https://crates.io/crates/lazy_static
1254     /// [`once_cell`]: https://crates.io/crates/once_cell
1255     /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1256     /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1257     pub CONST_ITEM_MUTATION,
1258     Warn,
1259     "detects attempts to mutate a `const` item",
1260 }
1261
1262 declare_lint! {
1263     /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1264     /// patterns as a parameter in functions without a body.
1265     ///
1266     /// ### Example
1267     ///
1268     /// ```rust,compile_fail
1269     /// trait Trait {
1270     ///     fn foo(mut arg: u8);
1271     /// }
1272     /// ```
1273     ///
1274     /// {{produces}}
1275     ///
1276     /// ### Explanation
1277     ///
1278     /// To fix this, remove `mut` from the parameter in the trait definition;
1279     /// it can be used in the implementation. That is, the following is OK:
1280     ///
1281     /// ```rust
1282     /// trait Trait {
1283     ///     fn foo(arg: u8); // Removed `mut` here
1284     /// }
1285     ///
1286     /// impl Trait for i32 {
1287     ///     fn foo(mut arg: u8) { // `mut` here is OK
1288     ///
1289     ///     }
1290     /// }
1291     /// ```
1292     ///
1293     /// Trait definitions can define functions without a body to specify a
1294     /// function that implementors must define. The parameter names in the
1295     /// body-less functions are only allowed to be `_` or an [identifier] for
1296     /// documentation purposes (only the type is relevant). Previous versions
1297     /// of the compiler erroneously allowed [identifier patterns] with the
1298     /// `mut` keyword, but this was not intended to be allowed. This is a
1299     /// [future-incompatible] lint to transition this to a hard error in the
1300     /// future. See [issue #35203] for more details.
1301     ///
1302     /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1303     /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1304     /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1305     /// [future-incompatible]: ../index.md#future-incompatible-lints
1306     pub PATTERNS_IN_FNS_WITHOUT_BODY,
1307     Deny,
1308     "patterns in functions without body were erroneously allowed",
1309     @future_incompatible = FutureIncompatibleInfo {
1310         reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1311     };
1312 }
1313
1314 declare_lint! {
1315     /// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1316     /// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1317     /// followed by a fragment specifier (e.g. `:expr`).
1318     ///
1319     /// This warning can always be fixed by removing the unused pattern in the
1320     /// `macro_rules!` macro definition.
1321     ///
1322     /// ### Example
1323     ///
1324     /// ```rust,compile_fail
1325     /// macro_rules! foo {
1326     ///    () => {};
1327     ///    ($name) => { };
1328     /// }
1329     ///
1330     /// fn main() {
1331     ///    foo!();
1332     /// }
1333     /// ```
1334     ///
1335     /// {{produces}}
1336     ///
1337     /// ### Explanation
1338     ///
1339     /// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1340     ///
1341     /// ```rust
1342     /// macro_rules! foo {
1343     ///     () => {};
1344     /// }
1345     /// fn main() {
1346     ///     foo!();
1347     /// }
1348     /// ```
1349     pub MISSING_FRAGMENT_SPECIFIER,
1350     Deny,
1351     "detects missing fragment specifiers in unused `macro_rules!` patterns",
1352     @future_incompatible = FutureIncompatibleInfo {
1353         reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1354     };
1355 }
1356
1357 declare_lint! {
1358     /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1359     /// arguments in path segments with late bound lifetime parameters.
1360     ///
1361     /// ### Example
1362     ///
1363     /// ```rust
1364     /// struct S;
1365     ///
1366     /// impl S {
1367     ///     fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
1368     /// }
1369     ///
1370     /// fn main() {
1371     ///     S.late::<'static>(&0, &0);
1372     /// }
1373     /// ```
1374     ///
1375     /// {{produces}}
1376     ///
1377     /// ### Explanation
1378     ///
1379     /// It is not clear how to provide arguments for early-bound lifetime
1380     /// parameters if they are intermixed with late-bound parameters in the
1381     /// same list. For now, providing any explicit arguments will trigger this
1382     /// lint if late-bound parameters are present, so in the future a solution
1383     /// can be adopted without hitting backward compatibility issues. This is
1384     /// a [future-incompatible] lint to transition this to a hard error in the
1385     /// future. See [issue #42868] for more details, along with a description
1386     /// of the difference between early and late-bound parameters.
1387     ///
1388     /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1389     /// [future-incompatible]: ../index.md#future-incompatible-lints
1390     pub LATE_BOUND_LIFETIME_ARGUMENTS,
1391     Warn,
1392     "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1393     @future_incompatible = FutureIncompatibleInfo {
1394         reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1395     };
1396 }
1397
1398 declare_lint! {
1399     /// The `order_dependent_trait_objects` lint detects a trait coherency
1400     /// violation that would allow creating two trait impls for the same
1401     /// dynamic trait object involving marker traits.
1402     ///
1403     /// ### Example
1404     ///
1405     /// ```rust,compile_fail
1406     /// pub trait Trait {}
1407     ///
1408     /// impl Trait for dyn Send + Sync { }
1409     /// impl Trait for dyn Sync + Send { }
1410     /// ```
1411     ///
1412     /// {{produces}}
1413     ///
1414     /// ### Explanation
1415     ///
1416     /// A previous bug caused the compiler to interpret traits with different
1417     /// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1418     /// when they were intended to be treated the same. This allowed code to
1419     /// define separate trait implementations when there should be a coherence
1420     /// error. This is a [future-incompatible] lint to transition this to a
1421     /// hard error in the future. See [issue #56484] for more details.
1422     ///
1423     /// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1424     /// [future-incompatible]: ../index.md#future-incompatible-lints
1425     pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1426     Deny,
1427     "trait-object types were treated as different depending on marker-trait order",
1428     @future_incompatible = FutureIncompatibleInfo {
1429         reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1430     };
1431 }
1432
1433 declare_lint! {
1434     /// The `coherence_leak_check` lint detects conflicting implementations of
1435     /// a trait that are only distinguished by the old leak-check code.
1436     ///
1437     /// ### Example
1438     ///
1439     /// ```rust
1440     /// trait SomeTrait { }
1441     /// impl SomeTrait for for<'a> fn(&'a u8) { }
1442     /// impl<'a> SomeTrait for fn(&'a u8) { }
1443     /// ```
1444     ///
1445     /// {{produces}}
1446     ///
1447     /// ### Explanation
1448     ///
1449     /// In the past, the compiler would accept trait implementations for
1450     /// identical functions that differed only in where the lifetime binder
1451     /// appeared. Due to a change in the borrow checker implementation to fix
1452     /// several bugs, this is no longer allowed. However, since this affects
1453     /// existing code, this is a [future-incompatible] lint to transition this
1454     /// to a hard error in the future.
1455     ///
1456     /// Code relying on this pattern should introduce "[newtypes]",
1457     /// like `struct Foo(for<'a> fn(&'a u8))`.
1458     ///
1459     /// See [issue #56105] for more details.
1460     ///
1461     /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1462     /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1463     /// [future-incompatible]: ../index.md#future-incompatible-lints
1464     pub COHERENCE_LEAK_CHECK,
1465     Warn,
1466     "distinct impls distinguished only by the leak-check code",
1467     @future_incompatible = FutureIncompatibleInfo {
1468         reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1469     };
1470 }
1471
1472 declare_lint! {
1473     /// The `deprecated` lint detects use of deprecated items.
1474     ///
1475     /// ### Example
1476     ///
1477     /// ```rust
1478     /// #[deprecated]
1479     /// fn foo() {}
1480     ///
1481     /// fn bar() {
1482     ///     foo();
1483     /// }
1484     /// ```
1485     ///
1486     /// {{produces}}
1487     ///
1488     /// ### Explanation
1489     ///
1490     /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1491     /// indicate that they should no longer be used. Usually the attribute
1492     /// should include a note on what to use instead, or check the
1493     /// documentation.
1494     ///
1495     /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1496     pub DEPRECATED,
1497     Warn,
1498     "detects use of deprecated items",
1499     report_in_external_macro
1500 }
1501
1502 declare_lint! {
1503     /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1504     ///
1505     /// ### Example
1506     ///
1507     /// ```rust
1508     /// unsafe {}
1509     /// ```
1510     ///
1511     /// {{produces}}
1512     ///
1513     /// ### Explanation
1514     ///
1515     /// If nothing within the block requires `unsafe`, then remove the
1516     /// `unsafe` marker because it is not required and may cause confusion.
1517     pub UNUSED_UNSAFE,
1518     Warn,
1519     "unnecessary use of an `unsafe` block"
1520 }
1521
1522 declare_lint! {
1523     /// The `unused_mut` lint detects mut variables which don't need to be
1524     /// mutable.
1525     ///
1526     /// ### Example
1527     ///
1528     /// ```rust
1529     /// let mut x = 5;
1530     /// ```
1531     ///
1532     /// {{produces}}
1533     ///
1534     /// ### Explanation
1535     ///
1536     /// The preferred style is to only mark variables as `mut` if it is
1537     /// required.
1538     pub UNUSED_MUT,
1539     Warn,
1540     "detect mut variables which don't need to be mutable"
1541 }
1542
1543 declare_lint! {
1544     /// The `unconditional_recursion` lint detects functions that cannot
1545     /// return without calling themselves.
1546     ///
1547     /// ### Example
1548     ///
1549     /// ```rust
1550     /// fn foo() {
1551     ///     foo();
1552     /// }
1553     /// ```
1554     ///
1555     /// {{produces}}
1556     ///
1557     /// ### Explanation
1558     ///
1559     /// It is usually a mistake to have a recursive call that does not have
1560     /// some condition to cause it to terminate. If you really intend to have
1561     /// an infinite loop, using a `loop` expression is recommended.
1562     pub UNCONDITIONAL_RECURSION,
1563     Warn,
1564     "functions that cannot return without calling themselves"
1565 }
1566
1567 declare_lint! {
1568     /// The `single_use_lifetimes` lint detects lifetimes that are only used
1569     /// once.
1570     ///
1571     /// ### Example
1572     ///
1573     /// ```rust,compile_fail
1574     /// #![deny(single_use_lifetimes)]
1575     ///
1576     /// fn foo<'a>(x: &'a u32) {}
1577     /// ```
1578     ///
1579     /// {{produces}}
1580     ///
1581     /// ### Explanation
1582     ///
1583     /// Specifying an explicit lifetime like `'a` in a function or `impl`
1584     /// should only be used to link together two things. Otherwise, you should
1585     /// just use `'_` to indicate that the lifetime is not linked to anything,
1586     /// or elide the lifetime altogether if possible.
1587     ///
1588     /// This lint is "allow" by default because it was introduced at a time
1589     /// when `'_` and elided lifetimes were first being introduced, and this
1590     /// lint would be too noisy. Also, there are some known false positives
1591     /// that it produces. See [RFC 2115] for historical context, and [issue
1592     /// #44752] for more details.
1593     ///
1594     /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1595     /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1596     pub SINGLE_USE_LIFETIMES,
1597     Allow,
1598     "detects lifetime parameters that are only used once"
1599 }
1600
1601 declare_lint! {
1602     /// The `unused_lifetimes` lint detects lifetime parameters that are never
1603     /// used.
1604     ///
1605     /// ### Example
1606     ///
1607     /// ```rust,compile_fail
1608     /// #[deny(unused_lifetimes)]
1609     ///
1610     /// pub fn foo<'a>() {}
1611     /// ```
1612     ///
1613     /// {{produces}}
1614     ///
1615     /// ### Explanation
1616     ///
1617     /// Unused lifetime parameters may signal a mistake or unfinished code.
1618     /// Consider removing the parameter.
1619     pub UNUSED_LIFETIMES,
1620     Allow,
1621     "detects lifetime parameters that are never used"
1622 }
1623
1624 declare_lint! {
1625     /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1626     /// inference variable.
1627     ///
1628     /// ### Example
1629     ///
1630     /// ```rust,edition2015
1631     /// // edition 2015
1632     /// let data = std::ptr::null();
1633     /// let _ = &data as *const *const ();
1634     ///
1635     /// if data.is_null() {}
1636     /// ```
1637     ///
1638     /// {{produces}}
1639     ///
1640     /// ### Explanation
1641     ///
1642     /// This kind of inference was previously allowed, but with the future
1643     /// arrival of [arbitrary self types], this can introduce ambiguity. To
1644     /// resolve this, use an explicit type instead of relying on type
1645     /// inference.
1646     ///
1647     /// This is a [future-incompatible] lint to transition this to a hard
1648     /// error in the 2018 edition. See [issue #46906] for more details. This
1649     /// is currently a hard-error on the 2018 edition, and is "warn" by
1650     /// default in the 2015 edition.
1651     ///
1652     /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1653     /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1654     /// [future-incompatible]: ../index.md#future-incompatible-lints
1655     pub TYVAR_BEHIND_RAW_POINTER,
1656     Warn,
1657     "raw pointer to an inference variable",
1658     @future_incompatible = FutureIncompatibleInfo {
1659         reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1660         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1661     };
1662 }
1663
1664 declare_lint! {
1665     /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1666     /// lifetime parameters.
1667     ///
1668     /// ### Example
1669     ///
1670     /// ```rust,compile_fail
1671     /// #![deny(elided_lifetimes_in_paths)]
1672     /// struct Foo<'a> {
1673     ///     x: &'a u32
1674     /// }
1675     ///
1676     /// fn foo(x: &Foo) {
1677     /// }
1678     /// ```
1679     ///
1680     /// {{produces}}
1681     ///
1682     /// ### Explanation
1683     ///
1684     /// Elided lifetime parameters can make it difficult to see at a glance
1685     /// that borrowing is occurring. This lint ensures that lifetime
1686     /// parameters are always explicitly stated, even if it is the `'_`
1687     /// [placeholder lifetime].
1688     ///
1689     /// This lint is "allow" by default because it has some known issues, and
1690     /// may require a significant transition for old code.
1691     ///
1692     /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1693     pub ELIDED_LIFETIMES_IN_PATHS,
1694     Allow,
1695     "hidden lifetime parameters in types are deprecated",
1696     crate_level_only
1697 }
1698
1699 declare_lint! {
1700     /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1701     /// objects.
1702     ///
1703     /// ### Example
1704     ///
1705     /// ```rust,edition2018
1706     /// trait Trait { }
1707     ///
1708     /// fn takes_trait_object(_: Box<Trait>) {
1709     /// }
1710     /// ```
1711     ///
1712     /// {{produces}}
1713     ///
1714     /// ### Explanation
1715     ///
1716     /// Without the `dyn` indicator, it can be ambiguous or confusing when
1717     /// reading code as to whether or not you are looking at a trait object.
1718     /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1719     /// with [`impl Trait`].
1720     ///
1721     /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1722     pub BARE_TRAIT_OBJECTS,
1723     Warn,
1724     "suggest using `dyn Trait` for trait objects",
1725     @future_incompatible = FutureIncompatibleInfo {
1726         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
1727         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
1728     };
1729 }
1730
1731 declare_lint! {
1732     /// The `absolute_paths_not_starting_with_crate` lint detects fully
1733     /// qualified paths that start with a module name instead of `crate`,
1734     /// `self`, or an extern crate name
1735     ///
1736     /// ### Example
1737     ///
1738     /// ```rust,edition2015,compile_fail
1739     /// #![deny(absolute_paths_not_starting_with_crate)]
1740     ///
1741     /// mod foo {
1742     ///     pub fn bar() {}
1743     /// }
1744     ///
1745     /// fn main() {
1746     ///     ::foo::bar();
1747     /// }
1748     /// ```
1749     ///
1750     /// {{produces}}
1751     ///
1752     /// ### Explanation
1753     ///
1754     /// Rust [editions] allow the language to evolve without breaking
1755     /// backwards compatibility. This lint catches code that uses absolute
1756     /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1757     /// paths (those starting with `::`) refer to either the crate root or an
1758     /// external crate. In the 2018 edition it was changed so that they only
1759     /// refer to external crates. The path prefix `crate::` should be used
1760     /// instead to reference items from the crate root.
1761     ///
1762     /// If you switch the compiler from the 2015 to 2018 edition without
1763     /// updating the code, then it will fail to compile if the old style paths
1764     /// are used. You can manually change the paths to use the `crate::`
1765     /// prefix to transition to the 2018 edition.
1766     ///
1767     /// This lint solves the problem automatically. It is "allow" by default
1768     /// because the code is perfectly valid in the 2015 edition. The [`cargo
1769     /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1770     /// and automatically apply the suggested fix from the compiler. This
1771     /// provides a completely automated way to update old code to the 2018
1772     /// edition.
1773     ///
1774     /// [editions]: https://doc.rust-lang.org/edition-guide/
1775     /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1776     pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1777     Allow,
1778     "fully qualified paths that start with a module name \
1779      instead of `crate`, `self`, or an extern crate name",
1780      @future_incompatible = FutureIncompatibleInfo {
1781         reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1782         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1783      };
1784 }
1785
1786 declare_lint! {
1787     /// The `illegal_floating_point_literal_pattern` lint detects
1788     /// floating-point literals used in patterns.
1789     ///
1790     /// ### Example
1791     ///
1792     /// ```rust
1793     /// let x = 42.0;
1794     ///
1795     /// match x {
1796     ///     5.0 => {}
1797     ///     _ => {}
1798     /// }
1799     /// ```
1800     ///
1801     /// {{produces}}
1802     ///
1803     /// ### Explanation
1804     ///
1805     /// Previous versions of the compiler accepted floating-point literals in
1806     /// patterns, but it was later determined this was a mistake. The
1807     /// semantics of comparing floating-point values may not be clear in a
1808     /// pattern when contrasted with "structural equality". Typically you can
1809     /// work around this by using a [match guard], such as:
1810     ///
1811     /// ```rust
1812     /// # let x = 42.0;
1813     ///
1814     /// match x {
1815     ///     y if y == 5.0 => {}
1816     ///     _ => {}
1817     /// }
1818     /// ```
1819     ///
1820     /// This is a [future-incompatible] lint to transition this to a hard
1821     /// error in the future. See [issue #41620] for more details.
1822     ///
1823     /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1824     /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1825     /// [future-incompatible]: ../index.md#future-incompatible-lints
1826     pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1827     Warn,
1828     "floating-point literals cannot be used in patterns",
1829     @future_incompatible = FutureIncompatibleInfo {
1830         reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1831     };
1832 }
1833
1834 declare_lint! {
1835     /// The `unstable_name_collisions` lint detects that you have used a name
1836     /// that the standard library plans to add in the future.
1837     ///
1838     /// ### Example
1839     ///
1840     /// ```rust
1841     /// trait MyIterator : Iterator {
1842     ///     // is_sorted is an unstable method that already exists on the Iterator trait
1843     ///     fn is_sorted(self) -> bool where Self: Sized {true}
1844     /// }
1845     ///
1846     /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1847     ///
1848     /// let x = vec![1, 2, 3];
1849     /// let _ = x.iter().is_sorted();
1850     /// ```
1851     ///
1852     /// {{produces}}
1853     ///
1854     /// ### Explanation
1855     ///
1856     /// When new methods are added to traits in the standard library, they are
1857     /// usually added in an "unstable" form which is only available on the
1858     /// [nightly channel] with a [`feature` attribute]. If there is any
1859     /// pre-existing code which extends a trait to have a method with the same
1860     /// name, then the names will collide. In the future, when the method is
1861     /// stabilized, this will cause an error due to the ambiguity. This lint
1862     /// is an early-warning to let you know that there may be a collision in
1863     /// the future. This can be avoided by adding type annotations to
1864     /// disambiguate which trait method you intend to call, such as
1865     /// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
1866     ///
1867     /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1868     /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1869     pub UNSTABLE_NAME_COLLISIONS,
1870     Warn,
1871     "detects name collision with an existing but unstable method",
1872     @future_incompatible = FutureIncompatibleInfo {
1873         reason: FutureIncompatibilityReason::Custom(
1874             "once this associated item is added to the standard library, \
1875              the ambiguity may cause an error or change in behavior!"
1876         ),
1877         reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1878         // Note: this item represents future incompatibility of all unstable functions in the
1879         //       standard library, and thus should never be removed or changed to an error.
1880     };
1881 }
1882
1883 declare_lint! {
1884     /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1885     /// in [`if let`]s, [`while let`]s, and `if let` guards.
1886     ///
1887     /// ### Example
1888     ///
1889     /// ```rust
1890     /// if let _ = 123 {
1891     ///     println!("always runs!");
1892     /// }
1893     /// ```
1894     ///
1895     /// {{produces}}
1896     ///
1897     /// ### Explanation
1898     ///
1899     /// There usually isn't a reason to have an irrefutable pattern in an
1900     /// `if let` or `while let` statement, because the pattern will always match
1901     /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1902     /// when generating code with a macro, forbidding irrefutable patterns
1903     /// would require awkward workarounds in situations where the macro
1904     /// doesn't know if the pattern is refutable or not. This lint allows
1905     /// macros to accept this form, while alerting for a possibly incorrect
1906     /// use in normal code.
1907     ///
1908     /// See [RFC 2086] for more details.
1909     ///
1910     /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1911     /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1912     /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1913     /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1914     /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1915     /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1916     pub IRREFUTABLE_LET_PATTERNS,
1917     Warn,
1918     "detects irrefutable patterns in `if let` and `while let` statements"
1919 }
1920
1921 declare_lint! {
1922     /// The `unused_labels` lint detects [labels] that are never used.
1923     ///
1924     /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1925     ///
1926     /// ### Example
1927     ///
1928     /// ```rust,no_run
1929     /// 'unused_label: loop {}
1930     /// ```
1931     ///
1932     /// {{produces}}
1933     ///
1934     /// ### Explanation
1935     ///
1936     /// Unused labels may signal a mistake or unfinished code. To silence the
1937     /// warning for the individual label, prefix it with an underscore such as
1938     /// `'_my_label:`.
1939     pub UNUSED_LABELS,
1940     Warn,
1941     "detects labels that are never used"
1942 }
1943
1944 declare_lint! {
1945     /// The `where_clauses_object_safety` lint detects for [object safety] of
1946     /// [where clauses].
1947     ///
1948     /// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
1949     /// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
1950     ///
1951     /// ### Example
1952     ///
1953     /// ```rust,no_run
1954     /// trait Trait {}
1955     ///
1956     /// trait X { fn foo(&self) where Self: Trait; }
1957     ///
1958     /// impl X for () { fn foo(&self) {} }
1959     ///
1960     /// impl Trait for dyn X {}
1961     ///
1962     /// // Segfault at opt-level 0, SIGILL otherwise.
1963     /// pub fn main() { <dyn X as X>::foo(&()); }
1964     /// ```
1965     ///
1966     /// {{produces}}
1967     ///
1968     /// ### Explanation
1969     ///
1970     /// The compiler previously allowed these object-unsafe bounds, which was
1971     /// incorrect. This is a [future-incompatible] lint to transition this to
1972     /// a hard error in the future. See [issue #51443] for more details.
1973     ///
1974     /// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
1975     /// [future-incompatible]: ../index.md#future-incompatible-lints
1976     pub WHERE_CLAUSES_OBJECT_SAFETY,
1977     Warn,
1978     "checks the object safety of where clauses",
1979     @future_incompatible = FutureIncompatibleInfo {
1980         reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
1981     };
1982 }
1983
1984 declare_lint! {
1985     /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1986     /// derives using inaccessible names from parent modules.
1987     ///
1988     /// ### Example
1989     ///
1990     /// ```rust,ignore (proc-macro)
1991     /// // foo.rs
1992     /// #![crate_type = "proc-macro"]
1993     ///
1994     /// extern crate proc_macro;
1995     ///
1996     /// use proc_macro::*;
1997     ///
1998     /// #[proc_macro_derive(Foo)]
1999     /// pub fn foo1(a: TokenStream) -> TokenStream {
2000     ///     drop(a);
2001     ///     "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2002     /// }
2003     /// ```
2004     ///
2005     /// ```rust,ignore (needs-dependency)
2006     /// // bar.rs
2007     /// #[macro_use]
2008     /// extern crate foo;
2009     ///
2010     /// struct Something;
2011     ///
2012     /// #[derive(Foo)]
2013     /// struct Another;
2014     ///
2015     /// fn main() {}
2016     /// ```
2017     ///
2018     /// This will produce:
2019     ///
2020     /// ```text
2021     /// warning: cannot find type `Something` in this scope
2022     ///  --> src/main.rs:8:10
2023     ///   |
2024     /// 8 | #[derive(Foo)]
2025     ///   |          ^^^ names from parent modules are not accessible without an explicit import
2026     ///   |
2027     ///   = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2028     ///   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2029     ///   = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2030     /// ```
2031     ///
2032     /// ### Explanation
2033     ///
2034     /// If a proc-macro generates a module, the compiler unintentionally
2035     /// allowed items in that module to refer to items in the crate root
2036     /// without importing them. This is a [future-incompatible] lint to
2037     /// transition this to a hard error in the future. See [issue #50504] for
2038     /// more details.
2039     ///
2040     /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2041     /// [future-incompatible]: ../index.md#future-incompatible-lints
2042     pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2043     Deny,
2044     "detects proc macro derives using inaccessible names from parent modules",
2045     @future_incompatible = FutureIncompatibleInfo {
2046         reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
2047         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2048     };
2049 }
2050
2051 declare_lint! {
2052     /// The `macro_use_extern_crate` lint detects the use of the
2053     /// [`macro_use` attribute].
2054     ///
2055     /// ### Example
2056     ///
2057     /// ```rust,ignore (needs extern crate)
2058     /// #![deny(macro_use_extern_crate)]
2059     ///
2060     /// #[macro_use]
2061     /// extern crate serde_json;
2062     ///
2063     /// fn main() {
2064     ///     let _ = json!{{}};
2065     /// }
2066     /// ```
2067     ///
2068     /// This will produce:
2069     ///
2070     /// ```text
2071     /// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
2072     ///  --> src/main.rs:3:1
2073     ///   |
2074     /// 3 | #[macro_use]
2075     ///   | ^^^^^^^^^^^^
2076     ///   |
2077     /// note: the lint level is defined here
2078     ///  --> src/main.rs:1:9
2079     ///   |
2080     /// 1 | #![deny(macro_use_extern_crate)]
2081     ///   |         ^^^^^^^^^^^^^^^^^^^^^^
2082     /// ```
2083     ///
2084     /// ### Explanation
2085     ///
2086     /// The [`macro_use` attribute] on an [`extern crate`] item causes
2087     /// macros in that external crate to be brought into the prelude of the
2088     /// crate, making the macros in scope everywhere. As part of the efforts
2089     /// to simplify handling of dependencies in the [2018 edition], the use of
2090     /// `extern crate` is being phased out. To bring macros from extern crates
2091     /// into scope, it is recommended to use a [`use` import].
2092     ///
2093     /// This lint is "allow" by default because this is a stylistic choice
2094     /// that has not been settled, see [issue #52043] for more information.
2095     ///
2096     /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2097     /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2098     /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2099     pub MACRO_USE_EXTERN_CRATE,
2100     Allow,
2101     "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2102      via the module system"
2103 }
2104
2105 declare_lint! {
2106     /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2107     /// detects macro-expanded [`macro_export`] macros from the current crate
2108     /// that cannot be referred to by absolute paths.
2109     ///
2110     /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2111     ///
2112     /// ### Example
2113     ///
2114     /// ```rust,compile_fail
2115     /// macro_rules! define_exported {
2116     ///     () => {
2117     ///         #[macro_export]
2118     ///         macro_rules! exported {
2119     ///             () => {};
2120     ///         }
2121     ///     };
2122     /// }
2123     ///
2124     /// define_exported!();
2125     ///
2126     /// fn main() {
2127     ///     crate::exported!();
2128     /// }
2129     /// ```
2130     ///
2131     /// {{produces}}
2132     ///
2133     /// ### Explanation
2134     ///
2135     /// The intent is that all macros marked with the `#[macro_export]`
2136     /// attribute are made available in the root of the crate. However, when a
2137     /// `macro_rules!` definition is generated by another macro, the macro
2138     /// expansion is unable to uphold this rule. This is a
2139     /// [future-incompatible] lint to transition this to a hard error in the
2140     /// future. See [issue #53495] for more details.
2141     ///
2142     /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2143     /// [future-incompatible]: ../index.md#future-incompatible-lints
2144     pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2145     Deny,
2146     "macro-expanded `macro_export` macros from the current crate \
2147      cannot be referred to by absolute paths",
2148     @future_incompatible = FutureIncompatibleInfo {
2149         reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2150     };
2151     crate_level_only
2152 }
2153
2154 declare_lint! {
2155     /// The `explicit_outlives_requirements` lint detects unnecessary
2156     /// lifetime bounds that can be inferred.
2157     ///
2158     /// ### Example
2159     ///
2160     /// ```rust,compile_fail
2161     /// # #![allow(unused)]
2162     /// #![deny(explicit_outlives_requirements)]
2163     ///
2164     /// struct SharedRef<'a, T>
2165     /// where
2166     ///     T: 'a,
2167     /// {
2168     ///     data: &'a T,
2169     /// }
2170     /// ```
2171     ///
2172     /// {{produces}}
2173     ///
2174     /// ### Explanation
2175     ///
2176     /// If a `struct` contains a reference, such as `&'a T`, the compiler
2177     /// requires that `T` outlives the lifetime `'a`. This historically
2178     /// required writing an explicit lifetime bound to indicate this
2179     /// requirement. However, this can be overly explicit, causing clutter and
2180     /// unnecessary complexity. The language was changed to automatically
2181     /// infer the bound if it is not specified. Specifically, if the struct
2182     /// contains a reference, directly or indirectly, to `T` with lifetime
2183     /// `'x`, then it will infer that `T: 'x` is a requirement.
2184     ///
2185     /// This lint is "allow" by default because it can be noisy for existing
2186     /// code that already had these requirements. This is a stylistic choice,
2187     /// as it is still valid to explicitly state the bound. It also has some
2188     /// false positives that can cause confusion.
2189     ///
2190     /// See [RFC 2093] for more details.
2191     ///
2192     /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2193     pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2194     Allow,
2195     "outlives requirements can be inferred"
2196 }
2197
2198 declare_lint! {
2199     /// The `indirect_structural_match` lint detects a `const` in a pattern
2200     /// that manually implements [`PartialEq`] and [`Eq`].
2201     ///
2202     /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2203     /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2204     ///
2205     /// ### Example
2206     ///
2207     /// ```rust,compile_fail
2208     /// #![deny(indirect_structural_match)]
2209     ///
2210     /// struct NoDerive(i32);
2211     /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2212     /// impl Eq for NoDerive { }
2213     /// #[derive(PartialEq, Eq)]
2214     /// struct WrapParam<T>(T);
2215     /// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
2216     /// fn main() {
2217     ///     match WRAP_INDIRECT_PARAM {
2218     ///         WRAP_INDIRECT_PARAM => { }
2219     ///         _ => { }
2220     ///     }
2221     /// }
2222     /// ```
2223     ///
2224     /// {{produces}}
2225     ///
2226     /// ### Explanation
2227     ///
2228     /// The compiler unintentionally accepted this form in the past. This is a
2229     /// [future-incompatible] lint to transition this to a hard error in the
2230     /// future. See [issue #62411] for a complete description of the problem,
2231     /// and some possible solutions.
2232     ///
2233     /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2234     /// [future-incompatible]: ../index.md#future-incompatible-lints
2235     pub INDIRECT_STRUCTURAL_MATCH,
2236     Warn,
2237     "constant used in pattern contains value of non-structural-match type in a field or a variant",
2238     @future_incompatible = FutureIncompatibleInfo {
2239         reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2240     };
2241 }
2242
2243 declare_lint! {
2244     /// The `deprecated_in_future` lint is internal to rustc and should not be
2245     /// used by user code.
2246     ///
2247     /// This lint is only enabled in the standard library. It works with the
2248     /// use of `#[deprecated]` with a `since` field of a version in the future.
2249     /// This allows something to be marked as deprecated in a future version,
2250     /// and then this lint will ensure that the item is no longer used in the
2251     /// standard library. See the [stability documentation] for more details.
2252     ///
2253     /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2254     pub DEPRECATED_IN_FUTURE,
2255     Allow,
2256     "detects use of items that will be deprecated in a future version",
2257     report_in_external_macro
2258 }
2259
2260 declare_lint! {
2261     /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2262     /// cannot be relied upon across compiler versions and optimization levels.
2263     ///
2264     /// ### Example
2265     ///
2266     /// ```rust,compile_fail
2267     /// #![deny(pointer_structural_match)]
2268     /// fn foo(a: usize, b: usize) -> usize { a + b }
2269     /// const FOO: fn(usize, usize) -> usize = foo;
2270     /// fn main() {
2271     ///     match FOO {
2272     ///         FOO => {},
2273     ///         _ => {},
2274     ///     }
2275     /// }
2276     /// ```
2277     ///
2278     /// {{produces}}
2279     ///
2280     /// ### Explanation
2281     ///
2282     /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2283     /// While these work in many cases as expected by users, it is possible that due to
2284     /// optimizations pointers are "not equal to themselves" or pointers to different functions
2285     /// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2286     /// functions if their bodies are the same, thus also making pointers to these functions point
2287     /// to the same location. Additionally functions may get duplicated if they are instantiated
2288     /// in different crates and not deduplicated again via LTO.
2289     pub POINTER_STRUCTURAL_MATCH,
2290     Allow,
2291     "pointers are not structural-match",
2292     @future_incompatible = FutureIncompatibleInfo {
2293         reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2294     };
2295 }
2296
2297 declare_lint! {
2298     /// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2299     /// whose type is not structural-match and whose initializer body actually uses values
2300     /// that are not structural-match. So `Option<NotStructuralMatch>` is ok if the constant
2301     /// is just `None`.
2302     ///
2303     /// ### Example
2304     ///
2305     /// ```rust,compile_fail
2306     /// #![deny(nontrivial_structural_match)]
2307     ///
2308     /// #[derive(Copy, Clone, Debug)]
2309     /// struct NoDerive(u32);
2310     /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2311     /// impl Eq for NoDerive { }
2312     /// fn main() {
2313     ///     const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2314     ///     match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2315     /// }
2316     /// ```
2317     ///
2318     /// {{produces}}
2319     ///
2320     /// ### Explanation
2321     ///
2322     /// Previous versions of Rust accepted constants in patterns, even if those constants' types
2323     /// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2324     /// `PartialEq`, which can report that two constants are not equal even if they are
2325     /// bit-equivalent.
2326     pub NONTRIVIAL_STRUCTURAL_MATCH,
2327     Warn,
2328     "constant used in pattern of non-structural-match type and the constant's initializer \
2329     expression contains values of non-structural-match types",
2330     @future_incompatible = FutureIncompatibleInfo {
2331         reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2332     };
2333 }
2334
2335 declare_lint! {
2336     /// The `ambiguous_associated_items` lint detects ambiguity between
2337     /// [associated items] and [enum variants].
2338     ///
2339     /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2340     /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2341     ///
2342     /// ### Example
2343     ///
2344     /// ```rust,compile_fail
2345     /// enum E {
2346     ///     V
2347     /// }
2348     ///
2349     /// trait Tr {
2350     ///     type V;
2351     ///     fn foo() -> Self::V;
2352     /// }
2353     ///
2354     /// impl Tr for E {
2355     ///     type V = u8;
2356     ///     // `Self::V` is ambiguous because it may refer to the associated type or
2357     ///     // the enum variant.
2358     ///     fn foo() -> Self::V { 0 }
2359     /// }
2360     /// ```
2361     ///
2362     /// {{produces}}
2363     ///
2364     /// ### Explanation
2365     ///
2366     /// Previous versions of Rust did not allow accessing enum variants
2367     /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2368     /// introduced some situations where it can be ambiguous what a type
2369     /// was referring to.
2370     ///
2371     /// To fix this ambiguity, you should use a [qualified path] to explicitly
2372     /// state which type to use. For example, in the above example the
2373     /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2374     /// specifically refer to the associated type.
2375     ///
2376     /// This is a [future-incompatible] lint to transition this to a hard
2377     /// error in the future. See [issue #57644] for more details.
2378     ///
2379     /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2380     /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2381     /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2382     /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2383     /// [future-incompatible]: ../index.md#future-incompatible-lints
2384     pub AMBIGUOUS_ASSOCIATED_ITEMS,
2385     Deny,
2386     "ambiguous associated items",
2387     @future_incompatible = FutureIncompatibleInfo {
2388         reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2389     };
2390 }
2391
2392 declare_lint! {
2393     /// The `soft_unstable` lint detects unstable features that were
2394     /// unintentionally allowed on stable.
2395     ///
2396     /// ### Example
2397     ///
2398     /// ```rust,compile_fail
2399     /// #[cfg(test)]
2400     /// extern crate test;
2401     ///
2402     /// #[bench]
2403     /// fn name(b: &mut test::Bencher) {
2404     ///     b.iter(|| 123)
2405     /// }
2406     /// ```
2407     ///
2408     /// {{produces}}
2409     ///
2410     /// ### Explanation
2411     ///
2412     /// The [`bench` attribute] was accidentally allowed to be specified on
2413     /// the [stable release channel]. Turning this to a hard error would have
2414     /// broken some projects. This lint allows those projects to continue to
2415     /// build correctly when [`--cap-lints`] is used, but otherwise signal an
2416     /// error that `#[bench]` should not be used on the stable channel. This
2417     /// is a [future-incompatible] lint to transition this to a hard error in
2418     /// the future. See [issue #64266] for more details.
2419     ///
2420     /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2421     /// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
2422     /// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2423     /// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
2424     /// [future-incompatible]: ../index.md#future-incompatible-lints
2425     pub SOFT_UNSTABLE,
2426     Deny,
2427     "a feature gate that doesn't break dependent crates",
2428     @future_incompatible = FutureIncompatibleInfo {
2429         reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2430     };
2431 }
2432
2433 declare_lint! {
2434     /// The `inline_no_sanitize` lint detects incompatible use of
2435     /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2436     ///
2437     /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2438     /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2439     ///
2440     /// ### Example
2441     ///
2442     /// ```rust
2443     /// #![feature(no_sanitize)]
2444     ///
2445     /// #[inline(always)]
2446     /// #[no_sanitize(address)]
2447     /// fn x() {}
2448     ///
2449     /// fn main() {
2450     ///     x()
2451     /// }
2452     /// ```
2453     ///
2454     /// {{produces}}
2455     ///
2456     /// ### Explanation
2457     ///
2458     /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2459     /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2460     /// Consider temporarily removing `inline` attribute.
2461     pub INLINE_NO_SANITIZE,
2462     Warn,
2463     "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2464 }
2465
2466 declare_lint! {
2467     /// The `asm_sub_register` lint detects using only a subset of a register
2468     /// for inline asm inputs.
2469     ///
2470     /// ### Example
2471     ///
2472     /// ```rust,ignore (fails on non-x86_64)
2473     /// #[cfg(target_arch="x86_64")]
2474     /// use std::arch::asm;
2475     ///
2476     /// fn main() {
2477     ///     #[cfg(target_arch="x86_64")]
2478     ///     unsafe {
2479     ///         asm!("mov {0}, {0}", in(reg) 0i16);
2480     ///     }
2481     /// }
2482     /// ```
2483     ///
2484     /// This will produce:
2485     ///
2486     /// ```text
2487     /// warning: formatting may not be suitable for sub-register argument
2488     ///  --> src/main.rs:7:19
2489     ///   |
2490     /// 7 |         asm!("mov {0}, {0}", in(reg) 0i16);
2491     ///   |                   ^^^  ^^^           ---- for this argument
2492     ///   |
2493     ///   = note: `#[warn(asm_sub_register)]` on by default
2494     ///   = help: use the `x` modifier to have the register formatted as `ax`
2495     ///   = help: or use the `r` modifier to keep the default formatting of `rax`
2496     /// ```
2497     ///
2498     /// ### Explanation
2499     ///
2500     /// Registers on some architectures can use different names to refer to a
2501     /// subset of the register. By default, the compiler will use the name for
2502     /// the full register size. To explicitly use a subset of the register,
2503     /// you can override the default by using a modifier on the template
2504     /// string operand to specify when subregister to use. This lint is issued
2505     /// if you pass in a value with a smaller data type than the default
2506     /// register size, to alert you of possibly using the incorrect width. To
2507     /// fix this, add the suggested modifier to the template, or cast the
2508     /// value to the correct size.
2509     ///
2510     /// See [register template modifiers] in the reference for more details.
2511     ///
2512     /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2513     pub ASM_SUB_REGISTER,
2514     Warn,
2515     "using only a subset of a register for inline asm inputs",
2516 }
2517
2518 declare_lint! {
2519     /// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2520     /// `.att_syntax` directives.
2521     ///
2522     /// ### Example
2523     ///
2524     /// ```rust,ignore (fails on non-x86_64)
2525     /// #[cfg(target_arch="x86_64")]
2526     /// use std::arch::asm;
2527     ///
2528     /// fn main() {
2529     ///     #[cfg(target_arch="x86_64")]
2530     ///     unsafe {
2531     ///         asm!(
2532     ///             ".att_syntax",
2533     ///             "movq %{0}, %{0}", in(reg) 0usize
2534     ///         );
2535     ///     }
2536     /// }
2537     /// ```
2538     ///
2539     /// This will produce:
2540     ///
2541     /// ```text
2542     /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2543     ///  --> src/main.rs:8:14
2544     ///   |
2545     /// 8 |             ".att_syntax",
2546     ///   |              ^^^^^^^^^^^
2547     ///   |
2548     ///   = note: `#[warn(bad_asm_style)]` on by default
2549     /// ```
2550     ///
2551     /// ### Explanation
2552     ///
2553     /// On x86, `asm!` uses the intel assembly syntax by default. While this
2554     /// can be switched using assembler directives like `.att_syntax`, using the
2555     /// `att_syntax` option is recommended instead because it will also properly
2556     /// prefix register placeholders with `%` as required by AT&T syntax.
2557     pub BAD_ASM_STYLE,
2558     Warn,
2559     "incorrect use of inline assembly",
2560 }
2561
2562 declare_lint! {
2563     /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2564     /// functions without an explicit unsafe block.
2565     ///
2566     /// ### Example
2567     ///
2568     /// ```rust,compile_fail
2569     /// #![deny(unsafe_op_in_unsafe_fn)]
2570     ///
2571     /// unsafe fn foo() {}
2572     ///
2573     /// unsafe fn bar() {
2574     ///     foo();
2575     /// }
2576     ///
2577     /// fn main() {}
2578     /// ```
2579     ///
2580     /// {{produces}}
2581     ///
2582     /// ### Explanation
2583     ///
2584     /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2585     /// body. However, this can increase the surface area of code that needs
2586     /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2587     /// convenient way to make it clear exactly which parts of the code are
2588     /// performing unsafe operations. In the future, it is desired to change
2589     /// it so that unsafe operations cannot be performed in an `unsafe fn`
2590     /// without an `unsafe` block.
2591     ///
2592     /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2593     ///
2594     /// This lint is "allow" by default since this will affect a large amount
2595     /// of existing code, and the exact plan for increasing the severity is
2596     /// still being considered. See [RFC #2585] and [issue #71668] for more
2597     /// details.
2598     ///
2599     /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2600     /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2601     /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2602     /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2603     /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2604     pub UNSAFE_OP_IN_UNSAFE_FN,
2605     Allow,
2606     "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2607 }
2608
2609 declare_lint! {
2610     /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2611     /// `enum` that implements [`Drop`].
2612     ///
2613     /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2614     ///
2615     /// ### Example
2616     ///
2617     /// ```compile_fail
2618     /// # #![allow(unused)]
2619     /// enum E {
2620     ///     A,
2621     /// }
2622     ///
2623     /// impl Drop for E {
2624     ///     fn drop(&mut self) {
2625     ///         println!("Drop");
2626     ///     }
2627     /// }
2628     ///
2629     /// fn main() {
2630     ///     let e = E::A;
2631     ///     let i = e as u32;
2632     /// }
2633     /// ```
2634     ///
2635     /// {{produces}}
2636     ///
2637     /// ### Explanation
2638     ///
2639     /// Casting a field-less `enum` that does not implement [`Copy`] to an
2640     /// integer moves the value without calling `drop`. This can result in
2641     /// surprising behavior if it was expected that `drop` should be called.
2642     /// Calling `drop` automatically would be inconsistent with other move
2643     /// operations. Since neither behavior is clear or consistent, it was
2644     /// decided that a cast of this nature will no longer be allowed.
2645     ///
2646     /// This is a [future-incompatible] lint to transition this to a hard error
2647     /// in the future. See [issue #73333] for more details.
2648     ///
2649     /// [future-incompatible]: ../index.md#future-incompatible-lints
2650     /// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
2651     /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
2652     pub CENUM_IMPL_DROP_CAST,
2653     Deny,
2654     "a C-like enum implementing Drop is cast",
2655     @future_incompatible = FutureIncompatibleInfo {
2656         reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
2657         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2658     };
2659 }
2660
2661 declare_lint! {
2662     /// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
2663     /// and a pointer.
2664     ///
2665     /// ### Example
2666     ///
2667     /// ```rust
2668     /// #![feature(strict_provenance)]
2669     /// #![warn(fuzzy_provenance_casts)]
2670     ///
2671     /// fn main() {
2672     ///     let _dangling = 16_usize as *const u8;
2673     /// }
2674     /// ```
2675     ///
2676     /// {{produces}}
2677     ///
2678     /// ### Explanation
2679     ///
2680     /// This lint is part of the strict provenance effort, see [issue #95228].
2681     /// Casting an integer to a pointer is considered bad style, as a pointer
2682     /// contains, besides the *address* also a *provenance*, indicating what
2683     /// memory the pointer is allowed to read/write. Casting an integer, which
2684     /// doesn't have provenance, to a pointer requires the compiler to assign
2685     /// (guess) provenance. The compiler assigns "all exposed valid" (see the
2686     /// docs of [`ptr::from_exposed_addr`] for more information about this
2687     /// "exposing"). This penalizes the optimiser and is not well suited for
2688     /// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
2689     /// platforms).
2690     ///
2691     /// It is much better to use [`ptr::with_addr`] instead to specify the
2692     /// provenance you want. If using this function is not possible because the
2693     /// code relies on exposed provenance then there is as an escape hatch
2694     /// [`ptr::from_exposed_addr`].
2695     ///
2696     /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2697     /// [`ptr::with_addr`]: https://doc.rust-lang.org/core/ptr/fn.with_addr
2698     /// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr
2699     pub FUZZY_PROVENANCE_CASTS,
2700     Allow,
2701     "a fuzzy integer to pointer cast is used",
2702     @feature_gate = sym::strict_provenance;
2703 }
2704
2705 declare_lint! {
2706     /// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
2707     /// and an integer.
2708     ///
2709     /// ### Example
2710     ///
2711     /// ```rust
2712     /// #![feature(strict_provenance)]
2713     /// #![warn(lossy_provenance_casts)]
2714     ///
2715     /// fn main() {
2716     ///     let x: u8 = 37;
2717     ///     let _addr: usize = &x as *const u8 as usize;
2718     /// }
2719     /// ```
2720     ///
2721     /// {{produces}}
2722     ///
2723     /// ### Explanation
2724     ///
2725     /// This lint is part of the strict provenance effort, see [issue #95228].
2726     /// Casting a pointer to an integer is a lossy operation, because beyond
2727     /// just an *address* a pointer may be associated with a particular
2728     /// *provenance*. This information is used by the optimiser and for dynamic
2729     /// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
2730     ///
2731     /// Since this cast is lossy, it is considered good style to use the
2732     /// [`ptr::addr`] method instead, which has a similar effect, but doesn't
2733     /// "expose" the pointer provenance. This improves optimisation potential.
2734     /// See the docs of [`ptr::addr`] and [`ptr::expose_addr`] for more information
2735     /// about exposing pointer provenance.
2736     ///
2737     /// If your code can't comply with strict provenance and needs to expose
2738     /// the provenance, then there is [`ptr::expose_addr`] as an escape hatch,
2739     /// which preserves the behaviour of `as usize` casts while being explicit
2740     /// about the semantics.
2741     ///
2742     /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2743     /// [`ptr::addr`]: https://doc.rust-lang.org/core/ptr/fn.addr
2744     /// [`ptr::expose_addr`]: https://doc.rust-lang.org/core/ptr/fn.expose_addr
2745     pub LOSSY_PROVENANCE_CASTS,
2746     Allow,
2747     "a lossy pointer to integer cast is used",
2748     @feature_gate = sym::strict_provenance;
2749 }
2750
2751 declare_lint! {
2752     /// The `const_evaluatable_unchecked` lint detects a generic constant used
2753     /// in a type.
2754     ///
2755     /// ### Example
2756     ///
2757     /// ```rust
2758     /// const fn foo<T>() -> usize {
2759     ///     if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2760     ///         4
2761     ///     } else {
2762     ///         8
2763     ///     }
2764     /// }
2765     ///
2766     /// fn test<T>() {
2767     ///     let _ = [0; foo::<T>()];
2768     /// }
2769     /// ```
2770     ///
2771     /// {{produces}}
2772     ///
2773     /// ### Explanation
2774     ///
2775     /// In the 1.43 release, some uses of generic parameters in array repeat
2776     /// expressions were accidentally allowed. This is a [future-incompatible]
2777     /// lint to transition this to a hard error in the future. See [issue
2778     /// #76200] for a more detailed description and possible fixes.
2779     ///
2780     /// [future-incompatible]: ../index.md#future-incompatible-lints
2781     /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2782     pub CONST_EVALUATABLE_UNCHECKED,
2783     Warn,
2784     "detects a generic constant is used in a type without a emitting a warning",
2785     @future_incompatible = FutureIncompatibleInfo {
2786         reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2787     };
2788 }
2789
2790 declare_lint! {
2791     /// The `function_item_references` lint detects function references that are
2792     /// formatted with [`fmt::Pointer`] or transmuted.
2793     ///
2794     /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2795     ///
2796     /// ### Example
2797     ///
2798     /// ```rust
2799     /// fn foo() { }
2800     ///
2801     /// fn main() {
2802     ///     println!("{:p}", &foo);
2803     /// }
2804     /// ```
2805     ///
2806     /// {{produces}}
2807     ///
2808     /// ### Explanation
2809     ///
2810     /// Taking a reference to a function may be mistaken as a way to obtain a
2811     /// pointer to that function. This can give unexpected results when
2812     /// formatting the reference as a pointer or transmuting it. This lint is
2813     /// issued when function references are formatted as pointers, passed as
2814     /// arguments bound by [`fmt::Pointer`] or transmuted.
2815     pub FUNCTION_ITEM_REFERENCES,
2816     Warn,
2817     "suggest casting to a function pointer when attempting to take references to function items",
2818 }
2819
2820 declare_lint! {
2821     /// The `uninhabited_static` lint detects uninhabited statics.
2822     ///
2823     /// ### Example
2824     ///
2825     /// ```rust
2826     /// enum Void {}
2827     /// extern {
2828     ///     static EXTERN: Void;
2829     /// }
2830     /// ```
2831     ///
2832     /// {{produces}}
2833     ///
2834     /// ### Explanation
2835     ///
2836     /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2837     /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2838     /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2839     /// statics). This was accidentally allowed, but is being phased out.
2840     pub UNINHABITED_STATIC,
2841     Warn,
2842     "uninhabited static",
2843     @future_incompatible = FutureIncompatibleInfo {
2844         reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2845     };
2846 }
2847
2848 declare_lint! {
2849     /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2850     ///
2851     /// ### Example
2852     ///
2853     /// ```rust,compile_fail
2854     /// struct X;
2855     ///
2856     /// #[deprecated = "message"]
2857     /// impl Default for X {
2858     ///     fn default() -> Self {
2859     ///         X
2860     ///     }
2861     /// }
2862     /// ```
2863     ///
2864     /// {{produces}}
2865     ///
2866     /// ### Explanation
2867     ///
2868     /// Deprecation attributes have no effect on trait implementations.
2869     pub USELESS_DEPRECATED,
2870     Deny,
2871     "detects deprecation attributes with no effect",
2872 }
2873
2874 declare_lint! {
2875     /// The `undefined_naked_function_abi` lint detects naked function definitions that
2876     /// either do not specify an ABI or specify the Rust ABI.
2877     ///
2878     /// ### Example
2879     ///
2880     /// ```rust
2881     /// #![feature(naked_functions)]
2882     ///
2883     /// use std::arch::asm;
2884     ///
2885     /// #[naked]
2886     /// pub fn default_abi() -> u32 {
2887     ///     unsafe { asm!("", options(noreturn)); }
2888     /// }
2889     ///
2890     /// #[naked]
2891     /// pub extern "Rust" fn rust_abi() -> u32 {
2892     ///     unsafe { asm!("", options(noreturn)); }
2893     /// }
2894     /// ```
2895     ///
2896     /// {{produces}}
2897     ///
2898     /// ### Explanation
2899     ///
2900     /// The Rust ABI is currently undefined. Therefore, naked functions should
2901     /// specify a non-Rust ABI.
2902     pub UNDEFINED_NAKED_FUNCTION_ABI,
2903     Warn,
2904     "undefined naked function ABI"
2905 }
2906
2907 declare_lint! {
2908     /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2909     ///
2910     /// ### Example
2911     ///
2912     /// ```rust,compile_fail
2913     /// #![feature(staged_api)]
2914     ///
2915     /// #[derive(Clone)]
2916     /// #[stable(feature = "x", since = "1")]
2917     /// struct S {}
2918     ///
2919     /// #[unstable(feature = "y", issue = "none")]
2920     /// impl Copy for S {}
2921     /// ```
2922     ///
2923     /// {{produces}}
2924     ///
2925     /// ### Explanation
2926     ///
2927     /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2928     /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2929     pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2930     Deny,
2931     "detects `#[unstable]` on stable trait implementations for stable types"
2932 }
2933
2934 declare_lint! {
2935     /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2936     /// in macro bodies when the macro is invoked in expression position.
2937     /// This was previous accepted, but is being phased out.
2938     ///
2939     /// ### Example
2940     ///
2941     /// ```rust,compile_fail
2942     /// #![deny(semicolon_in_expressions_from_macros)]
2943     /// macro_rules! foo {
2944     ///     () => { true; }
2945     /// }
2946     ///
2947     /// fn main() {
2948     ///     let val = match true {
2949     ///         true => false,
2950     ///         _ => foo!()
2951     ///     };
2952     /// }
2953     /// ```
2954     ///
2955     /// {{produces}}
2956     ///
2957     /// ### Explanation
2958     ///
2959     /// Previous, Rust ignored trailing semicolon in a macro
2960     /// body when a macro was invoked in expression position.
2961     /// However, this makes the treatment of semicolons in the language
2962     /// inconsistent, and could lead to unexpected runtime behavior
2963     /// in some circumstances (e.g. if the macro author expects
2964     /// a value to be dropped).
2965     ///
2966     /// This is a [future-incompatible] lint to transition this
2967     /// to a hard error in the future. See [issue #79813] for more details.
2968     ///
2969     /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2970     /// [future-incompatible]: ../index.md#future-incompatible-lints
2971     pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2972     Warn,
2973     "trailing semicolon in macro body used as expression",
2974     @future_incompatible = FutureIncompatibleInfo {
2975         reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
2976     };
2977 }
2978
2979 declare_lint! {
2980     /// The `legacy_derive_helpers` lint detects derive helper attributes
2981     /// that are used before they are introduced.
2982     ///
2983     /// ### Example
2984     ///
2985     /// ```rust,ignore (needs extern crate)
2986     /// #[serde(rename_all = "camelCase")]
2987     /// #[derive(Deserialize)]
2988     /// struct S { /* fields */ }
2989     /// ```
2990     ///
2991     /// produces:
2992     ///
2993     /// ```text
2994     /// warning: derive helper attribute is used before it is introduced
2995     ///   --> $DIR/legacy-derive-helpers.rs:1:3
2996     ///    |
2997     ///  1 | #[serde(rename_all = "camelCase")]
2998     ///    |   ^^^^^
2999     /// ...
3000     ///  2 | #[derive(Deserialize)]
3001     ///    |          ----------- the attribute is introduced here
3002     /// ```
3003     ///
3004     /// ### Explanation
3005     ///
3006     /// Attributes like this work for historical reasons, but attribute expansion works in
3007     /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
3008     /// into the future" at not yet expanded part of the item , but such attempts are not always
3009     /// reliable.
3010     ///
3011     /// To fix the warning place the helper attribute after its corresponding derive.
3012     /// ```rust,ignore (needs extern crate)
3013     /// #[derive(Deserialize)]
3014     /// #[serde(rename_all = "camelCase")]
3015     /// struct S { /* fields */ }
3016     /// ```
3017     pub LEGACY_DERIVE_HELPERS,
3018     Warn,
3019     "detects derive helper attributes that are used before they are introduced",
3020     @future_incompatible = FutureIncompatibleInfo {
3021         reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
3022     };
3023 }
3024
3025 declare_lint! {
3026     /// The `large_assignments` lint detects when objects of large
3027     /// types are being moved around.
3028     ///
3029     /// ### Example
3030     ///
3031     /// ```rust,ignore (can crash on some platforms)
3032     /// let x = [0; 50000];
3033     /// let y = x;
3034     /// ```
3035     ///
3036     /// produces:
3037     ///
3038     /// ```text
3039     /// warning: moving a large value
3040     ///   --> $DIR/move-large.rs:1:3
3041     ///   let y = x;
3042     ///           - Copied large value here
3043     /// ```
3044     ///
3045     /// ### Explanation
3046     ///
3047     /// When using a large type in a plain assignment or in a function
3048     /// argument, idiomatic code can be inefficient.
3049     /// Ideally appropriate optimizations would resolve this, but such
3050     /// optimizations are only done in a best-effort manner.
3051     /// This lint will trigger on all sites of large moves and thus allow the
3052     /// user to resolve them in code.
3053     pub LARGE_ASSIGNMENTS,
3054     Warn,
3055     "detects large moves or copies",
3056 }
3057
3058 declare_lint! {
3059     /// The `deprecated_cfg_attr_crate_type_name` lint detects uses of the
3060     /// `#![cfg_attr(..., crate_type = "...")]` and
3061     /// `#![cfg_attr(..., crate_name = "...")]` attributes to conditionally
3062     /// specify the crate type and name in the source code.
3063     ///
3064     /// ### Example
3065     ///
3066     /// ```rust,compile_fail
3067     /// #![cfg_attr(debug_assertions, crate_type = "lib")]
3068     /// ```
3069     ///
3070     /// {{produces}}
3071     ///
3072     ///
3073     /// ### Explanation
3074     ///
3075     /// The `#![crate_type]` and `#![crate_name]` attributes require a hack in
3076     /// the compiler to be able to change the used crate type and crate name
3077     /// after macros have been expanded. Neither attribute works in combination
3078     /// with Cargo as it explicitly passes `--crate-type` and `--crate-name` on
3079     /// the commandline. These values must match the value used in the source
3080     /// code to prevent an error.
3081     ///
3082     /// To fix the warning use `--crate-type` on the commandline when running
3083     /// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
3084     /// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
3085     pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3086     Deny,
3087     "detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
3088     @future_incompatible = FutureIncompatibleInfo {
3089         reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",
3090     };
3091 }
3092
3093 declare_lint! {
3094     /// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
3095     ///
3096     /// ### Example
3097     ///
3098     /// ```text
3099     /// rustc --check-cfg 'names()'
3100     /// ```
3101     ///
3102     /// ```rust,ignore (needs command line option)
3103     /// #[cfg(widnows)]
3104     /// fn foo() {}
3105     /// ```
3106     ///
3107     /// This will produce:
3108     ///
3109     /// ```text
3110     /// warning: unknown condition name used
3111     ///  --> lint_example.rs:1:7
3112     ///   |
3113     /// 1 | #[cfg(widnows)]
3114     ///   |       ^^^^^^^
3115     ///   |
3116     ///   = note: `#[warn(unexpected_cfgs)]` on by default
3117     /// ```
3118     ///
3119     /// ### Explanation
3120     ///
3121     /// This lint is only active when a `--check-cfg='names(...)'` option has been passed
3122     /// to the compiler and triggers whenever an unknown condition name or value is used.
3123     /// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
3124     /// well-knows names and values built into the compiler.
3125     pub UNEXPECTED_CFGS,
3126     Warn,
3127     "detects unexpected names and values in `#[cfg]` conditions",
3128 }
3129
3130 declare_lint! {
3131     /// The `repr_transparent_external_private_fields` lint
3132     /// detects types marked `#[repr(transparent)]` that (transitively)
3133     /// contain an external ZST type marked `#[non_exhaustive]` or containing
3134     /// private fields
3135     ///
3136     /// ### Example
3137     ///
3138     /// ```rust,ignore (needs external crate)
3139     /// #![deny(repr_transparent_external_private_fields)]
3140     /// use foo::NonExhaustiveZst;
3141     ///
3142     /// #[repr(transparent)]
3143     /// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3144     /// ```
3145     ///
3146     /// This will produce:
3147     ///
3148     /// ```text
3149     /// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
3150     ///  --> src/main.rs:5:28
3151     ///   |
3152     /// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3153     ///   |                            ^^^^^^^^^^^^^^^^
3154     ///   |
3155     /// note: the lint level is defined here
3156     ///  --> src/main.rs:1:9
3157     ///   |
3158     /// 1 | #![deny(repr_transparent_external_private_fields)]
3159     ///   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3160     ///   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3161     ///   = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3162     ///   = 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.
3163     /// ```
3164     ///
3165     /// ### Explanation
3166     ///
3167     /// Previous, Rust accepted fields that contain external private zero-sized types,
3168     /// even though it should not be a breaking change to add a non-zero-sized field to
3169     /// that private type.
3170     ///
3171     /// This is a [future-incompatible] lint to transition this
3172     /// to a hard error in the future. See [issue #78586] for more details.
3173     ///
3174     /// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
3175     /// [future-incompatible]: ../index.md#future-incompatible-lints
3176     pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3177     Warn,
3178     "transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
3179     @future_incompatible = FutureIncompatibleInfo {
3180         reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
3181     };
3182 }
3183
3184 declare_lint! {
3185     /// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3186     /// syntax that is discarded during attribute expansion.
3187     ///
3188     /// ### Example
3189     ///
3190     /// ```rust
3191     /// #[cfg(FALSE)]
3192     /// macro foo() {}
3193     /// ```
3194     ///
3195     /// {{produces}}
3196     ///
3197     /// ### Explanation
3198     ///
3199     /// The input to active attributes such as `#[cfg]` or procedural macro
3200     /// attributes is required to be valid syntax. Previously, the compiler only
3201     /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3202     /// and expanding procedural macros.
3203     ///
3204     /// To avoid relying on unstable syntax, move the use of unstable syntax
3205     /// into a position where the compiler does not parse the syntax, such as a
3206     /// functionlike macro.
3207     ///
3208     /// ```rust
3209     /// # #![deny(unstable_syntax_pre_expansion)]
3210     ///
3211     /// macro_rules! identity {
3212     ///    ( $($tokens:tt)* ) => { $($tokens)* }
3213     /// }
3214     ///
3215     /// #[cfg(FALSE)]
3216     /// identity! {
3217     ///    macro foo() {}
3218     /// }
3219     /// ```
3220     ///
3221     /// This is a [future-incompatible] lint to transition this
3222     /// to a hard error in the future. See [issue #65860] for more details.
3223     ///
3224     /// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
3225     /// [future-incompatible]: ../index.md#future-incompatible-lints
3226     pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3227     Warn,
3228     "unstable syntax can change at any point in the future, causing a hard error!",
3229     @future_incompatible = FutureIncompatibleInfo {
3230         reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
3231     };
3232 }
3233
3234 declare_lint_pass! {
3235     /// Does nothing as a lint pass, but registers some `Lint`s
3236     /// that are used by other parts of the compiler.
3237     HardwiredLints => [
3238         FORBIDDEN_LINT_GROUPS,
3239         ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
3240         ARITHMETIC_OVERFLOW,
3241         UNCONDITIONAL_PANIC,
3242         UNUSED_IMPORTS,
3243         UNUSED_EXTERN_CRATES,
3244         UNUSED_CRATE_DEPENDENCIES,
3245         UNUSED_QUALIFICATIONS,
3246         UNKNOWN_LINTS,
3247         UNFULFILLED_LINT_EXPECTATIONS,
3248         UNUSED_VARIABLES,
3249         UNUSED_ASSIGNMENTS,
3250         DEAD_CODE,
3251         UNREACHABLE_CODE,
3252         UNREACHABLE_PATTERNS,
3253         OVERLAPPING_RANGE_ENDPOINTS,
3254         BINDINGS_WITH_VARIANT_NAME,
3255         UNUSED_MACROS,
3256         UNUSED_MACRO_RULES,
3257         WARNINGS,
3258         UNUSED_FEATURES,
3259         STABLE_FEATURES,
3260         UNKNOWN_CRATE_TYPES,
3261         TRIVIAL_CASTS,
3262         TRIVIAL_NUMERIC_CASTS,
3263         PRIVATE_IN_PUBLIC,
3264         EXPORTED_PRIVATE_DEPENDENCIES,
3265         PUB_USE_OF_PRIVATE_EXTERN_CRATE,
3266         INVALID_TYPE_PARAM_DEFAULT,
3267         RENAMED_AND_REMOVED_LINTS,
3268         UNALIGNED_REFERENCES,
3269         CONST_ITEM_MUTATION,
3270         PATTERNS_IN_FNS_WITHOUT_BODY,
3271         MISSING_FRAGMENT_SPECIFIER,
3272         LATE_BOUND_LIFETIME_ARGUMENTS,
3273         ORDER_DEPENDENT_TRAIT_OBJECTS,
3274         COHERENCE_LEAK_CHECK,
3275         DEPRECATED,
3276         UNUSED_UNSAFE,
3277         UNUSED_MUT,
3278         UNCONDITIONAL_RECURSION,
3279         SINGLE_USE_LIFETIMES,
3280         UNUSED_LIFETIMES,
3281         UNUSED_LABELS,
3282         TYVAR_BEHIND_RAW_POINTER,
3283         ELIDED_LIFETIMES_IN_PATHS,
3284         BARE_TRAIT_OBJECTS,
3285         ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
3286         UNSTABLE_NAME_COLLISIONS,
3287         IRREFUTABLE_LET_PATTERNS,
3288         WHERE_CLAUSES_OBJECT_SAFETY,
3289         PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
3290         MACRO_USE_EXTERN_CRATE,
3291         MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
3292         ILL_FORMED_ATTRIBUTE_INPUT,
3293         CONFLICTING_REPR_HINTS,
3294         META_VARIABLE_MISUSE,
3295         DEPRECATED_IN_FUTURE,
3296         AMBIGUOUS_ASSOCIATED_ITEMS,
3297         INDIRECT_STRUCTURAL_MATCH,
3298         POINTER_STRUCTURAL_MATCH,
3299         NONTRIVIAL_STRUCTURAL_MATCH,
3300         SOFT_UNSTABLE,
3301         UNSTABLE_SYNTAX_PRE_EXPANSION,
3302         INLINE_NO_SANITIZE,
3303         BAD_ASM_STYLE,
3304         ASM_SUB_REGISTER,
3305         UNSAFE_OP_IN_UNSAFE_FN,
3306         INCOMPLETE_INCLUDE,
3307         CENUM_IMPL_DROP_CAST,
3308         FUZZY_PROVENANCE_CASTS,
3309         LOSSY_PROVENANCE_CASTS,
3310         CONST_EVALUATABLE_UNCHECKED,
3311         INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
3312         MUST_NOT_SUSPEND,
3313         UNINHABITED_STATIC,
3314         FUNCTION_ITEM_REFERENCES,
3315         USELESS_DEPRECATED,
3316         MISSING_ABI,
3317         INVALID_DOC_ATTRIBUTES,
3318         SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
3319         RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3320         LEGACY_DERIVE_HELPERS,
3321         PROC_MACRO_BACK_COMPAT,
3322         RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3323         LARGE_ASSIGNMENTS,
3324         RUST_2021_PRELUDE_COLLISIONS,
3325         RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3326         UNSUPPORTED_CALLING_CONVENTIONS,
3327         BREAK_WITH_LABEL_AND_LOOP,
3328         UNUSED_ATTRIBUTES,
3329         UNUSED_TUPLE_STRUCT_FIELDS,
3330         NON_EXHAUSTIVE_OMITTED_PATTERNS,
3331         TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3332         DEREF_INTO_DYN_SUPERTRAIT,
3333         DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3334         DUPLICATE_MACRO_ATTRIBUTES,
3335         SUSPICIOUS_AUTO_TRAIT_IMPLS,
3336         DEPRECATED_WHERE_CLAUSE_LOCATION,
3337         TEST_UNSTABLE_LINT,
3338         FFI_UNWIND_CALLS,
3339         REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3340         NAMED_ARGUMENTS_USED_POSITIONALLY,
3341     ]
3342 }
3343
3344 declare_lint! {
3345     /// The `unused_doc_comments` lint detects doc comments that aren't used
3346     /// by `rustdoc`.
3347     ///
3348     /// ### Example
3349     ///
3350     /// ```rust
3351     /// /// docs for x
3352     /// let x = 12;
3353     /// ```
3354     ///
3355     /// {{produces}}
3356     ///
3357     /// ### Explanation
3358     ///
3359     /// `rustdoc` does not use doc comments in all positions, and so the doc
3360     /// comment will be ignored. Try changing it to a normal comment with `//`
3361     /// to avoid the warning.
3362     pub UNUSED_DOC_COMMENTS,
3363     Warn,
3364     "detects doc comments that aren't used by rustdoc"
3365 }
3366
3367 declare_lint! {
3368     /// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3369     /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3370     /// Rust 2018 and 2021.
3371     ///
3372     /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3373     /// and the field is captured by a closure and used with the assumption that said field implements
3374     /// the same trait as the root variable.
3375     ///
3376     /// ### Example of drop reorder
3377     ///
3378     /// ```rust,edition2018,compile_fail
3379     /// #![deny(rust_2021_incompatible_closure_captures)]
3380     /// # #![allow(unused)]
3381     ///
3382     /// struct FancyInteger(i32);
3383     ///
3384     /// impl Drop for FancyInteger {
3385     ///     fn drop(&mut self) {
3386     ///         println!("Just dropped {}", self.0);
3387     ///     }
3388     /// }
3389     ///
3390     /// struct Point { x: FancyInteger, y: FancyInteger }
3391     ///
3392     /// fn main() {
3393     ///   let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3394     ///
3395     ///   let c = || {
3396     ///      let x = p.x;
3397     ///   };
3398     ///
3399     ///   c();
3400     ///
3401     ///   // ... More code ...
3402     /// }
3403     /// ```
3404     ///
3405     /// {{produces}}
3406     ///
3407     /// ### Explanation
3408     ///
3409     /// In the above example, `p.y` will be dropped at the end of `f` instead of
3410     /// with `c` in Rust 2021.
3411     ///
3412     /// ### Example of auto-trait
3413     ///
3414     /// ```rust,edition2018,compile_fail
3415     /// #![deny(rust_2021_incompatible_closure_captures)]
3416     /// use std::thread;
3417     ///
3418     /// struct Pointer(*mut i32);
3419     /// unsafe impl Send for Pointer {}
3420     ///
3421     /// fn main() {
3422     ///     let mut f = 10;
3423     ///     let fptr = Pointer(&mut f as *mut i32);
3424     ///     thread::spawn(move || unsafe {
3425     ///         *fptr.0 = 20;
3426     ///     });
3427     /// }
3428     /// ```
3429     ///
3430     /// {{produces}}
3431     ///
3432     /// ### Explanation
3433     ///
3434     /// In the above example, only `fptr.0` is captured in Rust 2021.
3435     /// The field is of type `*mut i32`, which doesn't implement `Send`,
3436     /// making the code invalid as the field cannot be sent between threads safely.
3437     pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3438     Allow,
3439     "detects closures affected by Rust 2021 changes",
3440     @future_incompatible = FutureIncompatibleInfo {
3441         reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
3442         explain_reason: false,
3443     };
3444 }
3445
3446 declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3447
3448 declare_lint! {
3449     /// The `missing_abi` lint detects cases where the ABI is omitted from
3450     /// extern declarations.
3451     ///
3452     /// ### Example
3453     ///
3454     /// ```rust,compile_fail
3455     /// #![deny(missing_abi)]
3456     ///
3457     /// extern fn foo() {}
3458     /// ```
3459     ///
3460     /// {{produces}}
3461     ///
3462     /// ### Explanation
3463     ///
3464     /// Historically, Rust implicitly selected C as the ABI for extern
3465     /// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
3466     /// though this has not yet happened, and especially with their addition
3467     /// seeing the ABI easily will make code review easier.
3468     pub MISSING_ABI,
3469     Allow,
3470     "No declared ABI for extern declaration"
3471 }
3472
3473 declare_lint! {
3474     /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3475     /// misused.
3476     ///
3477     /// ### Example
3478     ///
3479     /// ```rust,compile_fail
3480     /// #![deny(warnings)]
3481     ///
3482     /// pub mod submodule {
3483     ///     #![doc(test(no_crate_inject))]
3484     /// }
3485     /// ```
3486     ///
3487     /// {{produces}}
3488     ///
3489     /// ### Explanation
3490     ///
3491     /// Previously, there were very like checks being performed on `#[doc(..)]`
3492     /// unlike the other attributes. It'll now catch all the issues that it
3493     /// silently ignored previously.
3494     pub INVALID_DOC_ATTRIBUTES,
3495     Warn,
3496     "detects invalid `#[doc(...)]` attributes",
3497     @future_incompatible = FutureIncompatibleInfo {
3498         reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
3499     };
3500 }
3501
3502 declare_lint! {
3503     /// The `proc_macro_back_compat` lint detects uses of old versions of certain
3504     /// proc-macro crates, which have hardcoded workarounds in the compiler.
3505     ///
3506     /// ### Example
3507     ///
3508     /// ```rust,ignore (needs-dependency)
3509     ///
3510     /// use time_macros_impl::impl_macros;
3511     /// struct Foo;
3512     /// impl_macros!(Foo);
3513     /// ```
3514     ///
3515     /// This will produce:
3516     ///
3517     /// ```text
3518     /// warning: using an old version of `time-macros-impl`
3519     ///   ::: $DIR/group-compat-hack.rs:27:5
3520     ///    |
3521     /// LL |     impl_macros!(Foo);
3522     ///    |     ------------------ in this macro invocation
3523     ///    |
3524     ///    = note: `#[warn(proc_macro_back_compat)]` on by default
3525     ///    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3526     ///    = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3527     ///    = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
3528     ///    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3529     /// ```
3530     ///
3531     /// ### Explanation
3532     ///
3533     /// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3534     /// causing older versions of certain crates to stop compiling.
3535     /// This is a [future-incompatible] lint to ease the transition to an error.
3536     /// See [issue #83125] for more details.
3537     ///
3538     /// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3539     /// [future-incompatible]: ../index.md#future-incompatible-lints
3540     pub PROC_MACRO_BACK_COMPAT,
3541     Deny,
3542     "detects usage of old versions of certain proc-macro crates",
3543     @future_incompatible = FutureIncompatibleInfo {
3544         reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3545         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
3546     };
3547 }
3548
3549 declare_lint! {
3550     /// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3551     ///
3552     /// ### Example
3553     ///
3554     /// ```rust,compile_fail
3555     /// #![deny(rust_2021_incompatible_or_patterns)]
3556     ///
3557     /// macro_rules! match_any {
3558     ///     ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3559     ///         match $expr {
3560     ///             $(
3561     ///                 $( $pat => $expr_arm, )+
3562     ///             )+
3563     ///         }
3564     ///     };
3565     /// }
3566     ///
3567     /// fn main() {
3568     ///     let result: Result<i64, i32> = Err(42);
3569     ///     let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3570     ///     assert_eq!(int, 42);
3571     /// }
3572     /// ```
3573     ///
3574     /// {{produces}}
3575     ///
3576     /// ### Explanation
3577     ///
3578     /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3579     pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3580     Allow,
3581     "detects usage of old versions of or-patterns",
3582     @future_incompatible = FutureIncompatibleInfo {
3583         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>",
3584         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3585     };
3586 }
3587
3588 declare_lint! {
3589     /// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3590     /// with traits added to the prelude in future editions.
3591     ///
3592     /// ### Example
3593     ///
3594     /// ```rust,compile_fail
3595     /// #![deny(rust_2021_prelude_collisions)]
3596     ///
3597     /// trait Foo {
3598     ///     fn try_into(self) -> Result<String, !>;
3599     /// }
3600     ///
3601     /// impl Foo for &str {
3602     ///     fn try_into(self) -> Result<String, !> {
3603     ///         Ok(String::from(self))
3604     ///     }
3605     /// }
3606     ///
3607     /// fn main() {
3608     ///     let x: String = "3".try_into().unwrap();
3609     ///     //                  ^^^^^^^^
3610     ///     // This call to try_into matches both Foo:try_into and TryInto::try_into as
3611     ///     // `TryInto` has been added to the Rust prelude in 2021 edition.
3612     ///     println!("{x}");
3613     /// }
3614     /// ```
3615     ///
3616     /// {{produces}}
3617     ///
3618     /// ### Explanation
3619     ///
3620     /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3621     /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3622     /// results in an ambiguity as to which method/function to call when an existing `try_into`
3623     /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3624     /// is called directly on a type.
3625     ///
3626     /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3627     pub RUST_2021_PRELUDE_COLLISIONS,
3628     Allow,
3629     "detects the usage of trait methods which are ambiguous with traits added to the \
3630         prelude in future editions",
3631     @future_incompatible = FutureIncompatibleInfo {
3632         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>",
3633         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3634     };
3635 }
3636
3637 declare_lint! {
3638     /// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3639     /// prefix instead in Rust 2021.
3640     ///
3641     /// ### Example
3642     ///
3643     /// ```rust,edition2018,compile_fail
3644     /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3645     ///
3646     /// macro_rules! m {
3647     ///     (z $x:expr) => ();
3648     /// }
3649     ///
3650     /// m!(z"hey");
3651     /// ```
3652     ///
3653     /// {{produces}}
3654     ///
3655     /// ### Explanation
3656     ///
3657     /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3658     /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3659     /// considered a prefix for `"hey"`.
3660     ///
3661     /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3662     /// to keep them separated in Rust 2021.
3663     // Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3664     #[allow(rustdoc::invalid_rust_codeblocks)]
3665     pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3666     Allow,
3667     "identifiers that will be parsed as a prefix in Rust 2021",
3668     @future_incompatible = FutureIncompatibleInfo {
3669         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>",
3670         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3671     };
3672     crate_level_only
3673 }
3674
3675 declare_lint! {
3676     /// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3677     /// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3678     /// variants) on targets that cannot meaningfully be supported for the requested target.
3679     ///
3680     /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3681     /// code, because this calling convention was never specified for those targets.
3682     ///
3683     /// Historically MSVC toolchains have fallen back to the regular C calling convention for
3684     /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3685     /// hack across many more targets.
3686     ///
3687     /// ### Example
3688     ///
3689     /// ```rust,ignore (needs specific targets)
3690     /// extern "stdcall" fn stdcall() {}
3691     /// ```
3692     ///
3693     /// This will produce:
3694     ///
3695     /// ```text
3696     /// warning: use of calling convention not supported on this target
3697     ///   --> $DIR/unsupported.rs:39:1
3698     ///    |
3699     /// LL | extern "stdcall" fn stdcall() {}
3700     ///    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3701     ///    |
3702     ///    = note: `#[warn(unsupported_calling_conventions)]` on by default
3703     ///    = warning: this was previously accepted by the compiler but is being phased out;
3704     ///               it will become a hard error in a future release!
3705     ///    = note: for more information, see issue ...
3706     /// ```
3707     ///
3708     /// ### Explanation
3709     ///
3710     /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3711     /// defined at all, but was previously accepted due to a bug in the implementation of the
3712     /// compiler.
3713     pub UNSUPPORTED_CALLING_CONVENTIONS,
3714     Warn,
3715     "use of unsupported calling convention",
3716     @future_incompatible = FutureIncompatibleInfo {
3717         reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
3718     };
3719 }
3720
3721 declare_lint! {
3722     /// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3723     /// an unlabeled loop as their value expression.
3724     ///
3725     /// ### Example
3726     ///
3727     /// ```rust
3728     /// 'label: loop {
3729     ///     break 'label loop { break 42; };
3730     /// };
3731     /// ```
3732     ///
3733     /// {{produces}}
3734     ///
3735     /// ### Explanation
3736     ///
3737     /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3738     /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3739     /// can also carry a value expression, which can be another loop. A labeled `break` with an
3740     /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3741     /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3742     /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3743     /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3744     /// in parentheses.
3745     pub BREAK_WITH_LABEL_AND_LOOP,
3746     Warn,
3747     "`break` expression with label and unlabeled loop as value expression"
3748 }
3749
3750 declare_lint! {
3751     /// The `non_exhaustive_omitted_patterns` lint detects when a wildcard (`_` or `..`) in a
3752     /// pattern for a `#[non_exhaustive]` struct or enum is reachable.
3753     ///
3754     /// ### Example
3755     ///
3756     /// ```rust,ignore (needs separate crate)
3757     /// // crate A
3758     /// #[non_exhaustive]
3759     /// pub enum Bar {
3760     ///     A,
3761     ///     B, // added variant in non breaking change
3762     /// }
3763     ///
3764     /// // in crate B
3765     /// #![feature(non_exhaustive_omitted_patterns_lint)]
3766     ///
3767     /// match Bar::A {
3768     ///     Bar::A => {},
3769     ///     #[warn(non_exhaustive_omitted_patterns)]
3770     ///     _ => {},
3771     /// }
3772     /// ```
3773     ///
3774     /// This will produce:
3775     ///
3776     /// ```text
3777     /// warning: reachable patterns not covered of non exhaustive enum
3778     ///    --> $DIR/reachable-patterns.rs:70:9
3779     ///    |
3780     /// LL |         _ => {}
3781     ///    |         ^ pattern `B` not covered
3782     ///    |
3783     ///  note: the lint level is defined here
3784     ///   --> $DIR/reachable-patterns.rs:69:16
3785     ///    |
3786     /// LL |         #[warn(non_exhaustive_omitted_patterns)]
3787     ///    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3788     ///    = help: ensure that all possible cases are being handled by adding the suggested match arms
3789     ///    = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3790     /// ```
3791     ///
3792     /// ### Explanation
3793     ///
3794     /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a
3795     /// (potentially redundant) wildcard when pattern-matching, to allow for future
3796     /// addition of fields or variants. The `non_exhaustive_omitted_patterns` lint
3797     /// detects when such a wildcard happens to actually catch some fields/variants.
3798     /// In other words, when the match without the wildcard would not be exhaustive.
3799     /// This lets the user be informed if new fields/variants were added.
3800     pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3801     Allow,
3802     "detect when patterns of types marked `non_exhaustive` are missed",
3803     @feature_gate = sym::non_exhaustive_omitted_patterns_lint;
3804 }
3805
3806 declare_lint! {
3807     /// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3808     /// change the visual representation of text on screen in a way that does not correspond to
3809     /// their on memory representation.
3810     ///
3811     /// ### Example
3812     ///
3813     /// ```rust,compile_fail
3814     /// #![deny(text_direction_codepoint_in_comment)]
3815     /// fn main() {
3816     ///     println!("{:?}"); // '‮');
3817     /// }
3818     /// ```
3819     ///
3820     /// {{produces}}
3821     ///
3822     /// ### Explanation
3823     ///
3824     /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3825     /// are written right-to-left, but a specially crafted comment can make code that will be
3826     /// compiled appear to be part of a comment, depending on the software used to read the code.
3827     /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3828     /// their use.
3829     pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3830     Deny,
3831     "invisible directionality-changing codepoints in comment"
3832 }
3833
3834 declare_lint! {
3835     /// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the
3836     /// `Deref` implementation with a `dyn SuperTrait` type as `Output`.
3837     ///
3838     /// These implementations will become shadowed when the `trait_upcasting` feature is stabilized.
3839     /// The `deref` functions will no longer be called implicitly, so there might be behavior change.
3840     ///
3841     /// ### Example
3842     ///
3843     /// ```rust,compile_fail
3844     /// #![deny(deref_into_dyn_supertrait)]
3845     /// #![allow(dead_code)]
3846     ///
3847     /// use core::ops::Deref;
3848     ///
3849     /// trait A {}
3850     /// trait B: A {}
3851     /// impl<'a> Deref for dyn 'a + B {
3852     ///     type Target = dyn A;
3853     ///     fn deref(&self) -> &Self::Target {
3854     ///         todo!()
3855     ///     }
3856     /// }
3857     ///
3858     /// fn take_a(_: &dyn A) { }
3859     ///
3860     /// fn take_b(b: &dyn B) {
3861     ///     take_a(b);
3862     /// }
3863     /// ```
3864     ///
3865     /// {{produces}}
3866     ///
3867     /// ### Explanation
3868     ///
3869     /// The dyn upcasting coercion feature adds new coercion rules, taking priority
3870     /// over certain other coercion rules, which will cause some behavior change.
3871     pub DEREF_INTO_DYN_SUPERTRAIT,
3872     Warn,
3873     "`Deref` implementation usage with a supertrait trait object for output might be shadowed in the future",
3874     @future_incompatible = FutureIncompatibleInfo {
3875         reference: "issue #89460 <https://github.com/rust-lang/rust/issues/89460>",
3876     };
3877 }
3878
3879 declare_lint! {
3880     /// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3881     /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3882     /// and `test_case`.
3883     ///
3884     /// ### Example
3885     ///
3886     /// ```rust,ignore (needs --test)
3887     /// #[test]
3888     /// #[test]
3889     /// fn foo() {}
3890     /// ```
3891     ///
3892     /// This will produce:
3893     ///
3894     /// ```text
3895     /// warning: duplicated attribute
3896     ///  --> src/lib.rs:2:1
3897     ///   |
3898     /// 2 | #[test]
3899     ///   | ^^^^^^^
3900     ///   |
3901     ///   = note: `#[warn(duplicate_macro_attributes)]` on by default
3902     /// ```
3903     ///
3904     /// ### Explanation
3905     ///
3906     /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3907     /// being duplicated may not be obvious or desirable.
3908     ///
3909     /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3910     /// change to its environment.
3911     ///
3912     /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3913     pub DUPLICATE_MACRO_ATTRIBUTES,
3914     Warn,
3915     "duplicated attribute"
3916 }
3917
3918 declare_lint! {
3919     /// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
3920     /// implementations of auto traits.
3921     ///
3922     /// ### Example
3923     ///
3924     /// ```rust
3925     /// struct Foo<T>(T);
3926     ///
3927     /// unsafe impl<T> Send for Foo<*const T> {}
3928     /// ```
3929     ///
3930     /// {{produces}}
3931     ///
3932     /// ### Explanation
3933     ///
3934     /// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
3935     /// in two different ways: either by writing an explicit impl or if
3936     /// all fields of the type implement that auto trait.
3937     ///
3938     /// The compiler disables the automatic implementation if an explicit one
3939     /// exists for given type constructor. The exact rules governing this
3940     /// are currently unsound and quite subtle and and will be modified in the future.
3941     /// This change will cause the automatic implementation to be disabled in more
3942     /// cases, potentially breaking some code.
3943     pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
3944     Warn,
3945     "the rules governing auto traits will change in the future",
3946     @future_incompatible = FutureIncompatibleInfo {
3947         reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
3948         reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
3949     };
3950 }
3951
3952 declare_lint! {
3953     /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3954     /// in an associated type.
3955     ///
3956     /// ### Example
3957     ///
3958     /// ```rust
3959     /// trait Trait {
3960     ///   type Assoc<'a> where Self: 'a;
3961     /// }
3962     ///
3963     /// impl Trait for () {
3964     ///   type Assoc<'a> where Self: 'a = ();
3965     /// }
3966     /// ```
3967     ///
3968     /// {{produces}}
3969     ///
3970     /// ### Explanation
3971     ///
3972     /// The preferred location for where clauses on associated types in impls
3973     /// is after the type. However, for most of generic associated types development,
3974     /// it was only accepted before the equals. To provide a transition period and
3975     /// further evaluate this change, both are currently accepted. At some point in
3976     /// the future, this may be disallowed at an edition boundary; but, that is
3977     /// undecided currently.
3978     pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3979     Warn,
3980     "deprecated where clause location"
3981 }
3982
3983 declare_lint! {
3984     /// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3985     ///
3986     /// ### Example
3987     ///
3988     /// ```
3989     /// #![allow(test_unstable_lint)]
3990     /// ```
3991     ///
3992     /// {{produces}}
3993     ///
3994     /// ### Explanation
3995     ///
3996     /// In order to test the behavior of unstable lints, a permanently-unstable
3997     /// lint is required. This lint can be used to trigger warnings and errors
3998     /// from the compiler related to unstable lints.
3999     pub TEST_UNSTABLE_LINT,
4000     Deny,
4001     "this unstable lint is only for testing",
4002     @feature_gate = sym::test_unstable_lint;
4003 }
4004
4005 declare_lint! {
4006     /// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
4007     /// `C-unwind` or other FFI-unwind ABIs.
4008     ///
4009     /// ### Example
4010     ///
4011     /// ```rust,ignore (need FFI)
4012     /// #![feature(ffi_unwind_calls)]
4013     /// #![feature(c_unwind)]
4014     ///
4015     /// # mod impl {
4016     /// #     #[no_mangle]
4017     /// #     pub fn "C-unwind" fn foo() {}
4018     /// # }
4019     ///
4020     /// extern "C-unwind" {
4021     ///     fn foo();
4022     /// }
4023     ///
4024     /// fn bar() {
4025     ///     unsafe { foo(); }
4026     ///     let ptr: unsafe extern "C-unwind" fn() = foo;
4027     ///     unsafe { ptr(); }
4028     /// }
4029     /// ```
4030     ///
4031     /// {{produces}}
4032     ///
4033     /// ### Explanation
4034     ///
4035     /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
4036     /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
4037     /// that desire this ability it is therefore necessary to avoid such calls.
4038     pub FFI_UNWIND_CALLS,
4039     Allow,
4040     "call to foreign functions or function pointers with FFI-unwind ABI",
4041     @feature_gate = sym::c_unwind;
4042 }
4043
4044 declare_lint! {
4045     /// The `named_arguments_used_positionally` lint detects cases where named arguments are only
4046     /// used positionally in format strings. This usage is valid but potentially very confusing.
4047     ///
4048     /// ### Example
4049     ///
4050     /// ```rust,compile_fail
4051     /// #![deny(named_arguments_used_positionally)]
4052     /// fn main() {
4053     ///     let _x = 5;
4054     ///     println!("{}", _x = 1); // Prints 1, will trigger lint
4055     ///
4056     ///     println!("{}", _x); // Prints 5, no lint emitted
4057     ///     println!("{_x}", _x = _x); // Prints 5, no lint emitted
4058     /// }
4059     /// ```
4060     ///
4061     /// {{produces}}
4062     ///
4063     /// ### Explanation
4064     ///
4065     /// Rust formatting strings can refer to named arguments by their position, but this usage is
4066     /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4067     /// of named arguments is an assignment (which would produce the unit type).
4068     /// For backwards compatibility, this is not a hard error.
4069     pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4070     Warn,
4071     "named arguments in format used positionally"
4072 }