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