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