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