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