1 // ignore-tidy-filelength
3 //! Some lints that are built in to the compiler.
5 //! These are the built-in lints that are emitted direct in the main
6 //! compiler code, rather than using their own custom pass. Those
7 //! lints are all available in `rustc_lint::builtin`.
9 use crate::{declare_lint, declare_lint_pass, FutureBreakage};
10 use rustc_span::edition::Edition;
13 /// The `forbidden_lint_groups` lint detects violations of
14 /// `forbid` applied to a lint group. Due to a bug in the compiler,
15 /// these used to be overlooked entirely. They now generate a warning.
20 /// #![forbid(warnings)]
21 /// #![deny(bad_style)]
28 /// ### Recommended fix
30 /// If your crate is using `#![forbid(warnings)]`,
31 /// we recommend that you change to `#![deny(warnings)]`.
35 /// Due to a compiler bug, applying `forbid` to lint groups
36 /// previously had no effect. The bug is now fixed but instead of
37 /// enforcing `forbid` we issue this future-compatibility warning
38 /// to avoid breaking existing crates.
39 pub FORBIDDEN_LINT_GROUPS,
41 "applying forbid to lint-groups",
42 @future_incompatible = FutureIncompatibleInfo {
43 reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
49 /// The `ill_formed_attribute_input` lint detects ill-formed attribute
50 /// inputs that were previously accepted and used in practice.
54 /// ```rust,compile_fail
55 /// #[inline = "this is not valid"]
63 /// Previously, inputs for many built-in attributes weren't validated and
64 /// nonsensical attribute inputs were accepted. After validation was
65 /// added, it was determined that some existing projects made use of these
66 /// invalid forms. This is a [future-incompatible] lint to transition this
67 /// to a hard error in the future. See [issue #57571] for more details.
69 /// Check the [attribute reference] for details on the valid inputs for
72 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
73 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
74 /// [future-incompatible]: ../index.md#future-incompatible-lints
75 pub ILL_FORMED_ATTRIBUTE_INPUT,
77 "ill-formed attribute inputs that were previously accepted and used in practice",
78 @future_incompatible = FutureIncompatibleInfo {
79 reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
86 /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
87 /// conflicting hints.
89 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
93 /// ```rust,compile_fail
104 /// The compiler incorrectly accepted these conflicting representations in
105 /// the past. This is a [future-incompatible] lint to transition this to a
106 /// hard error in the future. See [issue #68585] for more details.
108 /// To correct the issue, remove one of the conflicting hints.
110 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
111 /// [future-incompatible]: ../index.md#future-incompatible-lints
112 pub CONFLICTING_REPR_HINTS,
114 "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
115 @future_incompatible = FutureIncompatibleInfo {
116 reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
122 /// The `meta_variable_misuse` lint detects possible meta-variable misuse
123 /// in macro definitions.
127 /// ```rust,compile_fail
128 /// #![deny(meta_variable_misuse)]
130 /// macro_rules! foo {
132 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
144 /// There are quite a few different ways a [`macro_rules`] macro can be
145 /// improperly defined. Many of these errors were previously only detected
146 /// when the macro was expanded or not at all. This lint is an attempt to
147 /// catch some of these problems when the macro is *defined*.
149 /// This lint is "allow" by default because it may have false positives
150 /// and other issues. See [issue #61053] for more details.
152 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
153 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
154 pub META_VARIABLE_MISUSE,
156 "possible meta-variable misuse at macro definition"
160 /// The `incomplete_include` lint detects the use of the [`include!`]
161 /// macro with a file that contains more than one expression.
163 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
167 /// ```rust,ignore (needs separate file)
169 /// include!("foo.txt");
173 /// where the file `foo.txt` contains:
182 /// error: include macro expected single expression in source
185 /// 1 | println!("1");
188 /// = note: `#[deny(incomplete_include)]` on by default
193 /// The [`include!`] macro is currently only intended to be used to
194 /// include a single [expression] or multiple [items]. Historically it
195 /// would ignore any contents after the first expression, but that can be
196 /// confusing. In the example above, the `println!` expression ends just
197 /// before the semicolon, making the semicolon "extra" information that is
198 /// ignored. Perhaps even more surprising, if the included file had
199 /// multiple print statements, the subsequent ones would be ignored!
201 /// One workaround is to place the contents in braces to create a [block
202 /// expression]. Also consider alternatives, like using functions to
203 /// encapsulate the expressions, or use [proc-macros].
205 /// This is a lint instead of a hard error because existing projects were
206 /// found to hit this error. To be cautious, it is a lint for now. The
207 /// future semantics of the `include!` macro are also uncertain, see
210 /// [items]: https://doc.rust-lang.org/reference/items.html
211 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
212 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
213 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
214 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
215 pub INCOMPLETE_INCLUDE,
217 "trailing content in included file"
221 /// The `arithmetic_overflow` lint detects that an arithmetic operation
224 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
228 /// ```rust,compile_fail
236 /// It is very likely a mistake to perform an arithmetic operation that
237 /// overflows its value. If the compiler is able to detect these kinds of
238 /// overflows at compile-time, it will trigger this lint. Consider
239 /// adjusting the expression to avoid overflow, or use a data type that
240 /// will not overflow.
241 pub ARITHMETIC_OVERFLOW,
243 "arithmetic operation overflows"
247 /// The `unconditional_panic` lint detects an operation that will cause a
248 /// panic at runtime.
252 /// ```rust,compile_fail
253 /// # #![allow(unused)]
261 /// This lint detects code that is very likely incorrect because it will
262 /// always panic, such as division by zero and out-of-bounds array
263 /// accesses. Consider adjusting your code if this is a bug, or using the
264 /// `panic!` or `unreachable!` macro instead in case the panic is intended.
265 pub UNCONDITIONAL_PANIC,
267 "operation will cause a panic at runtime"
271 /// The `const_err` lint detects an erroneous expression while doing
272 /// constant evaluation.
276 /// ```rust,compile_fail
277 /// #![allow(unconditional_panic)]
278 /// const C: i32 = 1/0;
285 /// This lint detects constants that fail to evaluate. Allowing the lint will accept the
286 /// constant declaration, but any use of this constant will still lead to a hard error. This is
287 /// a future incompatibility lint; the plan is to eventually entirely forbid even declaring
288 /// constants that cannot be evaluated. See [issue #71800] for more details.
290 /// [issue #71800]: https://github.com/rust-lang/rust/issues/71800
293 "constant evaluation encountered erroneous expression",
294 @future_incompatible = FutureIncompatibleInfo {
295 reference: "issue #71800 <https://github.com/rust-lang/rust/issues/71800>",
298 report_in_external_macro
302 /// The `unused_imports` lint detects imports that are never used.
307 /// use std::collections::HashMap;
314 /// Unused imports may signal a mistake or unfinished code, and clutter
315 /// the code, and should be removed. If you intended to re-export the item
316 /// to make it available outside of the module, add a visibility modifier
320 "imports that are never used"
324 /// The `unused_extern_crates` lint guards against `extern crate` items
325 /// that are never used.
329 /// ```rust,compile_fail
330 /// #![deny(unused_extern_crates)]
331 /// extern crate proc_macro;
338 /// `extern crate` items that are unused have no effect and should be
339 /// removed. Note that there are some cases where specifying an `extern
340 /// crate` is desired for the side effect of ensuring the given crate is
341 /// linked, even though it is not otherwise directly referenced. The lint
342 /// can be silenced by aliasing the crate to an underscore, such as
343 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
344 /// use `extern crate` in the [2018 edition], as extern crates are now
345 /// automatically added in scope.
347 /// This lint is "allow" by default because it can be noisy, and produce
348 /// false-positives. If a dependency is being removed from a project, it
349 /// is recommended to remove it from the build configuration (such as
350 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
352 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
353 pub UNUSED_EXTERN_CRATES,
355 "extern crates that are never used"
359 /// The `unused_crate_dependencies` lint detects crate dependencies that
364 /// ```rust,ignore (needs extern crate)
365 /// #![deny(unused_crate_dependencies)]
368 /// This will produce:
371 /// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
373 /// note: the lint level is defined here
374 /// --> src/lib.rs:1:9
376 /// 1 | #![deny(unused_crate_dependencies)]
377 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
382 /// After removing the code that uses a dependency, this usually also
383 /// requires removing the dependency from the build configuration.
384 /// However, sometimes that step can be missed, which leads to time wasted
385 /// building dependencies that are no longer used. This lint can be
386 /// enabled to detect dependencies that are never used (more specifically,
387 /// any dependency passed with the `--extern` command-line flag that is
388 /// never referenced via [`use`], [`extern crate`], or in any [path]).
390 /// This lint is "allow" by default because it can provide false positives
391 /// depending on how the build system is configured. For example, when
392 /// using Cargo, a "package" consists of multiple crates (such as a
393 /// library and a binary), but the dependencies are defined for the
394 /// package as a whole. If there is a dependency that is only used in the
395 /// binary, but not the library, then the lint will be incorrectly issued
398 /// [path]: https://doc.rust-lang.org/reference/paths.html
399 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
400 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
401 pub UNUSED_CRATE_DEPENDENCIES,
403 "crate dependencies that are never used",
408 /// The `unused_qualifications` lint detects unnecessarily qualified
413 /// ```rust,compile_fail
414 /// #![deny(unused_qualifications)]
429 /// If an item from another module is already brought into scope, then
430 /// there is no need to qualify it in this case. You can call `bar()`
431 /// directly, without the `foo::`.
433 /// This lint is "allow" by default because it is somewhat pedantic, and
434 /// doesn't indicate an actual problem, but rather a stylistic choice, and
435 /// can be noisy when refactoring or moving around code.
436 pub UNUSED_QUALIFICATIONS,
438 "detects unnecessarily qualified names"
442 /// The `unknown_lints` lint detects unrecognized lint attribute.
447 /// #![allow(not_a_real_lint)]
454 /// It is usually a mistake to specify a lint that does not exist. Check
455 /// the spelling, and check the lint listing for the correct name. Also
456 /// consider if you are using an old version of the compiler, and the lint
457 /// is only available in a newer version.
460 "unrecognized lint attribute"
464 /// The `unused_variables` lint detects variables which are not used in
477 /// Unused variables may signal a mistake or unfinished code. To silence
478 /// the warning for the individual variable, prefix it with an underscore
480 pub UNUSED_VARIABLES,
482 "detect variables which are not used in any way"
486 /// The `unused_assignments` lint detects assignments that will never be read.
499 /// Unused assignments may signal a mistake or unfinished code. If the
500 /// variable is never used after being assigned, then the assignment can
501 /// be removed. Variables with an underscore prefix such as `_x` will not
502 /// trigger this lint.
503 pub UNUSED_ASSIGNMENTS,
505 "detect assignments that will never be read"
509 /// The `dead_code` lint detects unused, unexported items.
521 /// Dead code may signal a mistake or unfinished code. To silence the
522 /// warning for individual items, prefix the name with an underscore such
523 /// as `_foo`. If it was intended to expose the item outside of the crate,
524 /// consider adding a visibility modifier like `pub`. Otherwise consider
525 /// removing the unused code.
528 "detect unused, unexported items"
532 /// The `unused_attributes` lint detects attributes that were not used by
545 /// Unused [attributes] may indicate the attribute is placed in the wrong
546 /// position. Consider removing it, or placing it in the correct position.
547 /// Also consider if you intended to use an _inner attribute_ (with a `!`
548 /// such as `#![allow(unused)]`) which applies to the item the attribute
549 /// is within, or an _outer attribute_ (without a `!` such as
550 /// `#[allow(unused)]`) which applies to the item *following* the
553 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
554 pub UNUSED_ATTRIBUTES,
556 "detects attributes that were not used by the compiler"
560 /// The `unreachable_code` lint detects unreachable code paths.
565 /// panic!("we never go past here!");
574 /// Unreachable code may signal a mistake or unfinished code. If the code
575 /// is no longer in use, consider removing it.
576 pub UNREACHABLE_CODE,
578 "detects unreachable code paths",
579 report_in_external_macro
583 /// The `unreachable_patterns` lint detects unreachable patterns.
599 /// This usually indicates a mistake in how the patterns are specified or
600 /// ordered. In this example, the `y` pattern will always match, so the
601 /// five is impossible to reach. Remember, match arms match in order, you
602 /// probably wanted to put the `5` case above the `y` case.
603 pub UNREACHABLE_PATTERNS,
605 "detects unreachable patterns"
609 /// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
610 /// overlap on their endpoints.
612 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
619 /// 0..=100 => { println!("small"); }
620 /// 100..=255 => { println!("large"); }
628 /// It is likely a mistake to have range patterns in a match expression that overlap in this
629 /// way. Check that the beginning and end values are what you expect, and keep in mind that
630 /// with `..=` the left and right bounds are inclusive.
631 pub OVERLAPPING_RANGE_ENDPOINTS,
633 "detects range patterns with overlapping endpoints"
637 /// The `bindings_with_variant_name` lint detects pattern bindings with
638 /// the same name as one of the matched variants.
648 /// pub fn foo(x: Enum) {
660 /// It is usually a mistake to specify an enum variant name as an
661 /// [identifier pattern]. In the example above, the `match` arms are
662 /// specifying a variable name to bind the value of `x` to. The second arm
663 /// is ignored because the first one matches *all* values. The likely
664 /// intent is that the arm was intended to match on the enum variant.
666 /// Two possible solutions are:
668 /// * Specify the enum variant using a [path pattern], such as
670 /// * Bring the enum variants into local scope, such as adding `use
671 /// Enum::*;` to the beginning of the `foo` function in the example
674 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
675 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
676 pub BINDINGS_WITH_VARIANT_NAME,
678 "detects pattern bindings with the same name as one of the matched variants"
682 /// The `unused_macros` lint detects macros that were not used.
687 /// macro_rules! unused {
699 /// Unused macros may signal a mistake or unfinished code. To silence the
700 /// warning for the individual macro, prefix the name with an underscore
701 /// such as `_my_macro`. If you intended to export the macro to make it
702 /// available outside of the crate, use the [`macro_export` attribute].
704 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
707 "detects macros that were not used"
711 /// The `warnings` lint allows you to change the level of other
712 /// lints which produce warnings.
717 /// #![deny(warnings)]
725 /// The `warnings` lint is a bit special; by changing its level, you
726 /// change every other warning that would produce a warning to whatever
727 /// value you'd like. As such, you won't ever trigger this lint in your
731 "mass-change the level for lints which produce warnings"
735 /// The `unused_features` lint detects unused or unknown features found in
736 /// crate-level [`feature` attributes].
738 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
740 /// Note: This lint is currently not functional, see [issue #44232] for
743 /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
746 "unused features found in crate-level `#[feature]` directives"
750 /// The `stable_features` lint detects a [`feature` attribute] that
751 /// has since been made stable.
753 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
758 /// #![feature(test_accepted_feature)]
766 /// When a feature is stabilized, it is no longer necessary to include a
767 /// `#![feature]` attribute for it. To fix, simply remove the
768 /// `#![feature]` attribute.
771 "stable features found in `#[feature]` directive"
775 /// The `unknown_crate_types` lint detects an unknown crate type found in
776 /// a [`crate_type` attribute].
780 /// ```rust,compile_fail
781 /// #![crate_type="lol"]
789 /// An unknown value give to the `crate_type` attribute is almost
790 /// certainly a mistake.
792 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
793 pub UNKNOWN_CRATE_TYPES,
795 "unknown crate type found in `#[crate_type]` directive",
800 /// The `trivial_casts` lint detects trivial casts which could be replaced
801 /// with coercion, which may require [type ascription] or a temporary
806 /// ```rust,compile_fail
807 /// #![deny(trivial_casts)]
808 /// let x: &u32 = &42;
809 /// let y = x as *const u32;
816 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
817 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
818 /// usually be inferred.
820 /// This lint is "allow" by default because there are situations, such as
821 /// with FFI interfaces or complex type aliases, where it triggers
822 /// incorrectly, or in situations where it will be more difficult to
823 /// clearly express the intent. It may be possible that this will become a
824 /// warning in the future, possibly with [type ascription] providing a
825 /// convenient way to work around the current issues. See [RFC 401] for
826 /// historical context.
828 /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
829 /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
832 "detects trivial casts which could be removed"
836 /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
837 /// which could be removed.
841 /// ```rust,compile_fail
842 /// #![deny(trivial_numeric_casts)]
843 /// let x = 42_i32 as i32;
850 /// A trivial numeric cast is a cast of a numeric type to the same numeric
851 /// type. This type of cast is usually unnecessary.
853 /// This lint is "allow" by default because there are situations, such as
854 /// with FFI interfaces or complex type aliases, where it triggers
855 /// incorrectly, or in situations where it will be more difficult to
856 /// clearly express the intent. It may be possible that this will become a
857 /// warning in the future, possibly with [type ascription] providing a
858 /// convenient way to work around the current issues. See [RFC 401] for
859 /// historical context.
861 /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
862 /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
863 pub TRIVIAL_NUMERIC_CASTS,
865 "detects trivial casts of numeric types which could be removed"
869 /// The `private_in_public` lint detects private items in public
870 /// interfaces not caught by the old implementation.
875 /// # #![allow(unused)]
880 /// impl super::SemiPriv {
881 /// pub fn f(_: Priv) {}
891 /// The visibility rules are intended to prevent exposing private items in
892 /// public interfaces. This is a [future-incompatible] lint to transition
893 /// this to a hard error in the future. See [issue #34537] for more
896 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
897 /// [future-incompatible]: ../index.md#future-incompatible-lints
898 pub PRIVATE_IN_PUBLIC,
900 "detect private items in public interfaces not caught by the old implementation",
901 @future_incompatible = FutureIncompatibleInfo {
902 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
908 /// The `exported_private_dependencies` lint detects private dependencies
909 /// that are exposed in a public interface.
913 /// ```rust,ignore (needs-dependency)
914 /// pub fn foo() -> Option<some_private_dependency::Thing> {
919 /// This will produce:
922 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
923 /// --> src/lib.rs:3:1
925 /// 3 | pub fn foo() -> Option<bar::Thing> {
926 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
928 /// = note: `#[warn(exported_private_dependencies)]` on by default
933 /// Dependencies can be marked as "private" to indicate that they are not
934 /// exposed in the public interface of a crate. This can be used by Cargo
935 /// to independently resolve those dependencies because it can assume it
936 /// does not need to unify them with other packages using that same
937 /// dependency. This lint is an indication of a violation of that
940 /// To fix this, avoid exposing the dependency in your public interface.
941 /// Or, switch the dependency to a public dependency.
943 /// Note that support for this is only available on the nightly channel.
944 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
946 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
947 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
948 pub EXPORTED_PRIVATE_DEPENDENCIES,
950 "public interface leaks type from a private dependency"
954 /// The `pub_use_of_private_extern_crate` lint detects a specific
955 /// situation of re-exporting a private `extern crate`.
959 /// ```rust,compile_fail
960 /// extern crate core;
961 /// pub use core as reexported_core;
968 /// A public `use` declaration should not be used to publicly re-export a
969 /// private `extern crate`. `pub extern crate` should be used instead.
971 /// This was historically allowed, but is not the intended behavior
972 /// according to the visibility rules. This is a [future-incompatible]
973 /// lint to transition this to a hard error in the future. See [issue
974 /// #34537] for more details.
976 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
977 /// [future-incompatible]: ../index.md#future-incompatible-lints
978 pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
980 "detect public re-exports of private extern crates",
981 @future_incompatible = FutureIncompatibleInfo {
982 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
988 /// The `invalid_type_param_default` lint detects type parameter defaults
989 /// erroneously allowed in an invalid location.
993 /// ```rust,compile_fail
994 /// fn foo<T=i32>(t: T) {}
1001 /// Default type parameters were only intended to be allowed in certain
1002 /// situations, but historically the compiler allowed them everywhere.
1003 /// This is a [future-incompatible] lint to transition this to a hard
1004 /// error in the future. See [issue #36887] for more details.
1006 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1007 /// [future-incompatible]: ../index.md#future-incompatible-lints
1008 pub INVALID_TYPE_PARAM_DEFAULT,
1010 "type parameter default erroneously allowed in invalid location",
1011 @future_incompatible = FutureIncompatibleInfo {
1012 reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
1018 /// The `renamed_and_removed_lints` lint detects lints that have been
1019 /// renamed or removed.
1024 /// #![deny(raw_pointer_derive)]
1031 /// To fix this, either remove the lint or use the new name. This can help
1032 /// avoid confusion about lints that are no longer valid, and help
1033 /// maintain consistency for renamed lints.
1034 pub RENAMED_AND_REMOVED_LINTS,
1036 "lints that have been renamed or removed"
1040 /// The `unaligned_references` lint detects unaligned references to fields
1041 /// of [packed] structs.
1043 /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1047 /// ```rust,compile_fail
1048 /// #![deny(unaligned_references)]
1051 /// pub struct Foo {
1058 /// let foo = Foo { field1: 0, field2: 0 };
1059 /// let _ = &foo.field1;
1060 /// println!("{}", foo.field1); // An implicit `&` is added here, triggering the lint.
1069 /// Creating a reference to an insufficiently aligned packed field is [undefined behavior] and
1070 /// should be disallowed. Using an `unsafe` block does not change anything about this. Instead,
1071 /// the code should do a copy of the data in the packed field or use raw pointers and unaligned
1072 /// accesses. See [issue #82523] for more information.
1074 /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1075 /// [issue #82523]: https://github.com/rust-lang/rust/issues/82523
1076 pub UNALIGNED_REFERENCES,
1078 "detects unaligned references to fields of packed structs",
1079 @future_incompatible = FutureIncompatibleInfo {
1080 reference: "issue #82523 <https://github.com/rust-lang/rust/issues/82523>",
1083 report_in_external_macro
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 `patterns_in_fns_without_body` lint detects `mut` identifier
1156 /// patterns as a parameter in functions without a body.
1160 /// ```rust,compile_fail
1162 /// fn foo(mut arg: u8);
1170 /// To fix this, remove `mut` from the parameter in the trait definition;
1171 /// it can be used in the implementation. That is, the following is OK:
1175 /// fn foo(arg: u8); // Removed `mut` here
1178 /// impl Trait for i32 {
1179 /// fn foo(mut arg: u8) { // `mut` here is OK
1185 /// Trait definitions can define functions without a body to specify a
1186 /// function that implementors must define. The parameter names in the
1187 /// body-less functions are only allowed to be `_` or an [identifier] for
1188 /// documentation purposes (only the type is relevant). Previous versions
1189 /// of the compiler erroneously allowed [identifier patterns] with the
1190 /// `mut` keyword, but this was not intended to be allowed. This is a
1191 /// [future-incompatible] lint to transition this to a hard error in the
1192 /// future. See [issue #35203] for more details.
1194 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1195 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1196 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1197 /// [future-incompatible]: ../index.md#future-incompatible-lints
1198 pub PATTERNS_IN_FNS_WITHOUT_BODY,
1200 "patterns in functions without body were erroneously allowed",
1201 @future_incompatible = FutureIncompatibleInfo {
1202 reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1208 /// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1209 /// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1210 /// followed by a fragment specifier (e.g. `:expr`).
1212 /// This warning can always be fixed by removing the unused pattern in the
1213 /// `macro_rules!` macro definition.
1217 /// ```rust,compile_fail
1218 /// macro_rules! foo {
1232 /// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1235 /// macro_rules! foo {
1242 pub MISSING_FRAGMENT_SPECIFIER,
1244 "detects missing fragment specifiers in unused `macro_rules!` patterns",
1245 @future_incompatible = FutureIncompatibleInfo {
1246 reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1252 /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1253 /// arguments in path segments with late bound lifetime parameters.
1261 /// fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
1265 /// S.late::<'static>(&0, &0);
1273 /// It is not clear how to provide arguments for early-bound lifetime
1274 /// parameters if they are intermixed with late-bound parameters in the
1275 /// same list. For now, providing any explicit arguments will trigger this
1276 /// lint if late-bound parameters are present, so in the future a solution
1277 /// can be adopted without hitting backward compatibility issues. This is
1278 /// a [future-incompatible] lint to transition this to a hard error in the
1279 /// future. See [issue #42868] for more details, along with a description
1280 /// of the difference between early and late-bound parameters.
1282 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1283 /// [future-incompatible]: ../index.md#future-incompatible-lints
1284 pub LATE_BOUND_LIFETIME_ARGUMENTS,
1286 "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1287 @future_incompatible = FutureIncompatibleInfo {
1288 reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1294 /// The `order_dependent_trait_objects` lint detects a trait coherency
1295 /// violation that would allow creating two trait impls for the same
1296 /// dynamic trait object involving marker traits.
1300 /// ```rust,compile_fail
1301 /// pub trait Trait {}
1303 /// impl Trait for dyn Send + Sync { }
1304 /// impl Trait for dyn Sync + Send { }
1311 /// A previous bug caused the compiler to interpret traits with different
1312 /// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1313 /// when they were intended to be treated the same. This allowed code to
1314 /// define separate trait implementations when there should be a coherence
1315 /// error. This is a [future-incompatible] lint to transition this to a
1316 /// hard error in the future. See [issue #56484] for more details.
1318 /// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1319 /// [future-incompatible]: ../index.md#future-incompatible-lints
1320 pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1322 "trait-object types were treated as different depending on marker-trait order",
1323 @future_incompatible = FutureIncompatibleInfo {
1324 reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1330 /// The `coherence_leak_check` lint detects conflicting implementations of
1331 /// a trait that are only distinguished by the old leak-check code.
1336 /// trait SomeTrait { }
1337 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1338 /// impl<'a> SomeTrait for fn(&'a u8) { }
1345 /// In the past, the compiler would accept trait implementations for
1346 /// identical functions that differed only in where the lifetime binder
1347 /// appeared. Due to a change in the borrow checker implementation to fix
1348 /// several bugs, this is no longer allowed. However, since this affects
1349 /// existing code, this is a [future-incompatible] lint to transition this
1350 /// to a hard error in the future.
1352 /// Code relying on this pattern should introduce "[newtypes]",
1353 /// like `struct Foo(for<'a> fn(&'a u8))`.
1355 /// See [issue #56105] for more details.
1357 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1358 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1359 /// [future-incompatible]: ../index.md#future-incompatible-lints
1360 pub COHERENCE_LEAK_CHECK,
1362 "distinct impls distinguished only by the leak-check code",
1363 @future_incompatible = FutureIncompatibleInfo {
1364 reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1370 /// The `deprecated` lint detects use of deprecated items.
1387 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1388 /// indicate that they should no longer be used. Usually the attribute
1389 /// should include a note on what to use instead, or check the
1392 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1395 "detects use of deprecated items",
1396 report_in_external_macro
1400 /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1412 /// If nothing within the block requires `unsafe`, then remove the
1413 /// `unsafe` marker because it is not required and may cause confusion.
1416 "unnecessary use of an `unsafe` block"
1420 /// The `unused_mut` lint detects mut variables which don't need to be
1433 /// The preferred style is to only mark variables as `mut` if it is
1437 "detect mut variables which don't need to be mutable"
1441 /// The `unconditional_recursion` lint detects functions that cannot
1442 /// return without calling themselves.
1456 /// It is usually a mistake to have a recursive call that does not have
1457 /// some condition to cause it to terminate. If you really intend to have
1458 /// an infinite loop, using a `loop` expression is recommended.
1459 pub UNCONDITIONAL_RECURSION,
1461 "functions that cannot return without calling themselves"
1465 /// The `single_use_lifetimes` lint detects lifetimes that are only used
1470 /// ```rust,compile_fail
1471 /// #![deny(single_use_lifetimes)]
1473 /// fn foo<'a>(x: &'a u32) {}
1480 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1481 /// should only be used to link together two things. Otherwise, you should
1482 /// just use `'_` to indicate that the lifetime is not linked to anything,
1483 /// or elide the lifetime altogether if possible.
1485 /// This lint is "allow" by default because it was introduced at a time
1486 /// when `'_` and elided lifetimes were first being introduced, and this
1487 /// lint would be too noisy. Also, there are some known false positives
1488 /// that it produces. See [RFC 2115] for historical context, and [issue
1489 /// #44752] for more details.
1491 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1492 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1493 pub SINGLE_USE_LIFETIMES,
1495 "detects lifetime parameters that are only used once"
1499 /// The `unused_lifetimes` lint detects lifetime parameters that are never
1504 /// ```rust,compile_fail
1505 /// #[deny(unused_lifetimes)]
1507 /// pub fn foo<'a>() {}
1514 /// Unused lifetime parameters may signal a mistake or unfinished code.
1515 /// Consider removing the parameter.
1516 pub UNUSED_LIFETIMES,
1518 "detects lifetime parameters that are never used"
1522 /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1523 /// inference variable.
1527 /// ```rust,edition2015
1529 /// let data = std::ptr::null();
1530 /// let _ = &data as *const *const ();
1532 /// if data.is_null() {}
1539 /// This kind of inference was previously allowed, but with the future
1540 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1541 /// resolve this, use an explicit type instead of relying on type
1544 /// This is a [future-incompatible] lint to transition this to a hard
1545 /// error in the 2018 edition. See [issue #46906] for more details. This
1546 /// is currently a hard-error on the 2018 edition, and is "warn" by
1547 /// default in the 2015 edition.
1549 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1550 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1551 /// [future-incompatible]: ../index.md#future-incompatible-lints
1552 pub TYVAR_BEHIND_RAW_POINTER,
1554 "raw pointer to an inference variable",
1555 @future_incompatible = FutureIncompatibleInfo {
1556 reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1557 edition: Some(Edition::Edition2018),
1562 /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1563 /// lifetime parameters.
1567 /// ```rust,compile_fail
1568 /// #![deny(elided_lifetimes_in_paths)]
1569 /// struct Foo<'a> {
1573 /// fn foo(x: &Foo) {
1581 /// Elided lifetime parameters can make it difficult to see at a glance
1582 /// that borrowing is occurring. This lint ensures that lifetime
1583 /// parameters are always explicitly stated, even if it is the `'_`
1584 /// [placeholder lifetime].
1586 /// This lint is "allow" by default because it has some known issues, and
1587 /// may require a significant transition for old code.
1589 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1590 pub ELIDED_LIFETIMES_IN_PATHS,
1592 "hidden lifetime parameters in types are deprecated",
1597 /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1605 /// fn takes_trait_object(_: Box<Trait>) {
1613 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1614 /// reading code as to whether or not you are looking at a trait object.
1615 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1616 /// with [`impl Trait`].
1618 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1619 pub BARE_TRAIT_OBJECTS,
1621 "suggest using `dyn Trait` for trait objects",
1622 @future_incompatible = FutureIncompatibleInfo {
1623 reference: "issue #80165 <https://github.com/rust-lang/rust/issues/80165>",
1624 edition: Some(Edition::Edition2021),
1629 /// The `absolute_paths_not_starting_with_crate` lint detects fully
1630 /// qualified paths that start with a module name instead of `crate`,
1631 /// `self`, or an extern crate name
1635 /// ```rust,edition2015,compile_fail
1636 /// #![deny(absolute_paths_not_starting_with_crate)]
1651 /// Rust [editions] allow the language to evolve without breaking
1652 /// backwards compatibility. This lint catches code that uses absolute
1653 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1654 /// paths (those starting with `::`) refer to either the crate root or an
1655 /// external crate. In the 2018 edition it was changed so that they only
1656 /// refer to external crates. The path prefix `crate::` should be used
1657 /// instead to reference items from the crate root.
1659 /// If you switch the compiler from the 2015 to 2018 edition without
1660 /// updating the code, then it will fail to compile if the old style paths
1661 /// are used. You can manually change the paths to use the `crate::`
1662 /// prefix to transition to the 2018 edition.
1664 /// This lint solves the problem automatically. It is "allow" by default
1665 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1666 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1667 /// and automatically apply the suggested fix from the compiler. This
1668 /// provides a completely automated way to update old code to the 2018
1671 /// [editions]: https://doc.rust-lang.org/edition-guide/
1672 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1673 pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1675 "fully qualified paths that start with a module name \
1676 instead of `crate`, `self`, or an extern crate name",
1677 @future_incompatible = FutureIncompatibleInfo {
1678 reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1679 edition: Some(Edition::Edition2018),
1684 /// The `illegal_floating_point_literal_pattern` lint detects
1685 /// floating-point literals used in patterns.
1702 /// Previous versions of the compiler accepted floating-point literals in
1703 /// patterns, but it was later determined this was a mistake. The
1704 /// semantics of comparing floating-point values may not be clear in a
1705 /// pattern when contrasted with "structural equality". Typically you can
1706 /// work around this by using a [match guard], such as:
1712 /// y if y == 5.0 => {}
1717 /// This is a [future-incompatible] lint to transition this to a hard
1718 /// error in the future. See [issue #41620] for more details.
1720 /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1721 /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1722 /// [future-incompatible]: ../index.md#future-incompatible-lints
1723 pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1725 "floating-point literals cannot be used in patterns",
1726 @future_incompatible = FutureIncompatibleInfo {
1727 reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1733 /// The `unstable_name_collisions` lint detects that you have used a name
1734 /// that the standard library plans to add in the future.
1739 /// trait MyIterator : Iterator {
1740 /// // is_sorted is an unstable method that already exists on the Iterator trait
1741 /// fn is_sorted(self) -> bool where Self: Sized {true}
1744 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1746 /// let x = vec![1, 2, 3];
1747 /// let _ = x.iter().is_sorted();
1754 /// When new methods are added to traits in the standard library, they are
1755 /// usually added in an "unstable" form which is only available on the
1756 /// [nightly channel] with a [`feature` attribute]. If there is any
1757 /// pre-existing code which extends a trait to have a method with the same
1758 /// name, then the names will collide. In the future, when the method is
1759 /// stabilized, this will cause an error due to the ambiguity. This lint
1760 /// is an early-warning to let you know that there may be a collision in
1761 /// the future. This can be avoided by adding type annotations to
1762 /// disambiguate which trait method you intend to call, such as
1763 /// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
1765 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1766 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1767 pub UNSTABLE_NAME_COLLISIONS,
1769 "detects name collision with an existing but unstable method",
1770 @future_incompatible = FutureIncompatibleInfo {
1771 reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1773 // Note: this item represents future incompatibility of all unstable functions in the
1774 // standard library, and thus should never be removed or changed to an error.
1779 /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1780 /// in [`if let`]s, [`while let`]s, and `if let` guards.
1785 /// if let _ = 123 {
1786 /// println!("always runs!");
1794 /// There usually isn't a reason to have an irrefutable pattern in an
1795 /// `if let` or `while let` statement, because the pattern will always match
1796 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1797 /// when generating code with a macro, forbidding irrefutable patterns
1798 /// would require awkward workarounds in situations where the macro
1799 /// doesn't know if the pattern is refutable or not. This lint allows
1800 /// macros to accept this form, while alerting for a possibly incorrect
1801 /// use in normal code.
1803 /// See [RFC 2086] for more details.
1805 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1806 /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1807 /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1808 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1809 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1810 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1811 pub IRREFUTABLE_LET_PATTERNS,
1813 "detects irrefutable patterns in `if let` and `while let` statements"
1817 /// The `unused_labels` lint detects [labels] that are never used.
1819 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1824 /// 'unused_label: loop {}
1831 /// Unused labels may signal a mistake or unfinished code. To silence the
1832 /// warning for the individual label, prefix it with an underscore such as
1836 "detects labels that are never used"
1840 /// The `where_clauses_object_safety` lint detects for [object safety] of
1841 /// [where clauses].
1843 /// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
1844 /// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
1851 /// trait X { fn foo(&self) where Self: Trait; }
1853 /// impl X for () { fn foo(&self) {} }
1855 /// impl Trait for dyn X {}
1857 /// // Segfault at opt-level 0, SIGILL otherwise.
1858 /// pub fn main() { <dyn X as X>::foo(&()); }
1865 /// The compiler previously allowed these object-unsafe bounds, which was
1866 /// incorrect. This is a [future-incompatible] lint to transition this to
1867 /// a hard error in the future. See [issue #51443] for more details.
1869 /// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
1870 /// [future-incompatible]: ../index.md#future-incompatible-lints
1871 pub WHERE_CLAUSES_OBJECT_SAFETY,
1873 "checks the object safety of where clauses",
1874 @future_incompatible = FutureIncompatibleInfo {
1875 reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
1881 /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1882 /// derives using inaccessible names from parent modules.
1886 /// ```rust,ignore (proc-macro)
1888 /// #![crate_type = "proc-macro"]
1890 /// extern crate proc_macro;
1892 /// use proc_macro::*;
1894 /// #[proc_macro_derive(Foo)]
1895 /// pub fn foo1(a: TokenStream) -> TokenStream {
1897 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
1901 /// ```rust,ignore (needs-dependency)
1904 /// extern crate foo;
1906 /// struct Something;
1914 /// This will produce:
1917 /// warning: cannot find type `Something` in this scope
1918 /// --> src/main.rs:8:10
1920 /// 8 | #[derive(Foo)]
1921 /// | ^^^ names from parent modules are not accessible without an explicit import
1923 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
1924 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1925 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
1930 /// If a proc-macro generates a module, the compiler unintentionally
1931 /// allowed items in that module to refer to items in the crate root
1932 /// without importing them. This is a [future-incompatible] lint to
1933 /// transition this to a hard error in the future. See [issue #50504] for
1936 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
1937 /// [future-incompatible]: ../index.md#future-incompatible-lints
1938 pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
1940 "detects proc macro derives using inaccessible names from parent modules",
1941 @future_incompatible = FutureIncompatibleInfo {
1942 reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
1948 /// The `macro_use_extern_crate` lint detects the use of the
1949 /// [`macro_use` attribute].
1953 /// ```rust,ignore (needs extern crate)
1954 /// #![deny(macro_use_extern_crate)]
1957 /// extern crate serde_json;
1960 /// let _ = json!{{}};
1964 /// This will produce:
1967 /// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
1968 /// --> src/main.rs:3:1
1970 /// 3 | #[macro_use]
1973 /// note: the lint level is defined here
1974 /// --> src/main.rs:1:9
1976 /// 1 | #![deny(macro_use_extern_crate)]
1977 /// | ^^^^^^^^^^^^^^^^^^^^^^
1982 /// The [`macro_use` attribute] on an [`extern crate`] item causes
1983 /// macros in that external crate to be brought into the prelude of the
1984 /// crate, making the macros in scope everywhere. As part of the efforts
1985 /// to simplify handling of dependencies in the [2018 edition], the use of
1986 /// `extern crate` is being phased out. To bring macros from extern crates
1987 /// into scope, it is recommended to use a [`use` import].
1989 /// This lint is "allow" by default because this is a stylistic choice
1990 /// that has not been settled, see [issue #52043] for more information.
1992 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
1993 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
1994 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
1995 pub MACRO_USE_EXTERN_CRATE,
1997 "the `#[macro_use]` attribute is now deprecated in favor of using macros \
1998 via the module system"
2002 /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2003 /// detects macro-expanded [`macro_export`] macros from the current crate
2004 /// that cannot be referred to by absolute paths.
2006 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2010 /// ```rust,compile_fail
2011 /// macro_rules! define_exported {
2014 /// macro_rules! exported {
2020 /// define_exported!();
2023 /// crate::exported!();
2031 /// The intent is that all macros marked with the `#[macro_export]`
2032 /// attribute are made available in the root of the crate. However, when a
2033 /// `macro_rules!` definition is generated by another macro, the macro
2034 /// expansion is unable to uphold this rule. This is a
2035 /// [future-incompatible] lint to transition this to a hard error in the
2036 /// future. See [issue #53495] for more details.
2038 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2039 /// [future-incompatible]: ../index.md#future-incompatible-lints
2040 pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2042 "macro-expanded `macro_export` macros from the current crate \
2043 cannot be referred to by absolute paths",
2044 @future_incompatible = FutureIncompatibleInfo {
2045 reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2052 /// The `explicit_outlives_requirements` lint detects unnecessary
2053 /// lifetime bounds that can be inferred.
2057 /// ```rust,compile_fail
2058 /// # #![allow(unused)]
2059 /// #![deny(explicit_outlives_requirements)]
2061 /// struct SharedRef<'a, T>
2073 /// If a `struct` contains a reference, such as `&'a T`, the compiler
2074 /// requires that `T` outlives the lifetime `'a`. This historically
2075 /// required writing an explicit lifetime bound to indicate this
2076 /// requirement. However, this can be overly explicit, causing clutter and
2077 /// unnecessary complexity. The language was changed to automatically
2078 /// infer the bound if it is not specified. Specifically, if the struct
2079 /// contains a reference, directly or indirectly, to `T` with lifetime
2080 /// `'x`, then it will infer that `T: 'x` is a requirement.
2082 /// This lint is "allow" by default because it can be noisy for existing
2083 /// code that already had these requirements. This is a stylistic choice,
2084 /// as it is still valid to explicitly state the bound. It also has some
2085 /// false positives that can cause confusion.
2087 /// See [RFC 2093] for more details.
2089 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2090 pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2092 "outlives requirements can be inferred"
2096 /// The `indirect_structural_match` lint detects a `const` in a pattern
2097 /// that manually implements [`PartialEq`] and [`Eq`].
2099 /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2100 /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2104 /// ```rust,compile_fail
2105 /// #![deny(indirect_structural_match)]
2107 /// struct NoDerive(i32);
2108 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2109 /// impl Eq for NoDerive { }
2110 /// #[derive(PartialEq, Eq)]
2111 /// struct WrapParam<T>(T);
2112 /// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
2114 /// match WRAP_INDIRECT_PARAM {
2115 /// WRAP_INDIRECT_PARAM => { }
2125 /// The compiler unintentionally accepted this form in the past. This is a
2126 /// [future-incompatible] lint to transition this to a hard error in the
2127 /// future. See [issue #62411] for a complete description of the problem,
2128 /// and some possible solutions.
2130 /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2131 /// [future-incompatible]: ../index.md#future-incompatible-lints
2132 pub INDIRECT_STRUCTURAL_MATCH,
2134 "constant used in pattern contains value of non-structural-match type in a field or a variant",
2135 @future_incompatible = FutureIncompatibleInfo {
2136 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2142 /// The `deprecated_in_future` lint is internal to rustc and should not be
2143 /// used by user code.
2145 /// This lint is only enabled in the standard library. It works with the
2146 /// use of `#[rustc_deprecated]` with a `since` field of a version in the
2147 /// future. This allows something to be marked as deprecated in a future
2148 /// version, and then this lint will ensure that the item is no longer
2149 /// used in the standard library. See the [stability documentation] for
2152 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
2153 pub DEPRECATED_IN_FUTURE,
2155 "detects use of items that will be deprecated in a future version",
2156 report_in_external_macro
2160 /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2161 /// cannot be relied upon across compiler versions and optimization levels.
2165 /// ```rust,compile_fail
2166 /// #![deny(pointer_structural_match)]
2167 /// fn foo(a: usize, b: usize) -> usize { a + b }
2168 /// const FOO: fn(usize, usize) -> usize = foo;
2181 /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2182 /// While these work in many cases as expected by users, it is possible that due to
2183 /// optimizations pointers are "not equal to themselves" or pointers to different functions
2184 /// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2185 /// functions if their bodies are the same, thus also making pointers to these functions point
2186 /// to the same location. Additionally functions may get duplicated if they are instantiated
2187 /// in different crates and not deduplicated again via LTO.
2188 pub POINTER_STRUCTURAL_MATCH,
2190 "pointers are not structural-match",
2191 @future_incompatible = FutureIncompatibleInfo {
2192 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2198 /// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2199 /// whose type is not structural-match and whose initializer body actually uses values
2200 /// that are not structural-match. So `Option<NotStruturalMatch>` is ok if the constant
2205 /// ```rust,compile_fail
2206 /// #![deny(nontrivial_structural_match)]
2208 /// #[derive(Copy, Clone, Debug)]
2209 /// struct NoDerive(u32);
2210 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2211 /// impl Eq for NoDerive { }
2213 /// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2214 /// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2222 /// Previous versions of Rust accepted constants in patterns, even if those constants's types
2223 /// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2224 /// `PartialEq`, which can report that two constants are not equal even if they are
2226 pub NONTRIVIAL_STRUCTURAL_MATCH,
2228 "constant used in pattern of non-structural-match type and the constant's initializer \
2229 expression contains values of non-structural-match types",
2230 @future_incompatible = FutureIncompatibleInfo {
2231 reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2237 /// The `ambiguous_associated_items` lint detects ambiguity between
2238 /// [associated items] and [enum variants].
2240 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2241 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2245 /// ```rust,compile_fail
2252 /// fn foo() -> Self::V;
2257 /// // `Self::V` is ambiguous because it may refer to the associated type or
2258 /// // the enum variant.
2259 /// fn foo() -> Self::V { 0 }
2267 /// Previous versions of Rust did not allow accessing enum variants
2268 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2269 /// introduced some situations where it can be ambiguous what a type
2270 /// was referring to.
2272 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2273 /// state which type to use. For example, in the above example the
2274 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2275 /// specifically refer to the associated type.
2277 /// This is a [future-incompatible] lint to transition this to a hard
2278 /// error in the future. See [issue #57644] for more details.
2280 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2281 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2282 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2283 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2284 /// [future-incompatible]: ../index.md#future-incompatible-lints
2285 pub AMBIGUOUS_ASSOCIATED_ITEMS,
2287 "ambiguous associated items",
2288 @future_incompatible = FutureIncompatibleInfo {
2289 reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2295 /// The `mutable_borrow_reservation_conflict` lint detects the reservation
2296 /// of a two-phased borrow that conflicts with other shared borrows.
2301 /// let mut v = vec![0, 1, 2];
2302 /// let shared = &v;
2303 /// v.push(shared.len());
2310 /// This is a [future-incompatible] lint to transition this to a hard error
2311 /// in the future. See [issue #59159] for a complete description of the
2312 /// problem, and some possible solutions.
2314 /// [issue #59159]: https://github.com/rust-lang/rust/issues/59159
2315 /// [future-incompatible]: ../index.md#future-incompatible-lints
2316 pub MUTABLE_BORROW_RESERVATION_CONFLICT,
2318 "reservation of a two-phased borrow conflicts with other shared borrows",
2319 @future_incompatible = FutureIncompatibleInfo {
2320 reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
2326 /// The `soft_unstable` lint detects unstable features that were
2327 /// unintentionally allowed on stable.
2331 /// ```rust,compile_fail
2333 /// extern crate test;
2336 /// fn name(b: &mut test::Bencher) {
2345 /// The [`bench` attribute] was accidentally allowed to be specified on
2346 /// the [stable release channel]. Turning this to a hard error would have
2347 /// broken some projects. This lint allows those projects to continue to
2348 /// build correctly when [`--cap-lints`] is used, but otherwise signal an
2349 /// error that `#[bench]` should not be used on the stable channel. This
2350 /// is a [future-incompatible] lint to transition this to a hard error in
2351 /// the future. See [issue #64266] for more details.
2353 /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2354 /// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
2355 /// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2356 /// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
2357 /// [future-incompatible]: ../index.md#future-incompatible-lints
2360 "a feature gate that doesn't break dependent crates",
2361 @future_incompatible = FutureIncompatibleInfo {
2362 reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2368 /// The `inline_no_sanitize` lint detects incompatible use of
2369 /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2371 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2372 /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2377 /// #![feature(no_sanitize)]
2379 /// #[inline(always)]
2380 /// #[no_sanitize(address)]
2392 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2393 /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2394 /// Consider temporarily removing `inline` attribute.
2395 pub INLINE_NO_SANITIZE,
2397 "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2401 /// The `asm_sub_register` lint detects using only a subset of a register
2402 /// for inline asm inputs.
2406 /// ```rust,ignore (fails on system llvm)
2407 /// #![feature(asm)]
2410 /// #[cfg(target_arch="x86_64")]
2412 /// asm!("mov {0}, {0}", in(reg) 0i16);
2417 /// This will produce:
2420 /// warning: formatting may not be suitable for sub-register argument
2421 /// --> src/main.rs:6:19
2423 /// 6 | asm!("mov {0}, {0}", in(reg) 0i16);
2424 /// | ^^^ ^^^ ---- for this argument
2426 /// = note: `#[warn(asm_sub_register)]` on by default
2427 /// = help: use the `x` modifier to have the register formatted as `ax`
2428 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2433 /// Registers on some architectures can use different names to refer to a
2434 /// subset of the register. By default, the compiler will use the name for
2435 /// the full register size. To explicitly use a subset of the register,
2436 /// you can override the default by using a modifier on the template
2437 /// string operand to specify when subregister to use. This lint is issued
2438 /// if you pass in a value with a smaller data type than the default
2439 /// register size, to alert you of possibly using the incorrect width. To
2440 /// fix this, add the suggested modifier to the template, or cast the
2441 /// value to the correct size.
2443 /// See [register template modifiers] for more details.
2445 /// [register template modifiers]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#register-template-modifiers
2446 pub ASM_SUB_REGISTER,
2448 "using only a subset of a register for inline asm inputs",
2452 /// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2453 /// `.att_syntax` directives.
2457 /// ```rust,ignore (fails on system llvm)
2458 /// #![feature(asm)]
2461 /// #[cfg(target_arch="x86_64")]
2465 /// "movl {0}, {0}", in(reg) 0usize
2471 /// This will produce:
2474 /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2475 /// --> test.rs:7:14
2477 /// 7 | ".att_syntax",
2479 /// 8 | "movq {0}, {0}", out(reg) _,
2481 /// | - help: add option: `, options(att_syntax)`
2483 /// = note: `#[warn(bad_asm_style)]` on by default
2488 /// On x86, `asm!` uses the intel assembly syntax by default. While this
2489 /// can be switched using assembler directives like `.att_syntax`, using the
2490 /// `att_syntax` option is recommended instead because it will also properly
2491 /// prefix register placeholders with `%` as required by AT&T syntax.
2494 "incorrect use of inline assembly",
2498 /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2499 /// functions without an explicit unsafe block.
2503 /// ```rust,compile_fail
2504 /// #![deny(unsafe_op_in_unsafe_fn)]
2506 /// unsafe fn foo() {}
2508 /// unsafe fn bar() {
2519 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2520 /// body. However, this can increase the surface area of code that needs
2521 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2522 /// convenient way to make it clear exactly which parts of the code are
2523 /// performing unsafe operations. In the future, it is desired to change
2524 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2525 /// without an `unsafe` block.
2527 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2529 /// This lint is "allow" by default since this will affect a large amount
2530 /// of existing code, and the exact plan for increasing the severity is
2531 /// still being considered. See [RFC #2585] and [issue #71668] for more
2534 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2535 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2536 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2537 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2538 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2539 pub UNSAFE_OP_IN_UNSAFE_FN,
2541 "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2545 /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2546 /// `enum` that implements [`Drop`].
2548 /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2553 /// # #![allow(unused)]
2558 /// impl Drop for E {
2559 /// fn drop(&mut self) {
2560 /// println!("Drop");
2566 /// let i = e as u32;
2574 /// Casting a field-less `enum` that does not implement [`Copy`] to an
2575 /// integer moves the value without calling `drop`. This can result in
2576 /// surprising behavior if it was expected that `drop` should be called.
2577 /// Calling `drop` automatically would be inconsistent with other move
2578 /// operations. Since neither behavior is clear or consistent, it was
2579 /// decided that a cast of this nature will no longer be allowed.
2581 /// This is a [future-incompatible] lint to transition this to a hard error
2582 /// in the future. See [issue #73333] for more details.
2584 /// [future-incompatible]: ../index.md#future-incompatible-lints
2585 /// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
2586 /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
2587 pub CENUM_IMPL_DROP_CAST,
2589 "a C-like enum implementing Drop is cast",
2590 @future_incompatible = FutureIncompatibleInfo {
2591 reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
2597 /// The `const_evaluatable_unchecked` lint detects a generic constant used
2603 /// const fn foo<T>() -> usize {
2604 /// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2612 /// let _ = [0; foo::<T>()];
2620 /// In the 1.43 release, some uses of generic parameters in array repeat
2621 /// expressions were accidentally allowed. This is a [future-incompatible]
2622 /// lint to transition this to a hard error in the future. See [issue
2623 /// #76200] for a more detailed description and possible fixes.
2625 /// [future-incompatible]: ../index.md#future-incompatible-lints
2626 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2627 pub CONST_EVALUATABLE_UNCHECKED,
2629 "detects a generic constant is used in a type without a emitting a warning",
2630 @future_incompatible = FutureIncompatibleInfo {
2631 reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2637 /// The `function_item_references` lint detects function references that are
2638 /// formatted with [`fmt::Pointer`] or transmuted.
2640 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2648 /// println!("{:p}", &foo);
2656 /// Taking a reference to a function may be mistaken as a way to obtain a
2657 /// pointer to that function. This can give unexpected results when
2658 /// formatting the reference as a pointer or transmuting it. This lint is
2659 /// issued when function references are formatted as pointers, passed as
2660 /// arguments bound by [`fmt::Pointer`] or transmuted.
2661 pub FUNCTION_ITEM_REFERENCES,
2663 "suggest casting to a function pointer when attempting to take references to function items",
2667 /// The `uninhabited_static` lint detects uninhabited statics.
2674 /// static EXTERN: Void;
2682 /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2683 /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2684 /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2685 /// statics). This was accidentally allowed, but is being phased out.
2686 pub UNINHABITED_STATIC,
2688 "uninhabited static",
2689 @future_incompatible = FutureIncompatibleInfo {
2690 reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2696 /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2700 /// ```rust,compile_fail
2703 /// #[deprecated = "message"]
2704 /// impl Default for X {
2705 /// fn default() -> Self {
2715 /// Deprecation attributes have no effect on trait implementations.
2716 pub USELESS_DEPRECATED,
2718 "detects deprecation attributes with no effect",
2722 /// The `unsupported_naked_functions` lint detects naked function
2723 /// definitions that are unsupported but were previously accepted.
2728 /// #![feature(naked_functions)]
2731 /// pub fn f() -> u32 {
2740 /// The naked functions must be defined using a single inline assembly
2743 /// The execution must never fall through past the end of the assembly
2744 /// code so the block must use `noreturn` option. The asm block can also
2745 /// use `att_syntax` option, but other options are not allowed.
2747 /// The asm block must not contain any operands other than `const` and
2748 /// `sym`. Additionally, naked function should specify a non-Rust ABI.
2750 /// While other definitions of naked functions were previously accepted,
2751 /// they are unsupported and might not work reliably. This is a
2752 /// [future-incompatible] lint that will transition into hard error in
2755 /// [future-incompatible]: ../index.md#future-incompatible-lints
2756 pub UNSUPPORTED_NAKED_FUNCTIONS,
2758 "unsupported naked function definitions",
2759 @future_incompatible = FutureIncompatibleInfo {
2760 reference: "issue #32408 <https://github.com/rust-lang/rust/issues/32408>",
2766 /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2771 /// #![feature(staged_api)]
2773 /// #[derive(Clone)]
2774 /// #[stable(feature = "x", since = "1")]
2777 /// #[unstable(feature = "y", issue = "none")]
2778 /// impl Copy for S {}
2785 /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2786 /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2787 pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2789 "detects `#[unstable]` on stable trait implementations for stable types"
2793 /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2794 /// in macro bodies when the macro is invoked in expression position.
2795 /// This was previous accepted, but is being phased out.
2799 /// ```rust,compile_fail
2800 /// #![deny(semicolon_in_expressions_from_macros)]
2801 /// macro_rules! foo {
2806 /// let val = match true {
2817 /// Previous, Rust ignored trailing semicolon in a macro
2818 /// body when a macro was invoked in expression position.
2819 /// However, this makes the treatment of semicolons in the language
2820 /// inconsistent, and could lead to unexpected runtime behavior
2821 /// in some circumstances (e.g. if the macro author expects
2822 /// a value to be dropped).
2824 /// This is a [future-incompatible] lint to transition this
2825 /// to a hard error in the future. See [issue #79813] for more details.
2827 /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2828 /// [future-incompatible]: ../index.md#future-incompatible-lints
2829 pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2831 "trailing semicolon in macro body used as expression",
2832 @future_incompatible = FutureIncompatibleInfo {
2833 reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
2839 /// The `legacy_derive_helpers` lint detects derive helper attributes
2840 /// that are used before they are introduced.
2844 /// ```rust,ignore (needs extern crate)
2845 /// #[serde(rename_all = "camelCase")]
2846 /// #[derive(Deserialize)]
2847 /// struct S { /* fields */ }
2853 /// warning: derive helper attribute is used before it is introduced
2854 /// --> $DIR/legacy-derive-helpers.rs:1:3
2856 /// 1 | #[serde(rename_all = "camelCase")]
2859 /// 2 | #[derive(Deserialize)]
2860 /// | ----------- the attribute is introduced here
2865 /// Attributes like this work for historical reasons, but attribute expansion works in
2866 /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2867 /// into the future" at not yet expanded part of the item , but such attempts are not always
2870 /// To fix the warning place the helper attribute after its corresponding derive.
2871 /// ```rust,ignore (needs extern crate)
2872 /// #[derive(Deserialize)]
2873 /// #[serde(rename_all = "camelCase")]
2874 /// struct S { /* fields */ }
2876 pub LEGACY_DERIVE_HELPERS,
2878 "detects derive helper attributes that are used before they are introduced",
2879 @future_incompatible = FutureIncompatibleInfo {
2880 reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
2885 /// The `large_assignments` lint detects when objects of large
2886 /// types are being moved around.
2890 /// ```rust,ignore (can crash on some platforms)
2891 /// let x = [0; 50000];
2898 /// warning: moving a large value
2899 /// --> $DIR/move-large.rs:1:3
2901 /// - Copied large value here
2906 /// When using a large type in a plain assignment or in a function
2907 /// argument, idiomatic code can be inefficient.
2908 /// Ideally appropriate optimizations would resolve this, but such
2909 /// optimizations are only done in a best-effort manner.
2910 /// This lint will trigger on all sites of large moves and thus allow the
2911 /// user to resolve them in code.
2912 pub LARGE_ASSIGNMENTS,
2914 "detects large moves or copies",
2917 declare_lint_pass! {
2918 /// Does nothing as a lint pass, but registers some `Lint`s
2919 /// that are used by other parts of the compiler.
2921 FORBIDDEN_LINT_GROUPS,
2922 ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
2923 ARITHMETIC_OVERFLOW,
2924 UNCONDITIONAL_PANIC,
2926 UNUSED_EXTERN_CRATES,
2927 UNUSED_CRATE_DEPENDENCIES,
2928 UNUSED_QUALIFICATIONS,
2934 UNREACHABLE_PATTERNS,
2935 OVERLAPPING_RANGE_ENDPOINTS,
2936 BINDINGS_WITH_VARIANT_NAME,
2941 UNKNOWN_CRATE_TYPES,
2943 TRIVIAL_NUMERIC_CASTS,
2945 EXPORTED_PRIVATE_DEPENDENCIES,
2946 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
2947 INVALID_TYPE_PARAM_DEFAULT,
2949 RENAMED_AND_REMOVED_LINTS,
2950 UNALIGNED_REFERENCES,
2951 CONST_ITEM_MUTATION,
2952 PATTERNS_IN_FNS_WITHOUT_BODY,
2953 MISSING_FRAGMENT_SPECIFIER,
2954 LATE_BOUND_LIFETIME_ARGUMENTS,
2955 ORDER_DEPENDENT_TRAIT_OBJECTS,
2956 COHERENCE_LEAK_CHECK,
2960 UNCONDITIONAL_RECURSION,
2961 SINGLE_USE_LIFETIMES,
2964 TYVAR_BEHIND_RAW_POINTER,
2965 ELIDED_LIFETIMES_IN_PATHS,
2967 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
2968 UNSTABLE_NAME_COLLISIONS,
2969 IRREFUTABLE_LET_PATTERNS,
2970 WHERE_CLAUSES_OBJECT_SAFETY,
2971 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2972 MACRO_USE_EXTERN_CRATE,
2973 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2974 ILL_FORMED_ATTRIBUTE_INPUT,
2975 CONFLICTING_REPR_HINTS,
2976 META_VARIABLE_MISUSE,
2977 DEPRECATED_IN_FUTURE,
2978 AMBIGUOUS_ASSOCIATED_ITEMS,
2979 MUTABLE_BORROW_RESERVATION_CONFLICT,
2980 INDIRECT_STRUCTURAL_MATCH,
2981 POINTER_STRUCTURAL_MATCH,
2982 NONTRIVIAL_STRUCTURAL_MATCH,
2987 UNSAFE_OP_IN_UNSAFE_FN,
2989 CENUM_IMPL_DROP_CAST,
2990 CONST_EVALUATABLE_UNCHECKED,
2991 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2993 FUNCTION_ITEM_REFERENCES,
2995 UNSUPPORTED_NAKED_FUNCTIONS,
2997 INVALID_DOC_ATTRIBUTES,
2998 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2999 DISJOINT_CAPTURE_MIGRATION,
3000 LEGACY_DERIVE_HELPERS,
3001 PROC_MACRO_BACK_COMPAT,
3002 OR_PATTERNS_BACK_COMPAT,
3008 /// The `unused_doc_comments` lint detects doc comments that aren't used
3022 /// `rustdoc` does not use doc comments in all positions, and so the doc
3023 /// comment will be ignored. Try changing it to a normal comment with `//`
3024 /// to avoid the warning.
3025 pub UNUSED_DOC_COMMENTS,
3027 "detects doc comments that aren't used by rustdoc"
3031 /// The `disjoint_capture_migration` lint detects variables that aren't completely
3032 /// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
3033 /// order of at least one path starting at this variable.
3034 /// It can also detect when a variable implements a trait, but one of its field does not and
3035 /// the field is captured by a closure and used with the assumption that said field implements
3036 /// the same trait as the root variable.
3038 /// ### Example of drop reorder
3040 /// ```rust,compile_fail
3041 /// # #![deny(disjoint_capture_migration)]
3042 /// # #![allow(unused)]
3043 /// struct FancyInteger(i32);
3045 /// impl Drop for FancyInteger {
3046 /// fn drop(&mut self) {
3047 /// println!("Just dropped {}", self.0);
3051 /// struct Point { x: FancyInteger, y: FancyInteger }
3054 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3062 /// // ... More code ...
3070 /// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
3071 /// the feature `capture_disjoint_fields` is enabled.
3073 /// ### Example of auto-trait
3075 /// ```rust,compile_fail
3076 /// #![deny(disjoint_capture_migration)]
3077 /// use std::thread;
3079 /// struct Pointer (*mut i32);
3080 /// unsafe impl Send for Pointer {}
3084 /// let fptr = Pointer(&mut f as *mut i32);
3085 /// thread::spawn(move || unsafe {
3095 /// In the above example `fptr.0` is captured when feature `capture_disjoint_fields` is enabled.
3096 /// The field is of type *mut i32 which doesn't implement Send, making the code invalid as the
3097 /// field cannot be sent between thread safely.
3098 pub DISJOINT_CAPTURE_MIGRATION,
3100 "Drop reorder and auto traits error because of `capture_disjoint_fields`"
3103 declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3106 /// The `missing_abi` lint detects cases where the ABI is omitted from
3107 /// extern declarations.
3111 /// ```rust,compile_fail
3112 /// #![deny(missing_abi)]
3114 /// extern fn foo() {}
3121 /// Historically, Rust implicitly selected C as the ABI for extern
3122 /// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
3123 /// though this has not yet happened, and especially with their addition
3124 /// seeing the ABI easily will make code review easier.
3127 "No declared ABI for extern declaration"
3131 /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3136 /// ```rust,compile_fail
3137 /// #![deny(warnings)]
3139 /// pub mod submodule {
3140 /// #![doc(test(no_crate_inject))]
3148 /// Previously, there were very like checks being performed on `#[doc(..)]`
3149 /// unlike the other attributes. It'll now catch all the issues that it
3150 /// silently ignored previously.
3151 pub INVALID_DOC_ATTRIBUTES,
3153 "detects invalid `#[doc(...)]` attributes",
3154 @future_incompatible = FutureIncompatibleInfo {
3155 reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
3161 /// The `proc_macro_back_compat` lint detects uses of old versions of certain
3162 /// proc-macro crates, which have hardcoded workarounds in the compiler.
3166 /// ```rust,ignore (needs-dependency)
3168 /// use time_macros_impl::impl_macros;
3170 /// impl_macros!(Foo);
3173 /// This will produce:
3176 /// warning: using an old version of `time-macros-impl`
3177 /// ::: $DIR/group-compat-hack.rs:27:5
3179 /// LL | impl_macros!(Foo);
3180 /// | ------------------ in this macro invocation
3182 /// = note: `#[warn(proc_macro_back_compat)]` on by default
3183 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3184 /// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3185 /// = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
3186 /// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3191 /// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3192 /// causing older versions of certain crates to stop compiling.
3193 /// This is a [future-incompatible] lint to ease the transition to an error.
3194 /// See [issue #83125] for more details.
3196 /// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3197 /// [future-incompatible]: ../index.md#future-incompatible-lints
3198 pub PROC_MACRO_BACK_COMPAT,
3200 "detects usage of old versions of certain proc-macro crates",
3201 @future_incompatible = FutureIncompatibleInfo {
3202 reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3204 future_breakage: Some(FutureBreakage {
3211 /// The `or_patterns_back_compat` lint detects usage of old versions of or-patterns.
3215 /// ```rust,compile_fail
3216 /// #![deny(or_patterns_back_compat)]
3217 /// macro_rules! match_any {
3218 /// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3221 /// $( $pat => $expr_arm, )+
3228 /// let result: Result<i64, i32> = Err(42);
3229 /// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3230 /// assert_eq!(int, 42);
3238 /// In Rust 2021, the pat matcher will match new patterns, which include the | character.
3239 pub OR_PATTERNS_BACK_COMPAT,
3241 "detects usage of old versions of or-patterns",