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