1//! Some lints that are built in to the compiler.
2//!
3//! These are the built-in lints that are emitted direct in the main
4//! compiler code, rather than using their own custom pass. Those
5//! lints are all available in `rustc_lint::builtin`.
6//!
7//! When removing a lint, make sure to also add a call to `register_removed` in
8//! compiler/rustc_lint/src/lib.rs.
910use crate::{declare_lint, declare_lint_pass, fcw};
1112#[doc = r" Does nothing as a lint pass, but registers some `Lint`s"]
#[doc = r" that are used by other parts of the compiler."]
pub struct HardwiredLints;
#[automatically_derived]
impl ::core::marker::Copy for HardwiredLints { }
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for HardwiredLints { }
#[automatically_derived]
impl ::core::clone::Clone for HardwiredLints {
#[inline]
fn clone(&self) -> HardwiredLints { *self }
}
impl crate::LintPass for HardwiredLints {
fn name(&self) -> &'static str { "HardwiredLints" }
fn get_lints(&self) -> crate::LintVec {
<[_]>::into_vec(::alloc::boxed::box_new([AARCH64_SOFTFLOAT_NEON,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS, AMBIGUOUS_PANIC_IMPORTS,
ARITHMETIC_OVERFLOW, ASM_SUB_REGISTER, BAD_ASM_STYLE,
BARE_TRAIT_OBJECTS, BINDINGS_WITH_VARIANT_NAME,
BREAK_WITH_LABEL_AND_LOOP, COHERENCE_LEAK_CHECK,
CONFLICTING_REPR_HINTS, CONST_EVALUATABLE_UNCHECKED,
CONST_ITEM_MUTATION, DEAD_CODE,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, DEPRECATED,
DEPRECATED_IN_FUTURE, DEPRECATED_SAFE_2024,
DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES, FFI_UNWIND_CALLS,
FORBIDDEN_LINT_GROUPS, FUNCTION_ITEM_REFERENCES,
FUZZY_PROVENANCE_CASTS, HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT, INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
INLINE_NO_SANITIZE, INVALID_DOC_ATTRIBUTES,
INVALID_MACRO_EXPORT_ARGUMENTS, INVALID_TYPE_PARAM_DEFAULT,
IRREFUTABLE_LET_PATTERNS, LARGE_ASSIGNMENTS,
LATE_BOUND_LIFETIME_ARGUMENTS, LEGACY_DERIVE_HELPERS,
LINKER_MESSAGES, LONG_RUNNING_CONST_EVAL,
LOSSY_PROVENANCE_CASTS,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
MACRO_USE_EXTERN_CRATE, MALFORMED_DIAGNOSTIC_ATTRIBUTES,
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, META_VARIABLE_MISUSE,
MISPLACED_DIAGNOSTIC_ATTRIBUTES, MISSING_ABI,
MISSING_UNSAFE_ON_EXTERN, MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
NON_CONTIGUOUS_RANGE_ENDPOINTS,
NON_EXHAUSTIVE_OMITTED_PATTERNS, OUT_OF_SCOPE_MACRO_CALLS,
OVERLAPPING_RANGE_ENDPOINTS, PATTERNS_IN_FNS_WITHOUT_BODY,
PRIVATE_BOUNDS, PRIVATE_INTERFACES,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
PUB_USE_OF_PRIVATE_EXTERN_CRATE, REDUNDANT_IMPORTS,
REDUNDANT_LIFETIMES, REFINING_IMPL_TRAIT_INTERNAL,
REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS,
REPR_C_ENUMS_LARGER_THAN_INT,
REPR_TRANSPARENT_NON_ZST_FIELDS,
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
RTSAN_NONBLOCKING_ASYNC,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
RUST_2021_PRELUDE_COLLISIONS,
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
RUST_2024_INCOMPATIBLE_PAT, RUST_2024_PRELUDE_COLLISIONS,
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
SHADOWING_SUPERTRAIT_ITEMS, SINGLE_USE_LIFETIMES,
SOFT_UNSTABLE, STABLE_FEATURES, TAIL_EXPR_DROP_ORDER,
TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TEXT_DIRECTION_CODEPOINT_IN_LITERAL, TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS, TYVAR_BEHIND_RAW_POINTER,
UNCONDITIONAL_PANIC, UNCONDITIONAL_RECURSION,
UNCOVERED_PARAM_IN_PROJECTION, UNEXPECTED_CFGS,
UNFULFILLED_LINT_EXPECTATIONS, UNINHABITED_STATIC,
UNKNOWN_CRATE_TYPES, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
UNKNOWN_LINTS, UNNAMEABLE_TEST_ITEMS, UNNAMEABLE_TYPES,
UNREACHABLE_CODE, UNREACHABLE_PATTERNS,
UNSAFE_ATTR_OUTSIDE_UNSAFE, UNSAFE_OP_IN_UNSAFE_FN,
UNSTABLE_NAME_COLLISIONS, UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_CALLING_CONVENTIONS, UNUSED_ASSIGNMENTS,
UNUSED_ASSOCIATED_TYPE_BOUNDS, UNUSED_ATTRIBUTES,
UNUSED_CRATE_DEPENDENCIES, UNUSED_EXTERN_CRATES,
UNUSED_FEATURES, UNUSED_IMPORTS, UNUSED_LABELS,
UNUSED_LIFETIMES, UNUSED_MACROS, UNUSED_MACRO_RULES,
UNUSED_MUT, UNUSED_QUALIFICATIONS, UNUSED_UNSAFE,
UNUSED_VARIABLES, UNUSED_VISIBILITIES, USELESS_DEPRECATED,
VARARGS_WITHOUT_PATTERN, WARNINGS]))
}
}
impl HardwiredLints {
#[allow(unused)]
pub fn lint_vec() -> crate::LintVec {
<[_]>::into_vec(::alloc::boxed::box_new([AARCH64_SOFTFLOAT_NEON,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS, AMBIGUOUS_PANIC_IMPORTS,
ARITHMETIC_OVERFLOW, ASM_SUB_REGISTER, BAD_ASM_STYLE,
BARE_TRAIT_OBJECTS, BINDINGS_WITH_VARIANT_NAME,
BREAK_WITH_LABEL_AND_LOOP, COHERENCE_LEAK_CHECK,
CONFLICTING_REPR_HINTS, CONST_EVALUATABLE_UNCHECKED,
CONST_ITEM_MUTATION, DEAD_CODE,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, DEPRECATED,
DEPRECATED_IN_FUTURE, DEPRECATED_SAFE_2024,
DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES, FFI_UNWIND_CALLS,
FORBIDDEN_LINT_GROUPS, FUNCTION_ITEM_REFERENCES,
FUZZY_PROVENANCE_CASTS, HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT, INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
INLINE_NO_SANITIZE, INVALID_DOC_ATTRIBUTES,
INVALID_MACRO_EXPORT_ARGUMENTS, INVALID_TYPE_PARAM_DEFAULT,
IRREFUTABLE_LET_PATTERNS, LARGE_ASSIGNMENTS,
LATE_BOUND_LIFETIME_ARGUMENTS, LEGACY_DERIVE_HELPERS,
LINKER_MESSAGES, LONG_RUNNING_CONST_EVAL,
LOSSY_PROVENANCE_CASTS,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
MACRO_USE_EXTERN_CRATE, MALFORMED_DIAGNOSTIC_ATTRIBUTES,
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, META_VARIABLE_MISUSE,
MISPLACED_DIAGNOSTIC_ATTRIBUTES, MISSING_ABI,
MISSING_UNSAFE_ON_EXTERN, MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
NON_CONTIGUOUS_RANGE_ENDPOINTS,
NON_EXHAUSTIVE_OMITTED_PATTERNS, OUT_OF_SCOPE_MACRO_CALLS,
OVERLAPPING_RANGE_ENDPOINTS, PATTERNS_IN_FNS_WITHOUT_BODY,
PRIVATE_BOUNDS, PRIVATE_INTERFACES,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
PUB_USE_OF_PRIVATE_EXTERN_CRATE, REDUNDANT_IMPORTS,
REDUNDANT_LIFETIMES, REFINING_IMPL_TRAIT_INTERNAL,
REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS,
REPR_C_ENUMS_LARGER_THAN_INT,
REPR_TRANSPARENT_NON_ZST_FIELDS,
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
RTSAN_NONBLOCKING_ASYNC,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
RUST_2021_PRELUDE_COLLISIONS,
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
RUST_2024_INCOMPATIBLE_PAT, RUST_2024_PRELUDE_COLLISIONS,
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
SHADOWING_SUPERTRAIT_ITEMS, SINGLE_USE_LIFETIMES,
SOFT_UNSTABLE, STABLE_FEATURES, TAIL_EXPR_DROP_ORDER,
TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TEXT_DIRECTION_CODEPOINT_IN_LITERAL, TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS, TYVAR_BEHIND_RAW_POINTER,
UNCONDITIONAL_PANIC, UNCONDITIONAL_RECURSION,
UNCOVERED_PARAM_IN_PROJECTION, UNEXPECTED_CFGS,
UNFULFILLED_LINT_EXPECTATIONS, UNINHABITED_STATIC,
UNKNOWN_CRATE_TYPES, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
UNKNOWN_LINTS, UNNAMEABLE_TEST_ITEMS, UNNAMEABLE_TYPES,
UNREACHABLE_CODE, UNREACHABLE_PATTERNS,
UNSAFE_ATTR_OUTSIDE_UNSAFE, UNSAFE_OP_IN_UNSAFE_FN,
UNSTABLE_NAME_COLLISIONS, UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_CALLING_CONVENTIONS, UNUSED_ASSIGNMENTS,
UNUSED_ASSOCIATED_TYPE_BOUNDS, UNUSED_ATTRIBUTES,
UNUSED_CRATE_DEPENDENCIES, UNUSED_EXTERN_CRATES,
UNUSED_FEATURES, UNUSED_IMPORTS, UNUSED_LABELS,
UNUSED_LIFETIMES, UNUSED_MACROS, UNUSED_MACRO_RULES,
UNUSED_MUT, UNUSED_QUALIFICATIONS, UNUSED_UNSAFE,
UNUSED_VARIABLES, UNUSED_VISIBILITIES, USELESS_DEPRECATED,
VARARGS_WITHOUT_PATTERN, WARNINGS]))
}
}declare_lint_pass! {
13/// Does nothing as a lint pass, but registers some `Lint`s
14 /// that are used by other parts of the compiler.
15HardwiredLints => [
16// tidy-alphabetical-start
17AARCH64_SOFTFLOAT_NEON,
18 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
19 AMBIGUOUS_ASSOCIATED_ITEMS,
20 AMBIGUOUS_GLOB_IMPORTS,
21 AMBIGUOUS_GLOB_REEXPORTS,
22 AMBIGUOUS_PANIC_IMPORTS,
23 ARITHMETIC_OVERFLOW,
24 ASM_SUB_REGISTER,
25 BAD_ASM_STYLE,
26 BARE_TRAIT_OBJECTS,
27 BINDINGS_WITH_VARIANT_NAME,
28 BREAK_WITH_LABEL_AND_LOOP,
29 COHERENCE_LEAK_CHECK,
30 CONFLICTING_REPR_HINTS,
31 CONST_EVALUATABLE_UNCHECKED,
32 CONST_ITEM_MUTATION,
33 DEAD_CODE,
34 DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
35 DEPRECATED,
36 DEPRECATED_IN_FUTURE,
37 DEPRECATED_SAFE_2024,
38 DEPRECATED_WHERE_CLAUSE_LOCATION,
39 DUPLICATE_MACRO_ATTRIBUTES,
40 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
41 ELIDED_LIFETIMES_IN_PATHS,
42 EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
43 EXPORTED_PRIVATE_DEPENDENCIES,
44 FFI_UNWIND_CALLS,
45 FORBIDDEN_LINT_GROUPS,
46 FUNCTION_ITEM_REFERENCES,
47 FUZZY_PROVENANCE_CASTS,
48 HIDDEN_GLOB_REEXPORTS,
49 ILL_FORMED_ATTRIBUTE_INPUT,
50 INCOMPLETE_INCLUDE,
51 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
52 INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
53 INLINE_NO_SANITIZE,
54 INVALID_DOC_ATTRIBUTES,
55 INVALID_MACRO_EXPORT_ARGUMENTS,
56 INVALID_TYPE_PARAM_DEFAULT,
57 IRREFUTABLE_LET_PATTERNS,
58 LARGE_ASSIGNMENTS,
59 LATE_BOUND_LIFETIME_ARGUMENTS,
60 LEGACY_DERIVE_HELPERS,
61 LINKER_MESSAGES,
62 LONG_RUNNING_CONST_EVAL,
63 LOSSY_PROVENANCE_CASTS,
64 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
65 MACRO_USE_EXTERN_CRATE,
66 MALFORMED_DIAGNOSTIC_ATTRIBUTES,
67 MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
68 META_VARIABLE_MISUSE,
69 MISPLACED_DIAGNOSTIC_ATTRIBUTES,
70 MISSING_ABI,
71 MISSING_UNSAFE_ON_EXTERN,
72 MUST_NOT_SUSPEND,
73 NAMED_ARGUMENTS_USED_POSITIONALLY,
74 NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
75 NON_CONTIGUOUS_RANGE_ENDPOINTS,
76 NON_EXHAUSTIVE_OMITTED_PATTERNS,
77 OUT_OF_SCOPE_MACRO_CALLS,
78 OVERLAPPING_RANGE_ENDPOINTS,
79 PATTERNS_IN_FNS_WITHOUT_BODY,
80 PRIVATE_BOUNDS,
81 PRIVATE_INTERFACES,
82 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
83 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
84 REDUNDANT_IMPORTS,
85 REDUNDANT_LIFETIMES,
86 REFINING_IMPL_TRAIT_INTERNAL,
87 REFINING_IMPL_TRAIT_REACHABLE,
88 RENAMED_AND_REMOVED_LINTS,
89 REPR_C_ENUMS_LARGER_THAN_INT,
90 REPR_TRANSPARENT_NON_ZST_FIELDS,
91 RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
92 RTSAN_NONBLOCKING_ASYNC,
93 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
94 RUST_2021_INCOMPATIBLE_OR_PATTERNS,
95 RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
96 RUST_2021_PRELUDE_COLLISIONS,
97 RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
98 RUST_2024_INCOMPATIBLE_PAT,
99 RUST_2024_PRELUDE_COLLISIONS,
100 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
101 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
102 SHADOWING_SUPERTRAIT_ITEMS,
103 SINGLE_USE_LIFETIMES,
104 SOFT_UNSTABLE,
105 STABLE_FEATURES,
106 TAIL_EXPR_DROP_ORDER,
107 TEST_UNSTABLE_LINT,
108 TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
109 TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
110 TRIVIAL_CASTS,
111 TRIVIAL_NUMERIC_CASTS,
112 TYVAR_BEHIND_RAW_POINTER,
113 UNCONDITIONAL_PANIC,
114 UNCONDITIONAL_RECURSION,
115 UNCOVERED_PARAM_IN_PROJECTION,
116 UNEXPECTED_CFGS,
117 UNFULFILLED_LINT_EXPECTATIONS,
118 UNINHABITED_STATIC,
119 UNKNOWN_CRATE_TYPES,
120 UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
121 UNKNOWN_LINTS,
122 UNNAMEABLE_TEST_ITEMS,
123 UNNAMEABLE_TYPES,
124 UNREACHABLE_CODE,
125 UNREACHABLE_PATTERNS,
126 UNSAFE_ATTR_OUTSIDE_UNSAFE,
127 UNSAFE_OP_IN_UNSAFE_FN,
128 UNSTABLE_NAME_COLLISIONS,
129 UNSTABLE_SYNTAX_PRE_EXPANSION,
130 UNSUPPORTED_CALLING_CONVENTIONS,
131 UNUSED_ASSIGNMENTS,
132 UNUSED_ASSOCIATED_TYPE_BOUNDS,
133 UNUSED_ATTRIBUTES,
134 UNUSED_CRATE_DEPENDENCIES,
135 UNUSED_EXTERN_CRATES,
136 UNUSED_FEATURES,
137 UNUSED_IMPORTS,
138 UNUSED_LABELS,
139 UNUSED_LIFETIMES,
140 UNUSED_MACROS,
141 UNUSED_MACRO_RULES,
142 UNUSED_MUT,
143 UNUSED_QUALIFICATIONS,
144 UNUSED_UNSAFE,
145 UNUSED_VARIABLES,
146 UNUSED_VISIBILITIES,
147 USELESS_DEPRECATED,
148 VARARGS_WITHOUT_PATTERN,
149 WARNINGS,
150// tidy-alphabetical-end
151]
152}153154#[doc = r" The `forbidden_lint_groups` lint detects violations of"]
#[doc = r" `forbid` applied to a lint group. Due to a bug in the compiler,"]
#[doc =
r" these used to be overlooked entirely. They now generate a warning."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![forbid(warnings)]"]
#[doc = r" #![warn(bad_style)]"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Recommended fix"]
#[doc = r""]
#[doc = r" If your crate is using `#![forbid(warnings)]`,"]
#[doc = r" we recommend that you change to `#![deny(warnings)]`."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Due to a compiler bug, applying `forbid` to lint groups"]
#[doc = r" previously had no effect. The bug is now fixed but instead of"]
#[doc = r" enforcing `forbid` we issue this future-compatibility warning"]
#[doc = r" to avoid breaking existing crates."]
pub static FORBIDDEN_LINT_GROUPS: &crate::Lint =
&crate::Lint {
name: "FORBIDDEN_LINT_GROUPS",
default_level: crate::Warn,
desc: "applying forbid to lint-groups",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 81670,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
155/// The `forbidden_lint_groups` lint detects violations of
156 /// `forbid` applied to a lint group. Due to a bug in the compiler,
157 /// these used to be overlooked entirely. They now generate a warning.
158 ///
159 /// ### Example
160 ///
161 /// ```rust
162 /// #![forbid(warnings)]
163 /// #![warn(bad_style)]
164 ///
165 /// fn main() {}
166 /// ```
167 ///
168 /// {{produces}}
169 ///
170 /// ### Recommended fix
171 ///
172 /// If your crate is using `#![forbid(warnings)]`,
173 /// we recommend that you change to `#![deny(warnings)]`.
174 ///
175 /// ### Explanation
176 ///
177 /// Due to a compiler bug, applying `forbid` to lint groups
178 /// previously had no effect. The bug is now fixed but instead of
179 /// enforcing `forbid` we issue this future-compatibility warning
180 /// to avoid breaking existing crates.
181pub FORBIDDEN_LINT_GROUPS,
182 Warn,
183"applying forbid to lint-groups",
184 @future_incompatible = FutureIncompatibleInfo {
185 reason: fcw!(FutureReleaseError #81670),
186 report_in_deps: true,
187 };
188}189190#[doc =
r" The `ill_formed_attribute_input` lint detects ill-formed attribute"]
#[doc = r" inputs that were previously accepted and used in practice."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r#" #[inline = "this is not valid"]"#]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Previously, inputs for many built-in attributes weren't validated and"]
#[doc = r" nonsensical attribute inputs were accepted. After validation was"]
#[doc =
r" added, it was determined that some existing projects made use of these"]
#[doc =
r" invalid forms. This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #57571] for more details."]
#[doc = r""]
#[doc =
r" Check the [attribute reference] for details on the valid inputs for"]
#[doc = r" attributes."]
#[doc = r""]
#[doc = r" [issue #57571]: https://github.com/rust-lang/rust/issues/57571"]
#[doc =
r" [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static ILL_FORMED_ATTRIBUTE_INPUT: &crate::Lint =
&crate::Lint {
name: "ILL_FORMED_ATTRIBUTE_INPUT",
default_level: crate::Deny,
desc: "ill-formed attribute inputs that were previously accepted and used in practice",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57571,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
191/// The `ill_formed_attribute_input` lint detects ill-formed attribute
192 /// inputs that were previously accepted and used in practice.
193 ///
194 /// ### Example
195 ///
196 /// ```rust,compile_fail
197 /// #[inline = "this is not valid"]
198 /// fn foo() {}
199 /// ```
200 ///
201 /// {{produces}}
202 ///
203 /// ### Explanation
204 ///
205 /// Previously, inputs for many built-in attributes weren't validated and
206 /// nonsensical attribute inputs were accepted. After validation was
207 /// added, it was determined that some existing projects made use of these
208 /// invalid forms. This is a [future-incompatible] lint to transition this
209 /// to a hard error in the future. See [issue #57571] for more details.
210 ///
211 /// Check the [attribute reference] for details on the valid inputs for
212 /// attributes.
213 ///
214 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
215 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
216 /// [future-incompatible]: ../index.md#future-incompatible-lints
217pub ILL_FORMED_ATTRIBUTE_INPUT,
218 Deny,
219"ill-formed attribute inputs that were previously accepted and used in practice",
220 @future_incompatible = FutureIncompatibleInfo {
221 reason: fcw!(FutureReleaseError #57571),
222 report_in_deps: true,
223 };
224 crate_level_only
225}226227#[doc =
r" The `conflicting_repr_hints` lint detects [`repr` attributes] with"]
#[doc = r" conflicting hints."]
#[doc = r""]
#[doc =
r" [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[repr(u32, u64)]"]
#[doc = r" enum Foo {"]
#[doc = r" Variant1,"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The compiler incorrectly accepted these conflicting representations in"]
#[doc =
r" the past. This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future. See [issue #68585] for more details."]
#[doc = r""]
#[doc = r" To correct the issue, remove one of the conflicting hints."]
#[doc = r""]
#[doc = r" [issue #68585]: https://github.com/rust-lang/rust/issues/68585"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static CONFLICTING_REPR_HINTS: &crate::Lint =
&crate::Lint {
name: "CONFLICTING_REPR_HINTS",
default_level: crate::Deny,
desc: "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 68585,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
228/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
229 /// conflicting hints.
230 ///
231 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
232 ///
233 /// ### Example
234 ///
235 /// ```rust,compile_fail
236 /// #[repr(u32, u64)]
237 /// enum Foo {
238 /// Variant1,
239 /// }
240 /// ```
241 ///
242 /// {{produces}}
243 ///
244 /// ### Explanation
245 ///
246 /// The compiler incorrectly accepted these conflicting representations in
247 /// the past. This is a [future-incompatible] lint to transition this to a
248 /// hard error in the future. See [issue #68585] for more details.
249 ///
250 /// To correct the issue, remove one of the conflicting hints.
251 ///
252 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
253 /// [future-incompatible]: ../index.md#future-incompatible-lints
254pub CONFLICTING_REPR_HINTS,
255 Deny,
256"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
257 @future_incompatible = FutureIncompatibleInfo {
258 reason: fcw!(FutureReleaseError #68585),
259 report_in_deps: true,
260 };
261}262263#[doc =
r" The `meta_variable_misuse` lint detects possible meta-variable misuse"]
#[doc = r" in macro definitions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(meta_variable_misuse)]"]
#[doc = r""]
#[doc = r" macro_rules! foo {"]
#[doc = r" () => {};"]
#[doc =
r" ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" foo!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" There are quite a few different ways a [`macro_rules`] macro can be"]
#[doc =
r" improperly defined. Many of these errors were previously only detected"]
#[doc =
r" when the macro was expanded or not at all. This lint is an attempt to"]
#[doc = r" catch some of these problems when the macro is *defined*."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it may have false positives"#]
#[doc = r" and other issues. See [issue #61053] for more details."]
#[doc = r""]
#[doc =
r" [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html"]
#[doc = r" [issue #61053]: https://github.com/rust-lang/rust/issues/61053"]
pub static META_VARIABLE_MISUSE: &crate::Lint =
&crate::Lint {
name: "META_VARIABLE_MISUSE",
default_level: crate::Allow,
desc: "possible meta-variable misuse at macro definition",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
264/// The `meta_variable_misuse` lint detects possible meta-variable misuse
265 /// in macro definitions.
266 ///
267 /// ### Example
268 ///
269 /// ```rust,compile_fail
270 /// #![deny(meta_variable_misuse)]
271 ///
272 /// macro_rules! foo {
273 /// () => {};
274 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
275 /// }
276 ///
277 /// fn main() {
278 /// foo!();
279 /// }
280 /// ```
281 ///
282 /// {{produces}}
283 ///
284 /// ### Explanation
285 ///
286 /// There are quite a few different ways a [`macro_rules`] macro can be
287 /// improperly defined. Many of these errors were previously only detected
288 /// when the macro was expanded or not at all. This lint is an attempt to
289 /// catch some of these problems when the macro is *defined*.
290 ///
291 /// This lint is "allow" by default because it may have false positives
292 /// and other issues. See [issue #61053] for more details.
293 ///
294 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
295 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
296pub META_VARIABLE_MISUSE,
297 Allow,
298"possible meta-variable misuse at macro definition"
299}300301#[doc = r" The `incomplete_include` lint detects the use of the [`include!`]"]
#[doc = r" macro with a file that contains more than one expression."]
#[doc = r""]
#[doc = r" [`include!`]: https://doc.rust-lang.org/std/macro.include.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs separate file)"]
#[doc = r" fn main() {"]
#[doc = r#" include!("foo.txt");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" where the file `foo.txt` contains:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r#" println!("hi!");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: include macro expected single expression in source"]
#[doc = r" --> foo.txt:1:14"]
#[doc = r" |"]
#[doc = r#" 1 | println!("1");"#]
#[doc = r" | ^"]
#[doc = r" |"]
#[doc = r" = note: `#[deny(incomplete_include)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The [`include!`] macro is currently only intended to be used to"]
#[doc =
r" include a single [expression] or multiple [items]. Historically it"]
#[doc =
r" would ignore any contents after the first expression, but that can be"]
#[doc =
r" confusing. In the example above, the `println!` expression ends just"]
#[doc =
r#" before the semicolon, making the semicolon "extra" information that is"#]
#[doc = r" ignored. Perhaps even more surprising, if the included file had"]
#[doc = r" multiple print statements, the subsequent ones would be ignored!"]
#[doc = r""]
#[doc =
r" One workaround is to place the contents in braces to create a [block"]
#[doc = r" expression]. Also consider alternatives, like using functions to"]
#[doc = r" encapsulate the expressions, or use [proc-macros]."]
#[doc = r""]
#[doc =
r" This is a lint instead of a hard error because existing projects were"]
#[doc =
r" found to hit this error. To be cautious, it is a lint for now. The"]
#[doc = r" future semantics of the `include!` macro are also uncertain, see"]
#[doc = r" [issue #35560]."]
#[doc = r""]
#[doc = r" [items]: https://doc.rust-lang.org/reference/items.html"]
#[doc =
r" [expression]: https://doc.rust-lang.org/reference/expressions.html"]
#[doc =
r" [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html"]
#[doc =
r" [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html"]
#[doc = r" [issue #35560]: https://github.com/rust-lang/rust/issues/35560"]
pub static INCOMPLETE_INCLUDE: &crate::Lint =
&crate::Lint {
name: "INCOMPLETE_INCLUDE",
default_level: crate::Deny,
desc: "trailing content in included file",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
302/// The `incomplete_include` lint detects the use of the [`include!`]
303 /// macro with a file that contains more than one expression.
304 ///
305 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
306 ///
307 /// ### Example
308 ///
309 /// ```rust,ignore (needs separate file)
310 /// fn main() {
311 /// include!("foo.txt");
312 /// }
313 /// ```
314 ///
315 /// where the file `foo.txt` contains:
316 ///
317 /// ```text
318 /// println!("hi!");
319 /// ```
320 ///
321 /// produces:
322 ///
323 /// ```text
324 /// error: include macro expected single expression in source
325 /// --> foo.txt:1:14
326 /// |
327 /// 1 | println!("1");
328 /// | ^
329 /// |
330 /// = note: `#[deny(incomplete_include)]` on by default
331 /// ```
332 ///
333 /// ### Explanation
334 ///
335 /// The [`include!`] macro is currently only intended to be used to
336 /// include a single [expression] or multiple [items]. Historically it
337 /// would ignore any contents after the first expression, but that can be
338 /// confusing. In the example above, the `println!` expression ends just
339 /// before the semicolon, making the semicolon "extra" information that is
340 /// ignored. Perhaps even more surprising, if the included file had
341 /// multiple print statements, the subsequent ones would be ignored!
342 ///
343 /// One workaround is to place the contents in braces to create a [block
344 /// expression]. Also consider alternatives, like using functions to
345 /// encapsulate the expressions, or use [proc-macros].
346 ///
347 /// This is a lint instead of a hard error because existing projects were
348 /// found to hit this error. To be cautious, it is a lint for now. The
349 /// future semantics of the `include!` macro are also uncertain, see
350 /// [issue #35560].
351 ///
352 /// [items]: https://doc.rust-lang.org/reference/items.html
353 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
354 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
355 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
356 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
357pub INCOMPLETE_INCLUDE,
358 Deny,
359"trailing content in included file"
360}361362#[doc =
r" The `arithmetic_overflow` lint detects that an arithmetic operation"]
#[doc = r" will [overflow]."]
#[doc = r""]
#[doc =
r" [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" 1_i32 << 32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is very likely a mistake to perform an arithmetic operation that"]
#[doc =
r" overflows its value. If the compiler is able to detect these kinds of"]
#[doc = r" overflows at compile-time, it will trigger this lint. Consider"]
#[doc =
r" adjusting the expression to avoid overflow, or use a data type that"]
#[doc = r" will not overflow."]
pub static ARITHMETIC_OVERFLOW: &crate::Lint =
&crate::Lint {
name: "ARITHMETIC_OVERFLOW",
default_level: crate::Deny,
desc: "arithmetic operation overflows",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
363/// The `arithmetic_overflow` lint detects that an arithmetic operation
364 /// will [overflow].
365 ///
366 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
367 ///
368 /// ### Example
369 ///
370 /// ```rust,compile_fail
371 /// 1_i32 << 32;
372 /// ```
373 ///
374 /// {{produces}}
375 ///
376 /// ### Explanation
377 ///
378 /// It is very likely a mistake to perform an arithmetic operation that
379 /// overflows its value. If the compiler is able to detect these kinds of
380 /// overflows at compile-time, it will trigger this lint. Consider
381 /// adjusting the expression to avoid overflow, or use a data type that
382 /// will not overflow.
383pub ARITHMETIC_OVERFLOW,
384 Deny,
385"arithmetic operation overflows",
386 @eval_always = true
387}388389#[doc =
r" The `unconditional_panic` lint detects an operation that will cause a"]
#[doc = r" panic at runtime."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" let x = 1 / 0;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint detects code that is very likely incorrect because it will"]
#[doc = r" always panic, such as division by zero and out-of-bounds array"]
#[doc =
r" accesses. Consider adjusting your code if this is a bug, or using the"]
#[doc =
r" `panic!` or `unreachable!` macro instead in case the panic is intended."]
pub static UNCONDITIONAL_PANIC: &crate::Lint =
&crate::Lint {
name: "UNCONDITIONAL_PANIC",
default_level: crate::Deny,
desc: "operation will cause a panic at runtime",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
390/// The `unconditional_panic` lint detects an operation that will cause a
391 /// panic at runtime.
392 ///
393 /// ### Example
394 ///
395 /// ```rust,compile_fail
396 /// # #![allow(unused)]
397 /// let x = 1 / 0;
398 /// ```
399 ///
400 /// {{produces}}
401 ///
402 /// ### Explanation
403 ///
404 /// This lint detects code that is very likely incorrect because it will
405 /// always panic, such as division by zero and out-of-bounds array
406 /// accesses. Consider adjusting your code if this is a bug, or using the
407 /// `panic!` or `unreachable!` macro instead in case the panic is intended.
408pub UNCONDITIONAL_PANIC,
409 Deny,
410"operation will cause a panic at runtime",
411 @eval_always = true
412}413414#[doc = r" The `unused_imports` lint detects imports that are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" use std::collections::HashMap;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused imports may signal a mistake or unfinished code, and clutter"]
#[doc =
r" the code, and should be removed. If you intended to re-export the item"]
#[doc =
r" to make it available outside of the module, add a visibility modifier"]
#[doc = r" like `pub`."]
pub static UNUSED_IMPORTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_IMPORTS",
default_level: crate::Warn,
desc: "imports that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
415/// The `unused_imports` lint detects imports that are never used.
416 ///
417 /// ### Example
418 ///
419 /// ```rust
420 /// use std::collections::HashMap;
421 /// ```
422 ///
423 /// {{produces}}
424 ///
425 /// ### Explanation
426 ///
427 /// Unused imports may signal a mistake or unfinished code, and clutter
428 /// the code, and should be removed. If you intended to re-export the item
429 /// to make it available outside of the module, add a visibility modifier
430 /// like `pub`.
431pub UNUSED_IMPORTS,
432 Warn,
433"imports that are never used"
434}435436#[doc =
r" The `redundant_imports` lint detects imports that are redundant due to being"]
#[doc =
r" imported already; either through a previous import, or being present in"]
#[doc = r" the prelude."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(redundant_imports)]"]
#[doc = r" use std::option::Option::None;"]
#[doc = r" fn foo() -> Option<i32> { None }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Redundant imports are unnecessary and can be removed to simplify code."]
#[doc =
r" If you intended to re-export the item to make it available outside of the"]
#[doc = r" module, add a visibility modifier like `pub`."]
pub static REDUNDANT_IMPORTS: &crate::Lint =
&crate::Lint {
name: "REDUNDANT_IMPORTS",
default_level: crate::Allow,
desc: "imports that are redundant due to being imported already",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
437/// The `redundant_imports` lint detects imports that are redundant due to being
438 /// imported already; either through a previous import, or being present in
439 /// the prelude.
440 ///
441 /// ### Example
442 ///
443 /// ```rust,compile_fail
444 /// #![deny(redundant_imports)]
445 /// use std::option::Option::None;
446 /// fn foo() -> Option<i32> { None }
447 /// ```
448 ///
449 /// {{produces}}
450 ///
451 /// ### Explanation
452 ///
453 /// Redundant imports are unnecessary and can be removed to simplify code.
454 /// If you intended to re-export the item to make it available outside of the
455 /// module, add a visibility modifier like `pub`.
456pub REDUNDANT_IMPORTS,
457 Allow,
458"imports that are redundant due to being imported already"
459}460461#[doc =
r" The `must_not_suspend` lint guards against values that shouldn't be held across suspend points"]
#[doc = r" (`.await`)"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(must_not_suspend)]"]
#[doc = r" #![warn(must_not_suspend)]"]
#[doc = r""]
#[doc = r" #[must_not_suspend]"]
#[doc = r" struct SyncThing {}"]
#[doc = r""]
#[doc = r" async fn yield_now() {}"]
#[doc = r""]
#[doc = r" pub async fn uhoh() {"]
#[doc = r" let guard = SyncThing {};"]
#[doc = r" yield_now().await;"]
#[doc = r" let _guard = guard;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`"]
#[doc =
r#" attribute being held across suspend points. A "suspend" point is usually a `.await` in an async"#]
#[doc = r" function."]
#[doc = r""]
#[doc =
r" This attribute can be used to mark values that are semantically incorrect across suspends"]
#[doc =
r" (like certain types of timers), values that have async alternatives, and values that"]
#[doc =
r" regularly cause problems with the `Send`-ness of async fn's returned futures (like"]
#[doc = r" `MutexGuard`'s)"]
#[doc = r""]
pub static MUST_NOT_SUSPEND: &crate::Lint =
&crate::Lint {
name: "MUST_NOT_SUSPEND",
default_level: crate::Allow,
desc: "use of a `#[must_not_suspend]` value across a yield point",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::must_not_suspend),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
462/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
463 /// (`.await`)
464 ///
465 /// ### Example
466 ///
467 /// ```rust
468 /// #![feature(must_not_suspend)]
469 /// #![warn(must_not_suspend)]
470 ///
471 /// #[must_not_suspend]
472 /// struct SyncThing {}
473 ///
474 /// async fn yield_now() {}
475 ///
476 /// pub async fn uhoh() {
477 /// let guard = SyncThing {};
478 /// yield_now().await;
479 /// let _guard = guard;
480 /// }
481 /// ```
482 ///
483 /// {{produces}}
484 ///
485 /// ### Explanation
486 ///
487 /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
488 /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
489 /// function.
490 ///
491 /// This attribute can be used to mark values that are semantically incorrect across suspends
492 /// (like certain types of timers), values that have async alternatives, and values that
493 /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
494 /// `MutexGuard`'s)
495 ///
496pub MUST_NOT_SUSPEND,
497 Allow,
498"use of a `#[must_not_suspend]` value across a yield point",
499 @feature_gate = must_not_suspend;
500}501502#[doc =
r" The `unused_extern_crates` lint guards against `extern crate` items"]
#[doc = r" that are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unused_extern_crates)]"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" extern crate proc_macro;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" `extern crate` items that are unused have no effect and should be"]
#[doc =
r" removed. Note that there are some cases where specifying an `extern"]
#[doc =
r" crate` is desired for the side effect of ensuring the given crate is"]
#[doc =
r" linked, even though it is not otherwise directly referenced. The lint"]
#[doc = r" can be silenced by aliasing the crate to an underscore, such as"]
#[doc =
r" `extern crate foo as _`. Also note that it is no longer idiomatic to"]
#[doc =
r" use `extern crate` in the [2018 edition], as extern crates are now"]
#[doc = r" automatically added in scope."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it can be noisy, and produce"#]
#[doc =
r" false-positives. If a dependency is being removed from a project, it"]
#[doc = r" is recommended to remove it from the build configuration (such as"]
#[doc = r" `Cargo.toml`) to ensure stale build entries aren't left behind."]
#[doc = r""]
#[doc =
r" [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate"]
pub static UNUSED_EXTERN_CRATES: &crate::Lint =
&crate::Lint {
name: "UNUSED_EXTERN_CRATES",
default_level: crate::Allow,
desc: "extern crates that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
503/// The `unused_extern_crates` lint guards against `extern crate` items
504 /// that are never used.
505 ///
506 /// ### Example
507 ///
508 /// ```rust,compile_fail
509 /// #![deny(unused_extern_crates)]
510 /// #![deny(warnings)]
511 /// extern crate proc_macro;
512 /// ```
513 ///
514 /// {{produces}}
515 ///
516 /// ### Explanation
517 ///
518 /// `extern crate` items that are unused have no effect and should be
519 /// removed. Note that there are some cases where specifying an `extern
520 /// crate` is desired for the side effect of ensuring the given crate is
521 /// linked, even though it is not otherwise directly referenced. The lint
522 /// can be silenced by aliasing the crate to an underscore, such as
523 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
524 /// use `extern crate` in the [2018 edition], as extern crates are now
525 /// automatically added in scope.
526 ///
527 /// This lint is "allow" by default because it can be noisy, and produce
528 /// false-positives. If a dependency is being removed from a project, it
529 /// is recommended to remove it from the build configuration (such as
530 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
531 ///
532 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
533pub UNUSED_EXTERN_CRATES,
534 Allow,
535"extern crates that are never used"
536}537538#[doc =
r" The `unused_crate_dependencies` lint detects crate dependencies that"]
#[doc = r" are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #![deny(unused_crate_dependencies)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: extern crate `regex` is unused in crate `lint_example`"]
#[doc = r" |"]
#[doc =
r" = help: remove the dependency or add `use regex as _;` to the crate root"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> src/lib.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![deny(unused_crate_dependencies)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" After removing the code that uses a dependency, this usually also"]
#[doc = r" requires removing the dependency from the build configuration."]
#[doc =
r" However, sometimes that step can be missed, which leads to time wasted"]
#[doc = r" building dependencies that are no longer used. This lint can be"]
#[doc =
r" enabled to detect dependencies that are never used (more specifically,"]
#[doc =
r" any dependency passed with the `--extern` command-line flag that is"]
#[doc =
r" never referenced via [`use`], [`extern crate`], or in any [path])."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it can provide false positives"#]
#[doc =
r" depending on how the build system is configured. For example, when"]
#[doc = r#" using Cargo, a "package" consists of multiple crates (such as a"#]
#[doc = r" library and a binary), but the dependencies are defined for the"]
#[doc =
r" package as a whole. If there is a dependency that is only used in the"]
#[doc =
r" binary, but not the library, then the lint will be incorrectly issued"]
#[doc = r" in the library."]
#[doc = r""]
#[doc = r" [path]: https://doc.rust-lang.org/reference/paths.html"]
#[doc =
r" [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html"]
#[doc =
r" [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html"]
pub static UNUSED_CRATE_DEPENDENCIES: &crate::Lint =
&crate::Lint {
name: "UNUSED_CRATE_DEPENDENCIES",
default_level: crate::Allow,
desc: "crate dependencies that are never used",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
539/// The `unused_crate_dependencies` lint detects crate dependencies that
540 /// are never used.
541 ///
542 /// ### Example
543 ///
544 /// ```rust,ignore (needs extern crate)
545 /// #![deny(unused_crate_dependencies)]
546 /// ```
547 ///
548 /// This will produce:
549 ///
550 /// ```text
551 /// error: extern crate `regex` is unused in crate `lint_example`
552 /// |
553 /// = help: remove the dependency or add `use regex as _;` to the crate root
554 /// note: the lint level is defined here
555 /// --> src/lib.rs:1:9
556 /// |
557 /// 1 | #![deny(unused_crate_dependencies)]
558 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
559 /// ```
560 ///
561 /// ### Explanation
562 ///
563 /// After removing the code that uses a dependency, this usually also
564 /// requires removing the dependency from the build configuration.
565 /// However, sometimes that step can be missed, which leads to time wasted
566 /// building dependencies that are no longer used. This lint can be
567 /// enabled to detect dependencies that are never used (more specifically,
568 /// any dependency passed with the `--extern` command-line flag that is
569 /// never referenced via [`use`], [`extern crate`], or in any [path]).
570 ///
571 /// This lint is "allow" by default because it can provide false positives
572 /// depending on how the build system is configured. For example, when
573 /// using Cargo, a "package" consists of multiple crates (such as a
574 /// library and a binary), but the dependencies are defined for the
575 /// package as a whole. If there is a dependency that is only used in the
576 /// binary, but not the library, then the lint will be incorrectly issued
577 /// in the library.
578 ///
579 /// [path]: https://doc.rust-lang.org/reference/paths.html
580 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
581 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
582pub UNUSED_CRATE_DEPENDENCIES,
583 Allow,
584"crate dependencies that are never used",
585 crate_level_only
586}587588#[doc = r" The `unused_qualifications` lint detects unnecessarily qualified"]
#[doc = r" names."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unused_qualifications)]"]
#[doc = r" mod foo {"]
#[doc = r" pub fn bar() {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" use foo::bar;"]
#[doc = r" foo::bar();"]
#[doc = r" bar();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" If an item from another module is already brought into scope, then"]
#[doc = r" there is no need to qualify it in this case. You can call `bar()`"]
#[doc = r" directly, without the `foo::`."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it is somewhat pedantic, and"#]
#[doc =
r" doesn't indicate an actual problem, but rather a stylistic choice, and"]
#[doc = r" can be noisy when refactoring or moving around code."]
pub static UNUSED_QUALIFICATIONS: &crate::Lint =
&crate::Lint {
name: "UNUSED_QUALIFICATIONS",
default_level: crate::Allow,
desc: "detects unnecessarily qualified names",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
589/// The `unused_qualifications` lint detects unnecessarily qualified
590 /// names.
591 ///
592 /// ### Example
593 ///
594 /// ```rust,compile_fail
595 /// #![deny(unused_qualifications)]
596 /// mod foo {
597 /// pub fn bar() {}
598 /// }
599 ///
600 /// fn main() {
601 /// use foo::bar;
602 /// foo::bar();
603 /// bar();
604 /// }
605 /// ```
606 ///
607 /// {{produces}}
608 ///
609 /// ### Explanation
610 ///
611 /// If an item from another module is already brought into scope, then
612 /// there is no need to qualify it in this case. You can call `bar()`
613 /// directly, without the `foo::`.
614 ///
615 /// This lint is "allow" by default because it is somewhat pedantic, and
616 /// doesn't indicate an actual problem, but rather a stylistic choice, and
617 /// can be noisy when refactoring or moving around code.
618pub UNUSED_QUALIFICATIONS,
619 Allow,
620"detects unnecessarily qualified names"
621}622623#[doc = r" The `unknown_lints` lint detects unrecognized lint attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![allow(not_a_real_lint)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a lint that does not exist. Check"]
#[doc =
r" the spelling, and check the lint listing for the correct name. Also"]
#[doc =
r" consider if you are using an old version of the compiler, and the lint"]
#[doc = r" is only available in a newer version."]
pub static UNKNOWN_LINTS: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_LINTS",
default_level: crate::Warn,
desc: "unrecognized lint attribute",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
624/// The `unknown_lints` lint detects unrecognized lint attributes.
625 ///
626 /// ### Example
627 ///
628 /// ```rust
629 /// #![allow(not_a_real_lint)]
630 /// ```
631 ///
632 /// {{produces}}
633 ///
634 /// ### Explanation
635 ///
636 /// It is usually a mistake to specify a lint that does not exist. Check
637 /// the spelling, and check the lint listing for the correct name. Also
638 /// consider if you are using an old version of the compiler, and the lint
639 /// is only available in a newer version.
640pub UNKNOWN_LINTS,
641 Warn,
642"unrecognized lint attribute",
643 @eval_always = true
644}645646#[doc =
r" The `unfulfilled_lint_expectations` lint detects when a lint expectation is"]
#[doc = r" unfulfilled."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[expect(unused_variables)]"]
#[doc = r" let x = 10;"]
#[doc = r#" println!("{}", x);"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `#[expect]` attribute can be used to create a lint expectation. The"]
#[doc =
r" expectation is fulfilled, if a `#[warn]` attribute at the same location"]
#[doc =
r" would result in a lint emission. If the expectation is unfulfilled,"]
#[doc =
r" because no lint was emitted, this lint will be emitted on the attribute."]
#[doc = r""]
pub static UNFULFILLED_LINT_EXPECTATIONS: &crate::Lint =
&crate::Lint {
name: "UNFULFILLED_LINT_EXPECTATIONS",
default_level: crate::Warn,
desc: "unfulfilled lint expectation",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
647/// The `unfulfilled_lint_expectations` lint detects when a lint expectation is
648 /// unfulfilled.
649 ///
650 /// ### Example
651 ///
652 /// ```rust
653 /// #[expect(unused_variables)]
654 /// let x = 10;
655 /// println!("{}", x);
656 /// ```
657 ///
658 /// {{produces}}
659 ///
660 /// ### Explanation
661 ///
662 /// The `#[expect]` attribute can be used to create a lint expectation. The
663 /// expectation is fulfilled, if a `#[warn]` attribute at the same location
664 /// would result in a lint emission. If the expectation is unfulfilled,
665 /// because no lint was emitted, this lint will be emitted on the attribute.
666 ///
667pub UNFULFILLED_LINT_EXPECTATIONS,
668 Warn,
669"unfulfilled lint expectation"
670}671672#[doc =
r" The `unused_variables` lint detects variables which are not used in"]
#[doc = r" any way."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused variables may signal a mistake or unfinished code. To silence"]
#[doc =
r" the warning for the individual variable, prefix it with an underscore"]
#[doc = r" such as `_x`."]
pub static UNUSED_VARIABLES: &crate::Lint =
&crate::Lint {
name: "UNUSED_VARIABLES",
default_level: crate::Warn,
desc: "detect variables which are not used in any way",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
673/// The `unused_variables` lint detects variables which are not used in
674 /// any way.
675 ///
676 /// ### Example
677 ///
678 /// ```rust
679 /// let x = 5;
680 /// ```
681 ///
682 /// {{produces}}
683 ///
684 /// ### Explanation
685 ///
686 /// Unused variables may signal a mistake or unfinished code. To silence
687 /// the warning for the individual variable, prefix it with an underscore
688 /// such as `_x`.
689pub UNUSED_VARIABLES,
690 Warn,
691"detect variables which are not used in any way"
692}693694#[doc =
r" The `unused_visibilities` lint detects visibility qualifiers (like `pub`)"]
#[doc = r" on a `const _` item."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" pub const _: () = {};"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" These qualifiers have no effect, as `const _` items are unnameable."]
pub static UNUSED_VISIBILITIES: &crate::Lint =
&crate::Lint {
name: "UNUSED_VISIBILITIES",
default_level: crate::Warn,
desc: "detect visibility qualifiers on `const _` items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
695/// The `unused_visibilities` lint detects visibility qualifiers (like `pub`)
696 /// on a `const _` item.
697 ///
698 /// ### Example
699 ///
700 /// ```rust
701 /// pub const _: () = {};
702 /// ```
703 ///
704 /// {{produces}}
705 ///
706 /// ### Explanation
707 ///
708 /// These qualifiers have no effect, as `const _` items are unnameable.
709pub UNUSED_VISIBILITIES,
710 Warn,
711"detect visibility qualifiers on `const _` items"
712}713714#[doc =
r" The `unused_assignments` lint detects assignments that will never be read."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let mut x = 5;"]
#[doc = r" x = 6;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused assignments may signal a mistake or unfinished code. If the"]
#[doc =
r" variable is never used after being assigned, then the assignment can"]
#[doc =
r" be removed. Variables with an underscore prefix such as `_x` will not"]
#[doc = r" trigger this lint."]
pub static UNUSED_ASSIGNMENTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_ASSIGNMENTS",
default_level: crate::Warn,
desc: "detect assignments that will never be read",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
715/// The `unused_assignments` lint detects assignments that will never be read.
716 ///
717 /// ### Example
718 ///
719 /// ```rust
720 /// let mut x = 5;
721 /// x = 6;
722 /// ```
723 ///
724 /// {{produces}}
725 ///
726 /// ### Explanation
727 ///
728 /// Unused assignments may signal a mistake or unfinished code. If the
729 /// variable is never used after being assigned, then the assignment can
730 /// be removed. Variables with an underscore prefix such as `_x` will not
731 /// trigger this lint.
732pub UNUSED_ASSIGNMENTS,
733 Warn,
734"detect assignments that will never be read"
735}736737#[doc = r" The `dead_code` lint detects unused, unexported items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Dead code may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for individual items, prefix the name with an underscore such"]
#[doc =
r" as `_foo`. If it was intended to expose the item outside of the crate,"]
#[doc = r" consider adding a visibility modifier like `pub`."]
#[doc = r""]
#[doc = r" To preserve the numbering of tuple structs with unused fields,"]
#[doc = r" change the unused fields to have unit type or use"]
#[doc = r" `PhantomData`."]
#[doc = r""]
#[doc = r" Otherwise consider removing the unused code."]
#[doc = r""]
#[doc = r" ### Limitations"]
#[doc = r""]
#[doc = r" Removing fields that are only used for side-effects and never"]
#[doc = r" read will result in behavioral changes. Examples of this"]
#[doc = r" include:"]
#[doc = r""]
#[doc = r" - If a field's value performs an action when it is dropped."]
#[doc = r" - If a field's type does not implement an auto trait"]
#[doc = r" (e.g. `Send`, `Sync`, `Unpin`)."]
#[doc = r""]
#[doc = r" For side-effects from dropping field values, this lint should"]
#[doc = r" be allowed on those fields. For side-effects from containing"]
#[doc = r" field types, `PhantomData` should be used."]
pub static DEAD_CODE: &crate::Lint =
&crate::Lint {
name: "DEAD_CODE",
default_level: crate::Warn,
desc: "detect unused, unexported items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
738/// The `dead_code` lint detects unused, unexported items.
739 ///
740 /// ### Example
741 ///
742 /// ```rust
743 /// fn foo() {}
744 /// ```
745 ///
746 /// {{produces}}
747 ///
748 /// ### Explanation
749 ///
750 /// Dead code may signal a mistake or unfinished code. To silence the
751 /// warning for individual items, prefix the name with an underscore such
752 /// as `_foo`. If it was intended to expose the item outside of the crate,
753 /// consider adding a visibility modifier like `pub`.
754 ///
755 /// To preserve the numbering of tuple structs with unused fields,
756 /// change the unused fields to have unit type or use
757 /// `PhantomData`.
758 ///
759 /// Otherwise consider removing the unused code.
760 ///
761 /// ### Limitations
762 ///
763 /// Removing fields that are only used for side-effects and never
764 /// read will result in behavioral changes. Examples of this
765 /// include:
766 ///
767 /// - If a field's value performs an action when it is dropped.
768 /// - If a field's type does not implement an auto trait
769 /// (e.g. `Send`, `Sync`, `Unpin`).
770 ///
771 /// For side-effects from dropping field values, this lint should
772 /// be allowed on those fields. For side-effects from containing
773 /// field types, `PhantomData` should be used.
774pub DEAD_CODE,
775 Warn,
776"detect unused, unexported items"
777}778779#[doc =
r" The `unused_attributes` lint detects attributes that were not used by"]
#[doc = r" the compiler."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![ignore]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused [attributes] may indicate the attribute is placed in the wrong"]
#[doc =
r" position. Consider removing it, or placing it in the correct position."]
#[doc =
r" Also consider if you intended to use an _inner attribute_ (with a `!`"]
#[doc =
r" such as `#![allow(unused)]`) which applies to the item the attribute"]
#[doc = r" is within, or an _outer attribute_ (without a `!` such as"]
#[doc = r" `#[allow(unused)]`) which applies to the item *following* the"]
#[doc = r" attribute."]
#[doc = r""]
#[doc = r" [attributes]: https://doc.rust-lang.org/reference/attributes.html"]
pub static UNUSED_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "UNUSED_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects attributes that were not used by the compiler",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
780/// The `unused_attributes` lint detects attributes that were not used by
781 /// the compiler.
782 ///
783 /// ### Example
784 ///
785 /// ```rust
786 /// #![ignore]
787 /// ```
788 ///
789 /// {{produces}}
790 ///
791 /// ### Explanation
792 ///
793 /// Unused [attributes] may indicate the attribute is placed in the wrong
794 /// position. Consider removing it, or placing it in the correct position.
795 /// Also consider if you intended to use an _inner attribute_ (with a `!`
796 /// such as `#![allow(unused)]`) which applies to the item the attribute
797 /// is within, or an _outer attribute_ (without a `!` such as
798 /// `#[allow(unused)]`) which applies to the item *following* the
799 /// attribute.
800 ///
801 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
802pub UNUSED_ATTRIBUTES,
803 Warn,
804"detects attributes that were not used by the compiler"
805}806807#[doc = r" The `unreachable_code` lint detects unreachable code paths."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r#" panic!("we never go past here!");"#]
#[doc = r""]
#[doc = r" let x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unreachable code may signal a mistake or unfinished code. If the code"]
#[doc = r" is no longer in use, consider removing it."]
pub static UNREACHABLE_CODE: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_CODE",
default_level: crate::Warn,
desc: "detects unreachable code paths",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
808/// The `unreachable_code` lint detects unreachable code paths.
809 ///
810 /// ### Example
811 ///
812 /// ```rust,no_run
813 /// panic!("we never go past here!");
814 ///
815 /// let x = 5;
816 /// ```
817 ///
818 /// {{produces}}
819 ///
820 /// ### Explanation
821 ///
822 /// Unreachable code may signal a mistake or unfinished code. If the code
823 /// is no longer in use, consider removing it.
824pub UNREACHABLE_CODE,
825 Warn,
826"detects unreachable code paths",
827 report_in_external_macro
828}829830#[doc = r" The `unreachable_patterns` lint detects unreachable patterns."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 5;"]
#[doc = r" match x {"]
#[doc = r" y => (),"]
#[doc = r" 5 => (),"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This usually indicates a mistake in how the patterns are specified or"]
#[doc =
r" ordered. In this example, the `y` pattern will always match, so the"]
#[doc =
r" five is impossible to reach. Remember, match arms match in order, you"]
#[doc = r" probably wanted to put the `5` case above the `y` case."]
pub static UNREACHABLE_PATTERNS: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_PATTERNS",
default_level: crate::Warn,
desc: "detects unreachable patterns",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
831/// The `unreachable_patterns` lint detects unreachable patterns.
832 ///
833 /// ### Example
834 ///
835 /// ```rust
836 /// let x = 5;
837 /// match x {
838 /// y => (),
839 /// 5 => (),
840 /// }
841 /// ```
842 ///
843 /// {{produces}}
844 ///
845 /// ### Explanation
846 ///
847 /// This usually indicates a mistake in how the patterns are specified or
848 /// ordered. In this example, the `y` pattern will always match, so the
849 /// five is impossible to reach. Remember, match arms match in order, you
850 /// probably wanted to put the `5` case above the `y` case.
851pub UNREACHABLE_PATTERNS,
852 Warn,
853"detects unreachable patterns"
854}855856#[doc =
r" The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that"]
#[doc = r" overlap on their endpoints."]
#[doc = r""]
#[doc =
r" [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 123u8;"]
#[doc = r" match x {"]
#[doc = r#" 0..=100 => { println!("small"); }"#]
#[doc = r#" 100..=255 => { println!("large"); }"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is likely a mistake to have range patterns in a match expression that overlap in this"]
#[doc =
r" way. Check that the beginning and end values are what you expect, and keep in mind that"]
#[doc = r" with `..=` the left and right bounds are inclusive."]
pub static OVERLAPPING_RANGE_ENDPOINTS: &crate::Lint =
&crate::Lint {
name: "OVERLAPPING_RANGE_ENDPOINTS",
default_level: crate::Warn,
desc: "detects range patterns with overlapping endpoints",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
857/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
858 /// overlap on their endpoints.
859 ///
860 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
861 ///
862 /// ### Example
863 ///
864 /// ```rust
865 /// let x = 123u8;
866 /// match x {
867 /// 0..=100 => { println!("small"); }
868 /// 100..=255 => { println!("large"); }
869 /// }
870 /// ```
871 ///
872 /// {{produces}}
873 ///
874 /// ### Explanation
875 ///
876 /// It is likely a mistake to have range patterns in a match expression that overlap in this
877 /// way. Check that the beginning and end values are what you expect, and keep in mind that
878 /// with `..=` the left and right bounds are inclusive.
879pub OVERLAPPING_RANGE_ENDPOINTS,
880 Warn,
881"detects range patterns with overlapping endpoints"
882}883884#[doc =
r" The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using"]
#[doc = r" exclusive [range patterns]."]
#[doc = r""]
#[doc =
r" [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 123u32;"]
#[doc = r" match x {"]
#[doc = r#" 0..100 => { println!("small"); }"#]
#[doc = r#" 101..1000 => { println!("large"); }"#]
#[doc = r#" _ => { println!("larger"); }"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is likely a mistake to have range patterns in a match expression that miss out a single"]
#[doc =
r" number. Check that the beginning and end values are what you expect, and keep in mind that"]
#[doc =
r" with `..=` the right bound is inclusive, and with `..` it is exclusive."]
pub static NON_CONTIGUOUS_RANGE_ENDPOINTS: &crate::Lint =
&crate::Lint {
name: "NON_CONTIGUOUS_RANGE_ENDPOINTS",
default_level: crate::Warn,
desc: "detects off-by-one errors with exclusive range patterns",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
885/// The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
886 /// exclusive [range patterns].
887 ///
888 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
889 ///
890 /// ### Example
891 ///
892 /// ```rust
893 /// let x = 123u32;
894 /// match x {
895 /// 0..100 => { println!("small"); }
896 /// 101..1000 => { println!("large"); }
897 /// _ => { println!("larger"); }
898 /// }
899 /// ```
900 ///
901 /// {{produces}}
902 ///
903 /// ### Explanation
904 ///
905 /// It is likely a mistake to have range patterns in a match expression that miss out a single
906 /// number. Check that the beginning and end values are what you expect, and keep in mind that
907 /// with `..=` the right bound is inclusive, and with `..` it is exclusive.
908pub NON_CONTIGUOUS_RANGE_ENDPOINTS,
909 Warn,
910"detects off-by-one errors with exclusive range patterns"
911}912913#[doc =
r" The `bindings_with_variant_name` lint detects pattern bindings with"]
#[doc = r" the same name as one of the matched variants."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" pub enum Enum {"]
#[doc = r" Foo,"]
#[doc = r" Bar,"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub fn foo(x: Enum) {"]
#[doc = r" match x {"]
#[doc = r" Foo => {}"]
#[doc = r" Bar => {}"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" It is usually a mistake to specify an enum variant name as an"]
#[doc = r" [identifier pattern]. In the example above, the `match` arms are"]
#[doc =
r" specifying a variable name to bind the value of `x` to. The second arm"]
#[doc = r" is ignored because the first one matches *all* values. The likely"]
#[doc = r" intent is that the arm was intended to match on the enum variant."]
#[doc = r""]
#[doc = r" Two possible solutions are:"]
#[doc = r""]
#[doc = r" * Specify the enum variant using a [path pattern], such as"]
#[doc = r" `Enum::Foo`."]
#[doc = r" * Bring the enum variants into local scope, such as adding `use"]
#[doc = r" Enum::*;` to the beginning of the `foo` function in the example"]
#[doc = r" above."]
#[doc = r""]
#[doc =
r" [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns"]
#[doc =
r" [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns"]
pub static BINDINGS_WITH_VARIANT_NAME: &crate::Lint =
&crate::Lint {
name: "BINDINGS_WITH_VARIANT_NAME",
default_level: crate::Deny,
desc: "detects pattern bindings with the same name as one of the matched variants",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
914/// The `bindings_with_variant_name` lint detects pattern bindings with
915 /// the same name as one of the matched variants.
916 ///
917 /// ### Example
918 ///
919 /// ```rust,compile_fail
920 /// pub enum Enum {
921 /// Foo,
922 /// Bar,
923 /// }
924 ///
925 /// pub fn foo(x: Enum) {
926 /// match x {
927 /// Foo => {}
928 /// Bar => {}
929 /// }
930 /// }
931 /// ```
932 ///
933 /// {{produces}}
934 ///
935 /// ### Explanation
936 ///
937 /// It is usually a mistake to specify an enum variant name as an
938 /// [identifier pattern]. In the example above, the `match` arms are
939 /// specifying a variable name to bind the value of `x` to. The second arm
940 /// is ignored because the first one matches *all* values. The likely
941 /// intent is that the arm was intended to match on the enum variant.
942 ///
943 /// Two possible solutions are:
944 ///
945 /// * Specify the enum variant using a [path pattern], such as
946 /// `Enum::Foo`.
947 /// * Bring the enum variants into local scope, such as adding `use
948 /// Enum::*;` to the beginning of the `foo` function in the example
949 /// above.
950 ///
951 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
952 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
953pub BINDINGS_WITH_VARIANT_NAME,
954 Deny,
955"detects pattern bindings with the same name as one of the matched variants"
956}957958#[doc = r" The `unused_macros` lint detects macros that were not used."]
#[doc = r""]
#[doc =
r" Note that this lint is distinct from the `unused_macro_rules` lint,"]
#[doc =
r" which checks for single rules that never match of an otherwise used"]
#[doc = r" macro, and thus never expand."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" macro_rules! unused {"]
#[doc = r" () => {};"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused macros may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for the individual macro, prefix the name with an underscore"]
#[doc =
r" such as `_my_macro`. If you intended to export the macro to make it"]
#[doc =
r" available outside of the crate, use the [`macro_export` attribute]."]
#[doc = r""]
#[doc =
r" [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
pub static UNUSED_MACROS: &crate::Lint =
&crate::Lint {
name: "UNUSED_MACROS",
default_level: crate::Warn,
desc: "detects macros that were not used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
959/// The `unused_macros` lint detects macros that were not used.
960 ///
961 /// Note that this lint is distinct from the `unused_macro_rules` lint,
962 /// which checks for single rules that never match of an otherwise used
963 /// macro, and thus never expand.
964 ///
965 /// ### Example
966 ///
967 /// ```rust
968 /// macro_rules! unused {
969 /// () => {};
970 /// }
971 ///
972 /// fn main() {
973 /// }
974 /// ```
975 ///
976 /// {{produces}}
977 ///
978 /// ### Explanation
979 ///
980 /// Unused macros may signal a mistake or unfinished code. To silence the
981 /// warning for the individual macro, prefix the name with an underscore
982 /// such as `_my_macro`. If you intended to export the macro to make it
983 /// available outside of the crate, use the [`macro_export` attribute].
984 ///
985 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
986pub UNUSED_MACROS,
987 Warn,
988"detects macros that were not used"
989}990991#[doc =
r" The `unused_macro_rules` lint detects macro rules that were not used."]
#[doc = r""]
#[doc =
r" Note that the lint is distinct from the `unused_macros` lint, which"]
#[doc =
r" fires if the entire macro is never called, while this lint fires for"]
#[doc = r" single unused rules of the macro that is otherwise used."]
#[doc = r" `unused_macro_rules` fires only if `unused_macros` wouldn't fire."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[warn(unused_macro_rules)]"]
#[doc = r" macro_rules! unused_empty {"]
#[doc =
r#" (hello) => { println!("Hello, world!") }; // This rule is unused"#]
#[doc = r#" () => { println!("empty") }; // This rule is used"#]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" unused_empty!(hello);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused macro rules may signal a mistake or unfinished code. Furthermore,"]
#[doc =
r" they slow down compilation. Right now, silencing the warning is not"]
#[doc =
r" supported on a single rule level, so you have to add an allow to the"]
#[doc = r" entire macro definition."]
#[doc = r""]
#[doc = r" If you intended to export the macro to make it"]
#[doc =
r" available outside of the crate, use the [`macro_export` attribute]."]
#[doc = r""]
#[doc =
r" [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
pub static UNUSED_MACRO_RULES: &crate::Lint =
&crate::Lint {
name: "UNUSED_MACRO_RULES",
default_level: crate::Allow,
desc: "detects macro rules that were not used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
992/// The `unused_macro_rules` lint detects macro rules that were not used.
993 ///
994 /// Note that the lint is distinct from the `unused_macros` lint, which
995 /// fires if the entire macro is never called, while this lint fires for
996 /// single unused rules of the macro that is otherwise used.
997 /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
998 ///
999 /// ### Example
1000 ///
1001 /// ```rust
1002 /// #[warn(unused_macro_rules)]
1003 /// macro_rules! unused_empty {
1004 /// (hello) => { println!("Hello, world!") }; // This rule is unused
1005 /// () => { println!("empty") }; // This rule is used
1006 /// }
1007 ///
1008 /// fn main() {
1009 /// unused_empty!(hello);
1010 /// }
1011 /// ```
1012 ///
1013 /// {{produces}}
1014 ///
1015 /// ### Explanation
1016 ///
1017 /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
1018 /// they slow down compilation. Right now, silencing the warning is not
1019 /// supported on a single rule level, so you have to add an allow to the
1020 /// entire macro definition.
1021 ///
1022 /// If you intended to export the macro to make it
1023 /// available outside of the crate, use the [`macro_export` attribute].
1024 ///
1025 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1026pub UNUSED_MACRO_RULES,
1027 Allow,
1028"detects macro rules that were not used"
1029}10301031#[doc = r" The `warnings` lint allows you to change the level of other"]
#[doc = r" lints which produce warnings."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The `warnings` lint is a bit special; by changing its level, you"]
#[doc =
r" change every other warning that would produce a warning to whatever"]
#[doc =
r" value you'd like. As such, you won't ever trigger this lint in your"]
#[doc = r" code directly."]
pub static WARNINGS: &crate::Lint =
&crate::Lint {
name: "WARNINGS",
default_level: crate::Warn,
desc: "mass-change the level for lints which produce warnings",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1032/// The `warnings` lint allows you to change the level of other
1033 /// lints which produce warnings.
1034 ///
1035 /// ### Example
1036 ///
1037 /// ```rust
1038 /// #![deny(warnings)]
1039 /// fn foo() {}
1040 /// ```
1041 ///
1042 /// {{produces}}
1043 ///
1044 /// ### Explanation
1045 ///
1046 /// The `warnings` lint is a bit special; by changing its level, you
1047 /// change every other warning that would produce a warning to whatever
1048 /// value you'd like. As such, you won't ever trigger this lint in your
1049 /// code directly.
1050pub WARNINGS,
1051 Warn,
1052"mass-change the level for lints which produce warnings"
1053}10541055#[doc =
r" The `unused_features` lint detects unused or unknown features found in"]
#[doc = r" crate-level [`feature` attributes]."]
#[doc = r""]
#[doc =
r" [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/"]
#[doc = r""]
#[doc =
r" Note: This lint is currently not functional, see [issue #44232] for"]
#[doc = r" more details."]
#[doc = r""]
#[doc = r" [issue #44232]: https://github.com/rust-lang/rust/issues/44232"]
pub static UNUSED_FEATURES: &crate::Lint =
&crate::Lint {
name: "UNUSED_FEATURES",
default_level: crate::Warn,
desc: "unused features found in crate-level `#[feature]` directives",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1056/// The `unused_features` lint detects unused or unknown features found in
1057 /// crate-level [`feature` attributes].
1058 ///
1059 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1060 ///
1061 /// Note: This lint is currently not functional, see [issue #44232] for
1062 /// more details.
1063 ///
1064 /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
1065pub UNUSED_FEATURES,
1066 Warn,
1067"unused features found in crate-level `#[feature]` directives"
1068}10691070#[doc = r" The `stable_features` lint detects a [`feature` attribute] that"]
#[doc = r" has since been made stable."]
#[doc = r""]
#[doc =
r" [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(test_accepted_feature)]"]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When a feature is stabilized, it is no longer necessary to include a"]
#[doc = r" `#![feature]` attribute for it. To fix, simply remove the"]
#[doc = r" `#![feature]` attribute."]
pub static STABLE_FEATURES: &crate::Lint =
&crate::Lint {
name: "STABLE_FEATURES",
default_level: crate::Warn,
desc: "stable features found in `#[feature]` directive",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1071/// The `stable_features` lint detects a [`feature` attribute] that
1072 /// has since been made stable.
1073 ///
1074 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1075 ///
1076 /// ### Example
1077 ///
1078 /// ```rust
1079 /// #![feature(test_accepted_feature)]
1080 /// fn main() {}
1081 /// ```
1082 ///
1083 /// {{produces}}
1084 ///
1085 /// ### Explanation
1086 ///
1087 /// When a feature is stabilized, it is no longer necessary to include a
1088 /// `#![feature]` attribute for it. To fix, simply remove the
1089 /// `#![feature]` attribute.
1090pub STABLE_FEATURES,
1091 Warn,
1092"stable features found in `#[feature]` directive"
1093}10941095#[doc =
r" The `unknown_crate_types` lint detects an unknown crate type found in"]
#[doc = r" a [`crate_type` attribute]."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r#" #![crate_type="lol"]"#]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" An unknown value give to the `crate_type` attribute is almost"]
#[doc = r" certainly a mistake."]
#[doc = r""]
#[doc =
r" [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html"]
pub static UNKNOWN_CRATE_TYPES: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_CRATE_TYPES",
default_level: crate::Deny,
desc: "unknown crate type found in `#[crate_type]` directive",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1096/// The `unknown_crate_types` lint detects an unknown crate type found in
1097 /// a [`crate_type` attribute].
1098 ///
1099 /// ### Example
1100 ///
1101 /// ```rust,compile_fail
1102 /// #![crate_type="lol"]
1103 /// fn main() {}
1104 /// ```
1105 ///
1106 /// {{produces}}
1107 ///
1108 /// ### Explanation
1109 ///
1110 /// An unknown value give to the `crate_type` attribute is almost
1111 /// certainly a mistake.
1112 ///
1113 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
1114pub UNKNOWN_CRATE_TYPES,
1115 Deny,
1116"unknown crate type found in `#[crate_type]` directive",
1117 crate_level_only
1118}11191120#[doc =
r" The `trivial_casts` lint detects trivial casts which could be replaced"]
#[doc = r" with coercion, which may require a temporary variable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(trivial_casts)]"]
#[doc = r" let x: &u32 = &42;"]
#[doc = r" let y = x as *const u32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a"]
#[doc =
r" subtype of `T`. This type of cast is usually unnecessary, as it can be"]
#[doc = r" usually be inferred."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because there are situations, such as"#]
#[doc = r" with FFI interfaces or complex type aliases, where it triggers"]
#[doc = r" incorrectly, or in situations where it will be more difficult to"]
#[doc =
r" clearly express the intent. It may be possible that this will become a"]
#[doc =
r" warning in the future, possibly with an explicit syntax for coercions"]
#[doc = r" providing a convenient way to work around the current issues."]
#[doc =
r" See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and"]
#[doc =
r" [RFC 3307 (remove type ascription)][rfc-3307] for historical context."]
#[doc = r""]
#[doc =
r" [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md"]
#[doc =
r" [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md"]
#[doc =
r" [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md"]
pub static TRIVIAL_CASTS: &crate::Lint =
&crate::Lint {
name: "TRIVIAL_CASTS",
default_level: crate::Allow,
desc: "detects trivial casts which could be removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1121/// The `trivial_casts` lint detects trivial casts which could be replaced
1122 /// with coercion, which may require a temporary variable.
1123 ///
1124 /// ### Example
1125 ///
1126 /// ```rust,compile_fail
1127 /// #![deny(trivial_casts)]
1128 /// let x: &u32 = &42;
1129 /// let y = x as *const u32;
1130 /// ```
1131 ///
1132 /// {{produces}}
1133 ///
1134 /// ### Explanation
1135 ///
1136 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
1137 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
1138 /// usually be inferred.
1139 ///
1140 /// This lint is "allow" by default because there are situations, such as
1141 /// with FFI interfaces or complex type aliases, where it triggers
1142 /// incorrectly, or in situations where it will be more difficult to
1143 /// clearly express the intent. It may be possible that this will become a
1144 /// warning in the future, possibly with an explicit syntax for coercions
1145 /// providing a convenient way to work around the current issues.
1146 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1147 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1148 ///
1149 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1150 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1151 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1152pub TRIVIAL_CASTS,
1153 Allow,
1154"detects trivial casts which could be removed"
1155}11561157#[doc =
r" The `trivial_numeric_casts` lint detects trivial numeric casts of types"]
#[doc = r" which could be removed."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(trivial_numeric_casts)]"]
#[doc = r" let x = 42_i32 as i32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A trivial numeric cast is a cast of a numeric type to the same numeric"]
#[doc = r" type. This type of cast is usually unnecessary."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because there are situations, such as"#]
#[doc = r" with FFI interfaces or complex type aliases, where it triggers"]
#[doc = r" incorrectly, or in situations where it will be more difficult to"]
#[doc =
r" clearly express the intent. It may be possible that this will become a"]
#[doc =
r" warning in the future, possibly with an explicit syntax for coercions"]
#[doc = r" providing a convenient way to work around the current issues."]
#[doc =
r" See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and"]
#[doc =
r" [RFC 3307 (remove type ascription)][rfc-3307] for historical context."]
#[doc = r""]
#[doc =
r" [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md"]
#[doc =
r" [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md"]
#[doc =
r" [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md"]
pub static TRIVIAL_NUMERIC_CASTS: &crate::Lint =
&crate::Lint {
name: "TRIVIAL_NUMERIC_CASTS",
default_level: crate::Allow,
desc: "detects trivial casts of numeric types which could be removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1158/// The `trivial_numeric_casts` lint detects trivial numeric casts of types
1159 /// which could be removed.
1160 ///
1161 /// ### Example
1162 ///
1163 /// ```rust,compile_fail
1164 /// #![deny(trivial_numeric_casts)]
1165 /// let x = 42_i32 as i32;
1166 /// ```
1167 ///
1168 /// {{produces}}
1169 ///
1170 /// ### Explanation
1171 ///
1172 /// A trivial numeric cast is a cast of a numeric type to the same numeric
1173 /// type. This type of cast is usually unnecessary.
1174 ///
1175 /// This lint is "allow" by default because there are situations, such as
1176 /// with FFI interfaces or complex type aliases, where it triggers
1177 /// incorrectly, or in situations where it will be more difficult to
1178 /// clearly express the intent. It may be possible that this will become a
1179 /// warning in the future, possibly with an explicit syntax for coercions
1180 /// providing a convenient way to work around the current issues.
1181 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1182 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1183 ///
1184 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1185 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1186 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1187pub TRIVIAL_NUMERIC_CASTS,
1188 Allow,
1189"detects trivial casts of numeric types which could be removed"
1190}11911192#[doc =
r" The `exported_private_dependencies` lint detects private dependencies"]
#[doc = r" that are exposed in a public interface."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" pub fn foo() -> Option<some_private_dependency::Thing> {"]
#[doc = r" None"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning: type `bar::Thing` from private dependency 'bar' in public interface"]
#[doc = r" --> src/lib.rs:3:1"]
#[doc = r" |"]
#[doc = r" 3 | pub fn foo() -> Option<bar::Thing> {"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(exported_private_dependencies)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Dependencies can be marked as "private" to indicate that they are not"#]
#[doc =
r" exposed in the public interface of a crate. This can be used by Cargo"]
#[doc =
r" to independently resolve those dependencies because it can assume it"]
#[doc = r" does not need to unify them with other packages using that same"]
#[doc = r" dependency. This lint is an indication of a violation of that"]
#[doc = r" contract."]
#[doc = r""]
#[doc =
r" To fix this, avoid exposing the dependency in your public interface."]
#[doc = r" Or, switch the dependency to a public dependency."]
#[doc = r""]
#[doc =
r" Note that support for this is only available on the nightly channel."]
#[doc =
r" See [RFC 1977] for more details, as well as the [Cargo documentation]."]
#[doc = r""]
#[doc =
r" [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md"]
#[doc =
r" [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency"]
pub static EXPORTED_PRIVATE_DEPENDENCIES: &crate::Lint =
&crate::Lint {
name: "EXPORTED_PRIVATE_DEPENDENCIES",
default_level: crate::Warn,
desc: "public interface leaks type from a private dependency",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1193/// The `exported_private_dependencies` lint detects private dependencies
1194 /// that are exposed in a public interface.
1195 ///
1196 /// ### Example
1197 ///
1198 /// ```rust,ignore (needs-dependency)
1199 /// pub fn foo() -> Option<some_private_dependency::Thing> {
1200 /// None
1201 /// }
1202 /// ```
1203 ///
1204 /// This will produce:
1205 ///
1206 /// ```text
1207 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1208 /// --> src/lib.rs:3:1
1209 /// |
1210 /// 3 | pub fn foo() -> Option<bar::Thing> {
1211 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212 /// |
1213 /// = note: `#[warn(exported_private_dependencies)]` on by default
1214 /// ```
1215 ///
1216 /// ### Explanation
1217 ///
1218 /// Dependencies can be marked as "private" to indicate that they are not
1219 /// exposed in the public interface of a crate. This can be used by Cargo
1220 /// to independently resolve those dependencies because it can assume it
1221 /// does not need to unify them with other packages using that same
1222 /// dependency. This lint is an indication of a violation of that
1223 /// contract.
1224 ///
1225 /// To fix this, avoid exposing the dependency in your public interface.
1226 /// Or, switch the dependency to a public dependency.
1227 ///
1228 /// Note that support for this is only available on the nightly channel.
1229 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1230 ///
1231 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1232 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1233pub EXPORTED_PRIVATE_DEPENDENCIES,
1234 Warn,
1235"public interface leaks type from a private dependency"
1236}12371238#[doc = r" The `pub_use_of_private_extern_crate` lint detects a specific"]
#[doc = r" situation of re-exporting a private `extern crate`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" extern crate core;"]
#[doc = r" pub use core as reexported_core;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A public `use` declaration should not be used to publically re-export a"]
#[doc =
r" private `extern crate`. `pub extern crate` should be used instead."]
#[doc = r""]
#[doc = r" This was historically allowed, but is not the intended behavior"]
#[doc =
r" according to the visibility rules. This is a [future-incompatible]"]
#[doc = r" lint to transition this to a hard error in the future. See [issue"]
#[doc = r" #127909] for more details."]
#[doc = r""]
#[doc = r" [issue #127909]: https://github.com/rust-lang/rust/issues/127909"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PUB_USE_OF_PRIVATE_EXTERN_CRATE: &crate::Lint =
&crate::Lint {
name: "PUB_USE_OF_PRIVATE_EXTERN_CRATE",
default_level: crate::Deny,
desc: "detect public re-exports of private extern crates",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 127909,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1239/// The `pub_use_of_private_extern_crate` lint detects a specific
1240 /// situation of re-exporting a private `extern crate`.
1241 ///
1242 /// ### Example
1243 ///
1244 /// ```rust,compile_fail
1245 /// extern crate core;
1246 /// pub use core as reexported_core;
1247 /// ```
1248 ///
1249 /// {{produces}}
1250 ///
1251 /// ### Explanation
1252 ///
1253 /// A public `use` declaration should not be used to publically re-export a
1254 /// private `extern crate`. `pub extern crate` should be used instead.
1255 ///
1256 /// This was historically allowed, but is not the intended behavior
1257 /// according to the visibility rules. This is a [future-incompatible]
1258 /// lint to transition this to a hard error in the future. See [issue
1259 /// #127909] for more details.
1260 ///
1261 /// [issue #127909]: https://github.com/rust-lang/rust/issues/127909
1262 /// [future-incompatible]: ../index.md#future-incompatible-lints
1263pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1264 Deny,
1265"detect public re-exports of private extern crates",
1266 @future_incompatible = FutureIncompatibleInfo {
1267 reason: fcw!(FutureReleaseError #127909),
1268 report_in_deps: true,
1269 };
1270}12711272#[doc =
r" The `invalid_type_param_default` lint detects type parameter defaults"]
#[doc = r" erroneously allowed in an invalid location."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" fn foo<T=i32>(t: T) {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Default type parameters were only intended to be allowed in certain"]
#[doc =
r" situations, but historically the compiler allowed them everywhere."]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc = r" error in the future. See [issue #36887] for more details."]
#[doc = r""]
#[doc = r" [issue #36887]: https://github.com/rust-lang/rust/issues/36887"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static INVALID_TYPE_PARAM_DEFAULT: &crate::Lint =
&crate::Lint {
name: "INVALID_TYPE_PARAM_DEFAULT",
default_level: crate::Deny,
desc: "type parameter default erroneously allowed in invalid location",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 36887,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1273/// The `invalid_type_param_default` lint detects type parameter defaults
1274 /// erroneously allowed in an invalid location.
1275 ///
1276 /// ### Example
1277 ///
1278 /// ```rust,compile_fail
1279 /// fn foo<T=i32>(t: T) {}
1280 /// ```
1281 ///
1282 /// {{produces}}
1283 ///
1284 /// ### Explanation
1285 ///
1286 /// Default type parameters were only intended to be allowed in certain
1287 /// situations, but historically the compiler allowed them everywhere.
1288 /// This is a [future-incompatible] lint to transition this to a hard
1289 /// error in the future. See [issue #36887] for more details.
1290 ///
1291 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1292 /// [future-incompatible]: ../index.md#future-incompatible-lints
1293pub INVALID_TYPE_PARAM_DEFAULT,
1294 Deny,
1295"type parameter default erroneously allowed in invalid location",
1296 @future_incompatible = FutureIncompatibleInfo {
1297 reason: fcw!(FutureReleaseError #36887),
1298 report_in_deps: true,
1299 };
1300}13011302#[doc = r" The `renamed_and_removed_lints` lint detects lints that have been"]
#[doc = r" renamed or removed."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(raw_pointer_derive)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" To fix this, either remove the lint or use the new name. This can help"]
#[doc = r" avoid confusion about lints that are no longer valid, and help"]
#[doc = r" maintain consistency for renamed lints."]
pub static RENAMED_AND_REMOVED_LINTS: &crate::Lint =
&crate::Lint {
name: "RENAMED_AND_REMOVED_LINTS",
default_level: crate::Warn,
desc: "lints that have been renamed or removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1303/// The `renamed_and_removed_lints` lint detects lints that have been
1304 /// renamed or removed.
1305 ///
1306 /// ### Example
1307 ///
1308 /// ```rust
1309 /// #![deny(raw_pointer_derive)]
1310 /// ```
1311 ///
1312 /// {{produces}}
1313 ///
1314 /// ### Explanation
1315 ///
1316 /// To fix this, either remove the lint or use the new name. This can help
1317 /// avoid confusion about lints that are no longer valid, and help
1318 /// maintain consistency for renamed lints.
1319pub RENAMED_AND_REMOVED_LINTS,
1320 Warn,
1321"lints that have been renamed or removed"
1322}13231324#[doc =
r" The `const_item_mutation` lint detects attempts to mutate a `const`"]
#[doc = r" item."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" const FOO: [i32; 1] = [0];"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" FOO[0] = 1;"]
#[doc = r#" // This will print "[0]"."#]
#[doc = r#" println!("{:?}", FOO);"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Trying to directly mutate a `const` item is almost always a mistake."]
#[doc =
r" What is happening in the example above is that a temporary copy of the"]
#[doc =
r" `const` is mutated, but the original `const` is not. Each time you"]
#[doc =
r" refer to the `const` by name (such as `FOO` in the example above), a"]
#[doc = r" separate copy of the value is inlined at that location."]
#[doc = r""]
#[doc = r" This lint checks for writing directly to a field (`FOO.field ="]
#[doc = r" some_value`) or array entry (`FOO[0] = val`), or taking a mutable"]
#[doc = r" reference to the const item (`&mut FOO`), including through an"]
#[doc = r" autoderef (`FOO.some_mut_self_method()`)."]
#[doc = r""]
#[doc =
r" There are various alternatives depending on what you are trying to"]
#[doc = r" accomplish:"]
#[doc = r""]
#[doc = r" * First, always reconsider using mutable globals, as they can be"]
#[doc =
r" difficult to use correctly, and can make the code more difficult to"]
#[doc = r" use or understand."]
#[doc =
r" * If you are trying to perform a one-time initialization of a global:"]
#[doc =
r" * If the value can be computed at compile-time, consider using"]
#[doc = r" const-compatible values (see [Constant Evaluation])."]
#[doc =
r" * For more complex single-initialization cases, consider using"]
#[doc = r" [`std::sync::LazyLock`]."]
#[doc =
r" * If you truly need a mutable global, consider using a [`static`],"]
#[doc = r" which has a variety of options:"]
#[doc = r" * Simple data types can be directly defined and mutated with an"]
#[doc = r" [`atomic`] type."]
#[doc =
r" * More complex types can be placed in a synchronization primitive"]
#[doc =
r" like a [`Mutex`], which can be initialized with one of the options"]
#[doc = r" listed above."]
#[doc =
r" * A [mutable `static`] is a low-level primitive, requiring unsafe."]
#[doc = r" Typically This should be avoided in preference of something"]
#[doc = r" higher-level like one of the above."]
#[doc = r""]
#[doc =
r" [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html"]
#[doc =
r" [`static`]: https://doc.rust-lang.org/reference/items/static-items.html"]
#[doc =
r" [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics"]
#[doc =
r" [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html"]
#[doc = r" [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html"]
#[doc = r" [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html"]
pub static CONST_ITEM_MUTATION: &crate::Lint =
&crate::Lint {
name: "CONST_ITEM_MUTATION",
default_level: crate::Warn,
desc: "detects attempts to mutate a `const` item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1325/// The `const_item_mutation` lint detects attempts to mutate a `const`
1326 /// item.
1327 ///
1328 /// ### Example
1329 ///
1330 /// ```rust
1331 /// const FOO: [i32; 1] = [0];
1332 ///
1333 /// fn main() {
1334 /// FOO[0] = 1;
1335 /// // This will print "[0]".
1336 /// println!("{:?}", FOO);
1337 /// }
1338 /// ```
1339 ///
1340 /// {{produces}}
1341 ///
1342 /// ### Explanation
1343 ///
1344 /// Trying to directly mutate a `const` item is almost always a mistake.
1345 /// What is happening in the example above is that a temporary copy of the
1346 /// `const` is mutated, but the original `const` is not. Each time you
1347 /// refer to the `const` by name (such as `FOO` in the example above), a
1348 /// separate copy of the value is inlined at that location.
1349 ///
1350 /// This lint checks for writing directly to a field (`FOO.field =
1351 /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1352 /// reference to the const item (`&mut FOO`), including through an
1353 /// autoderef (`FOO.some_mut_self_method()`).
1354 ///
1355 /// There are various alternatives depending on what you are trying to
1356 /// accomplish:
1357 ///
1358 /// * First, always reconsider using mutable globals, as they can be
1359 /// difficult to use correctly, and can make the code more difficult to
1360 /// use or understand.
1361 /// * If you are trying to perform a one-time initialization of a global:
1362 /// * If the value can be computed at compile-time, consider using
1363 /// const-compatible values (see [Constant Evaluation]).
1364 /// * For more complex single-initialization cases, consider using
1365 /// [`std::sync::LazyLock`].
1366 /// * If you truly need a mutable global, consider using a [`static`],
1367 /// which has a variety of options:
1368 /// * Simple data types can be directly defined and mutated with an
1369 /// [`atomic`] type.
1370 /// * More complex types can be placed in a synchronization primitive
1371 /// like a [`Mutex`], which can be initialized with one of the options
1372 /// listed above.
1373 /// * A [mutable `static`] is a low-level primitive, requiring unsafe.
1374 /// Typically This should be avoided in preference of something
1375 /// higher-level like one of the above.
1376 ///
1377 /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1378 /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1379 /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1380 /// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
1381 /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1382 /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1383pub CONST_ITEM_MUTATION,
1384 Warn,
1385"detects attempts to mutate a `const` item",
1386}13871388#[doc = r" The `patterns_in_fns_without_body` lint detects `mut` identifier"]
#[doc = r" patterns as a parameter in functions without a body."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" trait Trait {"]
#[doc = r" fn foo(mut arg: u8);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" To fix this, remove `mut` from the parameter in the trait definition;"]
#[doc =
r" it can be used in the implementation. That is, the following is OK:"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Trait {"]
#[doc = r" fn foo(arg: u8); // Removed `mut` here"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Trait for i32 {"]
#[doc = r" fn foo(mut arg: u8) { // `mut` here is OK"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" Trait definitions can define functions without a body to specify a"]
#[doc =
r" function that implementors must define. The parameter names in the"]
#[doc =
r" body-less functions are only allowed to be `_` or an [identifier] for"]
#[doc =
r" documentation purposes (only the type is relevant). Previous versions"]
#[doc =
r" of the compiler erroneously allowed [identifier patterns] with the"]
#[doc = r" `mut` keyword, but this was not intended to be allowed. This is a"]
#[doc =
r" [future-incompatible] lint to transition this to a hard error in the"]
#[doc = r" future. See [issue #35203] for more details."]
#[doc = r""]
#[doc =
r" [identifier]: https://doc.rust-lang.org/reference/identifiers.html"]
#[doc =
r" [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns"]
#[doc = r" [issue #35203]: https://github.com/rust-lang/rust/issues/35203"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PATTERNS_IN_FNS_WITHOUT_BODY: &crate::Lint =
&crate::Lint {
name: "PATTERNS_IN_FNS_WITHOUT_BODY",
default_level: crate::Deny,
desc: "patterns in functions without body were erroneously allowed",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 35203,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1389/// The `patterns_in_fns_without_body` lint detects `mut` identifier
1390 /// patterns as a parameter in functions without a body.
1391 ///
1392 /// ### Example
1393 ///
1394 /// ```rust,compile_fail
1395 /// trait Trait {
1396 /// fn foo(mut arg: u8);
1397 /// }
1398 /// ```
1399 ///
1400 /// {{produces}}
1401 ///
1402 /// ### Explanation
1403 ///
1404 /// To fix this, remove `mut` from the parameter in the trait definition;
1405 /// it can be used in the implementation. That is, the following is OK:
1406 ///
1407 /// ```rust
1408 /// trait Trait {
1409 /// fn foo(arg: u8); // Removed `mut` here
1410 /// }
1411 ///
1412 /// impl Trait for i32 {
1413 /// fn foo(mut arg: u8) { // `mut` here is OK
1414 ///
1415 /// }
1416 /// }
1417 /// ```
1418 ///
1419 /// Trait definitions can define functions without a body to specify a
1420 /// function that implementors must define. The parameter names in the
1421 /// body-less functions are only allowed to be `_` or an [identifier] for
1422 /// documentation purposes (only the type is relevant). Previous versions
1423 /// of the compiler erroneously allowed [identifier patterns] with the
1424 /// `mut` keyword, but this was not intended to be allowed. This is a
1425 /// [future-incompatible] lint to transition this to a hard error in the
1426 /// future. See [issue #35203] for more details.
1427 ///
1428 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1429 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1430 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1431 /// [future-incompatible]: ../index.md#future-incompatible-lints
1432pub PATTERNS_IN_FNS_WITHOUT_BODY,
1433 Deny,
1434"patterns in functions without body were erroneously allowed",
1435 @future_incompatible = FutureIncompatibleInfo {
1436 reason: fcw!(FutureReleaseError #35203),
1437 };
1438}14391440#[doc = r" The `late_bound_lifetime_arguments` lint detects generic lifetime"]
#[doc = r" arguments in path segments with late bound lifetime parameters."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" struct S;"]
#[doc = r""]
#[doc = r" impl S {"]
#[doc = r" fn late(self, _: &u8, _: &u8) {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" S.late::<'static>(&0, &0);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" It is not clear how to provide arguments for early-bound lifetime"]
#[doc =
r" parameters if they are intermixed with late-bound parameters in the"]
#[doc =
r" same list. For now, providing any explicit arguments will trigger this"]
#[doc =
r" lint if late-bound parameters are present, so in the future a solution"]
#[doc =
r" can be adopted without hitting backward compatibility issues. This is"]
#[doc =
r" a [future-incompatible] lint to transition this to a hard error in the"]
#[doc =
r" future. See [issue #42868] for more details, along with a description"]
#[doc = r" of the difference between early and late-bound parameters."]
#[doc = r""]
#[doc = r" [issue #42868]: https://github.com/rust-lang/rust/issues/42868"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static LATE_BOUND_LIFETIME_ARGUMENTS: &crate::Lint =
&crate::Lint {
name: "LATE_BOUND_LIFETIME_ARGUMENTS",
default_level: crate::Warn,
desc: "detects generic lifetime arguments in path segments with late bound lifetime parameters",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 42868,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1441/// The `late_bound_lifetime_arguments` lint detects generic lifetime
1442 /// arguments in path segments with late bound lifetime parameters.
1443 ///
1444 /// ### Example
1445 ///
1446 /// ```rust
1447 /// struct S;
1448 ///
1449 /// impl S {
1450 /// fn late(self, _: &u8, _: &u8) {}
1451 /// }
1452 ///
1453 /// fn main() {
1454 /// S.late::<'static>(&0, &0);
1455 /// }
1456 /// ```
1457 ///
1458 /// {{produces}}
1459 ///
1460 /// ### Explanation
1461 ///
1462 /// It is not clear how to provide arguments for early-bound lifetime
1463 /// parameters if they are intermixed with late-bound parameters in the
1464 /// same list. For now, providing any explicit arguments will trigger this
1465 /// lint if late-bound parameters are present, so in the future a solution
1466 /// can be adopted without hitting backward compatibility issues. This is
1467 /// a [future-incompatible] lint to transition this to a hard error in the
1468 /// future. See [issue #42868] for more details, along with a description
1469 /// of the difference between early and late-bound parameters.
1470 ///
1471 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1472 /// [future-incompatible]: ../index.md#future-incompatible-lints
1473pub LATE_BOUND_LIFETIME_ARGUMENTS,
1474 Warn,
1475"detects generic lifetime arguments in path segments with late bound lifetime parameters",
1476 @future_incompatible = FutureIncompatibleInfo {
1477 reason: fcw!(FutureReleaseError #42868),
1478 };
1479}14801481#[doc =
r" The `coherence_leak_check` lint detects conflicting implementations of"]
#[doc = r" a trait that are only distinguished by the old leak-check code."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait SomeTrait { }"]
#[doc = r" impl SomeTrait for for<'a> fn(&'a u8) { }"]
#[doc = r" impl<'a> SomeTrait for fn(&'a u8) { }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In the past, the compiler would accept trait implementations for"]
#[doc =
r" identical functions that differed only in where the lifetime binder"]
#[doc =
r" appeared. Due to a change in the borrow checker implementation to fix"]
#[doc =
r" several bugs, this is no longer allowed. However, since this affects"]
#[doc =
r" existing code, this is a [future-incompatible] lint to transition this"]
#[doc = r" to a hard error in the future."]
#[doc = r""]
#[doc = r#" Code relying on this pattern should introduce "[newtypes]","#]
#[doc = r" like `struct Foo(for<'a> fn(&'a u8))`."]
#[doc = r""]
#[doc = r" See [issue #56105] for more details."]
#[doc = r""]
#[doc = r" [issue #56105]: https://github.com/rust-lang/rust/issues/56105"]
#[doc =
r" [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static COHERENCE_LEAK_CHECK: &crate::Lint =
&crate::Lint {
name: "COHERENCE_LEAK_CHECK",
default_level: crate::Warn,
desc: "distinct impls distinguished only by the leak-check code",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::Custom("the behavior may change in a future release",
crate::ReleaseFcw { issue_number: 56105 }),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1482/// The `coherence_leak_check` lint detects conflicting implementations of
1483 /// a trait that are only distinguished by the old leak-check code.
1484 ///
1485 /// ### Example
1486 ///
1487 /// ```rust
1488 /// trait SomeTrait { }
1489 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1490 /// impl<'a> SomeTrait for fn(&'a u8) { }
1491 /// ```
1492 ///
1493 /// {{produces}}
1494 ///
1495 /// ### Explanation
1496 ///
1497 /// In the past, the compiler would accept trait implementations for
1498 /// identical functions that differed only in where the lifetime binder
1499 /// appeared. Due to a change in the borrow checker implementation to fix
1500 /// several bugs, this is no longer allowed. However, since this affects
1501 /// existing code, this is a [future-incompatible] lint to transition this
1502 /// to a hard error in the future.
1503 ///
1504 /// Code relying on this pattern should introduce "[newtypes]",
1505 /// like `struct Foo(for<'a> fn(&'a u8))`.
1506 ///
1507 /// See [issue #56105] for more details.
1508 ///
1509 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1510 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1511 /// [future-incompatible]: ../index.md#future-incompatible-lints
1512pub COHERENCE_LEAK_CHECK,
1513 Warn,
1514"distinct impls distinguished only by the leak-check code",
1515 @future_incompatible = FutureIncompatibleInfo {
1516 reason: fcw!("the behavior may change in a future release" #56105),
1517 };
1518}15191520#[doc = r" The `deprecated` lint detects use of deprecated items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[deprecated]"]
#[doc = r" fn foo() {}"]
#[doc = r""]
#[doc = r" fn bar() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Items may be marked "deprecated" with the [`deprecated` attribute] to"#]
#[doc =
r" indicate that they should no longer be used. Usually the attribute"]
#[doc = r" should include a note on what to use instead, or check the"]
#[doc = r" documentation."]
#[doc = r""]
#[doc =
r" [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"]
pub static DEPRECATED: &crate::Lint =
&crate::Lint {
name: "DEPRECATED",
default_level: crate::Warn,
desc: "detects use of deprecated items",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1521/// The `deprecated` lint detects use of deprecated items.
1522 ///
1523 /// ### Example
1524 ///
1525 /// ```rust
1526 /// #[deprecated]
1527 /// fn foo() {}
1528 ///
1529 /// fn bar() {
1530 /// foo();
1531 /// }
1532 /// ```
1533 ///
1534 /// {{produces}}
1535 ///
1536 /// ### Explanation
1537 ///
1538 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1539 /// indicate that they should no longer be used. Usually the attribute
1540 /// should include a note on what to use instead, or check the
1541 /// documentation.
1542 ///
1543 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1544pub DEPRECATED,
1545 Warn,
1546"detects use of deprecated items",
1547 report_in_external_macro
1548}15491550#[doc =
r" The `unused_unsafe` lint detects unnecessary use of an `unsafe` block."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" unsafe {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" If nothing within the block requires `unsafe`, then remove the"]
#[doc =
r" `unsafe` marker because it is not required and may cause confusion."]
pub static UNUSED_UNSAFE: &crate::Lint =
&crate::Lint {
name: "UNUSED_UNSAFE",
default_level: crate::Warn,
desc: "unnecessary use of an `unsafe` block",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1551/// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1552 ///
1553 /// ### Example
1554 ///
1555 /// ```rust
1556 /// unsafe {}
1557 /// ```
1558 ///
1559 /// {{produces}}
1560 ///
1561 /// ### Explanation
1562 ///
1563 /// If nothing within the block requires `unsafe`, then remove the
1564 /// `unsafe` marker because it is not required and may cause confusion.
1565pub UNUSED_UNSAFE,
1566 Warn,
1567"unnecessary use of an `unsafe` block"
1568}15691570#[doc =
r" The `unused_mut` lint detects mut variables which don't need to be"]
#[doc = r" mutable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let mut x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The preferred style is to only mark variables as `mut` if it is"]
#[doc = r" required."]
pub static UNUSED_MUT: &crate::Lint =
&crate::Lint {
name: "UNUSED_MUT",
default_level: crate::Warn,
desc: "detect mut variables which don't need to be mutable",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1571/// The `unused_mut` lint detects mut variables which don't need to be
1572 /// mutable.
1573 ///
1574 /// ### Example
1575 ///
1576 /// ```rust
1577 /// let mut x = 5;
1578 /// ```
1579 ///
1580 /// {{produces}}
1581 ///
1582 /// ### Explanation
1583 ///
1584 /// The preferred style is to only mark variables as `mut` if it is
1585 /// required.
1586pub UNUSED_MUT,
1587 Warn,
1588"detect mut variables which don't need to be mutable"
1589}15901591#[doc = r" The `rust_2024_incompatible_pat` lint"]
#[doc =
r" detects patterns whose meaning will change in the Rust 2024 edition."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(rust_2024_incompatible_pat)]"]
#[doc = r""]
#[doc = r" if let Some(&a) = &Some(&0u8) {"]
#[doc = r" let _: u8 = a;"]
#[doc = r" }"]
#[doc = r" if let Some(mut _a) = &mut Some(0u8) {"]
#[doc = r" _a = 7u8;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,"]
#[doc =
r" and nor do `&` or `&mut` patterns. The lint will suggest code that"]
#[doc = r" has the same meaning in all editions."]
pub static RUST_2024_INCOMPATIBLE_PAT: &crate::Lint =
&crate::Lint {
name: "RUST_2024_INCOMPATIBLE_PAT",
default_level: crate::Allow,
desc: "detects patterns whose meaning will change in Rust 2024",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "match-ergonomics",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1592/// The `rust_2024_incompatible_pat` lint
1593 /// detects patterns whose meaning will change in the Rust 2024 edition.
1594 ///
1595 /// ### Example
1596 ///
1597 /// ```rust,edition2021
1598 /// #![warn(rust_2024_incompatible_pat)]
1599 ///
1600 /// if let Some(&a) = &Some(&0u8) {
1601 /// let _: u8 = a;
1602 /// }
1603 /// if let Some(mut _a) = &mut Some(0u8) {
1604 /// _a = 7u8;
1605 /// }
1606 /// ```
1607 ///
1608 /// {{produces}}
1609 ///
1610 /// ### Explanation
1611 ///
1612 /// In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,
1613 /// and nor do `&` or `&mut` patterns. The lint will suggest code that
1614 /// has the same meaning in all editions.
1615pub RUST_2024_INCOMPATIBLE_PAT,
1616 Allow,
1617"detects patterns whose meaning will change in Rust 2024",
1618 @future_incompatible = FutureIncompatibleInfo {
1619 reason: fcw!(EditionSemanticsChange 2024 "match-ergonomics"),
1620 };
1621}16221623#[doc = r" The `unconditional_recursion` lint detects functions that cannot"]
#[doc = r" return without calling themselves."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to have a recursive call that does not have"]
#[doc =
r" some condition to cause it to terminate. If you really intend to have"]
#[doc = r" an infinite loop, using a `loop` expression is recommended."]
pub static UNCONDITIONAL_RECURSION: &crate::Lint =
&crate::Lint {
name: "UNCONDITIONAL_RECURSION",
default_level: crate::Warn,
desc: "functions that cannot return without calling themselves",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1624/// The `unconditional_recursion` lint detects functions that cannot
1625 /// return without calling themselves.
1626 ///
1627 /// ### Example
1628 ///
1629 /// ```rust
1630 /// fn foo() {
1631 /// foo();
1632 /// }
1633 /// ```
1634 ///
1635 /// {{produces}}
1636 ///
1637 /// ### Explanation
1638 ///
1639 /// It is usually a mistake to have a recursive call that does not have
1640 /// some condition to cause it to terminate. If you really intend to have
1641 /// an infinite loop, using a `loop` expression is recommended.
1642pub UNCONDITIONAL_RECURSION,
1643 Warn,
1644"functions that cannot return without calling themselves"
1645}16461647#[doc =
r" The `single_use_lifetimes` lint detects lifetimes that are only used"]
#[doc = r" once."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(single_use_lifetimes)]"]
#[doc = r""]
#[doc = r" fn foo<'a>(x: &'a u32) {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Specifying an explicit lifetime like `'a` in a function or `impl`"]
#[doc =
r" should only be used to link together two things. Otherwise, you should"]
#[doc =
r" just use `'_` to indicate that the lifetime is not linked to anything,"]
#[doc = r" or elide the lifetime altogether if possible."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it was introduced at a time"#]
#[doc =
r" when `'_` and elided lifetimes were first being introduced, and this"]
#[doc =
r" lint would be too noisy. Also, there are some known false positives"]
#[doc =
r" that it produces. See [RFC 2115] for historical context, and [issue"]
#[doc = r" #44752] for more details."]
#[doc = r""]
#[doc =
r" [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md"]
#[doc = r" [issue #44752]: https://github.com/rust-lang/rust/issues/44752"]
pub static SINGLE_USE_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "SINGLE_USE_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are only used once",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1648/// The `single_use_lifetimes` lint detects lifetimes that are only used
1649 /// once.
1650 ///
1651 /// ### Example
1652 ///
1653 /// ```rust,compile_fail
1654 /// #![deny(single_use_lifetimes)]
1655 ///
1656 /// fn foo<'a>(x: &'a u32) {}
1657 /// ```
1658 ///
1659 /// {{produces}}
1660 ///
1661 /// ### Explanation
1662 ///
1663 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1664 /// should only be used to link together two things. Otherwise, you should
1665 /// just use `'_` to indicate that the lifetime is not linked to anything,
1666 /// or elide the lifetime altogether if possible.
1667 ///
1668 /// This lint is "allow" by default because it was introduced at a time
1669 /// when `'_` and elided lifetimes were first being introduced, and this
1670 /// lint would be too noisy. Also, there are some known false positives
1671 /// that it produces. See [RFC 2115] for historical context, and [issue
1672 /// #44752] for more details.
1673 ///
1674 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1675 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1676pub SINGLE_USE_LIFETIMES,
1677 Allow,
1678"detects lifetime parameters that are only used once"
1679}16801681#[doc =
r" The `unused_lifetimes` lint detects lifetime parameters that are never"]
#[doc = r" used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[deny(unused_lifetimes)]"]
#[doc = r""]
#[doc = r" pub fn foo<'a>() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused lifetime parameters may signal a mistake or unfinished code."]
#[doc = r" Consider removing the parameter."]
pub static UNUSED_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "UNUSED_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1682/// The `unused_lifetimes` lint detects lifetime parameters that are never
1683 /// used.
1684 ///
1685 /// ### Example
1686 ///
1687 /// ```rust,compile_fail
1688 /// #[deny(unused_lifetimes)]
1689 ///
1690 /// pub fn foo<'a>() {}
1691 /// ```
1692 ///
1693 /// {{produces}}
1694 ///
1695 /// ### Explanation
1696 ///
1697 /// Unused lifetime parameters may signal a mistake or unfinished code.
1698 /// Consider removing the parameter.
1699pub UNUSED_LIFETIMES,
1700 Allow,
1701"detects lifetime parameters that are never used"
1702}17031704#[doc =
r" The `redundant_lifetimes` lint detects lifetime parameters that are"]
#[doc = r" redundant because they are equal to another named lifetime."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[deny(redundant_lifetimes)]"]
#[doc = r""]
#[doc =
r" // `'a = 'static`, so all usages of `'a` can be replaced with `'static`"]
#[doc = r" pub fn bar<'a: 'static>() {}"]
#[doc = r""]
#[doc = r" // `'a = 'b`, so all usages of `'b` can be replaced with `'a`"]
#[doc = r" pub fn bar<'a: 'b, 'b: 'a>() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused lifetime parameters may signal a mistake or unfinished code."]
#[doc = r" Consider removing the parameter."]
pub static REDUNDANT_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "REDUNDANT_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are redundant because they are equal to some other named lifetime",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1705/// The `redundant_lifetimes` lint detects lifetime parameters that are
1706 /// redundant because they are equal to another named lifetime.
1707 ///
1708 /// ### Example
1709 ///
1710 /// ```rust,compile_fail
1711 /// #[deny(redundant_lifetimes)]
1712 ///
1713 /// // `'a = 'static`, so all usages of `'a` can be replaced with `'static`
1714 /// pub fn bar<'a: 'static>() {}
1715 ///
1716 /// // `'a = 'b`, so all usages of `'b` can be replaced with `'a`
1717 /// pub fn bar<'a: 'b, 'b: 'a>() {}
1718 /// ```
1719 ///
1720 /// {{produces}}
1721 ///
1722 /// ### Explanation
1723 ///
1724 /// Unused lifetime parameters may signal a mistake or unfinished code.
1725 /// Consider removing the parameter.
1726pub REDUNDANT_LIFETIMES,
1727 Allow,
1728"detects lifetime parameters that are redundant because they are equal to some other named lifetime"
1729}17301731#[doc = r" The `tyvar_behind_raw_pointer` lint detects raw pointer to an"]
#[doc = r" inference variable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2015"]
#[doc = r" // edition 2015"]
#[doc = r" let data = std::ptr::null();"]
#[doc = r" let _ = &data as *const *const ();"]
#[doc = r""]
#[doc = r" if data.is_null() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This kind of inference was previously allowed, but with the future"]
#[doc =
r" arrival of [arbitrary self types], this can introduce ambiguity. To"]
#[doc = r" resolve this, use an explicit type instead of relying on type"]
#[doc = r" inference."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc =
r" error in the 2018 edition. See [issue #46906] for more details. This"]
#[doc = r#" is currently a hard-error on the 2018 edition, and is "warn" by"#]
#[doc = r" default in the 2015 edition."]
#[doc = r""]
#[doc =
r" [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874"]
#[doc = r" [issue #46906]: https://github.com/rust-lang/rust/issues/46906"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static TYVAR_BEHIND_RAW_POINTER: &crate::Lint =
&crate::Lint {
name: "TYVAR_BEHIND_RAW_POINTER",
default_level: crate::Warn,
desc: "raw pointer to an inference variable",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2018,
page_slug: "tyvar-behind-raw-pointer",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1732/// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1733 /// inference variable.
1734 ///
1735 /// ### Example
1736 ///
1737 /// ```rust,edition2015
1738 /// // edition 2015
1739 /// let data = std::ptr::null();
1740 /// let _ = &data as *const *const ();
1741 ///
1742 /// if data.is_null() {}
1743 /// ```
1744 ///
1745 /// {{produces}}
1746 ///
1747 /// ### Explanation
1748 ///
1749 /// This kind of inference was previously allowed, but with the future
1750 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1751 /// resolve this, use an explicit type instead of relying on type
1752 /// inference.
1753 ///
1754 /// This is a [future-incompatible] lint to transition this to a hard
1755 /// error in the 2018 edition. See [issue #46906] for more details. This
1756 /// is currently a hard-error on the 2018 edition, and is "warn" by
1757 /// default in the 2015 edition.
1758 ///
1759 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1760 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1761 /// [future-incompatible]: ../index.md#future-incompatible-lints
1762pub TYVAR_BEHIND_RAW_POINTER,
1763 Warn,
1764"raw pointer to an inference variable",
1765 @future_incompatible = FutureIncompatibleInfo {
1766 reason: fcw!(EditionError 2018 "tyvar-behind-raw-pointer"),
1767 };
1768}17691770#[doc = r" The `elided_lifetimes_in_paths` lint detects the use of hidden"]
#[doc = r" lifetime parameters."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(elided_lifetimes_in_paths)]"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" struct Foo<'a> {"]
#[doc = r" x: &'a u32"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn foo(x: &Foo) {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Elided lifetime parameters can make it difficult to see at a glance"]
#[doc = r" that borrowing is occurring. This lint ensures that lifetime"]
#[doc = r" parameters are always explicitly stated, even if it is the `'_`"]
#[doc = r" [placeholder lifetime]."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it has some known issues, and"#]
#[doc = r" may require a significant transition for old code."]
#[doc = r""]
#[doc =
r" [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions"]
pub static ELIDED_LIFETIMES_IN_PATHS: &crate::Lint =
&crate::Lint {
name: "ELIDED_LIFETIMES_IN_PATHS",
default_level: crate::Allow,
desc: "hidden lifetime parameters in types are deprecated",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1771/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1772 /// lifetime parameters.
1773 ///
1774 /// ### Example
1775 ///
1776 /// ```rust,compile_fail
1777 /// #![deny(elided_lifetimes_in_paths)]
1778 /// #![deny(warnings)]
1779 /// struct Foo<'a> {
1780 /// x: &'a u32
1781 /// }
1782 ///
1783 /// fn foo(x: &Foo) {
1784 /// }
1785 /// ```
1786 ///
1787 /// {{produces}}
1788 ///
1789 /// ### Explanation
1790 ///
1791 /// Elided lifetime parameters can make it difficult to see at a glance
1792 /// that borrowing is occurring. This lint ensures that lifetime
1793 /// parameters are always explicitly stated, even if it is the `'_`
1794 /// [placeholder lifetime].
1795 ///
1796 /// This lint is "allow" by default because it has some known issues, and
1797 /// may require a significant transition for old code.
1798 ///
1799 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1800pub ELIDED_LIFETIMES_IN_PATHS,
1801 Allow,
1802"hidden lifetime parameters in types are deprecated"
1803}18041805#[doc =
r" The `bare_trait_objects` lint suggests using `dyn Trait` for trait"]
#[doc = r" objects."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018"]
#[doc = r" trait Trait { }"]
#[doc = r""]
#[doc = r" fn takes_trait_object(_: Box<Trait>) {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Without the `dyn` indicator, it can be ambiguous or confusing when"]
#[doc =
r" reading code as to whether or not you are looking at a trait object."]
#[doc =
r" The `dyn` keyword makes it explicit, and adds a symmetry to contrast"]
#[doc = r" with [`impl Trait`]."]
#[doc = r""]
#[doc =
r" [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters"]
pub static BARE_TRAIT_OBJECTS: &crate::Lint =
&crate::Lint {
name: "BARE_TRAIT_OBJECTS",
default_level: crate::Warn,
desc: "suggest using `dyn Trait` for trait objects",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "warnings-promoted-to-error",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1806/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1807 /// objects.
1808 ///
1809 /// ### Example
1810 ///
1811 /// ```rust,edition2018
1812 /// trait Trait { }
1813 ///
1814 /// fn takes_trait_object(_: Box<Trait>) {
1815 /// }
1816 /// ```
1817 ///
1818 /// {{produces}}
1819 ///
1820 /// ### Explanation
1821 ///
1822 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1823 /// reading code as to whether or not you are looking at a trait object.
1824 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1825 /// with [`impl Trait`].
1826 ///
1827 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1828pub BARE_TRAIT_OBJECTS,
1829 Warn,
1830"suggest using `dyn Trait` for trait objects",
1831 @future_incompatible = FutureIncompatibleInfo {
1832 reason: fcw!(EditionError 2021 "warnings-promoted-to-error"),
1833 };
1834}18351836#[doc = r" The `absolute_paths_not_starting_with_crate` lint detects fully"]
#[doc = r" qualified paths that start with a module name instead of `crate`,"]
#[doc = r" `self`, or an extern crate name"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2015,compile_fail"]
#[doc = r" #![deny(absolute_paths_not_starting_with_crate)]"]
#[doc = r""]
#[doc = r" mod foo {"]
#[doc = r" pub fn bar() {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" ::foo::bar();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Rust [editions] allow the language to evolve without breaking"]
#[doc =
r" backwards compatibility. This lint catches code that uses absolute"]
#[doc =
r" paths in the style of the 2015 edition. In the 2015 edition, absolute"]
#[doc =
r" paths (those starting with `::`) refer to either the crate root or an"]
#[doc =
r" external crate. In the 2018 edition it was changed so that they only"]
#[doc =
r" refer to external crates. The path prefix `crate::` should be used"]
#[doc = r" instead to reference items from the crate root."]
#[doc = r""]
#[doc = r" If you switch the compiler from the 2015 to 2018 edition without"]
#[doc =
r" updating the code, then it will fail to compile if the old style paths"]
#[doc = r" are used. You can manually change the paths to use the `crate::`"]
#[doc = r" prefix to transition to the 2018 edition."]
#[doc = r""]
#[doc =
r#" This lint solves the problem automatically. It is "allow" by default"#]
#[doc =
r" because the code is perfectly valid in the 2015 edition. The [`cargo"]
#[doc =
r#" fix`] tool with the `--edition` flag will switch this lint to "warn""#]
#[doc = r" and automatically apply the suggested fix from the compiler. This"]
#[doc =
r" provides a completely automated way to update old code to the 2018"]
#[doc = r" edition."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
#[doc =
r" [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html"]
pub static ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE: &crate::Lint =
&crate::Lint {
name: "ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE",
default_level: crate::Allow,
desc: "fully qualified paths that start with a module name \
instead of `crate`, `self`, or an extern crate name",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2018,
page_slug: "path-changes",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1837/// The `absolute_paths_not_starting_with_crate` lint detects fully
1838 /// qualified paths that start with a module name instead of `crate`,
1839 /// `self`, or an extern crate name
1840 ///
1841 /// ### Example
1842 ///
1843 /// ```rust,edition2015,compile_fail
1844 /// #![deny(absolute_paths_not_starting_with_crate)]
1845 ///
1846 /// mod foo {
1847 /// pub fn bar() {}
1848 /// }
1849 ///
1850 /// fn main() {
1851 /// ::foo::bar();
1852 /// }
1853 /// ```
1854 ///
1855 /// {{produces}}
1856 ///
1857 /// ### Explanation
1858 ///
1859 /// Rust [editions] allow the language to evolve without breaking
1860 /// backwards compatibility. This lint catches code that uses absolute
1861 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1862 /// paths (those starting with `::`) refer to either the crate root or an
1863 /// external crate. In the 2018 edition it was changed so that they only
1864 /// refer to external crates. The path prefix `crate::` should be used
1865 /// instead to reference items from the crate root.
1866 ///
1867 /// If you switch the compiler from the 2015 to 2018 edition without
1868 /// updating the code, then it will fail to compile if the old style paths
1869 /// are used. You can manually change the paths to use the `crate::`
1870 /// prefix to transition to the 2018 edition.
1871 ///
1872 /// This lint solves the problem automatically. It is "allow" by default
1873 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1874 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1875 /// and automatically apply the suggested fix from the compiler. This
1876 /// provides a completely automated way to update old code to the 2018
1877 /// edition.
1878 ///
1879 /// [editions]: https://doc.rust-lang.org/edition-guide/
1880 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1881pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1882 Allow,
1883"fully qualified paths that start with a module name \
1884 instead of `crate`, `self`, or an extern crate name",
1885 @future_incompatible = FutureIncompatibleInfo {
1886 reason: fcw!(EditionError 2018 "path-changes"),
1887 };
1888}18891890#[doc =
r" The `unstable_name_collisions` lint detects that you have used a name"]
#[doc = r" that the standard library plans to add in the future."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait MyIterator : Iterator {"]
#[doc =
r" // is_partitioned is an unstable method that already exists on the Iterator trait"]
#[doc = r" fn is_partitioned<P>(self, predicate: P) -> bool"]
#[doc = r" where"]
#[doc = r" Self: Sized,"]
#[doc = r" P: FnMut(Self::Item) -> bool,"]
#[doc = r" {true}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<T: ?Sized> MyIterator for T where T: Iterator { }"]
#[doc = r""]
#[doc = r" let x = vec![1, 2, 3];"]
#[doc = r" let _ = x.iter().is_partitioned(|_| true);"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When new methods are added to traits in the standard library, they are"]
#[doc =
r#" usually added in an "unstable" form which is only available on the"#]
#[doc = r" [nightly channel] with a [`feature` attribute]. If there is any"]
#[doc =
r" preexisting code which extends a trait to have a method with the same"]
#[doc =
r" name, then the names will collide. In the future, when the method is"]
#[doc =
r" stabilized, this will cause an error due to the ambiguity. This lint"]
#[doc =
r" is an early-warning to let you know that there may be a collision in"]
#[doc = r" the future. This can be avoided by adding type annotations to"]
#[doc = r" disambiguate which trait method you intend to call, such as"]
#[doc =
r" `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method."]
#[doc = r""]
#[doc =
r" [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html"]
#[doc =
r" [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/"]
pub static UNSTABLE_NAME_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "UNSTABLE_NAME_COLLISIONS",
default_level: crate::Warn,
desc: "detects name collision with an existing but unstable method",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::Custom("once this associated item is added to the standard library, \
the ambiguity may cause an error or change in behavior!",
crate::ReleaseFcw { issue_number: 48919 }),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1891/// The `unstable_name_collisions` lint detects that you have used a name
1892 /// that the standard library plans to add in the future.
1893 ///
1894 /// ### Example
1895 ///
1896 /// ```rust
1897 /// trait MyIterator : Iterator {
1898 /// // is_partitioned is an unstable method that already exists on the Iterator trait
1899 /// fn is_partitioned<P>(self, predicate: P) -> bool
1900 /// where
1901 /// Self: Sized,
1902 /// P: FnMut(Self::Item) -> bool,
1903 /// {true}
1904 /// }
1905 ///
1906 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1907 ///
1908 /// let x = vec![1, 2, 3];
1909 /// let _ = x.iter().is_partitioned(|_| true);
1910 /// ```
1911 ///
1912 /// {{produces}}
1913 ///
1914 /// ### Explanation
1915 ///
1916 /// When new methods are added to traits in the standard library, they are
1917 /// usually added in an "unstable" form which is only available on the
1918 /// [nightly channel] with a [`feature` attribute]. If there is any
1919 /// preexisting code which extends a trait to have a method with the same
1920 /// name, then the names will collide. In the future, when the method is
1921 /// stabilized, this will cause an error due to the ambiguity. This lint
1922 /// is an early-warning to let you know that there may be a collision in
1923 /// the future. This can be avoided by adding type annotations to
1924 /// disambiguate which trait method you intend to call, such as
1925 /// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
1926 ///
1927 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1928 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1929pub UNSTABLE_NAME_COLLISIONS,
1930 Warn,
1931"detects name collision with an existing but unstable method",
1932 @future_incompatible = FutureIncompatibleInfo {
1933 reason: fcw!(
1934"once this associated item is added to the standard library, \
1935 the ambiguity may cause an error or change in behavior!"
1936#48919
1937),
1938// Note: this item represents future incompatibility of all unstable functions in the
1939 // standard library, and thus should never be removed or changed to an error.
1940};
1941}19421943#[doc =
r" The `irrefutable_let_patterns` lint detects [irrefutable patterns]"]
#[doc = r" in [`if let`]s, [`while let`]s, and `if let` guards."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" if let _ = 123 {"]
#[doc = r#" println!("always runs!");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" There usually isn't a reason to have an irrefutable pattern in an"]
#[doc =
r" `if let` or `while let` statement, because the pattern will always match"]
#[doc =
r" successfully. A [`let`] or [`loop`] statement will suffice. However,"]
#[doc =
r" when generating code with a macro, forbidding irrefutable patterns"]
#[doc = r" would require awkward workarounds in situations where the macro"]
#[doc = r" doesn't know if the pattern is refutable or not. This lint allows"]
#[doc =
r" macros to accept this form, while alerting for a possibly incorrect"]
#[doc = r" use in normal code."]
#[doc = r""]
#[doc = r" See [RFC 2086] for more details."]
#[doc = r""]
#[doc =
r" [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability"]
#[doc =
r" [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions"]
#[doc =
r" [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops"]
#[doc =
r" [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements"]
#[doc =
r" [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops"]
#[doc =
r" [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md"]
pub static IRREFUTABLE_LET_PATTERNS: &crate::Lint =
&crate::Lint {
name: "IRREFUTABLE_LET_PATTERNS",
default_level: crate::Warn,
desc: "detects irrefutable patterns in `if let` and `while let` statements",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1944/// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
1945 /// in [`if let`]s, [`while let`]s, and `if let` guards.
1946 ///
1947 /// ### Example
1948 ///
1949 /// ```rust
1950 /// if let _ = 123 {
1951 /// println!("always runs!");
1952 /// }
1953 /// ```
1954 ///
1955 /// {{produces}}
1956 ///
1957 /// ### Explanation
1958 ///
1959 /// There usually isn't a reason to have an irrefutable pattern in an
1960 /// `if let` or `while let` statement, because the pattern will always match
1961 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1962 /// when generating code with a macro, forbidding irrefutable patterns
1963 /// would require awkward workarounds in situations where the macro
1964 /// doesn't know if the pattern is refutable or not. This lint allows
1965 /// macros to accept this form, while alerting for a possibly incorrect
1966 /// use in normal code.
1967 ///
1968 /// See [RFC 2086] for more details.
1969 ///
1970 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1971 /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1972 /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1973 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1974 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1975 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1976pub IRREFUTABLE_LET_PATTERNS,
1977 Warn,
1978"detects irrefutable patterns in `if let` and `while let` statements"
1979}19801981#[doc = r" The `unused_labels` lint detects [labels] that are never used."]
#[doc = r""]
#[doc =
r" [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r" 'unused_label: loop {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused labels may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for the individual label, prefix it with an underscore such as"]
#[doc = r" `'_my_label:`."]
pub static UNUSED_LABELS: &crate::Lint =
&crate::Lint {
name: "UNUSED_LABELS",
default_level: crate::Warn,
desc: "detects labels that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1982/// The `unused_labels` lint detects [labels] that are never used.
1983 ///
1984 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1985 ///
1986 /// ### Example
1987 ///
1988 /// ```rust,no_run
1989 /// 'unused_label: loop {}
1990 /// ```
1991 ///
1992 /// {{produces}}
1993 ///
1994 /// ### Explanation
1995 ///
1996 /// Unused labels may signal a mistake or unfinished code. To silence the
1997 /// warning for the individual label, prefix it with an underscore such as
1998 /// `'_my_label:`.
1999pub UNUSED_LABELS,
2000 Warn,
2001"detects labels that are never used"
2002}20032004#[doc =
r" The `proc_macro_derive_resolution_fallback` lint detects proc macro"]
#[doc = r" derives using inaccessible names from parent modules."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (proc-macro)"]
#[doc = r" // foo.rs"]
#[doc = r#" #![crate_type = "proc-macro"]"#]
#[doc = r""]
#[doc = r" extern crate proc_macro;"]
#[doc = r""]
#[doc = r" use proc_macro::*;"]
#[doc = r""]
#[doc = r" #[proc_macro_derive(Foo)]"]
#[doc = r" pub fn foo1(a: TokenStream) -> TokenStream {"]
#[doc = r" drop(a);"]
#[doc =
r#" "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" // bar.rs"]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate foo;"]
#[doc = r""]
#[doc = r" struct Something;"]
#[doc = r""]
#[doc = r" #[derive(Foo)]"]
#[doc = r" struct Another;"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: cannot find type `Something` in this scope"]
#[doc = r" --> src/main.rs:8:10"]
#[doc = r" |"]
#[doc = r" 8 | #[derive(Foo)]"]
#[doc =
r" | ^^^ names from parent modules are not accessible without an explicit import"]
#[doc = r" |"]
#[doc =
r" = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" If a proc-macro generates a module, the compiler unintentionally"]
#[doc = r" allowed items in that module to refer to items in the crate root"]
#[doc = r" without importing them. This is a [future-incompatible] lint to"]
#[doc =
r" transition this to a hard error in the future. See [issue #50504] for"]
#[doc = r" more details."]
#[doc = r""]
#[doc = r" [issue #50504]: https://github.com/rust-lang/rust/issues/50504"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PROC_MACRO_DERIVE_RESOLUTION_FALLBACK: &crate::Lint =
&crate::Lint {
name: "PROC_MACRO_DERIVE_RESOLUTION_FALLBACK",
default_level: crate::Deny,
desc: "detects proc macro derives using inaccessible names from parent modules",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 83583,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2005/// The `proc_macro_derive_resolution_fallback` lint detects proc macro
2006 /// derives using inaccessible names from parent modules.
2007 ///
2008 /// ### Example
2009 ///
2010 /// ```rust,ignore (proc-macro)
2011 /// // foo.rs
2012 /// #![crate_type = "proc-macro"]
2013 ///
2014 /// extern crate proc_macro;
2015 ///
2016 /// use proc_macro::*;
2017 ///
2018 /// #[proc_macro_derive(Foo)]
2019 /// pub fn foo1(a: TokenStream) -> TokenStream {
2020 /// drop(a);
2021 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2022 /// }
2023 /// ```
2024 ///
2025 /// ```rust,ignore (needs-dependency)
2026 /// // bar.rs
2027 /// #[macro_use]
2028 /// extern crate foo;
2029 ///
2030 /// struct Something;
2031 ///
2032 /// #[derive(Foo)]
2033 /// struct Another;
2034 ///
2035 /// fn main() {}
2036 /// ```
2037 ///
2038 /// This will produce:
2039 ///
2040 /// ```text
2041 /// warning: cannot find type `Something` in this scope
2042 /// --> src/main.rs:8:10
2043 /// |
2044 /// 8 | #[derive(Foo)]
2045 /// | ^^^ names from parent modules are not accessible without an explicit import
2046 /// |
2047 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2048 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2049 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2050 /// ```
2051 ///
2052 /// ### Explanation
2053 ///
2054 /// If a proc-macro generates a module, the compiler unintentionally
2055 /// allowed items in that module to refer to items in the crate root
2056 /// without importing them. This is a [future-incompatible] lint to
2057 /// transition this to a hard error in the future. See [issue #50504] for
2058 /// more details.
2059 ///
2060 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2061 /// [future-incompatible]: ../index.md#future-incompatible-lints
2062pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2063 Deny,
2064"detects proc macro derives using inaccessible names from parent modules",
2065 @future_incompatible = FutureIncompatibleInfo {
2066 reason: fcw!(FutureReleaseError #83583),
2067 report_in_deps: true,
2068 };
2069}20702071#[doc =
r" The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute]."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #![deny(macro_use_extern_crate)]"]
#[doc = r""]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate serde_json;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let _ = json!{{}};"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated"]
#[doc = r" --> src/main.rs:3:1"]
#[doc = r" |"]
#[doc = r" 3 | #[macro_use]"]
#[doc = r" | ^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = help: remove it and import macros at use sites with a `use` item instead"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> src/main.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![deny(macro_use_extern_crate)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The [`macro_use` attribute] on an [`extern crate`] item causes"]
#[doc =
r" macros in that external crate to be brought into the prelude of the"]
#[doc =
r" crate, making the macros in scope everywhere. As part of the efforts"]
#[doc =
r" to simplify handling of dependencies in the [2018 edition], the use of"]
#[doc =
r" `extern crate` is being phased out. To bring macros from extern crates"]
#[doc = r" into scope, it is recommended to use a [`use` import]."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because this is a stylistic choice"#]
#[doc =
r" that has not been settled, see [issue #52043] for more information."]
#[doc = r""]
#[doc =
r" [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute"]
#[doc =
r" [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html"]
#[doc = r" [issue #52043]: https://github.com/rust-lang/rust/issues/52043"]
pub static MACRO_USE_EXTERN_CRATE: &crate::Lint =
&crate::Lint {
name: "MACRO_USE_EXTERN_CRATE",
default_level: crate::Allow,
desc: "the `#[macro_use]` attribute is now deprecated in favor of using macros \
via the module system",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2072/// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
2073 ///
2074 /// ### Example
2075 ///
2076 /// ```rust,ignore (needs extern crate)
2077 /// #![deny(macro_use_extern_crate)]
2078 ///
2079 /// #[macro_use]
2080 /// extern crate serde_json;
2081 ///
2082 /// fn main() {
2083 /// let _ = json!{{}};
2084 /// }
2085 /// ```
2086 ///
2087 /// This will produce:
2088 ///
2089 /// ```text
2090 /// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
2091 /// --> src/main.rs:3:1
2092 /// |
2093 /// 3 | #[macro_use]
2094 /// | ^^^^^^^^^^^^
2095 /// |
2096 /// = help: remove it and import macros at use sites with a `use` item instead
2097 /// note: the lint level is defined here
2098 /// --> src/main.rs:1:9
2099 /// |
2100 /// 1 | #![deny(macro_use_extern_crate)]
2101 /// | ^^^^^^^^^^^^^^^^^^^^^^
2102 /// ```
2103 ///
2104 /// ### Explanation
2105 ///
2106 /// The [`macro_use` attribute] on an [`extern crate`] item causes
2107 /// macros in that external crate to be brought into the prelude of the
2108 /// crate, making the macros in scope everywhere. As part of the efforts
2109 /// to simplify handling of dependencies in the [2018 edition], the use of
2110 /// `extern crate` is being phased out. To bring macros from extern crates
2111 /// into scope, it is recommended to use a [`use` import].
2112 ///
2113 /// This lint is "allow" by default because this is a stylistic choice
2114 /// that has not been settled, see [issue #52043] for more information.
2115 ///
2116 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2117 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2118 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2119pub MACRO_USE_EXTERN_CRATE,
2120 Allow,
2121"the `#[macro_use]` attribute is now deprecated in favor of using macros \
2122 via the module system"
2123}21242125#[doc =
r" The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint"]
#[doc =
r" detects macro-expanded [`macro_export`] macros from the current crate"]
#[doc = r" that cannot be referred to by absolute paths."]
#[doc = r""]
#[doc =
r" [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" macro_rules! define_exported {"]
#[doc = r" () => {"]
#[doc = r" #[macro_export]"]
#[doc = r" macro_rules! exported {"]
#[doc = r" () => {};"]
#[doc = r" }"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" define_exported!();"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" crate::exported!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The intent is that all macros marked with the `#[macro_export]`"]
#[doc =
r" attribute are made available in the root of the crate. However, when a"]
#[doc =
r" `macro_rules!` definition is generated by another macro, the macro"]
#[doc = r" expansion is unable to uphold this rule. This is a"]
#[doc =
r" [future-incompatible] lint to transition this to a hard error in the"]
#[doc = r" future. See [issue #53495] for more details."]
#[doc = r""]
#[doc = r" [issue #53495]: https://github.com/rust-lang/rust/issues/53495"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS:
&crate::Lint =
&crate::Lint {
name: "MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS",
default_level: crate::Deny,
desc: "macro-expanded `macro_export` macros from the current crate \
cannot be referred to by absolute paths",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 52234,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2126/// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2127 /// detects macro-expanded [`macro_export`] macros from the current crate
2128 /// that cannot be referred to by absolute paths.
2129 ///
2130 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2131 ///
2132 /// ### Example
2133 ///
2134 /// ```rust,compile_fail
2135 /// macro_rules! define_exported {
2136 /// () => {
2137 /// #[macro_export]
2138 /// macro_rules! exported {
2139 /// () => {};
2140 /// }
2141 /// };
2142 /// }
2143 ///
2144 /// define_exported!();
2145 ///
2146 /// fn main() {
2147 /// crate::exported!();
2148 /// }
2149 /// ```
2150 ///
2151 /// {{produces}}
2152 ///
2153 /// ### Explanation
2154 ///
2155 /// The intent is that all macros marked with the `#[macro_export]`
2156 /// attribute are made available in the root of the crate. However, when a
2157 /// `macro_rules!` definition is generated by another macro, the macro
2158 /// expansion is unable to uphold this rule. This is a
2159 /// [future-incompatible] lint to transition this to a hard error in the
2160 /// future. See [issue #53495] for more details.
2161 ///
2162 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2163 /// [future-incompatible]: ../index.md#future-incompatible-lints
2164pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2165 Deny,
2166"macro-expanded `macro_export` macros from the current crate \
2167 cannot be referred to by absolute paths",
2168 @future_incompatible = FutureIncompatibleInfo {
2169 reason: fcw!(FutureReleaseError #52234),
2170 report_in_deps: true,
2171 };
2172 crate_level_only
2173}21742175#[doc = r" The `explicit_outlives_requirements` lint detects unnecessary"]
#[doc = r" lifetime bounds that can be inferred."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(explicit_outlives_requirements)]"]
#[doc = r" #![deny(warnings)]"]
#[doc = r""]
#[doc = r" struct SharedRef<'a, T>"]
#[doc = r" where"]
#[doc = r" T: 'a,"]
#[doc = r" {"]
#[doc = r" data: &'a T,"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" If a `struct` contains a reference, such as `&'a T`, the compiler"]
#[doc = r" requires that `T` outlives the lifetime `'a`. This historically"]
#[doc = r" required writing an explicit lifetime bound to indicate this"]
#[doc =
r" requirement. However, this can be overly explicit, causing clutter and"]
#[doc = r" unnecessary complexity. The language was changed to automatically"]
#[doc =
r" infer the bound if it is not specified. Specifically, if the struct"]
#[doc =
r" contains a reference, directly or indirectly, to `T` with lifetime"]
#[doc = r" `'x`, then it will infer that `T: 'x` is a requirement."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it can be noisy for existing"#]
#[doc =
r" code that already had these requirements. This is a stylistic choice,"]
#[doc =
r" as it is still valid to explicitly state the bound. It also has some"]
#[doc = r" false positives that can cause confusion."]
#[doc = r""]
#[doc = r" See [RFC 2093] for more details."]
#[doc = r""]
#[doc =
r" [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md"]
pub static EXPLICIT_OUTLIVES_REQUIREMENTS: &crate::Lint =
&crate::Lint {
name: "EXPLICIT_OUTLIVES_REQUIREMENTS",
default_level: crate::Allow,
desc: "outlives requirements can be inferred",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2176/// The `explicit_outlives_requirements` lint detects unnecessary
2177 /// lifetime bounds that can be inferred.
2178 ///
2179 /// ### Example
2180 ///
2181 /// ```rust,compile_fail
2182 /// # #![allow(unused)]
2183 /// #![deny(explicit_outlives_requirements)]
2184 /// #![deny(warnings)]
2185 ///
2186 /// struct SharedRef<'a, T>
2187 /// where
2188 /// T: 'a,
2189 /// {
2190 /// data: &'a T,
2191 /// }
2192 /// ```
2193 ///
2194 /// {{produces}}
2195 ///
2196 /// ### Explanation
2197 ///
2198 /// If a `struct` contains a reference, such as `&'a T`, the compiler
2199 /// requires that `T` outlives the lifetime `'a`. This historically
2200 /// required writing an explicit lifetime bound to indicate this
2201 /// requirement. However, this can be overly explicit, causing clutter and
2202 /// unnecessary complexity. The language was changed to automatically
2203 /// infer the bound if it is not specified. Specifically, if the struct
2204 /// contains a reference, directly or indirectly, to `T` with lifetime
2205 /// `'x`, then it will infer that `T: 'x` is a requirement.
2206 ///
2207 /// This lint is "allow" by default because it can be noisy for existing
2208 /// code that already had these requirements. This is a stylistic choice,
2209 /// as it is still valid to explicitly state the bound. It also has some
2210 /// false positives that can cause confusion.
2211 ///
2212 /// See [RFC 2093] for more details.
2213 ///
2214 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2215pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2216 Allow,
2217"outlives requirements can be inferred"
2218}22192220#[doc =
r" The `deprecated_in_future` lint is internal to rustc and should not be"]
#[doc = r" used by user code."]
#[doc = r""]
#[doc =
r" This lint is only enabled in the standard library. It works with the"]
#[doc =
r" use of `#[deprecated]` with a `since` field of a version in the future."]
#[doc =
r" This allows something to be marked as deprecated in a future version,"]
#[doc =
r" and then this lint will ensure that the item is no longer used in the"]
#[doc =
r" standard library. See the [stability documentation] for more details."]
#[doc = r""]
#[doc =
r" [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated"]
pub static DEPRECATED_IN_FUTURE: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_IN_FUTURE",
default_level: crate::Allow,
desc: "detects use of items that will be deprecated in a future version",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2221/// The `deprecated_in_future` lint is internal to rustc and should not be
2222 /// used by user code.
2223 ///
2224 /// This lint is only enabled in the standard library. It works with the
2225 /// use of `#[deprecated]` with a `since` field of a version in the future.
2226 /// This allows something to be marked as deprecated in a future version,
2227 /// and then this lint will ensure that the item is no longer used in the
2228 /// standard library. See the [stability documentation] for more details.
2229 ///
2230 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2231pub DEPRECATED_IN_FUTURE,
2232 Allow,
2233"detects use of items that will be deprecated in a future version",
2234 report_in_external_macro
2235}22362237#[doc = r" The `ambiguous_associated_items` lint detects ambiguity between"]
#[doc = r" [associated items] and [enum variants]."]
#[doc = r""]
#[doc =
r" [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html"]
#[doc =
r" [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" enum E {"]
#[doc = r" V"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" trait Tr {"]
#[doc = r" type V;"]
#[doc = r" fn foo() -> Self::V;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Tr for E {"]
#[doc = r" type V = u8;"]
#[doc =
r" // `Self::V` is ambiguous because it may refer to the associated type or"]
#[doc = r" // the enum variant."]
#[doc = r" fn foo() -> Self::V { 0 }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust did not allow accessing enum variants"]
#[doc =
r" through [type aliases]. When this ability was added (see [RFC 2338]), this"]
#[doc = r" introduced some situations where it can be ambiguous what a type"]
#[doc = r" was referring to."]
#[doc = r""]
#[doc =
r" To fix this ambiguity, you should use a [qualified path] to explicitly"]
#[doc = r" state which type to use. For example, in the above example the"]
#[doc = r" function can be written as `fn f() -> <Self as Tr>::V { 0 }` to"]
#[doc = r" specifically refer to the associated type."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc = r" error in the future. See [issue #57644] for more details."]
#[doc = r""]
#[doc = r" [issue #57644]: https://github.com/rust-lang/rust/issues/57644"]
#[doc =
r" [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases"]
#[doc =
r" [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md"]
#[doc =
r" [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_ASSOCIATED_ITEMS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_ASSOCIATED_ITEMS",
default_level: crate::Deny,
desc: "ambiguous associated items",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57644,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2238/// The `ambiguous_associated_items` lint detects ambiguity between
2239 /// [associated items] and [enum variants].
2240 ///
2241 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2242 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2243 ///
2244 /// ### Example
2245 ///
2246 /// ```rust,compile_fail
2247 /// enum E {
2248 /// V
2249 /// }
2250 ///
2251 /// trait Tr {
2252 /// type V;
2253 /// fn foo() -> Self::V;
2254 /// }
2255 ///
2256 /// impl Tr for E {
2257 /// type V = u8;
2258 /// // `Self::V` is ambiguous because it may refer to the associated type or
2259 /// // the enum variant.
2260 /// fn foo() -> Self::V { 0 }
2261 /// }
2262 /// ```
2263 ///
2264 /// {{produces}}
2265 ///
2266 /// ### Explanation
2267 ///
2268 /// Previous versions of Rust did not allow accessing enum variants
2269 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2270 /// introduced some situations where it can be ambiguous what a type
2271 /// was referring to.
2272 ///
2273 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2274 /// state which type to use. For example, in the above example the
2275 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2276 /// specifically refer to the associated type.
2277 ///
2278 /// This is a [future-incompatible] lint to transition this to a hard
2279 /// error in the future. See [issue #57644] for more details.
2280 ///
2281 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2282 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2283 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2284 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2285 /// [future-incompatible]: ../index.md#future-incompatible-lints
2286pub AMBIGUOUS_ASSOCIATED_ITEMS,
2287 Deny,
2288"ambiguous associated items",
2289 @future_incompatible = FutureIncompatibleInfo {
2290 reason: fcw!(FutureReleaseError #57644),
2291 };
2292}22932294#[doc =
r" The `soft_unstable` lint detects unstable features that were unintentionally allowed on"]
#[doc =
r" stable. This is a [future-incompatible] lint to transition this to a hard error in the"]
#[doc = r" future. See [issue #64266] for more details."]
#[doc = r""]
#[doc = r" [issue #64266]: https://github.com/rust-lang/rust/issues/64266"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static SOFT_UNSTABLE: &crate::Lint =
&crate::Lint {
name: "SOFT_UNSTABLE",
default_level: crate::Deny,
desc: "a feature gate that doesn't break dependent crates",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 64266,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2295/// The `soft_unstable` lint detects unstable features that were unintentionally allowed on
2296 /// stable. This is a [future-incompatible] lint to transition this to a hard error in the
2297 /// future. See [issue #64266] for more details.
2298 ///
2299 /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2300 /// [future-incompatible]: ../index.md#future-incompatible-lints
2301pub SOFT_UNSTABLE,
2302 Deny,
2303"a feature gate that doesn't break dependent crates",
2304 @future_incompatible = FutureIncompatibleInfo {
2305 reason: fcw!(FutureReleaseError #64266),
2306 report_in_deps: true,
2307 };
2308}23092310#[doc = r" The `inline_no_sanitize` lint detects incompatible use of"]
#[doc =
r#" [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize]."#]
#[doc = r""]
#[doc =
r" [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute"]
#[doc =
r" [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(sanitize)]"]
#[doc = r""]
#[doc = r" #[inline(always)]"]
#[doc = r#" #[sanitize(address = "off")]"#]
#[doc = r" fn x() {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" x()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The use of the [`#[inline(always)]`][inline] attribute prevents the"]
#[doc =
r#" the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working."#]
#[doc = r" Consider temporarily removing `inline` attribute."]
pub static INLINE_NO_SANITIZE: &crate::Lint =
&crate::Lint {
name: "INLINE_NO_SANITIZE",
default_level: crate::Warn,
desc: r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2311/// The `inline_no_sanitize` lint detects incompatible use of
2312 /// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
2313 ///
2314 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2315 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2316 ///
2317 /// ### Example
2318 ///
2319 /// ```rust
2320 /// #![feature(sanitize)]
2321 ///
2322 /// #[inline(always)]
2323 /// #[sanitize(address = "off")]
2324 /// fn x() {}
2325 ///
2326 /// fn main() {
2327 /// x()
2328 /// }
2329 /// ```
2330 ///
2331 /// {{produces}}
2332 ///
2333 /// ### Explanation
2334 ///
2335 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2336 /// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
2337 /// Consider temporarily removing `inline` attribute.
2338pub INLINE_NO_SANITIZE,
2339 Warn,
2340r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
2341}23422343#[doc = r" The `rtsan_nonblocking_async` lint detects incompatible use of"]
#[doc =
r#" [`#[sanitize(realtime = "nonblocking")]`][sanitize] on async functions."#]
#[doc = r""]
#[doc =
r" [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html"]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r" #![feature(sanitize)]"]
#[doc = r""]
#[doc = r#" #[sanitize(realtime = "nonblocking")]"#]
#[doc = r" async fn x() {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" x();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The sanitizer only considers the async function body nonblocking. The executor, which runs on"]
#[doc =
r" every `.await` point can run non-realtime code, without the sanitizer catching it."]
pub static RTSAN_NONBLOCKING_ASYNC: &crate::Lint =
&crate::Lint {
name: "RTSAN_NONBLOCKING_ASYNC",
default_level: crate::Warn,
desc: r#"detects incompatible uses of `#[sanitize(realtime = "nonblocking")]` on async functions"#,
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2344/// The `rtsan_nonblocking_async` lint detects incompatible use of
2345 /// [`#[sanitize(realtime = "nonblocking")]`][sanitize] on async functions.
2346 ///
2347 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2348 /// ### Example
2349 ///
2350 /// ```rust,no_run
2351 /// #![feature(sanitize)]
2352 ///
2353 /// #[sanitize(realtime = "nonblocking")]
2354 /// async fn x() {}
2355 ///
2356 /// fn main() {
2357 /// x();
2358 /// }
2359 /// ```
2360 ///
2361 /// {{produces}}
2362 ///
2363 /// ### Explanation
2364 ///
2365 /// The sanitizer only considers the async function body nonblocking. The executor, which runs on
2366 /// every `.await` point can run non-realtime code, without the sanitizer catching it.
2367pub RTSAN_NONBLOCKING_ASYNC,
2368 Warn,
2369r#"detects incompatible uses of `#[sanitize(realtime = "nonblocking")]` on async functions"#,
2370}23712372#[doc =
r" The `asm_sub_register` lint detects using only a subset of a register"]
#[doc = r" for inline asm inputs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (fails on non-x86_64)"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" use std::arch::asm;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" unsafe {"]
#[doc = r#" asm!("mov {0}, {0}", in(reg) 0i16);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: formatting may not be suitable for sub-register argument"]
#[doc = r" --> src/main.rs:7:19"]
#[doc = r" |"]
#[doc = r#" 7 | asm!("mov {0}, {0}", in(reg) 0i16);"#]
#[doc = r" | ^^^ ^^^ ---- for this argument"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(asm_sub_register)]` on by default"]
#[doc =
r" = help: use the `x` modifier to have the register formatted as `ax`"]
#[doc =
r" = help: or use the `r` modifier to keep the default formatting of `rax`"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Registers on some architectures can use different names to refer to a"]
#[doc =
r" subset of the register. By default, the compiler will use the name for"]
#[doc =
r" the full register size. To explicitly use a subset of the register,"]
#[doc = r" you can override the default by using a modifier on the template"]
#[doc =
r" string operand to specify when subregister to use. This lint is issued"]
#[doc = r" if you pass in a value with a smaller data type than the default"]
#[doc =
r" register size, to alert you of possibly using the incorrect width. To"]
#[doc = r" fix this, add the suggested modifier to the template, or cast the"]
#[doc = r" value to the correct size."]
#[doc = r""]
#[doc =
r" See [register template modifiers] in the reference for more details."]
#[doc = r""]
#[doc =
r" [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers"]
pub static ASM_SUB_REGISTER: &crate::Lint =
&crate::Lint {
name: "ASM_SUB_REGISTER",
default_level: crate::Warn,
desc: "using only a subset of a register for inline asm inputs",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2373/// The `asm_sub_register` lint detects using only a subset of a register
2374 /// for inline asm inputs.
2375 ///
2376 /// ### Example
2377 ///
2378 /// ```rust,ignore (fails on non-x86_64)
2379 /// #[cfg(target_arch="x86_64")]
2380 /// use std::arch::asm;
2381 ///
2382 /// fn main() {
2383 /// #[cfg(target_arch="x86_64")]
2384 /// unsafe {
2385 /// asm!("mov {0}, {0}", in(reg) 0i16);
2386 /// }
2387 /// }
2388 /// ```
2389 ///
2390 /// This will produce:
2391 ///
2392 /// ```text
2393 /// warning: formatting may not be suitable for sub-register argument
2394 /// --> src/main.rs:7:19
2395 /// |
2396 /// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
2397 /// | ^^^ ^^^ ---- for this argument
2398 /// |
2399 /// = note: `#[warn(asm_sub_register)]` on by default
2400 /// = help: use the `x` modifier to have the register formatted as `ax`
2401 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2402 /// ```
2403 ///
2404 /// ### Explanation
2405 ///
2406 /// Registers on some architectures can use different names to refer to a
2407 /// subset of the register. By default, the compiler will use the name for
2408 /// the full register size. To explicitly use a subset of the register,
2409 /// you can override the default by using a modifier on the template
2410 /// string operand to specify when subregister to use. This lint is issued
2411 /// if you pass in a value with a smaller data type than the default
2412 /// register size, to alert you of possibly using the incorrect width. To
2413 /// fix this, add the suggested modifier to the template, or cast the
2414 /// value to the correct size.
2415 ///
2416 /// See [register template modifiers] in the reference for more details.
2417 ///
2418 /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2419pub ASM_SUB_REGISTER,
2420 Warn,
2421"using only a subset of a register for inline asm inputs",
2422}24232424#[doc =
r" The `bad_asm_style` lint detects the use of the `.intel_syntax` and"]
#[doc = r" `.att_syntax` directives."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (fails on non-x86_64)"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" use std::arch::asm;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" unsafe {"]
#[doc = r" asm!("]
#[doc = r#" ".att_syntax","#]
#[doc = r#" "movq %{0}, %{0}", in(reg) 0usize"#]
#[doc = r" );"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead"]
#[doc = r" --> src/main.rs:8:14"]
#[doc = r" |"]
#[doc = r#" 8 | ".att_syntax","#]
#[doc = r" | ^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(bad_asm_style)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On x86, `asm!` uses the intel assembly syntax by default. While this"]
#[doc =
r" can be switched using assembler directives like `.att_syntax`, using the"]
#[doc =
r" `att_syntax` option is recommended instead because it will also properly"]
#[doc = r" prefix register placeholders with `%` as required by AT&T syntax."]
pub static BAD_ASM_STYLE: &crate::Lint =
&crate::Lint {
name: "BAD_ASM_STYLE",
default_level: crate::Warn,
desc: "incorrect use of inline assembly",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2425/// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2426 /// `.att_syntax` directives.
2427 ///
2428 /// ### Example
2429 ///
2430 /// ```rust,ignore (fails on non-x86_64)
2431 /// #[cfg(target_arch="x86_64")]
2432 /// use std::arch::asm;
2433 ///
2434 /// fn main() {
2435 /// #[cfg(target_arch="x86_64")]
2436 /// unsafe {
2437 /// asm!(
2438 /// ".att_syntax",
2439 /// "movq %{0}, %{0}", in(reg) 0usize
2440 /// );
2441 /// }
2442 /// }
2443 /// ```
2444 ///
2445 /// This will produce:
2446 ///
2447 /// ```text
2448 /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2449 /// --> src/main.rs:8:14
2450 /// |
2451 /// 8 | ".att_syntax",
2452 /// | ^^^^^^^^^^^
2453 /// |
2454 /// = note: `#[warn(bad_asm_style)]` on by default
2455 /// ```
2456 ///
2457 /// ### Explanation
2458 ///
2459 /// On x86, `asm!` uses the intel assembly syntax by default. While this
2460 /// can be switched using assembler directives like `.att_syntax`, using the
2461 /// `att_syntax` option is recommended instead because it will also properly
2462 /// prefix register placeholders with `%` as required by AT&T syntax.
2463pub BAD_ASM_STYLE,
2464 Warn,
2465"incorrect use of inline assembly",
2466}24672468#[doc =
r" The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe"]
#[doc = r" functions without an explicit unsafe block."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unsafe_op_in_unsafe_fn)]"]
#[doc = r""]
#[doc = r" unsafe fn foo() {}"]
#[doc = r""]
#[doc = r" unsafe fn bar() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Currently, an [`unsafe fn`] allows any [unsafe] operation within its"]
#[doc =
r" body. However, this can increase the surface area of code that needs"]
#[doc =
r" to be scrutinized for proper behavior. The [`unsafe` block] provides a"]
#[doc =
r" convenient way to make it clear exactly which parts of the code are"]
#[doc =
r" performing unsafe operations. In the future, it is desired to change"]
#[doc =
r" it so that unsafe operations cannot be performed in an `unsafe fn`"]
#[doc = r" without an `unsafe` block."]
#[doc = r""]
#[doc = r" The fix to this is to wrap the unsafe code in an `unsafe` block."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default on editions up to 2021, from 2024 it is"#]
#[doc = r#" "warn" by default; the plan for increasing severity further is"#]
#[doc =
r" still being considered. See [RFC #2585] and [issue #71668] for more"]
#[doc = r" details."]
#[doc = r""]
#[doc =
r" [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html"]
#[doc =
r" [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks"]
#[doc = r" [unsafe]: https://doc.rust-lang.org/reference/unsafety.html"]
#[doc =
r" [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md"]
#[doc = r" [issue #71668]: https://github.com/rust-lang/rust/issues/71668"]
pub static UNSAFE_OP_IN_UNSAFE_FN: &crate::Lint =
&crate::Lint {
name: "UNSAFE_OP_IN_UNSAFE_FN",
default_level: crate::Allow,
desc: "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-op-in-unsafe-fn",
}),
explain_reason: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
edition_lint_opts: Some((crate::Edition::Edition2024,
crate::Warn)),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2469/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2470 /// functions without an explicit unsafe block.
2471 ///
2472 /// ### Example
2473 ///
2474 /// ```rust,compile_fail
2475 /// #![deny(unsafe_op_in_unsafe_fn)]
2476 ///
2477 /// unsafe fn foo() {}
2478 ///
2479 /// unsafe fn bar() {
2480 /// foo();
2481 /// }
2482 ///
2483 /// fn main() {}
2484 /// ```
2485 ///
2486 /// {{produces}}
2487 ///
2488 /// ### Explanation
2489 ///
2490 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2491 /// body. However, this can increase the surface area of code that needs
2492 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2493 /// convenient way to make it clear exactly which parts of the code are
2494 /// performing unsafe operations. In the future, it is desired to change
2495 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2496 /// without an `unsafe` block.
2497 ///
2498 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2499 ///
2500 /// This lint is "allow" by default on editions up to 2021, from 2024 it is
2501 /// "warn" by default; the plan for increasing severity further is
2502 /// still being considered. See [RFC #2585] and [issue #71668] for more
2503 /// details.
2504 ///
2505 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2506 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2507 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2508 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2509 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2510pub UNSAFE_OP_IN_UNSAFE_FN,
2511 Allow,
2512"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2513 @future_incompatible = FutureIncompatibleInfo {
2514 reason: fcw!(EditionError 2024 "unsafe-op-in-unsafe-fn"),
2515 explain_reason: false
2516};
2517 @edition Edition2024 => Warn;
2518}25192520#[doc =
r" The `fuzzy_provenance_casts` lint detects an `as` cast between an integer"]
#[doc = r" and a pointer."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(strict_provenance_lints)]"]
#[doc = r" #![warn(fuzzy_provenance_casts)]"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let _dangling = 16_usize as *const u8;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is part of the strict provenance effort, see [issue #95228]."]
#[doc =
r" Casting an integer to a pointer is considered bad style, as a pointer"]
#[doc =
r" contains, besides the *address* also a *provenance*, indicating what"]
#[doc =
r" memory the pointer is allowed to read/write. Casting an integer, which"]
#[doc =
r" doesn't have provenance, to a pointer requires the compiler to assign"]
#[doc =
r#" (guess) provenance. The compiler assigns "all exposed valid" (see the"#]
#[doc =
r" docs of [`ptr::with_exposed_provenance`] for more information about this"]
#[doc =
r#" "exposing"). This penalizes the optimiser and is not well suited for"#]
#[doc = r" dynamic analysis/dynamic program verification (e.g. Miri or CHERI"]
#[doc = r" platforms)."]
#[doc = r""]
#[doc =
r" It is much better to use [`ptr::with_addr`] instead to specify the"]
#[doc =
r" provenance you want. If using this function is not possible because the"]
#[doc =
r" code relies on exposed provenance then there is as an escape hatch"]
#[doc = r" [`ptr::with_exposed_provenance`]."]
#[doc = r""]
#[doc = r" [issue #95228]: https://github.com/rust-lang/rust/issues/95228"]
#[doc =
r" [`ptr::with_addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.with_addr"]
#[doc =
r" [`ptr::with_exposed_provenance`]: https://doc.rust-lang.org/core/ptr/fn.with_exposed_provenance.html"]
pub static FUZZY_PROVENANCE_CASTS: &crate::Lint =
&crate::Lint {
name: "FUZZY_PROVENANCE_CASTS",
default_level: crate::Allow,
desc: "a fuzzy integer to pointer cast is used",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::strict_provenance_lints),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2521/// The `fuzzy_provenance_casts` lint detects an `as` cast between an integer
2522 /// and a pointer.
2523 ///
2524 /// ### Example
2525 ///
2526 /// ```rust
2527 /// #![feature(strict_provenance_lints)]
2528 /// #![warn(fuzzy_provenance_casts)]
2529 ///
2530 /// fn main() {
2531 /// let _dangling = 16_usize as *const u8;
2532 /// }
2533 /// ```
2534 ///
2535 /// {{produces}}
2536 ///
2537 /// ### Explanation
2538 ///
2539 /// This lint is part of the strict provenance effort, see [issue #95228].
2540 /// Casting an integer to a pointer is considered bad style, as a pointer
2541 /// contains, besides the *address* also a *provenance*, indicating what
2542 /// memory the pointer is allowed to read/write. Casting an integer, which
2543 /// doesn't have provenance, to a pointer requires the compiler to assign
2544 /// (guess) provenance. The compiler assigns "all exposed valid" (see the
2545 /// docs of [`ptr::with_exposed_provenance`] for more information about this
2546 /// "exposing"). This penalizes the optimiser and is not well suited for
2547 /// dynamic analysis/dynamic program verification (e.g. Miri or CHERI
2548 /// platforms).
2549 ///
2550 /// It is much better to use [`ptr::with_addr`] instead to specify the
2551 /// provenance you want. If using this function is not possible because the
2552 /// code relies on exposed provenance then there is as an escape hatch
2553 /// [`ptr::with_exposed_provenance`].
2554 ///
2555 /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2556 /// [`ptr::with_addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.with_addr
2557 /// [`ptr::with_exposed_provenance`]: https://doc.rust-lang.org/core/ptr/fn.with_exposed_provenance.html
2558pub FUZZY_PROVENANCE_CASTS,
2559 Allow,
2560"a fuzzy integer to pointer cast is used",
2561 @feature_gate = strict_provenance_lints;
2562}25632564#[doc =
r" The `lossy_provenance_casts` lint detects an `as` cast between a pointer"]
#[doc = r" and an integer."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(strict_provenance_lints)]"]
#[doc = r" #![warn(lossy_provenance_casts)]"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let x: u8 = 37;"]
#[doc = r" let _addr: usize = &x as *const u8 as usize;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is part of the strict provenance effort, see [issue #95228]."]
#[doc =
r" Casting a pointer to an integer is a lossy operation, because beyond"]
#[doc = r" just an *address* a pointer may be associated with a particular"]
#[doc =
r" *provenance*. This information is used by the optimiser and for dynamic"]
#[doc =
r" analysis/dynamic program verification (e.g. Miri or CHERI platforms)."]
#[doc = r""]
#[doc = r" Since this cast is lossy, it is considered good style to use the"]
#[doc =
r" [`ptr::addr`] method instead, which has a similar effect, but doesn't"]
#[doc =
r#" "expose" the pointer provenance. This improves optimisation potential."#]
#[doc =
r" See the docs of [`ptr::addr`] and [`ptr::expose_provenance`] for more information"]
#[doc = r" about exposing pointer provenance."]
#[doc = r""]
#[doc =
r" If your code can't comply with strict provenance and needs to expose"]
#[doc =
r" the provenance, then there is [`ptr::expose_provenance`] as an escape hatch,"]
#[doc =
r" which preserves the behaviour of `as usize` casts while being explicit"]
#[doc = r" about the semantics."]
#[doc = r""]
#[doc = r" [issue #95228]: https://github.com/rust-lang/rust/issues/95228"]
#[doc =
r" [`ptr::addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.addr"]
#[doc =
r" [`ptr::expose_provenance`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.expose_provenance"]
pub static LOSSY_PROVENANCE_CASTS: &crate::Lint =
&crate::Lint {
name: "LOSSY_PROVENANCE_CASTS",
default_level: crate::Allow,
desc: "a lossy pointer to integer cast is used",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::strict_provenance_lints),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2565/// The `lossy_provenance_casts` lint detects an `as` cast between a pointer
2566 /// and an integer.
2567 ///
2568 /// ### Example
2569 ///
2570 /// ```rust
2571 /// #![feature(strict_provenance_lints)]
2572 /// #![warn(lossy_provenance_casts)]
2573 ///
2574 /// fn main() {
2575 /// let x: u8 = 37;
2576 /// let _addr: usize = &x as *const u8 as usize;
2577 /// }
2578 /// ```
2579 ///
2580 /// {{produces}}
2581 ///
2582 /// ### Explanation
2583 ///
2584 /// This lint is part of the strict provenance effort, see [issue #95228].
2585 /// Casting a pointer to an integer is a lossy operation, because beyond
2586 /// just an *address* a pointer may be associated with a particular
2587 /// *provenance*. This information is used by the optimiser and for dynamic
2588 /// analysis/dynamic program verification (e.g. Miri or CHERI platforms).
2589 ///
2590 /// Since this cast is lossy, it is considered good style to use the
2591 /// [`ptr::addr`] method instead, which has a similar effect, but doesn't
2592 /// "expose" the pointer provenance. This improves optimisation potential.
2593 /// See the docs of [`ptr::addr`] and [`ptr::expose_provenance`] for more information
2594 /// about exposing pointer provenance.
2595 ///
2596 /// If your code can't comply with strict provenance and needs to expose
2597 /// the provenance, then there is [`ptr::expose_provenance`] as an escape hatch,
2598 /// which preserves the behaviour of `as usize` casts while being explicit
2599 /// about the semantics.
2600 ///
2601 /// [issue #95228]: https://github.com/rust-lang/rust/issues/95228
2602 /// [`ptr::addr`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.addr
2603 /// [`ptr::expose_provenance`]: https://doc.rust-lang.org/core/primitive.pointer.html#method.expose_provenance
2604pub LOSSY_PROVENANCE_CASTS,
2605 Allow,
2606"a lossy pointer to integer cast is used",
2607 @feature_gate = strict_provenance_lints;
2608}26092610#[doc =
r" The `const_evaluatable_unchecked` lint detects a generic constant used"]
#[doc = r" in a type."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" const fn foo<T>() -> usize {"]
#[doc =
r" if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T"]
#[doc = r" 4"]
#[doc = r" } else {"]
#[doc = r" 8"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn test<T>() {"]
#[doc = r" let _ = [0; foo::<T>()];"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In the 1.43 release, some uses of generic parameters in array repeat"]
#[doc =
r" expressions were accidentally allowed. This is a [future-incompatible]"]
#[doc = r" lint to transition this to a hard error in the future. See [issue"]
#[doc = r" #76200] for a more detailed description and possible fixes."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
#[doc = r" [issue #76200]: https://github.com/rust-lang/rust/issues/76200"]
pub static CONST_EVALUATABLE_UNCHECKED: &crate::Lint =
&crate::Lint {
name: "CONST_EVALUATABLE_UNCHECKED",
default_level: crate::Warn,
desc: "detects a generic constant is used in a type without a emitting a warning",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 76200,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2611/// The `const_evaluatable_unchecked` lint detects a generic constant used
2612 /// in a type.
2613 ///
2614 /// ### Example
2615 ///
2616 /// ```rust
2617 /// const fn foo<T>() -> usize {
2618 /// if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2619 /// 4
2620 /// } else {
2621 /// 8
2622 /// }
2623 /// }
2624 ///
2625 /// fn test<T>() {
2626 /// let _ = [0; foo::<T>()];
2627 /// }
2628 /// ```
2629 ///
2630 /// {{produces}}
2631 ///
2632 /// ### Explanation
2633 ///
2634 /// In the 1.43 release, some uses of generic parameters in array repeat
2635 /// expressions were accidentally allowed. This is a [future-incompatible]
2636 /// lint to transition this to a hard error in the future. See [issue
2637 /// #76200] for a more detailed description and possible fixes.
2638 ///
2639 /// [future-incompatible]: ../index.md#future-incompatible-lints
2640 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2641pub CONST_EVALUATABLE_UNCHECKED,
2642 Warn,
2643"detects a generic constant is used in a type without a emitting a warning",
2644 @future_incompatible = FutureIncompatibleInfo {
2645 reason: fcw!(FutureReleaseError #76200),
2646 };
2647}26482649#[doc =
r" The `function_item_references` lint detects function references that are"]
#[doc = r" formatted with [`fmt::Pointer`] or transmuted."]
#[doc = r""]
#[doc =
r" [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() { }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" println!("{:p}", &foo);"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Taking a reference to a function may be mistaken as a way to obtain a"]
#[doc = r" pointer to that function. This can give unexpected results when"]
#[doc =
r" formatting the reference as a pointer or transmuting it. This lint is"]
#[doc =
r" issued when function references are formatted as pointers, passed as"]
#[doc = r" arguments bound by [`fmt::Pointer`] or transmuted."]
pub static FUNCTION_ITEM_REFERENCES: &crate::Lint =
&crate::Lint {
name: "FUNCTION_ITEM_REFERENCES",
default_level: crate::Warn,
desc: "suggest casting to a function pointer when attempting to take references to function items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2650/// The `function_item_references` lint detects function references that are
2651 /// formatted with [`fmt::Pointer`] or transmuted.
2652 ///
2653 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2654 ///
2655 /// ### Example
2656 ///
2657 /// ```rust
2658 /// fn foo() { }
2659 ///
2660 /// fn main() {
2661 /// println!("{:p}", &foo);
2662 /// }
2663 /// ```
2664 ///
2665 /// {{produces}}
2666 ///
2667 /// ### Explanation
2668 ///
2669 /// Taking a reference to a function may be mistaken as a way to obtain a
2670 /// pointer to that function. This can give unexpected results when
2671 /// formatting the reference as a pointer or transmuting it. This lint is
2672 /// issued when function references are formatted as pointers, passed as
2673 /// arguments bound by [`fmt::Pointer`] or transmuted.
2674pub FUNCTION_ITEM_REFERENCES,
2675 Warn,
2676"suggest casting to a function pointer when attempting to take references to function items",
2677}26782679#[doc = r" The `uninhabited_static` lint detects uninhabited statics."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" enum Void {}"]
#[doc = r" unsafe extern {"]
#[doc = r" static EXTERN: Void;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Statics with an uninhabited type can never be initialized, so they are impossible to define."]
#[doc =
r" However, this can be side-stepped with an `extern static`, leading to problems later in the"]
#[doc =
r" compiler which assumes that there are no initialized uninhabited places (such as locals or"]
#[doc = r" statics). This was accidentally allowed, but is being phased out."]
pub static UNINHABITED_STATIC: &crate::Lint =
&crate::Lint {
name: "UNINHABITED_STATIC",
default_level: crate::Warn,
desc: "uninhabited static",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 74840,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2680/// The `uninhabited_static` lint detects uninhabited statics.
2681 ///
2682 /// ### Example
2683 ///
2684 /// ```rust
2685 /// enum Void {}
2686 /// unsafe extern {
2687 /// static EXTERN: Void;
2688 /// }
2689 /// ```
2690 ///
2691 /// {{produces}}
2692 ///
2693 /// ### Explanation
2694 ///
2695 /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2696 /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2697 /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2698 /// statics). This was accidentally allowed, but is being phased out.
2699pub UNINHABITED_STATIC,
2700 Warn,
2701"uninhabited static",
2702 @future_incompatible = FutureIncompatibleInfo {
2703 reason: fcw!(FutureReleaseError #74840),
2704 };
2705}27062707#[doc =
r" The `unnameable_test_items` lint detects [`#[test]`][test] functions"]
#[doc =
r" that are not able to be run by the test harness because they are in a"]
#[doc = r" position where they are not nameable."]
#[doc = r""]
#[doc =
r" [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,test"]
#[doc = r" fn main() {"]
#[doc = r" #[test]"]
#[doc = r" fn foo() {"]
#[doc = r" // This test will not fail because it does not run."]
#[doc = r" assert_eq!(1, 2);"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In order for the test harness to run a test, the test function must be"]
#[doc =
r" located in a position where it can be accessed from the crate root."]
#[doc =
r" This generally means it must be defined in a module, and not anywhere"]
#[doc =
r" else such as inside another function. The compiler previously allowed"]
#[doc =
r" this without an error, so a lint was added as an alert that a test is"]
#[doc =
r" not being used. Whether or not this should be allowed has not yet been"]
#[doc = r" decided, see [RFC 2471] and [issue #36629]."]
#[doc = r""]
#[doc =
r" [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443"]
#[doc = r" [issue #36629]: https://github.com/rust-lang/rust/issues/36629"]
pub static UNNAMEABLE_TEST_ITEMS: &crate::Lint =
&crate::Lint {
name: "UNNAMEABLE_TEST_ITEMS",
default_level: crate::Warn,
desc: "detects an item that cannot be named being marked as `#[test_case]`",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2708/// The `unnameable_test_items` lint detects [`#[test]`][test] functions
2709 /// that are not able to be run by the test harness because they are in a
2710 /// position where they are not nameable.
2711 ///
2712 /// [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute
2713 ///
2714 /// ### Example
2715 ///
2716 /// ```rust,test
2717 /// fn main() {
2718 /// #[test]
2719 /// fn foo() {
2720 /// // This test will not fail because it does not run.
2721 /// assert_eq!(1, 2);
2722 /// }
2723 /// }
2724 /// ```
2725 ///
2726 /// {{produces}}
2727 ///
2728 /// ### Explanation
2729 ///
2730 /// In order for the test harness to run a test, the test function must be
2731 /// located in a position where it can be accessed from the crate root.
2732 /// This generally means it must be defined in a module, and not anywhere
2733 /// else such as inside another function. The compiler previously allowed
2734 /// this without an error, so a lint was added as an alert that a test is
2735 /// not being used. Whether or not this should be allowed has not yet been
2736 /// decided, see [RFC 2471] and [issue #36629].
2737 ///
2738 /// [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443
2739 /// [issue #36629]: https://github.com/rust-lang/rust/issues/36629
2740pub UNNAMEABLE_TEST_ITEMS,
2741 Warn,
2742"detects an item that cannot be named being marked as `#[test_case]`",
2743 report_in_external_macro
2744}27452746#[doc =
r" The `useless_deprecated` lint detects deprecation attributes with no effect."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" struct X;"]
#[doc = r""]
#[doc = r#" #[deprecated = "message"]"#]
#[doc = r" impl Default for X {"]
#[doc = r" fn default() -> Self {"]
#[doc = r" X"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Deprecation attributes have no effect on trait implementations."]
pub static USELESS_DEPRECATED: &crate::Lint =
&crate::Lint {
name: "USELESS_DEPRECATED",
default_level: crate::Deny,
desc: "detects deprecation attributes with no effect",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2747/// The `useless_deprecated` lint detects deprecation attributes with no effect.
2748 ///
2749 /// ### Example
2750 ///
2751 /// ```rust,compile_fail
2752 /// struct X;
2753 ///
2754 /// #[deprecated = "message"]
2755 /// impl Default for X {
2756 /// fn default() -> Self {
2757 /// X
2758 /// }
2759 /// }
2760 /// ```
2761 ///
2762 /// {{produces}}
2763 ///
2764 /// ### Explanation
2765 ///
2766 /// Deprecation attributes have no effect on trait implementations.
2767pub USELESS_DEPRECATED,
2768 Deny,
2769"detects deprecation attributes with no effect",
2770}27712772#[doc =
r" The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(staged_api)]"]
#[doc = r""]
#[doc = r" #[derive(Clone)]"]
#[doc = r#" #[stable(feature = "x", since = "1")]"#]
#[doc = r" struct S {}"]
#[doc = r""]
#[doc = r#" #[unstable(feature = "y", issue = "none")]"#]
#[doc = r" impl Copy for S {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" `staged_api` does not currently support using a stability attribute on `impl` blocks."]
#[doc =
r" `impl`s are always stable if both the type and trait are stable, and always unstable otherwise."]
pub static INEFFECTIVE_UNSTABLE_TRAIT_IMPL: &crate::Lint =
&crate::Lint {
name: "INEFFECTIVE_UNSTABLE_TRAIT_IMPL",
default_level: crate::Deny,
desc: "detects `#[unstable]` on stable trait implementations for stable types",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2773/// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2774 ///
2775 /// ### Example
2776 ///
2777 /// ```rust,compile_fail
2778 /// #![feature(staged_api)]
2779 ///
2780 /// #[derive(Clone)]
2781 /// #[stable(feature = "x", since = "1")]
2782 /// struct S {}
2783 ///
2784 /// #[unstable(feature = "y", issue = "none")]
2785 /// impl Copy for S {}
2786 /// ```
2787 ///
2788 /// {{produces}}
2789 ///
2790 /// ### Explanation
2791 ///
2792 /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2793 /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2794pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2795 Deny,
2796"detects `#[unstable]` on stable trait implementations for stable types"
2797}27982799#[doc =
r" The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor"]
#[doc =
r" was silently allowed due to a bug in the resolver, and which may produce surprising"]
#[doc = r" and unintended behavior."]
#[doc = r""]
#[doc =
r" Using a `Self` type alias from an outer item was never intended, but was silently allowed."]
#[doc =
r" This is deprecated -- and is a hard error when the `Self` type alias references generics"]
#[doc = r" that are not in scope."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(self_constructor_from_outer_item)]"]
#[doc = r""]
#[doc = r" struct S0(usize);"]
#[doc = r""]
#[doc = r" impl S0 {"]
#[doc = r" fn foo() {"]
#[doc = r" const C: S0 = Self(0);"]
#[doc = r" fn bar() -> S0 {"]
#[doc = r" Self(0)"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `Self` type alias should not be reachable because nested items are not associated with"]
#[doc = r" the scope of the parameters from the parent item."]
pub static SELF_CONSTRUCTOR_FROM_OUTER_ITEM: &crate::Lint =
&crate::Lint {
name: "SELF_CONSTRUCTOR_FROM_OUTER_ITEM",
default_level: crate::Warn,
desc: "detect unsupported use of `Self` from outer item",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124186,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2800/// The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor
2801 /// was silently allowed due to a bug in the resolver, and which may produce surprising
2802 /// and unintended behavior.
2803 ///
2804 /// Using a `Self` type alias from an outer item was never intended, but was silently allowed.
2805 /// This is deprecated -- and is a hard error when the `Self` type alias references generics
2806 /// that are not in scope.
2807 ///
2808 /// ### Example
2809 ///
2810 /// ```rust,compile_fail
2811 /// #![deny(self_constructor_from_outer_item)]
2812 ///
2813 /// struct S0(usize);
2814 ///
2815 /// impl S0 {
2816 /// fn foo() {
2817 /// const C: S0 = Self(0);
2818 /// fn bar() -> S0 {
2819 /// Self(0)
2820 /// }
2821 /// }
2822 /// }
2823 /// ```
2824 ///
2825 /// {{produces}}
2826 ///
2827 /// ### Explanation
2828 ///
2829 /// The `Self` type alias should not be reachable because nested items are not associated with
2830 /// the scope of the parameters from the parent item.
2831pub SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
2832 Warn,
2833"detect unsupported use of `Self` from outer item",
2834 @future_incompatible = FutureIncompatibleInfo {
2835 reason: fcw!(FutureReleaseError #124186),
2836 };
2837}28382839#[doc =
r" The `semicolon_in_expressions_from_macros` lint detects trailing semicolons"]
#[doc = r" in macro bodies when the macro is invoked in expression position."]
#[doc = r" This was previous accepted, but is being phased out."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(semicolon_in_expressions_from_macros)]"]
#[doc = r" macro_rules! foo {"]
#[doc = r" () => { true; }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let val = match true {"]
#[doc = r" true => false,"]
#[doc = r" _ => foo!()"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous, Rust ignored trailing semicolon in a macro"]
#[doc = r" body when a macro was invoked in expression position."]
#[doc = r" However, this makes the treatment of semicolons in the language"]
#[doc = r" inconsistent, and could lead to unexpected runtime behavior"]
#[doc = r" in some circumstances (e.g. if the macro author expects"]
#[doc = r" a value to be dropped)."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #79813] for more details."]
#[doc = r""]
#[doc = r" [issue #79813]: https://github.com/rust-lang/rust/issues/79813"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static SEMICOLON_IN_EXPRESSIONS_FROM_MACROS: &crate::Lint =
&crate::Lint {
name: "SEMICOLON_IN_EXPRESSIONS_FROM_MACROS",
default_level: crate::Deny,
desc: "trailing semicolon in macro body used as expression",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 79813,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2840/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2841 /// in macro bodies when the macro is invoked in expression position.
2842 /// This was previous accepted, but is being phased out.
2843 ///
2844 /// ### Example
2845 ///
2846 /// ```rust,compile_fail
2847 /// #![deny(semicolon_in_expressions_from_macros)]
2848 /// macro_rules! foo {
2849 /// () => { true; }
2850 /// }
2851 ///
2852 /// fn main() {
2853 /// let val = match true {
2854 /// true => false,
2855 /// _ => foo!()
2856 /// };
2857 /// }
2858 /// ```
2859 ///
2860 /// {{produces}}
2861 ///
2862 /// ### Explanation
2863 ///
2864 /// Previous, Rust ignored trailing semicolon in a macro
2865 /// body when a macro was invoked in expression position.
2866 /// However, this makes the treatment of semicolons in the language
2867 /// inconsistent, and could lead to unexpected runtime behavior
2868 /// in some circumstances (e.g. if the macro author expects
2869 /// a value to be dropped).
2870 ///
2871 /// This is a [future-incompatible] lint to transition this
2872 /// to a hard error in the future. See [issue #79813] for more details.
2873 ///
2874 /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2875 /// [future-incompatible]: ../index.md#future-incompatible-lints
2876pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2877 Deny,
2878"trailing semicolon in macro body used as expression",
2879 @future_incompatible = FutureIncompatibleInfo {
2880 reason: fcw!(FutureReleaseError #79813),
2881 report_in_deps: true,
2882 };
2883}28842885#[doc = r" The `legacy_derive_helpers` lint detects derive helper attributes"]
#[doc = r" that are used before they are introduced."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r#" #[serde(rename_all = "camelCase")]"#]
#[doc = r" #[derive(Deserialize)]"]
#[doc = r" struct S { /* fields */ }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: derive helper attribute is used before it is introduced"]
#[doc = r" --> $DIR/legacy-derive-helpers.rs:1:3"]
#[doc = r" |"]
#[doc = r#" 1 | #[serde(rename_all = "camelCase")]"#]
#[doc = r" | ^^^^^"]
#[doc = r" ..."]
#[doc = r" 2 | #[derive(Deserialize)]"]
#[doc = r" | ----------- the attribute is introduced here"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Attributes like this work for historical reasons, but attribute expansion works in"]
#[doc =
r#" left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look"#]
#[doc =
r#" into the future" at not yet expanded part of the item , but such attempts are not always"#]
#[doc = r" reliable."]
#[doc = r""]
#[doc =
r" To fix the warning place the helper attribute after its corresponding derive."]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #[derive(Deserialize)]"]
#[doc = r#" #[serde(rename_all = "camelCase")]"#]
#[doc = r" struct S { /* fields */ }"]
#[doc = r" ```"]
pub static LEGACY_DERIVE_HELPERS: &crate::Lint =
&crate::Lint {
name: "LEGACY_DERIVE_HELPERS",
default_level: crate::Deny,
desc: "detects derive helper attributes that are used before they are introduced",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 79202,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2886/// The `legacy_derive_helpers` lint detects derive helper attributes
2887 /// that are used before they are introduced.
2888 ///
2889 /// ### Example
2890 ///
2891 /// ```rust,ignore (needs extern crate)
2892 /// #[serde(rename_all = "camelCase")]
2893 /// #[derive(Deserialize)]
2894 /// struct S { /* fields */ }
2895 /// ```
2896 ///
2897 /// produces:
2898 ///
2899 /// ```text
2900 /// warning: derive helper attribute is used before it is introduced
2901 /// --> $DIR/legacy-derive-helpers.rs:1:3
2902 /// |
2903 /// 1 | #[serde(rename_all = "camelCase")]
2904 /// | ^^^^^
2905 /// ...
2906 /// 2 | #[derive(Deserialize)]
2907 /// | ----------- the attribute is introduced here
2908 /// ```
2909 ///
2910 /// ### Explanation
2911 ///
2912 /// Attributes like this work for historical reasons, but attribute expansion works in
2913 /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2914 /// into the future" at not yet expanded part of the item , but such attempts are not always
2915 /// reliable.
2916 ///
2917 /// To fix the warning place the helper attribute after its corresponding derive.
2918 /// ```rust,ignore (needs extern crate)
2919 /// #[derive(Deserialize)]
2920 /// #[serde(rename_all = "camelCase")]
2921 /// struct S { /* fields */ }
2922 /// ```
2923pub LEGACY_DERIVE_HELPERS,
2924 Deny,
2925"detects derive helper attributes that are used before they are introduced",
2926 @future_incompatible = FutureIncompatibleInfo {
2927 reason: fcw!(FutureReleaseError #79202),
2928 report_in_deps: true,
2929 };
2930}29312932#[doc = r" The `large_assignments` lint detects when objects of large"]
#[doc = r" types are being moved around."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (can crash on some platforms)"]
#[doc = r" let x = [0; 50000];"]
#[doc = r" let y = x;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: moving a large value"]
#[doc = r" --> $DIR/move-large.rs:1:3"]
#[doc = r" let y = x;"]
#[doc = r" - Copied large value here"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" When using a large type in a plain assignment or in a function"]
#[doc = r" argument, idiomatic code can be inefficient."]
#[doc = r" Ideally appropriate optimizations would resolve this, but such"]
#[doc = r" optimizations are only done in a best-effort manner."]
#[doc =
r" This lint will trigger on all sites of large moves and thus allow the"]
#[doc = r" user to resolve them in code."]
pub static LARGE_ASSIGNMENTS: &crate::Lint =
&crate::Lint {
name: "LARGE_ASSIGNMENTS",
default_level: crate::Warn,
desc: "detects large moves or copies",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2933/// The `large_assignments` lint detects when objects of large
2934 /// types are being moved around.
2935 ///
2936 /// ### Example
2937 ///
2938 /// ```rust,ignore (can crash on some platforms)
2939 /// let x = [0; 50000];
2940 /// let y = x;
2941 /// ```
2942 ///
2943 /// produces:
2944 ///
2945 /// ```text
2946 /// warning: moving a large value
2947 /// --> $DIR/move-large.rs:1:3
2948 /// let y = x;
2949 /// - Copied large value here
2950 /// ```
2951 ///
2952 /// ### Explanation
2953 ///
2954 /// When using a large type in a plain assignment or in a function
2955 /// argument, idiomatic code can be inefficient.
2956 /// Ideally appropriate optimizations would resolve this, but such
2957 /// optimizations are only done in a best-effort manner.
2958 /// This lint will trigger on all sites of large moves and thus allow the
2959 /// user to resolve them in code.
2960pub LARGE_ASSIGNMENTS,
2961 Warn,
2962"detects large moves or copies",
2963}29642965#[doc =
r" The `unexpected_cfgs` lint detects unexpected conditional compilation conditions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" rustc --check-cfg 'cfg()'"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs command line option)"]
#[doc = r" #[cfg(widnows)]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: unexpected `cfg` condition name: `widnows`"]
#[doc = r" --> lint_example.rs:1:7"]
#[doc = r" |"]
#[doc = r" 1 | #[cfg(widnows)]"]
#[doc = r" | ^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(unexpected_cfgs)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is only active when [`--check-cfg`][check-cfg] arguments are being"]
#[doc =
r" passed to the compiler and triggers whenever an unexpected condition name or value is"]
#[doc = r" used."]
#[doc = r""]
#[doc =
r" See the [Checking Conditional Configurations][check-cfg] section for more"]
#[doc = r" details."]
#[doc = r""]
#[doc =
r" See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in"]
#[doc = r" `Cargo.toml`."]
#[doc = r""]
#[doc =
r" [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html"]
#[doc =
r" [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table"]
pub static UNEXPECTED_CFGS: &crate::Lint =
&crate::Lint {
name: "UNEXPECTED_CFGS",
default_level: crate::Warn,
desc: "detects unexpected names and values in `#[cfg]` conditions",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2966/// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
2967 ///
2968 /// ### Example
2969 ///
2970 /// ```text
2971 /// rustc --check-cfg 'cfg()'
2972 /// ```
2973 ///
2974 /// ```rust,ignore (needs command line option)
2975 /// #[cfg(widnows)]
2976 /// fn foo() {}
2977 /// ```
2978 ///
2979 /// This will produce:
2980 ///
2981 /// ```text
2982 /// warning: unexpected `cfg` condition name: `widnows`
2983 /// --> lint_example.rs:1:7
2984 /// |
2985 /// 1 | #[cfg(widnows)]
2986 /// | ^^^^^^^
2987 /// |
2988 /// = note: `#[warn(unexpected_cfgs)]` on by default
2989 /// ```
2990 ///
2991 /// ### Explanation
2992 ///
2993 /// This lint is only active when [`--check-cfg`][check-cfg] arguments are being
2994 /// passed to the compiler and triggers whenever an unexpected condition name or value is
2995 /// used.
2996 ///
2997 /// See the [Checking Conditional Configurations][check-cfg] section for more
2998 /// details.
2999 ///
3000 /// See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in
3001 /// `Cargo.toml`.
3002 ///
3003 /// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
3004 /// [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table
3005pub UNEXPECTED_CFGS,
3006 Warn,
3007"detects unexpected names and values in `#[cfg]` conditions",
3008 report_in_external_macro
3009}30103011#[doc =
r" The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" rustc --cfg unix"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs command line option)"]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: unexpected `--cfg unix` flag"]
#[doc = r" |"]
#[doc =
r" = note: config `unix` is only supposed to be controlled by `--target`"]
#[doc =
r" = note: manually setting a built-in cfg can and does create incoherent behaviors"]
#[doc = r" = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Setting builtin cfgs can and does produce incoherent behavior, it's better to the use"]
#[doc =
r" the appropriate `rustc` flag that controls the config. For example setting the `windows`"]
#[doc = r" cfg but on Linux based target."]
pub static EXPLICIT_BUILTIN_CFGS_IN_FLAGS: &crate::Lint =
&crate::Lint {
name: "EXPLICIT_BUILTIN_CFGS_IN_FLAGS",
default_level: crate::Deny,
desc: "detects builtin cfgs set via the `--cfg`",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3012/// The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.
3013 ///
3014 /// ### Example
3015 ///
3016 /// ```text
3017 /// rustc --cfg unix
3018 /// ```
3019 ///
3020 /// ```rust,ignore (needs command line option)
3021 /// fn main() {}
3022 /// ```
3023 ///
3024 /// This will produce:
3025 ///
3026 /// ```text
3027 /// error: unexpected `--cfg unix` flag
3028 /// |
3029 /// = note: config `unix` is only supposed to be controlled by `--target`
3030 /// = note: manually setting a built-in cfg can and does create incoherent behaviors
3031 /// = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
3032 /// ```
3033 ///
3034 /// ### Explanation
3035 ///
3036 /// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
3037 /// the appropriate `rustc` flag that controls the config. For example setting the `windows`
3038 /// cfg but on Linux based target.
3039pub EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
3040 Deny,
3041"detects builtin cfgs set via the `--cfg`"
3042}30433044#[doc = r" The `repr_transparent_non_zst_fields` lint"]
#[doc = r" detects types marked `#[repr(transparent)]` that (transitively)"]
#[doc =
r" contain a type that is not guaranteed to remain a ZST type under all configurations."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs external crate)"]
#[doc = r" #![deny(repr_transparent_external_private_fields)]"]
#[doc = r" use foo::NonExhaustiveZst;"]
#[doc = r""]
#[doc = r" #[repr(C)]"]
#[doc = r" struct CZst([u8; 0]);"]
#[doc = r""]
#[doc = r" #[repr(transparent)]"]
#[doc = r" struct Bar(u32, ([u32; 0], NonExhaustiveZst));"]
#[doc = r" #[repr(transparent)]"]
#[doc = r" struct Baz(u32, CZst);"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types"]
#[doc = r" --> src/main.rs:5:28"]
#[doc = r" |"]
#[doc = r" 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));"]
#[doc = r" | ^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> src/main.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![deny(repr_transparent_external_private_fields)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>"]
#[doc =
r" = note: this field contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, so it could become non-zero-sized in the future."]
#[doc = r""]
#[doc =
r" error: zero-sized fields in repr(transparent) cannot contain `#[repr(C)]` types"]
#[doc = r" --> src/main.rs:5:28"]
#[doc = r" |"]
#[doc = r" 5 | struct Baz(u32, CZst);"]
#[doc = r" | ^^^^"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>"]
#[doc =
r" = note: this field contains `CZst`, which is a `#[repr(C)]` type, so it is not guaranteed to be zero-sized on all targets."]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Previous, Rust accepted fields that contain external private zero-sized types, even though"]
#[doc =
r" those types could gain a non-zero-sized field in a future, semver-compatible update."]
#[doc = r""]
#[doc =
r" Rust also accepted fields that contain `repr(C)` zero-sized types, even though those types"]
#[doc =
r" are not guaranteed to be zero-sized on all targets, and even though those types can"]
#[doc =
r" make a difference for the ABI (and therefore cannot be ignored by `repr(transparent)`)."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #78586] for more details."]
#[doc = r""]
#[doc = r" [issue #78586]: https://github.com/rust-lang/rust/issues/78586"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static REPR_TRANSPARENT_NON_ZST_FIELDS: &crate::Lint =
&crate::Lint {
name: "REPR_TRANSPARENT_NON_ZST_FIELDS",
default_level: crate::Deny,
desc: "transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 78586,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3045/// The `repr_transparent_non_zst_fields` lint
3046 /// detects types marked `#[repr(transparent)]` that (transitively)
3047 /// contain a type that is not guaranteed to remain a ZST type under all configurations.
3048 ///
3049 /// ### Example
3050 ///
3051 /// ```rust,ignore (needs external crate)
3052 /// #![deny(repr_transparent_external_private_fields)]
3053 /// use foo::NonExhaustiveZst;
3054 ///
3055 /// #[repr(C)]
3056 /// struct CZst([u8; 0]);
3057 ///
3058 /// #[repr(transparent)]
3059 /// struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3060 /// #[repr(transparent)]
3061 /// struct Baz(u32, CZst);
3062 /// ```
3063 ///
3064 /// This will produce:
3065 ///
3066 /// ```text
3067 /// error: zero-sized fields in repr(transparent) cannot contain external non-exhaustive types
3068 /// --> src/main.rs:5:28
3069 /// |
3070 /// 5 | struct Bar(u32, ([u32; 0], NonExhaustiveZst));
3071 /// | ^^^^^^^^^^^^^^^^
3072 /// |
3073 /// note: the lint level is defined here
3074 /// --> src/main.rs:1:9
3075 /// |
3076 /// 1 | #![deny(repr_transparent_external_private_fields)]
3077 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3078 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3079 /// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3080 /// = note: this field contains `NonExhaustiveZst`, which is marked with `#[non_exhaustive]`, so it could become non-zero-sized in the future.
3081 ///
3082 /// error: zero-sized fields in repr(transparent) cannot contain `#[repr(C)]` types
3083 /// --> src/main.rs:5:28
3084 /// |
3085 /// 5 | struct Baz(u32, CZst);
3086 /// | ^^^^
3087 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3088 /// = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
3089 /// = note: this field contains `CZst`, which is a `#[repr(C)]` type, so it is not guaranteed to be zero-sized on all targets.
3090 /// ```
3091 ///
3092 /// ### Explanation
3093 ///
3094 /// Previous, Rust accepted fields that contain external private zero-sized types, even though
3095 /// those types could gain a non-zero-sized field in a future, semver-compatible update.
3096 ///
3097 /// Rust also accepted fields that contain `repr(C)` zero-sized types, even though those types
3098 /// are not guaranteed to be zero-sized on all targets, and even though those types can
3099 /// make a difference for the ABI (and therefore cannot be ignored by `repr(transparent)`).
3100 ///
3101 /// This is a [future-incompatible] lint to transition this
3102 /// to a hard error in the future. See [issue #78586] for more details.
3103 ///
3104 /// [issue #78586]: https://github.com/rust-lang/rust/issues/78586
3105 /// [future-incompatible]: ../index.md#future-incompatible-lints
3106pub REPR_TRANSPARENT_NON_ZST_FIELDS,
3107 Deny,
3108"transparent type contains an external ZST that is marked #[non_exhaustive] or contains private fields",
3109 @future_incompatible = FutureIncompatibleInfo {
3110 reason: fcw!(FutureReleaseError #78586),
3111 report_in_deps: true,
3112 };
3113}31143115#[doc =
r" The `unstable_syntax_pre_expansion` lint detects the use of unstable"]
#[doc = r" syntax that is discarded during attribute expansion."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[cfg(FALSE)]"]
#[doc = r" macro foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The input to active attributes such as `#[cfg]` or procedural macro"]
#[doc =
r" attributes is required to be valid syntax. Previously, the compiler only"]
#[doc =
r" gated the use of unstable syntax features after resolving `#[cfg]` gates"]
#[doc = r" and expanding procedural macros."]
#[doc = r""]
#[doc =
r" To avoid relying on unstable syntax, move the use of unstable syntax"]
#[doc =
r" into a position where the compiler does not parse the syntax, such as a"]
#[doc = r" functionlike macro."]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" # #![deny(unstable_syntax_pre_expansion)]"]
#[doc = r""]
#[doc = r" macro_rules! identity {"]
#[doc = r" ( $($tokens:tt)* ) => { $($tokens)* }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[cfg(FALSE)]"]
#[doc = r" identity! {"]
#[doc = r" macro foo() {}"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #65860] for more details."]
#[doc = r""]
#[doc = r" [issue #65860]: https://github.com/rust-lang/rust/issues/65860"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static UNSTABLE_SYNTAX_PRE_EXPANSION: &crate::Lint =
&crate::Lint {
name: "UNSTABLE_SYNTAX_PRE_EXPANSION",
default_level: crate::Warn,
desc: "unstable syntax can change at any point in the future, causing a hard error!",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 65860,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3116/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3117 /// syntax that is discarded during attribute expansion.
3118 ///
3119 /// ### Example
3120 ///
3121 /// ```rust
3122 /// #[cfg(FALSE)]
3123 /// macro foo() {}
3124 /// ```
3125 ///
3126 /// {{produces}}
3127 ///
3128 /// ### Explanation
3129 ///
3130 /// The input to active attributes such as `#[cfg]` or procedural macro
3131 /// attributes is required to be valid syntax. Previously, the compiler only
3132 /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3133 /// and expanding procedural macros.
3134 ///
3135 /// To avoid relying on unstable syntax, move the use of unstable syntax
3136 /// into a position where the compiler does not parse the syntax, such as a
3137 /// functionlike macro.
3138 ///
3139 /// ```rust
3140 /// # #![deny(unstable_syntax_pre_expansion)]
3141 ///
3142 /// macro_rules! identity {
3143 /// ( $($tokens:tt)* ) => { $($tokens)* }
3144 /// }
3145 ///
3146 /// #[cfg(FALSE)]
3147 /// identity! {
3148 /// macro foo() {}
3149 /// }
3150 /// ```
3151 ///
3152 /// This is a [future-incompatible] lint to transition this
3153 /// to a hard error in the future. See [issue #65860] for more details.
3154 ///
3155 /// [issue #65860]: https://github.com/rust-lang/rust/issues/65860
3156 /// [future-incompatible]: ../index.md#future-incompatible-lints
3157pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3158 Warn,
3159"unstable syntax can change at any point in the future, causing a hard error!",
3160 @future_incompatible = FutureIncompatibleInfo {
3161 reason: fcw!(FutureReleaseError #65860),
3162 };
3163}31643165#[doc =
r" The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs"]
#[doc =
r" collide. Downstream users trying to use the same name re-exported from multiple globs"]
#[doc =
r" will receive a warning pointing out redefinition of the same name."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_glob_reexports)]"]
#[doc = r" pub mod foo {"]
#[doc = r" pub type X = u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub mod bar {"]
#[doc = r" pub type Y = u8;"]
#[doc = r" pub type X = u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub use foo::*;"]
#[doc = r" pub use bar::*;"]
#[doc = r""]
#[doc = r""]
#[doc = r" pub fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This was previously accepted but it could silently break a crate's downstream users code."]
#[doc =
r" For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the"]
#[doc =
r" re-exports, down stream users could use `this_crate::X` without problems. However, adding"]
#[doc =
r" `bar::X` would cause compilation errors in downstream crates because `X` is defined"]
#[doc = r" multiple times in the same namespace of `this_crate`."]
pub static AMBIGUOUS_GLOB_REEXPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_REEXPORTS",
default_level: crate::Warn,
desc: "ambiguous glob re-exports",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3166/// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
3167 /// collide. Downstream users trying to use the same name re-exported from multiple globs
3168 /// will receive a warning pointing out redefinition of the same name.
3169 ///
3170 /// ### Example
3171 ///
3172 /// ```rust,compile_fail
3173 /// #![deny(ambiguous_glob_reexports)]
3174 /// pub mod foo {
3175 /// pub type X = u8;
3176 /// }
3177 ///
3178 /// pub mod bar {
3179 /// pub type Y = u8;
3180 /// pub type X = u8;
3181 /// }
3182 ///
3183 /// pub use foo::*;
3184 /// pub use bar::*;
3185 ///
3186 ///
3187 /// pub fn main() {}
3188 /// ```
3189 ///
3190 /// {{produces}}
3191 ///
3192 /// ### Explanation
3193 ///
3194 /// This was previously accepted but it could silently break a crate's downstream users code.
3195 /// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
3196 /// re-exports, down stream users could use `this_crate::X` without problems. However, adding
3197 /// `bar::X` would cause compilation errors in downstream crates because `X` is defined
3198 /// multiple times in the same namespace of `this_crate`.
3199pub AMBIGUOUS_GLOB_REEXPORTS,
3200 Warn,
3201"ambiguous glob re-exports",
3202}32033204#[doc =
r" The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by"]
#[doc = r" private items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(hidden_glob_reexports)]"]
#[doc = r""]
#[doc = r" pub mod upstream {"]
#[doc = r" mod inner { pub struct Foo {}; pub struct Bar {}; }"]
#[doc = r" pub use self::inner::*;"]
#[doc = r" struct Foo {} // private item shadows `inner::Foo`"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" // mod downstream {"]
#[doc = r" // fn test() {"]
#[doc = r" // let _ = crate::upstream::Foo; // inaccessible"]
#[doc = r" // }"]
#[doc = r" // }"]
#[doc = r""]
#[doc = r" pub fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This was previously accepted without any errors or warnings but it could silently break a"]
#[doc =
r" crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would"]
#[doc =
r#" silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at"#]
#[doc = r" the downstream use site."]
pub static HIDDEN_GLOB_REEXPORTS: &crate::Lint =
&crate::Lint {
name: "HIDDEN_GLOB_REEXPORTS",
default_level: crate::Warn,
desc: "name introduced by a private item shadows a name introduced by a public glob re-export",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3205/// The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by
3206 /// private items.
3207 ///
3208 /// ### Example
3209 ///
3210 /// ```rust,compile_fail
3211 /// #![deny(hidden_glob_reexports)]
3212 ///
3213 /// pub mod upstream {
3214 /// mod inner { pub struct Foo {}; pub struct Bar {}; }
3215 /// pub use self::inner::*;
3216 /// struct Foo {} // private item shadows `inner::Foo`
3217 /// }
3218 ///
3219 /// // mod downstream {
3220 /// // fn test() {
3221 /// // let _ = crate::upstream::Foo; // inaccessible
3222 /// // }
3223 /// // }
3224 ///
3225 /// pub fn main() {}
3226 /// ```
3227 ///
3228 /// {{produces}}
3229 ///
3230 /// ### Explanation
3231 ///
3232 /// This was previously accepted without any errors or warnings but it could silently break a
3233 /// crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would
3234 /// silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at
3235 /// the downstream use site.
3236pub HIDDEN_GLOB_REEXPORTS,
3237 Warn,
3238"name introduced by a private item shadows a name introduced by a public glob re-export",
3239}32403241#[doc = r" The `long_running_const_eval` lint is emitted when const"]
#[doc = r" eval is running for a long time to ensure rustc terminates"]
#[doc = r" even if you accidentally wrote an infinite loop."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" const FOO: () = loop {};"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Loops allow const evaluation to compute arbitrary code, but may also"]
#[doc = r" cause infinite loops or just very long running computations."]
#[doc = r" Users can enable long running computations by allowing the lint"]
#[doc = r" on individual constants or for entire crates."]
#[doc = r""]
#[doc = r" ### Unconditional warnings"]
#[doc = r""]
#[doc =
r" Note that regardless of whether the lint is allowed or set to warn,"]
#[doc =
r" the compiler will issue warnings if constant evaluation runs significantly"]
#[doc =
r" longer than this lint's limit. These warnings are also shown to downstream"]
#[doc =
r" users from crates.io or similar registries. If you are above the lint's limit,"]
#[doc = r" both you and downstream users might be exposed to these warnings."]
#[doc =
r" They might also appear on compiler updates, as the compiler makes minor changes"]
#[doc =
r" about how complexity is measured: staying below the limit ensures that there"]
#[doc =
r" is enough room, and given that the lint is disabled for people who use your"]
#[doc =
r" dependency it means you will be the only one to get the warning and can put"]
#[doc = r" out an update in your own time."]
pub static LONG_RUNNING_CONST_EVAL: &crate::Lint =
&crate::Lint {
name: "LONG_RUNNING_CONST_EVAL",
default_level: crate::Deny,
desc: "detects long const eval operations",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3242/// The `long_running_const_eval` lint is emitted when const
3243 /// eval is running for a long time to ensure rustc terminates
3244 /// even if you accidentally wrote an infinite loop.
3245 ///
3246 /// ### Example
3247 ///
3248 /// ```rust,compile_fail
3249 /// const FOO: () = loop {};
3250 /// ```
3251 ///
3252 /// {{produces}}
3253 ///
3254 /// ### Explanation
3255 ///
3256 /// Loops allow const evaluation to compute arbitrary code, but may also
3257 /// cause infinite loops or just very long running computations.
3258 /// Users can enable long running computations by allowing the lint
3259 /// on individual constants or for entire crates.
3260 ///
3261 /// ### Unconditional warnings
3262 ///
3263 /// Note that regardless of whether the lint is allowed or set to warn,
3264 /// the compiler will issue warnings if constant evaluation runs significantly
3265 /// longer than this lint's limit. These warnings are also shown to downstream
3266 /// users from crates.io or similar registries. If you are above the lint's limit,
3267 /// both you and downstream users might be exposed to these warnings.
3268 /// They might also appear on compiler updates, as the compiler makes minor changes
3269 /// about how complexity is measured: staying below the limit ensures that there
3270 /// is enough room, and given that the lint is disabled for people who use your
3271 /// dependency it means you will be the only one to get the warning and can put
3272 /// out an update in your own time.
3273pub LONG_RUNNING_CONST_EVAL,
3274 Deny,
3275"detects long const eval operations",
3276 report_in_external_macro
3277}32783279#[doc = r" The `unused_associated_type_bounds` lint is emitted when an"]
#[doc =
r" associated type bound is added to a trait object, but the associated"]
#[doc =
r" type has a `where Self: Sized` bound, and is thus unavailable on the"]
#[doc = r" trait object anyway."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Foo {"]
#[doc = r" type Bar where Self: Sized;"]
#[doc = r" }"]
#[doc = r" type Mop = dyn Foo<Bar = ()>;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Just like methods with `Self: Sized` bounds are unavailable on trait"]
#[doc = r" objects, associated types can be removed from the trait object."]
pub static UNUSED_ASSOCIATED_TYPE_BOUNDS: &crate::Lint =
&crate::Lint {
name: "UNUSED_ASSOCIATED_TYPE_BOUNDS",
default_level: crate::Warn,
desc: "detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3280/// The `unused_associated_type_bounds` lint is emitted when an
3281 /// associated type bound is added to a trait object, but the associated
3282 /// type has a `where Self: Sized` bound, and is thus unavailable on the
3283 /// trait object anyway.
3284 ///
3285 /// ### Example
3286 ///
3287 /// ```rust
3288 /// trait Foo {
3289 /// type Bar where Self: Sized;
3290 /// }
3291 /// type Mop = dyn Foo<Bar = ()>;
3292 /// ```
3293 ///
3294 /// {{produces}}
3295 ///
3296 /// ### Explanation
3297 ///
3298 /// Just like methods with `Self: Sized` bounds are unavailable on trait
3299 /// objects, associated types can be removed from the trait object.
3300pub UNUSED_ASSOCIATED_TYPE_BOUNDS,
3301 Warn,
3302"detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`"
3303}33043305#[doc =
r" The `unused_doc_comments` lint detects doc comments that aren't used"]
#[doc = r" by `rustdoc`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" /// docs for x"]
#[doc = r" let x = 12;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" `rustdoc` does not use doc comments in all positions, and so the doc"]
#[doc =
r" comment will be ignored. Try changing it to a normal comment with `//`"]
#[doc = r" to avoid the warning."]
pub static UNUSED_DOC_COMMENTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_DOC_COMMENTS",
default_level: crate::Warn,
desc: "detects doc comments that aren't used by rustdoc",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3306/// The `unused_doc_comments` lint detects doc comments that aren't used
3307 /// by `rustdoc`.
3308 ///
3309 /// ### Example
3310 ///
3311 /// ```rust
3312 /// /// docs for x
3313 /// let x = 12;
3314 /// ```
3315 ///
3316 /// {{produces}}
3317 ///
3318 /// ### Explanation
3319 ///
3320 /// `rustdoc` does not use doc comments in all positions, and so the doc
3321 /// comment will be ignored. Try changing it to a normal comment with `//`
3322 /// to avoid the warning.
3323pub UNUSED_DOC_COMMENTS,
3324 Warn,
3325"detects doc comments that aren't used by rustdoc"
3326}33273328#[doc =
r" The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely"]
#[doc =
r" captured in Rust 2021, such that the `Drop` order of their fields may differ between"]
#[doc = r" Rust 2018 and 2021."]
#[doc = r""]
#[doc =
r" It can also detect when a variable implements a trait like `Send`, but one of its fields does not,"]
#[doc =
r" and the field is captured by a closure and used with the assumption that said field implements"]
#[doc = r" the same trait as the root variable."]
#[doc = r""]
#[doc = r" ### Example of drop reorder"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_closure_captures)]"]
#[doc = r" # #![allow(unused)]"]
#[doc = r""]
#[doc = r" struct FancyInteger(i32);"]
#[doc = r""]
#[doc = r" impl Drop for FancyInteger {"]
#[doc = r" fn drop(&mut self) {"]
#[doc = r#" println!("Just dropped {}", self.0);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" struct Point { x: FancyInteger, y: FancyInteger }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let p = Point { x: FancyInteger(10), y: FancyInteger(20) };"]
#[doc = r""]
#[doc = r" let c = || {"]
#[doc = r" let x = p.x;"]
#[doc = r" };"]
#[doc = r""]
#[doc = r" c();"]
#[doc = r""]
#[doc = r" // ... More code ..."]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In the above example, `p.y` will be dropped at the end of `f` instead of"]
#[doc = r" with `c` in Rust 2021."]
#[doc = r""]
#[doc = r" ### Example of auto-trait"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_closure_captures)]"]
#[doc = r" use std::thread;"]
#[doc = r""]
#[doc = r" struct Pointer(*mut i32);"]
#[doc = r" unsafe impl Send for Pointer {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let mut f = 10;"]
#[doc = r" let fptr = Pointer(&mut f as *mut i32);"]
#[doc = r" thread::spawn(move || unsafe {"]
#[doc = r" *fptr.0 = 20;"]
#[doc = r" });"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In the above example, only `fptr.0` is captured in Rust 2021."]
#[doc = r" The field is of type `*mut i32`, which doesn't implement `Send`,"]
#[doc =
r" making the code invalid as the field cannot be sent between threads safely."]
pub static RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES: &crate::Lint =
&crate::Lint {
name: "RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES",
default_level: crate::Allow,
desc: "detects closures affected by Rust 2021 changes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "disjoint-capture-in-closures",
}),
explain_reason: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3329/// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3330 /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3331 /// Rust 2018 and 2021.
3332 ///
3333 /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3334 /// and the field is captured by a closure and used with the assumption that said field implements
3335 /// the same trait as the root variable.
3336 ///
3337 /// ### Example of drop reorder
3338 ///
3339 /// ```rust,edition2018,compile_fail
3340 /// #![deny(rust_2021_incompatible_closure_captures)]
3341 /// # #![allow(unused)]
3342 ///
3343 /// struct FancyInteger(i32);
3344 ///
3345 /// impl Drop for FancyInteger {
3346 /// fn drop(&mut self) {
3347 /// println!("Just dropped {}", self.0);
3348 /// }
3349 /// }
3350 ///
3351 /// struct Point { x: FancyInteger, y: FancyInteger }
3352 ///
3353 /// fn main() {
3354 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3355 ///
3356 /// let c = || {
3357 /// let x = p.x;
3358 /// };
3359 ///
3360 /// c();
3361 ///
3362 /// // ... More code ...
3363 /// }
3364 /// ```
3365 ///
3366 /// {{produces}}
3367 ///
3368 /// ### Explanation
3369 ///
3370 /// In the above example, `p.y` will be dropped at the end of `f` instead of
3371 /// with `c` in Rust 2021.
3372 ///
3373 /// ### Example of auto-trait
3374 ///
3375 /// ```rust,edition2018,compile_fail
3376 /// #![deny(rust_2021_incompatible_closure_captures)]
3377 /// use std::thread;
3378 ///
3379 /// struct Pointer(*mut i32);
3380 /// unsafe impl Send for Pointer {}
3381 ///
3382 /// fn main() {
3383 /// let mut f = 10;
3384 /// let fptr = Pointer(&mut f as *mut i32);
3385 /// thread::spawn(move || unsafe {
3386 /// *fptr.0 = 20;
3387 /// });
3388 /// }
3389 /// ```
3390 ///
3391 /// {{produces}}
3392 ///
3393 /// ### Explanation
3394 ///
3395 /// In the above example, only `fptr.0` is captured in Rust 2021.
3396 /// The field is of type `*mut i32`, which doesn't implement `Send`,
3397 /// making the code invalid as the field cannot be sent between threads safely.
3398pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3399 Allow,
3400"detects closures affected by Rust 2021 changes",
3401 @future_incompatible = FutureIncompatibleInfo {
3402 reason: fcw!(EditionSemanticsChange 2021 "disjoint-capture-in-closures"),
3403 explain_reason: false,
3404 };
3405}34063407pub struct UnusedDocComment;
#[automatically_derived]
impl ::core::marker::Copy for UnusedDocComment { }
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for UnusedDocComment { }
#[automatically_derived]
impl ::core::clone::Clone for UnusedDocComment {
#[inline]
fn clone(&self) -> UnusedDocComment { *self }
}
impl crate::LintPass for UnusedDocComment {
fn name(&self) -> &'static str { "UnusedDocComment" }
fn get_lints(&self) -> crate::LintVec {
<[_]>::into_vec(::alloc::boxed::box_new([UNUSED_DOC_COMMENTS]))
}
}
impl UnusedDocComment {
#[allow(unused)]
pub fn lint_vec() -> crate::LintVec {
<[_]>::into_vec(::alloc::boxed::box_new([UNUSED_DOC_COMMENTS]))
}
}declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
34083409#[doc =
r" The `missing_abi` lint detects cases where the ABI is omitted from"]
#[doc = r" `extern` declarations."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(missing_abi)]"]
#[doc = r""]
#[doc = r" extern fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" For historic reasons, Rust implicitly selects `C` as the default ABI for"]
#[doc =
r" `extern` declarations. [Other ABIs] like `C-unwind` and `system` have"]
#[doc =
r" been added since then, and especially with their addition seeing the ABI"]
#[doc = r" easily makes code review easier."]
#[doc = r""]
#[doc =
r" [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi"]
pub static MISSING_ABI: &crate::Lint =
&crate::Lint {
name: "MISSING_ABI",
default_level: crate::Warn,
desc: "No declared ABI for extern declaration",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3410/// The `missing_abi` lint detects cases where the ABI is omitted from
3411 /// `extern` declarations.
3412 ///
3413 /// ### Example
3414 ///
3415 /// ```rust,compile_fail
3416 /// #![deny(missing_abi)]
3417 ///
3418 /// extern fn foo() {}
3419 /// ```
3420 ///
3421 /// {{produces}}
3422 ///
3423 /// ### Explanation
3424 ///
3425 /// For historic reasons, Rust implicitly selects `C` as the default ABI for
3426 /// `extern` declarations. [Other ABIs] like `C-unwind` and `system` have
3427 /// been added since then, and especially with their addition seeing the ABI
3428 /// easily makes code review easier.
3429 ///
3430 /// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
3431pub MISSING_ABI,
3432 Warn,
3433"No declared ABI for extern declaration"
3434}34353436#[doc =
r" The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is"]
#[doc = r" misused."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(warnings)]"]
#[doc = r""]
#[doc = r" pub mod submodule {"]
#[doc = r" #![doc(test(no_crate_inject))]"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previously, incorrect usage of the `#[doc(..)]` attribute was not"]
#[doc =
r" being validated. Usually these should be rejected as a hard error,"]
#[doc = r" but this lint was introduced to avoid breaking any existing"]
#[doc = r" crates which included them."]
pub static INVALID_DOC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "INVALID_DOC_ATTRIBUTES",
default_level: crate::Deny,
desc: "detects invalid `#[doc(...)]` attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3437/// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3438 /// misused.
3439 ///
3440 /// ### Example
3441 ///
3442 /// ```rust,compile_fail
3443 /// #![deny(warnings)]
3444 ///
3445 /// pub mod submodule {
3446 /// #![doc(test(no_crate_inject))]
3447 /// }
3448 /// ```
3449 ///
3450 /// {{produces}}
3451 ///
3452 /// ### Explanation
3453 ///
3454 /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
3455 /// being validated. Usually these should be rejected as a hard error,
3456 /// but this lint was introduced to avoid breaking any existing
3457 /// crates which included them.
3458pub INVALID_DOC_ATTRIBUTES,
3459 Deny,
3460"detects invalid `#[doc(...)]` attributes",
3461}34623463#[doc =
r" The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_or_patterns)]"]
#[doc = r""]
#[doc = r" macro_rules! match_any {"]
#[doc =
r" ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {"]
#[doc = r" match $expr {"]
#[doc = r" $("]
#[doc = r" $( $pat => $expr_arm, )+"]
#[doc = r" )+"]
#[doc = r" }"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let result: Result<i64, i32> = Err(42);"]
#[doc =
r" let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());"]
#[doc = r" assert_eq!(int, 42);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character."]
pub static RUST_2021_INCOMPATIBLE_OR_PATTERNS: &crate::Lint =
&crate::Lint {
name: "RUST_2021_INCOMPATIBLE_OR_PATTERNS",
default_level: crate::Allow,
desc: "detects usage of old versions of or-patterns",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "or-patterns-macro-rules",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3464/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3465 ///
3466 /// ### Example
3467 ///
3468 /// ```rust,edition2018,compile_fail
3469 /// #![deny(rust_2021_incompatible_or_patterns)]
3470 ///
3471 /// macro_rules! match_any {
3472 /// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3473 /// match $expr {
3474 /// $(
3475 /// $( $pat => $expr_arm, )+
3476 /// )+
3477 /// }
3478 /// };
3479 /// }
3480 ///
3481 /// fn main() {
3482 /// let result: Result<i64, i32> = Err(42);
3483 /// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3484 /// assert_eq!(int, 42);
3485 /// }
3486 /// ```
3487 ///
3488 /// {{produces}}
3489 ///
3490 /// ### Explanation
3491 ///
3492 /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3493pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3494 Allow,
3495"detects usage of old versions of or-patterns",
3496 @future_incompatible = FutureIncompatibleInfo {
3497 reason: fcw!(EditionError 2021 "or-patterns-macro-rules"),
3498 };
3499}35003501#[doc =
r" The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous"]
#[doc = r" with traits added to the prelude in future editions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_prelude_collisions)]"]
#[doc = r""]
#[doc = r" trait Foo {"]
#[doc = r" fn try_into(self) -> Result<String, !>;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Foo for &str {"]
#[doc = r" fn try_into(self) -> Result<String, !> {"]
#[doc = r" Ok(String::from(self))"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" let x: String = "3".try_into().unwrap();"#]
#[doc = r" // ^^^^^^^^"]
#[doc =
r" // This call to try_into matches both Foo::try_into and TryInto::try_into as"]
#[doc =
r" // `TryInto` has been added to the Rust prelude in 2021 edition."]
#[doc = r#" println!("{x}");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2021, one of the important introductions is the [prelude changes], which add"]
#[doc =
r" `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this"]
#[doc =
r" results in an ambiguity as to which method/function to call when an existing `try_into`"]
#[doc =
r" method is called via dot-call syntax or a `try_from`/`from_iter` associated function"]
#[doc = r" is called directly on a type."]
#[doc = r""]
#[doc =
r" [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes"]
pub static RUST_2021_PRELUDE_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "RUST_2021_PRELUDE_COLLISIONS",
default_level: crate::Allow,
desc: "detects the usage of trait methods which are ambiguous with traits added to the \
prelude in future editions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "prelude",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3502/// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3503 /// with traits added to the prelude in future editions.
3504 ///
3505 /// ### Example
3506 ///
3507 /// ```rust,edition2018,compile_fail
3508 /// #![deny(rust_2021_prelude_collisions)]
3509 ///
3510 /// trait Foo {
3511 /// fn try_into(self) -> Result<String, !>;
3512 /// }
3513 ///
3514 /// impl Foo for &str {
3515 /// fn try_into(self) -> Result<String, !> {
3516 /// Ok(String::from(self))
3517 /// }
3518 /// }
3519 ///
3520 /// fn main() {
3521 /// let x: String = "3".try_into().unwrap();
3522 /// // ^^^^^^^^
3523 /// // This call to try_into matches both Foo::try_into and TryInto::try_into as
3524 /// // `TryInto` has been added to the Rust prelude in 2021 edition.
3525 /// println!("{x}");
3526 /// }
3527 /// ```
3528 ///
3529 /// {{produces}}
3530 ///
3531 /// ### Explanation
3532 ///
3533 /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3534 /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3535 /// results in an ambiguity as to which method/function to call when an existing `try_into`
3536 /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3537 /// is called directly on a type.
3538 ///
3539 /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3540pub RUST_2021_PRELUDE_COLLISIONS,
3541 Allow,
3542"detects the usage of trait methods which are ambiguous with traits added to the \
3543 prelude in future editions",
3544 @future_incompatible = FutureIncompatibleInfo {
3545 reason: fcw!(EditionError 2021 "prelude"),
3546 };
3547}35483549#[doc =
r" The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous"]
#[doc = r" with traits added to the prelude in future editions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(rust_2024_prelude_collisions)]"]
#[doc = r" trait Meow {"]
#[doc = r" fn poll(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Meow for T {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" core::pin::pin!(async {}).poll();"]
#[doc = r" // ^^^^^^"]
#[doc =
r" // This call to try_into matches both Future::poll and Meow::poll as"]
#[doc =
r" // `Future` has been added to the Rust prelude in 2024 edition."]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust 2024, introduces two new additions to the standard library's prelude:"]
#[doc =
r" `Future` and `IntoFuture`. This results in an ambiguity as to which method/function"]
#[doc =
r" to call when an existing `poll`/`into_future` method is called via dot-call syntax or"]
#[doc =
r" a `poll`/`into_future` associated function is called directly on a type."]
#[doc = r""]
pub static RUST_2024_PRELUDE_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "RUST_2024_PRELUDE_COLLISIONS",
default_level: crate::Allow,
desc: "detects the usage of trait methods which are ambiguous with traits added to the \
prelude in future editions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "prelude",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3550/// The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3551 /// with traits added to the prelude in future editions.
3552 ///
3553 /// ### Example
3554 ///
3555 /// ```rust,edition2021,compile_fail
3556 /// #![deny(rust_2024_prelude_collisions)]
3557 /// trait Meow {
3558 /// fn poll(&self) {}
3559 /// }
3560 /// impl<T> Meow for T {}
3561 ///
3562 /// fn main() {
3563 /// core::pin::pin!(async {}).poll();
3564 /// // ^^^^^^
3565 /// // This call to try_into matches both Future::poll and Meow::poll as
3566 /// // `Future` has been added to the Rust prelude in 2024 edition.
3567 /// }
3568 /// ```
3569 ///
3570 /// {{produces}}
3571 ///
3572 /// ### Explanation
3573 ///
3574 /// Rust 2024, introduces two new additions to the standard library's prelude:
3575 /// `Future` and `IntoFuture`. This results in an ambiguity as to which method/function
3576 /// to call when an existing `poll`/`into_future` method is called via dot-call syntax or
3577 /// a `poll`/`into_future` associated function is called directly on a type.
3578 ///
3579pub RUST_2024_PRELUDE_COLLISIONS,
3580 Allow,
3581"detects the usage of trait methods which are ambiguous with traits added to the \
3582 prelude in future editions",
3583 @future_incompatible = FutureIncompatibleInfo {
3584 reason: fcw!(EditionError 2024 "prelude"),
3585 };
3586}35873588#[doc =
r" The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a"]
#[doc = r" prefix instead in Rust 2021."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_prefixes_incompatible_syntax)]"]
#[doc = r""]
#[doc = r" macro_rules! m {"]
#[doc = r" (z $x:expr) => ();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r#" m!(z"hey");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`"#]
#[doc =
r#" followed by the string literal `"hey"`. In Rust 2021, the `z` is"#]
#[doc = r#" considered a prefix for `"hey"`."#]
#[doc = r""]
#[doc =
r#" This lint suggests to add whitespace between the `z` and `"hey"` tokens"#]
#[doc = r" to keep them separated in Rust 2021."]
#[allow(rustdoc::invalid_rust_codeblocks)]
pub static RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX: &crate::Lint =
&crate::Lint {
name: "RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX",
default_level: crate::Allow,
desc: "identifiers that will be parsed as a prefix in Rust 2021",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "reserving-syntax",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3589/// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3590 /// prefix instead in Rust 2021.
3591 ///
3592 /// ### Example
3593 ///
3594 /// ```rust,edition2018,compile_fail
3595 /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3596 ///
3597 /// macro_rules! m {
3598 /// (z $x:expr) => ();
3599 /// }
3600 ///
3601 /// m!(z"hey");
3602 /// ```
3603 ///
3604 /// {{produces}}
3605 ///
3606 /// ### Explanation
3607 ///
3608 /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3609 /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3610 /// considered a prefix for `"hey"`.
3611 ///
3612 /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3613 /// to keep them separated in Rust 2021.
3614// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3615#[allow(rustdoc::invalid_rust_codeblocks)]
3616pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3617 Allow,
3618"identifiers that will be parsed as a prefix in Rust 2021",
3619 @future_incompatible = FutureIncompatibleInfo {
3620 reason: fcw!(EditionError 2021 "reserving-syntax"),
3621 };
3622 crate_level_only
3623}36243625#[doc =
r" The `unsupported_calling_conventions` lint is output whenever there is a use of the"]
#[doc =
r" `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind"]
#[doc =
r" variants) on targets that cannot meaningfully be supported for the requested target."]
#[doc = r""]
#[doc =
r" For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc"]
#[doc =
r" code, because this calling convention was never specified for those targets."]
#[doc = r""]
#[doc =
r" Historically MSVC toolchains have fallen back to the regular C calling convention for"]
#[doc =
r" targets other than x86, but Rust doesn't really see a similar need to introduce a similar"]
#[doc = r" hack across many more targets."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs specific targets)"]
#[doc = r#" extern "stdcall" fn stdcall() {}"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: use of calling convention not supported on this target"]
#[doc = r" --> $DIR/unsupported.rs:39:1"]
#[doc = r" |"]
#[doc = r#" LL | extern "stdcall" fn stdcall() {}"#]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = note: `#[warn(unsupported_calling_conventions)]` on by default"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out;"]
#[doc = r" it will become a hard error in a future release!"]
#[doc = r" = note: for more information, see issue ..."]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On most of the targets the behaviour of `stdcall` and similar calling conventions is not"]
#[doc =
r" defined at all, but was previously accepted due to a bug in the implementation of the"]
#[doc = r" compiler."]
pub static UNSUPPORTED_CALLING_CONVENTIONS: &crate::Lint =
&crate::Lint {
name: "UNSUPPORTED_CALLING_CONVENTIONS",
default_level: crate::Warn,
desc: "use of unsupported calling convention",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 137018,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3626/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3627 /// `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind
3628 /// variants) on targets that cannot meaningfully be supported for the requested target.
3629 ///
3630 /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3631 /// code, because this calling convention was never specified for those targets.
3632 ///
3633 /// Historically MSVC toolchains have fallen back to the regular C calling convention for
3634 /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3635 /// hack across many more targets.
3636 ///
3637 /// ### Example
3638 ///
3639 /// ```rust,ignore (needs specific targets)
3640 /// extern "stdcall" fn stdcall() {}
3641 /// ```
3642 ///
3643 /// This will produce:
3644 ///
3645 /// ```text
3646 /// warning: use of calling convention not supported on this target
3647 /// --> $DIR/unsupported.rs:39:1
3648 /// |
3649 /// LL | extern "stdcall" fn stdcall() {}
3650 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3651 /// |
3652 /// = note: `#[warn(unsupported_calling_conventions)]` on by default
3653 /// = warning: this was previously accepted by the compiler but is being phased out;
3654 /// it will become a hard error in a future release!
3655 /// = note: for more information, see issue ...
3656 /// ```
3657 ///
3658 /// ### Explanation
3659 ///
3660 /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3661 /// defined at all, but was previously accepted due to a bug in the implementation of the
3662 /// compiler.
3663pub UNSUPPORTED_CALLING_CONVENTIONS,
3664 Warn,
3665"use of unsupported calling convention",
3666 @future_incompatible = FutureIncompatibleInfo {
3667 reason: fcw!(FutureReleaseError #137018),
3668 report_in_deps: false,
3669 };
3670}36713672#[doc =
r" The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of"]
#[doc =
r" a target dependent calling convention on a target that does not support this calling"]
#[doc = r" convention on a function pointer."]
#[doc = r""]
#[doc =
r" For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc"]
#[doc =
r" code, because this calling convention was never specified for those targets."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs specific targets)"]
#[doc = r#" fn stdcall_ptr(f: extern "stdcall" fn ()) {"#]
#[doc = r" f()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r#" warning: the calling convention `"stdcall"` is not supported on this target"#]
#[doc = r" --> $DIR/unsupported.rs:34:15"]
#[doc = r" |"]
#[doc = r#" LL | fn stdcall_ptr(f: extern "stdcall" fn()) {"#]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>"]
#[doc =
r" = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On most of the targets the behaviour of `stdcall` and similar calling conventions is not"]
#[doc =
r" defined at all, but was previously accepted due to a bug in the implementation of the"]
#[doc = r" compiler."]
pub static UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS: &crate::Lint =
&crate::Lint {
name: "UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS",
default_level: crate::Warn,
desc: "use of unsupported calling convention for function pointer",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 130260,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3673/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
3674 /// a target dependent calling convention on a target that does not support this calling
3675 /// convention on a function pointer.
3676 ///
3677 /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3678 /// code, because this calling convention was never specified for those targets.
3679 ///
3680 /// ### Example
3681 ///
3682 /// ```rust,ignore (needs specific targets)
3683 /// fn stdcall_ptr(f: extern "stdcall" fn ()) {
3684 /// f()
3685 /// }
3686 /// ```
3687 ///
3688 /// This will produce:
3689 ///
3690 /// ```text
3691 /// warning: the calling convention `"stdcall"` is not supported on this target
3692 /// --> $DIR/unsupported.rs:34:15
3693 /// |
3694 /// LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
3695 /// | ^^^^^^^^^^^^^^^^^^^^^^^^
3696 /// |
3697 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3698 /// = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
3699 /// = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
3700 /// ```
3701 ///
3702 /// ### Explanation
3703 ///
3704 /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3705 /// defined at all, but was previously accepted due to a bug in the implementation of the
3706 /// compiler.
3707pub UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
3708 Warn,
3709"use of unsupported calling convention for function pointer",
3710 @future_incompatible = FutureIncompatibleInfo {
3711 reason: fcw!(FutureReleaseError #130260),
3712 report_in_deps: true,
3713 };
3714}37153716#[doc =
r" The `break_with_label_and_loop` lint detects labeled `break` expressions with"]
#[doc = r" an unlabeled loop as their value expression."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" 'label: loop {"]
#[doc = r" break 'label loop { break 42; };"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust, loops can have a label, and `break` expressions can refer to that label to"]
#[doc =
r" break out of specific loops (and not necessarily the innermost one). `break` expressions"]
#[doc =
r" can also carry a value expression, which can be another loop. A labeled `break` with an"]
#[doc =
r" unlabeled loop as its value expression is easy to confuse with an unlabeled break with"]
#[doc =
r" a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses"]
#[doc =
r" around the loop expression to silence this warning. Unlabeled `break` expressions with"]
#[doc =
r" labeled loops yield a hard error, which can also be silenced by wrapping the expression"]
#[doc = r" in parentheses."]
pub static BREAK_WITH_LABEL_AND_LOOP: &crate::Lint =
&crate::Lint {
name: "BREAK_WITH_LABEL_AND_LOOP",
default_level: crate::Warn,
desc: "`break` expression with label and unlabeled loop as value expression",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3717/// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3718 /// an unlabeled loop as their value expression.
3719 ///
3720 /// ### Example
3721 ///
3722 /// ```rust
3723 /// 'label: loop {
3724 /// break 'label loop { break 42; };
3725 /// };
3726 /// ```
3727 ///
3728 /// {{produces}}
3729 ///
3730 /// ### Explanation
3731 ///
3732 /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3733 /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3734 /// can also carry a value expression, which can be another loop. A labeled `break` with an
3735 /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3736 /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3737 /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3738 /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3739 /// in parentheses.
3740pub BREAK_WITH_LABEL_AND_LOOP,
3741 Warn,
3742"`break` expression with label and unlabeled loop as value expression"
3743}37443745#[doc =
r" The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`"]
#[doc =
r" struct or enum who want to match all of its fields/variants explicitly."]
#[doc = r""]
#[doc =
r" The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness"]
#[doc =
r" checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy"]
#[doc =
r" this, this allow-by-default lint warns the user when a match mentions some but not all of"]
#[doc = r" the fields/variants of a `#[non_exhaustive]` struct or enum."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs separate crate)"]
#[doc = r" // crate A"]
#[doc = r" #[non_exhaustive]"]
#[doc = r" pub enum Bar {"]
#[doc = r" A,"]
#[doc = r" B, // added variant in non breaking change"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" // in crate B"]
#[doc = r" #![feature(non_exhaustive_omitted_patterns_lint)]"]
#[doc = r" #[warn(non_exhaustive_omitted_patterns)]"]
#[doc = r" match Bar::A {"]
#[doc = r" Bar::A => {},"]
#[doc = r" _ => {},"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: some variants are not matched explicitly"]
#[doc = r" --> $DIR/reachable-patterns.rs:70:9"]
#[doc = r" |"]
#[doc = r" LL | match Bar::A {"]
#[doc = r" | ^ pattern `Bar::B` not covered"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> $DIR/reachable-patterns.rs:69:16"]
#[doc = r" |"]
#[doc = r" LL | #[warn(non_exhaustive_omitted_patterns)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc =
r" = help: ensure that all variants are matched explicitly by adding the suggested match arms"]
#[doc =
r" = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or"]
#[doc =
r" variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against"]
#[doc = r" expected semver behavior."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially"]
#[doc =
r" redundant) wildcard when pattern-matching, to allow for future addition of fields or"]
#[doc =
r" variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to"]
#[doc =
r" actually catch some fields/variants. In other words, when the match without the wildcard"]
#[doc =
r" would not be exhaustive. This lets the user be informed if new fields/variants were added."]
pub static NON_EXHAUSTIVE_OMITTED_PATTERNS: &crate::Lint =
&crate::Lint {
name: "NON_EXHAUSTIVE_OMITTED_PATTERNS",
default_level: crate::Allow,
desc: "detect when patterns of types marked `non_exhaustive` are missed",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::non_exhaustive_omitted_patterns_lint),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3746/// The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`
3747 /// struct or enum who want to match all of its fields/variants explicitly.
3748 ///
3749 /// The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness
3750 /// checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy
3751 /// this, this allow-by-default lint warns the user when a match mentions some but not all of
3752 /// the fields/variants of a `#[non_exhaustive]` struct or enum.
3753 ///
3754 /// ### Example
3755 ///
3756 /// ```rust,ignore (needs separate crate)
3757 /// // crate A
3758 /// #[non_exhaustive]
3759 /// pub enum Bar {
3760 /// A,
3761 /// B, // added variant in non breaking change
3762 /// }
3763 ///
3764 /// // in crate B
3765 /// #![feature(non_exhaustive_omitted_patterns_lint)]
3766 /// #[warn(non_exhaustive_omitted_patterns)]
3767 /// match Bar::A {
3768 /// Bar::A => {},
3769 /// _ => {},
3770 /// }
3771 /// ```
3772 ///
3773 /// This will produce:
3774 ///
3775 /// ```text
3776 /// warning: some variants are not matched explicitly
3777 /// --> $DIR/reachable-patterns.rs:70:9
3778 /// |
3779 /// LL | match Bar::A {
3780 /// | ^ pattern `Bar::B` not covered
3781 /// |
3782 /// note: the lint level is defined here
3783 /// --> $DIR/reachable-patterns.rs:69:16
3784 /// |
3785 /// LL | #[warn(non_exhaustive_omitted_patterns)]
3786 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3787 /// = help: ensure that all variants are matched explicitly by adding the suggested match arms
3788 /// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3789 /// ```
3790 ///
3791 /// Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or
3792 /// variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against
3793 /// expected semver behavior.
3794 ///
3795 /// ### Explanation
3796 ///
3797 /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially
3798 /// redundant) wildcard when pattern-matching, to allow for future addition of fields or
3799 /// variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to
3800 /// actually catch some fields/variants. In other words, when the match without the wildcard
3801 /// would not be exhaustive. This lets the user be informed if new fields/variants were added.
3802pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3803 Allow,
3804"detect when patterns of types marked `non_exhaustive` are missed",
3805 @feature_gate = non_exhaustive_omitted_patterns_lint;
3806}38073808#[doc =
r" The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that"]
#[doc =
r" change the visual representation of text on screen in a way that does not correspond to"]
#[doc = r" their on memory representation."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(text_direction_codepoint_in_comment)]"]
#[doc = r" fn main() {"]
#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unicode allows changing the visual flow of text on screen in order to support scripts that"]
#[doc =
r" are written right-to-left, but a specially crafted comment can make code that will be"]
#[doc =
r" compiled appear to be part of a comment, depending on the software used to read the code."]
#[doc =
r" To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny"]
#[doc = r" their use."]
pub static TEXT_DIRECTION_CODEPOINT_IN_COMMENT: &crate::Lint =
&crate::Lint {
name: "TEXT_DIRECTION_CODEPOINT_IN_COMMENT",
default_level: crate::Deny,
desc: "invisible directionality-changing codepoints in comment",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3809/// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3810 /// change the visual representation of text on screen in a way that does not correspond to
3811 /// their on memory representation.
3812 ///
3813 /// ### Example
3814 ///
3815 /// ```rust,compile_fail
3816 /// #![deny(text_direction_codepoint_in_comment)]
3817 /// fn main() {
3818#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
3819/// }
3820 /// ```
3821 ///
3822 /// {{produces}}
3823 ///
3824 /// ### Explanation
3825 ///
3826 /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3827 /// are written right-to-left, but a specially crafted comment can make code that will be
3828 /// compiled appear to be part of a comment, depending on the software used to read the code.
3829 /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3830 /// their use.
3831pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3832 Deny,
3833"invisible directionality-changing codepoints in comment",
3834 crate_level_only
3835}38363837#[doc =
r" The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the"]
#[doc =
r" visual representation of text on screen in a way that does not correspond to their on"]
#[doc = r" memory representation."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,"]
#[doc =
r" `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change"]
#[doc =
r#" its direction on software that supports these codepoints. This makes the text "abc" display"#]
#[doc =
r#" as "cba" on screen. By leveraging software that supports these, people can write specially"#]
#[doc =
r" crafted literals that make the surrounding code seem like it's performing one action, when"]
#[doc =
r" in reality it is performing another. Because of this, we proactively lint against their"]
#[doc = r" presence to avoid surprises."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(text_direction_codepoint_in_literal)]"]
#[doc = r" fn main() {"]
#[doc = " println!(\"{:?}\", '\u{202E}');"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
pub static TEXT_DIRECTION_CODEPOINT_IN_LITERAL: &crate::Lint =
&crate::Lint {
name: "TEXT_DIRECTION_CODEPOINT_IN_LITERAL",
default_level: crate::Deny,
desc: "detect special Unicode codepoints that affect the visual representation of text on screen, \
changing the direction in which text flows",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3838/// The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the
3839 /// visual representation of text on screen in a way that does not correspond to their on
3840 /// memory representation.
3841 ///
3842 /// ### Explanation
3843 ///
3844 /// The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,
3845 /// `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change
3846 /// its direction on software that supports these codepoints. This makes the text "abc" display
3847 /// as "cba" on screen. By leveraging software that supports these, people can write specially
3848 /// crafted literals that make the surrounding code seem like it's performing one action, when
3849 /// in reality it is performing another. Because of this, we proactively lint against their
3850 /// presence to avoid surprises.
3851 ///
3852 /// ### Example
3853 ///
3854 /// ```rust,compile_fail
3855 /// #![deny(text_direction_codepoint_in_literal)]
3856 /// fn main() {
3857// ` - convince tidy that backticks match
3858#[doc = " println!(\"{:?}\", '\u{202E}');"]
3859// `
3860/// }
3861 /// ```
3862 ///
3863 /// {{produces}}
3864 ///
3865pub TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
3866 Deny,
3867"detect special Unicode codepoints that affect the visual representation of text on screen, \
3868 changing the direction in which text flows",
3869 crate_level_only
3870}38713872#[doc =
r" The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro"]
#[doc =
r" attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`"]
#[doc = r" and `test_case`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs --test)"]
#[doc = r" #[test]"]
#[doc = r" #[test]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: duplicated attribute"]
#[doc = r" --> src/lib.rs:2:1"]
#[doc = r" |"]
#[doc = r" 2 | #[test]"]
#[doc = r" | ^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(duplicate_macro_attributes)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A duplicated attribute may erroneously originate from a copy-paste and the effect of it"]
#[doc = r" being duplicated may not be obvious or desirable."]
#[doc = r""]
#[doc =
r" For instance, doubling the `#[test]` attributes registers the test to be run twice with no"]
#[doc = r" change to its environment."]
#[doc = r""]
#[doc = r" [issue #90979]: https://github.com/rust-lang/rust/issues/90979"]
pub static DUPLICATE_MACRO_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "DUPLICATE_MACRO_ATTRIBUTES",
default_level: crate::Warn,
desc: "duplicated attribute",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3873/// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3874 /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3875 /// and `test_case`.
3876 ///
3877 /// ### Example
3878 ///
3879 /// ```rust,ignore (needs --test)
3880 /// #[test]
3881 /// #[test]
3882 /// fn foo() {}
3883 /// ```
3884 ///
3885 /// This will produce:
3886 ///
3887 /// ```text
3888 /// warning: duplicated attribute
3889 /// --> src/lib.rs:2:1
3890 /// |
3891 /// 2 | #[test]
3892 /// | ^^^^^^^
3893 /// |
3894 /// = note: `#[warn(duplicate_macro_attributes)]` on by default
3895 /// ```
3896 ///
3897 /// ### Explanation
3898 ///
3899 /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3900 /// being duplicated may not be obvious or desirable.
3901 ///
3902 /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3903 /// change to its environment.
3904 ///
3905 /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3906pub DUPLICATE_MACRO_ATTRIBUTES,
3907 Warn,
3908"duplicated attribute"
3909}39103911#[doc =
r" The `deprecated_where_clause_location` lint detects when a where clause in front of the equals"]
#[doc = r" in an associated type."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Trait {"]
#[doc = r" type Assoc<'a> where Self: 'a;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Trait for () {"]
#[doc = r" type Assoc<'a> where Self: 'a = ();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The preferred location for where clauses on associated types"]
#[doc =
r" is after the type. However, for most of generic associated types development,"]
#[doc =
r" it was only accepted before the equals. To provide a transition period and"]
#[doc =
r" further evaluate this change, both are currently accepted. At some point in"]
#[doc =
r" the future, this may be disallowed at an edition boundary; but, that is"]
#[doc = r" undecided currently."]
pub static DEPRECATED_WHERE_CLAUSE_LOCATION: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_WHERE_CLAUSE_LOCATION",
default_level: crate::Warn,
desc: "deprecated where clause location",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3912/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3913 /// in an associated type.
3914 ///
3915 /// ### Example
3916 ///
3917 /// ```rust
3918 /// trait Trait {
3919 /// type Assoc<'a> where Self: 'a;
3920 /// }
3921 ///
3922 /// impl Trait for () {
3923 /// type Assoc<'a> where Self: 'a = ();
3924 /// }
3925 /// ```
3926 ///
3927 /// {{produces}}
3928 ///
3929 /// ### Explanation
3930 ///
3931 /// The preferred location for where clauses on associated types
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.
3937pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3938 Warn,
3939"deprecated where clause location"
3940}39413942#[doc =
r" The `test_unstable_lint` lint tests unstable lints and is perma-unstable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc =
r" // This lint is intentionally used to test the compiler's behavior"]
#[doc =
r" // when an unstable lint is enabled without the corresponding feature gate."]
#[doc = r" #![allow(test_unstable_lint)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In order to test the behavior of unstable lints, a permanently-unstable"]
#[doc =
r" lint is required. This lint can be used to trigger warnings and errors"]
#[doc = r" from the compiler related to unstable lints."]
pub static TEST_UNSTABLE_LINT: &crate::Lint =
&crate::Lint {
name: "TEST_UNSTABLE_LINT",
default_level: crate::Deny,
desc: "this unstable lint is only for testing",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::test_unstable_lint),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3943/// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3944 ///
3945 /// ### Example
3946 ///
3947 /// ```rust
3948 /// // This lint is intentionally used to test the compiler's behavior
3949 /// // when an unstable lint is enabled without the corresponding feature gate.
3950 /// #![allow(test_unstable_lint)]
3951 /// ```
3952 ///
3953 /// {{produces}}
3954 ///
3955 /// ### Explanation
3956 ///
3957 /// In order to test the behavior of unstable lints, a permanently-unstable
3958 /// lint is required. This lint can be used to trigger warnings and errors
3959 /// from the compiler related to unstable lints.
3960pub TEST_UNSTABLE_LINT,
3961 Deny,
3962"this unstable lint is only for testing",
3963 @feature_gate = test_unstable_lint;
3964}39653966#[doc =
r" The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with"]
#[doc = r" `C-unwind` or other FFI-unwind ABIs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![warn(ffi_unwind_calls)]"]
#[doc = r""]
#[doc = r#" unsafe extern "C-unwind" {"#]
#[doc = r" fn foo();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn bar() {"]
#[doc = r" unsafe { foo(); }"]
#[doc = r#" let ptr: unsafe extern "C-unwind" fn() = foo;"#]
#[doc = r" unsafe { ptr(); }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" For crates containing such calls, if they are compiled with `-C panic=unwind` then the"]
#[doc =
r" produced library cannot be linked with crates compiled with `-C panic=abort`. For crates"]
#[doc =
r" that desire this ability it is therefore necessary to avoid such calls."]
pub static FFI_UNWIND_CALLS: &crate::Lint =
&crate::Lint {
name: "FFI_UNWIND_CALLS",
default_level: crate::Allow,
desc: "call to foreign functions or function pointers with FFI-unwind ABI",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3967/// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3968 /// `C-unwind` or other FFI-unwind ABIs.
3969 ///
3970 /// ### Example
3971 ///
3972 /// ```rust
3973 /// #![warn(ffi_unwind_calls)]
3974 ///
3975 /// unsafe extern "C-unwind" {
3976 /// fn foo();
3977 /// }
3978 ///
3979 /// fn bar() {
3980 /// unsafe { foo(); }
3981 /// let ptr: unsafe extern "C-unwind" fn() = foo;
3982 /// unsafe { ptr(); }
3983 /// }
3984 /// ```
3985 ///
3986 /// {{produces}}
3987 ///
3988 /// ### Explanation
3989 ///
3990 /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3991 /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3992 /// that desire this ability it is therefore necessary to avoid such calls.
3993pub FFI_UNWIND_CALLS,
3994 Allow,
3995"call to foreign functions or function pointers with FFI-unwind ABI"
3996}39973998#[doc = r" The `linker_messages` lint forwards warnings from the linker."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs CLI args, platform-specific)"]
#[doc = r" #[warn(linker_messages)]"]
#[doc = r#" extern "C" {"#]
#[doc = r" fn foo();"]
#[doc = r" }"]
#[doc = r" fn main () { unsafe { foo(); } }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: linker stderr: rust-lld: undefined symbol: foo"]
#[doc = r" >>> referenced by rust_out.69edbd30df4ae57d-cgu.0"]
#[doc =
r" >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> warn.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![warn(linker_messages)]"]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" warning: 1 warning emitted"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Linkers emit platform-specific and program-specific warnings that cannot be predicted in"]
#[doc =
r" advance by the Rust compiler. Such messages are ignored by default for now. While linker"]
#[doc =
r" warnings could be very useful they have been ignored for many years by essentially all"]
#[doc =
r" users, so we need to do a bit more work than just surfacing their text to produce a clear"]
#[doc =
r" and actionable warning of similar quality to our other diagnostics. See this tracking"]
#[doc =
r" issue for more details: <https://github.com/rust-lang/rust/issues/136096>."]
pub static LINKER_MESSAGES: &crate::Lint =
&crate::Lint {
name: "LINKER_MESSAGES",
default_level: crate::Allow,
desc: "warnings emitted at runtime by the target-specific linker program",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3999/// The `linker_messages` lint forwards warnings from the linker.
4000 ///
4001 /// ### Example
4002 ///
4003 /// ```rust,ignore (needs CLI args, platform-specific)
4004 /// #[warn(linker_messages)]
4005 /// extern "C" {
4006 /// fn foo();
4007 /// }
4008 /// fn main () { unsafe { foo(); } }
4009 /// ```
4010 ///
4011 /// On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce
4012 ///
4013 /// ```text
4014 /// warning: linker stderr: rust-lld: undefined symbol: foo
4015 /// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
4016 /// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
4017 /// |
4018 /// note: the lint level is defined here
4019 /// --> warn.rs:1:9
4020 /// |
4021 /// 1 | #![warn(linker_messages)]
4022 /// | ^^^^^^^^^^^^^^^
4023 /// warning: 1 warning emitted
4024 /// ```
4025 ///
4026 /// ### Explanation
4027 ///
4028 /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
4029 /// advance by the Rust compiler. Such messages are ignored by default for now. While linker
4030 /// warnings could be very useful they have been ignored for many years by essentially all
4031 /// users, so we need to do a bit more work than just surfacing their text to produce a clear
4032 /// and actionable warning of similar quality to our other diagnostics. See this tracking
4033 /// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
4034pub LINKER_MESSAGES,
4035 Allow,
4036"warnings emitted at runtime by the target-specific linker program"
4037}40384039#[doc =
r" The `named_arguments_used_positionally` lint detects cases where named arguments are only"]
#[doc =
r" used positionally in format strings. This usage is valid but potentially very confusing."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(named_arguments_used_positionally)]"]
#[doc = r" fn main() {"]
#[doc = r" let _x = 5;"]
#[doc = r#" println!("{}", _x = 1); // Prints 1, will trigger lint"#]
#[doc = r""]
#[doc = r#" println!("{}", _x); // Prints 5, no lint emitted"#]
#[doc = r#" println!("{_x}", _x = _x); // Prints 5, no lint emitted"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust formatting strings can refer to named arguments by their position, but this usage is"]
#[doc =
r" potentially confusing. In particular, readers can incorrectly assume that the declaration"]
#[doc =
r" of named arguments is an assignment (which would produce the unit type)."]
#[doc = r" For backwards compatibility, this is not a hard error."]
pub static NAMED_ARGUMENTS_USED_POSITIONALLY: &crate::Lint =
&crate::Lint {
name: "NAMED_ARGUMENTS_USED_POSITIONALLY",
default_level: crate::Warn,
desc: "named arguments in format used positionally",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4040/// The `named_arguments_used_positionally` lint detects cases where named arguments are only
4041 /// used positionally in format strings. This usage is valid but potentially very confusing.
4042 ///
4043 /// ### Example
4044 ///
4045 /// ```rust,compile_fail
4046 /// #![deny(named_arguments_used_positionally)]
4047 /// fn main() {
4048 /// let _x = 5;
4049 /// println!("{}", _x = 1); // Prints 1, will trigger lint
4050 ///
4051 /// println!("{}", _x); // Prints 5, no lint emitted
4052 /// println!("{_x}", _x = _x); // Prints 5, no lint emitted
4053 /// }
4054 /// ```
4055 ///
4056 /// {{produces}}
4057 ///
4058 /// ### Explanation
4059 ///
4060 /// Rust formatting strings can refer to named arguments by their position, but this usage is
4061 /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4062 /// of named arguments is an assignment (which would produce the unit type).
4063 /// For backwards compatibility, this is not a hard error.
4064pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4065 Warn,
4066"named arguments in format used positionally"
4067}40684069#[doc =
r" The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback"]
#[doc = r" affects unsafe function calls."]
#[doc = r""]
#[doc = r" ### Never type fallback"]
#[doc = r""]
#[doc =
r" When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),"]
#[doc = r" to allow type check to infer any type:"]
#[doc = r""]
#[doc = r" ```ignore (illustrative-and-has-placeholders)"]
#[doc = r" // this"]
#[doc = r" let x: u8 = panic!();"]
#[doc = r""]
#[doc = r" // is (essentially) turned by the compiler into"]
#[doc = r" let x: u8 = absurd(panic!());"]
#[doc = r""]
#[doc = r" // where absurd is a function with the following signature"]
#[doc = r" // (it's sound, because `!` always marks unreachable code):"]
#[doc = r" fn absurd<T>(never: !) -> T { ... }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" While it's convenient to be able to use non-diverging code in one of the branches (like"]
#[doc =
r" `if a { b } else { return }`) this could lead to compilation errors:"]
#[doc = r""]
#[doc = r" ```compile_fail"]
#[doc = r" // this"]
#[doc = r" { panic!() };"]
#[doc = r""]
#[doc = r" // gets turned into this"]
#[doc = r" { absurd(panic!()) }; // error: can't infer the type of `absurd`"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it"]
#[doc =
r" can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`."]
#[doc = r#" This is what is known as "never type fallback"."#]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" fn main() {"]
#[doc = r" if true {"]
#[doc =
r" // return has type `!` which, is some cases, causes never type fallback"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // `zeroed` is an unsafe function, which returns an unbounded type"]
#[doc = r" unsafe { std::mem::zeroed() }"]
#[doc = r" };"]
#[doc =
r" // depending on the fallback, `zeroed` may create `()` (which is completely sound),"]
#[doc = r" // or `!` (which is instant undefined behavior)"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously"]
#[doc =
r" coerced to `()`. There are plans to change that, but they may make the code such as above"]
#[doc =
r" unsound. Instead of depending on the fallback, you should specify the type explicitly:"]
#[doc = r" ```"]
#[doc = r" if true {"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // type is explicitly specified, fallback can't hurt us no more"]
#[doc = r" unsafe { std::mem::zeroed::<()>() }"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748)."]
#[doc = r""]
#[doc = r" [`!`]: https://doc.rust-lang.org/core/primitive.never.html"]
#[doc = r" [`()`]: https://doc.rust-lang.org/core/primitive.unit.html"]
pub static NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE: &crate::Lint =
&crate::Lint {
name: "NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE",
default_level: crate::Deny,
desc: "never type fallback affecting unsafe function calls",
is_externally_loaded: false,
report_in_external_macro: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "never-type-fallback",
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
edition_lint_opts: Some((crate::Edition::Edition2024,
crate::Deny)),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4070/// The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback
4071 /// affects unsafe function calls.
4072 ///
4073 /// ### Never type fallback
4074 ///
4075 /// When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),
4076 /// to allow type check to infer any type:
4077 ///
4078 /// ```ignore (illustrative-and-has-placeholders)
4079 /// // this
4080 /// let x: u8 = panic!();
4081 ///
4082 /// // is (essentially) turned by the compiler into
4083 /// let x: u8 = absurd(panic!());
4084 ///
4085 /// // where absurd is a function with the following signature
4086 /// // (it's sound, because `!` always marks unreachable code):
4087 /// fn absurd<T>(never: !) -> T { ... }
4088 /// ```
4089 ///
4090 /// While it's convenient to be able to use non-diverging code in one of the branches (like
4091 /// `if a { b } else { return }`) this could lead to compilation errors:
4092 ///
4093 /// ```compile_fail
4094 /// // this
4095 /// { panic!() };
4096 ///
4097 /// // gets turned into this
4098 /// { absurd(panic!()) }; // error: can't infer the type of `absurd`
4099 /// ```
4100 ///
4101 /// To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it
4102 /// can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`.
4103 /// This is what is known as "never type fallback".
4104 ///
4105 /// ### Example
4106 ///
4107 /// ```rust,compile_fail
4108 /// fn main() {
4109 /// if true {
4110 /// // return has type `!` which, is some cases, causes never type fallback
4111 /// return
4112 /// } else {
4113 /// // `zeroed` is an unsafe function, which returns an unbounded type
4114 /// unsafe { std::mem::zeroed() }
4115 /// };
4116 /// // depending on the fallback, `zeroed` may create `()` (which is completely sound),
4117 /// // or `!` (which is instant undefined behavior)
4118 /// }
4119 /// ```
4120 ///
4121 /// {{produces}}
4122 ///
4123 /// ### Explanation
4124 ///
4125 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4126 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4127 /// unsound. Instead of depending on the fallback, you should specify the type explicitly:
4128 /// ```
4129 /// if true {
4130 /// return
4131 /// } else {
4132 /// // type is explicitly specified, fallback can't hurt us no more
4133 /// unsafe { std::mem::zeroed::<()>() }
4134 /// };
4135 /// ```
4136 ///
4137 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4138 ///
4139 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4140 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4141pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
4142 Deny,
4143"never type fallback affecting unsafe function calls",
4144 @future_incompatible = FutureIncompatibleInfo {
4145 reason: fcw!(EditionAndFutureReleaseSemanticsChange 2024 "never-type-fallback"),
4146 report_in_deps: true,
4147 };
4148 @edition Edition2024 => Deny;
4149 report_in_external_macro
4150}41514152#[doc =
r" The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with"]
#[doc =
r" [never type fallback] being [`()`], but will stop compiling with fallback being [`!`]."]
#[doc = r""]
#[doc =
r" [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback"]
#[doc = r" [`!`]: https://doc.rust-lang.org/core/primitive.never.html"]
#[doc = r" [`()`]: https://doc.rust-lang.org/core/primitive.unit.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail,edition2021"]
#[doc = r" # #![deny(dependency_on_unit_never_type_fallback)]"]
#[doc = r" fn main() {"]
#[doc = r" if true {"]
#[doc =
r" // return has type `!` which, is some cases, causes never type fallback"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // the type produced by this call is not specified explicitly,"]
#[doc = r" // so it will be inferred from the previous branch"]
#[doc = r" Default::default()"]
#[doc = r" };"]
#[doc =
r" // depending on the fallback, this may compile (because `()` implements `Default`),"]
#[doc = r" // or it may not (because `!` does not implement `Default`)"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously"]
#[doc =
r" coerced to `()`. There are plans to change that, but they may make the code such as above"]
#[doc =
r" not compile. Instead of depending on the fallback, you should specify the type explicitly:"]
#[doc = r" ```"]
#[doc = r" if true {"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // type is explicitly specified, fallback can't hurt us no more"]
#[doc = r" <() as Default>::default()"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748)."]
pub static DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK: &crate::Lint =
&crate::Lint {
name: "DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK",
default_level: crate::Deny,
desc: "never type fallback affecting unsafe function calls",
is_externally_loaded: false,
report_in_external_macro: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionAndFutureReleaseError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "never-type-fallback",
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4153/// The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with
4154 /// [never type fallback] being [`()`], but will stop compiling with fallback being [`!`].
4155 ///
4156 /// [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback
4157 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4158 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4159 ///
4160 /// ### Example
4161 ///
4162 /// ```rust,compile_fail,edition2021
4163 /// # #![deny(dependency_on_unit_never_type_fallback)]
4164 /// fn main() {
4165 /// if true {
4166 /// // return has type `!` which, is some cases, causes never type fallback
4167 /// return
4168 /// } else {
4169 /// // the type produced by this call is not specified explicitly,
4170 /// // so it will be inferred from the previous branch
4171 /// Default::default()
4172 /// };
4173 /// // depending on the fallback, this may compile (because `()` implements `Default`),
4174 /// // or it may not (because `!` does not implement `Default`)
4175 /// }
4176 /// ```
4177 ///
4178 /// {{produces}}
4179 ///
4180 /// ### Explanation
4181 ///
4182 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4183 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4184 /// not compile. Instead of depending on the fallback, you should specify the type explicitly:
4185 /// ```
4186 /// if true {
4187 /// return
4188 /// } else {
4189 /// // type is explicitly specified, fallback can't hurt us no more
4190 /// <() as Default>::default()
4191 /// };
4192 /// ```
4193 ///
4194 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4195pub DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
4196 Deny,
4197"never type fallback affecting unsafe function calls",
4198 @future_incompatible = FutureIncompatibleInfo {
4199 reason: fcw!(EditionAndFutureReleaseError 2024 "never-type-fallback"),
4200 report_in_deps: true,
4201 };
4202 report_in_external_macro
4203}42044205#[doc =
r" The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(invalid_macro_export_arguments)]"]
#[doc = r""]
#[doc = r" #[macro_export(invalid_parameter)]"]
#[doc = r" macro_rules! myMacro {"]
#[doc = r" () => {"]
#[doc = r" // [...]"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[macro_export(too, many, items)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`)."]
#[doc =
r" You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`."]
#[doc = r""]
pub static INVALID_MACRO_EXPORT_ARGUMENTS: &crate::Lint =
&crate::Lint {
name: "INVALID_MACRO_EXPORT_ARGUMENTS",
default_level: crate::Deny,
desc: "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57571,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4206/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
4207 ///
4208 /// ### Example
4209 ///
4210 /// ```rust,compile_fail
4211 /// #![deny(invalid_macro_export_arguments)]
4212 ///
4213 /// #[macro_export(invalid_parameter)]
4214 /// macro_rules! myMacro {
4215 /// () => {
4216 /// // [...]
4217 /// }
4218 /// }
4219 ///
4220 /// #[macro_export(too, many, items)]
4221 /// ```
4222 ///
4223 /// {{produces}}
4224 ///
4225 /// ### Explanation
4226 ///
4227 /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
4228 /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
4229 ///
4230pub INVALID_MACRO_EXPORT_ARGUMENTS,
4231 Deny,
4232"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
4233 @future_incompatible = FutureIncompatibleInfo {
4234 reason: fcw!(FutureReleaseError #57571),
4235 report_in_deps: true,
4236 };
4237}42384239#[doc =
r" The `private_interfaces` lint detects types in a primary interface of an item,"]
#[doc =
r" that are more private than the item itself. Primary interface of an item is all"]
#[doc =
r" its interface except for bounds on generic parameters and where clauses."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(private_interfaces)]"]
#[doc = r" struct SemiPriv;"]
#[doc = r""]
#[doc = r" mod m1 {"]
#[doc = r" struct Priv;"]
#[doc = r" impl crate::SemiPriv {"]
#[doc = r" pub fn f(_: Priv) {}"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Having something private in primary interface guarantees that"]
#[doc = r" the item will be unusable from outer modules due to type privacy."]
pub static PRIVATE_INTERFACES: &crate::Lint =
&crate::Lint {
name: "PRIVATE_INTERFACES",
default_level: crate::Warn,
desc: "private type in primary interface of an item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4240/// The `private_interfaces` lint detects types in a primary interface of an item,
4241 /// that are more private than the item itself. Primary interface of an item is all
4242 /// its interface except for bounds on generic parameters and where clauses.
4243 ///
4244 /// ### Example
4245 ///
4246 /// ```rust,compile_fail
4247 /// # #![allow(unused)]
4248 /// #![deny(private_interfaces)]
4249 /// struct SemiPriv;
4250 ///
4251 /// mod m1 {
4252 /// struct Priv;
4253 /// impl crate::SemiPriv {
4254 /// pub fn f(_: Priv) {}
4255 /// }
4256 /// }
4257 ///
4258 /// # fn main() {}
4259 /// ```
4260 ///
4261 /// {{produces}}
4262 ///
4263 /// ### Explanation
4264 ///
4265 /// Having something private in primary interface guarantees that
4266 /// the item will be unusable from outer modules due to type privacy.
4267pub PRIVATE_INTERFACES,
4268 Warn,
4269"private type in primary interface of an item",
4270}42714272#[doc =
r" The `private_bounds` lint detects types in a secondary interface of an item,"]
#[doc =
r" that are more private than the item itself. Secondary interface of an item consists of"]
#[doc =
r" bounds on generic parameters and where clauses, including supertraits for trait items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(private_bounds)]"]
#[doc = r""]
#[doc = r" struct PrivTy;"]
#[doc = r" pub struct S"]
#[doc = r" where PrivTy:"]
#[doc = r" {}"]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Having private types or traits in item bounds makes it less clear what interface"]
#[doc = r" the item actually provides."]
pub static PRIVATE_BOUNDS: &crate::Lint =
&crate::Lint {
name: "PRIVATE_BOUNDS",
default_level: crate::Warn,
desc: "private type in secondary interface of an item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4273/// The `private_bounds` lint detects types in a secondary interface of an item,
4274 /// that are more private than the item itself. Secondary interface of an item consists of
4275 /// bounds on generic parameters and where clauses, including supertraits for trait items.
4276 ///
4277 /// ### Example
4278 ///
4279 /// ```rust,compile_fail
4280 /// # #![allow(unused)]
4281 /// #![deny(private_bounds)]
4282 ///
4283 /// struct PrivTy;
4284 /// pub struct S
4285 /// where PrivTy:
4286 /// {}
4287 /// # fn main() {}
4288 /// ```
4289 ///
4290 /// {{produces}}
4291 ///
4292 /// ### Explanation
4293 ///
4294 /// Having private types or traits in item bounds makes it less clear what interface
4295 /// the item actually provides.
4296pub PRIVATE_BOUNDS,
4297 Warn,
4298"private type in secondary interface of an item",
4299}43004301#[doc =
r" The `unnameable_types` lint detects types for which you can get objects of that type,"]
#[doc = r" but cannot name the type itself."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(unnameable_types)]"]
#[doc = r" mod m {"]
#[doc = r" pub struct S;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub fn get_unnameable() -> m::S { m::S }"]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is often expected that if you can obtain an object of type `T`, then"]
#[doc =
r" you can name the type `T` as well; this lint attempts to enforce this rule."]
#[doc =
r" The recommended action is to either reexport the type properly to make it nameable,"]
#[doc =
r" or document that users are not supposed to be able to name it for one reason or another."]
#[doc = r""]
#[doc =
r" Besides types, this lint applies to traits because traits can also leak through signatures,"]
#[doc =
r" and you may obtain objects of their `dyn Trait` or `impl Trait` types."]
pub static UNNAMEABLE_TYPES: &crate::Lint =
&crate::Lint {
name: "UNNAMEABLE_TYPES",
default_level: crate::Allow,
desc: "effective visibility of a type is larger than the area in which it can be named",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4302/// The `unnameable_types` lint detects types for which you can get objects of that type,
4303 /// but cannot name the type itself.
4304 ///
4305 /// ### Example
4306 ///
4307 /// ```rust,compile_fail
4308 /// # #![allow(unused)]
4309 /// #![deny(unnameable_types)]
4310 /// mod m {
4311 /// pub struct S;
4312 /// }
4313 ///
4314 /// pub fn get_unnameable() -> m::S { m::S }
4315 /// # fn main() {}
4316 /// ```
4317 ///
4318 /// {{produces}}
4319 ///
4320 /// ### Explanation
4321 ///
4322 /// It is often expected that if you can obtain an object of type `T`, then
4323 /// you can name the type `T` as well; this lint attempts to enforce this rule.
4324 /// The recommended action is to either reexport the type properly to make it nameable,
4325 /// or document that users are not supposed to be able to name it for one reason or another.
4326 ///
4327 /// Besides types, this lint applies to traits because traits can also leak through signatures,
4328 /// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
4329pub UNNAMEABLE_TYPES,
4330 Allow,
4331"effective visibility of a type is larger than the area in which it can be named",
4332}43334334#[doc =
r" The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r#" #[diagnostic::do_not_recommend(message = "message")]"#]
#[doc = r" trait Trait {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to use options or syntax that is not supported. Check the spelling,"]
#[doc =
r" and check the diagnostic attribute listing for the correct name and syntax. Also consider if"]
#[doc =
r" you are using an old version of the compiler; perhaps the option or syntax is only available"]
#[doc =
r" in a newer version. See the [reference] for a list of diagnostic attributes and the syntax"]
#[doc = r" of each."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MALFORMED_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "MALFORMED_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects malformed diagnostic attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4335/// The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes.
4336 ///
4337 /// ### Example
4338 ///
4339 /// ```rust
4340 /// #[diagnostic::do_not_recommend(message = "message")]
4341 /// trait Trait {}
4342 /// ```
4343 ///
4344 /// {{produces}}
4345 ///
4346 /// ### Explanation
4347 ///
4348 /// It is usually a mistake to use options or syntax that is not supported. Check the spelling,
4349 /// and check the diagnostic attribute listing for the correct name and syntax. Also consider if
4350 /// you are using an old version of the compiler; perhaps the option or syntax is only available
4351 /// in a newer version. See the [reference] for a list of diagnostic attributes and the syntax
4352 /// of each.
4353 ///
4354 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4355pub MALFORMED_DIAGNOSTIC_ATTRIBUTES,
4356 Warn,
4357"detects malformed diagnostic attributes",
4358}43594360#[doc =
r" The `misplaced_diagnostic_attributes` lint detects wrongly placed diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[diagnostic::do_not_recommend]"]
#[doc = r" struct NotUserFacing;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a diagnostic attribute on an item it is not meant for."]
#[doc =
r" For example, `#[diagnostic::do_not_recommend]` can only be placed on trait implementations,"]
#[doc =
r" and does nothing if placed elsewhere. See the [reference] for a list of diagnostic"]
#[doc = r" attributes and their correct positions."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MISPLACED_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "MISPLACED_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects diagnostic attributes that are placed on the wrong item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4361/// The `misplaced_diagnostic_attributes` lint detects wrongly placed diagnostic attributes.
4362 ///
4363 /// ### Example
4364 ///
4365 /// ```rust
4366 /// #[diagnostic::do_not_recommend]
4367 /// struct NotUserFacing;
4368 /// ```
4369 ///
4370 /// {{produces}}
4371 ///
4372 /// ### Explanation
4373 ///
4374 /// It is usually a mistake to specify a diagnostic attribute on an item it is not meant for.
4375 /// For example, `#[diagnostic::do_not_recommend]` can only be placed on trait implementations,
4376 /// and does nothing if placed elsewhere. See the [reference] for a list of diagnostic
4377 /// attributes and their correct positions.
4378 ///
4379 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4380pub MISPLACED_DIAGNOSTIC_ATTRIBUTES,
4381 Warn,
4382"detects diagnostic attributes that are placed on the wrong item",
4383}43844385#[doc =
r" The `unknown_diagnostic_attributes` lint detects unknown diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[diagnostic::does_not_exist]"]
#[doc = r" struct Thing;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a diagnostic attribute that does not exist. Check the"]
#[doc =
r" spelling, and check the diagnostic attribute listing for the correct name. Also consider if"]
#[doc =
r" you are using an old version of the compiler and the attribute is only available in a newer"]
#[doc =
r" version. See the [reference] for the list of diagnostic attributes."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static UNKNOWN_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects unknown diagnostic attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4386/// The `unknown_diagnostic_attributes` lint detects unknown diagnostic attributes.
4387 ///
4388 /// ### Example
4389 ///
4390 /// ```rust
4391 /// #[diagnostic::does_not_exist]
4392 /// struct Thing;
4393 /// ```
4394 ///
4395 /// {{produces}}
4396 ///
4397 /// ### Explanation
4398 ///
4399 /// It is usually a mistake to specify a diagnostic attribute that does not exist. Check the
4400 /// spelling, and check the diagnostic attribute listing for the correct name. Also consider if
4401 /// you are using an old version of the compiler and the attribute is only available in a newer
4402 /// version. See the [reference] for the list of diagnostic attributes.
4403 ///
4404 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4405pub UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
4406 Warn,
4407"detects unknown diagnostic attributes",
4408}44094410#[doc =
r" The `malformed_diagnostic_format_literals` lint detects malformed diagnostic format"]
#[doc = r" literals."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc =
r#" #[diagnostic::on_unimplemented(message = "{Self}} does not implement `Trait`")]"#]
#[doc = r" trait Trait {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `#[diagnostic::on_unimplemented]` attribute accepts string literal values that are"]
#[doc =
r" similar to `format!`'s string literal. See the [reference] for details on what is permitted"]
#[doc = r" in this string literal."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MALFORMED_DIAGNOSTIC_FORMAT_LITERALS: &crate::Lint =
&crate::Lint {
name: "MALFORMED_DIAGNOSTIC_FORMAT_LITERALS",
default_level: crate::Warn,
desc: "detects diagnostic attribute with malformed diagnostic format literals",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4411/// The `malformed_diagnostic_format_literals` lint detects malformed diagnostic format
4412 /// literals.
4413 ///
4414 /// ### Example
4415 ///
4416 /// ```rust
4417 /// #[diagnostic::on_unimplemented(message = "{Self}} does not implement `Trait`")]
4418 /// trait Trait {}
4419 /// ```
4420 ///
4421 /// {{produces}}
4422 ///
4423 /// ### Explanation
4424 ///
4425 /// The `#[diagnostic::on_unimplemented]` attribute accepts string literal values that are
4426 /// similar to `format!`'s string literal. See the [reference] for details on what is permitted
4427 /// in this string literal.
4428 ///
4429 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4430pub MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
4431 Warn,
4432"detects diagnostic attribute with malformed diagnostic format literals",
4433}4434#[doc =
r" The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity"]
#[doc = r" errors, but previously didn't do that due to rustc bugs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_glob_imports)]"]
#[doc = r" pub fn foo() -> u32 {"]
#[doc = r" use sub::*;"]
#[doc = r" C"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" mod sub {"]
#[doc = r" mod mod1 { pub const C: u32 = 1; }"]
#[doc = r" mod mod2 { pub const C: u32 = 2; }"]
#[doc = r""]
#[doc = r" pub use mod1::*;"]
#[doc = r" pub use mod2::*;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust compile it successfully because it"]
#[doc = r" had lost the ambiguity error when resolve `use sub::mod2::*`."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_GLOB_IMPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_IMPORTS",
default_level: crate::Warn,
desc: "detects certain glob imports that require reporting an ambiguity error",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 114095,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4435/// The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity
4436 /// errors, but previously didn't do that due to rustc bugs.
4437 ///
4438 /// ### Example
4439 ///
4440 /// ```rust,compile_fail
4441 /// #![deny(ambiguous_glob_imports)]
4442 /// pub fn foo() -> u32 {
4443 /// use sub::*;
4444 /// C
4445 /// }
4446 ///
4447 /// mod sub {
4448 /// mod mod1 { pub const C: u32 = 1; }
4449 /// mod mod2 { pub const C: u32 = 2; }
4450 ///
4451 /// pub use mod1::*;
4452 /// pub use mod2::*;
4453 /// }
4454 /// ```
4455 ///
4456 /// {{produces}}
4457 ///
4458 /// ### Explanation
4459 ///
4460 /// Previous versions of Rust compile it successfully because it
4461 /// had lost the ambiguity error when resolve `use sub::mod2::*`.
4462 ///
4463 /// This is a [future-incompatible] lint to transition this to a
4464 /// hard error in the future.
4465 ///
4466 /// [future-incompatible]: ../index.md#future-incompatible-lints
4467pub AMBIGUOUS_GLOB_IMPORTS,
4468 Warn,
4469"detects certain glob imports that require reporting an ambiguity error",
4470 @future_incompatible = FutureIncompatibleInfo {
4471 reason: fcw!(FutureReleaseError #114095),
4472 report_in_deps: true,
4473 };
4474}44754476#[doc =
r" The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but"]
#[doc =
r" previously didn't do that due to `#[macro_use]` prelude macro import."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_panic_imports)]"]
#[doc = r" #![no_std]"]
#[doc = r""]
#[doc = r" extern crate std;"]
#[doc = r" use std::prelude::v1::*;"]
#[doc = r""]
#[doc = r" fn xx() {"]
#[doc = r" panic!(); // resolves to core::panic"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Future versions of Rust will no longer accept the ambiguous resolution."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_PANIC_IMPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_PANIC_IMPORTS",
default_level: crate::Warn,
desc: "detects ambiguous core and std panic imports",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 147319,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4477/// The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but
4478 /// previously didn't do that due to `#[macro_use]` prelude macro import.
4479 ///
4480 /// ### Example
4481 ///
4482 /// ```rust,compile_fail
4483 /// #![deny(ambiguous_panic_imports)]
4484 /// #![no_std]
4485 ///
4486 /// extern crate std;
4487 /// use std::prelude::v1::*;
4488 ///
4489 /// fn xx() {
4490 /// panic!(); // resolves to core::panic
4491 /// }
4492 /// ```
4493 ///
4494 /// {{produces}}
4495 ///
4496 /// ### Explanation
4497 ///
4498 /// Future versions of Rust will no longer accept the ambiguous resolution.
4499 ///
4500 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
4501 ///
4502 /// [future-incompatible]: ../index.md#future-incompatible-lints
4503pub AMBIGUOUS_PANIC_IMPORTS,
4504 Warn,
4505"detects ambiguous core and std panic imports",
4506 @future_incompatible = FutureIncompatibleInfo {
4507 reason: fcw!(FutureReleaseError #147319),
4508 report_in_deps: false,
4509 };
4510}45114512#[doc =
r" The `refining_impl_trait_reachable` lint detects `impl Trait` return"]
#[doc =
r" types in method signatures that are refined by a publically reachable"]
#[doc =
r" trait implementation, meaning the implementation adds information about"]
#[doc = r" the return type that is not present in the trait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(refining_impl_trait)]"]
#[doc = r""]
#[doc = r" use std::fmt::Display;"]
#[doc = r""]
#[doc = r" pub trait AsDisplay {"]
#[doc = r" fn as_display(&self) -> impl Display;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<'s> AsDisplay for &'s str {"]
#[doc = r" fn as_display(&self) -> Self {"]
#[doc = r" *self"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" // users can observe that the return type of"]
#[doc = r" // `<&str as AsDisplay>::as_display()` is `&str`."]
#[doc = r#" let _x: &str = "".as_display();"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Callers of methods for types where the implementation is known are"]
#[doc =
r" able to observe the types written in the impl signature. This may be"]
#[doc =
r" intended behavior, but may also lead to implementation details being"]
#[doc =
r" revealed unintentionally. In particular, it may pose a semver hazard"]
#[doc =
r" for authors of libraries who do not wish to make stronger guarantees"]
#[doc = r" about the types than what is written in the trait signature."]
#[doc = r""]
#[doc = r" `refining_impl_trait` is a lint group composed of two lints:"]
#[doc = r""]
#[doc =
r" * `refining_impl_trait_reachable`, for refinements that are publically"]
#[doc = r" reachable outside a crate, and"]
#[doc =
r" * `refining_impl_trait_internal`, for refinements that are only visible"]
#[doc = r" within a crate."]
#[doc = r""]
#[doc = r" We are seeking feedback on each of these lints; see issue"]
#[doc =
r" [#121718](https://github.com/rust-lang/rust/issues/121718) for more"]
#[doc = r" information."]
pub static REFINING_IMPL_TRAIT_REACHABLE: &crate::Lint =
&crate::Lint {
name: "REFINING_IMPL_TRAIT_REACHABLE",
default_level: crate::Warn,
desc: "impl trait in impl method signature does not match trait method signature",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4513/// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4514 /// types in method signatures that are refined by a publically reachable
4515 /// trait implementation, meaning the implementation adds information about
4516 /// the return type that is not present in the trait.
4517 ///
4518 /// ### Example
4519 ///
4520 /// ```rust,compile_fail
4521 /// #![deny(refining_impl_trait)]
4522 ///
4523 /// use std::fmt::Display;
4524 ///
4525 /// pub trait AsDisplay {
4526 /// fn as_display(&self) -> impl Display;
4527 /// }
4528 ///
4529 /// impl<'s> AsDisplay for &'s str {
4530 /// fn as_display(&self) -> Self {
4531 /// *self
4532 /// }
4533 /// }
4534 ///
4535 /// fn main() {
4536 /// // users can observe that the return type of
4537 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4538 /// let _x: &str = "".as_display();
4539 /// }
4540 /// ```
4541 ///
4542 /// {{produces}}
4543 ///
4544 /// ### Explanation
4545 ///
4546 /// Callers of methods for types where the implementation is known are
4547 /// able to observe the types written in the impl signature. This may be
4548 /// intended behavior, but may also lead to implementation details being
4549 /// revealed unintentionally. In particular, it may pose a semver hazard
4550 /// for authors of libraries who do not wish to make stronger guarantees
4551 /// about the types than what is written in the trait signature.
4552 ///
4553 /// `refining_impl_trait` is a lint group composed of two lints:
4554 ///
4555 /// * `refining_impl_trait_reachable`, for refinements that are publically
4556 /// reachable outside a crate, and
4557 /// * `refining_impl_trait_internal`, for refinements that are only visible
4558 /// within a crate.
4559 ///
4560 /// We are seeking feedback on each of these lints; see issue
4561 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4562 /// information.
4563pub REFINING_IMPL_TRAIT_REACHABLE,
4564 Warn,
4565"impl trait in impl method signature does not match trait method signature",
4566}45674568#[doc =
r" The `refining_impl_trait_internal` lint detects `impl Trait` return"]
#[doc =
r" types in method signatures that are refined by a trait implementation,"]
#[doc =
r" meaning the implementation adds information about the return type that"]
#[doc = r" is not present in the trait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(refining_impl_trait)]"]
#[doc = r""]
#[doc = r" use std::fmt::Display;"]
#[doc = r""]
#[doc = r" trait AsDisplay {"]
#[doc = r" fn as_display(&self) -> impl Display;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<'s> AsDisplay for &'s str {"]
#[doc = r" fn as_display(&self) -> Self {"]
#[doc = r" *self"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" // users can observe that the return type of"]
#[doc = r" // `<&str as AsDisplay>::as_display()` is `&str`."]
#[doc = r#" let _x: &str = "".as_display();"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Callers of methods for types where the implementation is known are"]
#[doc =
r" able to observe the types written in the impl signature. This may be"]
#[doc =
r" intended behavior, but may also lead to implementation details being"]
#[doc =
r" revealed unintentionally. In particular, it may pose a semver hazard"]
#[doc =
r" for authors of libraries who do not wish to make stronger guarantees"]
#[doc = r" about the types than what is written in the trait signature."]
#[doc = r""]
#[doc = r" `refining_impl_trait` is a lint group composed of two lints:"]
#[doc = r""]
#[doc =
r" * `refining_impl_trait_reachable`, for refinements that are publically"]
#[doc = r" reachable outside a crate, and"]
#[doc =
r" * `refining_impl_trait_internal`, for refinements that are only visible"]
#[doc = r" within a crate."]
#[doc = r""]
#[doc = r" We are seeking feedback on each of these lints; see issue"]
#[doc =
r" [#121718](https://github.com/rust-lang/rust/issues/121718) for more"]
#[doc = r" information."]
pub static REFINING_IMPL_TRAIT_INTERNAL: &crate::Lint =
&crate::Lint {
name: "REFINING_IMPL_TRAIT_INTERNAL",
default_level: crate::Warn,
desc: "impl trait in impl method signature does not match trait method signature",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4569/// The `refining_impl_trait_internal` lint detects `impl Trait` return
4570 /// types in method signatures that are refined by a trait implementation,
4571 /// meaning the implementation adds information about the return type that
4572 /// is not present in the trait.
4573 ///
4574 /// ### Example
4575 ///
4576 /// ```rust,compile_fail
4577 /// #![deny(refining_impl_trait)]
4578 ///
4579 /// use std::fmt::Display;
4580 ///
4581 /// trait AsDisplay {
4582 /// fn as_display(&self) -> impl Display;
4583 /// }
4584 ///
4585 /// impl<'s> AsDisplay for &'s str {
4586 /// fn as_display(&self) -> Self {
4587 /// *self
4588 /// }
4589 /// }
4590 ///
4591 /// fn main() {
4592 /// // users can observe that the return type of
4593 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4594 /// let _x: &str = "".as_display();
4595 /// }
4596 /// ```
4597 ///
4598 /// {{produces}}
4599 ///
4600 /// ### Explanation
4601 ///
4602 /// Callers of methods for types where the implementation is known are
4603 /// able to observe the types written in the impl signature. This may be
4604 /// intended behavior, but may also lead to implementation details being
4605 /// revealed unintentionally. In particular, it may pose a semver hazard
4606 /// for authors of libraries who do not wish to make stronger guarantees
4607 /// about the types than what is written in the trait signature.
4608 ///
4609 /// `refining_impl_trait` is a lint group composed of two lints:
4610 ///
4611 /// * `refining_impl_trait_reachable`, for refinements that are publically
4612 /// reachable outside a crate, and
4613 /// * `refining_impl_trait_internal`, for refinements that are only visible
4614 /// within a crate.
4615 ///
4616 /// We are seeking feedback on each of these lints; see issue
4617 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4618 /// information.
4619pub REFINING_IMPL_TRAIT_INTERNAL,
4620 Warn,
4621"impl trait in impl method signature does not match trait method signature",
4622}46234624#[doc =
r" The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes"]
#[doc =
r" in associated constants when there are other lifetimes in scope. This was"]
#[doc =
r" accidentally supported, and this lint was later relaxed to allow eliding"]
#[doc = r" lifetimes to `'static` when there are no lifetimes in scope."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(elided_lifetimes_in_associated_constant)]"]
#[doc = r""]
#[doc = r" struct Foo<'a>(&'a ());"]
#[doc = r""]
#[doc = r" impl<'a> Foo<'a> {"]
#[doc = r#" const STR: &str = "hello, world";"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous version of Rust"]
#[doc = r""]
#[doc =
r" Implicit static-in-const behavior was decided [against] for associated"]
#[doc =
r" constants because of ambiguity. This, however, regressed and the compiler"]
#[doc =
r" erroneously treats elided lifetimes in associated constants as lifetime"]
#[doc = r" parameters on the impl."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [against]: https://github.com/rust-lang/rust/issues/38831"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT: &crate::Lint =
&crate::Lint {
name: "ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT",
default_level: crate::Deny,
desc: "elided lifetimes cannot be used in associated constants in impls",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 115010,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4625/// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
4626 /// in associated constants when there are other lifetimes in scope. This was
4627 /// accidentally supported, and this lint was later relaxed to allow eliding
4628 /// lifetimes to `'static` when there are no lifetimes in scope.
4629 ///
4630 /// ### Example
4631 ///
4632 /// ```rust,compile_fail
4633 /// #![deny(elided_lifetimes_in_associated_constant)]
4634 ///
4635 /// struct Foo<'a>(&'a ());
4636 ///
4637 /// impl<'a> Foo<'a> {
4638 /// const STR: &str = "hello, world";
4639 /// }
4640 /// ```
4641 ///
4642 /// {{produces}}
4643 ///
4644 /// ### Explanation
4645 ///
4646 /// Previous version of Rust
4647 ///
4648 /// Implicit static-in-const behavior was decided [against] for associated
4649 /// constants because of ambiguity. This, however, regressed and the compiler
4650 /// erroneously treats elided lifetimes in associated constants as lifetime
4651 /// parameters on the impl.
4652 ///
4653 /// This is a [future-incompatible] lint to transition this to a
4654 /// hard error in the future.
4655 ///
4656 /// [against]: https://github.com/rust-lang/rust/issues/38831
4657 /// [future-incompatible]: ../index.md#future-incompatible-lints
4658pub ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
4659 Deny,
4660"elided lifetimes cannot be used in associated constants in impls",
4661 @future_incompatible = FutureIncompatibleInfo {
4662 reason: fcw!(FutureReleaseError #115010),
4663 };
4664}46654666#[doc =
r" The `private_macro_use` lint detects private macros that are imported"]
#[doc = r" with `#[macro_use]`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" // extern_macro.rs"]
#[doc = r" macro_rules! foo_ { () => {}; }"]
#[doc = r" use foo_ as foo;"]
#[doc = r""]
#[doc = r" // code.rs"]
#[doc = r""]
#[doc = r" #![deny(private_macro_use)]"]
#[doc = r""]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate extern_macro;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" foo!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: cannot find macro `foo` in this scope"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" This lint arises from overlooking visibility checks for macros"]
#[doc = r" in an external crate."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PRIVATE_MACRO_USE: &crate::Lint =
&crate::Lint {
name: "PRIVATE_MACRO_USE",
default_level: crate::Deny,
desc: "detects certain macro bindings that should not be re-exported",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 120192,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4667/// The `private_macro_use` lint detects private macros that are imported
4668 /// with `#[macro_use]`.
4669 ///
4670 /// ### Example
4671 ///
4672 /// ```rust,ignore (needs extern crate)
4673 /// // extern_macro.rs
4674 /// macro_rules! foo_ { () => {}; }
4675 /// use foo_ as foo;
4676 ///
4677 /// // code.rs
4678 ///
4679 /// #![deny(private_macro_use)]
4680 ///
4681 /// #[macro_use]
4682 /// extern crate extern_macro;
4683 ///
4684 /// fn main() {
4685 /// foo!();
4686 /// }
4687 /// ```
4688 ///
4689 /// This will produce:
4690 ///
4691 /// ```text
4692 /// error: cannot find macro `foo` in this scope
4693 /// ```
4694 ///
4695 /// ### Explanation
4696 ///
4697 /// This lint arises from overlooking visibility checks for macros
4698 /// in an external crate.
4699 ///
4700 /// This is a [future-incompatible] lint to transition this to a
4701 /// hard error in the future.
4702 ///
4703 /// [future-incompatible]: ../index.md#future-incompatible-lints
4704pub PRIVATE_MACRO_USE,
4705 Deny,
4706"detects certain macro bindings that should not be re-exported",
4707 @future_incompatible = FutureIncompatibleInfo {
4708 reason: fcw!(FutureReleaseError #120192),
4709 report_in_deps: true,
4710 };
4711}47124713#[doc =
r" The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for"]
#[doc =
r" foreign trait implementations that concerns the use of type parameters inside trait associated"]
#[doc =
r#" type paths ("projections") whose output may not be a local type that is mistakenly considered"#]
#[doc =
r#" to "cover" said parameters which is **unsound** and which may be rejected by a future version"#]
#[doc = r" of the compiler."]
#[doc = r""]
#[doc = r" Originally reported in [#99554]."]
#[doc = r""]
#[doc = r" [#99554]: https://github.com/rust-lang/rust/issues/99554"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (dependent)"]
#[doc = r" // dependency.rs"]
#[doc = r#" #![crate_type = "lib"]"#]
#[doc = r""]
#[doc = r" pub trait Trait<T, U> {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```edition2021,ignore (needs dependency)"]
#[doc = r" // dependent.rs"]
#[doc = r" trait Identity {"]
#[doc = r" type Output;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<T> Identity for T {"]
#[doc = r" type Output = T;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" struct Local;"]
#[doc = r""]
#[doc =
r" impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)"]
#[doc = r" --> dependent.rs:11:6"]
#[doc = r" |"]
#[doc =
r" 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}"]
#[doc =
r" | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>"]
#[doc =
r" = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type"]
#[doc =
r" = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last"]
#[doc = r" = note: `#[warn(uncovered_param_in_projection)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" FIXME(fmease): Write explainer."]
pub static UNCOVERED_PARAM_IN_PROJECTION: &crate::Lint =
&crate::Lint {
name: "UNCOVERED_PARAM_IN_PROJECTION",
default_level: crate::Warn,
desc: "impl contains type parameters that are not covered",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124559,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4714/// The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for
4715 /// foreign trait implementations that concerns the use of type parameters inside trait associated
4716 /// type paths ("projections") whose output may not be a local type that is mistakenly considered
4717 /// to "cover" said parameters which is **unsound** and which may be rejected by a future version
4718 /// of the compiler.
4719 ///
4720 /// Originally reported in [#99554].
4721 ///
4722 /// [#99554]: https://github.com/rust-lang/rust/issues/99554
4723 ///
4724 /// ### Example
4725 ///
4726 /// ```rust,ignore (dependent)
4727 /// // dependency.rs
4728 /// #![crate_type = "lib"]
4729 ///
4730 /// pub trait Trait<T, U> {}
4731 /// ```
4732 ///
4733 /// ```edition2021,ignore (needs dependency)
4734 /// // dependent.rs
4735 /// trait Identity {
4736 /// type Output;
4737 /// }
4738 ///
4739 /// impl<T> Identity for T {
4740 /// type Output = T;
4741 /// }
4742 ///
4743 /// struct Local;
4744 ///
4745 /// impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4746 ///
4747 /// fn main() {}
4748 /// ```
4749 ///
4750 /// This will produce:
4751 ///
4752 /// ```text
4753 /// warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4754 /// --> dependent.rs:11:6
4755 /// |
4756 /// 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4757 /// | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4758 /// |
4759 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4760 /// = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
4761 /// = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type
4762 /// = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last
4763 /// = note: `#[warn(uncovered_param_in_projection)]` on by default
4764 /// ```
4765 ///
4766 /// ### Explanation
4767 ///
4768 /// FIXME(fmease): Write explainer.
4769pub UNCOVERED_PARAM_IN_PROJECTION,
4770 Warn,
4771"impl contains type parameters that are not covered",
4772 @future_incompatible = FutureIncompatibleInfo {
4773 reason: fcw!(FutureReleaseError #124559),
4774 };
4775}47764777#[doc =
r" The `deprecated_safe_2024` lint detects unsafe functions being used as"]
#[doc = r" safe functions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(deprecated_safe)]"]
#[doc = r" // edition 2021"]
#[doc = r" use std::env;"]
#[doc = r" fn enable_backtrace() {"]
#[doc = r#" env::set_var("RUST_BACKTRACE", "1");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust [editions] allow the language to evolve without breaking backward"]
#[doc =
r" compatibility. This lint catches code that uses `unsafe` functions that"]
#[doc =
r" were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If"]
#[doc =
r" you switch the compiler to Rust 2024 without updating the code, then it"]
#[doc =
r" will fail to compile if you are using a function previously marked as"]
#[doc = r" safe."]
#[doc = r""]
#[doc =
r" You can audit the code to see if it suffices the preconditions of the"]
#[doc =
r" `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If"]
#[doc =
r" you can't fulfill the preconditions, you probably need to switch to a"]
#[doc = r" different way of doing what you want to achieve."]
#[doc = r""]
#[doc =
r" This lint can automatically wrap the calls in `unsafe` blocks, but this"]
#[doc = r" obviously cannot verify that the preconditions of the `unsafe`"]
#[doc = r" functions are fulfilled, so that is still up to the user."]
#[doc = r""]
#[doc =
r#" The lint is currently "allow" by default, but that might change in the"#]
#[doc = r" future."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
pub static DEPRECATED_SAFE_2024: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_SAFE_2024",
default_level: crate::Allow,
desc: "detects unsafe functions being used as safe functions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "newly-unsafe-functions",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4778/// The `deprecated_safe_2024` lint detects unsafe functions being used as
4779 /// safe functions.
4780 ///
4781 /// ### Example
4782 ///
4783 /// ```rust,edition2021,compile_fail
4784 /// #![deny(deprecated_safe)]
4785 /// // edition 2021
4786 /// use std::env;
4787 /// fn enable_backtrace() {
4788 /// env::set_var("RUST_BACKTRACE", "1");
4789 /// }
4790 /// ```
4791 ///
4792 /// {{produces}}
4793 ///
4794 /// ### Explanation
4795 ///
4796 /// Rust [editions] allow the language to evolve without breaking backward
4797 /// compatibility. This lint catches code that uses `unsafe` functions that
4798 /// were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If
4799 /// you switch the compiler to Rust 2024 without updating the code, then it
4800 /// will fail to compile if you are using a function previously marked as
4801 /// safe.
4802 ///
4803 /// You can audit the code to see if it suffices the preconditions of the
4804 /// `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If
4805 /// you can't fulfill the preconditions, you probably need to switch to a
4806 /// different way of doing what you want to achieve.
4807 ///
4808 /// This lint can automatically wrap the calls in `unsafe` blocks, but this
4809 /// obviously cannot verify that the preconditions of the `unsafe`
4810 /// functions are fulfilled, so that is still up to the user.
4811 ///
4812 /// The lint is currently "allow" by default, but that might change in the
4813 /// future.
4814 ///
4815 /// [editions]: https://doc.rust-lang.org/edition-guide/
4816pub DEPRECATED_SAFE_2024,
4817 Allow,
4818"detects unsafe functions being used as safe functions",
4819 @future_incompatible = FutureIncompatibleInfo {
4820 reason: fcw!(EditionError 2024 "newly-unsafe-functions"),
4821 };
4822}48234824#[doc =
r" The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(missing_unsafe_on_extern)]"]
#[doc = r" #![allow(dead_code)]"]
#[doc = r""]
#[doc = r#" extern "C" {"#]
#[doc = r" fn foo(_: i32);"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Declaring extern items, even without ever using them, can cause Undefined Behavior. We"]
#[doc = r" should consider all sources of Undefined Behavior to be unsafe."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static MISSING_UNSAFE_ON_EXTERN: &crate::Lint =
&crate::Lint {
name: "MISSING_UNSAFE_ON_EXTERN",
default_level: crate::Allow,
desc: "detects missing unsafe keyword on extern declarations",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-extern",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4825/// The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations.
4826 ///
4827 /// ### Example
4828 ///
4829 /// ```rust,edition2021
4830 /// #![warn(missing_unsafe_on_extern)]
4831 /// #![allow(dead_code)]
4832 ///
4833 /// extern "C" {
4834 /// fn foo(_: i32);
4835 /// }
4836 ///
4837 /// fn main() {}
4838 /// ```
4839 ///
4840 /// {{produces}}
4841 ///
4842 /// ### Explanation
4843 ///
4844 /// Declaring extern items, even without ever using them, can cause Undefined Behavior. We
4845 /// should consider all sources of Undefined Behavior to be unsafe.
4846 ///
4847 /// This is a [future-incompatible] lint to transition this to a
4848 /// hard error in the future.
4849 ///
4850 /// [future-incompatible]: ../index.md#future-incompatible-lints
4851pub MISSING_UNSAFE_ON_EXTERN,
4852 Allow,
4853"detects missing unsafe keyword on extern declarations",
4854 @future_incompatible = FutureIncompatibleInfo {
4855 reason: fcw!(EditionError 2024 "unsafe-extern"),
4856 };
4857}48584859#[doc =
r" The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword"]
#[doc = r" on attributes considered unsafe."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(unsafe_attr_outside_unsafe)]"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r#" extern "C" fn foo() {}"#]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see"]
#[doc =
r#" [issue #82499] for a more complete list) are considered "unsafe" attributes."#]
#[doc = r" An unsafe attribute must only be used inside unsafe(...)."]
#[doc = r""]
#[doc =
r" This lint can automatically wrap the attributes in `unsafe(...)` , but this"]
#[doc = r" obviously cannot verify that the preconditions of the `unsafe`"]
#[doc = r" attributes are fulfilled, so that is still up to the user."]
#[doc = r""]
#[doc =
r#" The lint is currently "allow" by default, but that might change in the"#]
#[doc = r" future."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
#[doc = r" [issue #82499]: https://github.com/rust-lang/rust/issues/82499"]
pub static UNSAFE_ATTR_OUTSIDE_UNSAFE: &crate::Lint =
&crate::Lint {
name: "UNSAFE_ATTR_OUTSIDE_UNSAFE",
default_level: crate::Allow,
desc: "detects unsafe attributes outside of unsafe",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-attributes",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4860/// The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword
4861 /// on attributes considered unsafe.
4862 ///
4863 /// ### Example
4864 ///
4865 /// ```rust,edition2021
4866 /// #![warn(unsafe_attr_outside_unsafe)]
4867 ///
4868 /// #[no_mangle]
4869 /// extern "C" fn foo() {}
4870 ///
4871 /// fn main() {}
4872 /// ```
4873 ///
4874 /// {{produces}}
4875 ///
4876 /// ### Explanation
4877 ///
4878 /// Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see
4879 /// [issue #82499] for a more complete list) are considered "unsafe" attributes.
4880 /// An unsafe attribute must only be used inside unsafe(...).
4881 ///
4882 /// This lint can automatically wrap the attributes in `unsafe(...)` , but this
4883 /// obviously cannot verify that the preconditions of the `unsafe`
4884 /// attributes are fulfilled, so that is still up to the user.
4885 ///
4886 /// The lint is currently "allow" by default, but that might change in the
4887 /// future.
4888 ///
4889 /// [editions]: https://doc.rust-lang.org/edition-guide/
4890 /// [issue #82499]: https://github.com/rust-lang/rust/issues/82499
4891pub UNSAFE_ATTR_OUTSIDE_UNSAFE,
4892 Allow,
4893"detects unsafe attributes outside of unsafe",
4894 @future_incompatible = FutureIncompatibleInfo {
4895 reason: fcw!(EditionError 2024 "unsafe-attributes"),
4896 };
4897}48984899#[doc =
r" The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,"]
#[doc = r" above their definition, which may happen in key-value attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![doc = in_root!()]"]
#[doc = r""]
#[doc = r#" macro_rules! in_root { () => { "" } }"#]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The scope in which a `macro_rules` item is visible starts at that item and continues"]
#[doc =
r" below it. This is more similar to `let` than to other items, which are in scope both above"]
#[doc = r" and below their definition."]
#[doc =
r" Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes"]
#[doc = r" above their definition. The lint catches such cases."]
#[doc =
r" To address the issue turn the `macro_rules` into a regularly scoped item by importing it"]
#[doc = r" with `use`."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static OUT_OF_SCOPE_MACRO_CALLS: &crate::Lint =
&crate::Lint {
name: "OUT_OF_SCOPE_MACRO_CALLS",
default_level: crate::Deny,
desc: "detects out of scope calls to `macro_rules` in key-value attributes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124535,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4900/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
4901 /// above their definition, which may happen in key-value attributes.
4902 ///
4903 /// ### Example
4904 ///
4905 /// ```rust,compile_fail
4906 /// #![doc = in_root!()]
4907 ///
4908 /// macro_rules! in_root { () => { "" } }
4909 ///
4910 /// fn main() {}
4911 /// ```
4912 ///
4913 /// {{produces}}
4914 ///
4915 /// ### Explanation
4916 ///
4917 /// The scope in which a `macro_rules` item is visible starts at that item and continues
4918 /// below it. This is more similar to `let` than to other items, which are in scope both above
4919 /// and below their definition.
4920 /// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
4921 /// above their definition. The lint catches such cases.
4922 /// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
4923 /// with `use`.
4924 ///
4925 /// This is a [future-incompatible] lint to transition this to a
4926 /// hard error in the future.
4927 ///
4928 /// [future-incompatible]: ../index.md#future-incompatible-lints
4929pub OUT_OF_SCOPE_MACRO_CALLS,
4930 Deny,
4931"detects out of scope calls to `macro_rules` in key-value attributes",
4932 @future_incompatible = FutureIncompatibleInfo {
4933 reason: fcw!(FutureReleaseError #124535),
4934 report_in_deps: true,
4935 };
4936}49374938#[doc =
r" The `resolving_to_items_shadowing_supertrait_items` lint detects when the"]
#[doc =
r" usage of an item that is provided by both a subtrait and supertrait"]
#[doc = r" is shadowed, preferring the subtrait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(supertrait_item_shadowing)]"]
#[doc = r" #![deny(resolving_to_items_shadowing_supertrait_items)]"]
#[doc = r""]
#[doc = r" trait Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Upstream for T {}"]
#[doc = r""]
#[doc = r" trait Downstream: Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Downstream for T {}"]
#[doc = r""]
#[doc = r" struct MyType;"]
#[doc = r" MyType.hello();"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" RFC 3624 specified a heuristic in which a supertrait item would be"]
#[doc = r" shadowed by a subtrait item when ambiguity occurs during item"]
#[doc = r" selection. In order to mitigate side-effects of this happening"]
#[doc =
r" silently, this lint detects these cases when users want to deny them"]
#[doc = r" or fix the call sites."]
pub static RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS: &crate::Lint =
&crate::Lint {
name: "RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS",
default_level: crate::Allow,
desc: "detects when a supertrait item is shadowed by a subtrait item",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::supertrait_item_shadowing),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4939/// The `resolving_to_items_shadowing_supertrait_items` lint detects when the
4940 /// usage of an item that is provided by both a subtrait and supertrait
4941 /// is shadowed, preferring the subtrait.
4942 ///
4943 /// ### Example
4944 ///
4945 /// ```rust,compile_fail
4946 /// #![feature(supertrait_item_shadowing)]
4947 /// #![deny(resolving_to_items_shadowing_supertrait_items)]
4948 ///
4949 /// trait Upstream {
4950 /// fn hello(&self) {}
4951 /// }
4952 /// impl<T> Upstream for T {}
4953 ///
4954 /// trait Downstream: Upstream {
4955 /// fn hello(&self) {}
4956 /// }
4957 /// impl<T> Downstream for T {}
4958 ///
4959 /// struct MyType;
4960 /// MyType.hello();
4961 /// ```
4962 ///
4963 /// {{produces}}
4964 ///
4965 /// ### Explanation
4966 ///
4967 /// RFC 3624 specified a heuristic in which a supertrait item would be
4968 /// shadowed by a subtrait item when ambiguity occurs during item
4969 /// selection. In order to mitigate side-effects of this happening
4970 /// silently, this lint detects these cases when users want to deny them
4971 /// or fix the call sites.
4972pub RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
4973// FIXME(supertrait_item_shadowing): It is not decided if this should
4974 // warn by default at the call site.
4975Allow,
4976"detects when a supertrait item is shadowed by a subtrait item",
4977 @feature_gate = supertrait_item_shadowing;
4978}49794980#[doc = r" The `shadowing_supertrait_items` lint detects when the"]
#[doc = r" definition of an item that is provided by both a subtrait and"]
#[doc = r" supertrait is shadowed, preferring the subtrait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(supertrait_item_shadowing)]"]
#[doc = r" #![deny(shadowing_supertrait_items)]"]
#[doc = r""]
#[doc = r" trait Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Upstream for T {}"]
#[doc = r""]
#[doc = r" trait Downstream: Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Downstream for T {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" RFC 3624 specified a heuristic in which a supertrait item would be"]
#[doc = r" shadowed by a subtrait item when ambiguity occurs during item"]
#[doc = r" selection. In order to mitigate side-effects of this happening"]
#[doc =
r" silently, this lint detects these cases when users want to deny them"]
#[doc = r" or fix their trait definitions."]
pub static SHADOWING_SUPERTRAIT_ITEMS: &crate::Lint =
&crate::Lint {
name: "SHADOWING_SUPERTRAIT_ITEMS",
default_level: crate::Allow,
desc: "detects when a supertrait item is shadowed by a subtrait item",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::supertrait_item_shadowing),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4981/// The `shadowing_supertrait_items` lint detects when the
4982 /// definition of an item that is provided by both a subtrait and
4983 /// supertrait is shadowed, preferring the subtrait.
4984 ///
4985 /// ### Example
4986 ///
4987 /// ```rust,compile_fail
4988 /// #![feature(supertrait_item_shadowing)]
4989 /// #![deny(shadowing_supertrait_items)]
4990 ///
4991 /// trait Upstream {
4992 /// fn hello(&self) {}
4993 /// }
4994 /// impl<T> Upstream for T {}
4995 ///
4996 /// trait Downstream: Upstream {
4997 /// fn hello(&self) {}
4998 /// }
4999 /// impl<T> Downstream for T {}
5000 /// ```
5001 ///
5002 /// {{produces}}
5003 ///
5004 /// ### Explanation
5005 ///
5006 /// RFC 3624 specified a heuristic in which a supertrait item would be
5007 /// shadowed by a subtrait item when ambiguity occurs during item
5008 /// selection. In order to mitigate side-effects of this happening
5009 /// silently, this lint detects these cases when users want to deny them
5010 /// or fix their trait definitions.
5011pub SHADOWING_SUPERTRAIT_ITEMS,
5012// FIXME(supertrait_item_shadowing): It is not decided if this should
5013 // warn by default at the usage site.
5014Allow,
5015"detects when a supertrait item is shadowed by a subtrait item",
5016 @feature_gate = supertrait_item_shadowing;
5017}50185019#[doc =
r" The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,"]
#[doc = r" that runs a custom `Drop` destructor."]
#[doc =
r" Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior."]
#[doc =
r" This lint detects those cases and provides you information on those values and their custom destructor implementations."]
#[doc = r" Your discretion on this information is required."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(tail_expr_drop_order)]"]
#[doc = r" struct Droppy(i32);"]
#[doc = r" impl Droppy {"]
#[doc = r" fn get(&self) -> i32 {"]
#[doc = r" self.0"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" impl Drop for Droppy {"]
#[doc = r" fn drop(&mut self) {"]
#[doc =
r" // This is a custom destructor and it induces side-effects that is observable"]
#[doc =
r" // especially when the drop order at a tail expression changes."]
#[doc = r#" println!("loud drop {}", self.0);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" fn edition_2021() -> i32 {"]
#[doc = r" let another_droppy = Droppy(0);"]
#[doc = r" Droppy(1).get()"]
#[doc = r" }"]
#[doc = r" fn main() {"]
#[doc = r" edition_2021();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In tail expression of blocks or function bodies,"]
#[doc =
r" values of type with significant `Drop` implementation has an ill-specified drop order"]
#[doc =
r" before Edition 2024 so that they are dropped only after dropping local variables."]
#[doc = r" Edition 2024 introduces a new rule with drop orders for them,"]
#[doc = r" so that they are dropped first before dropping local variables."]
#[doc = r""]
#[doc =
r" A significant `Drop::drop` destructor here refers to an explicit, arbitrary"]
#[doc =
r" implementation of the `Drop` trait on the type, with exceptions including `Vec`,"]
#[doc =
r" `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise"]
#[doc =
r" so long that the generic types have no significant destructor recursively."]
#[doc =
r" In other words, a type has a significant drop destructor when it has a `Drop` implementation"]
#[doc = r" or its destructor invokes a significant destructor on a type."]
#[doc =
r" Since we cannot completely reason about the change by just inspecting the existence of"]
#[doc =
r" a significant destructor, this lint remains only a suggestion and is set to `allow` by default."]
#[doc = r""]
#[doc =
r" This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`"]
#[doc = r" does in Edition 2024."]
#[doc = r" No fix will be proposed by this lint."]
#[doc =
r" However, the most probable fix is to hoist `Droppy` into its own local variable binding."]
#[doc = r" ```rust"]
#[doc = r" struct Droppy(i32);"]
#[doc = r" impl Droppy {"]
#[doc = r" fn get(&self) -> i32 {"]
#[doc = r" self.0"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" fn edition_2024() -> i32 {"]
#[doc = r" let value = Droppy(0);"]
#[doc = r" let another_droppy = Droppy(1);"]
#[doc = r" value.get()"]
#[doc = r" }"]
#[doc = r" ```"]
pub static TAIL_EXPR_DROP_ORDER: &crate::Lint =
&crate::Lint {
name: "TAIL_EXPR_DROP_ORDER",
default_level: crate::Allow,
desc: "Detect and warn on significant change in drop order in tail expression location",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "temporary-tail-expr-scope",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5020/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,
5021 /// that runs a custom `Drop` destructor.
5022 /// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior.
5023 /// This lint detects those cases and provides you information on those values and their custom destructor implementations.
5024 /// Your discretion on this information is required.
5025 ///
5026 /// ### Example
5027 /// ```rust,edition2021
5028 /// #![warn(tail_expr_drop_order)]
5029 /// struct Droppy(i32);
5030 /// impl Droppy {
5031 /// fn get(&self) -> i32 {
5032 /// self.0
5033 /// }
5034 /// }
5035 /// impl Drop for Droppy {
5036 /// fn drop(&mut self) {
5037 /// // This is a custom destructor and it induces side-effects that is observable
5038 /// // especially when the drop order at a tail expression changes.
5039 /// println!("loud drop {}", self.0);
5040 /// }
5041 /// }
5042 /// fn edition_2021() -> i32 {
5043 /// let another_droppy = Droppy(0);
5044 /// Droppy(1).get()
5045 /// }
5046 /// fn main() {
5047 /// edition_2021();
5048 /// }
5049 /// ```
5050 ///
5051 /// {{produces}}
5052 ///
5053 /// ### Explanation
5054 ///
5055 /// In tail expression of blocks or function bodies,
5056 /// values of type with significant `Drop` implementation has an ill-specified drop order
5057 /// before Edition 2024 so that they are dropped only after dropping local variables.
5058 /// Edition 2024 introduces a new rule with drop orders for them,
5059 /// so that they are dropped first before dropping local variables.
5060 ///
5061 /// A significant `Drop::drop` destructor here refers to an explicit, arbitrary
5062 /// implementation of the `Drop` trait on the type, with exceptions including `Vec`,
5063 /// `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise
5064 /// so long that the generic types have no significant destructor recursively.
5065 /// In other words, a type has a significant drop destructor when it has a `Drop` implementation
5066 /// or its destructor invokes a significant destructor on a type.
5067 /// Since we cannot completely reason about the change by just inspecting the existence of
5068 /// a significant destructor, this lint remains only a suggestion and is set to `allow` by default.
5069 ///
5070 /// This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`
5071 /// does in Edition 2024.
5072 /// No fix will be proposed by this lint.
5073 /// However, the most probable fix is to hoist `Droppy` into its own local variable binding.
5074 /// ```rust
5075 /// struct Droppy(i32);
5076 /// impl Droppy {
5077 /// fn get(&self) -> i32 {
5078 /// self.0
5079 /// }
5080 /// }
5081 /// fn edition_2024() -> i32 {
5082 /// let value = Droppy(0);
5083 /// let another_droppy = Droppy(1);
5084 /// value.get()
5085 /// }
5086 /// ```
5087pub TAIL_EXPR_DROP_ORDER,
5088 Allow,
5089"Detect and warn on significant change in drop order in tail expression location",
5090 @future_incompatible = FutureIncompatibleInfo {
5091 reason: fcw!(EditionSemanticsChange 2024 "temporary-tail-expr-scope"),
5092 };
5093}50945095#[doc =
r" The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens"]
#[doc =
r" that will be parsed as part of a guarded string literal in Rust 2024."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(rust_2024_guarded_string_incompatible_syntax)]"]
#[doc = r""]
#[doc = r" macro_rules! m {"]
#[doc = r" (# $x:expr #) => ();"]
#[doc = r" (# $x:expr) => ();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r##" m!(#"hey"#);"##]
#[doc = r#" m!(#"hello");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r##" Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`"##]
#[doc = r#" followed by the string literal `"hey"` then the final `#`."#]
#[doc = r" In Rust 2024, the whole sequence is considered a single token."]
#[doc = r""]
#[doc = r" This lint suggests to add whitespace between the leading `#`"]
#[doc = r" and the string to keep them separated in Rust 2024."]
#[allow(rustdoc::invalid_rust_codeblocks)]
pub static RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX: &crate::Lint =
&crate::Lint {
name: "RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX",
default_level: crate::Allow,
desc: "will be parsed as a guarded string in Rust 2024",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "reserved-syntax",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5096/// The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens
5097 /// that will be parsed as part of a guarded string literal in Rust 2024.
5098 ///
5099 /// ### Example
5100 ///
5101 /// ```rust,edition2021,compile_fail
5102 /// #![deny(rust_2024_guarded_string_incompatible_syntax)]
5103 ///
5104 /// macro_rules! m {
5105 /// (# $x:expr #) => ();
5106 /// (# $x:expr) => ();
5107 /// }
5108 ///
5109 /// m!(#"hey"#);
5110 /// m!(#"hello");
5111 /// ```
5112 ///
5113 /// {{produces}}
5114 ///
5115 /// ### Explanation
5116 ///
5117 /// Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`
5118 /// followed by the string literal `"hey"` then the final `#`.
5119 /// In Rust 2024, the whole sequence is considered a single token.
5120 ///
5121 /// This lint suggests to add whitespace between the leading `#`
5122 /// and the string to keep them separated in Rust 2024.
5123// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
5124#[allow(rustdoc::invalid_rust_codeblocks)]
5125pub RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
5126 Allow,
5127"will be parsed as a guarded string in Rust 2024",
5128 @future_incompatible = FutureIncompatibleInfo {
5129 reason: fcw!(EditionError 2024 "reserved-syntax"),
5130 };
5131 crate_level_only
5132}51335134#[doc =
r#" The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on"#]
#[doc =
r" softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of"]
#[doc = r" function calls, making this attribute unsound to use."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs aarch64-unknown-none-softfloat)"]
#[doc = r#" #[target_feature(enable = "neon")]"#]
#[doc = r" fn with_neon() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: enabling the `neon` target feature on the current target is unsound due to ABI issues"]
#[doc = r" --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18"]
#[doc = r" |"]
#[doc = r#" | #[target_feature(enable = "neon")]"#]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" If a function like `with_neon` above ends up containing calls to LLVM builtins, those will"]
#[doc =
r" not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with"]
#[doc =
r" and without the `neon` target feature. The target feature should never have been stabilized"]
#[doc =
r" on this target due to this issue, but the problem was not known at the time of"]
#[doc = r" stabilization."]
pub static AARCH64_SOFTFLOAT_NEON: &crate::Lint =
&crate::Lint {
name: "AARCH64_SOFTFLOAT_NEON",
default_level: crate::Warn,
desc: "detects code that could be affected by ABI issues on aarch64 softfloat targets",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 134375,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5135/// The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on
5136 /// softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of
5137 /// function calls, making this attribute unsound to use.
5138 ///
5139 /// ### Example
5140 ///
5141 /// ```rust,ignore (needs aarch64-unknown-none-softfloat)
5142 /// #[target_feature(enable = "neon")]
5143 /// fn with_neon() {}
5144 /// ```
5145 ///
5146 /// This will produce:
5147 ///
5148 /// ```text
5149 /// error: enabling the `neon` target feature on the current target is unsound due to ABI issues
5150 /// --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
5151 /// |
5152 /// | #[target_feature(enable = "neon")]
5153 /// | ^^^^^^^^^^^^^^^
5154 /// |
5155 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5156 /// = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
5157 /// ```
5158 ///
5159 /// ### Explanation
5160 ///
5161 /// If a function like `with_neon` above ends up containing calls to LLVM builtins, those will
5162 /// not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with
5163 /// and without the `neon` target feature. The target feature should never have been stabilized
5164 /// on this target due to this issue, but the problem was not known at the time of
5165 /// stabilization.
5166pub AARCH64_SOFTFLOAT_NEON,
5167 Warn,
5168"detects code that could be affected by ABI issues on aarch64 softfloat targets",
5169 @future_incompatible = FutureIncompatibleInfo {
5170 reason: fcw!(FutureReleaseError #134375),
5171 report_in_deps: true,
5172 };
5173}51745175#[doc =
r" The `tail_call_track_caller` lint detects usage of `become` attempting to tail call"]
#[doc = r" a function marked with `#[track_caller]`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(explicit_tail_calls)]"]
#[doc = r" #![expect(incomplete_features)]"]
#[doc = r""]
#[doc = r" #[track_caller]"]
#[doc = r" fn f() {}"]
#[doc = r""]
#[doc = r" fn g() {"]
#[doc = r" become f();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" g();"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to implementation details of tail calls and `#[track_caller]` attribute, calls to"]
#[doc =
r" functions marked with `#[track_caller]` cannot become tail calls. As such using `become`"]
#[doc =
r" is no different than a normal call (except for changes in drop order)."]
pub static TAIL_CALL_TRACK_CALLER: &crate::Lint =
&crate::Lint {
name: "TAIL_CALL_TRACK_CALLER",
default_level: crate::Warn,
desc: "detects tail calls of functions marked with `#[track_caller]`",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::explicit_tail_calls),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5176/// The `tail_call_track_caller` lint detects usage of `become` attempting to tail call
5177 /// a function marked with `#[track_caller]`.
5178 ///
5179 /// ### Example
5180 ///
5181 /// ```rust
5182 /// #![feature(explicit_tail_calls)]
5183 /// #![expect(incomplete_features)]
5184 ///
5185 /// #[track_caller]
5186 /// fn f() {}
5187 ///
5188 /// fn g() {
5189 /// become f();
5190 /// }
5191 ///
5192 /// g();
5193 /// ```
5194 ///
5195 /// {{produces}}
5196 ///
5197 /// ### Explanation
5198 ///
5199 /// Due to implementation details of tail calls and `#[track_caller]` attribute, calls to
5200 /// functions marked with `#[track_caller]` cannot become tail calls. As such using `become`
5201 /// is no different than a normal call (except for changes in drop order).
5202pub TAIL_CALL_TRACK_CALLER,
5203 Warn,
5204"detects tail calls of functions marked with `#[track_caller]`",
5205 @feature_gate = explicit_tail_calls;
5206}5207#[doc =
r" The `inline_always_mismatching_target_features` lint will trigger when a"]
#[doc =
r#" function with the `#[inline(always)]` and `#[target_feature(enable = "...")]`"#]
#[doc =
r" attributes is called and cannot be inlined due to missing target features in the caller."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (fails on x86_64)"]
#[doc = r" #[inline(always)]"]
#[doc = r#" #[target_feature(enable = "fp16")]"#]
#[doc = r" unsafe fn callee() {"]
#[doc = r" // operations using fp16 types"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" // Caller does not enable the required target feature"]
#[doc = r" fn caller() {"]
#[doc = r" unsafe { callee(); }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" caller();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning: call to `#[inline(always)]`-annotated `callee` requires the same target features. Function will not have `alwaysinline` attribute applied"]
#[doc = r" --> $DIR/builtin.rs:5192:14"]
#[doc = r" |"]
#[doc = r" 10 | unsafe { callee(); }"]
#[doc = r" | ^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" note: `fp16` target feature enabled in `callee` here but missing from `caller`"]
#[doc = r" --> $DIR/builtin.rs:5185:1"]
#[doc = r" |"]
#[doc = r#" 3 | #[target_feature(enable = "fp16")]"#]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" 4 | unsafe fn callee() {"]
#[doc = r" | ------------------"]
#[doc =
r" = note: `#[warn(inline_always_mismatching_target_features)]` on by default"]
#[doc = r" warning: 1 warning emitted"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Inlining a function with a target feature attribute into a caller that"]
#[doc =
r" lacks the corresponding target feature can lead to unsound behavior."]
#[doc = r" LLVM may select the wrong instructions or registers, or reorder"]
#[doc = r" operations, potentially resulting in runtime errors."]
pub static INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES: &crate::Lint =
&crate::Lint {
name: "INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES",
default_level: crate::Warn,
desc: r#"detects when a function annotated with `#[inline(always)]` and `#[target_feature(enable = "..")]` is inlined into a caller without the required target feature"#,
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5208/// The `inline_always_mismatching_target_features` lint will trigger when a
5209 /// function with the `#[inline(always)]` and `#[target_feature(enable = "...")]`
5210 /// attributes is called and cannot be inlined due to missing target features in the caller.
5211 ///
5212 /// ### Example
5213 ///
5214 /// ```rust,ignore (fails on x86_64)
5215 /// #[inline(always)]
5216 /// #[target_feature(enable = "fp16")]
5217 /// unsafe fn callee() {
5218 /// // operations using fp16 types
5219 /// }
5220 ///
5221 /// // Caller does not enable the required target feature
5222 /// fn caller() {
5223 /// unsafe { callee(); }
5224 /// }
5225 ///
5226 /// fn main() {
5227 /// caller();
5228 /// }
5229 /// ```
5230 ///
5231 /// This will produce:
5232 ///
5233 /// ```text
5234 /// warning: call to `#[inline(always)]`-annotated `callee` requires the same target features. Function will not have `alwaysinline` attribute applied
5235 /// --> $DIR/builtin.rs:5192:14
5236 /// |
5237 /// 10 | unsafe { callee(); }
5238 /// | ^^^^^^^^
5239 /// |
5240 /// note: `fp16` target feature enabled in `callee` here but missing from `caller`
5241 /// --> $DIR/builtin.rs:5185:1
5242 /// |
5243 /// 3 | #[target_feature(enable = "fp16")]
5244 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5245 /// 4 | unsafe fn callee() {
5246 /// | ------------------
5247 /// = note: `#[warn(inline_always_mismatching_target_features)]` on by default
5248 /// warning: 1 warning emitted
5249 /// ```
5250 ///
5251 /// ### Explanation
5252 ///
5253 /// Inlining a function with a target feature attribute into a caller that
5254 /// lacks the corresponding target feature can lead to unsound behavior.
5255 /// LLVM may select the wrong instructions or registers, or reorder
5256 /// operations, potentially resulting in runtime errors.
5257pub INLINE_ALWAYS_MISMATCHING_TARGET_FEATURES,
5258 Warn,
5259r#"detects when a function annotated with `#[inline(always)]` and `#[target_feature(enable = "..")]` is inlined into a caller without the required target feature"#,
5260}52615262#[doc =
r" The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant"]
#[doc = r" values that do not fit into a C `int` or `unsigned int`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (only errors on 64bit)"]
#[doc = r" #[repr(C)]"]
#[doc = r" enum E {"]
#[doc = r" V = 9223372036854775807, // i64::MAX"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: `repr(C)` enum discriminant does not fit into C `int` nor into C `unsigned int`"]
#[doc = r" --> $DIR/repr-c-big-discriminant1.rs:16:5"]
#[doc = r" |"]
#[doc = r" LL | A = 9223372036854775807, // i64::MAX"]
#[doc = r" | ^"]
#[doc = r" |"]
#[doc =
r" = note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C"]
#[doc =
r" = help: use `repr($int_ty)` instead to explicitly set the size of this enum"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In C, enums with discriminants that do not all fit into an `int` or all fit into an"]
#[doc =
r" `unsigned int` are a portability hazard: such enums are only permitted since C23, and not"]
#[doc = r" supported e.g. by MSVC."]
#[doc = r""]
#[doc =
r" Furthermore, Rust interprets the discriminant values of `repr(C)` enums as expressions of"]
#[doc =
r" type `isize`. This makes it impossible to implement the C23 behavior of enums where the enum"]
#[doc =
r" discriminants have no predefined type and instead the enum uses a type large enough to hold"]
#[doc = r" all discriminants."]
#[doc = r""]
#[doc =
r" Therefore, `repr(C)` enums in Rust require that either all discriminants to fit into a C"]
#[doc = r" `int` or they all fit into an `unsigned int`."]
pub static REPR_C_ENUMS_LARGER_THAN_INT: &crate::Lint =
&crate::Lint {
name: "REPR_C_ENUMS_LARGER_THAN_INT",
default_level: crate::Warn,
desc: "repr(C) enums with discriminant values that do not fit into a C int",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124403,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5263/// The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant
5264 /// values that do not fit into a C `int` or `unsigned int`.
5265 ///
5266 /// ### Example
5267 ///
5268 /// ```rust,ignore (only errors on 64bit)
5269 /// #[repr(C)]
5270 /// enum E {
5271 /// V = 9223372036854775807, // i64::MAX
5272 /// }
5273 /// ```
5274 ///
5275 /// This will produce:
5276 ///
5277 /// ```text
5278 /// error: `repr(C)` enum discriminant does not fit into C `int` nor into C `unsigned int`
5279 /// --> $DIR/repr-c-big-discriminant1.rs:16:5
5280 /// |
5281 /// LL | A = 9223372036854775807, // i64::MAX
5282 /// | ^
5283 /// |
5284 /// = note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
5285 /// = help: use `repr($int_ty)` instead to explicitly set the size of this enum
5286 /// ```
5287 ///
5288 /// ### Explanation
5289 ///
5290 /// In C, enums with discriminants that do not all fit into an `int` or all fit into an
5291 /// `unsigned int` are a portability hazard: such enums are only permitted since C23, and not
5292 /// supported e.g. by MSVC.
5293 ///
5294 /// Furthermore, Rust interprets the discriminant values of `repr(C)` enums as expressions of
5295 /// type `isize`. This makes it impossible to implement the C23 behavior of enums where the enum
5296 /// discriminants have no predefined type and instead the enum uses a type large enough to hold
5297 /// all discriminants.
5298 ///
5299 /// Therefore, `repr(C)` enums in Rust require that either all discriminants to fit into a C
5300 /// `int` or they all fit into an `unsigned int`.
5301pub REPR_C_ENUMS_LARGER_THAN_INT,
5302 Warn,
5303"repr(C) enums with discriminant values that do not fit into a C int",
5304 @future_incompatible = FutureIncompatibleInfo {
5305 reason: fcw!(FutureReleaseError #124403),
5306 report_in_deps: false,
5307 };
5308}53095310#[doc =
r" The `varargs_without_pattern` lint detects when `...` is used as an argument to a"]
#[doc = r" non-foreign function without any pattern being specified."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc =
r" // Using `...` in non-foreign function definitions is unstable, however stability is"]
#[doc =
r" // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will"]
#[doc = r" // allow this to compile on stable Rust."]
#[doc = r" #[cfg(false)]"]
#[doc = r" fn foo(...) {"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Patterns are currently required for all non-`...` arguments in function definitions (with"]
#[doc =
r" some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in"]
#[doc =
r" non-foreign function definitions makes the language more consistent, and removes a source of"]
#[doc =
r" confusion for the unstable C variadic feature. `...` arguments without a pattern are already"]
#[doc =
r" stable and widely used in foreign function definitions; this lint only affects non-foreign"]
#[doc = r" function definitions."]
#[doc = r""]
#[doc =
r" Using `...` (C varargs) in a non-foreign function definition is currently unstable. However,"]
#[doc =
r" stability checking for the `...` syntax in non-foreign function definitions is currently"]
#[doc =
r" implemented after attributes have been expanded, meaning that if the attribute removes the"]
#[doc =
r" use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will"]
#[doc =
r" compile on stable Rust; this is the only situation where this lint affects code that"]
#[doc = r" compiles on stable Rust."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static VARARGS_WITHOUT_PATTERN: &crate::Lint =
&crate::Lint {
name: "VARARGS_WITHOUT_PATTERN",
default_level: crate::Warn,
desc: "detects usage of `...` arguments without a pattern in non-foreign items",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 145544,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5311/// The `varargs_without_pattern` lint detects when `...` is used as an argument to a
5312 /// non-foreign function without any pattern being specified.
5313 ///
5314 /// ### Example
5315 ///
5316 /// ```rust
5317 /// // Using `...` in non-foreign function definitions is unstable, however stability is
5318 /// // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will
5319 /// // allow this to compile on stable Rust.
5320 /// #[cfg(false)]
5321 /// fn foo(...) {
5322 ///
5323 /// }
5324 /// ```
5325 ///
5326 /// {{produces}}
5327 ///
5328 /// ### Explanation
5329 ///
5330 /// Patterns are currently required for all non-`...` arguments in function definitions (with
5331 /// some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in
5332 /// non-foreign function definitions makes the language more consistent, and removes a source of
5333 /// confusion for the unstable C variadic feature. `...` arguments without a pattern are already
5334 /// stable and widely used in foreign function definitions; this lint only affects non-foreign
5335 /// function definitions.
5336 ///
5337 /// Using `...` (C varargs) in a non-foreign function definition is currently unstable. However,
5338 /// stability checking for the `...` syntax in non-foreign function definitions is currently
5339 /// implemented after attributes have been expanded, meaning that if the attribute removes the
5340 /// use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will
5341 /// compile on stable Rust; this is the only situation where this lint affects code that
5342 /// compiles on stable Rust.
5343 ///
5344 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
5345 ///
5346 /// [future-incompatible]: ../index.md#future-incompatible-lints
5347pub VARARGS_WITHOUT_PATTERN,
5348 Warn,
5349"detects usage of `...` arguments without a pattern in non-foreign items",
5350 @future_incompatible = FutureIncompatibleInfo {
5351 reason: fcw!(FutureReleaseError #145544),
5352 report_in_deps: false,
5353 };
5354}