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