]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_lint_defs/src/builtin.rs
Auto merge of #105436 - nnethercote:inline-place_contents_drop_state_cannot_differ...
[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     /// ```rust
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 a temporary variable.
915     ///
916     /// ### Example
917     ///
918     /// ```rust,compile_fail
919     /// #![deny(trivial_casts)]
920     /// let x: &u32 = &42;
921     /// let y = x as *const u32;
922     /// ```
923     ///
924     /// {{produces}}
925     ///
926     /// ### Explanation
927     ///
928     /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
929     /// subtype of `T`. This type of cast is usually unnecessary, as it can be
930     /// usually be inferred.
931     ///
932     /// This lint is "allow" by default because there are situations, such as
933     /// with FFI interfaces or complex type aliases, where it triggers
934     /// incorrectly, or in situations where it will be more difficult to
935     /// clearly express the intent. It may be possible that this will become a
936     /// warning in the future, possibly with an explicit syntax for coercions
937     /// providing a convenient way to work around the current issues.
938     /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
939     /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
940     ///
941     /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
942     /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
943     /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
944     pub TRIVIAL_CASTS,
945     Allow,
946     "detects trivial casts which could be removed"
947 }
948
949 declare_lint! {
950     /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
951     /// which could be removed.
952     ///
953     /// ### Example
954     ///
955     /// ```rust,compile_fail
956     /// #![deny(trivial_numeric_casts)]
957     /// let x = 42_i32 as i32;
958     /// ```
959     ///
960     /// {{produces}}
961     ///
962     /// ### Explanation
963     ///
964     /// A trivial numeric cast is a cast of a numeric type to the same numeric
965     /// type. This type of cast is usually unnecessary.
966     ///
967     /// This lint is "allow" by default because there are situations, such as
968     /// with FFI interfaces or complex type aliases, where it triggers
969     /// incorrectly, or in situations where it will be more difficult to
970     /// clearly express the intent. It may be possible that this will become a
971     /// warning in the future, possibly with an explicit syntax for coercions
972     /// providing a convenient way to work around the current issues.
973     /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
974     /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
975     ///
976     /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
977     /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
978     /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
979     pub TRIVIAL_NUMERIC_CASTS,
980     Allow,
981     "detects trivial casts of numeric types which could be removed"
982 }
983
984 declare_lint! {
985     /// The `private_in_public` lint detects private items in public
986     /// interfaces not caught by the old implementation.
987     ///
988     /// ### Example
989     ///
990     /// ```rust
991     /// # #![allow(unused)]
992     /// struct SemiPriv;
993     ///
994     /// mod m1 {
995     ///     struct Priv;
996     ///     impl super::SemiPriv {
997     ///         pub fn f(_: Priv) {}
998     ///     }
999     /// }
1000     /// # fn main() {}
1001     /// ```
1002     ///
1003     /// {{produces}}
1004     ///
1005     /// ### Explanation
1006     ///
1007     /// The visibility rules are intended to prevent exposing private items in
1008     /// public interfaces. This is a [future-incompatible] lint to transition
1009     /// this to a hard error in the future. See [issue #34537] for more
1010     /// details.
1011     ///
1012     /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1013     /// [future-incompatible]: ../index.md#future-incompatible-lints
1014     pub PRIVATE_IN_PUBLIC,
1015     Warn,
1016     "detect private items in public interfaces not caught by the old implementation",
1017     @future_incompatible = FutureIncompatibleInfo {
1018         reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1019     };
1020 }
1021
1022 declare_lint! {
1023     /// The `exported_private_dependencies` lint detects private dependencies
1024     /// that are exposed in a public interface.
1025     ///
1026     /// ### Example
1027     ///
1028     /// ```rust,ignore (needs-dependency)
1029     /// pub fn foo() -> Option<some_private_dependency::Thing> {
1030     ///     None
1031     /// }
1032     /// ```
1033     ///
1034     /// This will produce:
1035     ///
1036     /// ```text
1037     /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1038     ///  --> src/lib.rs:3:1
1039     ///   |
1040     /// 3 | pub fn foo() -> Option<bar::Thing> {
1041     ///   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1042     ///   |
1043     ///   = note: `#[warn(exported_private_dependencies)]` on by default
1044     /// ```
1045     ///
1046     /// ### Explanation
1047     ///
1048     /// Dependencies can be marked as "private" to indicate that they are not
1049     /// exposed in the public interface of a crate. This can be used by Cargo
1050     /// to independently resolve those dependencies because it can assume it
1051     /// does not need to unify them with other packages using that same
1052     /// dependency. This lint is an indication of a violation of that
1053     /// contract.
1054     ///
1055     /// To fix this, avoid exposing the dependency in your public interface.
1056     /// Or, switch the dependency to a public dependency.
1057     ///
1058     /// Note that support for this is only available on the nightly channel.
1059     /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1060     ///
1061     /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1062     /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1063     pub EXPORTED_PRIVATE_DEPENDENCIES,
1064     Warn,
1065     "public interface leaks type from a private dependency"
1066 }
1067
1068 declare_lint! {
1069     /// The `pub_use_of_private_extern_crate` lint detects a specific
1070     /// situation of re-exporting a private `extern crate`.
1071     ///
1072     /// ### Example
1073     ///
1074     /// ```rust,compile_fail
1075     /// extern crate core;
1076     /// pub use core as reexported_core;
1077     /// ```
1078     ///
1079     /// {{produces}}
1080     ///
1081     /// ### Explanation
1082     ///
1083     /// A public `use` declaration should not be used to publicly re-export a
1084     /// private `extern crate`. `pub extern crate` should be used instead.
1085     ///
1086     /// This was historically allowed, but is not the intended behavior
1087     /// according to the visibility rules. This is a [future-incompatible]
1088     /// lint to transition this to a hard error in the future. See [issue
1089     /// #34537] for more details.
1090     ///
1091     /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1092     /// [future-incompatible]: ../index.md#future-incompatible-lints
1093     pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1094     Deny,
1095     "detect public re-exports of private extern crates",
1096     @future_incompatible = FutureIncompatibleInfo {
1097         reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1098     };
1099 }
1100
1101 declare_lint! {
1102     /// The `invalid_type_param_default` lint detects type parameter defaults
1103     /// erroneously allowed in an invalid location.
1104     ///
1105     /// ### Example
1106     ///
1107     /// ```rust,compile_fail
1108     /// fn foo<T=i32>(t: T) {}
1109     /// ```
1110     ///
1111     /// {{produces}}
1112     ///
1113     /// ### Explanation
1114     ///
1115     /// Default type parameters were only intended to be allowed in certain
1116     /// situations, but historically the compiler allowed them everywhere.
1117     /// This is a [future-incompatible] lint to transition this to a hard
1118     /// error in the future. See [issue #36887] for more details.
1119     ///
1120     /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1121     /// [future-incompatible]: ../index.md#future-incompatible-lints
1122     pub INVALID_TYPE_PARAM_DEFAULT,
1123     Deny,
1124     "type parameter default erroneously allowed in invalid location",
1125     @future_incompatible = FutureIncompatibleInfo {
1126         reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
1127     };
1128 }
1129
1130 declare_lint! {
1131     /// The `renamed_and_removed_lints` lint detects lints that have been
1132     /// renamed or removed.
1133     ///
1134     /// ### Example
1135     ///
1136     /// ```rust
1137     /// #![deny(raw_pointer_derive)]
1138     /// ```
1139     ///
1140     /// {{produces}}
1141     ///
1142     /// ### Explanation
1143     ///
1144     /// To fix this, either remove the lint or use the new name. This can help
1145     /// avoid confusion about lints that are no longer valid, and help
1146     /// maintain consistency for renamed lints.
1147     pub RENAMED_AND_REMOVED_LINTS,
1148     Warn,
1149     "lints that have been renamed or removed"
1150 }
1151
1152 declare_lint! {
1153     /// The `unaligned_references` lint detects unaligned references to fields
1154     /// of [packed] structs.
1155     ///
1156     /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1157     ///
1158     /// ### Example
1159     ///
1160     /// ```rust,compile_fail
1161     /// #[repr(packed)]
1162     /// pub struct Foo {
1163     ///     field1: u64,
1164     ///     field2: u8,
1165     /// }
1166     ///
1167     /// fn main() {
1168     ///     unsafe {
1169     ///         let foo = Foo { field1: 0, field2: 0 };
1170     ///         let _ = &foo.field1;
1171     ///         println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
1172     ///     }
1173     /// }
1174     /// ```
1175     ///
1176     /// {{produces}}
1177     ///
1178     /// ### Explanation
1179     ///
1180     /// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
1181     /// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
1182     /// the code should do a copy of the data in the packed field or use raw pointers and unaligned
1183     /// accesses. See [issue #82523] for more information.
1184     ///
1185     /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1186     /// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
1187     pub UNALIGNED_REFERENCES,
1188     Deny,
1189     "detects unaligned references to fields of packed structs",
1190     @future_incompatible = FutureIncompatibleInfo {
1191         reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
1192         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1193     };
1194     report_in_external_macro
1195 }
1196
1197 declare_lint! {
1198     /// The `const_item_mutation` lint detects attempts to mutate a `const`
1199     /// item.
1200     ///
1201     /// ### Example
1202     ///
1203     /// ```rust
1204     /// const FOO: [i32; 1] = [0];
1205     ///
1206     /// fn main() {
1207     ///     FOO[0] = 1;
1208     ///     // This will print "[0]".
1209     ///     println!("{:?}", FOO);
1210     /// }
1211     /// ```
1212     ///
1213     /// {{produces}}
1214     ///
1215     /// ### Explanation
1216     ///
1217     /// Trying to directly mutate a `const` item is almost always a mistake.
1218     /// What is happening in the example above is that a temporary copy of the
1219     /// `const` is mutated, but the original `const` is not. Each time you
1220     /// refer to the `const` by name (such as `FOO` in the example above), a
1221     /// separate copy of the value is inlined at that location.
1222     ///
1223     /// This lint checks for writing directly to a field (`FOO.field =
1224     /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1225     /// reference to the const item (`&mut FOO`), including through an
1226     /// autoderef (`FOO.some_mut_self_method()`).
1227     ///
1228     /// There are various alternatives depending on what you are trying to
1229     /// accomplish:
1230     ///
1231     /// * First, always reconsider using mutable globals, as they can be
1232     ///   difficult to use correctly, and can make the code more difficult to
1233     ///   use or understand.
1234     /// * If you are trying to perform a one-time initialization of a global:
1235     ///     * If the value can be computed at compile-time, consider using
1236     ///       const-compatible values (see [Constant Evaluation]).
1237     ///     * For more complex single-initialization cases, consider using a
1238     ///       third-party crate, such as [`lazy_static`] or [`once_cell`].
1239     ///     * If you are using the [nightly channel], consider the new
1240     ///       [`lazy`] module in the standard library.
1241     /// * If you truly need a mutable global, consider using a [`static`],
1242     ///   which has a variety of options:
1243     ///   * Simple data types can be directly defined and mutated with an
1244     ///     [`atomic`] type.
1245     ///   * More complex types can be placed in a synchronization primitive
1246     ///     like a [`Mutex`], which can be initialized with one of the options
1247     ///     listed above.
1248     ///   * A [mutable `static`] is a low-level primitive, requiring unsafe.
1249     ///     Typically This should be avoided in preference of something
1250     ///     higher-level like one of the above.
1251     ///
1252     /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1253     /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1254     /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1255     /// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
1256     /// [`lazy_static`]: https://crates.io/crates/lazy_static
1257     /// [`once_cell`]: https://crates.io/crates/once_cell
1258     /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1259     /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1260     pub CONST_ITEM_MUTATION,
1261     Warn,
1262     "detects attempts to mutate a `const` item",
1263 }
1264
1265 declare_lint! {
1266     /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1267     /// patterns as a parameter in functions without a body.
1268     ///
1269     /// ### Example
1270     ///
1271     /// ```rust,compile_fail
1272     /// trait Trait {
1273     ///     fn foo(mut arg: u8);
1274     /// }
1275     /// ```
1276     ///
1277     /// {{produces}}
1278     ///
1279     /// ### Explanation
1280     ///
1281     /// To fix this, remove `mut` from the parameter in the trait definition;
1282     /// it can be used in the implementation. That is, the following is OK:
1283     ///
1284     /// ```rust
1285     /// trait Trait {
1286     ///     fn foo(arg: u8); // Removed `mut` here
1287     /// }
1288     ///
1289     /// impl Trait for i32 {
1290     ///     fn foo(mut arg: u8) { // `mut` here is OK
1291     ///
1292     ///     }
1293     /// }
1294     /// ```
1295     ///
1296     /// Trait definitions can define functions without a body to specify a
1297     /// function that implementors must define. The parameter names in the
1298     /// body-less functions are only allowed to be `_` or an [identifier] for
1299     /// documentation purposes (only the type is relevant). Previous versions
1300     /// of the compiler erroneously allowed [identifier patterns] with the
1301     /// `mut` keyword, but this was not intended to be allowed. This is a
1302     /// [future-incompatible] lint to transition this to a hard error in the
1303     /// future. See [issue #35203] for more details.
1304     ///
1305     /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1306     /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1307     /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1308     /// [future-incompatible]: ../index.md#future-incompatible-lints
1309     pub PATTERNS_IN_FNS_WITHOUT_BODY,
1310     Deny,
1311     "patterns in functions without body were erroneously allowed",
1312     @future_incompatible = FutureIncompatibleInfo {
1313         reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1314     };
1315 }
1316
1317 declare_lint! {
1318     /// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1319     /// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1320     /// followed by a fragment specifier (e.g. `:expr`).
1321     ///
1322     /// This warning can always be fixed by removing the unused pattern in the
1323     /// `macro_rules!` macro definition.
1324     ///
1325     /// ### Example
1326     ///
1327     /// ```rust,compile_fail
1328     /// macro_rules! foo {
1329     ///    () => {};
1330     ///    ($name) => { };
1331     /// }
1332     ///
1333     /// fn main() {
1334     ///    foo!();
1335     /// }
1336     /// ```
1337     ///
1338     /// {{produces}}
1339     ///
1340     /// ### Explanation
1341     ///
1342     /// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1343     ///
1344     /// ```rust
1345     /// macro_rules! foo {
1346     ///     () => {};
1347     /// }
1348     /// fn main() {
1349     ///     foo!();
1350     /// }
1351     /// ```
1352     pub MISSING_FRAGMENT_SPECIFIER,
1353     Deny,
1354     "detects missing fragment specifiers in unused `macro_rules!` patterns",
1355     @future_incompatible = FutureIncompatibleInfo {
1356         reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1357     };
1358 }
1359
1360 declare_lint! {
1361     /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1362     /// arguments in path segments with late bound lifetime parameters.
1363     ///
1364     /// ### Example
1365     ///
1366     /// ```rust
1367     /// struct S;
1368     ///
1369     /// impl S {
1370     ///     fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
1371     /// }
1372     ///
1373     /// fn main() {
1374     ///     S.late::<'static>(&0, &0);
1375     /// }
1376     /// ```
1377     ///
1378     /// {{produces}}
1379     ///
1380     /// ### Explanation
1381     ///
1382     /// It is not clear how to provide arguments for early-bound lifetime
1383     /// parameters if they are intermixed with late-bound parameters in the
1384     /// same list. For now, providing any explicit arguments will trigger this
1385     /// lint if late-bound parameters are present, so in the future a solution
1386     /// can be adopted without hitting backward compatibility issues. This is
1387     /// a [future-incompatible] lint to transition this to a hard error in the
1388     /// future. See [issue #42868] for more details, along with a description
1389     /// of the difference between early and late-bound parameters.
1390     ///
1391     /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1392     /// [future-incompatible]: ../index.md#future-incompatible-lints
1393     pub LATE_BOUND_LIFETIME_ARGUMENTS,
1394     Warn,
1395     "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1396     @future_incompatible = FutureIncompatibleInfo {
1397         reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1398     };
1399 }
1400
1401 declare_lint! {
1402     /// The `order_dependent_trait_objects` lint detects a trait coherency
1403     /// violation that would allow creating two trait impls for the same
1404     /// dynamic trait object involving marker traits.
1405     ///
1406     /// ### Example
1407     ///
1408     /// ```rust,compile_fail
1409     /// pub trait Trait {}
1410     ///
1411     /// impl Trait for dyn Send + Sync { }
1412     /// impl Trait for dyn Sync + Send { }
1413     /// ```
1414     ///
1415     /// {{produces}}
1416     ///
1417     /// ### Explanation
1418     ///
1419     /// A previous bug caused the compiler to interpret traits with different
1420     /// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1421     /// when they were intended to be treated the same. This allowed code to
1422     /// define separate trait implementations when there should be a coherence
1423     /// error. This is a [future-incompatible] lint to transition this to a
1424     /// hard error in the future. See [issue #56484] for more details.
1425     ///
1426     /// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1427     /// [future-incompatible]: ../index.md#future-incompatible-lints
1428     pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1429     Deny,
1430     "trait-object types were treated as different depending on marker-trait order",
1431     @future_incompatible = FutureIncompatibleInfo {
1432         reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1433         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1434     };
1435 }
1436
1437 declare_lint! {
1438     /// The `coherence_leak_check` lint detects conflicting implementations of
1439     /// a trait that are only distinguished by the old leak-check code.
1440     ///
1441     /// ### Example
1442     ///
1443     /// ```rust
1444     /// trait SomeTrait { }
1445     /// impl SomeTrait for for<'a> fn(&'a u8) { }
1446     /// impl<'a> SomeTrait for fn(&'a u8) { }
1447     /// ```
1448     ///
1449     /// {{produces}}
1450     ///
1451     /// ### Explanation
1452     ///
1453     /// In the past, the compiler would accept trait implementations for
1454     /// identical functions that differed only in where the lifetime binder
1455     /// appeared. Due to a change in the borrow checker implementation to fix
1456     /// several bugs, this is no longer allowed. However, since this affects
1457     /// existing code, this is a [future-incompatible] lint to transition this
1458     /// to a hard error in the future.
1459     ///
1460     /// Code relying on this pattern should introduce "[newtypes]",
1461     /// like `struct Foo(for<'a> fn(&'a u8))`.
1462     ///
1463     /// See [issue #56105] for more details.
1464     ///
1465     /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1466     /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1467     /// [future-incompatible]: ../index.md#future-incompatible-lints
1468     pub COHERENCE_LEAK_CHECK,
1469     Warn,
1470     "distinct impls distinguished only by the leak-check code",
1471     @future_incompatible = FutureIncompatibleInfo {
1472         reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1473     };
1474 }
1475
1476 declare_lint! {
1477     /// The `deprecated` lint detects use of deprecated items.
1478     ///
1479     /// ### Example
1480     ///
1481     /// ```rust
1482     /// #[deprecated]
1483     /// fn foo() {}
1484     ///
1485     /// fn bar() {
1486     ///     foo();
1487     /// }
1488     /// ```
1489     ///
1490     /// {{produces}}
1491     ///
1492     /// ### Explanation
1493     ///
1494     /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1495     /// indicate that they should no longer be used. Usually the attribute
1496     /// should include a note on what to use instead, or check the
1497     /// documentation.
1498     ///
1499     /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1500     pub DEPRECATED,
1501     Warn,
1502     "detects use of deprecated items",
1503     report_in_external_macro
1504 }
1505
1506 declare_lint! {
1507     /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1508     ///
1509     /// ### Example
1510     ///
1511     /// ```rust
1512     /// unsafe {}
1513     /// ```
1514     ///
1515     /// {{produces}}
1516     ///
1517     /// ### Explanation
1518     ///
1519     /// If nothing within the block requires `unsafe`, then remove the
1520     /// `unsafe` marker because it is not required and may cause confusion.
1521     pub UNUSED_UNSAFE,
1522     Warn,
1523     "unnecessary use of an `unsafe` block"
1524 }
1525
1526 declare_lint! {
1527     /// The `unused_mut` lint detects mut variables which don't need to be
1528     /// mutable.
1529     ///
1530     /// ### Example
1531     ///
1532     /// ```rust
1533     /// let mut x = 5;
1534     /// ```
1535     ///
1536     /// {{produces}}
1537     ///
1538     /// ### Explanation
1539     ///
1540     /// The preferred style is to only mark variables as `mut` if it is
1541     /// required.
1542     pub UNUSED_MUT,
1543     Warn,
1544     "detect mut variables which don't need to be mutable"
1545 }
1546
1547 declare_lint! {
1548     /// The `unconditional_recursion` lint detects functions that cannot
1549     /// return without calling themselves.
1550     ///
1551     /// ### Example
1552     ///
1553     /// ```rust
1554     /// fn foo() {
1555     ///     foo();
1556     /// }
1557     /// ```
1558     ///
1559     /// {{produces}}
1560     ///
1561     /// ### Explanation
1562     ///
1563     /// It is usually a mistake to have a recursive call that does not have
1564     /// some condition to cause it to terminate. If you really intend to have
1565     /// an infinite loop, using a `loop` expression is recommended.
1566     pub UNCONDITIONAL_RECURSION,
1567     Warn,
1568     "functions that cannot return without calling themselves"
1569 }
1570
1571 declare_lint! {
1572     /// The `single_use_lifetimes` lint detects lifetimes that are only used
1573     /// once.
1574     ///
1575     /// ### Example
1576     ///
1577     /// ```rust,compile_fail
1578     /// #![deny(single_use_lifetimes)]
1579     ///
1580     /// fn foo<'a>(x: &'a u32) {}
1581     /// ```
1582     ///
1583     /// {{produces}}
1584     ///
1585     /// ### Explanation
1586     ///
1587     /// Specifying an explicit lifetime like `'a` in a function or `impl`
1588     /// should only be used to link together two things. Otherwise, you should
1589     /// just use `'_` to indicate that the lifetime is not linked to anything,
1590     /// or elide the lifetime altogether if possible.
1591     ///
1592     /// This lint is "allow" by default because it was introduced at a time
1593     /// when `'_` and elided lifetimes were first being introduced, and this
1594     /// lint would be too noisy. Also, there are some known false positives
1595     /// that it produces. See [RFC 2115] for historical context, and [issue
1596     /// #44752] for more details.
1597     ///
1598     /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1599     /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1600     pub SINGLE_USE_LIFETIMES,
1601     Allow,
1602     "detects lifetime parameters that are only used once"
1603 }
1604
1605 declare_lint! {
1606     /// The `unused_lifetimes` lint detects lifetime parameters that are never
1607     /// used.
1608     ///
1609     /// ### Example
1610     ///
1611     /// ```rust,compile_fail
1612     /// #[deny(unused_lifetimes)]
1613     ///
1614     /// pub fn foo<'a>() {}
1615     /// ```
1616     ///
1617     /// {{produces}}
1618     ///
1619     /// ### Explanation
1620     ///
1621     /// Unused lifetime parameters may signal a mistake or unfinished code.
1622     /// Consider removing the parameter.
1623     pub UNUSED_LIFETIMES,
1624     Allow,
1625     "detects lifetime parameters that are never used"
1626 }
1627
1628 declare_lint! {
1629     /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1630     /// inference variable.
1631     ///
1632     /// ### Example
1633     ///
1634     /// ```rust,edition2015
1635     /// // edition 2015
1636     /// let data = std::ptr::null();
1637     /// let _ = &data as *const *const ();
1638     ///
1639     /// if data.is_null() {}
1640     /// ```
1641     ///
1642     /// {{produces}}
1643     ///
1644     /// ### Explanation
1645     ///
1646     /// This kind of inference was previously allowed, but with the future
1647     /// arrival of [arbitrary self types], this can introduce ambiguity. To
1648     /// resolve this, use an explicit type instead of relying on type
1649     /// inference.
1650     ///
1651     /// This is a [future-incompatible] lint to transition this to a hard
1652     /// error in the 2018 edition. See [issue #46906] for more details. This
1653     /// is currently a hard-error on the 2018 edition, and is "warn" by
1654     /// default in the 2015 edition.
1655     ///
1656     /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1657     /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1658     /// [future-incompatible]: ../index.md#future-incompatible-lints
1659     pub TYVAR_BEHIND_RAW_POINTER,
1660     Warn,
1661     "raw pointer to an inference variable",
1662     @future_incompatible = FutureIncompatibleInfo {
1663         reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1664         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1665     };
1666 }
1667
1668 declare_lint! {
1669     /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1670     /// lifetime parameters.
1671     ///
1672     /// ### Example
1673     ///
1674     /// ```rust,compile_fail
1675     /// #![deny(elided_lifetimes_in_paths)]
1676     /// struct Foo<'a> {
1677     ///     x: &'a u32
1678     /// }
1679     ///
1680     /// fn foo(x: &Foo) {
1681     /// }
1682     /// ```
1683     ///
1684     /// {{produces}}
1685     ///
1686     /// ### Explanation
1687     ///
1688     /// Elided lifetime parameters can make it difficult to see at a glance
1689     /// that borrowing is occurring. This lint ensures that lifetime
1690     /// parameters are always explicitly stated, even if it is the `'_`
1691     /// [placeholder lifetime].
1692     ///
1693     /// This lint is "allow" by default because it has some known issues, and
1694     /// may require a significant transition for old code.
1695     ///
1696     /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1697     pub ELIDED_LIFETIMES_IN_PATHS,
1698     Allow,
1699     "hidden lifetime parameters in types are deprecated",
1700     crate_level_only
1701 }
1702
1703 declare_lint! {
1704     /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1705     /// objects.
1706     ///
1707     /// ### Example
1708     ///
1709     /// ```rust,edition2018
1710     /// trait Trait { }
1711     ///
1712     /// fn takes_trait_object(_: Box<Trait>) {
1713     /// }
1714     /// ```
1715     ///
1716     /// {{produces}}
1717     ///
1718     /// ### Explanation
1719     ///
1720     /// Without the `dyn` indicator, it can be ambiguous or confusing when
1721     /// reading code as to whether or not you are looking at a trait object.
1722     /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1723     /// with [`impl Trait`].
1724     ///
1725     /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1726     pub BARE_TRAIT_OBJECTS,
1727     Warn,
1728     "suggest using `dyn Trait` for trait objects",
1729     @future_incompatible = FutureIncompatibleInfo {
1730         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
1731         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
1732     };
1733 }
1734
1735 declare_lint! {
1736     /// The `absolute_paths_not_starting_with_crate` lint detects fully
1737     /// qualified paths that start with a module name instead of `crate`,
1738     /// `self`, or an extern crate name
1739     ///
1740     /// ### Example
1741     ///
1742     /// ```rust,edition2015,compile_fail
1743     /// #![deny(absolute_paths_not_starting_with_crate)]
1744     ///
1745     /// mod foo {
1746     ///     pub fn bar() {}
1747     /// }
1748     ///
1749     /// fn main() {
1750     ///     ::foo::bar();
1751     /// }
1752     /// ```
1753     ///
1754     /// {{produces}}
1755     ///
1756     /// ### Explanation
1757     ///
1758     /// Rust [editions] allow the language to evolve without breaking
1759     /// backwards compatibility. This lint catches code that uses absolute
1760     /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1761     /// paths (those starting with `::`) refer to either the crate root or an
1762     /// external crate. In the 2018 edition it was changed so that they only
1763     /// refer to external crates. The path prefix `crate::` should be used
1764     /// instead to reference items from the crate root.
1765     ///
1766     /// If you switch the compiler from the 2015 to 2018 edition without
1767     /// updating the code, then it will fail to compile if the old style paths
1768     /// are used. You can manually change the paths to use the `crate::`
1769     /// prefix to transition to the 2018 edition.
1770     ///
1771     /// This lint solves the problem automatically. It is "allow" by default
1772     /// because the code is perfectly valid in the 2015 edition. The [`cargo
1773     /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1774     /// and automatically apply the suggested fix from the compiler. This
1775     /// provides a completely automated way to update old code to the 2018
1776     /// edition.
1777     ///
1778     /// [editions]: https://doc.rust-lang.org/edition-guide/
1779     /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1780     pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1781     Allow,
1782     "fully qualified paths that start with a module name \
1783      instead of `crate`, `self`, or an extern crate name",
1784      @future_incompatible = FutureIncompatibleInfo {
1785         reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1786         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1787      };
1788 }
1789
1790 declare_lint! {
1791     /// The `illegal_floating_point_literal_pattern` lint detects
1792     /// floating-point literals used in patterns.
1793     ///
1794     /// ### Example
1795     ///
1796     /// ```rust
1797     /// let x = 42.0;
1798     ///
1799     /// match x {
1800     ///     5.0 => {}
1801     ///     _ => {}
1802     /// }
1803     /// ```
1804     ///
1805     /// {{produces}}
1806     ///
1807     /// ### Explanation
1808     ///
1809     /// Previous versions of the compiler accepted floating-point literals in
1810     /// patterns, but it was later determined this was a mistake. The
1811     /// semantics of comparing floating-point values may not be clear in a
1812     /// pattern when contrasted with "structural equality". Typically you can
1813     /// work around this by using a [match guard], such as:
1814     ///
1815     /// ```rust
1816     /// # let x = 42.0;
1817     ///
1818     /// match x {
1819     ///     y if y == 5.0 => {}
1820     ///     _ => {}
1821     /// }
1822     /// ```
1823     ///
1824     /// This is a [future-incompatible] lint to transition this to a hard
1825     /// error in the future. See [issue #41620] for more details.
1826     ///
1827     /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1828     /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1829     /// [future-incompatible]: ../index.md#future-incompatible-lints
1830     pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1831     Warn,
1832     "floating-point literals cannot be used in patterns",
1833     @future_incompatible = FutureIncompatibleInfo {
1834         reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1835     };
1836 }
1837
1838 declare_lint! {
1839     /// The `unstable_name_collisions` lint detects that you have used a name
1840     /// that the standard library plans to add in the future.
1841     ///
1842     /// ### Example
1843     ///
1844     /// ```rust
1845     /// trait MyIterator : Iterator {
1846     ///     // is_sorted is an unstable method that already exists on the Iterator trait
1847     ///     fn is_sorted(self) -> bool where Self: Sized {true}
1848     /// }
1849     ///
1850     /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1851     ///
1852     /// let x = vec![1, 2, 3];
1853     /// let _ = x.iter().is_sorted();
1854     /// ```
1855     ///
1856     /// {{produces}}
1857     ///
1858     /// ### Explanation
1859     ///
1860     /// When new methods are added to traits in the standard library, they are
1861     /// usually added in an "unstable" form which is only available on the
1862     /// [nightly channel] with a [`feature` attribute]. If there is any
1863     /// pre-existing code which extends a trait to have a method with the same
1864     /// name, then the names will collide. In the future, when the method is
1865     /// stabilized, this will cause an error due to the ambiguity. This lint
1866     /// is an early-warning to let you know that there may be a collision in
1867     /// the future. This can be avoided by adding type annotations to
1868     /// disambiguate which trait method you intend to call, such as
1869     /// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
1870     ///
1871     /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1872     /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1873     pub UNSTABLE_NAME_COLLISIONS,
1874     Warn,
1875     "detects name collision with an existing but unstable method",
1876     @future_incompatible = FutureIncompatibleInfo {
1877         reason: FutureIncompatibilityReason::Custom(
1878             "once this associated item is added to the standard library, \
1879              the ambiguity may cause an error or change in behavior!"
1880         ),
1881         reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1882         // Note: this item represents future incompatibility of all unstable functions in the
1883         //       standard library, and thus should never be removed or changed to an error.
1884     };
1885 }
1886
1887 declare_lint! {
1888     /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1889     /// in [`if let`]s, [`while let`]s, and `if let` guards.
1890     ///
1891     /// ### Example
1892     ///
1893     /// ```rust
1894     /// if let _ = 123 {
1895     ///     println!("always runs!");
1896     /// }
1897     /// ```
1898     ///
1899     /// {{produces}}
1900     ///
1901     /// ### Explanation
1902     ///
1903     /// There usually isn't a reason to have an irrefutable pattern in an
1904     /// `if let` or `while let` statement, because the pattern will always match
1905     /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1906     /// when generating code with a macro, forbidding irrefutable patterns
1907     /// would require awkward workarounds in situations where the macro
1908     /// doesn't know if the pattern is refutable or not. This lint allows
1909     /// macros to accept this form, while alerting for a possibly incorrect
1910     /// use in normal code.
1911     ///
1912     /// See [RFC 2086] for more details.
1913     ///
1914     /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1915     /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1916     /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1917     /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1918     /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1919     /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1920     pub IRREFUTABLE_LET_PATTERNS,
1921     Warn,
1922     "detects irrefutable patterns in `if let` and `while let` statements"
1923 }
1924
1925 declare_lint! {
1926     /// The `unused_labels` lint detects [labels] that are never used.
1927     ///
1928     /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1929     ///
1930     /// ### Example
1931     ///
1932     /// ```rust,no_run
1933     /// 'unused_label: loop {}
1934     /// ```
1935     ///
1936     /// {{produces}}
1937     ///
1938     /// ### Explanation
1939     ///
1940     /// Unused labels may signal a mistake or unfinished code. To silence the
1941     /// warning for the individual label, prefix it with an underscore such as
1942     /// `'_my_label:`.
1943     pub UNUSED_LABELS,
1944     Warn,
1945     "detects labels that are never used"
1946 }
1947
1948 declare_lint! {
1949     /// The `where_clauses_object_safety` lint detects for [object safety] of
1950     /// [where clauses].
1951     ///
1952     /// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
1953     /// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
1954     ///
1955     /// ### Example
1956     ///
1957     /// ```rust,no_run
1958     /// trait Trait {}
1959     ///
1960     /// trait X { fn foo(&self) where Self: Trait; }
1961     ///
1962     /// impl X for () { fn foo(&self) {} }
1963     ///
1964     /// impl Trait for dyn X {}
1965     ///
1966     /// // Segfault at opt-level 0, SIGILL otherwise.
1967     /// pub fn main() { <dyn X as X>::foo(&()); }
1968     /// ```
1969     ///
1970     /// {{produces}}
1971     ///
1972     /// ### Explanation
1973     ///
1974     /// The compiler previously allowed these object-unsafe bounds, which was
1975     /// incorrect. This is a [future-incompatible] lint to transition this to
1976     /// a hard error in the future. See [issue #51443] for more details.
1977     ///
1978     /// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
1979     /// [future-incompatible]: ../index.md#future-incompatible-lints
1980     pub WHERE_CLAUSES_OBJECT_SAFETY,
1981     Warn,
1982     "checks the object safety of where clauses",
1983     @future_incompatible = FutureIncompatibleInfo {
1984         reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
1985     };
1986 }
1987
1988 declare_lint! {
1989     /// The `macro_use_extern_crate` lint detects the use of the
1990     /// [`macro_use` attribute].
1991     ///
1992     /// ### Example
1993     ///
1994     /// ```rust,ignore (needs extern crate)
1995     /// #![deny(macro_use_extern_crate)]
1996     ///
1997     /// #[macro_use]
1998     /// extern crate serde_json;
1999     ///
2000     /// fn main() {
2001     ///     let _ = json!{{}};
2002     /// }
2003     /// ```
2004     ///
2005     /// This will produce:
2006     ///
2007     /// ```text
2008     /// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
2009     ///  --> src/main.rs:3:1
2010     ///   |
2011     /// 3 | #[macro_use]
2012     ///   | ^^^^^^^^^^^^
2013     ///   |
2014     /// note: the lint level is defined here
2015     ///  --> src/main.rs:1:9
2016     ///   |
2017     /// 1 | #![deny(macro_use_extern_crate)]
2018     ///   |         ^^^^^^^^^^^^^^^^^^^^^^
2019     /// ```
2020     ///
2021     /// ### Explanation
2022     ///
2023     /// The [`macro_use` attribute] on an [`extern crate`] item causes
2024     /// macros in that external crate to be brought into the prelude of the
2025     /// crate, making the macros in scope everywhere. As part of the efforts
2026     /// to simplify handling of dependencies in the [2018 edition], the use of
2027     /// `extern crate` is being phased out. To bring macros from extern crates
2028     /// into scope, it is recommended to use a [`use` import].
2029     ///
2030     /// This lint is "allow" by default because this is a stylistic choice
2031     /// that has not been settled, see [issue #52043] for more information.
2032     ///
2033     /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2034     /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2035     /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2036     pub MACRO_USE_EXTERN_CRATE,
2037     Allow,
2038     "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2039      via the module system"
2040 }
2041
2042 declare_lint! {
2043     /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2044     /// detects macro-expanded [`macro_export`] macros from the current crate
2045     /// that cannot be referred to by absolute paths.
2046     ///
2047     /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2048     ///
2049     /// ### Example
2050     ///
2051     /// ```rust,compile_fail
2052     /// macro_rules! define_exported {
2053     ///     () => {
2054     ///         #[macro_export]
2055     ///         macro_rules! exported {
2056     ///             () => {};
2057     ///         }
2058     ///     };
2059     /// }
2060     ///
2061     /// define_exported!();
2062     ///
2063     /// fn main() {
2064     ///     crate::exported!();
2065     /// }
2066     /// ```
2067     ///
2068     /// {{produces}}
2069     ///
2070     /// ### Explanation
2071     ///
2072     /// The intent is that all macros marked with the `#[macro_export]`
2073     /// attribute are made available in the root of the crate. However, when a
2074     /// `macro_rules!` definition is generated by another macro, the macro
2075     /// expansion is unable to uphold this rule. This is a
2076     /// [future-incompatible] lint to transition this to a hard error in the
2077     /// future. See [issue #53495] for more details.
2078     ///
2079     /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2080     /// [future-incompatible]: ../index.md#future-incompatible-lints
2081     pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2082     Deny,
2083     "macro-expanded `macro_export` macros from the current crate \
2084      cannot be referred to by absolute paths",
2085     @future_incompatible = FutureIncompatibleInfo {
2086         reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2087     };
2088     crate_level_only
2089 }
2090
2091 declare_lint! {
2092     /// The `explicit_outlives_requirements` lint detects unnecessary
2093     /// lifetime bounds that can be inferred.
2094     ///
2095     /// ### Example
2096     ///
2097     /// ```rust,compile_fail
2098     /// # #![allow(unused)]
2099     /// #![deny(explicit_outlives_requirements)]
2100     ///
2101     /// struct SharedRef<'a, T>
2102     /// where
2103     ///     T: 'a,
2104     /// {
2105     ///     data: &'a T,
2106     /// }
2107     /// ```
2108     ///
2109     /// {{produces}}
2110     ///
2111     /// ### Explanation
2112     ///
2113     /// If a `struct` contains a reference, such as `&'a T`, the compiler
2114     /// requires that `T` outlives the lifetime `'a`. This historically
2115     /// required writing an explicit lifetime bound to indicate this
2116     /// requirement. However, this can be overly explicit, causing clutter and
2117     /// unnecessary complexity. The language was changed to automatically
2118     /// infer the bound if it is not specified. Specifically, if the struct
2119     /// contains a reference, directly or indirectly, to `T` with lifetime
2120     /// `'x`, then it will infer that `T: 'x` is a requirement.
2121     ///
2122     /// This lint is "allow" by default because it can be noisy for existing
2123     /// code that already had these requirements. This is a stylistic choice,
2124     /// as it is still valid to explicitly state the bound. It also has some
2125     /// false positives that can cause confusion.
2126     ///
2127     /// See [RFC 2093] for more details.
2128     ///
2129     /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2130     pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2131     Allow,
2132     "outlives requirements can be inferred"
2133 }
2134
2135 declare_lint! {
2136     /// The `indirect_structural_match` lint detects a `const` in a pattern
2137     /// that manually implements [`PartialEq`] and [`Eq`].
2138     ///
2139     /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2140     /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2141     ///
2142     /// ### Example
2143     ///
2144     /// ```rust,compile_fail
2145     /// #![deny(indirect_structural_match)]
2146     ///
2147     /// struct NoDerive(i32);
2148     /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2149     /// impl Eq for NoDerive { }
2150     /// #[derive(PartialEq, Eq)]
2151     /// struct WrapParam<T>(T);
2152     /// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
2153     /// fn main() {
2154     ///     match WRAP_INDIRECT_PARAM {
2155     ///         WRAP_INDIRECT_PARAM => { }
2156     ///         _ => { }
2157     ///     }
2158     /// }
2159     /// ```
2160     ///
2161     /// {{produces}}
2162     ///
2163     /// ### Explanation
2164     ///
2165     /// The compiler unintentionally accepted this form in the past. This is a
2166     /// [future-incompatible] lint to transition this to a hard error in the
2167     /// future. See [issue #62411] for a complete description of the problem,
2168     /// and some possible solutions.
2169     ///
2170     /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2171     /// [future-incompatible]: ../index.md#future-incompatible-lints
2172     pub INDIRECT_STRUCTURAL_MATCH,
2173     Warn,
2174     "constant used in pattern contains value of non-structural-match type in a field or a variant",
2175     @future_incompatible = FutureIncompatibleInfo {
2176         reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2177     };
2178 }
2179
2180 declare_lint! {
2181     /// The `deprecated_in_future` lint is internal to rustc and should not be
2182     /// used by user code.
2183     ///
2184     /// This lint is only enabled in the standard library. It works with the
2185     /// use of `#[deprecated]` with a `since` field of a version in the future.
2186     /// This allows something to be marked as deprecated in a future version,
2187     /// and then this lint will ensure that the item is no longer used in the
2188     /// standard library. See the [stability documentation] for more details.
2189     ///
2190     /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2191     pub DEPRECATED_IN_FUTURE,
2192     Allow,
2193     "detects use of items that will be deprecated in a future version",
2194     report_in_external_macro
2195 }
2196
2197 declare_lint! {
2198     /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2199     /// cannot be relied upon across compiler versions and optimization levels.
2200     ///
2201     /// ### Example
2202     ///
2203     /// ```rust,compile_fail
2204     /// #![deny(pointer_structural_match)]
2205     /// fn foo(a: usize, b: usize) -> usize { a + b }
2206     /// const FOO: fn(usize, usize) -> usize = foo;
2207     /// fn main() {
2208     ///     match FOO {
2209     ///         FOO => {},
2210     ///         _ => {},
2211     ///     }
2212     /// }
2213     /// ```
2214     ///
2215     /// {{produces}}
2216     ///
2217     /// ### Explanation
2218     ///
2219     /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2220     /// While these work in many cases as expected by users, it is possible that due to
2221     /// optimizations pointers are "not equal to themselves" or pointers to different functions
2222     /// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2223     /// functions if their bodies are the same, thus also making pointers to these functions point
2224     /// to the same location. Additionally functions may get duplicated if they are instantiated
2225     /// in different crates and not deduplicated again via LTO.
2226     pub POINTER_STRUCTURAL_MATCH,
2227     Allow,
2228     "pointers are not structural-match",
2229     @future_incompatible = FutureIncompatibleInfo {
2230         reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2231     };
2232 }
2233
2234 declare_lint! {
2235     /// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2236     /// whose type is not structural-match and whose initializer body actually uses values
2237     /// that are not structural-match. So `Option<NotStructuralMatch>` is ok if the constant
2238     /// is just `None`.
2239     ///
2240     /// ### Example
2241     ///
2242     /// ```rust,compile_fail
2243     /// #![deny(nontrivial_structural_match)]
2244     ///
2245     /// #[derive(Copy, Clone, Debug)]
2246     /// struct NoDerive(u32);
2247     /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2248     /// impl Eq for NoDerive { }
2249     /// fn main() {
2250     ///     const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2251     ///     match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2252     /// }
2253     /// ```
2254     ///
2255     /// {{produces}}
2256     ///
2257     /// ### Explanation
2258     ///
2259     /// Previous versions of Rust accepted constants in patterns, even if those constants' types
2260     /// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2261     /// `PartialEq`, which can report that two constants are not equal even if they are
2262     /// bit-equivalent.
2263     pub NONTRIVIAL_STRUCTURAL_MATCH,
2264     Warn,
2265     "constant used in pattern of non-structural-match type and the constant's initializer \
2266     expression contains values of non-structural-match types",
2267     @future_incompatible = FutureIncompatibleInfo {
2268         reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2269     };
2270 }
2271
2272 declare_lint! {
2273     /// The `ambiguous_associated_items` lint detects ambiguity between
2274     /// [associated items] and [enum variants].
2275     ///
2276     /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2277     /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2278     ///
2279     /// ### Example
2280     ///
2281     /// ```rust,compile_fail
2282     /// enum E {
2283     ///     V
2284     /// }
2285     ///
2286     /// trait Tr {
2287     ///     type V;
2288     ///     fn foo() -> Self::V;
2289     /// }
2290     ///
2291     /// impl Tr for E {
2292     ///     type V = u8;
2293     ///     // `Self::V` is ambiguous because it may refer to the associated type or
2294     ///     // the enum variant.
2295     ///     fn foo() -> Self::V { 0 }
2296     /// }
2297     /// ```
2298     ///
2299     /// {{produces}}
2300     ///
2301     /// ### Explanation
2302     ///
2303     /// Previous versions of Rust did not allow accessing enum variants
2304     /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2305     /// introduced some situations where it can be ambiguous what a type
2306     /// was referring to.
2307     ///
2308     /// To fix this ambiguity, you should use a [qualified path] to explicitly
2309     /// state which type to use. For example, in the above example the
2310     /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2311     /// specifically refer to the associated type.
2312     ///
2313     /// This is a [future-incompatible] lint to transition this to a hard
2314     /// error in the future. See [issue #57644] for more details.
2315     ///
2316     /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2317     /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2318     /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2319     /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2320     /// [future-incompatible]: ../index.md#future-incompatible-lints
2321     pub AMBIGUOUS_ASSOCIATED_ITEMS,
2322     Deny,
2323     "ambiguous associated items",
2324     @future_incompatible = FutureIncompatibleInfo {
2325         reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2326     };
2327 }
2328
2329 declare_lint! {
2330     /// The `soft_unstable` lint detects unstable features that were
2331     /// unintentionally allowed on stable.
2332     ///
2333     /// ### Example
2334     ///
2335     /// ```rust,compile_fail
2336     /// #[cfg(test)]
2337     /// extern crate test;
2338     ///
2339     /// #[bench]
2340     /// fn name(b: &mut test::Bencher) {
2341     ///     b.iter(|| 123)
2342     /// }
2343     /// ```
2344     ///
2345     /// {{produces}}
2346     ///
2347     /// ### Explanation
2348     ///
2349     /// The [`bench` attribute] was accidentally allowed to be specified on
2350     /// the [stable release channel]. Turning this to a hard error would have
2351     /// broken some projects. This lint allows those projects to continue to
2352     /// build correctly when [`--cap-lints`] is used, but otherwise signal an
2353     /// error that `#[bench]` should not be used on the stable channel. This
2354     /// is a [future-incompatible] lint to transition this to a hard error in
2355     /// the future. See [issue #64266] for more details.
2356     ///
2357     /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2358     /// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
2359     /// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2360     /// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
2361     /// [future-incompatible]: ../index.md#future-incompatible-lints
2362     pub SOFT_UNSTABLE,
2363     Deny,
2364     "a feature gate that doesn't break dependent crates",
2365     @future_incompatible = FutureIncompatibleInfo {
2366         reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2367     };
2368 }
2369
2370 declare_lint! {
2371     /// The `inline_no_sanitize` lint detects incompatible use of
2372     /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2373     ///
2374     /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2375     /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2376     ///
2377     /// ### Example
2378     ///
2379     /// ```rust
2380     /// #![feature(no_sanitize)]
2381     ///
2382     /// #[inline(always)]
2383     /// #[no_sanitize(address)]
2384     /// fn x() {}
2385     ///
2386     /// fn main() {
2387     ///     x()
2388     /// }
2389     /// ```
2390     ///
2391     /// {{produces}}
2392     ///
2393     /// ### Explanation
2394     ///
2395     /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2396     /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2397     /// Consider temporarily removing `inline` attribute.
2398     pub INLINE_NO_SANITIZE,
2399     Warn,
2400     "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2401 }
2402
2403 declare_lint! {
2404     /// The `asm_sub_register` lint detects using only a subset of a register
2405     /// for inline asm inputs.
2406     ///
2407     /// ### Example
2408     ///
2409     /// ```rust,ignore (fails on non-x86_64)
2410     /// #[cfg(target_arch="x86_64")]
2411     /// use std::arch::asm;
2412     ///
2413     /// fn main() {
2414     ///     #[cfg(target_arch="x86_64")]
2415     ///     unsafe {
2416     ///         asm!("mov {0}, {0}", in(reg) 0i16);
2417     ///     }
2418     /// }
2419     /// ```
2420     ///
2421     /// This will produce:
2422     ///
2423     /// ```text
2424     /// warning: formatting may not be suitable for sub-register argument
2425     ///  --> src/main.rs:7:19
2426     ///   |
2427     /// 7 |         asm!("mov {0}, {0}", in(reg) 0i16);
2428     ///   |                   ^^^  ^^^           ---- for this argument
2429     ///   |
2430     ///   = note: `#[warn(asm_sub_register)]` on by default
2431     ///   = help: use the `x` modifier to have the register formatted as `ax`
2432     ///   = help: or use the `r` modifier to keep the default formatting of `rax`
2433     /// ```
2434     ///
2435     /// ### Explanation
2436     ///
2437     /// Registers on some architectures can use different names to refer to a
2438     /// subset of the register. By default, the compiler will use the name for
2439     /// the full register size. To explicitly use a subset of the register,
2440     /// you can override the default by using a modifier on the template
2441     /// string operand to specify when subregister to use. This lint is issued
2442     /// if you pass in a value with a smaller data type than the default
2443     /// register size, to alert you of possibly using the incorrect width. To
2444     /// fix this, add the suggested modifier to the template, or cast the
2445     /// value to the correct size.
2446     ///
2447     /// See [register template modifiers] in the reference for more details.
2448     ///
2449     /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2450     pub ASM_SUB_REGISTER,
2451     Warn,
2452     "using only a subset of a register for inline asm inputs",
2453 }
2454
2455 declare_lint! {
2456     /// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2457     /// `.att_syntax` directives.
2458     ///
2459     /// ### Example
2460     ///
2461     /// ```rust,ignore (fails on non-x86_64)
2462     /// #[cfg(target_arch="x86_64")]
2463     /// use std::arch::asm;
2464     ///
2465     /// fn main() {
2466     ///     #[cfg(target_arch="x86_64")]
2467     ///     unsafe {
2468     ///         asm!(
2469     ///             ".att_syntax",
2470     ///             "movq %{0}, %{0}", in(reg) 0usize
2471     ///         );
2472     ///     }
2473     /// }
2474     /// ```
2475     ///
2476     /// This will produce:
2477     ///
2478     /// ```text
2479     /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2480     ///  --> src/main.rs:8:14
2481     ///   |
2482     /// 8 |             ".att_syntax",
2483     ///   |              ^^^^^^^^^^^
2484     ///   |
2485     ///   = note: `#[warn(bad_asm_style)]` on by default
2486     /// ```
2487     ///
2488     /// ### Explanation
2489     ///
2490     /// On x86, `asm!` uses the intel assembly syntax by default. While this
2491     /// can be switched using assembler directives like `.att_syntax`, using the
2492     /// `att_syntax` option is recommended instead because it will also properly
2493     /// prefix register placeholders with `%` as required by AT&T syntax.
2494     pub BAD_ASM_STYLE,
2495     Warn,
2496     "incorrect use of inline assembly",
2497 }
2498
2499 declare_lint! {
2500     /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2501     /// functions without an explicit unsafe block.
2502     ///
2503     /// ### Example
2504     ///
2505     /// ```rust,compile_fail
2506     /// #![deny(unsafe_op_in_unsafe_fn)]
2507     ///
2508     /// unsafe fn foo() {}
2509     ///
2510     /// unsafe fn bar() {
2511     ///     foo();
2512     /// }
2513     ///
2514     /// fn main() {}
2515     /// ```
2516     ///
2517     /// {{produces}}
2518     ///
2519     /// ### Explanation
2520     ///
2521     /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2522     /// body. However, this can increase the surface area of code that needs
2523     /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2524     /// convenient way to make it clear exactly which parts of the code are
2525     /// performing unsafe operations. In the future, it is desired to change
2526     /// it so that unsafe operations cannot be performed in an `unsafe fn`
2527     /// without an `unsafe` block.
2528     ///
2529     /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2530     ///
2531     /// This lint is "allow" by default since this will affect a large amount
2532     /// of existing code, and the exact plan for increasing the severity is
2533     /// still being considered. See [RFC #2585] and [issue #71668] for more
2534     /// details.
2535     ///
2536     /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2537     /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2538     /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2539     /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2540     /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2541     pub UNSAFE_OP_IN_UNSAFE_FN,
2542     Allow,
2543     "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2544 }
2545
2546 declare_lint! {
2547     /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2548     /// `enum` that implements [`Drop`].
2549     ///
2550     /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2551     ///
2552     /// ### Example
2553     ///
2554     /// ```rust,compile_fail
2555     /// # #![allow(unused)]
2556     /// enum E {
2557     ///     A,
2558     /// }
2559     ///
2560     /// impl Drop for E {
2561     ///     fn drop(&mut self) {
2562     ///         println!("Drop");
2563     ///     }
2564     /// }
2565     ///
2566     /// fn main() {
2567     ///     let e = E::A;
2568     ///     let i = e as u32;
2569     /// }
2570     /// ```
2571     ///
2572     /// {{produces}}
2573     ///
2574     /// ### Explanation
2575     ///
2576     /// Casting a field-less `enum` that does not implement [`Copy`] to an
2577     /// integer moves the value without calling `drop`. This can result in
2578     /// surprising behavior if it was expected that `drop` should be called.
2579     /// Calling `drop` automatically would be inconsistent with other move
2580     /// operations. Since neither behavior is clear or consistent, it was
2581     /// decided that a cast of this nature will no longer be allowed.
2582     ///
2583     /// This is a [future-incompatible] lint to transition this to a hard error
2584     /// in the future. See [issue #73333] for more details.
2585     ///
2586     /// [future-incompatible]: ../index.md#future-incompatible-lints
2587     /// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
2588     /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
2589     pub CENUM_IMPL_DROP_CAST,
2590     Deny,
2591     "a C-like enum implementing Drop is cast",
2592     @future_incompatible = FutureIncompatibleInfo {
2593         reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
2594         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2595     };
2596 }
2597
2598 declare_lint! {
2599     /// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
2600     /// and a pointer.
2601     ///
2602     /// ### Example
2603     ///
2604     /// ```rust
2605     /// #![feature(strict_provenance)]
2606     /// #![warn(fuzzy_provenance_casts)]
2607     ///
2608     /// fn main() {
2609     ///     let _dangling = 16_usize as *const u8;
2610     /// }
2611     /// ```
2612     ///
2613     /// {{produces}}
2614     ///
2615     /// ### Explanation
2616     ///
2617     /// This lint is part of the strict provenance effort, see [issue #95228].
2618     /// Casting an integer to a pointer is considered bad style, as a pointer
2619     /// contains, besides the *address* also a *provenance*, indicating what
2620     /// memory the pointer is allowed to read/write. Casting an integer, which
2621     /// doesn't have provenance, to a pointer requires the compiler to assign
2622     /// (guess) provenance. The compiler assigns "all exposed valid" (see the
2623     /// docs of [`ptr::from_exposed_addr`] for more information about this
2624     /// "exposing"). This penalizes the optimiser and is not well suited for
2625     /// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
2626     /// platforms).
2627     ///
2628     /// It is much better to use [`ptr::with_addr`] instead to specify the
2629     /// provenance you want. If using this function is not possible because the
2630     /// code relies on exposed provenance then there is as an escape hatch
2631     /// [`ptr::from_exposed_addr`].
2632     ///
2633     /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2634     /// [`ptr::with_addr`]: https://doc.rust-lang.org/core/ptr/fn.with_addr
2635     /// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr
2636     pub FUZZY_PROVENANCE_CASTS,
2637     Allow,
2638     "a fuzzy integer to pointer cast is used",
2639     @feature_gate = sym::strict_provenance;
2640 }
2641
2642 declare_lint! {
2643     /// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
2644     /// and an integer.
2645     ///
2646     /// ### Example
2647     ///
2648     /// ```rust
2649     /// #![feature(strict_provenance)]
2650     /// #![warn(lossy_provenance_casts)]
2651     ///
2652     /// fn main() {
2653     ///     let x: u8 = 37;
2654     ///     let _addr: usize = &x as *const u8 as usize;
2655     /// }
2656     /// ```
2657     ///
2658     /// {{produces}}
2659     ///
2660     /// ### Explanation
2661     ///
2662     /// This lint is part of the strict provenance effort, see [issue #95228].
2663     /// Casting a pointer to an integer is a lossy operation, because beyond
2664     /// just an *address* a pointer may be associated with a particular
2665     /// *provenance*. This information is used by the optimiser and for dynamic
2666     /// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
2667     ///
2668     /// Since this cast is lossy, it is considered good style to use the
2669     /// [`ptr::addr`] method instead, which has a similar effect, but doesn't
2670     /// "expose" the pointer provenance. This improves optimisation potential.
2671     /// See the docs of [`ptr::addr`] and [`ptr::expose_addr`] for more information
2672     /// about exposing pointer provenance.
2673     ///
2674     /// If your code can't comply with strict provenance and needs to expose
2675     /// the provenance, then there is [`ptr::expose_addr`] as an escape hatch,
2676     /// which preserves the behaviour of `as usize` casts while being explicit
2677     /// about the semantics.
2678     ///
2679     /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2680     /// [`ptr::addr`]: https://doc.rust-lang.org/core/ptr/fn.addr
2681     /// [`ptr::expose_addr`]: https://doc.rust-lang.org/core/ptr/fn.expose_addr
2682     pub LOSSY_PROVENANCE_CASTS,
2683     Allow,
2684     "a lossy pointer to integer cast is used",
2685     @feature_gate = sym::strict_provenance;
2686 }
2687
2688 declare_lint! {
2689     /// The `const_evaluatable_unchecked` lint detects a generic constant used
2690     /// in a type.
2691     ///
2692     /// ### Example
2693     ///
2694     /// ```rust
2695     /// const fn foo<T>() -> usize {
2696     ///     if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2697     ///         4
2698     ///     } else {
2699     ///         8
2700     ///     }
2701     /// }
2702     ///
2703     /// fn test<T>() {
2704     ///     let _ = [0; foo::<T>()];
2705     /// }
2706     /// ```
2707     ///
2708     /// {{produces}}
2709     ///
2710     /// ### Explanation
2711     ///
2712     /// In the 1.43 release, some uses of generic parameters in array repeat
2713     /// expressions were accidentally allowed. This is a [future-incompatible]
2714     /// lint to transition this to a hard error in the future. See [issue
2715     /// #76200] for a more detailed description and possible fixes.
2716     ///
2717     /// [future-incompatible]: ../index.md#future-incompatible-lints
2718     /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2719     pub CONST_EVALUATABLE_UNCHECKED,
2720     Warn,
2721     "detects a generic constant is used in a type without a emitting a warning",
2722     @future_incompatible = FutureIncompatibleInfo {
2723         reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2724     };
2725 }
2726
2727 declare_lint! {
2728     /// The `function_item_references` lint detects function references that are
2729     /// formatted with [`fmt::Pointer`] or transmuted.
2730     ///
2731     /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2732     ///
2733     /// ### Example
2734     ///
2735     /// ```rust
2736     /// fn foo() { }
2737     ///
2738     /// fn main() {
2739     ///     println!("{:p}", &foo);
2740     /// }
2741     /// ```
2742     ///
2743     /// {{produces}}
2744     ///
2745     /// ### Explanation
2746     ///
2747     /// Taking a reference to a function may be mistaken as a way to obtain a
2748     /// pointer to that function. This can give unexpected results when
2749     /// formatting the reference as a pointer or transmuting it. This lint is
2750     /// issued when function references are formatted as pointers, passed as
2751     /// arguments bound by [`fmt::Pointer`] or transmuted.
2752     pub FUNCTION_ITEM_REFERENCES,
2753     Warn,
2754     "suggest casting to a function pointer when attempting to take references to function items",
2755 }
2756
2757 declare_lint! {
2758     /// The `uninhabited_static` lint detects uninhabited statics.
2759     ///
2760     /// ### Example
2761     ///
2762     /// ```rust
2763     /// enum Void {}
2764     /// extern {
2765     ///     static EXTERN: Void;
2766     /// }
2767     /// ```
2768     ///
2769     /// {{produces}}
2770     ///
2771     /// ### Explanation
2772     ///
2773     /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2774     /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2775     /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2776     /// statics). This was accidentally allowed, but is being phased out.
2777     pub UNINHABITED_STATIC,
2778     Warn,
2779     "uninhabited static",
2780     @future_incompatible = FutureIncompatibleInfo {
2781         reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2782     };
2783 }
2784
2785 declare_lint! {
2786     /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2787     ///
2788     /// ### Example
2789     ///
2790     /// ```rust,compile_fail
2791     /// struct X;
2792     ///
2793     /// #[deprecated = "message"]
2794     /// impl Default for X {
2795     ///     fn default() -> Self {
2796     ///         X
2797     ///     }
2798     /// }
2799     /// ```
2800     ///
2801     /// {{produces}}
2802     ///
2803     /// ### Explanation
2804     ///
2805     /// Deprecation attributes have no effect on trait implementations.
2806     pub USELESS_DEPRECATED,
2807     Deny,
2808     "detects deprecation attributes with no effect",
2809 }
2810
2811 declare_lint! {
2812     /// The `undefined_naked_function_abi` lint detects naked function definitions that
2813     /// either do not specify an ABI or specify the Rust ABI.
2814     ///
2815     /// ### Example
2816     ///
2817     /// ```rust
2818     /// #![feature(asm_experimental_arch, naked_functions)]
2819     ///
2820     /// use std::arch::asm;
2821     ///
2822     /// #[naked]
2823     /// pub fn default_abi() -> u32 {
2824     ///     unsafe { asm!("", options(noreturn)); }
2825     /// }
2826     ///
2827     /// #[naked]
2828     /// pub extern "Rust" fn rust_abi() -> u32 {
2829     ///     unsafe { asm!("", options(noreturn)); }
2830     /// }
2831     /// ```
2832     ///
2833     /// {{produces}}
2834     ///
2835     /// ### Explanation
2836     ///
2837     /// The Rust ABI is currently undefined. Therefore, naked functions should
2838     /// specify a non-Rust ABI.
2839     pub UNDEFINED_NAKED_FUNCTION_ABI,
2840     Warn,
2841     "undefined naked function ABI"
2842 }
2843
2844 declare_lint! {
2845     /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2846     ///
2847     /// ### Example
2848     ///
2849     /// ```rust,compile_fail
2850     /// #![feature(staged_api)]
2851     ///
2852     /// #[derive(Clone)]
2853     /// #[stable(feature = "x", since = "1")]
2854     /// struct S {}
2855     ///
2856     /// #[unstable(feature = "y", issue = "none")]
2857     /// impl Copy for S {}
2858     /// ```
2859     ///
2860     /// {{produces}}
2861     ///
2862     /// ### Explanation
2863     ///
2864     /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2865     /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2866     pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2867     Deny,
2868     "detects `#[unstable]` on stable trait implementations for stable types"
2869 }
2870
2871 declare_lint! {
2872     /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2873     /// in macro bodies when the macro is invoked in expression position.
2874     /// This was previous accepted, but is being phased out.
2875     ///
2876     /// ### Example
2877     ///
2878     /// ```rust,compile_fail
2879     /// #![deny(semicolon_in_expressions_from_macros)]
2880     /// macro_rules! foo {
2881     ///     () => { true; }
2882     /// }
2883     ///
2884     /// fn main() {
2885     ///     let val = match true {
2886     ///         true => false,
2887     ///         _ => foo!()
2888     ///     };
2889     /// }
2890     /// ```
2891     ///
2892     /// {{produces}}
2893     ///
2894     /// ### Explanation
2895     ///
2896     /// Previous, Rust ignored trailing semicolon in a macro
2897     /// body when a macro was invoked in expression position.
2898     /// However, this makes the treatment of semicolons in the language
2899     /// inconsistent, and could lead to unexpected runtime behavior
2900     /// in some circumstances (e.g. if the macro author expects
2901     /// a value to be dropped).
2902     ///
2903     /// This is a [future-incompatible] lint to transition this
2904     /// to a hard error in the future. See [issue #79813] for more details.
2905     ///
2906     /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2907     /// [future-incompatible]: ../index.md#future-incompatible-lints
2908     pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2909     Warn,
2910     "trailing semicolon in macro body used as expression",
2911     @future_incompatible = FutureIncompatibleInfo {
2912         reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
2913     };
2914 }
2915
2916 declare_lint! {
2917     /// The `legacy_derive_helpers` lint detects derive helper attributes
2918     /// that are used before they are introduced.
2919     ///
2920     /// ### Example
2921     ///
2922     /// ```rust,ignore (needs extern crate)
2923     /// #[serde(rename_all = "camelCase")]
2924     /// #[derive(Deserialize)]
2925     /// struct S { /* fields */ }
2926     /// ```
2927     ///
2928     /// produces:
2929     ///
2930     /// ```text
2931     /// warning: derive helper attribute is used before it is introduced
2932     ///   --> $DIR/legacy-derive-helpers.rs:1:3
2933     ///    |
2934     ///  1 | #[serde(rename_all = "camelCase")]
2935     ///    |   ^^^^^
2936     /// ...
2937     ///  2 | #[derive(Deserialize)]
2938     ///    |          ----------- the attribute is introduced here
2939     /// ```
2940     ///
2941     /// ### Explanation
2942     ///
2943     /// Attributes like this work for historical reasons, but attribute expansion works in
2944     /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2945     /// into the future" at not yet expanded part of the item , but such attempts are not always
2946     /// reliable.
2947     ///
2948     /// To fix the warning place the helper attribute after its corresponding derive.
2949     /// ```rust,ignore (needs extern crate)
2950     /// #[derive(Deserialize)]
2951     /// #[serde(rename_all = "camelCase")]
2952     /// struct S { /* fields */ }
2953     /// ```
2954     pub LEGACY_DERIVE_HELPERS,
2955     Warn,
2956     "detects derive helper attributes that are used before they are introduced",
2957     @future_incompatible = FutureIncompatibleInfo {
2958         reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
2959     };
2960 }
2961
2962 declare_lint! {
2963     /// The `large_assignments` lint detects when objects of large
2964     /// types are being moved around.
2965     ///
2966     /// ### Example
2967     ///
2968     /// ```rust,ignore (can crash on some platforms)
2969     /// let x = [0; 50000];
2970     /// let y = x;
2971     /// ```
2972     ///
2973     /// produces:
2974     ///
2975     /// ```text
2976     /// warning: moving a large value
2977     ///   --> $DIR/move-large.rs:1:3
2978     ///   let y = x;
2979     ///           - Copied large value here
2980     /// ```
2981     ///
2982     /// ### Explanation
2983     ///
2984     /// When using a large type in a plain assignment or in a function
2985     /// argument, idiomatic code can be inefficient.
2986     /// Ideally appropriate optimizations would resolve this, but such
2987     /// optimizations are only done in a best-effort manner.
2988     /// This lint will trigger on all sites of large moves and thus allow the
2989     /// user to resolve them in code.
2990     pub LARGE_ASSIGNMENTS,
2991     Warn,
2992     "detects large moves or copies",
2993 }
2994
2995 declare_lint! {
2996     /// The `deprecated_cfg_attr_crate_type_name` lint detects uses of the
2997     /// `#![cfg_attr(..., crate_type = "...")]` and
2998     /// `#![cfg_attr(..., crate_name = "...")]` attributes to conditionally
2999     /// specify the crate type and name in the source code.
3000     ///
3001     /// ### Example
3002     ///
3003     /// ```rust,compile_fail
3004     /// #![cfg_attr(debug_assertions, crate_type = "lib")]
3005     /// ```
3006     ///
3007     /// {{produces}}
3008     ///
3009     ///
3010     /// ### Explanation
3011     ///
3012     /// The `#![crate_type]` and `#![crate_name]` attributes require a hack in
3013     /// the compiler to be able to change the used crate type and crate name
3014     /// after macros have been expanded. Neither attribute works in combination
3015     /// with Cargo as it explicitly passes `--crate-type` and `--crate-name` on
3016     /// the commandline. These values must match the value used in the source
3017     /// code to prevent an error.
3018     ///
3019     /// To fix the warning use `--crate-type` on the commandline when running
3020     /// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
3021     /// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
3022     pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3023     Deny,
3024     "detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
3025     @future_incompatible = FutureIncompatibleInfo {
3026         reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",
3027     };
3028 }
3029
3030 declare_lint! {
3031     /// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
3032     ///
3033     /// ### Example
3034     ///
3035     /// ```text
3036     /// rustc --check-cfg 'names()'
3037     /// ```
3038     ///
3039     /// ```rust,ignore (needs command line option)
3040     /// #[cfg(widnows)]
3041     /// fn foo() {}
3042     /// ```
3043     ///
3044     /// This will produce:
3045     ///
3046     /// ```text
3047     /// warning: unknown condition name used
3048     ///  --> lint_example.rs:1:7
3049     ///   |
3050     /// 1 | #[cfg(widnows)]
3051     ///   |       ^^^^^^^
3052     ///   |
3053     ///   = note: `#[warn(unexpected_cfgs)]` on by default
3054     /// ```
3055     ///
3056     /// ### Explanation
3057     ///
3058     /// This lint is only active when a `--check-cfg='names(...)'` option has been passed
3059     /// to the compiler and triggers whenever an unknown condition name or value is used.
3060     /// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
3061     /// well-knows names and values built into the compiler.
3062     pub UNEXPECTED_CFGS,
3063     Warn,
3064     "detects unexpected names and values in `#[cfg]` conditions",
3065 }
3066
3067 declare_lint! {
3068     /// The `repr_transparent_external_private_fields` lint
3069     /// detects types marked `#[repr(transparent)]` that (transitively)
3070     /// contain an external ZST type marked `#[non_exhaustive]` or containing
3071     /// private fields
3072     ///
3073     /// ### Example
3074     ///
3075     /// ```rust,ignore (needs external crate)
3076     /// #![deny(repr_transparent_external_private_fields)]
3077     /// use foo::NonExhaustiveZst;
3078     ///
3079     /// #[repr(transparent)]
3080     /// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3081     /// ```
3082     ///
3083     /// This will produce:
3084     ///
3085     /// ```text
3086     /// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
3087     ///  --> src/main.rs:5:28
3088     ///   |
3089     /// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3090     ///   |                            ^^^^^^^^^^^^^^^^
3091     ///   |
3092     /// note: the lint level is defined here
3093     ///  --> src/main.rs:1:9
3094     ///   |
3095     /// 1 | #![deny(repr_transparent_external_private_fields)]
3096     ///   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3097     ///   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3098     ///   = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3099     ///   = 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.
3100     /// ```
3101     ///
3102     /// ### Explanation
3103     ///
3104     /// Previous, Rust accepted fields that contain external private zero-sized types,
3105     /// even though it should not be a breaking change to add a non-zero-sized field to
3106     /// that private type.
3107     ///
3108     /// This is a [future-incompatible] lint to transition this
3109     /// to a hard error in the future. See [issue #78586] for more details.
3110     ///
3111     /// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
3112     /// [future-incompatible]: ../index.md#future-incompatible-lints
3113     pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3114     Warn,
3115     "transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
3116     @future_incompatible = FutureIncompatibleInfo {
3117         reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
3118     };
3119 }
3120
3121 declare_lint! {
3122     /// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3123     /// syntax that is discarded during attribute expansion.
3124     ///
3125     /// ### Example
3126     ///
3127     /// ```rust
3128     /// #[cfg(FALSE)]
3129     /// macro foo() {}
3130     /// ```
3131     ///
3132     /// {{produces}}
3133     ///
3134     /// ### Explanation
3135     ///
3136     /// The input to active attributes such as `#[cfg]` or procedural macro
3137     /// attributes is required to be valid syntax. Previously, the compiler only
3138     /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3139     /// and expanding procedural macros.
3140     ///
3141     /// To avoid relying on unstable syntax, move the use of unstable syntax
3142     /// into a position where the compiler does not parse the syntax, such as a
3143     /// functionlike macro.
3144     ///
3145     /// ```rust
3146     /// # #![deny(unstable_syntax_pre_expansion)]
3147     ///
3148     /// macro_rules! identity {
3149     ///    ( $($tokens:tt)* ) => { $($tokens)* }
3150     /// }
3151     ///
3152     /// #[cfg(FALSE)]
3153     /// identity! {
3154     ///    macro foo() {}
3155     /// }
3156     /// ```
3157     ///
3158     /// This is a [future-incompatible] lint to transition this
3159     /// to a hard error in the future. See [issue #65860] for more details.
3160     ///
3161     /// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
3162     /// [future-incompatible]: ../index.md#future-incompatible-lints
3163     pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3164     Warn,
3165     "unstable syntax can change at any point in the future, causing a hard error!",
3166     @future_incompatible = FutureIncompatibleInfo {
3167         reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
3168     };
3169 }
3170
3171 declare_lint_pass! {
3172     /// Does nothing as a lint pass, but registers some `Lint`s
3173     /// that are used by other parts of the compiler.
3174     HardwiredLints => [
3175         FORBIDDEN_LINT_GROUPS,
3176         ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
3177         ARITHMETIC_OVERFLOW,
3178         UNCONDITIONAL_PANIC,
3179         UNUSED_IMPORTS,
3180         UNUSED_EXTERN_CRATES,
3181         UNUSED_CRATE_DEPENDENCIES,
3182         UNUSED_QUALIFICATIONS,
3183         UNKNOWN_LINTS,
3184         UNFULFILLED_LINT_EXPECTATIONS,
3185         UNUSED_VARIABLES,
3186         UNUSED_ASSIGNMENTS,
3187         DEAD_CODE,
3188         UNREACHABLE_CODE,
3189         UNREACHABLE_PATTERNS,
3190         OVERLAPPING_RANGE_ENDPOINTS,
3191         BINDINGS_WITH_VARIANT_NAME,
3192         UNUSED_MACROS,
3193         UNUSED_MACRO_RULES,
3194         WARNINGS,
3195         UNUSED_FEATURES,
3196         STABLE_FEATURES,
3197         UNKNOWN_CRATE_TYPES,
3198         TRIVIAL_CASTS,
3199         TRIVIAL_NUMERIC_CASTS,
3200         PRIVATE_IN_PUBLIC,
3201         EXPORTED_PRIVATE_DEPENDENCIES,
3202         PUB_USE_OF_PRIVATE_EXTERN_CRATE,
3203         INVALID_TYPE_PARAM_DEFAULT,
3204         RENAMED_AND_REMOVED_LINTS,
3205         UNALIGNED_REFERENCES,
3206         CONST_ITEM_MUTATION,
3207         PATTERNS_IN_FNS_WITHOUT_BODY,
3208         MISSING_FRAGMENT_SPECIFIER,
3209         LATE_BOUND_LIFETIME_ARGUMENTS,
3210         ORDER_DEPENDENT_TRAIT_OBJECTS,
3211         COHERENCE_LEAK_CHECK,
3212         DEPRECATED,
3213         UNUSED_UNSAFE,
3214         UNUSED_MUT,
3215         UNCONDITIONAL_RECURSION,
3216         SINGLE_USE_LIFETIMES,
3217         UNUSED_LIFETIMES,
3218         UNUSED_LABELS,
3219         TYVAR_BEHIND_RAW_POINTER,
3220         ELIDED_LIFETIMES_IN_PATHS,
3221         BARE_TRAIT_OBJECTS,
3222         ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
3223         UNSTABLE_NAME_COLLISIONS,
3224         IRREFUTABLE_LET_PATTERNS,
3225         WHERE_CLAUSES_OBJECT_SAFETY,
3226         MACRO_USE_EXTERN_CRATE,
3227         MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
3228         ILL_FORMED_ATTRIBUTE_INPUT,
3229         CONFLICTING_REPR_HINTS,
3230         META_VARIABLE_MISUSE,
3231         DEPRECATED_IN_FUTURE,
3232         AMBIGUOUS_ASSOCIATED_ITEMS,
3233         INDIRECT_STRUCTURAL_MATCH,
3234         POINTER_STRUCTURAL_MATCH,
3235         NONTRIVIAL_STRUCTURAL_MATCH,
3236         SOFT_UNSTABLE,
3237         UNSTABLE_SYNTAX_PRE_EXPANSION,
3238         INLINE_NO_SANITIZE,
3239         BAD_ASM_STYLE,
3240         ASM_SUB_REGISTER,
3241         UNSAFE_OP_IN_UNSAFE_FN,
3242         INCOMPLETE_INCLUDE,
3243         CENUM_IMPL_DROP_CAST,
3244         FUZZY_PROVENANCE_CASTS,
3245         LOSSY_PROVENANCE_CASTS,
3246         CONST_EVALUATABLE_UNCHECKED,
3247         INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
3248         MUST_NOT_SUSPEND,
3249         UNINHABITED_STATIC,
3250         FUNCTION_ITEM_REFERENCES,
3251         USELESS_DEPRECATED,
3252         MISSING_ABI,
3253         INVALID_DOC_ATTRIBUTES,
3254         SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
3255         RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3256         LEGACY_DERIVE_HELPERS,
3257         PROC_MACRO_BACK_COMPAT,
3258         RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3259         LARGE_ASSIGNMENTS,
3260         RUST_2021_PRELUDE_COLLISIONS,
3261         RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3262         UNSUPPORTED_CALLING_CONVENTIONS,
3263         BREAK_WITH_LABEL_AND_LOOP,
3264         UNUSED_ATTRIBUTES,
3265         UNUSED_TUPLE_STRUCT_FIELDS,
3266         NON_EXHAUSTIVE_OMITTED_PATTERNS,
3267         TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3268         DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3269         DUPLICATE_MACRO_ATTRIBUTES,
3270         SUSPICIOUS_AUTO_TRAIT_IMPLS,
3271         DEPRECATED_WHERE_CLAUSE_LOCATION,
3272         TEST_UNSTABLE_LINT,
3273         FFI_UNWIND_CALLS,
3274         REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3275         NAMED_ARGUMENTS_USED_POSITIONALLY,
3276     ]
3277 }
3278
3279 declare_lint! {
3280     /// The `unused_doc_comments` lint detects doc comments that aren't used
3281     /// by `rustdoc`.
3282     ///
3283     /// ### Example
3284     ///
3285     /// ```rust
3286     /// /// docs for x
3287     /// let x = 12;
3288     /// ```
3289     ///
3290     /// {{produces}}
3291     ///
3292     /// ### Explanation
3293     ///
3294     /// `rustdoc` does not use doc comments in all positions, and so the doc
3295     /// comment will be ignored. Try changing it to a normal comment with `//`
3296     /// to avoid the warning.
3297     pub UNUSED_DOC_COMMENTS,
3298     Warn,
3299     "detects doc comments that aren't used by rustdoc"
3300 }
3301
3302 declare_lint! {
3303     /// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3304     /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3305     /// Rust 2018 and 2021.
3306     ///
3307     /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3308     /// and the field is captured by a closure and used with the assumption that said field implements
3309     /// the same trait as the root variable.
3310     ///
3311     /// ### Example of drop reorder
3312     ///
3313     /// ```rust,edition2018,compile_fail
3314     /// #![deny(rust_2021_incompatible_closure_captures)]
3315     /// # #![allow(unused)]
3316     ///
3317     /// struct FancyInteger(i32);
3318     ///
3319     /// impl Drop for FancyInteger {
3320     ///     fn drop(&mut self) {
3321     ///         println!("Just dropped {}", self.0);
3322     ///     }
3323     /// }
3324     ///
3325     /// struct Point { x: FancyInteger, y: FancyInteger }
3326     ///
3327     /// fn main() {
3328     ///   let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3329     ///
3330     ///   let c = || {
3331     ///      let x = p.x;
3332     ///   };
3333     ///
3334     ///   c();
3335     ///
3336     ///   // ... More code ...
3337     /// }
3338     /// ```
3339     ///
3340     /// {{produces}}
3341     ///
3342     /// ### Explanation
3343     ///
3344     /// In the above example, `p.y` will be dropped at the end of `f` instead of
3345     /// with `c` in Rust 2021.
3346     ///
3347     /// ### Example of auto-trait
3348     ///
3349     /// ```rust,edition2018,compile_fail
3350     /// #![deny(rust_2021_incompatible_closure_captures)]
3351     /// use std::thread;
3352     ///
3353     /// struct Pointer(*mut i32);
3354     /// unsafe impl Send for Pointer {}
3355     ///
3356     /// fn main() {
3357     ///     let mut f = 10;
3358     ///     let fptr = Pointer(&mut f as *mut i32);
3359     ///     thread::spawn(move || unsafe {
3360     ///         *fptr.0 = 20;
3361     ///     });
3362     /// }
3363     /// ```
3364     ///
3365     /// {{produces}}
3366     ///
3367     /// ### Explanation
3368     ///
3369     /// In the above example, only `fptr.0` is captured in Rust 2021.
3370     /// The field is of type `*mut i32`, which doesn't implement `Send`,
3371     /// making the code invalid as the field cannot be sent between threads safely.
3372     pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3373     Allow,
3374     "detects closures affected by Rust 2021 changes",
3375     @future_incompatible = FutureIncompatibleInfo {
3376         reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
3377         explain_reason: false,
3378     };
3379 }
3380
3381 declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3382
3383 declare_lint! {
3384     /// The `missing_abi` lint detects cases where the ABI is omitted from
3385     /// extern declarations.
3386     ///
3387     /// ### Example
3388     ///
3389     /// ```rust,compile_fail
3390     /// #![deny(missing_abi)]
3391     ///
3392     /// extern fn foo() {}
3393     /// ```
3394     ///
3395     /// {{produces}}
3396     ///
3397     /// ### Explanation
3398     ///
3399     /// Historically, Rust implicitly selected C as the ABI for extern
3400     /// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
3401     /// though this has not yet happened, and especially with their addition
3402     /// seeing the ABI easily will make code review easier.
3403     pub MISSING_ABI,
3404     Allow,
3405     "No declared ABI for extern declaration"
3406 }
3407
3408 declare_lint! {
3409     /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3410     /// misused.
3411     ///
3412     /// ### Example
3413     ///
3414     /// ```rust,compile_fail
3415     /// #![deny(warnings)]
3416     ///
3417     /// pub mod submodule {
3418     ///     #![doc(test(no_crate_inject))]
3419     /// }
3420     /// ```
3421     ///
3422     /// {{produces}}
3423     ///
3424     /// ### Explanation
3425     ///
3426     /// Previously, there were very like checks being performed on `#[doc(..)]`
3427     /// unlike the other attributes. It'll now catch all the issues that it
3428     /// silently ignored previously.
3429     pub INVALID_DOC_ATTRIBUTES,
3430     Warn,
3431     "detects invalid `#[doc(...)]` attributes",
3432     @future_incompatible = FutureIncompatibleInfo {
3433         reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
3434     };
3435 }
3436
3437 declare_lint! {
3438     /// The `proc_macro_back_compat` lint detects uses of old versions of certain
3439     /// proc-macro crates, which have hardcoded workarounds in the compiler.
3440     ///
3441     /// ### Example
3442     ///
3443     /// ```rust,ignore (needs-dependency)
3444     ///
3445     /// use time_macros_impl::impl_macros;
3446     /// struct Foo;
3447     /// impl_macros!(Foo);
3448     /// ```
3449     ///
3450     /// This will produce:
3451     ///
3452     /// ```text
3453     /// warning: using an old version of `time-macros-impl`
3454     ///   ::: $DIR/group-compat-hack.rs:27:5
3455     ///    |
3456     /// LL |     impl_macros!(Foo);
3457     ///    |     ------------------ in this macro invocation
3458     ///    |
3459     ///    = note: `#[warn(proc_macro_back_compat)]` on by default
3460     ///    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3461     ///    = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3462     ///    = 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
3463     ///    = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3464     /// ```
3465     ///
3466     /// ### Explanation
3467     ///
3468     /// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3469     /// causing older versions of certain crates to stop compiling.
3470     /// This is a [future-incompatible] lint to ease the transition to an error.
3471     /// See [issue #83125] for more details.
3472     ///
3473     /// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3474     /// [future-incompatible]: ../index.md#future-incompatible-lints
3475     pub PROC_MACRO_BACK_COMPAT,
3476     Deny,
3477     "detects usage of old versions of certain proc-macro crates",
3478     @future_incompatible = FutureIncompatibleInfo {
3479         reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3480         reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
3481     };
3482 }
3483
3484 declare_lint! {
3485     /// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3486     ///
3487     /// ### Example
3488     ///
3489     /// ```rust,compile_fail
3490     /// #![deny(rust_2021_incompatible_or_patterns)]
3491     ///
3492     /// macro_rules! match_any {
3493     ///     ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3494     ///         match $expr {
3495     ///             $(
3496     ///                 $( $pat => $expr_arm, )+
3497     ///             )+
3498     ///         }
3499     ///     };
3500     /// }
3501     ///
3502     /// fn main() {
3503     ///     let result: Result<i64, i32> = Err(42);
3504     ///     let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3505     ///     assert_eq!(int, 42);
3506     /// }
3507     /// ```
3508     ///
3509     /// {{produces}}
3510     ///
3511     /// ### Explanation
3512     ///
3513     /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3514     pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3515     Allow,
3516     "detects usage of old versions of or-patterns",
3517     @future_incompatible = FutureIncompatibleInfo {
3518         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>",
3519         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3520     };
3521 }
3522
3523 declare_lint! {
3524     /// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3525     /// with traits added to the prelude in future editions.
3526     ///
3527     /// ### Example
3528     ///
3529     /// ```rust,compile_fail
3530     /// #![deny(rust_2021_prelude_collisions)]
3531     ///
3532     /// trait Foo {
3533     ///     fn try_into(self) -> Result<String, !>;
3534     /// }
3535     ///
3536     /// impl Foo for &str {
3537     ///     fn try_into(self) -> Result<String, !> {
3538     ///         Ok(String::from(self))
3539     ///     }
3540     /// }
3541     ///
3542     /// fn main() {
3543     ///     let x: String = "3".try_into().unwrap();
3544     ///     //                  ^^^^^^^^
3545     ///     // This call to try_into matches both Foo:try_into and TryInto::try_into as
3546     ///     // `TryInto` has been added to the Rust prelude in 2021 edition.
3547     ///     println!("{x}");
3548     /// }
3549     /// ```
3550     ///
3551     /// {{produces}}
3552     ///
3553     /// ### Explanation
3554     ///
3555     /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3556     /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3557     /// results in an ambiguity as to which method/function to call when an existing `try_into`
3558     /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3559     /// is called directly on a type.
3560     ///
3561     /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3562     pub RUST_2021_PRELUDE_COLLISIONS,
3563     Allow,
3564     "detects the usage of trait methods which are ambiguous with traits added to the \
3565         prelude in future editions",
3566     @future_incompatible = FutureIncompatibleInfo {
3567         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>",
3568         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3569     };
3570 }
3571
3572 declare_lint! {
3573     /// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3574     /// prefix instead in Rust 2021.
3575     ///
3576     /// ### Example
3577     ///
3578     /// ```rust,edition2018,compile_fail
3579     /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3580     ///
3581     /// macro_rules! m {
3582     ///     (z $x:expr) => ();
3583     /// }
3584     ///
3585     /// m!(z"hey");
3586     /// ```
3587     ///
3588     /// {{produces}}
3589     ///
3590     /// ### Explanation
3591     ///
3592     /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3593     /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3594     /// considered a prefix for `"hey"`.
3595     ///
3596     /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3597     /// to keep them separated in Rust 2021.
3598     // Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3599     #[allow(rustdoc::invalid_rust_codeblocks)]
3600     pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3601     Allow,
3602     "identifiers that will be parsed as a prefix in Rust 2021",
3603     @future_incompatible = FutureIncompatibleInfo {
3604         reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>",
3605         reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3606     };
3607     crate_level_only
3608 }
3609
3610 declare_lint! {
3611     /// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3612     /// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3613     /// variants) on targets that cannot meaningfully be supported for the requested target.
3614     ///
3615     /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3616     /// code, because this calling convention was never specified for those targets.
3617     ///
3618     /// Historically MSVC toolchains have fallen back to the regular C calling convention for
3619     /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3620     /// hack across many more targets.
3621     ///
3622     /// ### Example
3623     ///
3624     /// ```rust,ignore (needs specific targets)
3625     /// extern "stdcall" fn stdcall() {}
3626     /// ```
3627     ///
3628     /// This will produce:
3629     ///
3630     /// ```text
3631     /// warning: use of calling convention not supported on this target
3632     ///   --> $DIR/unsupported.rs:39:1
3633     ///    |
3634     /// LL | extern "stdcall" fn stdcall() {}
3635     ///    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636     ///    |
3637     ///    = note: `#[warn(unsupported_calling_conventions)]` on by default
3638     ///    = warning: this was previously accepted by the compiler but is being phased out;
3639     ///               it will become a hard error in a future release!
3640     ///    = note: for more information, see issue ...
3641     /// ```
3642     ///
3643     /// ### Explanation
3644     ///
3645     /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3646     /// defined at all, but was previously accepted due to a bug in the implementation of the
3647     /// compiler.
3648     pub UNSUPPORTED_CALLING_CONVENTIONS,
3649     Warn,
3650     "use of unsupported calling convention",
3651     @future_incompatible = FutureIncompatibleInfo {
3652         reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
3653     };
3654 }
3655
3656 declare_lint! {
3657     /// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3658     /// an unlabeled loop as their value expression.
3659     ///
3660     /// ### Example
3661     ///
3662     /// ```rust
3663     /// 'label: loop {
3664     ///     break 'label loop { break 42; };
3665     /// };
3666     /// ```
3667     ///
3668     /// {{produces}}
3669     ///
3670     /// ### Explanation
3671     ///
3672     /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3673     /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3674     /// can also carry a value expression, which can be another loop. A labeled `break` with an
3675     /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3676     /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3677     /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3678     /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3679     /// in parentheses.
3680     pub BREAK_WITH_LABEL_AND_LOOP,
3681     Warn,
3682     "`break` expression with label and unlabeled loop as value expression"
3683 }
3684
3685 declare_lint! {
3686     /// The `non_exhaustive_omitted_patterns` lint detects when a wildcard (`_` or `..`) in a
3687     /// pattern for a `#[non_exhaustive]` struct or enum is reachable.
3688     ///
3689     /// ### Example
3690     ///
3691     /// ```rust,ignore (needs separate crate)
3692     /// // crate A
3693     /// #[non_exhaustive]
3694     /// pub enum Bar {
3695     ///     A,
3696     ///     B, // added variant in non breaking change
3697     /// }
3698     ///
3699     /// // in crate B
3700     /// #![feature(non_exhaustive_omitted_patterns_lint)]
3701     ///
3702     /// match Bar::A {
3703     ///     Bar::A => {},
3704     ///     #[warn(non_exhaustive_omitted_patterns)]
3705     ///     _ => {},
3706     /// }
3707     /// ```
3708     ///
3709     /// This will produce:
3710     ///
3711     /// ```text
3712     /// warning: reachable patterns not covered of non exhaustive enum
3713     ///    --> $DIR/reachable-patterns.rs:70:9
3714     ///    |
3715     /// LL |         _ => {}
3716     ///    |         ^ pattern `B` not covered
3717     ///    |
3718     ///  note: the lint level is defined here
3719     ///   --> $DIR/reachable-patterns.rs:69:16
3720     ///    |
3721     /// LL |         #[warn(non_exhaustive_omitted_patterns)]
3722     ///    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3723     ///    = help: ensure that all possible cases are being handled by adding the suggested match arms
3724     ///    = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3725     /// ```
3726     ///
3727     /// ### Explanation
3728     ///
3729     /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a
3730     /// (potentially redundant) wildcard when pattern-matching, to allow for future
3731     /// addition of fields or variants. The `non_exhaustive_omitted_patterns` lint
3732     /// detects when such a wildcard happens to actually catch some fields/variants.
3733     /// In other words, when the match without the wildcard would not be exhaustive.
3734     /// This lets the user be informed if new fields/variants were added.
3735     pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3736     Allow,
3737     "detect when patterns of types marked `non_exhaustive` are missed",
3738     @feature_gate = sym::non_exhaustive_omitted_patterns_lint;
3739 }
3740
3741 declare_lint! {
3742     /// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3743     /// change the visual representation of text on screen in a way that does not correspond to
3744     /// their on memory representation.
3745     ///
3746     /// ### Example
3747     ///
3748     /// ```rust,compile_fail
3749     /// #![deny(text_direction_codepoint_in_comment)]
3750     /// fn main() {
3751     ///     println!("{:?}"); // '‮');
3752     /// }
3753     /// ```
3754     ///
3755     /// {{produces}}
3756     ///
3757     /// ### Explanation
3758     ///
3759     /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3760     /// are written right-to-left, but a specially crafted comment can make code that will be
3761     /// compiled appear to be part of a comment, depending on the software used to read the code.
3762     /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3763     /// their use.
3764     pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3765     Deny,
3766     "invisible directionality-changing codepoints in comment"
3767 }
3768
3769 declare_lint! {
3770     /// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3771     /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3772     /// and `test_case`.
3773     ///
3774     /// ### Example
3775     ///
3776     /// ```rust,ignore (needs --test)
3777     /// #[test]
3778     /// #[test]
3779     /// fn foo() {}
3780     /// ```
3781     ///
3782     /// This will produce:
3783     ///
3784     /// ```text
3785     /// warning: duplicated attribute
3786     ///  --> src/lib.rs:2:1
3787     ///   |
3788     /// 2 | #[test]
3789     ///   | ^^^^^^^
3790     ///   |
3791     ///   = note: `#[warn(duplicate_macro_attributes)]` on by default
3792     /// ```
3793     ///
3794     /// ### Explanation
3795     ///
3796     /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3797     /// being duplicated may not be obvious or desirable.
3798     ///
3799     /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3800     /// change to its environment.
3801     ///
3802     /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3803     pub DUPLICATE_MACRO_ATTRIBUTES,
3804     Warn,
3805     "duplicated attribute"
3806 }
3807
3808 declare_lint! {
3809     /// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
3810     /// implementations of auto traits.
3811     ///
3812     /// ### Example
3813     ///
3814     /// ```rust
3815     /// struct Foo<T>(T);
3816     ///
3817     /// unsafe impl<T> Send for Foo<*const T> {}
3818     /// ```
3819     ///
3820     /// {{produces}}
3821     ///
3822     /// ### Explanation
3823     ///
3824     /// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
3825     /// in two different ways: either by writing an explicit impl or if
3826     /// all fields of the type implement that auto trait.
3827     ///
3828     /// The compiler disables the automatic implementation if an explicit one
3829     /// exists for given type constructor. The exact rules governing this
3830     /// are currently unsound, quite subtle, and will be modified in the future.
3831     /// This change will cause the automatic implementation to be disabled in more
3832     /// cases, potentially breaking some code.
3833     pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
3834     Warn,
3835     "the rules governing auto traits will change in the future",
3836     @future_incompatible = FutureIncompatibleInfo {
3837         reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
3838         reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
3839     };
3840 }
3841
3842 declare_lint! {
3843     /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3844     /// in an associated type.
3845     ///
3846     /// ### Example
3847     ///
3848     /// ```rust
3849     /// trait Trait {
3850     ///   type Assoc<'a> where Self: 'a;
3851     /// }
3852     ///
3853     /// impl Trait for () {
3854     ///   type Assoc<'a> where Self: 'a = ();
3855     /// }
3856     /// ```
3857     ///
3858     /// {{produces}}
3859     ///
3860     /// ### Explanation
3861     ///
3862     /// The preferred location for where clauses on associated types in impls
3863     /// is after the type. However, for most of generic associated types development,
3864     /// it was only accepted before the equals. To provide a transition period and
3865     /// further evaluate this change, both are currently accepted. At some point in
3866     /// the future, this may be disallowed at an edition boundary; but, that is
3867     /// undecided currently.
3868     pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3869     Warn,
3870     "deprecated where clause location"
3871 }
3872
3873 declare_lint! {
3874     /// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3875     ///
3876     /// ### Example
3877     ///
3878     /// ```rust
3879     /// #![allow(test_unstable_lint)]
3880     /// ```
3881     ///
3882     /// {{produces}}
3883     ///
3884     /// ### Explanation
3885     ///
3886     /// In order to test the behavior of unstable lints, a permanently-unstable
3887     /// lint is required. This lint can be used to trigger warnings and errors
3888     /// from the compiler related to unstable lints.
3889     pub TEST_UNSTABLE_LINT,
3890     Deny,
3891     "this unstable lint is only for testing",
3892     @feature_gate = sym::test_unstable_lint;
3893 }
3894
3895 declare_lint! {
3896     /// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3897     /// `C-unwind` or other FFI-unwind ABIs.
3898     ///
3899     /// ### Example
3900     ///
3901     /// ```rust,ignore (need FFI)
3902     /// #![feature(ffi_unwind_calls)]
3903     /// #![feature(c_unwind)]
3904     ///
3905     /// # mod impl {
3906     /// #     #[no_mangle]
3907     /// #     pub fn "C-unwind" fn foo() {}
3908     /// # }
3909     ///
3910     /// extern "C-unwind" {
3911     ///     fn foo();
3912     /// }
3913     ///
3914     /// fn bar() {
3915     ///     unsafe { foo(); }
3916     ///     let ptr: unsafe extern "C-unwind" fn() = foo;
3917     ///     unsafe { ptr(); }
3918     /// }
3919     /// ```
3920     ///
3921     /// {{produces}}
3922     ///
3923     /// ### Explanation
3924     ///
3925     /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3926     /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3927     /// that desire this ability it is therefore necessary to avoid such calls.
3928     pub FFI_UNWIND_CALLS,
3929     Allow,
3930     "call to foreign functions or function pointers with FFI-unwind ABI",
3931     @feature_gate = sym::c_unwind;
3932 }
3933
3934 declare_lint! {
3935     /// The `named_arguments_used_positionally` lint detects cases where named arguments are only
3936     /// used positionally in format strings. This usage is valid but potentially very confusing.
3937     ///
3938     /// ### Example
3939     ///
3940     /// ```rust,compile_fail
3941     /// #![deny(named_arguments_used_positionally)]
3942     /// fn main() {
3943     ///     let _x = 5;
3944     ///     println!("{}", _x = 1); // Prints 1, will trigger lint
3945     ///
3946     ///     println!("{}", _x); // Prints 5, no lint emitted
3947     ///     println!("{_x}", _x = _x); // Prints 5, no lint emitted
3948     /// }
3949     /// ```
3950     ///
3951     /// {{produces}}
3952     ///
3953     /// ### Explanation
3954     ///
3955     /// Rust formatting strings can refer to named arguments by their position, but this usage is
3956     /// potentially confusing. In particular, readers can incorrectly assume that the declaration
3957     /// of named arguments is an assignment (which would produce the unit type).
3958     /// For backwards compatibility, this is not a hard error.
3959     pub NAMED_ARGUMENTS_USED_POSITIONALLY,
3960     Warn,
3961     "named arguments in format used positionally"
3962 }