1 //! Some lints that are built in to the compiler.
3 //! These are the built-in lints that are emitted direct in the main
4 //! compiler code, rather than using their own custom pass. Those
5 //! lints are all available in `rustc_lint::builtin`.
7 use crate::{declare_lint, declare_lint_pass, FutureIncompatibilityReason};
8 use rustc_span::edition::Edition;
9 use rustc_span::symbol::sym;
12 /// The `forbidden_lint_groups` lint detects violations of
13 /// `forbid` applied to a lint group. Due to a bug in the compiler,
14 /// these used to be overlooked entirely. They now generate a warning.
19 /// #![forbid(warnings)]
20 /// #![deny(bad_style)]
27 /// ### Recommended fix
29 /// If your crate is using `#![forbid(warnings)]`,
30 /// we recommend that you change to `#![deny(warnings)]`.
34 /// Due to a compiler bug, applying `forbid` to lint groups
35 /// previously had no effect. The bug is now fixed but instead of
36 /// enforcing `forbid` we issue this future-compatibility warning
37 /// to avoid breaking existing crates.
38 pub FORBIDDEN_LINT_GROUPS,
40 "applying forbid to lint-groups",
41 @future_incompatible = FutureIncompatibleInfo {
42 reference: "issue #81670 <https://github.com/rust-lang/rust/issues/81670>",
47 /// The `ill_formed_attribute_input` lint detects ill-formed attribute
48 /// inputs that were previously accepted and used in practice.
52 /// ```rust,compile_fail
53 /// #[inline = "this is not valid"]
61 /// Previously, inputs for many built-in attributes weren't validated and
62 /// nonsensical attribute inputs were accepted. After validation was
63 /// added, it was determined that some existing projects made use of these
64 /// invalid forms. This is a [future-incompatible] lint to transition this
65 /// to a hard error in the future. See [issue #57571] for more details.
67 /// Check the [attribute reference] for details on the valid inputs for
70 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
71 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
72 /// [future-incompatible]: ../index.md#future-incompatible-lints
73 pub ILL_FORMED_ATTRIBUTE_INPUT,
75 "ill-formed attribute inputs that were previously accepted and used in practice",
76 @future_incompatible = FutureIncompatibleInfo {
77 reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
83 /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
84 /// conflicting hints.
86 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
90 /// ```rust,compile_fail
101 /// The compiler incorrectly accepted these conflicting representations in
102 /// the past. This is a [future-incompatible] lint to transition this to a
103 /// hard error in the future. See [issue #68585] for more details.
105 /// To correct the issue, remove one of the conflicting hints.
107 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
108 /// [future-incompatible]: ../index.md#future-incompatible-lints
109 pub CONFLICTING_REPR_HINTS,
111 "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
112 @future_incompatible = FutureIncompatibleInfo {
113 reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
118 /// The `meta_variable_misuse` lint detects possible meta-variable misuse
119 /// in macro definitions.
123 /// ```rust,compile_fail
124 /// #![deny(meta_variable_misuse)]
126 /// macro_rules! foo {
128 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
140 /// There are quite a few different ways a [`macro_rules`] macro can be
141 /// improperly defined. Many of these errors were previously only detected
142 /// when the macro was expanded or not at all. This lint is an attempt to
143 /// catch some of these problems when the macro is *defined*.
145 /// This lint is "allow" by default because it may have false positives
146 /// and other issues. See [issue #61053] for more details.
148 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
149 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
150 pub META_VARIABLE_MISUSE,
152 "possible meta-variable misuse at macro definition"
156 /// The `incomplete_include` lint detects the use of the [`include!`]
157 /// macro with a file that contains more than one expression.
159 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
163 /// ```rust,ignore (needs separate file)
165 /// include!("foo.txt");
169 /// where the file `foo.txt` contains:
178 /// error: include macro expected single expression in source
181 /// 1 | println!("1");
184 /// = note: `#[deny(incomplete_include)]` on by default
189 /// The [`include!`] macro is currently only intended to be used to
190 /// include a single [expression] or multiple [items]. Historically it
191 /// would ignore any contents after the first expression, but that can be
192 /// confusing. In the example above, the `println!` expression ends just
193 /// before the semicolon, making the semicolon "extra" information that is
194 /// ignored. Perhaps even more surprising, if the included file had
195 /// multiple print statements, the subsequent ones would be ignored!
197 /// One workaround is to place the contents in braces to create a [block
198 /// expression]. Also consider alternatives, like using functions to
199 /// encapsulate the expressions, or use [proc-macros].
201 /// This is a lint instead of a hard error because existing projects were
202 /// found to hit this error. To be cautious, it is a lint for now. The
203 /// future semantics of the `include!` macro are also uncertain, see
206 /// [items]: https://doc.rust-lang.org/reference/items.html
207 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
208 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
209 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
210 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
211 pub INCOMPLETE_INCLUDE,
213 "trailing content in included file"
217 /// The `arithmetic_overflow` lint detects that an arithmetic operation
220 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
224 /// ```rust,compile_fail
232 /// It is very likely a mistake to perform an arithmetic operation that
233 /// overflows its value. If the compiler is able to detect these kinds of
234 /// overflows at compile-time, it will trigger this lint. Consider
235 /// adjusting the expression to avoid overflow, or use a data type that
236 /// will not overflow.
237 pub ARITHMETIC_OVERFLOW,
239 "arithmetic operation overflows"
243 /// The `unconditional_panic` lint detects an operation that will cause a
244 /// panic at runtime.
248 /// ```rust,compile_fail
249 /// # #![allow(unused)]
257 /// This lint detects code that is very likely incorrect because it will
258 /// always panic, such as division by zero and out-of-bounds array
259 /// accesses. Consider adjusting your code if this is a bug, or using the
260 /// `panic!` or `unreachable!` macro instead in case the panic is intended.
261 pub UNCONDITIONAL_PANIC,
263 "operation will cause a panic at runtime"
267 /// The `unused_imports` lint detects imports that are never used.
272 /// use std::collections::HashMap;
279 /// Unused imports may signal a mistake or unfinished code, and clutter
280 /// the code, and should be removed. If you intended to re-export the item
281 /// to make it available outside of the module, add a visibility modifier
285 "imports that are never used"
289 /// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
295 /// #![feature(must_not_suspend)]
296 /// #![warn(must_not_suspend)]
298 /// #[must_not_suspend]
299 /// struct SyncThing {}
301 /// async fn yield_now() {}
303 /// pub async fn uhoh() {
304 /// let guard = SyncThing {};
305 /// yield_now().await;
313 /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
314 /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
317 /// This attribute can be used to mark values that are semantically incorrect across suspends
318 /// (like certain types of timers), values that have async alternatives, and values that
319 /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
322 pub MUST_NOT_SUSPEND,
324 "use of a `#[must_not_suspend]` value across a yield point",
325 @feature_gate = rustc_span::symbol::sym::must_not_suspend;
329 /// The `unused_extern_crates` lint guards against `extern crate` items
330 /// that are never used.
334 /// ```rust,compile_fail
335 /// #![deny(unused_extern_crates)]
336 /// extern crate proc_macro;
343 /// `extern crate` items that are unused have no effect and should be
344 /// removed. Note that there are some cases where specifying an `extern
345 /// crate` is desired for the side effect of ensuring the given crate is
346 /// linked, even though it is not otherwise directly referenced. The lint
347 /// can be silenced by aliasing the crate to an underscore, such as
348 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
349 /// use `extern crate` in the [2018 edition], as extern crates are now
350 /// automatically added in scope.
352 /// This lint is "allow" by default because it can be noisy, and produce
353 /// false-positives. If a dependency is being removed from a project, it
354 /// is recommended to remove it from the build configuration (such as
355 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
357 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
358 pub UNUSED_EXTERN_CRATES,
360 "extern crates that are never used"
364 /// The `unused_crate_dependencies` lint detects crate dependencies that
369 /// ```rust,ignore (needs extern crate)
370 /// #![deny(unused_crate_dependencies)]
373 /// This will produce:
376 /// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
378 /// note: the lint level is defined here
379 /// --> src/lib.rs:1:9
381 /// 1 | #![deny(unused_crate_dependencies)]
382 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
387 /// After removing the code that uses a dependency, this usually also
388 /// requires removing the dependency from the build configuration.
389 /// However, sometimes that step can be missed, which leads to time wasted
390 /// building dependencies that are no longer used. This lint can be
391 /// enabled to detect dependencies that are never used (more specifically,
392 /// any dependency passed with the `--extern` command-line flag that is
393 /// never referenced via [`use`], [`extern crate`], or in any [path]).
395 /// This lint is "allow" by default because it can provide false positives
396 /// depending on how the build system is configured. For example, when
397 /// using Cargo, a "package" consists of multiple crates (such as a
398 /// library and a binary), but the dependencies are defined for the
399 /// package as a whole. If there is a dependency that is only used in the
400 /// binary, but not the library, then the lint will be incorrectly issued
403 /// [path]: https://doc.rust-lang.org/reference/paths.html
404 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
405 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
406 pub UNUSED_CRATE_DEPENDENCIES,
408 "crate dependencies that are never used",
413 /// The `unused_qualifications` lint detects unnecessarily qualified
418 /// ```rust,compile_fail
419 /// #![deny(unused_qualifications)]
434 /// If an item from another module is already brought into scope, then
435 /// there is no need to qualify it in this case. You can call `bar()`
436 /// directly, without the `foo::`.
438 /// This lint is "allow" by default because it is somewhat pedantic, and
439 /// doesn't indicate an actual problem, but rather a stylistic choice, and
440 /// can be noisy when refactoring or moving around code.
441 pub UNUSED_QUALIFICATIONS,
443 "detects unnecessarily qualified names"
447 /// The `unknown_lints` lint detects unrecognized lint attributes.
452 /// #![allow(not_a_real_lint)]
459 /// It is usually a mistake to specify a lint that does not exist. Check
460 /// the spelling, and check the lint listing for the correct name. Also
461 /// consider if you are using an old version of the compiler, and the lint
462 /// is only available in a newer version.
465 "unrecognized lint attribute"
469 /// The `unfulfilled_lint_expectations` lint detects lint trigger expectations
470 /// that have not been fulfilled.
475 /// #![feature(lint_reasons)]
477 /// #[expect(unused_variables)]
479 /// println!("{}", x);
486 /// It was expected that the marked code would emit a lint. This expectation
487 /// has not been fulfilled.
489 /// The `expect` attribute can be removed if this is intended behavior otherwise
490 /// it should be investigated why the expected lint is no longer issued.
492 /// In rare cases, the expectation might be emitted at a different location than
493 /// shown in the shown code snippet. In most cases, the `#[expect]` attribute
494 /// works when added to the outer scope. A few lints can only be expected
495 /// on a crate level.
497 /// Part of RFC 2383. The progress is being tracked in [#54503]
499 /// [#54503]: https://github.com/rust-lang/rust/issues/54503
500 pub UNFULFILLED_LINT_EXPECTATIONS,
502 "unfulfilled lint expectation",
503 @feature_gate = rustc_span::sym::lint_reasons;
507 /// The `unused_variables` lint detects variables which are not used in
520 /// Unused variables may signal a mistake or unfinished code. To silence
521 /// the warning for the individual variable, prefix it with an underscore
523 pub UNUSED_VARIABLES,
525 "detect variables which are not used in any way"
529 /// The `unused_assignments` lint detects assignments that will never be read.
542 /// Unused assignments may signal a mistake or unfinished code. If the
543 /// variable is never used after being assigned, then the assignment can
544 /// be removed. Variables with an underscore prefix such as `_x` will not
545 /// trigger this lint.
546 pub UNUSED_ASSIGNMENTS,
548 "detect assignments that will never be read"
552 /// The `dead_code` lint detects unused, unexported items.
564 /// Dead code may signal a mistake or unfinished code. To silence the
565 /// warning for individual items, prefix the name with an underscore such
566 /// as `_foo`. If it was intended to expose the item outside of the crate,
567 /// consider adding a visibility modifier like `pub`. Otherwise consider
568 /// removing the unused code.
571 "detect unused, unexported items"
575 /// The `unused_attributes` lint detects attributes that were not used by
588 /// Unused [attributes] may indicate the attribute is placed in the wrong
589 /// position. Consider removing it, or placing it in the correct position.
590 /// Also consider if you intended to use an _inner attribute_ (with a `!`
591 /// such as `#![allow(unused)]`) which applies to the item the attribute
592 /// is within, or an _outer attribute_ (without a `!` such as
593 /// `#[allow(unused)]`) which applies to the item *following* the
596 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
597 pub UNUSED_ATTRIBUTES,
599 "detects attributes that were not used by the compiler"
603 /// The `unused_tuple_struct_fields` lint detects fields of tuple structs
604 /// that are never read.
609 /// #[warn(unused_tuple_struct_fields)]
610 /// struct S(i32, i32, i32);
611 /// let s = S(1, 2, 3);
612 /// let _ = (s.0, s.2);
619 /// Tuple struct fields that are never read anywhere may indicate a
620 /// mistake or unfinished code. To silence this warning, consider
621 /// removing the unused field(s) or, to preserve the numbering of the
622 /// remaining fields, change the unused field(s) to have unit type.
623 pub UNUSED_TUPLE_STRUCT_FIELDS,
625 "detects tuple struct fields that are never read"
629 /// The `unreachable_code` lint detects unreachable code paths.
634 /// panic!("we never go past here!");
643 /// Unreachable code may signal a mistake or unfinished code. If the code
644 /// is no longer in use, consider removing it.
645 pub UNREACHABLE_CODE,
647 "detects unreachable code paths",
648 report_in_external_macro
652 /// The `unreachable_patterns` lint detects unreachable patterns.
668 /// This usually indicates a mistake in how the patterns are specified or
669 /// ordered. In this example, the `y` pattern will always match, so the
670 /// five is impossible to reach. Remember, match arms match in order, you
671 /// probably wanted to put the `5` case above the `y` case.
672 pub UNREACHABLE_PATTERNS,
674 "detects unreachable patterns"
678 /// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
679 /// overlap on their endpoints.
681 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
688 /// 0..=100 => { println!("small"); }
689 /// 100..=255 => { println!("large"); }
697 /// It is likely a mistake to have range patterns in a match expression that overlap in this
698 /// way. Check that the beginning and end values are what you expect, and keep in mind that
699 /// with `..=` the left and right bounds are inclusive.
700 pub OVERLAPPING_RANGE_ENDPOINTS,
702 "detects range patterns with overlapping endpoints"
706 /// The `bindings_with_variant_name` lint detects pattern bindings with
707 /// the same name as one of the matched variants.
711 /// ```rust,compile_fail
717 /// pub fn foo(x: Enum) {
729 /// It is usually a mistake to specify an enum variant name as an
730 /// [identifier pattern]. In the example above, the `match` arms are
731 /// specifying a variable name to bind the value of `x` to. The second arm
732 /// is ignored because the first one matches *all* values. The likely
733 /// intent is that the arm was intended to match on the enum variant.
735 /// Two possible solutions are:
737 /// * Specify the enum variant using a [path pattern], such as
739 /// * Bring the enum variants into local scope, such as adding `use
740 /// Enum::*;` to the beginning of the `foo` function in the example
743 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
744 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
745 pub BINDINGS_WITH_VARIANT_NAME,
747 "detects pattern bindings with the same name as one of the matched variants"
751 /// The `unused_macros` lint detects macros that were not used.
753 /// Note that this lint is distinct from the `unused_macro_rules` lint,
754 /// which checks for single rules that never match of an otherwise used
755 /// macro, and thus never expand.
760 /// macro_rules! unused {
772 /// Unused macros may signal a mistake or unfinished code. To silence the
773 /// warning for the individual macro, prefix the name with an underscore
774 /// such as `_my_macro`. If you intended to export the macro to make it
775 /// available outside of the crate, use the [`macro_export` attribute].
777 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
780 "detects macros that were not used"
784 /// The `unused_macro_rules` lint detects macro rules that were not used.
786 /// Note that the lint is distinct from the `unused_macros` lint, which
787 /// fires if the entire macro is never called, while this lint fires for
788 /// single unused rules of the macro that is otherwise used.
789 /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
794 /// #[warn(unused_macro_rules)]
795 /// macro_rules! unused_empty {
796 /// (hello) => { println!("Hello, world!") }; // This rule is unused
797 /// () => { println!("empty") }; // This rule is used
801 /// unused_empty!(hello);
809 /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
810 /// they slow down compilation. Right now, silencing the warning is not
811 /// supported on a single rule level, so you have to add an allow to the
812 /// entire macro definition.
814 /// If you intended to export the macro to make it
815 /// available outside of the crate, use the [`macro_export` attribute].
817 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
818 pub UNUSED_MACRO_RULES,
820 "detects macro rules that were not used"
824 /// The `warnings` lint allows you to change the level of other
825 /// lints which produce warnings.
830 /// #![deny(warnings)]
838 /// The `warnings` lint is a bit special; by changing its level, you
839 /// change every other warning that would produce a warning to whatever
840 /// value you'd like. As such, you won't ever trigger this lint in your
844 "mass-change the level for lints which produce warnings"
848 /// The `unused_features` lint detects unused or unknown features found in
849 /// crate-level [`feature` attributes].
851 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
853 /// Note: This lint is currently not functional, see [issue #44232] for
856 /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
859 "unused features found in crate-level `#[feature]` directives"
863 /// The `stable_features` lint detects a [`feature` attribute] that
864 /// has since been made stable.
866 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
871 /// #![feature(test_accepted_feature)]
879 /// When a feature is stabilized, it is no longer necessary to include a
880 /// `#![feature]` attribute for it. To fix, simply remove the
881 /// `#![feature]` attribute.
884 "stable features found in `#[feature]` directive"
888 /// The `unknown_crate_types` lint detects an unknown crate type found in
889 /// a [`crate_type` attribute].
893 /// ```rust,compile_fail
894 /// #![crate_type="lol"]
902 /// An unknown value give to the `crate_type` attribute is almost
903 /// certainly a mistake.
905 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
906 pub UNKNOWN_CRATE_TYPES,
908 "unknown crate type found in `#[crate_type]` directive",
913 /// The `trivial_casts` lint detects trivial casts which could be replaced
914 /// with coercion, which may require a temporary variable.
918 /// ```rust,compile_fail
919 /// #![deny(trivial_casts)]
920 /// let x: &u32 = &42;
921 /// let y = x as *const u32;
928 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
929 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
930 /// usually be inferred.
932 /// This lint is "allow" by default because there are situations, such as
933 /// with FFI interfaces or complex type aliases, where it triggers
934 /// incorrectly, or in situations where it will be more difficult to
935 /// clearly express the intent. It may be possible that this will become a
936 /// warning in the future, possibly with an explicit syntax for coercions
937 /// providing a convenient way to work around the current issues.
938 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
939 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
941 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
942 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
943 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
946 "detects trivial casts which could be removed"
950 /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
951 /// which could be removed.
955 /// ```rust,compile_fail
956 /// #![deny(trivial_numeric_casts)]
957 /// let x = 42_i32 as i32;
964 /// A trivial numeric cast is a cast of a numeric type to the same numeric
965 /// type. This type of cast is usually unnecessary.
967 /// This lint is "allow" by default because there are situations, such as
968 /// with FFI interfaces or complex type aliases, where it triggers
969 /// incorrectly, or in situations where it will be more difficult to
970 /// clearly express the intent. It may be possible that this will become a
971 /// warning in the future, possibly with an explicit syntax for coercions
972 /// providing a convenient way to work around the current issues.
973 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
974 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
976 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
977 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
978 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
979 pub TRIVIAL_NUMERIC_CASTS,
981 "detects trivial casts of numeric types which could be removed"
985 /// The `private_in_public` lint detects private items in public
986 /// interfaces not caught by the old implementation.
991 /// # #![allow(unused)]
996 /// impl super::SemiPriv {
997 /// pub fn f(_: Priv) {}
1007 /// The visibility rules are intended to prevent exposing private items in
1008 /// public interfaces. This is a [future-incompatible] lint to transition
1009 /// this to a hard error in the future. See [issue #34537] for more
1012 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1013 /// [future-incompatible]: ../index.md#future-incompatible-lints
1014 pub PRIVATE_IN_PUBLIC,
1016 "detect private items in public interfaces not caught by the old implementation",
1017 @future_incompatible = FutureIncompatibleInfo {
1018 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1023 /// The `invalid_alignment` lint detects dereferences of misaligned pointers during
1024 /// constant evluation.
1028 /// ```rust,compile_fail
1029 /// #![feature(const_ptr_read)]
1030 /// const FOO: () = unsafe {
1031 /// let x = &[0_u8; 4];
1032 /// let y = x.as_ptr().cast::<u32>();
1033 /// y.read(); // the address of a `u8` array is unknown and thus we don't know if
1034 /// // it is aligned enough for reading a `u32`.
1042 /// The compiler allowed dereferencing raw pointers irrespective of alignment
1043 /// during const eval due to the const evaluator at the time not making it easy
1044 /// or cheap to check. Now that it is both, this is not accepted anymore.
1046 /// Since it was undefined behaviour to begin with, this breakage does not violate
1047 /// Rust's stability guarantees. Using undefined behaviour can cause arbitrary
1048 /// behaviour, including failure to build.
1050 /// [future-incompatible]: ../index.md#future-incompatible-lints
1051 pub INVALID_ALIGNMENT,
1053 "raw pointers must be aligned before dereferencing",
1054 @future_incompatible = FutureIncompatibleInfo {
1055 reference: "issue #68585 <https://github.com/rust-lang/rust/issues/104616>",
1056 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1061 /// The `exported_private_dependencies` lint detects private dependencies
1062 /// that are exposed in a public interface.
1066 /// ```rust,ignore (needs-dependency)
1067 /// pub fn foo() -> Option<some_private_dependency::Thing> {
1072 /// This will produce:
1075 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1076 /// --> src/lib.rs:3:1
1078 /// 3 | pub fn foo() -> Option<bar::Thing> {
1079 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1081 /// = note: `#[warn(exported_private_dependencies)]` on by default
1086 /// Dependencies can be marked as "private" to indicate that they are not
1087 /// exposed in the public interface of a crate. This can be used by Cargo
1088 /// to independently resolve those dependencies because it can assume it
1089 /// does not need to unify them with other packages using that same
1090 /// dependency. This lint is an indication of a violation of that
1093 /// To fix this, avoid exposing the dependency in your public interface.
1094 /// Or, switch the dependency to a public dependency.
1096 /// Note that support for this is only available on the nightly channel.
1097 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1099 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1100 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1101 pub EXPORTED_PRIVATE_DEPENDENCIES,
1103 "public interface leaks type from a private dependency"
1107 /// The `pub_use_of_private_extern_crate` lint detects a specific
1108 /// situation of re-exporting a private `extern crate`.
1112 /// ```rust,compile_fail
1113 /// extern crate core;
1114 /// pub use core as reexported_core;
1121 /// A public `use` declaration should not be used to publicly re-export a
1122 /// private `extern crate`. `pub extern crate` should be used instead.
1124 /// This was historically allowed, but is not the intended behavior
1125 /// according to the visibility rules. This is a [future-incompatible]
1126 /// lint to transition this to a hard error in the future. See [issue
1127 /// #34537] for more details.
1129 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
1130 /// [future-incompatible]: ../index.md#future-incompatible-lints
1131 pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1133 "detect public re-exports of private extern crates",
1134 @future_incompatible = FutureIncompatibleInfo {
1135 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
1140 /// The `invalid_type_param_default` lint detects type parameter defaults
1141 /// erroneously allowed in an invalid location.
1145 /// ```rust,compile_fail
1146 /// fn foo<T=i32>(t: T) {}
1153 /// Default type parameters were only intended to be allowed in certain
1154 /// situations, but historically the compiler allowed them everywhere.
1155 /// This is a [future-incompatible] lint to transition this to a hard
1156 /// error in the future. See [issue #36887] for more details.
1158 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1159 /// [future-incompatible]: ../index.md#future-incompatible-lints
1160 pub INVALID_TYPE_PARAM_DEFAULT,
1162 "type parameter default erroneously allowed in invalid location",
1163 @future_incompatible = FutureIncompatibleInfo {
1164 reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
1169 /// The `renamed_and_removed_lints` lint detects lints that have been
1170 /// renamed or removed.
1175 /// #![deny(raw_pointer_derive)]
1182 /// To fix this, either remove the lint or use the new name. This can help
1183 /// avoid confusion about lints that are no longer valid, and help
1184 /// maintain consistency for renamed lints.
1185 pub RENAMED_AND_REMOVED_LINTS,
1187 "lints that have been renamed or removed"
1191 /// The `const_item_mutation` lint detects attempts to mutate a `const`
1197 /// const FOO: [i32; 1] = [0];
1201 /// // This will print "[0]".
1202 /// println!("{:?}", FOO);
1210 /// Trying to directly mutate a `const` item is almost always a mistake.
1211 /// What is happening in the example above is that a temporary copy of the
1212 /// `const` is mutated, but the original `const` is not. Each time you
1213 /// refer to the `const` by name (such as `FOO` in the example above), a
1214 /// separate copy of the value is inlined at that location.
1216 /// This lint checks for writing directly to a field (`FOO.field =
1217 /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1218 /// reference to the const item (`&mut FOO`), including through an
1219 /// autoderef (`FOO.some_mut_self_method()`).
1221 /// There are various alternatives depending on what you are trying to
1224 /// * First, always reconsider using mutable globals, as they can be
1225 /// difficult to use correctly, and can make the code more difficult to
1226 /// use or understand.
1227 /// * If you are trying to perform a one-time initialization of a global:
1228 /// * If the value can be computed at compile-time, consider using
1229 /// const-compatible values (see [Constant Evaluation]).
1230 /// * For more complex single-initialization cases, consider using a
1231 /// third-party crate, such as [`lazy_static`] or [`once_cell`].
1232 /// * If you are using the [nightly channel], consider the new
1233 /// [`lazy`] module in the standard library.
1234 /// * If you truly need a mutable global, consider using a [`static`],
1235 /// which has a variety of options:
1236 /// * Simple data types can be directly defined and mutated with an
1237 /// [`atomic`] type.
1238 /// * More complex types can be placed in a synchronization primitive
1239 /// like a [`Mutex`], which can be initialized with one of the options
1241 /// * A [mutable `static`] is a low-level primitive, requiring unsafe.
1242 /// Typically This should be avoided in preference of something
1243 /// higher-level like one of the above.
1245 /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1246 /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1247 /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1248 /// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
1249 /// [`lazy_static`]: https://crates.io/crates/lazy_static
1250 /// [`once_cell`]: https://crates.io/crates/once_cell
1251 /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1252 /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1253 pub CONST_ITEM_MUTATION,
1255 "detects attempts to mutate a `const` item",
1259 /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1260 /// patterns as a parameter in functions without a body.
1264 /// ```rust,compile_fail
1266 /// fn foo(mut arg: u8);
1274 /// To fix this, remove `mut` from the parameter in the trait definition;
1275 /// it can be used in the implementation. That is, the following is OK:
1279 /// fn foo(arg: u8); // Removed `mut` here
1282 /// impl Trait for i32 {
1283 /// fn foo(mut arg: u8) { // `mut` here is OK
1289 /// Trait definitions can define functions without a body to specify a
1290 /// function that implementors must define. The parameter names in the
1291 /// body-less functions are only allowed to be `_` or an [identifier] for
1292 /// documentation purposes (only the type is relevant). Previous versions
1293 /// of the compiler erroneously allowed [identifier patterns] with the
1294 /// `mut` keyword, but this was not intended to be allowed. This is a
1295 /// [future-incompatible] lint to transition this to a hard error in the
1296 /// future. See [issue #35203] for more details.
1298 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1299 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1300 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1301 /// [future-incompatible]: ../index.md#future-incompatible-lints
1302 pub PATTERNS_IN_FNS_WITHOUT_BODY,
1304 "patterns in functions without body were erroneously allowed",
1305 @future_incompatible = FutureIncompatibleInfo {
1306 reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1311 /// The `missing_fragment_specifier` lint is issued when an unused pattern in a
1312 /// `macro_rules!` macro definition has a meta-variable (e.g. `$e`) that is not
1313 /// followed by a fragment specifier (e.g. `:expr`).
1315 /// This warning can always be fixed by removing the unused pattern in the
1316 /// `macro_rules!` macro definition.
1320 /// ```rust,compile_fail
1321 /// macro_rules! foo {
1335 /// To fix this, remove the unused pattern from the `macro_rules!` macro definition:
1338 /// macro_rules! foo {
1345 pub MISSING_FRAGMENT_SPECIFIER,
1347 "detects missing fragment specifiers in unused `macro_rules!` patterns",
1348 @future_incompatible = FutureIncompatibleInfo {
1349 reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1354 /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1355 /// arguments in path segments with late bound lifetime parameters.
1363 /// fn late(self, _: &u8, _: &u8) {}
1367 /// S.late::<'static>(&0, &0);
1375 /// It is not clear how to provide arguments for early-bound lifetime
1376 /// parameters if they are intermixed with late-bound parameters in the
1377 /// same list. For now, providing any explicit arguments will trigger this
1378 /// lint if late-bound parameters are present, so in the future a solution
1379 /// can be adopted without hitting backward compatibility issues. This is
1380 /// a [future-incompatible] lint to transition this to a hard error in the
1381 /// future. See [issue #42868] for more details, along with a description
1382 /// of the difference between early and late-bound parameters.
1384 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1385 /// [future-incompatible]: ../index.md#future-incompatible-lints
1386 pub LATE_BOUND_LIFETIME_ARGUMENTS,
1388 "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1389 @future_incompatible = FutureIncompatibleInfo {
1390 reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1395 /// The `order_dependent_trait_objects` lint detects a trait coherency
1396 /// violation that would allow creating two trait impls for the same
1397 /// dynamic trait object involving marker traits.
1401 /// ```rust,compile_fail
1402 /// pub trait Trait {}
1404 /// impl Trait for dyn Send + Sync { }
1405 /// impl Trait for dyn Sync + Send { }
1412 /// A previous bug caused the compiler to interpret traits with different
1413 /// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1414 /// when they were intended to be treated the same. This allowed code to
1415 /// define separate trait implementations when there should be a coherence
1416 /// error. This is a [future-incompatible] lint to transition this to a
1417 /// hard error in the future. See [issue #56484] for more details.
1419 /// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1420 /// [future-incompatible]: ../index.md#future-incompatible-lints
1421 pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1423 "trait-object types were treated as different depending on marker-trait order",
1424 @future_incompatible = FutureIncompatibleInfo {
1425 reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1426 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
1431 /// The `coherence_leak_check` lint detects conflicting implementations of
1432 /// a trait that are only distinguished by the old leak-check code.
1437 /// trait SomeTrait { }
1438 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1439 /// impl<'a> SomeTrait for fn(&'a u8) { }
1446 /// In the past, the compiler would accept trait implementations for
1447 /// identical functions that differed only in where the lifetime binder
1448 /// appeared. Due to a change in the borrow checker implementation to fix
1449 /// several bugs, this is no longer allowed. However, since this affects
1450 /// existing code, this is a [future-incompatible] lint to transition this
1451 /// to a hard error in the future.
1453 /// Code relying on this pattern should introduce "[newtypes]",
1454 /// like `struct Foo(for<'a> fn(&'a u8))`.
1456 /// See [issue #56105] for more details.
1458 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1459 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1460 /// [future-incompatible]: ../index.md#future-incompatible-lints
1461 pub COHERENCE_LEAK_CHECK,
1463 "distinct impls distinguished only by the leak-check code",
1464 @future_incompatible = FutureIncompatibleInfo {
1465 reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1470 /// The `deprecated` lint detects use of deprecated items.
1487 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1488 /// indicate that they should no longer be used. Usually the attribute
1489 /// should include a note on what to use instead, or check the
1492 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1495 "detects use of deprecated items",
1496 report_in_external_macro
1500 /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1512 /// If nothing within the block requires `unsafe`, then remove the
1513 /// `unsafe` marker because it is not required and may cause confusion.
1516 "unnecessary use of an `unsafe` block"
1520 /// The `unused_mut` lint detects mut variables which don't need to be
1533 /// The preferred style is to only mark variables as `mut` if it is
1537 "detect mut variables which don't need to be mutable"
1541 /// The `unconditional_recursion` lint detects functions that cannot
1542 /// return without calling themselves.
1556 /// It is usually a mistake to have a recursive call that does not have
1557 /// some condition to cause it to terminate. If you really intend to have
1558 /// an infinite loop, using a `loop` expression is recommended.
1559 pub UNCONDITIONAL_RECURSION,
1561 "functions that cannot return without calling themselves"
1565 /// The `single_use_lifetimes` lint detects lifetimes that are only used
1570 /// ```rust,compile_fail
1571 /// #![deny(single_use_lifetimes)]
1573 /// fn foo<'a>(x: &'a u32) {}
1580 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1581 /// should only be used to link together two things. Otherwise, you should
1582 /// just use `'_` to indicate that the lifetime is not linked to anything,
1583 /// or elide the lifetime altogether if possible.
1585 /// This lint is "allow" by default because it was introduced at a time
1586 /// when `'_` and elided lifetimes were first being introduced, and this
1587 /// lint would be too noisy. Also, there are some known false positives
1588 /// that it produces. See [RFC 2115] for historical context, and [issue
1589 /// #44752] for more details.
1591 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1592 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1593 pub SINGLE_USE_LIFETIMES,
1595 "detects lifetime parameters that are only used once"
1599 /// The `unused_lifetimes` lint detects lifetime parameters that are never
1604 /// ```rust,compile_fail
1605 /// #[deny(unused_lifetimes)]
1607 /// pub fn foo<'a>() {}
1614 /// Unused lifetime parameters may signal a mistake or unfinished code.
1615 /// Consider removing the parameter.
1616 pub UNUSED_LIFETIMES,
1618 "detects lifetime parameters that are never used"
1622 /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1623 /// inference variable.
1627 /// ```rust,edition2015
1629 /// let data = std::ptr::null();
1630 /// let _ = &data as *const *const ();
1632 /// if data.is_null() {}
1639 /// This kind of inference was previously allowed, but with the future
1640 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1641 /// resolve this, use an explicit type instead of relying on type
1644 /// This is a [future-incompatible] lint to transition this to a hard
1645 /// error in the 2018 edition. See [issue #46906] for more details. This
1646 /// is currently a hard-error on the 2018 edition, and is "warn" by
1647 /// default in the 2015 edition.
1649 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1650 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1651 /// [future-incompatible]: ../index.md#future-incompatible-lints
1652 pub TYVAR_BEHIND_RAW_POINTER,
1654 "raw pointer to an inference variable",
1655 @future_incompatible = FutureIncompatibleInfo {
1656 reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1657 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1662 /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1663 /// lifetime parameters.
1667 /// ```rust,compile_fail
1668 /// #![deny(elided_lifetimes_in_paths)]
1669 /// struct Foo<'a> {
1673 /// fn foo(x: &Foo) {
1681 /// Elided lifetime parameters can make it difficult to see at a glance
1682 /// that borrowing is occurring. This lint ensures that lifetime
1683 /// parameters are always explicitly stated, even if it is the `'_`
1684 /// [placeholder lifetime].
1686 /// This lint is "allow" by default because it has some known issues, and
1687 /// may require a significant transition for old code.
1689 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1690 pub ELIDED_LIFETIMES_IN_PATHS,
1692 "hidden lifetime parameters in types are deprecated",
1697 /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1702 /// ```rust,edition2018
1705 /// fn takes_trait_object(_: Box<Trait>) {
1713 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1714 /// reading code as to whether or not you are looking at a trait object.
1715 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1716 /// with [`impl Trait`].
1718 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1719 pub BARE_TRAIT_OBJECTS,
1721 "suggest using `dyn Trait` for trait objects",
1722 @future_incompatible = FutureIncompatibleInfo {
1723 reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>",
1724 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
1729 /// The `absolute_paths_not_starting_with_crate` lint detects fully
1730 /// qualified paths that start with a module name instead of `crate`,
1731 /// `self`, or an extern crate name
1735 /// ```rust,edition2015,compile_fail
1736 /// #![deny(absolute_paths_not_starting_with_crate)]
1751 /// Rust [editions] allow the language to evolve without breaking
1752 /// backwards compatibility. This lint catches code that uses absolute
1753 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1754 /// paths (those starting with `::`) refer to either the crate root or an
1755 /// external crate. In the 2018 edition it was changed so that they only
1756 /// refer to external crates. The path prefix `crate::` should be used
1757 /// instead to reference items from the crate root.
1759 /// If you switch the compiler from the 2015 to 2018 edition without
1760 /// updating the code, then it will fail to compile if the old style paths
1761 /// are used. You can manually change the paths to use the `crate::`
1762 /// prefix to transition to the 2018 edition.
1764 /// This lint solves the problem automatically. It is "allow" by default
1765 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1766 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1767 /// and automatically apply the suggested fix from the compiler. This
1768 /// provides a completely automated way to update old code to the 2018
1771 /// [editions]: https://doc.rust-lang.org/edition-guide/
1772 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1773 pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1775 "fully qualified paths that start with a module name \
1776 instead of `crate`, `self`, or an extern crate name",
1777 @future_incompatible = FutureIncompatibleInfo {
1778 reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1779 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2018),
1784 /// The `illegal_floating_point_literal_pattern` lint detects
1785 /// floating-point literals used in patterns.
1802 /// Previous versions of the compiler accepted floating-point literals in
1803 /// patterns, but it was later determined this was a mistake. The
1804 /// semantics of comparing floating-point values may not be clear in a
1805 /// pattern when contrasted with "structural equality". Typically you can
1806 /// work around this by using a [match guard], such as:
1812 /// y if y == 5.0 => {}
1817 /// This is a [future-incompatible] lint to transition this to a hard
1818 /// error in the future. See [issue #41620] for more details.
1820 /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1821 /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1822 /// [future-incompatible]: ../index.md#future-incompatible-lints
1823 pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1825 "floating-point literals cannot be used in patterns",
1826 @future_incompatible = FutureIncompatibleInfo {
1827 reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1832 /// The `unstable_name_collisions` lint detects that you have used a name
1833 /// that the standard library plans to add in the future.
1838 /// trait MyIterator : Iterator {
1839 /// // is_sorted is an unstable method that already exists on the Iterator trait
1840 /// fn is_sorted(self) -> bool where Self: Sized {true}
1843 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1845 /// let x = vec![1, 2, 3];
1846 /// let _ = x.iter().is_sorted();
1853 /// When new methods are added to traits in the standard library, they are
1854 /// usually added in an "unstable" form which is only available on the
1855 /// [nightly channel] with a [`feature` attribute]. If there is any
1856 /// pre-existing code which extends a trait to have a method with the same
1857 /// name, then the names will collide. In the future, when the method is
1858 /// stabilized, this will cause an error due to the ambiguity. This lint
1859 /// is an early-warning to let you know that there may be a collision in
1860 /// the future. This can be avoided by adding type annotations to
1861 /// disambiguate which trait method you intend to call, such as
1862 /// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
1864 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1865 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1866 pub UNSTABLE_NAME_COLLISIONS,
1868 "detects name collision with an existing but unstable method",
1869 @future_incompatible = FutureIncompatibleInfo {
1870 reason: FutureIncompatibilityReason::Custom(
1871 "once this associated item is added to the standard library, \
1872 the ambiguity may cause an error or change in behavior!"
1874 reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1875 // Note: this item represents future incompatibility of all unstable functions in the
1876 // standard library, and thus should never be removed or changed to an error.
1881 /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1882 /// in [`if let`]s, [`while let`]s, and `if let` guards.
1887 /// if let _ = 123 {
1888 /// println!("always runs!");
1896 /// There usually isn't a reason to have an irrefutable pattern in an
1897 /// `if let` or `while let` statement, because the pattern will always match
1898 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1899 /// when generating code with a macro, forbidding irrefutable patterns
1900 /// would require awkward workarounds in situations where the macro
1901 /// doesn't know if the pattern is refutable or not. This lint allows
1902 /// macros to accept this form, while alerting for a possibly incorrect
1903 /// use in normal code.
1905 /// See [RFC 2086] for more details.
1907 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1908 /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1909 /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1910 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1911 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1912 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1913 pub IRREFUTABLE_LET_PATTERNS,
1915 "detects irrefutable patterns in `if let` and `while let` statements"
1919 /// The `unused_labels` lint detects [labels] that are never used.
1921 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1926 /// 'unused_label: loop {}
1933 /// Unused labels may signal a mistake or unfinished code. To silence the
1934 /// warning for the individual label, prefix it with an underscore such as
1938 "detects labels that are never used"
1942 /// The `where_clauses_object_safety` lint detects for [object safety] of
1943 /// [where clauses].
1945 /// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
1946 /// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
1953 /// trait X { fn foo(&self) where Self: Trait; }
1955 /// impl X for () { fn foo(&self) {} }
1957 /// impl Trait for dyn X {}
1959 /// // Segfault at opt-level 0, SIGILL otherwise.
1960 /// pub fn main() { <dyn X as X>::foo(&()); }
1967 /// The compiler previously allowed these object-unsafe bounds, which was
1968 /// incorrect. This is a [future-incompatible] lint to transition this to
1969 /// a hard error in the future. See [issue #51443] for more details.
1971 /// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
1972 /// [future-incompatible]: ../index.md#future-incompatible-lints
1973 pub WHERE_CLAUSES_OBJECT_SAFETY,
1975 "checks the object safety of where clauses",
1976 @future_incompatible = FutureIncompatibleInfo {
1977 reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
1982 /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1983 /// derives using inaccessible names from parent modules.
1987 /// ```rust,ignore (proc-macro)
1989 /// #![crate_type = "proc-macro"]
1991 /// extern crate proc_macro;
1993 /// use proc_macro::*;
1995 /// #[proc_macro_derive(Foo)]
1996 /// pub fn foo1(a: TokenStream) -> TokenStream {
1998 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2002 /// ```rust,ignore (needs-dependency)
2005 /// extern crate foo;
2007 /// struct Something;
2015 /// This will produce:
2018 /// warning: cannot find type `Something` in this scope
2019 /// --> src/main.rs:8:10
2021 /// 8 | #[derive(Foo)]
2022 /// | ^^^ names from parent modules are not accessible without an explicit import
2024 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2025 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2026 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2031 /// If a proc-macro generates a module, the compiler unintentionally
2032 /// allowed items in that module to refer to items in the crate root
2033 /// without importing them. This is a [future-incompatible] lint to
2034 /// transition this to a hard error in the future. See [issue #50504] for
2037 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2038 /// [future-incompatible]: ../index.md#future-incompatible-lints
2039 pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2041 "detects proc macro derives using inaccessible names from parent modules",
2042 @future_incompatible = FutureIncompatibleInfo {
2043 reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
2044 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2049 /// The `macro_use_extern_crate` lint detects the use of the
2050 /// [`macro_use` attribute].
2054 /// ```rust,ignore (needs extern crate)
2055 /// #![deny(macro_use_extern_crate)]
2058 /// extern crate serde_json;
2061 /// let _ = json!{{}};
2065 /// This will produce:
2068 /// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
2069 /// --> src/main.rs:3:1
2071 /// 3 | #[macro_use]
2074 /// note: the lint level is defined here
2075 /// --> src/main.rs:1:9
2077 /// 1 | #![deny(macro_use_extern_crate)]
2078 /// | ^^^^^^^^^^^^^^^^^^^^^^
2083 /// The [`macro_use` attribute] on an [`extern crate`] item causes
2084 /// macros in that external crate to be brought into the prelude of the
2085 /// crate, making the macros in scope everywhere. As part of the efforts
2086 /// to simplify handling of dependencies in the [2018 edition], the use of
2087 /// `extern crate` is being phased out. To bring macros from extern crates
2088 /// into scope, it is recommended to use a [`use` import].
2090 /// This lint is "allow" by default because this is a stylistic choice
2091 /// that has not been settled, see [issue #52043] for more information.
2093 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2094 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2095 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2096 pub MACRO_USE_EXTERN_CRATE,
2098 "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2099 via the module system"
2103 /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2104 /// detects macro-expanded [`macro_export`] macros from the current crate
2105 /// that cannot be referred to by absolute paths.
2107 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2111 /// ```rust,compile_fail
2112 /// macro_rules! define_exported {
2115 /// macro_rules! exported {
2121 /// define_exported!();
2124 /// crate::exported!();
2132 /// The intent is that all macros marked with the `#[macro_export]`
2133 /// attribute are made available in the root of the crate. However, when a
2134 /// `macro_rules!` definition is generated by another macro, the macro
2135 /// expansion is unable to uphold this rule. This is a
2136 /// [future-incompatible] lint to transition this to a hard error in the
2137 /// future. See [issue #53495] for more details.
2139 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2140 /// [future-incompatible]: ../index.md#future-incompatible-lints
2141 pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2143 "macro-expanded `macro_export` macros from the current crate \
2144 cannot be referred to by absolute paths",
2145 @future_incompatible = FutureIncompatibleInfo {
2146 reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2152 /// The `explicit_outlives_requirements` lint detects unnecessary
2153 /// lifetime bounds that can be inferred.
2157 /// ```rust,compile_fail
2158 /// # #![allow(unused)]
2159 /// #![deny(explicit_outlives_requirements)]
2161 /// struct SharedRef<'a, T>
2173 /// If a `struct` contains a reference, such as `&'a T`, the compiler
2174 /// requires that `T` outlives the lifetime `'a`. This historically
2175 /// required writing an explicit lifetime bound to indicate this
2176 /// requirement. However, this can be overly explicit, causing clutter and
2177 /// unnecessary complexity. The language was changed to automatically
2178 /// infer the bound if it is not specified. Specifically, if the struct
2179 /// contains a reference, directly or indirectly, to `T` with lifetime
2180 /// `'x`, then it will infer that `T: 'x` is a requirement.
2182 /// This lint is "allow" by default because it can be noisy for existing
2183 /// code that already had these requirements. This is a stylistic choice,
2184 /// as it is still valid to explicitly state the bound. It also has some
2185 /// false positives that can cause confusion.
2187 /// See [RFC 2093] for more details.
2189 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2190 pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2192 "outlives requirements can be inferred"
2196 /// The `indirect_structural_match` lint detects a `const` in a pattern
2197 /// that manually implements [`PartialEq`] and [`Eq`].
2199 /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2200 /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2204 /// ```rust,compile_fail
2205 /// #![deny(indirect_structural_match)]
2207 /// struct NoDerive(i32);
2208 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2209 /// impl Eq for NoDerive { }
2210 /// #[derive(PartialEq, Eq)]
2211 /// struct WrapParam<T>(T);
2212 /// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
2214 /// match WRAP_INDIRECT_PARAM {
2215 /// WRAP_INDIRECT_PARAM => { }
2225 /// The compiler unintentionally accepted this form in the past. This is a
2226 /// [future-incompatible] lint to transition this to a hard error in the
2227 /// future. See [issue #62411] for a complete description of the problem,
2228 /// and some possible solutions.
2230 /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2231 /// [future-incompatible]: ../index.md#future-incompatible-lints
2232 pub INDIRECT_STRUCTURAL_MATCH,
2234 "constant used in pattern contains value of non-structural-match type in a field or a variant",
2235 @future_incompatible = FutureIncompatibleInfo {
2236 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2241 /// The `deprecated_in_future` lint is internal to rustc and should not be
2242 /// used by user code.
2244 /// This lint is only enabled in the standard library. It works with the
2245 /// use of `#[deprecated]` with a `since` field of a version in the future.
2246 /// This allows something to be marked as deprecated in a future version,
2247 /// and then this lint will ensure that the item is no longer used in the
2248 /// standard library. See the [stability documentation] for more details.
2250 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2251 pub DEPRECATED_IN_FUTURE,
2253 "detects use of items that will be deprecated in a future version",
2254 report_in_external_macro
2258 /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2259 /// cannot be relied upon across compiler versions and optimization levels.
2263 /// ```rust,compile_fail
2264 /// #![deny(pointer_structural_match)]
2265 /// fn foo(a: usize, b: usize) -> usize { a + b }
2266 /// const FOO: fn(usize, usize) -> usize = foo;
2279 /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2280 /// While these work in many cases as expected by users, it is possible that due to
2281 /// optimizations pointers are "not equal to themselves" or pointers to different functions
2282 /// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2283 /// functions if their bodies are the same, thus also making pointers to these functions point
2284 /// to the same location. Additionally functions may get duplicated if they are instantiated
2285 /// in different crates and not deduplicated again via LTO.
2286 pub POINTER_STRUCTURAL_MATCH,
2288 "pointers are not structural-match",
2289 @future_incompatible = FutureIncompatibleInfo {
2290 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2295 /// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2296 /// whose type is not structural-match and whose initializer body actually uses values
2297 /// that are not structural-match. So `Option<NotStructuralMatch>` is ok if the constant
2302 /// ```rust,compile_fail
2303 /// #![deny(nontrivial_structural_match)]
2305 /// #[derive(Copy, Clone, Debug)]
2306 /// struct NoDerive(u32);
2307 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2308 /// impl Eq for NoDerive { }
2310 /// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2311 /// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2319 /// Previous versions of Rust accepted constants in patterns, even if those constants' types
2320 /// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2321 /// `PartialEq`, which can report that two constants are not equal even if they are
2323 pub NONTRIVIAL_STRUCTURAL_MATCH,
2325 "constant used in pattern of non-structural-match type and the constant's initializer \
2326 expression contains values of non-structural-match types",
2327 @future_incompatible = FutureIncompatibleInfo {
2328 reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2333 /// The `ambiguous_associated_items` lint detects ambiguity between
2334 /// [associated items] and [enum variants].
2336 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2337 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2341 /// ```rust,compile_fail
2348 /// fn foo() -> Self::V;
2353 /// // `Self::V` is ambiguous because it may refer to the associated type or
2354 /// // the enum variant.
2355 /// fn foo() -> Self::V { 0 }
2363 /// Previous versions of Rust did not allow accessing enum variants
2364 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2365 /// introduced some situations where it can be ambiguous what a type
2366 /// was referring to.
2368 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2369 /// state which type to use. For example, in the above example the
2370 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2371 /// specifically refer to the associated type.
2373 /// This is a [future-incompatible] lint to transition this to a hard
2374 /// error in the future. See [issue #57644] for more details.
2376 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2377 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2378 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2379 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2380 /// [future-incompatible]: ../index.md#future-incompatible-lints
2381 pub AMBIGUOUS_ASSOCIATED_ITEMS,
2383 "ambiguous associated items",
2384 @future_incompatible = FutureIncompatibleInfo {
2385 reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2390 /// The `soft_unstable` lint detects unstable features that were
2391 /// unintentionally allowed on stable.
2395 /// ```rust,compile_fail
2397 /// extern crate test;
2400 /// fn name(b: &mut test::Bencher) {
2409 /// The [`bench` attribute] was accidentally allowed to be specified on
2410 /// the [stable release channel]. Turning this to a hard error would have
2411 /// broken some projects. This lint allows those projects to continue to
2412 /// build correctly when [`--cap-lints`] is used, but otherwise signal an
2413 /// error that `#[bench]` should not be used on the stable channel. This
2414 /// is a [future-incompatible] lint to transition this to a hard error in
2415 /// the future. See [issue #64266] for more details.
2417 /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2418 /// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
2419 /// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2420 /// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
2421 /// [future-incompatible]: ../index.md#future-incompatible-lints
2424 "a feature gate that doesn't break dependent crates",
2425 @future_incompatible = FutureIncompatibleInfo {
2426 reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2431 /// The `inline_no_sanitize` lint detects incompatible use of
2432 /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2434 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2435 /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2440 /// #![feature(no_sanitize)]
2442 /// #[inline(always)]
2443 /// #[no_sanitize(address)]
2455 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2456 /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2457 /// Consider temporarily removing `inline` attribute.
2458 pub INLINE_NO_SANITIZE,
2460 "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2464 /// The `asm_sub_register` lint detects using only a subset of a register
2465 /// for inline asm inputs.
2469 /// ```rust,ignore (fails on non-x86_64)
2470 /// #[cfg(target_arch="x86_64")]
2471 /// use std::arch::asm;
2474 /// #[cfg(target_arch="x86_64")]
2476 /// asm!("mov {0}, {0}", in(reg) 0i16);
2481 /// This will produce:
2484 /// warning: formatting may not be suitable for sub-register argument
2485 /// --> src/main.rs:7:19
2487 /// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
2488 /// | ^^^ ^^^ ---- for this argument
2490 /// = note: `#[warn(asm_sub_register)]` on by default
2491 /// = help: use the `x` modifier to have the register formatted as `ax`
2492 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2497 /// Registers on some architectures can use different names to refer to a
2498 /// subset of the register. By default, the compiler will use the name for
2499 /// the full register size. To explicitly use a subset of the register,
2500 /// you can override the default by using a modifier on the template
2501 /// string operand to specify when subregister to use. This lint is issued
2502 /// if you pass in a value with a smaller data type than the default
2503 /// register size, to alert you of possibly using the incorrect width. To
2504 /// fix this, add the suggested modifier to the template, or cast the
2505 /// value to the correct size.
2507 /// See [register template modifiers] in the reference for more details.
2509 /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2510 pub ASM_SUB_REGISTER,
2512 "using only a subset of a register for inline asm inputs",
2516 /// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2517 /// `.att_syntax` directives.
2521 /// ```rust,ignore (fails on non-x86_64)
2522 /// #[cfg(target_arch="x86_64")]
2523 /// use std::arch::asm;
2526 /// #[cfg(target_arch="x86_64")]
2530 /// "movq %{0}, %{0}", in(reg) 0usize
2536 /// This will produce:
2539 /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2540 /// --> src/main.rs:8:14
2542 /// 8 | ".att_syntax",
2545 /// = note: `#[warn(bad_asm_style)]` on by default
2550 /// On x86, `asm!` uses the intel assembly syntax by default. While this
2551 /// can be switched using assembler directives like `.att_syntax`, using the
2552 /// `att_syntax` option is recommended instead because it will also properly
2553 /// prefix register placeholders with `%` as required by AT&T syntax.
2556 "incorrect use of inline assembly",
2560 /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2561 /// functions without an explicit unsafe block.
2565 /// ```rust,compile_fail
2566 /// #![deny(unsafe_op_in_unsafe_fn)]
2568 /// unsafe fn foo() {}
2570 /// unsafe fn bar() {
2581 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2582 /// body. However, this can increase the surface area of code that needs
2583 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2584 /// convenient way to make it clear exactly which parts of the code are
2585 /// performing unsafe operations. In the future, it is desired to change
2586 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2587 /// without an `unsafe` block.
2589 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2591 /// This lint is "allow" by default since this will affect a large amount
2592 /// of existing code, and the exact plan for increasing the severity is
2593 /// still being considered. See [RFC #2585] and [issue #71668] for more
2596 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2597 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2598 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2599 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2600 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2601 pub UNSAFE_OP_IN_UNSAFE_FN,
2603 "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2607 /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2608 /// `enum` that implements [`Drop`].
2610 /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2614 /// ```rust,compile_fail
2615 /// # #![allow(unused)]
2620 /// impl Drop for E {
2621 /// fn drop(&mut self) {
2622 /// println!("Drop");
2628 /// let i = e as u32;
2636 /// Casting a field-less `enum` that does not implement [`Copy`] to an
2637 /// integer moves the value without calling `drop`. This can result in
2638 /// surprising behavior if it was expected that `drop` should be called.
2639 /// Calling `drop` automatically would be inconsistent with other move
2640 /// operations. Since neither behavior is clear or consistent, it was
2641 /// decided that a cast of this nature will no longer be allowed.
2643 /// This is a [future-incompatible] lint to transition this to a hard error
2644 /// in the future. See [issue #73333] for more details.
2646 /// [future-incompatible]: ../index.md#future-incompatible-lints
2647 /// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
2648 /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
2649 pub CENUM_IMPL_DROP_CAST,
2651 "a C-like enum implementing Drop is cast",
2652 @future_incompatible = FutureIncompatibleInfo {
2653 reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
2654 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2659 /// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
2665 /// #![feature(strict_provenance)]
2666 /// #![warn(fuzzy_provenance_casts)]
2669 /// let _dangling = 16_usize as *const u8;
2677 /// This lint is part of the strict provenance effort, see [issue #95228].
2678 /// Casting an integer to a pointer is considered bad style, as a pointer
2679 /// contains, besides the *address* also a *provenance*, indicating what
2680 /// memory the pointer is allowed to read/write. Casting an integer, which
2681 /// doesn't have provenance, to a pointer requires the compiler to assign
2682 /// (guess) provenance. The compiler assigns "all exposed valid" (see the
2683 /// docs of [`ptr::from_exposed_addr`] for more information about this
2684 /// "exposing"). This penalizes the optimiser and is not well suited for
2685 /// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
2688 /// It is much better to use [`ptr::with_addr`] instead to specify the
2689 /// provenance you want. If using this function is not possible because the
2690 /// code relies on exposed provenance then there is as an escape hatch
2691 /// [`ptr::from_exposed_addr`].
2693 /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2694 /// [`ptr::with_addr`]: https://doc.rust-lang.org/core/ptr/fn.with_addr
2695 /// [`ptr::from_exposed_addr`]: https://doc.rust-lang.org/core/ptr/fn.from_exposed_addr
2696 pub FUZZY_PROVENANCE_CASTS,
2698 "a fuzzy integer to pointer cast is used",
2699 @feature_gate = sym::strict_provenance;
2703 /// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
2709 /// #![feature(strict_provenance)]
2710 /// #![warn(lossy_provenance_casts)]
2714 /// let _addr: usize = &x as *const u8 as usize;
2722 /// This lint is part of the strict provenance effort, see [issue #95228].
2723 /// Casting a pointer to an integer is a lossy operation, because beyond
2724 /// just an *address* a pointer may be associated with a particular
2725 /// *provenance*. This information is used by the optimiser and for dynamic
2726 /// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
2728 /// Since this cast is lossy, it is considered good style to use the
2729 /// [`ptr::addr`] method instead, which has a similar effect, but doesn't
2730 /// "expose" the pointer provenance. This improves optimisation potential.
2731 /// See the docs of [`ptr::addr`] and [`ptr::expose_addr`] for more information
2732 /// about exposing pointer provenance.
2734 /// If your code can't comply with strict provenance and needs to expose
2735 /// the provenance, then there is [`ptr::expose_addr`] as an escape hatch,
2736 /// which preserves the behaviour of `as usize` casts while being explicit
2737 /// about the semantics.
2739 /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2740 /// [`ptr::addr`]: https://doc.rust-lang.org/core/ptr/fn.addr
2741 /// [`ptr::expose_addr`]: https://doc.rust-lang.org/core/ptr/fn.expose_addr
2742 pub LOSSY_PROVENANCE_CASTS,
2744 "a lossy pointer to integer cast is used",
2745 @feature_gate = sym::strict_provenance;
2749 /// The `const_evaluatable_unchecked` lint detects a generic constant used
2755 /// const fn foo<T>() -> usize {
2756 /// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2764 /// let _ = [0; foo::<T>()];
2772 /// In the 1.43 release, some uses of generic parameters in array repeat
2773 /// expressions were accidentally allowed. This is a [future-incompatible]
2774 /// lint to transition this to a hard error in the future. See [issue
2775 /// #76200] for a more detailed description and possible fixes.
2777 /// [future-incompatible]: ../index.md#future-incompatible-lints
2778 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2779 pub CONST_EVALUATABLE_UNCHECKED,
2781 "detects a generic constant is used in a type without a emitting a warning",
2782 @future_incompatible = FutureIncompatibleInfo {
2783 reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2788 /// The `function_item_references` lint detects function references that are
2789 /// formatted with [`fmt::Pointer`] or transmuted.
2791 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2799 /// println!("{:p}", &foo);
2807 /// Taking a reference to a function may be mistaken as a way to obtain a
2808 /// pointer to that function. This can give unexpected results when
2809 /// formatting the reference as a pointer or transmuting it. This lint is
2810 /// issued when function references are formatted as pointers, passed as
2811 /// arguments bound by [`fmt::Pointer`] or transmuted.
2812 pub FUNCTION_ITEM_REFERENCES,
2814 "suggest casting to a function pointer when attempting to take references to function items",
2818 /// The `uninhabited_static` lint detects uninhabited statics.
2825 /// static EXTERN: Void;
2833 /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2834 /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2835 /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2836 /// statics). This was accidentally allowed, but is being phased out.
2837 pub UNINHABITED_STATIC,
2839 "uninhabited static",
2840 @future_incompatible = FutureIncompatibleInfo {
2841 reference: "issue #74840 <https://github.com/rust-lang/rust/issues/74840>",
2846 /// The `useless_deprecated` lint detects deprecation attributes with no effect.
2850 /// ```rust,compile_fail
2853 /// #[deprecated = "message"]
2854 /// impl Default for X {
2855 /// fn default() -> Self {
2865 /// Deprecation attributes have no effect on trait implementations.
2866 pub USELESS_DEPRECATED,
2868 "detects deprecation attributes with no effect",
2872 /// The `undefined_naked_function_abi` lint detects naked function definitions that
2873 /// either do not specify an ABI or specify the Rust ABI.
2878 /// #![feature(asm_experimental_arch, naked_functions)]
2880 /// use std::arch::asm;
2883 /// pub fn default_abi() -> u32 {
2884 /// unsafe { asm!("", options(noreturn)); }
2888 /// pub extern "Rust" fn rust_abi() -> u32 {
2889 /// unsafe { asm!("", options(noreturn)); }
2897 /// The Rust ABI is currently undefined. Therefore, naked functions should
2898 /// specify a non-Rust ABI.
2899 pub UNDEFINED_NAKED_FUNCTION_ABI,
2901 "undefined naked function ABI"
2905 /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2909 /// ```rust,compile_fail
2910 /// #![feature(staged_api)]
2912 /// #[derive(Clone)]
2913 /// #[stable(feature = "x", since = "1")]
2916 /// #[unstable(feature = "y", issue = "none")]
2917 /// impl Copy for S {}
2924 /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2925 /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2926 pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2928 "detects `#[unstable]` on stable trait implementations for stable types"
2932 /// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2933 /// in macro bodies when the macro is invoked in expression position.
2934 /// This was previous accepted, but is being phased out.
2938 /// ```rust,compile_fail
2939 /// #![deny(semicolon_in_expressions_from_macros)]
2940 /// macro_rules! foo {
2945 /// let val = match true {
2956 /// Previous, Rust ignored trailing semicolon in a macro
2957 /// body when a macro was invoked in expression position.
2958 /// However, this makes the treatment of semicolons in the language
2959 /// inconsistent, and could lead to unexpected runtime behavior
2960 /// in some circumstances (e.g. if the macro author expects
2961 /// a value to be dropped).
2963 /// This is a [future-incompatible] lint to transition this
2964 /// to a hard error in the future. See [issue #79813] for more details.
2966 /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2967 /// [future-incompatible]: ../index.md#future-incompatible-lints
2968 pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2970 "trailing semicolon in macro body used as expression",
2971 @future_incompatible = FutureIncompatibleInfo {
2972 reference: "issue #79813 <https://github.com/rust-lang/rust/issues/79813>",
2973 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2978 /// The `legacy_derive_helpers` lint detects derive helper attributes
2979 /// that are used before they are introduced.
2983 /// ```rust,ignore (needs extern crate)
2984 /// #[serde(rename_all = "camelCase")]
2985 /// #[derive(Deserialize)]
2986 /// struct S { /* fields */ }
2992 /// warning: derive helper attribute is used before it is introduced
2993 /// --> $DIR/legacy-derive-helpers.rs:1:3
2995 /// 1 | #[serde(rename_all = "camelCase")]
2998 /// 2 | #[derive(Deserialize)]
2999 /// | ----------- the attribute is introduced here
3004 /// Attributes like this work for historical reasons, but attribute expansion works in
3005 /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
3006 /// into the future" at not yet expanded part of the item , but such attempts are not always
3009 /// To fix the warning place the helper attribute after its corresponding derive.
3010 /// ```rust,ignore (needs extern crate)
3011 /// #[derive(Deserialize)]
3012 /// #[serde(rename_all = "camelCase")]
3013 /// struct S { /* fields */ }
3015 pub LEGACY_DERIVE_HELPERS,
3017 "detects derive helper attributes that are used before they are introduced",
3018 @future_incompatible = FutureIncompatibleInfo {
3019 reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
3024 /// The `large_assignments` lint detects when objects of large
3025 /// types are being moved around.
3029 /// ```rust,ignore (can crash on some platforms)
3030 /// let x = [0; 50000];
3037 /// warning: moving a large value
3038 /// --> $DIR/move-large.rs:1:3
3040 /// - Copied large value here
3045 /// When using a large type in a plain assignment or in a function
3046 /// argument, idiomatic code can be inefficient.
3047 /// Ideally appropriate optimizations would resolve this, but such
3048 /// optimizations are only done in a best-effort manner.
3049 /// This lint will trigger on all sites of large moves and thus allow the
3050 /// user to resolve them in code.
3051 pub LARGE_ASSIGNMENTS,
3053 "detects large moves or copies",
3057 /// The `deprecated_cfg_attr_crate_type_name` lint detects uses of the
3058 /// `#![cfg_attr(..., crate_type = "...")]` and
3059 /// `#![cfg_attr(..., crate_name = "...")]` attributes to conditionally
3060 /// specify the crate type and name in the source code.
3064 /// ```rust,compile_fail
3065 /// #![cfg_attr(debug_assertions, crate_type = "lib")]
3073 /// The `#![crate_type]` and `#![crate_name]` attributes require a hack in
3074 /// the compiler to be able to change the used crate type and crate name
3075 /// after macros have been expanded. Neither attribute works in combination
3076 /// with Cargo as it explicitly passes `--crate-type` and `--crate-name` on
3077 /// the commandline. These values must match the value used in the source
3078 /// code to prevent an error.
3080 /// To fix the warning use `--crate-type` on the commandline when running
3081 /// rustc instead of `#![cfg_attr(..., crate_type = "...")]` and
3082 /// `--crate-name` instead of `#![cfg_attr(..., crate_name = "...")]`.
3083 pub DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3085 "detects usage of `#![cfg_attr(..., crate_type/crate_name = \"...\")]`",
3086 @future_incompatible = FutureIncompatibleInfo {
3087 reference: "issue #91632 <https://github.com/rust-lang/rust/issues/91632>",
3092 /// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
3097 /// rustc --check-cfg 'names()'
3100 /// ```rust,ignore (needs command line option)
3105 /// This will produce:
3108 /// warning: unknown condition name used
3109 /// --> lint_example.rs:1:7
3111 /// 1 | #[cfg(widnows)]
3114 /// = note: `#[warn(unexpected_cfgs)]` on by default
3119 /// This lint is only active when a `--check-cfg='names(...)'` option has been passed
3120 /// to the compiler and triggers whenever an unknown condition name or value is used.
3121 /// The known condition include names or values passed in `--check-cfg`, `--cfg`, and some
3122 /// well-knows names and values built into the compiler.
3123 pub UNEXPECTED_CFGS,
3125 "detects unexpected names and values in `#[cfg]` conditions",
3129 /// The `repr_transparent_external_private_fields` lint
3130 /// detects types marked `#[repr(transparent)]` that (transitively)
3131 /// contain an external ZST type marked `#[non_exhaustive]` or containing
3136 /// ```rust,ignore (needs external crate)
3137 /// #![deny(repr_transparent_external_private_fields)]
3138 /// use foo::NonExhaustiveZst;
3140 /// #[repr(transparent)]
3141 /// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3144 /// This will produce:
3147 /// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
3148 /// --> src/main.rs:5:28
3150 /// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3151 /// | ^^^^^^^^^^^^^^^^
3153 /// note: the lint level is defined here
3154 /// --> src/main.rs:1:9
3156 /// 1 | #![deny(repr_transparent_external_private_fields)]
3157 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3158 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3159 /// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3160 /// = note: this struct contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.
3165 /// Previous, Rust accepted fields that contain external private zero-sized types,
3166 /// even though it should not be a breaking change to add a non-zero-sized field to
3167 /// that private type.
3169 /// This is a [future-incompatible] lint to transition this
3170 /// to a hard error in the future. See [issue #78586] for more details.
3172 /// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
3173 /// [future-incompatible]: ../index.md#future-incompatible-lints
3174 pub REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3176 "transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
3177 @future_incompatible = FutureIncompatibleInfo {
3178 reference: "issue #78586 <https://github.com/rust-lang/rust/issues/78586>",
3183 /// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3184 /// syntax that is discarded during attribute expansion.
3197 /// The input to active attributes such as `#[cfg]` or procedural macro
3198 /// attributes is required to be valid syntax. Previously, the compiler only
3199 /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3200 /// and expanding procedural macros.
3202 /// To avoid relying on unstable syntax, move the use of unstable syntax
3203 /// into a position where the compiler does not parse the syntax, such as a
3204 /// functionlike macro.
3207 /// # #![deny(unstable_syntax_pre_expansion)]
3209 /// macro_rules! identity {
3210 /// ( $($tokens:tt)* ) => { $($tokens)* }
3219 /// This is a [future-incompatible] lint to transition this
3220 /// to a hard error in the future. See [issue #65860] for more details.
3222 /// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
3223 /// [future-incompatible]: ../index.md#future-incompatible-lints
3224 pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3226 "unstable syntax can change at any point in the future, causing a hard error!",
3227 @future_incompatible = FutureIncompatibleInfo {
3228 reference: "issue #65860 <https://github.com/rust-lang/rust/issues/65860>",
3232 declare_lint_pass! {
3233 /// Does nothing as a lint pass, but registers some `Lint`s
3234 /// that are used by other parts of the compiler.
3236 FORBIDDEN_LINT_GROUPS,
3237 ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
3238 ARITHMETIC_OVERFLOW,
3239 UNCONDITIONAL_PANIC,
3241 UNUSED_EXTERN_CRATES,
3242 UNUSED_CRATE_DEPENDENCIES,
3243 UNUSED_QUALIFICATIONS,
3245 UNFULFILLED_LINT_EXPECTATIONS,
3250 UNREACHABLE_PATTERNS,
3251 OVERLAPPING_RANGE_ENDPOINTS,
3252 BINDINGS_WITH_VARIANT_NAME,
3258 UNKNOWN_CRATE_TYPES,
3260 TRIVIAL_NUMERIC_CASTS,
3262 EXPORTED_PRIVATE_DEPENDENCIES,
3263 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
3264 INVALID_TYPE_PARAM_DEFAULT,
3265 RENAMED_AND_REMOVED_LINTS,
3266 CONST_ITEM_MUTATION,
3267 PATTERNS_IN_FNS_WITHOUT_BODY,
3268 MISSING_FRAGMENT_SPECIFIER,
3269 LATE_BOUND_LIFETIME_ARGUMENTS,
3270 ORDER_DEPENDENT_TRAIT_OBJECTS,
3271 COHERENCE_LEAK_CHECK,
3275 UNCONDITIONAL_RECURSION,
3276 SINGLE_USE_LIFETIMES,
3279 TYVAR_BEHIND_RAW_POINTER,
3280 ELIDED_LIFETIMES_IN_PATHS,
3282 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
3283 UNSTABLE_NAME_COLLISIONS,
3284 IRREFUTABLE_LET_PATTERNS,
3285 WHERE_CLAUSES_OBJECT_SAFETY,
3286 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
3287 MACRO_USE_EXTERN_CRATE,
3288 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
3289 ILL_FORMED_ATTRIBUTE_INPUT,
3290 CONFLICTING_REPR_HINTS,
3291 META_VARIABLE_MISUSE,
3292 DEPRECATED_IN_FUTURE,
3293 AMBIGUOUS_ASSOCIATED_ITEMS,
3294 INDIRECT_STRUCTURAL_MATCH,
3295 POINTER_STRUCTURAL_MATCH,
3296 NONTRIVIAL_STRUCTURAL_MATCH,
3298 UNSTABLE_SYNTAX_PRE_EXPANSION,
3302 UNSAFE_OP_IN_UNSAFE_FN,
3304 CENUM_IMPL_DROP_CAST,
3305 FUZZY_PROVENANCE_CASTS,
3306 LOSSY_PROVENANCE_CASTS,
3307 CONST_EVALUATABLE_UNCHECKED,
3308 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
3311 FUNCTION_ITEM_REFERENCES,
3314 INVALID_DOC_ATTRIBUTES,
3315 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
3316 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3317 LEGACY_DERIVE_HELPERS,
3318 PROC_MACRO_BACK_COMPAT,
3319 RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3321 RUST_2021_PRELUDE_COLLISIONS,
3322 RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3323 UNSUPPORTED_CALLING_CONVENTIONS,
3324 BREAK_WITH_LABEL_AND_LOOP,
3326 UNUSED_TUPLE_STRUCT_FIELDS,
3327 NON_EXHAUSTIVE_OMITTED_PATTERNS,
3328 TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3329 DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
3330 DUPLICATE_MACRO_ATTRIBUTES,
3331 SUSPICIOUS_AUTO_TRAIT_IMPLS,
3332 DEPRECATED_WHERE_CLAUSE_LOCATION,
3335 REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
3336 NAMED_ARGUMENTS_USED_POSITIONALLY,
3337 IMPLIED_BOUNDS_ENTAILMENT,
3338 BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
3343 /// The `unused_doc_comments` lint detects doc comments that aren't used
3357 /// `rustdoc` does not use doc comments in all positions, and so the doc
3358 /// comment will be ignored. Try changing it to a normal comment with `//`
3359 /// to avoid the warning.
3360 pub UNUSED_DOC_COMMENTS,
3362 "detects doc comments that aren't used by rustdoc"
3366 /// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3367 /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3368 /// Rust 2018 and 2021.
3370 /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3371 /// and the field is captured by a closure and used with the assumption that said field implements
3372 /// the same trait as the root variable.
3374 /// ### Example of drop reorder
3376 /// ```rust,edition2018,compile_fail
3377 /// #![deny(rust_2021_incompatible_closure_captures)]
3378 /// # #![allow(unused)]
3380 /// struct FancyInteger(i32);
3382 /// impl Drop for FancyInteger {
3383 /// fn drop(&mut self) {
3384 /// println!("Just dropped {}", self.0);
3388 /// struct Point { x: FancyInteger, y: FancyInteger }
3391 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3399 /// // ... More code ...
3407 /// In the above example, `p.y` will be dropped at the end of `f` instead of
3408 /// with `c` in Rust 2021.
3410 /// ### Example of auto-trait
3412 /// ```rust,edition2018,compile_fail
3413 /// #![deny(rust_2021_incompatible_closure_captures)]
3414 /// use std::thread;
3416 /// struct Pointer(*mut i32);
3417 /// unsafe impl Send for Pointer {}
3421 /// let fptr = Pointer(&mut f as *mut i32);
3422 /// thread::spawn(move || unsafe {
3432 /// In the above example, only `fptr.0` is captured in Rust 2021.
3433 /// The field is of type `*mut i32`, which doesn't implement `Send`,
3434 /// making the code invalid as the field cannot be sent between threads safely.
3435 pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3437 "detects closures affected by Rust 2021 changes",
3438 @future_incompatible = FutureIncompatibleInfo {
3439 reason: FutureIncompatibilityReason::EditionSemanticsChange(Edition::Edition2021),
3440 explain_reason: false,
3444 declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
3447 /// The `missing_abi` lint detects cases where the ABI is omitted from
3448 /// extern declarations.
3452 /// ```rust,compile_fail
3453 /// #![deny(missing_abi)]
3455 /// extern fn foo() {}
3462 /// Historically, Rust implicitly selected C as the ABI for extern
3463 /// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
3464 /// though this has not yet happened, and especially with their addition
3465 /// seeing the ABI easily will make code review easier.
3468 "No declared ABI for extern declaration"
3472 /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3477 /// ```rust,compile_fail
3478 /// #![deny(warnings)]
3480 /// pub mod submodule {
3481 /// #![doc(test(no_crate_inject))]
3489 /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
3490 /// being validated. Usually these should be rejected as a hard error,
3491 /// but this lint was introduced to avoid breaking any existing
3492 /// crates which included them.
3494 /// This is a [future-incompatible] lint to transition this to a hard
3495 /// error in the future. See [issue #82730] for more details.
3497 /// [issue #82730]: https://github.com/rust-lang/rust/issues/82730
3498 pub INVALID_DOC_ATTRIBUTES,
3500 "detects invalid `#[doc(...)]` attributes",
3501 @future_incompatible = FutureIncompatibleInfo {
3502 reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
3507 /// The `proc_macro_back_compat` lint detects uses of old versions of certain
3508 /// proc-macro crates, which have hardcoded workarounds in the compiler.
3512 /// ```rust,ignore (needs-dependency)
3514 /// use time_macros_impl::impl_macros;
3516 /// impl_macros!(Foo);
3519 /// This will produce:
3522 /// warning: using an old version of `time-macros-impl`
3523 /// ::: $DIR/group-compat-hack.rs:27:5
3525 /// LL | impl_macros!(Foo);
3526 /// | ------------------ in this macro invocation
3528 /// = note: `#[warn(proc_macro_back_compat)]` on by default
3529 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3530 /// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3531 /// = 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
3532 /// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3537 /// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3538 /// causing older versions of certain crates to stop compiling.
3539 /// This is a [future-incompatible] lint to ease the transition to an error.
3540 /// See [issue #83125] for more details.
3542 /// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3543 /// [future-incompatible]: ../index.md#future-incompatible-lints
3544 pub PROC_MACRO_BACK_COMPAT,
3546 "detects usage of old versions of certain proc-macro crates",
3547 @future_incompatible = FutureIncompatibleInfo {
3548 reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3549 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
3554 /// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3558 /// ```rust,compile_fail
3559 /// #![deny(rust_2021_incompatible_or_patterns)]
3561 /// macro_rules! match_any {
3562 /// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3565 /// $( $pat => $expr_arm, )+
3572 /// let result: Result<i64, i32> = Err(42);
3573 /// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3574 /// assert_eq!(int, 42);
3582 /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3583 pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3585 "detects usage of old versions of or-patterns",
3586 @future_incompatible = FutureIncompatibleInfo {
3587 reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/or-patterns-macro-rules.html>",
3588 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3593 /// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3594 /// with traits added to the prelude in future editions.
3598 /// ```rust,compile_fail
3599 /// #![deny(rust_2021_prelude_collisions)]
3602 /// fn try_into(self) -> Result<String, !>;
3605 /// impl Foo for &str {
3606 /// fn try_into(self) -> Result<String, !> {
3607 /// Ok(String::from(self))
3612 /// let x: String = "3".try_into().unwrap();
3614 /// // This call to try_into matches both Foo::try_into and TryInto::try_into as
3615 /// // `TryInto` has been added to the Rust prelude in 2021 edition.
3616 /// println!("{x}");
3624 /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3625 /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3626 /// results in an ambiguity as to which method/function to call when an existing `try_into`
3627 /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3628 /// is called directly on a type.
3630 /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3631 pub RUST_2021_PRELUDE_COLLISIONS,
3633 "detects the usage of trait methods which are ambiguous with traits added to the \
3634 prelude in future editions",
3635 @future_incompatible = FutureIncompatibleInfo {
3636 reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/prelude.html>",
3637 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3642 /// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3643 /// prefix instead in Rust 2021.
3647 /// ```rust,edition2018,compile_fail
3648 /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3650 /// macro_rules! m {
3651 /// (z $x:expr) => ();
3661 /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3662 /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3663 /// considered a prefix for `"hey"`.
3665 /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3666 /// to keep them separated in Rust 2021.
3667 // Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3668 #[allow(rustdoc::invalid_rust_codeblocks)]
3669 pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3671 "identifiers that will be parsed as a prefix in Rust 2021",
3672 @future_incompatible = FutureIncompatibleInfo {
3673 reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2021/reserving-syntax.html>",
3674 reason: FutureIncompatibilityReason::EditionError(Edition::Edition2021),
3680 /// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3681 /// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3682 /// variants) on targets that cannot meaningfully be supported for the requested target.
3684 /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3685 /// code, because this calling convention was never specified for those targets.
3687 /// Historically MSVC toolchains have fallen back to the regular C calling convention for
3688 /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3689 /// hack across many more targets.
3693 /// ```rust,ignore (needs specific targets)
3694 /// extern "stdcall" fn stdcall() {}
3697 /// This will produce:
3700 /// warning: use of calling convention not supported on this target
3701 /// --> $DIR/unsupported.rs:39:1
3703 /// LL | extern "stdcall" fn stdcall() {}
3704 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3706 /// = note: `#[warn(unsupported_calling_conventions)]` on by default
3707 /// = warning: this was previously accepted by the compiler but is being phased out;
3708 /// it will become a hard error in a future release!
3709 /// = note: for more information, see issue ...
3714 /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3715 /// defined at all, but was previously accepted due to a bug in the implementation of the
3717 pub UNSUPPORTED_CALLING_CONVENTIONS,
3719 "use of unsupported calling convention",
3720 @future_incompatible = FutureIncompatibleInfo {
3721 reference: "issue #87678 <https://github.com/rust-lang/rust/issues/87678>",
3726 /// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3727 /// an unlabeled loop as their value expression.
3733 /// break 'label loop { break 42; };
3741 /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3742 /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3743 /// can also carry a value expression, which can be another loop. A labeled `break` with an
3744 /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3745 /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3746 /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3747 /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3749 pub BREAK_WITH_LABEL_AND_LOOP,
3751 "`break` expression with label and unlabeled loop as value expression"
3755 /// The `non_exhaustive_omitted_patterns` lint detects when a wildcard (`_` or `..`) in a
3756 /// pattern for a `#[non_exhaustive]` struct or enum is reachable.
3760 /// ```rust,ignore (needs separate crate)
3762 /// #[non_exhaustive]
3765 /// B, // added variant in non breaking change
3769 /// #![feature(non_exhaustive_omitted_patterns_lint)]
3773 /// #[warn(non_exhaustive_omitted_patterns)]
3778 /// This will produce:
3781 /// warning: reachable patterns not covered of non exhaustive enum
3782 /// --> $DIR/reachable-patterns.rs:70:9
3785 /// | ^ pattern `B` not covered
3787 /// note: the lint level is defined here
3788 /// --> $DIR/reachable-patterns.rs:69:16
3790 /// LL | #[warn(non_exhaustive_omitted_patterns)]
3791 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3792 /// = help: ensure that all possible cases are being handled by adding the suggested match arms
3793 /// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3798 /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a
3799 /// (potentially redundant) wildcard when pattern-matching, to allow for future
3800 /// addition of fields or variants. The `non_exhaustive_omitted_patterns` lint
3801 /// detects when such a wildcard happens to actually catch some fields/variants.
3802 /// In other words, when the match without the wildcard would not be exhaustive.
3803 /// This lets the user be informed if new fields/variants were added.
3804 pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3806 "detect when patterns of types marked `non_exhaustive` are missed",
3807 @feature_gate = sym::non_exhaustive_omitted_patterns_lint;
3811 /// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3812 /// change the visual representation of text on screen in a way that does not correspond to
3813 /// their on memory representation.
3817 /// ```rust,compile_fail
3818 /// #![deny(text_direction_codepoint_in_comment)]
3820 /// println!("{:?}"); // '‮');
3828 /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3829 /// are written right-to-left, but a specially crafted comment can make code that will be
3830 /// compiled appear to be part of a comment, depending on the software used to read the code.
3831 /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3833 pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3835 "invisible directionality-changing codepoints in comment"
3839 /// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3840 /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3841 /// and `test_case`.
3845 /// ```rust,ignore (needs --test)
3851 /// This will produce:
3854 /// warning: duplicated attribute
3855 /// --> src/lib.rs:2:1
3860 /// = note: `#[warn(duplicate_macro_attributes)]` on by default
3865 /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3866 /// being duplicated may not be obvious or desirable.
3868 /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3869 /// change to its environment.
3871 /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3872 pub DUPLICATE_MACRO_ATTRIBUTES,
3874 "duplicated attribute"
3878 /// The `suspicious_auto_trait_impls` lint checks for potentially incorrect
3879 /// implementations of auto traits.
3884 /// struct Foo<T>(T);
3886 /// unsafe impl<T> Send for Foo<*const T> {}
3893 /// A type can implement auto traits, e.g. `Send`, `Sync` and `Unpin`,
3894 /// in two different ways: either by writing an explicit impl or if
3895 /// all fields of the type implement that auto trait.
3897 /// The compiler disables the automatic implementation if an explicit one
3898 /// exists for given type constructor. The exact rules governing this
3899 /// are currently unsound, quite subtle, and will be modified in the future.
3900 /// This change will cause the automatic implementation to be disabled in more
3901 /// cases, potentially breaking some code.
3902 pub SUSPICIOUS_AUTO_TRAIT_IMPLS,
3904 "the rules governing auto traits will change in the future",
3905 @future_incompatible = FutureIncompatibleInfo {
3906 reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
3907 reference: "issue #93367 <https://github.com/rust-lang/rust/issues/93367>",
3912 /// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3913 /// in an associated type.
3919 /// type Assoc<'a> where Self: 'a;
3922 /// impl Trait for () {
3923 /// type Assoc<'a> where Self: 'a = ();
3931 /// The preferred location for where clauses on associated types in impls
3932 /// is after the type. However, for most of generic associated types development,
3933 /// it was only accepted before the equals. To provide a transition period and
3934 /// further evaluate this change, both are currently accepted. At some point in
3935 /// the future, this may be disallowed at an edition boundary; but, that is
3936 /// undecided currently.
3937 pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3939 "deprecated where clause location"
3943 /// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3948 /// #![allow(test_unstable_lint)]
3955 /// In order to test the behavior of unstable lints, a permanently-unstable
3956 /// lint is required. This lint can be used to trigger warnings and errors
3957 /// from the compiler related to unstable lints.
3958 pub TEST_UNSTABLE_LINT,
3960 "this unstable lint is only for testing",
3961 @feature_gate = sym::test_unstable_lint;
3965 /// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3966 /// `C-unwind` or other FFI-unwind ABIs.
3970 /// ```rust,ignore (need FFI)
3971 /// #![feature(ffi_unwind_calls)]
3972 /// #![feature(c_unwind)]
3976 /// # pub fn "C-unwind" fn foo() {}
3979 /// extern "C-unwind" {
3984 /// unsafe { foo(); }
3985 /// let ptr: unsafe extern "C-unwind" fn() = foo;
3986 /// unsafe { ptr(); }
3994 /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3995 /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3996 /// that desire this ability it is therefore necessary to avoid such calls.
3997 pub FFI_UNWIND_CALLS,
3999 "call to foreign functions or function pointers with FFI-unwind ABI",
4000 @feature_gate = sym::c_unwind;
4004 /// The `named_arguments_used_positionally` lint detects cases where named arguments are only
4005 /// used positionally in format strings. This usage is valid but potentially very confusing.
4009 /// ```rust,compile_fail
4010 /// #![deny(named_arguments_used_positionally)]
4013 /// println!("{}", _x = 1); // Prints 1, will trigger lint
4015 /// println!("{}", _x); // Prints 5, no lint emitted
4016 /// println!("{_x}", _x = _x); // Prints 5, no lint emitted
4024 /// Rust formatting strings can refer to named arguments by their position, but this usage is
4025 /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4026 /// of named arguments is an assignment (which would produce the unit type).
4027 /// For backwards compatibility, this is not a hard error.
4028 pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4030 "named arguments in format used positionally"
4034 /// The `implied_bounds_entailment` lint detects cases where the arguments of an impl method
4035 /// have stronger implied bounds than those from the trait method it's implementing.
4039 /// ```rust,compile_fail
4040 /// #![deny(implied_bounds_entailment)]
4043 /// fn get<'s>(s: &'s str, _: &'static &'static ()) -> &'static str;
4046 /// impl Trait for () {
4047 /// fn get<'s>(s: &'s str, _: &'static &'s ()) -> &'static str {
4052 /// let val = <() as Trait>::get(&String::from("blah blah blah"), &&());
4053 /// println!("{}", val);
4060 /// Neither the trait method, which provides no implied bounds about `'s`, nor the impl,
4061 /// requires the main function to prove that 's: 'static, but the impl method is allowed
4062 /// to assume that `'s: 'static` within its own body.
4064 /// This can be used to implement an unsound API if used incorrectly.
4065 pub IMPLIED_BOUNDS_ENTAILMENT,
4067 "impl method assumes more implied bounds than its corresponding trait method",
4068 @future_incompatible = FutureIncompatibleInfo {
4069 reference: "issue #105572 <https://github.com/rust-lang/rust/issues/105572>",
4070 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
4075 /// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field
4076 /// (`[u8]`) is used in a `packed` struct that derives one or more built-in traits.
4083 /// struct FlexZeroSlice {
4093 /// This was previously accepted but is being phased out, because fields in packed structs are
4094 /// now required to implement `Copy` for `derive` to work. Byte slices are a temporary
4095 /// exception because certain crates depended on them.
4096 pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
4098 "`[u8]` slice used in a packed struct with `derive`",
4099 @future_incompatible = FutureIncompatibleInfo {
4100 reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
4101 reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
4103 report_in_external_macro