1 // ignore-tidy-filelength
2 //! Some lints that are built in to the compiler.
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`.
8 // ignore-tidy-filelength
10 use crate::{declare_lint, declare_lint_pass};
11 use rustc_span::edition::Edition;
12 use rustc_span::symbol::sym;
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.
22 /// #![forbid(warnings)]
23 /// #![deny(bad_style)]
30 /// ### Recommended fix
32 /// If your crate is using `#![forbid(warnings)]`,
33 /// we recommend that you change to `#![deny(warnings)]`.
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,
43 "applying forbid to lint-groups",
44 @future_incompatible = FutureIncompatibleInfo {
45 reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
51 /// The `ill_formed_attribute_input` lint detects ill-formed attribute
52 /// inputs that were previously accepted and used in practice.
56 /// ```rust,compile_fail
57 /// #[inline = "this is not valid"]
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.
71 /// Check the [attribute reference] for details on the valid inputs for
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,
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>",
88 /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
89 /// conflicting hints.
91 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
95 /// ```rust,compile_fail
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.
110 /// To correct the issue, remove one of the conflicting hints.
112 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
113 /// [future-incompatible]: ../index.md#future-incompatible-lints
114 pub CONFLICTING_REPR_HINTS,
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>",
124 /// The `meta_variable_misuse` lint detects possible meta-variable misuse
125 /// in macro definitions.
129 /// ```rust,compile_fail
130 /// #![deny(meta_variable_misuse)]
132 /// macro_rules! foo {
134 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
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*.
151 /// This lint is "allow" by default because it may have false positives
152 /// and other issues. See [issue #61053] for more details.
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,
158 "possible meta-variable misuse at macro definition"
162 /// The `incomplete_include` lint detects the use of the [`include!`]
163 /// macro with a file that contains more than one expression.
165 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
169 /// ```rust,ignore (needs separate file)
171 /// include!("foo.txt");
175 /// where the file `foo.txt` contains:
184 /// error: include macro expected single expression in source
187 /// 1 | println!("1");
190 /// = note: `#[deny(incomplete_include)]` on by default
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!
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].
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
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,
219 "trailing content in included file"
223 /// The `arithmetic_overflow` lint detects that an arithmetic operation
226 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
230 /// ```rust,compile_fail
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,
245 "arithmetic operation overflows"
249 /// The `unconditional_panic` lint detects an operation that will cause a
250 /// panic at runtime.
254 /// ```rust,compile_fail
255 /// # #![allow(unused)]
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,
269 "operation will cause a panic at runtime"
273 /// The `const_err` lint detects an erroneous expression while doing
274 /// constant evaluation.
278 /// ```rust,compile_fail
279 /// #![allow(unconditional_panic)]
280 /// const C: i32 = 1/0;
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.
292 /// [issue #71800]: https://github.com/rust-lang/rust/issues/71800
295 "constant evaluation encountered erroneous expression",
296 @future_incompatible = FutureIncompatibleInfo {
297 reference: "issue #71800 <https://github.com/rust-lang/rust/issues/71800>",
300 report_in_external_macro
304 /// The `unused_imports` lint detects imports that are never used.
309 /// use std::collections::HashMap;
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
322 "imports that are never used"
326 /// The `unused_extern_crates` lint guards against `extern crate` items
327 /// that are never used.
331 /// ```rust,compile_fail
332 /// #![deny(unused_extern_crates)]
333 /// extern crate proc_macro;
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.
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.
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,
357 "extern crates that are never used"
361 /// The `unused_crate_dependencies` lint detects crate dependencies that
366 /// ```rust,ignore (needs extern crate)
367 /// #![deny(unused_crate_dependencies)]
370 /// This will produce:
373 /// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
375 /// note: the lint level is defined here
376 /// --> src/lib.rs:1:9
378 /// 1 | #![deny(unused_crate_dependencies)]
379 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
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]).
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
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,
405 "crate dependencies that are never used",
410 /// The `unused_qualifications` lint detects unnecessarily qualified
415 /// ```rust,compile_fail
416 /// #![deny(unused_qualifications)]
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::`.
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,
440 "detects unnecessarily qualified names"
444 /// The `unknown_lints` lint detects unrecognized lint attribute.
449 /// #![allow(not_a_real_lint)]
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.
462 "unrecognized lint attribute"
466 /// The `unused_variables` lint detects variables which are not used in
479 /// Unused variables may signal a mistake or unfinished code. To silence
480 /// the warning for the individual variable, prefix it with an underscore
482 pub UNUSED_VARIABLES,
484 "detect variables which are not used in any way"
488 /// The `unused_assignments` lint detects assignments that will never be read.
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,
507 "detect assignments that will never be read"
511 /// The `dead_code` lint detects unused, unexported items.
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.
530 "detect unused, unexported items"
534 /// The `unused_attributes` lint detects attributes that were not used by
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
555 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
556 pub UNUSED_ATTRIBUTES,
558 "detects attributes that were not used by the compiler"
562 /// The `unreachable_code` lint detects unreachable code paths.
567 /// panic!("we never go past here!");
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,
580 "detects unreachable code paths",
581 report_in_external_macro
585 /// The `unreachable_patterns` lint detects unreachable patterns.
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,
607 "detects unreachable patterns"
611 /// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
612 /// overlap on their endpoints.
614 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
621 /// 0..=100 => { println!("small"); }
622 /// 100..=255 => { println!("large"); }
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,
635 "detects range patterns with overlapping endpoints"
639 /// The `bindings_with_variant_name` lint detects pattern bindings with
640 /// the same name as one of the matched variants.
650 /// pub fn foo(x: Enum) {
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.
668 /// Two possible solutions are:
670 /// * Specify the enum variant using a [path pattern], such as
672 /// * Bring the enum variants into local scope, such as adding `use
673 /// Enum::*;` to the beginning of the `foo` function in the example
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,
680 "detects pattern bindings with the same name as one of the matched variants"
684 /// The `unused_macros` lint detects macros that were not used.
689 /// macro_rules! unused {
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].
706 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
709 "detects macros that were not used"
713 /// The `warnings` lint allows you to change the level of other
714 /// lints which produce warnings.
719 /// #![deny(warnings)]
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
733 "mass-change the level for lints which produce warnings"
737 /// The `unused_features` lint detects unused or unknown features found in
738 /// crate-level [`feature` attributes].
740 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
742 /// Note: This lint is currently not functional, see [issue #44232] for
745 /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
748 "unused features found in crate-level `#[feature]` directives"
752 /// The `stable_features` lint detects a [`feature` attribute] that
753 /// has since been made stable.
755 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
760 /// #![feature(test_accepted_feature)]
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.
773 "stable features found in `#[feature]` directive"
777 /// The `unknown_crate_types` lint detects an unknown crate type found in
778 /// a [`crate_type` attribute].
782 /// ```rust,compile_fail
783 /// #![crate_type="lol"]
791 /// An unknown value give to the `crate_type` attribute is almost
792 /// certainly a mistake.
794 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
795 pub UNKNOWN_CRATE_TYPES,
797 "unknown crate type found in `#[crate_type]` directive",
802 /// The `trivial_casts` lint detects trivial casts which could be replaced
803 /// with coercion, which may require [type ascription] or a temporary
808 /// ```rust,compile_fail
809 /// #![deny(trivial_casts)]
810 /// let x: &u32 = &42;
811 /// let y = x as *const u32;
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.
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.
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
834 "detects trivial casts which could be removed"
838 /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
839 /// which could be removed.
843 /// ```rust,compile_fail
844 /// #![deny(trivial_numeric_casts)]
845 /// let x = 42_i32 as i32;
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.
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.
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,
867 "detects trivial casts of numeric types which could be removed"
871 /// The `private_in_public` lint detects private items in public
872 /// interfaces not caught by the old implementation.
877 /// # #![allow(unused)]
882 /// impl super::SemiPriv {
883 /// pub fn f(_: Priv) {}
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
898 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
899 /// [future-incompatible]: ../index.md#future-incompatible-lints
900 pub PRIVATE_IN_PUBLIC,
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>",
910 /// The `exported_private_dependencies` lint detects private dependencies
911 /// that are exposed in a public interface.
915 /// ```rust,ignore (needs-dependency)
916 /// pub fn foo() -> Option<some_private_dependency::Thing> {
921 /// This will produce:
924 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
925 /// --> src/lib.rs:3:1
927 /// 3 | pub fn foo() -> Option<bar::Thing> {
928 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
930 /// = note: `#[warn(exported_private_dependencies)]` on by default
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
942 /// To fix this, avoid exposing the dependency in your public interface.
943 /// Or, switch the dependency to a public dependency.
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].
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,
952 "public interface leaks type from a private dependency"
956 /// The `pub_use_of_private_extern_crate` lint detects a specific
957 /// situation of re-exporting a private `extern crate`.
961 /// ```rust,compile_fail
962 /// extern crate core;
963 /// pub use core as reexported_core;
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.
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.
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,
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>",
990 /// The `invalid_type_param_default` lint detects type parameter defaults
991 /// erroneously allowed in an invalid location.
995 /// ```rust,compile_fail
996 /// fn foo<T=i32>(t: T) {}
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.
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,
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>",
1020 /// The `renamed_and_removed_lints` lint detects lints that have been
1021 /// renamed or removed.
1026 /// #![deny(raw_pointer_derive)]
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,
1038 "lints that have been renamed or removed"
1042 /// The `unaligned_references` lint detects unaligned references to fields
1043 /// of [packed] structs.
1045 /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1049 /// ```rust,compile_fail
1050 /// #![deny(unaligned_references)]
1053 /// pub struct Foo {
1060 /// let foo = Foo { field1: 0, field2: 0 };
1061 /// let _ = &foo.field1;
1070 /// Creating a reference to an insufficiently aligned packed field is
1071 /// [undefined behavior] and should be disallowed.
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.
1077 /// See [issue #27060] for more discussion.
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,
1083 "detects unaligned references to fields of packed structs",
1087 /// The `const_item_mutation` lint detects attempts to mutate a `const`
1093 /// const FOO: [i32; 1] = [0];
1097 /// // This will print "[0]".
1098 /// println!("{:?}", FOO);
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.
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()`).
1117 /// There are various alternatives depending on what you are trying to
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
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.
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,
1151 "detects attempts to mutate a `const` item",
1155 /// The `safe_packed_borrows` lint detects borrowing a field in the
1156 /// interior of a packed structure with alignment other than 1.
1162 /// pub struct Unaligned<T>(pub T);
1164 /// pub struct Foo {
1166 /// data: Unaligned<u32>,
1170 /// let x = Foo { start: 0, data: Unaligned(1) };
1171 /// let y = &x.data.0;
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
1186 /// [issue #46043]: https://github.com/rust-lang/rust/issues/46043
1187 /// [future-incompatible]: ../index.md#future-incompatible-lints
1188 pub SAFE_PACKED_BORROWS,
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>",
1198 /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1199 /// patterns as a parameter in functions without a body.
1203 /// ```rust,compile_fail
1205 /// fn foo(mut arg: u8);
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:
1218 /// fn foo(arg: u8); // Removed `mut` here
1221 /// impl Trait for i32 {
1222 /// fn foo(mut arg: u8) { // `mut` here is OK
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.
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,
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>",
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`).
1255 /// This warning can always be fixed by removing the unused pattern in the
1256 /// `macro_rules!` macro definition.
1260 /// ```rust,compile_fail
1261 /// macro_rules! foo {
1275 /// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1278 /// macro_rules! foo {
1285 pub MISSING_FRAGMENT_SPECIFIER,
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>",
1295 /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1296 /// arguments in path segments with late bound lifetime parameters.
1304 /// fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
1308 /// S.late::<'static>(&0, &0);
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.
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,
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>",
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.
1343 /// ```rust,compile_fail
1344 /// pub trait Trait {}
1346 /// impl Trait for dyn Send + Sync { }
1347 /// impl Trait for dyn Sync + Send { }
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.
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,
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>",
1373 /// The `coherence_leak_check` lint detects conflicting implementations of
1374 /// a trait that are only distinguished by the old leak-check code.
1379 /// trait SomeTrait { }
1380 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1381 /// impl<'a> SomeTrait for fn(&'a u8) { }
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.
1395 /// Code relying on this pattern should introduce "[newtypes]",
1396 /// like `struct Foo(for<'a> fn(&'a u8))`.
1398 /// See [issue #56105] for more details.
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,
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>",
1413 /// The `deprecated` lint detects use of deprecated items.
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
1435 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1438 "detects use of deprecated items",
1439 report_in_external_macro
1443 /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1455 /// If nothing within the block requires `unsafe`, then remove the
1456 /// `unsafe` marker because it is not required and may cause confusion.
1459 "unnecessary use of an `unsafe` block"
1463 /// The `unused_mut` lint detects mut variables which don't need to be
1476 /// The preferred style is to only mark variables as `mut` if it is
1480 "detect mut variables which don't need to be mutable"
1484 /// The `unconditional_recursion` lint detects functions that cannot
1485 /// return without calling themselves.
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,
1504 "functions that cannot return without calling themselves"
1508 /// The `single_use_lifetimes` lint detects lifetimes that are only used
1513 /// ```rust,compile_fail
1514 /// #![deny(single_use_lifetimes)]
1516 /// fn foo<'a>(x: &'a u32) {}
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.
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.
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,
1538 "detects lifetime parameters that are only used once"
1542 /// The `unused_lifetimes` lint detects lifetime parameters that are never
1547 /// ```rust,compile_fail
1548 /// #[deny(unused_lifetimes)]
1550 /// pub fn foo<'a>() {}
1557 /// Unused lifetime parameters may signal a mistake or unfinished code.
1558 /// Consider removing the parameter.
1559 pub UNUSED_LIFETIMES,
1561 "detects lifetime parameters that are never used"
1565 /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1566 /// inference variable.
1570 /// ```rust,edition2015
1572 /// let data = std::ptr::null();
1573 /// let _ = &data as *const *const ();
1575 /// if data.is_null() {}
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
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.
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,
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),
1605 /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1606 /// lifetime parameters.
1610 /// ```rust,compile_fail
1611 /// #![deny(elided_lifetimes_in_paths)]
1612 /// struct Foo<'a> {
1616 /// fn foo(x: &Foo) {
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].
1629 /// This lint is "allow" by default because it has some known issues, and
1630 /// may require a significant transition for old code.
1632 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1633 pub ELIDED_LIFETIMES_IN_PATHS,
1635 "hidden lifetime parameters in types are deprecated",
1640 /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1648 /// fn takes_trait_object(_: Box<Trait>) {
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`].
1661 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1662 pub BARE_TRAIT_OBJECTS,
1664 "suggest using `dyn Trait` for trait objects"
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
1674 /// ```rust,edition2015,compile_fail
1675 /// #![deny(absolute_paths_not_starting_with_crate)]
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.
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.
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
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,
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),
1723 /// The `illegal_floating_point_literal_pattern` lint detects
1724 /// floating-point literals used in patterns.
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:
1751 /// y if y == 5.0 => {}
1756 /// This is a [future-incompatible] lint to transition this to a hard
1757 /// error in the future. See [issue #41620] for more details.
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,
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>",
1772 /// The `unstable_name_collisions` lint detects that you have used a name
1773 /// that the standard library plans to add in the future.
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}
1783 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1785 /// let x = vec![1, 2, 3];
1786 /// let _ = x.iter().is_sorted();
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.
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,
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>",
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.
1818 /// The `irrefutable_let_patterns` lint detects detects [irrefutable
1819 /// patterns] in [if-let] and [while-let] statements.
1826 /// if let _ = 123 {
1827 /// println!("always runs!");
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.
1844 /// See [RFC 2086] for more details.
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,
1854 "detects irrefutable patterns in if-let and while-let statements"
1858 /// The `unused_labels` lint detects [labels] that are never used.
1860 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1865 /// 'unused_label: loop {}
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
1877 "detects labels that are never used"
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].
1885 /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
1886 pub BROKEN_INTRA_DOC_LINKS,
1888 "failures in resolving intra-doc link targets"
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].
1896 /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
1897 pub PRIVATE_INTRA_DOC_LINKS,
1899 "linking from a public item to a private one"
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].
1907 /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
1908 pub INVALID_CODEBLOCK_ATTRIBUTES,
1910 "codeblock attribute looks a lot like a known one"
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].
1918 /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
1919 pub MISSING_CRATE_LEVEL_DOCS,
1921 "detects crates with no crate-level documentation"
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].
1929 /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
1930 pub MISSING_DOC_CODE_EXAMPLES,
1932 "detects publicly-exported items without code samples in their documentation"
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].
1940 /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
1941 pub PRIVATE_DOC_TESTS,
1943 "detects code samples in docs of private items not documented by rustdoc"
1947 /// The `invalid_html_tags` lint detects invalid HTML tags. This is a
1948 /// `rustdoc` only lint, see the documentation in the [rustdoc book].
1950 /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
1951 pub INVALID_HTML_TAGS,
1953 "detects invalid HTML tags in doc comments"
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].
1961 /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
1964 "detects URLs that could be written using only angle brackets"
1968 /// The `where_clauses_object_safety` lint detects for [object safety] of
1969 /// [where clauses].
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
1979 /// trait X { fn foo(&self) where Self: Trait; }
1981 /// impl X for () { fn foo(&self) {} }
1983 /// impl Trait for dyn X {}
1985 /// // Segfault at opt-level 0, SIGILL otherwise.
1986 /// pub fn main() { <dyn X as X>::foo(&()); }
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.
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,
2001 "checks the object safety of where clauses",
2002 @future_incompatible = FutureIncompatibleInfo {
2003 reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
2009 /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
2010 /// derives using inaccessible names from parent modules.
2014 /// ```rust,ignore (proc-macro)
2016 /// #![crate_type = "proc-macro"]
2018 /// extern crate proc_macro;
2020 /// use proc_macro::*;
2022 /// #[proc_macro_derive(Foo)]
2023 /// pub fn foo1(a: TokenStream) -> TokenStream {
2025 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2029 /// ```rust,ignore (needs-dependency)
2032 /// extern crate foo;
2034 /// struct Something;
2042 /// This will produce:
2045 /// warning: cannot find type `Something` in this scope
2046 /// --> src/main.rs:8:10
2048 /// 8 | #[derive(Foo)]
2049 /// | ^^^ names from parent modules are not accessible without an explicit import
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>
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
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,
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>",
2076 /// The `macro_use_extern_crate` lint detects the use of the
2077 /// [`macro_use` attribute].
2081 /// ```rust,ignore (needs extern crate)
2082 /// #![deny(macro_use_extern_crate)]
2085 /// extern crate serde_json;
2088 /// let _ = json!{{}};
2092 /// This will produce:
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
2098 /// 3 | #[macro_use]
2101 /// note: the lint level is defined here
2102 /// --> src/main.rs:1:9
2104 /// 1 | #![deny(macro_use_extern_crate)]
2105 /// | ^^^^^^^^^^^^^^^^^^^^^^
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].
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.
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,
2125 "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2126 via the module system"
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.
2134 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2138 /// ```rust,compile_fail
2139 /// macro_rules! define_exported {
2142 /// macro_rules! exported {
2148 /// define_exported!();
2151 /// crate::exported!();
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.
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,
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>",
2180 /// The `explicit_outlives_requirements` lint detects unnecessary
2181 /// lifetime bounds that can be inferred.
2185 /// ```rust,compile_fail
2186 /// # #![allow(unused)]
2187 /// #![deny(explicit_outlives_requirements)]
2189 /// struct SharedRef<'a, T>
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.
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.
2215 /// See [RFC 2093] for more details.
2217 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2218 pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2220 "outlives requirements can be inferred"
2224 /// The `indirect_structural_match` lint detects a `const` in a pattern
2225 /// that manually implements [`PartialEq`] and [`Eq`].
2227 /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2228 /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2232 /// ```rust,compile_fail
2233 /// #![deny(indirect_structural_match)]
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));
2242 /// match WRAP_INDIRECT_PARAM {
2243 /// WRAP_INDIRECT_PARAM => { }
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.
2258 /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2259 /// [future-incompatible]: ../index.md#future-incompatible-lints
2260 pub INDIRECT_STRUCTURAL_MATCH,
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>",
2270 /// The `deprecated_in_future` lint is internal to rustc and should not be
2271 /// used by user code.
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
2280 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
2281 pub DEPRECATED_IN_FUTURE,
2283 "detects use of items that will be deprecated in a future version",
2284 report_in_external_macro
2288 /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2289 /// cannot be relied upon across compiler versions and optimization levels.
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;
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,
2318 "pointers are not structural-match",
2319 @future_incompatible = FutureIncompatibleInfo {
2320 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
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
2333 /// ```rust,compile_fail
2334 /// #![deny(nontrivial_structural_match)]
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 { }
2341 /// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2342 /// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
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
2354 pub NONTRIVIAL_STRUCTURAL_MATCH,
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>",
2365 /// The `ambiguous_associated_items` lint detects ambiguity between
2366 /// [associated items] and [enum variants].
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
2373 /// ```rust,compile_fail
2380 /// fn foo() -> Self::V;
2385 /// // `Self::V` is ambiguous because it may refer to the associated type or
2386 /// // the enum variant.
2387 /// fn foo() -> Self::V { 0 }
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.
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.
2405 /// This is a [future-incompatible] lint to transition this to a hard
2406 /// error in the future. See [issue #57644] for more details.
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,
2415 "ambiguous associated items",
2416 @future_incompatible = FutureIncompatibleInfo {
2417 reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2423 /// The `mutable_borrow_reservation_conflict` lint detects the reservation
2424 /// of a two-phased borrow that conflicts with other shared borrows.
2429 /// let mut v = vec![0, 1, 2];
2430 /// let shared = &v;
2431 /// v.push(shared.len());
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.
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,
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>",
2454 /// The `soft_unstable` lint detects unstable features that were
2455 /// unintentionally allowed on stable.
2459 /// ```rust,compile_fail
2461 /// extern crate test;
2464 /// fn name(b: &mut test::Bencher) {
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.
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
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>",
2496 /// The `inline_no_sanitize` lint detects incompatible use of
2497 /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
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
2505 /// #![feature(no_sanitize)]
2507 /// #[inline(always)]
2508 /// #[no_sanitize(address)]
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,
2525 "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2529 /// The `asm_sub_register` lint detects using only a subset of a register
2530 /// for inline asm inputs.
2534 /// ```rust,ignore (fails on system llvm)
2535 /// #![feature(asm)]
2538 /// #[cfg(target_arch="x86_64")]
2540 /// asm!("mov {0}, {0}", in(reg) 0i16);
2545 /// This will produce:
2548 /// warning: formatting may not be suitable for sub-register argument
2549 /// --> src/main.rs:6:19
2551 /// 6 | asm!("mov {0}, {0}", in(reg) 0i16);
2552 /// | ^^^ ^^^ ---- for this argument
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`
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.
2571 /// See [register template modifiers] for more details.
2573 /// [register template modifiers]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#register-template-modifiers
2574 pub ASM_SUB_REGISTER,
2576 "using only a subset of a register for inline asm inputs",
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.
2585 /// [**nightly channel**]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2589 /// ```rust,compile_fail
2590 /// #![feature(unsafe_block_in_unsafe_fn)]
2591 /// #![deny(unsafe_op_in_unsafe_fn)]
2593 /// unsafe fn foo() {}
2595 /// unsafe fn bar() {
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.
2614 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
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
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,
2627 "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2628 @feature_gate = sym::unsafe_block_in_unsafe_fn;
2632 /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2633 /// `enum` that implements [`Drop`].
2635 /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2640 /// # #![allow(unused)]
2645 /// impl Drop for E {
2646 /// fn drop(&mut self) {
2647 /// println!("Drop");
2653 /// let i = e as u32;
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.
2668 /// This is a [future-incompatible] lint to transition this to a hard error
2669 /// in the future. See [issue #73333] for more details.
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,
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>",
2684 /// The `const_evaluatable_unchecked` lint detects a generic constant used
2690 /// const fn foo<T>() -> usize {
2691 /// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2699 /// let _ = [0; foo::<T>()];
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.
2712 /// [future-incompatible]: ../index.md#future-incompatible-lints
2713 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2714 pub CONST_EVALUATABLE_UNCHECKED,
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>",
2724 /// The `function_item_references` lint detects function references that are
2725 /// formatted with [`fmt::Pointer`] or transmuted.
2727 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2735 /// println!("{:p}", &foo);
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,
2750 "suggest casting to a function pointer when attempting to take references to function items",
2754 /// The `uninhabited_static` lint detects uninhabited statics.
2761 /// static EXTERN: Void;
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,
2775 "uninhabited static",
2776 @future_incompatible = FutureIncompatibleInfo {
2777 reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2783 /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2787 /// ```rust,compile_fail
2790 /// #[deprecated = "message"]
2791 /// impl Default for X {
2792 /// fn default() -> Self {
2802 /// Deprecation attributes have no effect on trait implementations.
2803 pub USELESS_DEPRECATED,
2805 "detects deprecation attributes with no effect",
2809 /// The `unsupported_naked_functions` lint detects naked function
2810 /// definitions that are unsupported but were previously accepted.
2815 /// #![feature(naked_functions)]
2818 /// pub fn f() -> u32 {
2827 /// The naked functions must be defined using a single inline assembly
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.
2834 /// The asm block must not contain any operands other than `const` and
2835 /// `sym`. Additionally, naked function should specify a non-Rust ABI.
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
2842 /// [future-incompatible]: ../index.md#future-incompatible-lints
2843 pub UNSUPPORTED_NAKED_FUNCTIONS,
2845 "unsupported naked function definitions",
2846 @future_incompatible = FutureIncompatibleInfo {
2847 reference: "issue #32408 <https://github.com/rust-lang/rust/issues/32408>",
2853 /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2858 /// #![feature(staged_api)]
2860 /// #[derive(Clone)]
2861 /// #[stable(feature = "x", since = "1")]
2864 /// #[unstable(feature = "y", issue = "none")]
2865 /// impl Copy for S {}
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,
2876 "detects `#[unstable]` on stable trait implementations for stable types"
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.
2886 /// ```rust,compile_fail
2887 /// #![deny(semicolon_in_expressions_from_macros)]
2888 /// macro_rules! foo {
2893 /// let val = match true {
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).
2911 /// This is a [future-incompatible] lint to transition this
2912 /// to a hard error in the future. See [issue #79813] for more details.
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,
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>",
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.
2929 FORBIDDEN_LINT_GROUPS,
2930 ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
2931 ARITHMETIC_OVERFLOW,
2932 UNCONDITIONAL_PANIC,
2934 UNUSED_EXTERN_CRATES,
2935 UNUSED_CRATE_DEPENDENCIES,
2936 UNUSED_QUALIFICATIONS,
2942 UNREACHABLE_PATTERNS,
2943 OVERLAPPING_RANGE_ENDPOINTS,
2944 BINDINGS_WITH_VARIANT_NAME,
2949 UNKNOWN_CRATE_TYPES,
2951 TRIVIAL_NUMERIC_CASTS,
2953 EXPORTED_PRIVATE_DEPENDENCIES,
2954 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
2955 INVALID_TYPE_PARAM_DEFAULT,
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,
2969 UNCONDITIONAL_RECURSION,
2970 SINGLE_USE_LIFETIMES,
2973 TYVAR_BEHIND_RAW_POINTER,
2974 ELIDED_LIFETIMES_IN_PATHS,
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,
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,
3003 UNSAFE_OP_IN_UNSAFE_FN,
3005 CENUM_IMPL_DROP_CAST,
3006 CONST_EVALUATABLE_UNCHECKED,
3007 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
3009 FUNCTION_ITEM_REFERENCES,
3011 UNSUPPORTED_NAKED_FUNCTIONS,
3013 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
3014 DISJOINT_CAPTURE_DROP_REORDER,
3019 /// The `unused_doc_comments` lint detects doc comments that aren't used
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,
3038 "detects doc comments that aren't used by rustdoc"
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.
3048 /// ```rust,compile_fail
3049 /// # #![deny(disjoint_capture_drop_reorder)]
3050 /// # #![allow(unused)]
3051 /// struct FancyInteger(i32);
3053 /// impl Drop for FancyInteger {
3054 /// fn drop(&mut self) {
3055 /// println!("Just dropped {}", self.0);
3059 /// struct Point { x: FancyInteger, y: FancyInteger }
3062 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3070 /// // ... More code ...
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,
3082 "Drop reorder because of `capture_disjoint_fields`"
3086 declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3089 /// The `missing_abi` lint detects cases where the ABI is omitted from
3090 /// extern declarations.
3094 /// ```rust,compile_fail
3095 /// #![deny(missing_abi)]
3097 /// extern fn foo() {}
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.
3110 "No declared ABI for extern declaration"