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 {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[AARCH64_SOFTFLOAT_NEON,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_DERIVE_HELPERS,
AMBIGUOUS_GLOB_IMPORTED_TRAITS, AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS, AMBIGUOUS_IMPORT_VISIBILITIES,
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,
DEAD_CODE_PUB_IN_BINARY,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, DEPRECATED,
DEPRECATED_IN_FUTURE, DEPRECATED_LLVM_INTRINSIC,
DEPRECATED_SAFE_2024, DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_FEATURES, DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES, FFI_UNWIND_CALLS,
FLOAT_LITERAL_F32_FALLBACK, FORBIDDEN_LINT_GROUPS,
FUNCTION_ITEM_REFERENCES, HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT, INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, 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_INFO, LINKER_MESSAGES,
LONG_RUNNING_CONST_EVAL,
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,
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,
STABLE_FEATURES, TAIL_CALL_TRACK_CALLER,
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_CFG_SELECT_PREDICATES, 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 {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[AARCH64_SOFTFLOAT_NEON,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_DERIVE_HELPERS,
AMBIGUOUS_GLOB_IMPORTED_TRAITS, AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS, AMBIGUOUS_IMPORT_VISIBILITIES,
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,
DEAD_CODE_PUB_IN_BINARY,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, DEPRECATED,
DEPRECATED_IN_FUTURE, DEPRECATED_LLVM_INTRINSIC,
DEPRECATED_SAFE_2024, DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_FEATURES, DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES, FFI_UNWIND_CALLS,
FLOAT_LITERAL_F32_FALLBACK, FORBIDDEN_LINT_GROUPS,
FUNCTION_ITEM_REFERENCES, HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT, INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, 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_INFO, LINKER_MESSAGES,
LONG_RUNNING_CONST_EVAL,
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,
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,
STABLE_FEATURES, TAIL_CALL_TRACK_CALLER,
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_CFG_SELECT_PREDICATES, 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_DERIVE_HELPERS,
21 AMBIGUOUS_GLOB_IMPORTED_TRAITS,
22 AMBIGUOUS_GLOB_IMPORTS,
23 AMBIGUOUS_GLOB_REEXPORTS,
24 AMBIGUOUS_IMPORT_VISIBILITIES,
25 AMBIGUOUS_PANIC_IMPORTS,
26 ARITHMETIC_OVERFLOW,
27 ASM_SUB_REGISTER,
28 BAD_ASM_STYLE,
29 BARE_TRAIT_OBJECTS,
30 BINDINGS_WITH_VARIANT_NAME,
31 BREAK_WITH_LABEL_AND_LOOP,
32 COHERENCE_LEAK_CHECK,
33 CONFLICTING_REPR_HINTS,
34 CONST_EVALUATABLE_UNCHECKED,
35 CONST_ITEM_MUTATION,
36 DEAD_CODE,
37 DEAD_CODE_PUB_IN_BINARY,
38 DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
39 DEPRECATED,
40 DEPRECATED_IN_FUTURE,
41 DEPRECATED_LLVM_INTRINSIC,
42 DEPRECATED_SAFE_2024,
43 DEPRECATED_WHERE_CLAUSE_LOCATION,
44 DUPLICATE_FEATURES,
45 DUPLICATE_MACRO_ATTRIBUTES,
46 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
47 ELIDED_LIFETIMES_IN_PATHS,
48 EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
49 EXPORTED_PRIVATE_DEPENDENCIES,
50 FFI_UNWIND_CALLS,
51 FLOAT_LITERAL_F32_FALLBACK,
52 FORBIDDEN_LINT_GROUPS,
53 FUNCTION_ITEM_REFERENCES,
54 HIDDEN_GLOB_REEXPORTS,
55 ILL_FORMED_ATTRIBUTE_INPUT,
56 INCOMPLETE_INCLUDE,
57 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
58 INLINE_NO_SANITIZE,
59 INVALID_DOC_ATTRIBUTES,
60 INVALID_MACRO_EXPORT_ARGUMENTS,
61 INVALID_TYPE_PARAM_DEFAULT,
62 IRREFUTABLE_LET_PATTERNS,
63 LARGE_ASSIGNMENTS,
64 LATE_BOUND_LIFETIME_ARGUMENTS,
65 LEGACY_DERIVE_HELPERS,
66 LINKER_INFO,
67 LINKER_MESSAGES,
68 LONG_RUNNING_CONST_EVAL,
69 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
70 MACRO_USE_EXTERN_CRATE,
71 MALFORMED_DIAGNOSTIC_ATTRIBUTES,
72 MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
73 META_VARIABLE_MISUSE,
74 MISPLACED_DIAGNOSTIC_ATTRIBUTES,
75 MISSING_ABI,
76 MISSING_UNSAFE_ON_EXTERN,
77 MUST_NOT_SUSPEND,
78 NAMED_ARGUMENTS_USED_POSITIONALLY,
79 NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
80 NON_CONTIGUOUS_RANGE_ENDPOINTS,
81 NON_EXHAUSTIVE_OMITTED_PATTERNS,
82 OUT_OF_SCOPE_MACRO_CALLS,
83 OVERLAPPING_RANGE_ENDPOINTS,
84 PATTERNS_IN_FNS_WITHOUT_BODY,
85 PRIVATE_BOUNDS,
86 PRIVATE_INTERFACES,
87 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
88 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
89 REDUNDANT_IMPORTS,
90 REDUNDANT_LIFETIMES,
91 REFINING_IMPL_TRAIT_INTERNAL,
92 REFINING_IMPL_TRAIT_REACHABLE,
93 RENAMED_AND_REMOVED_LINTS,
94 REPR_C_ENUMS_LARGER_THAN_INT,
95 RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
96 RTSAN_NONBLOCKING_ASYNC,
97 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
98 RUST_2021_INCOMPATIBLE_OR_PATTERNS,
99 RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
100 RUST_2021_PRELUDE_COLLISIONS,
101 RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
102 RUST_2024_INCOMPATIBLE_PAT,
103 RUST_2024_PRELUDE_COLLISIONS,
104 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
105 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
106 SHADOWING_SUPERTRAIT_ITEMS,
107 SINGLE_USE_LIFETIMES,
108 STABLE_FEATURES,
109 TAIL_CALL_TRACK_CALLER,
110 TAIL_EXPR_DROP_ORDER,
111 TEST_UNSTABLE_LINT,
112 TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
113 TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
114 TRIVIAL_CASTS,
115 TRIVIAL_NUMERIC_CASTS,
116 TYVAR_BEHIND_RAW_POINTER,
117 UNCONDITIONAL_PANIC,
118 UNCONDITIONAL_RECURSION,
119 UNCOVERED_PARAM_IN_PROJECTION,
120 UNEXPECTED_CFGS,
121 UNFULFILLED_LINT_EXPECTATIONS,
122 UNINHABITED_STATIC,
123 UNKNOWN_CRATE_TYPES,
124 UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
125 UNKNOWN_LINTS,
126 UNNAMEABLE_TEST_ITEMS,
127 UNNAMEABLE_TYPES,
128 UNREACHABLE_CFG_SELECT_PREDICATES,
129 UNREACHABLE_CODE,
130 UNREACHABLE_PATTERNS,
131 UNSAFE_ATTR_OUTSIDE_UNSAFE,
132 UNSAFE_OP_IN_UNSAFE_FN,
133 UNSTABLE_NAME_COLLISIONS,
134 UNSTABLE_SYNTAX_PRE_EXPANSION,
135 UNSUPPORTED_CALLING_CONVENTIONS,
136 UNUSED_ASSIGNMENTS,
137 UNUSED_ASSOCIATED_TYPE_BOUNDS,
138 UNUSED_ATTRIBUTES,
139 UNUSED_CRATE_DEPENDENCIES,
140 UNUSED_EXTERN_CRATES,
141 UNUSED_FEATURES,
142 UNUSED_IMPORTS,
143 UNUSED_LABELS,
144 UNUSED_LIFETIMES,
145 UNUSED_MACROS,
146 UNUSED_MACRO_RULES,
147 UNUSED_MUT,
148 UNUSED_QUALIFICATIONS,
149 UNUSED_UNSAFE,
150 UNUSED_VARIABLES,
151 UNUSED_VISIBILITIES,
152 USELESS_DEPRECATED,
153 VARARGS_WITHOUT_PATTERN,
154 WARNINGS,
155// tidy-alphabetical-end
156]
157}158159#[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,
ignore_deny_warnings: true,
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! {
160/// The `forbidden_lint_groups` lint detects violations of
161 /// `forbid` applied to a lint group. Due to a bug in the compiler,
162 /// these used to be overlooked entirely. They now generate a warning.
163 ///
164 /// ### Example
165 ///
166 /// ```rust
167 /// #![forbid(warnings)]
168 /// #![warn(bad_style)]
169 ///
170 /// fn main() {}
171 /// ```
172 ///
173 /// {{produces}}
174 ///
175 /// ### Recommended fix
176 ///
177 /// If your crate is using `#![forbid(warnings)]`,
178 /// we recommend that you change to `#![deny(warnings)]`.
179 ///
180 /// ### Explanation
181 ///
182 /// Due to a compiler bug, applying `forbid` to lint groups
183 /// previously had no effect. The bug is now fixed but instead of
184 /// enforcing `forbid` we issue this future-compatibility warning
185 /// to avoid breaking existing crates.
186pub FORBIDDEN_LINT_GROUPS,
187 Warn,
188"applying forbid to lint-groups",
189 @future_incompatible = FutureIncompatibleInfo {
190 reason: fcw!(FutureReleaseError #81670),
191 report_in_deps: true,
192 };
193// We exempt `FORBIDDEN_LINT_GROUPS` from `-Dwarnings` because it specifically
194 // triggers in cases (like #80988) where you have `forbid(warnings)`,
195 // and so if we turned that into an error, it'd defeat the purpose of the
196 // future compatibility warning.
197ignore_deny_warnings
198}199200#[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! {
201/// The `ill_formed_attribute_input` lint detects ill-formed attribute
202 /// inputs that were previously accepted and used in practice.
203 ///
204 /// ### Example
205 ///
206 /// ```rust,compile_fail
207 /// #[inline = "this is not valid"]
208 /// fn foo() {}
209 /// ```
210 ///
211 /// {{produces}}
212 ///
213 /// ### Explanation
214 ///
215 /// Previously, inputs for many built-in attributes weren't validated and
216 /// nonsensical attribute inputs were accepted. After validation was
217 /// added, it was determined that some existing projects made use of these
218 /// invalid forms. This is a [future-incompatible] lint to transition this
219 /// to a hard error in the future. See [issue #57571] for more details.
220 ///
221 /// Check the [attribute reference] for details on the valid inputs for
222 /// attributes.
223 ///
224 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
225 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
226 /// [future-incompatible]: ../index.md#future-incompatible-lints
227pub ILL_FORMED_ATTRIBUTE_INPUT,
228 Deny,
229"ill-formed attribute inputs that were previously accepted and used in practice",
230 @future_incompatible = FutureIncompatibleInfo {
231 reason: fcw!(FutureReleaseError #57571),
232 report_in_deps: true,
233 };
234 crate_level_only
235}236237#[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! {
238/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
239 /// conflicting hints.
240 ///
241 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
242 ///
243 /// ### Example
244 ///
245 /// ```rust,compile_fail
246 /// #[repr(u32, u64)]
247 /// enum Foo {
248 /// Variant1,
249 /// }
250 /// ```
251 ///
252 /// {{produces}}
253 ///
254 /// ### Explanation
255 ///
256 /// The compiler incorrectly accepted these conflicting representations in
257 /// the past. This is a [future-incompatible] lint to transition this to a
258 /// hard error in the future. See [issue #68585] for more details.
259 ///
260 /// To correct the issue, remove one of the conflicting hints.
261 ///
262 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
263 /// [future-incompatible]: ../index.md#future-incompatible-lints
264pub CONFLICTING_REPR_HINTS,
265 Deny,
266"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
267 @future_incompatible = FutureIncompatibleInfo {
268 reason: fcw!(FutureReleaseError #68585),
269 report_in_deps: true,
270 };
271}272273#[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! {
274/// The `meta_variable_misuse` lint detects possible meta-variable misuse
275 /// in macro definitions.
276 ///
277 /// ### Example
278 ///
279 /// ```rust,compile_fail
280 /// #![deny(meta_variable_misuse)]
281 ///
282 /// macro_rules! foo {
283 /// () => {};
284 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
285 /// }
286 ///
287 /// fn main() {
288 /// foo!();
289 /// }
290 /// ```
291 ///
292 /// {{produces}}
293 ///
294 /// ### Explanation
295 ///
296 /// There are quite a few different ways a [`macro_rules`] macro can be
297 /// improperly defined. Many of these errors were previously only detected
298 /// when the macro was expanded or not at all. This lint is an attempt to
299 /// catch some of these problems when the macro is *defined*.
300 ///
301 /// This lint is "allow" by default because it may have false positives
302 /// and other issues. See [issue #61053] for more details.
303 ///
304 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
305 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
306pub META_VARIABLE_MISUSE,
307 Allow,
308"possible meta-variable misuse at macro definition"
309}310311#[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! {
312/// The `incomplete_include` lint detects the use of the [`include!`]
313 /// macro with a file that contains more than one expression.
314 ///
315 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
316 ///
317 /// ### Example
318 ///
319 /// ```rust,ignore (needs separate file)
320 /// fn main() {
321 /// include!("foo.txt");
322 /// }
323 /// ```
324 ///
325 /// where the file `foo.txt` contains:
326 ///
327 /// ```text
328 /// println!("hi!");
329 /// ```
330 ///
331 /// produces:
332 ///
333 /// ```text
334 /// error: include macro expected single expression in source
335 /// --> foo.txt:1:14
336 /// |
337 /// 1 | println!("1");
338 /// | ^
339 /// |
340 /// = note: `#[deny(incomplete_include)]` on by default
341 /// ```
342 ///
343 /// ### Explanation
344 ///
345 /// The [`include!`] macro is currently only intended to be used to
346 /// include a single [expression] or multiple [items]. Historically it
347 /// would ignore any contents after the first expression, but that can be
348 /// confusing. In the example above, the `println!` expression ends just
349 /// before the semicolon, making the semicolon "extra" information that is
350 /// ignored. Perhaps even more surprising, if the included file had
351 /// multiple print statements, the subsequent ones would be ignored!
352 ///
353 /// One workaround is to place the contents in braces to create a [block
354 /// expression]. Also consider alternatives, like using functions to
355 /// encapsulate the expressions, or use [proc-macros].
356 ///
357 /// This is a lint instead of a hard error because existing projects were
358 /// found to hit this error. To be cautious, it is a lint for now. The
359 /// future semantics of the `include!` macro are also uncertain, see
360 /// [issue #35560].
361 ///
362 /// [items]: https://doc.rust-lang.org/reference/items.html
363 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
364 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
365 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
366 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
367pub INCOMPLETE_INCLUDE,
368 Deny,
369"trailing content in included file"
370}371372#[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! {
373/// The `arithmetic_overflow` lint detects that an arithmetic operation
374 /// will [overflow].
375 ///
376 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
377 ///
378 /// ### Example
379 ///
380 /// ```rust,compile_fail
381 /// 1_i32 << 32;
382 /// ```
383 ///
384 /// {{produces}}
385 ///
386 /// ### Explanation
387 ///
388 /// It is very likely a mistake to perform an arithmetic operation that
389 /// overflows its value. If the compiler is able to detect these kinds of
390 /// overflows at compile-time, it will trigger this lint. Consider
391 /// adjusting the expression to avoid overflow, or use a data type that
392 /// will not overflow.
393pub ARITHMETIC_OVERFLOW,
394 Deny,
395"arithmetic operation overflows",
396 @eval_always = true
397}398399#[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! {
400/// The `unconditional_panic` lint detects an operation that will cause a
401 /// panic at runtime.
402 ///
403 /// ### Example
404 ///
405 /// ```rust,compile_fail
406 /// # #![allow(unused)]
407 /// let x = 1 / 0;
408 /// ```
409 ///
410 /// {{produces}}
411 ///
412 /// ### Explanation
413 ///
414 /// This lint detects code that is very likely incorrect because it will
415 /// always panic, such as division by zero and out-of-bounds array
416 /// accesses. Consider adjusting your code if this is a bug, or using the
417 /// `panic!` or `unreachable!` macro instead in case the panic is intended.
418pub UNCONDITIONAL_PANIC,
419 Deny,
420"operation will cause a panic at runtime",
421 @eval_always = true
422}423424#[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! {
425/// The `unused_imports` lint detects imports that are never used.
426 ///
427 /// ### Example
428 ///
429 /// ```rust
430 /// use std::collections::HashMap;
431 /// ```
432 ///
433 /// {{produces}}
434 ///
435 /// ### Explanation
436 ///
437 /// Unused imports may signal a mistake or unfinished code, and clutter
438 /// the code, and should be removed. If you intended to re-export the item
439 /// to make it available outside of the module, add a visibility modifier
440 /// like `pub`.
441pub UNUSED_IMPORTS,
442 Warn,
443"imports that are never used"
444}445446#[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! {
447/// The `redundant_imports` lint detects imports that are redundant due to being
448 /// imported already; either through a previous import, or being present in
449 /// the prelude.
450 ///
451 /// ### Example
452 ///
453 /// ```rust,compile_fail
454 /// #![deny(redundant_imports)]
455 /// use std::option::Option::None;
456 /// fn foo() -> Option<i32> { None }
457 /// ```
458 ///
459 /// {{produces}}
460 ///
461 /// ### Explanation
462 ///
463 /// Redundant imports are unnecessary and can be removed to simplify code.
464 /// If you intended to re-export the item to make it available outside of the
465 /// module, add a visibility modifier like `pub`.
466pub REDUNDANT_IMPORTS,
467 Allow,
468"imports that are redundant due to being imported already"
469}470471#[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! {
472/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
473 /// (`.await`)
474 ///
475 /// ### Example
476 ///
477 /// ```rust
478 /// #![feature(must_not_suspend)]
479 /// #![warn(must_not_suspend)]
480 ///
481 /// #[must_not_suspend]
482 /// struct SyncThing {}
483 ///
484 /// async fn yield_now() {}
485 ///
486 /// pub async fn uhoh() {
487 /// let guard = SyncThing {};
488 /// yield_now().await;
489 /// let _guard = guard;
490 /// }
491 /// ```
492 ///
493 /// {{produces}}
494 ///
495 /// ### Explanation
496 ///
497 /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
498 /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
499 /// function.
500 ///
501 /// This attribute can be used to mark values that are semantically incorrect across suspends
502 /// (like certain types of timers), values that have async alternatives, and values that
503 /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
504 /// `MutexGuard`'s)
505 ///
506pub MUST_NOT_SUSPEND,
507 Allow,
508"use of a `#[must_not_suspend]` value across a yield point",
509 @feature_gate = must_not_suspend;
510}511512#[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! {
513/// The `unused_extern_crates` lint guards against `extern crate` items
514 /// that are never used.
515 ///
516 /// ### Example
517 ///
518 /// ```rust,compile_fail
519 /// #![deny(unused_extern_crates)]
520 /// #![deny(warnings)]
521 /// extern crate proc_macro;
522 /// ```
523 ///
524 /// {{produces}}
525 ///
526 /// ### Explanation
527 ///
528 /// `extern crate` items that are unused have no effect and should be
529 /// removed. Note that there are some cases where specifying an `extern
530 /// crate` is desired for the side effect of ensuring the given crate is
531 /// linked, even though it is not otherwise directly referenced. The lint
532 /// can be silenced by aliasing the crate to an underscore, such as
533 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
534 /// use `extern crate` in the [2018 edition], as extern crates are now
535 /// automatically added in scope.
536 ///
537 /// This lint is "allow" by default because it can be noisy, and produce
538 /// false-positives. If a dependency is being removed from a project, it
539 /// is recommended to remove it from the build configuration (such as
540 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
541 ///
542 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
543pub UNUSED_EXTERN_CRATES,
544 Allow,
545"extern crates that are never used"
546}547548#[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! {
549/// The `unused_crate_dependencies` lint detects crate dependencies that
550 /// are never used.
551 ///
552 /// ### Example
553 ///
554 /// ```rust,ignore (needs extern crate)
555 /// #![deny(unused_crate_dependencies)]
556 /// ```
557 ///
558 /// This will produce:
559 ///
560 /// ```text
561 /// error: extern crate `regex` is unused in crate `lint_example`
562 /// |
563 /// = help: remove the dependency or add `use regex as _;` to the crate root
564 /// note: the lint level is defined here
565 /// --> src/lib.rs:1:9
566 /// |
567 /// 1 | #![deny(unused_crate_dependencies)]
568 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
569 /// ```
570 ///
571 /// ### Explanation
572 ///
573 /// After removing the code that uses a dependency, this usually also
574 /// requires removing the dependency from the build configuration.
575 /// However, sometimes that step can be missed, which leads to time wasted
576 /// building dependencies that are no longer used. This lint can be
577 /// enabled to detect dependencies that are never used (more specifically,
578 /// any dependency passed with the `--extern` command-line flag that is
579 /// never referenced via [`use`], [`extern crate`], or in any [path]).
580 ///
581 /// This lint is "allow" by default because it can provide false positives
582 /// depending on how the build system is configured. For example, when
583 /// using Cargo, a "package" consists of multiple crates (such as a
584 /// library and a binary), but the dependencies are defined for the
585 /// package as a whole. If there is a dependency that is only used in the
586 /// binary, but not the library, then the lint will be incorrectly issued
587 /// in the library.
588 ///
589 /// [path]: https://doc.rust-lang.org/reference/paths.html
590 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
591 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
592pub UNUSED_CRATE_DEPENDENCIES,
593 Allow,
594"crate dependencies that are never used",
595 crate_level_only
596}597598#[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! {
599/// The `unused_qualifications` lint detects unnecessarily qualified
600 /// names.
601 ///
602 /// ### Example
603 ///
604 /// ```rust,compile_fail
605 /// #![deny(unused_qualifications)]
606 /// mod foo {
607 /// pub fn bar() {}
608 /// }
609 ///
610 /// fn main() {
611 /// use foo::bar;
612 /// foo::bar();
613 /// bar();
614 /// }
615 /// ```
616 ///
617 /// {{produces}}
618 ///
619 /// ### Explanation
620 ///
621 /// If an item from another module is already brought into scope, then
622 /// there is no need to qualify it in this case. You can call `bar()`
623 /// directly, without the `foo::`.
624 ///
625 /// This lint is "allow" by default because it is somewhat pedantic, and
626 /// doesn't indicate an actual problem, but rather a stylistic choice, and
627 /// can be noisy when refactoring or moving around code.
628pub UNUSED_QUALIFICATIONS,
629 Allow,
630"detects unnecessarily qualified names"
631}632633#[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! {
634/// The `unknown_lints` lint detects unrecognized lint attributes.
635 ///
636 /// ### Example
637 ///
638 /// ```rust
639 /// #![allow(not_a_real_lint)]
640 /// ```
641 ///
642 /// {{produces}}
643 ///
644 /// ### Explanation
645 ///
646 /// It is usually a mistake to specify a lint that does not exist. Check
647 /// the spelling, and check the lint listing for the correct name. Also
648 /// consider if you are using an old version of the compiler, and the lint
649 /// is only available in a newer version.
650pub UNKNOWN_LINTS,
651 Warn,
652"unrecognized lint attribute",
653 @eval_always = true
654}655656#[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! {
657/// The `unfulfilled_lint_expectations` lint detects when a lint expectation is
658 /// unfulfilled.
659 ///
660 /// ### Example
661 ///
662 /// ```rust
663 /// #[expect(unused_variables)]
664 /// let x = 10;
665 /// println!("{}", x);
666 /// ```
667 ///
668 /// {{produces}}
669 ///
670 /// ### Explanation
671 ///
672 /// The `#[expect]` attribute can be used to create a lint expectation. The
673 /// expectation is fulfilled, if a `#[warn]` attribute at the same location
674 /// would result in a lint emission. If the expectation is unfulfilled,
675 /// because no lint was emitted, this lint will be emitted on the attribute.
676 ///
677pub UNFULFILLED_LINT_EXPECTATIONS,
678 Warn,
679"unfulfilled lint expectation"
680}681682#[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! {
683/// The `unused_variables` lint detects variables which are not used in
684 /// any way.
685 ///
686 /// ### Example
687 ///
688 /// ```rust
689 /// let x = 5;
690 /// ```
691 ///
692 /// {{produces}}
693 ///
694 /// ### Explanation
695 ///
696 /// Unused variables may signal a mistake or unfinished code. To silence
697 /// the warning for the individual variable, prefix it with an underscore
698 /// such as `_x`.
699pub UNUSED_VARIABLES,
700 Warn,
701"detect variables which are not used in any way"
702}703704#[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! {
705/// The `unused_visibilities` lint detects visibility qualifiers (like `pub`)
706 /// on a `const _` item.
707 ///
708 /// ### Example
709 ///
710 /// ```rust
711 /// pub const _: () = {};
712 /// ```
713 ///
714 /// {{produces}}
715 ///
716 /// ### Explanation
717 ///
718 /// These qualifiers have no effect, as `const _` items are unnameable.
719pub UNUSED_VISIBILITIES,
720 Warn,
721"detect visibility qualifiers on `const _` items"
722}723724#[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! {
725/// The `unused_assignments` lint detects assignments that will never be read.
726 ///
727 /// ### Example
728 ///
729 /// ```rust
730 /// let mut x = 5;
731 /// x = 6;
732 /// ```
733 ///
734 /// {{produces}}
735 ///
736 /// ### Explanation
737 ///
738 /// Unused assignments may signal a mistake or unfinished code. If the
739 /// variable is never used after being assigned, then the assignment can
740 /// be removed. Variables with an underscore prefix such as `_x` will not
741 /// trigger this lint.
742pub UNUSED_ASSIGNMENTS,
743 Warn,
744"detect assignments that will never be read"
745}746747#[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! {
748/// The `dead_code` lint detects unused, unexported items.
749 ///
750 /// ### Example
751 ///
752 /// ```rust
753 /// fn foo() {}
754 /// ```
755 ///
756 /// {{produces}}
757 ///
758 /// ### Explanation
759 ///
760 /// Dead code may signal a mistake or unfinished code. To silence the
761 /// warning for individual items, prefix the name with an underscore such
762 /// as `_foo`. If it was intended to expose the item outside of the crate,
763 /// consider adding a visibility modifier like `pub`.
764 ///
765 /// To preserve the numbering of tuple structs with unused fields,
766 /// change the unused fields to have unit type or use
767 /// `PhantomData`.
768 ///
769 /// Otherwise consider removing the unused code.
770 ///
771 /// ### Limitations
772 ///
773 /// Removing fields that are only used for side-effects and never
774 /// read will result in behavioral changes. Examples of this
775 /// include:
776 ///
777 /// - If a field's value performs an action when it is dropped.
778 /// - If a field's type does not implement an auto trait
779 /// (e.g. `Send`, `Sync`, `Unpin`).
780 ///
781 /// For side-effects from dropping field values, this lint should
782 /// be allowed on those fields. For side-effects from containing
783 /// field types, `PhantomData` should be used.
784pub DEAD_CODE,
785 Warn,
786"detect unused, unexported items"
787}788789#[doc = r" The `dead_code_pub_in_binary` lint detects unused `pub` items in"]
#[doc = r" executable crates."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(dead_code_pub_in_binary)]"]
#[doc = r""]
#[doc = r" pub fn unused_pub_fn() {}"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In executable crates, `pub` items are often implementation details"]
#[doc =
r" rather than part of an external API. This lint helps find those items"]
#[doc = r" when they are never used."]
#[doc = r""]
#[doc =
r" This lint only applies to executable crates. In library crates, public"]
#[doc =
r" items are considered part of the crate's API and are not reported by"]
#[doc = r" this lint."]
pub static DEAD_CODE_PUB_IN_BINARY: &crate::Lint =
&crate::Lint {
name: "DEAD_CODE_PUB_IN_BINARY",
default_level: crate::Allow,
desc: "detect public items in executable crates that are never used",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
790/// The `dead_code_pub_in_binary` lint detects unused `pub` items in
791 /// executable crates.
792 ///
793 /// ### Example
794 ///
795 /// ```rust
796 /// #![deny(dead_code_pub_in_binary)]
797 ///
798 /// pub fn unused_pub_fn() {}
799 ///
800 /// fn main() {}
801 /// ```
802 ///
803 /// {{produces}}
804 ///
805 /// ### Explanation
806 ///
807 /// In executable crates, `pub` items are often implementation details
808 /// rather than part of an external API. This lint helps find those items
809 /// when they are never used.
810 ///
811 /// This lint only applies to executable crates. In library crates, public
812 /// items are considered part of the crate's API and are not reported by
813 /// this lint.
814pub DEAD_CODE_PUB_IN_BINARY,
815 Allow,
816"detect public items in executable crates that are never used",
817 crate_level_only
818}819820#[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! {
821/// The `unused_attributes` lint detects attributes that were not used by
822 /// the compiler.
823 ///
824 /// ### Example
825 ///
826 /// ```rust
827 /// #![ignore]
828 /// ```
829 ///
830 /// {{produces}}
831 ///
832 /// ### Explanation
833 ///
834 /// Unused [attributes] may indicate the attribute is placed in the wrong
835 /// position. Consider removing it, or placing it in the correct position.
836 /// Also consider if you intended to use an _inner attribute_ (with a `!`
837 /// such as `#![allow(unused)]`) which applies to the item the attribute
838 /// is within, or an _outer attribute_ (without a `!` such as
839 /// `#[allow(unused)]`) which applies to the item *following* the
840 /// attribute.
841 ///
842 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
843pub UNUSED_ATTRIBUTES,
844 Warn,
845"detects attributes that were not used by the compiler"
846}847848#[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! {
849/// The `unreachable_code` lint detects unreachable code paths.
850 ///
851 /// ### Example
852 ///
853 /// ```rust,no_run
854 /// panic!("we never go past here!");
855 ///
856 /// let x = 5;
857 /// ```
858 ///
859 /// {{produces}}
860 ///
861 /// ### Explanation
862 ///
863 /// Unreachable code may signal a mistake or unfinished code. If the code
864 /// is no longer in use, consider removing it.
865pub UNREACHABLE_CODE,
866 Warn,
867"detects unreachable code paths",
868 report_in_external_macro
869}870871#[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! {
872/// The `unreachable_patterns` lint detects unreachable patterns.
873 ///
874 /// ### Example
875 ///
876 /// ```rust
877 /// let x = 5;
878 /// match x {
879 /// y => (),
880 /// 5 => (),
881 /// }
882 /// ```
883 ///
884 /// {{produces}}
885 ///
886 /// ### Explanation
887 ///
888 /// This usually indicates a mistake in how the patterns are specified or
889 /// ordered. In this example, the `y` pattern will always match, so the
890 /// five is impossible to reach. Remember, match arms match in order, you
891 /// probably wanted to put the `5` case above the `y` case.
892pub UNREACHABLE_PATTERNS,
893 Warn,
894"detects unreachable patterns"
895}896897#[doc =
r" The `unreachable_cfg_select_predicates` lint detects unreachable configuration"]
#[doc = r" predicates in the `cfg_select!` macro."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" cfg_select! {"]
#[doc = r" _ => (),"]
#[doc = r" windows => (),"]
#[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 predicates are specified or"]
#[doc =
r" ordered. In this example, the `_` predicate will always match, so the"]
#[doc =
r" `windows` is impossible to reach. Remember, arms match in order, you"]
#[doc = r" probably wanted to put the `windows` case above the `_` case."]
pub static UNREACHABLE_CFG_SELECT_PREDICATES: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_CFG_SELECT_PREDICATES",
default_level: crate::Warn,
desc: "detects unreachable configuration predicates in the cfg_select macro",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
898/// The `unreachable_cfg_select_predicates` lint detects unreachable configuration
899 /// predicates in the `cfg_select!` macro.
900 ///
901 /// ### Example
902 ///
903 /// ```rust
904 /// cfg_select! {
905 /// _ => (),
906 /// windows => (),
907 /// }
908 /// ```
909 ///
910 /// {{produces}}
911 ///
912 /// ### Explanation
913 ///
914 /// This usually indicates a mistake in how the predicates are specified or
915 /// ordered. In this example, the `_` predicate will always match, so the
916 /// `windows` is impossible to reach. Remember, arms match in order, you
917 /// probably wanted to put the `windows` case above the `_` case.
918pub UNREACHABLE_CFG_SELECT_PREDICATES,
919 Warn,
920"detects unreachable configuration predicates in the cfg_select macro",
921}922923#[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! {
924/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
925 /// overlap on their endpoints.
926 ///
927 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
928 ///
929 /// ### Example
930 ///
931 /// ```rust
932 /// let x = 123u8;
933 /// match x {
934 /// 0..=100 => { println!("small"); }
935 /// 100..=255 => { println!("large"); }
936 /// }
937 /// ```
938 ///
939 /// {{produces}}
940 ///
941 /// ### Explanation
942 ///
943 /// It is likely a mistake to have range patterns in a match expression that overlap in this
944 /// way. Check that the beginning and end values are what you expect, and keep in mind that
945 /// with `..=` the left and right bounds are inclusive.
946pub OVERLAPPING_RANGE_ENDPOINTS,
947 Warn,
948"detects range patterns with overlapping endpoints"
949}950951#[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! {
952/// The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
953 /// exclusive [range patterns].
954 ///
955 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
956 ///
957 /// ### Example
958 ///
959 /// ```rust
960 /// let x = 123u32;
961 /// match x {
962 /// 0..100 => { println!("small"); }
963 /// 101..1000 => { println!("large"); }
964 /// _ => { println!("larger"); }
965 /// }
966 /// ```
967 ///
968 /// {{produces}}
969 ///
970 /// ### Explanation
971 ///
972 /// It is likely a mistake to have range patterns in a match expression that miss out a single
973 /// number. Check that the beginning and end values are what you expect, and keep in mind that
974 /// with `..=` the right bound is inclusive, and with `..` it is exclusive.
975pub NON_CONTIGUOUS_RANGE_ENDPOINTS,
976 Warn,
977"detects off-by-one errors with exclusive range patterns"
978}979980#[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! {
981/// The `bindings_with_variant_name` lint detects pattern bindings with
982 /// the same name as one of the matched variants.
983 ///
984 /// ### Example
985 ///
986 /// ```rust,compile_fail
987 /// pub enum Enum {
988 /// Foo,
989 /// Bar,
990 /// }
991 ///
992 /// pub fn foo(x: Enum) {
993 /// match x {
994 /// Foo => {}
995 /// Bar => {}
996 /// }
997 /// }
998 /// ```
999 ///
1000 /// {{produces}}
1001 ///
1002 /// ### Explanation
1003 ///
1004 /// It is usually a mistake to specify an enum variant name as an
1005 /// [identifier pattern]. In the example above, the `match` arms are
1006 /// specifying a variable name to bind the value of `x` to. The second arm
1007 /// is ignored because the first one matches *all* values. The likely
1008 /// intent is that the arm was intended to match on the enum variant.
1009 ///
1010 /// Two possible solutions are:
1011 ///
1012 /// * Specify the enum variant using a [path pattern], such as
1013 /// `Enum::Foo`.
1014 /// * Bring the enum variants into local scope, such as adding `use
1015 /// Enum::*;` to the beginning of the `foo` function in the example
1016 /// above.
1017 ///
1018 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1019 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
1020pub BINDINGS_WITH_VARIANT_NAME,
1021 Deny,
1022"detects pattern bindings with the same name as one of the matched variants"
1023}10241025#[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! {
1026/// The `unused_macros` lint detects macros that were not used.
1027 ///
1028 /// Note that this lint is distinct from the `unused_macro_rules` lint,
1029 /// which checks for single rules that never match of an otherwise used
1030 /// macro, and thus never expand.
1031 ///
1032 /// ### Example
1033 ///
1034 /// ```rust
1035 /// macro_rules! unused {
1036 /// () => {};
1037 /// }
1038 ///
1039 /// fn main() {
1040 /// }
1041 /// ```
1042 ///
1043 /// {{produces}}
1044 ///
1045 /// ### Explanation
1046 ///
1047 /// Unused macros may signal a mistake or unfinished code. To silence the
1048 /// warning for the individual macro, prefix the name with an underscore
1049 /// such as `_my_macro`. If you intended to export the macro to make it
1050 /// available outside of the crate, use the [`macro_export` attribute].
1051 ///
1052 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1053pub UNUSED_MACROS,
1054 Warn,
1055"detects macros that were not used"
1056}10571058#[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 used"#]
#[doc = r#" () => { println!("empty") }; // This rule is unused"#]
#[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! {
1059/// The `unused_macro_rules` lint detects macro rules that were not used.
1060 ///
1061 /// Note that the lint is distinct from the `unused_macros` lint, which
1062 /// fires if the entire macro is never called, while this lint fires for
1063 /// single unused rules of the macro that is otherwise used.
1064 /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
1065 ///
1066 /// ### Example
1067 ///
1068 /// ```rust
1069 /// #[warn(unused_macro_rules)]
1070 /// macro_rules! unused_empty {
1071 /// (hello) => { println!("Hello, world!") }; // This rule is used
1072 /// () => { println!("empty") }; // This rule is unused
1073 /// }
1074 ///
1075 /// fn main() {
1076 /// unused_empty!(hello);
1077 /// }
1078 /// ```
1079 ///
1080 /// {{produces}}
1081 ///
1082 /// ### Explanation
1083 ///
1084 /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
1085 /// they slow down compilation. Right now, silencing the warning is not
1086 /// supported on a single rule level, so you have to add an allow to the
1087 /// entire macro definition.
1088 ///
1089 /// If you intended to export the macro to make it
1090 /// available outside of the crate, use the [`macro_export` attribute].
1091 ///
1092 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1093pub UNUSED_MACRO_RULES,
1094 Allow,
1095"detects macro rules that were not used"
1096}10971098#[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! {
1099/// The `warnings` lint allows you to change the level of other
1100 /// lints which produce warnings.
1101 ///
1102 /// ### Example
1103 ///
1104 /// ```rust
1105 /// #![deny(warnings)]
1106 /// fn foo() {}
1107 /// ```
1108 ///
1109 /// {{produces}}
1110 ///
1111 /// ### Explanation
1112 ///
1113 /// The `warnings` lint is a bit special; by changing its level, you
1114 /// change every other warning that would produce a warning to whatever
1115 /// value you'd like. As such, you won't ever trigger this lint in your
1116 /// code directly.
1117pub WARNINGS,
1118 Warn,
1119"mass-change the level for lints which produce warnings"
1120}11211122#[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/"]
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! {
1123/// The `unused_features` lint detects unused or unknown features found in
1124 /// crate-level [`feature` attributes].
1125 ///
1126 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1127pub UNUSED_FEATURES,
1128 Warn,
1129"unused features found in crate-level `#[feature]` directives"
1130}11311132#[doc = r" The `duplicate_features` lint detects duplicate features found in"]
#[doc = r" crate-level [`feature` attributes]."]
#[doc = r""]
#[doc = r" Note: This lint used to be a hard error (E0636)."]
#[doc = r""]
#[doc =
r" [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(internal_features)]"]
#[doc = r" #![feature(rustc_attrs)]"]
#[doc = r" #![feature(rustc_attrs)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Enabling a feature more than once is a no-op."]
#[doc = r" To avoid this warning, remove the second `feature()` attribute."]
pub static DUPLICATE_FEATURES: &crate::Lint =
&crate::Lint {
name: "DUPLICATE_FEATURES",
default_level: crate::Deny,
desc: "duplicate features found in crate-level `#[feature]` directives",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1133/// The `duplicate_features` lint detects duplicate features found in
1134 /// crate-level [`feature` attributes].
1135 ///
1136 /// Note: This lint used to be a hard error (E0636).
1137 ///
1138 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1139 ///
1140 /// ### Example
1141 ///
1142 /// ```rust,compile_fail
1143 /// # #![allow(internal_features)]
1144 /// #![feature(rustc_attrs)]
1145 /// #![feature(rustc_attrs)]
1146 /// ```
1147 ///
1148 /// {{produces}}
1149 ///
1150 /// ### Explanation
1151 ///
1152 /// Enabling a feature more than once is a no-op.
1153 /// To avoid this warning, remove the second `feature()` attribute.
1154pub DUPLICATE_FEATURES,
1155 Deny,
1156"duplicate features found in crate-level `#[feature]` directives"
1157}11581159#[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! {
1160/// The `stable_features` lint detects a [`feature` attribute] that
1161 /// has since been made stable.
1162 ///
1163 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1164 ///
1165 /// ### Example
1166 ///
1167 /// ```rust
1168 /// #![feature(test_accepted_feature)]
1169 /// fn main() {}
1170 /// ```
1171 ///
1172 /// {{produces}}
1173 ///
1174 /// ### Explanation
1175 ///
1176 /// When a feature is stabilized, it is no longer necessary to include a
1177 /// `#![feature]` attribute for it. To fix, simply remove the
1178 /// `#![feature]` attribute.
1179pub STABLE_FEATURES,
1180 Warn,
1181"stable features found in `#[feature]` directive"
1182}11831184#[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! {
1185/// The `unknown_crate_types` lint detects an unknown crate type found in
1186 /// a [`crate_type` attribute].
1187 ///
1188 /// ### Example
1189 ///
1190 /// ```rust,compile_fail
1191 /// #![crate_type="lol"]
1192 /// fn main() {}
1193 /// ```
1194 ///
1195 /// {{produces}}
1196 ///
1197 /// ### Explanation
1198 ///
1199 /// An unknown value give to the `crate_type` attribute is almost
1200 /// certainly a mistake.
1201 ///
1202 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
1203pub UNKNOWN_CRATE_TYPES,
1204 Deny,
1205"unknown crate type found in `#[crate_type]` directive",
1206 crate_level_only
1207}12081209#[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! {
1210/// The `trivial_casts` lint detects trivial casts which could be replaced
1211 /// with coercion, which may require a temporary variable.
1212 ///
1213 /// ### Example
1214 ///
1215 /// ```rust,compile_fail
1216 /// #![deny(trivial_casts)]
1217 /// let x: &u32 = &42;
1218 /// let y = x as *const u32;
1219 /// ```
1220 ///
1221 /// {{produces}}
1222 ///
1223 /// ### Explanation
1224 ///
1225 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
1226 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
1227 /// usually be inferred.
1228 ///
1229 /// This lint is "allow" by default because there are situations, such as
1230 /// with FFI interfaces or complex type aliases, where it triggers
1231 /// incorrectly, or in situations where it will be more difficult to
1232 /// clearly express the intent. It may be possible that this will become a
1233 /// warning in the future, possibly with an explicit syntax for coercions
1234 /// providing a convenient way to work around the current issues.
1235 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1236 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1237 ///
1238 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1239 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1240 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1241pub TRIVIAL_CASTS,
1242 Allow,
1243"detects trivial casts which could be removed"
1244}12451246#[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! {
1247/// The `trivial_numeric_casts` lint detects trivial numeric casts of types
1248 /// which could be removed.
1249 ///
1250 /// ### Example
1251 ///
1252 /// ```rust,compile_fail
1253 /// #![deny(trivial_numeric_casts)]
1254 /// let x = 42_i32 as i32;
1255 /// ```
1256 ///
1257 /// {{produces}}
1258 ///
1259 /// ### Explanation
1260 ///
1261 /// A trivial numeric cast is a cast of a numeric type to the same numeric
1262 /// type. This type of cast is usually unnecessary.
1263 ///
1264 /// This lint is "allow" by default because there are situations, such as
1265 /// with FFI interfaces or complex type aliases, where it triggers
1266 /// incorrectly, or in situations where it will be more difficult to
1267 /// clearly express the intent. It may be possible that this will become a
1268 /// warning in the future, possibly with an explicit syntax for coercions
1269 /// providing a convenient way to work around the current issues.
1270 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1271 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1272 ///
1273 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1274 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1275 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1276pub TRIVIAL_NUMERIC_CASTS,
1277 Allow,
1278"detects trivial casts of numeric types which could be removed"
1279}12801281#[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! {
1282/// The `exported_private_dependencies` lint detects private dependencies
1283 /// that are exposed in a public interface.
1284 ///
1285 /// ### Example
1286 ///
1287 /// ```rust,ignore (needs-dependency)
1288 /// pub fn foo() -> Option<some_private_dependency::Thing> {
1289 /// None
1290 /// }
1291 /// ```
1292 ///
1293 /// This will produce:
1294 ///
1295 /// ```text
1296 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1297 /// --> src/lib.rs:3:1
1298 /// |
1299 /// 3 | pub fn foo() -> Option<bar::Thing> {
1300 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1301 /// |
1302 /// = note: `#[warn(exported_private_dependencies)]` on by default
1303 /// ```
1304 ///
1305 /// ### Explanation
1306 ///
1307 /// Dependencies can be marked as "private" to indicate that they are not
1308 /// exposed in the public interface of a crate. This can be used by Cargo
1309 /// to independently resolve those dependencies because it can assume it
1310 /// does not need to unify them with other packages using that same
1311 /// dependency. This lint is an indication of a violation of that
1312 /// contract.
1313 ///
1314 /// To fix this, avoid exposing the dependency in your public interface.
1315 /// Or, switch the dependency to a public dependency.
1316 ///
1317 /// Note that support for this is only available on the nightly channel.
1318 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1319 ///
1320 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1321 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1322pub EXPORTED_PRIVATE_DEPENDENCIES,
1323 Warn,
1324"public interface leaks type from a private dependency"
1325}13261327#[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! {
1328/// The `pub_use_of_private_extern_crate` lint detects a specific
1329 /// situation of re-exporting a private `extern crate`.
1330 ///
1331 /// ### Example
1332 ///
1333 /// ```rust,compile_fail
1334 /// extern crate core;
1335 /// pub use core as reexported_core;
1336 /// ```
1337 ///
1338 /// {{produces}}
1339 ///
1340 /// ### Explanation
1341 ///
1342 /// A public `use` declaration should not be used to publically re-export a
1343 /// private `extern crate`. `pub extern crate` should be used instead.
1344 ///
1345 /// This was historically allowed, but is not the intended behavior
1346 /// according to the visibility rules. This is a [future-incompatible]
1347 /// lint to transition this to a hard error in the future. See [issue
1348 /// #127909] for more details.
1349 ///
1350 /// [issue #127909]: https://github.com/rust-lang/rust/issues/127909
1351 /// [future-incompatible]: ../index.md#future-incompatible-lints
1352pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1353 Deny,
1354"detect public re-exports of private extern crates",
1355 @future_incompatible = FutureIncompatibleInfo {
1356 reason: fcw!(FutureReleaseError #127909),
1357 report_in_deps: true,
1358 };
1359}13601361#[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! {
1362/// The `invalid_type_param_default` lint detects type parameter defaults
1363 /// erroneously allowed in an invalid location.
1364 ///
1365 /// ### Example
1366 ///
1367 /// ```rust,compile_fail
1368 /// fn foo<T=i32>(t: T) {}
1369 /// ```
1370 ///
1371 /// {{produces}}
1372 ///
1373 /// ### Explanation
1374 ///
1375 /// Default type parameters were only intended to be allowed in certain
1376 /// situations, but historically the compiler allowed them everywhere.
1377 /// This is a [future-incompatible] lint to transition this to a hard
1378 /// error in the future. See [issue #36887] for more details.
1379 ///
1380 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1381 /// [future-incompatible]: ../index.md#future-incompatible-lints
1382pub INVALID_TYPE_PARAM_DEFAULT,
1383 Deny,
1384"type parameter default erroneously allowed in invalid location",
1385 @future_incompatible = FutureIncompatibleInfo {
1386 reason: fcw!(FutureReleaseError #36887),
1387 report_in_deps: true,
1388 };
1389}13901391#[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! {
1392/// The `renamed_and_removed_lints` lint detects lints that have been
1393 /// renamed or removed.
1394 ///
1395 /// ### Example
1396 ///
1397 /// ```rust
1398 /// #![deny(raw_pointer_derive)]
1399 /// ```
1400 ///
1401 /// {{produces}}
1402 ///
1403 /// ### Explanation
1404 ///
1405 /// To fix this, either remove the lint or use the new name. This can help
1406 /// avoid confusion about lints that are no longer valid, and help
1407 /// maintain consistency for renamed lints.
1408pub RENAMED_AND_REMOVED_LINTS,
1409 Warn,
1410"lints that have been renamed or removed"
1411}14121413#[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! {
1414/// The `const_item_mutation` lint detects attempts to mutate a `const`
1415 /// item.
1416 ///
1417 /// ### Example
1418 ///
1419 /// ```rust
1420 /// const FOO: [i32; 1] = [0];
1421 ///
1422 /// fn main() {
1423 /// FOO[0] = 1;
1424 /// // This will print "[0]".
1425 /// println!("{:?}", FOO);
1426 /// }
1427 /// ```
1428 ///
1429 /// {{produces}}
1430 ///
1431 /// ### Explanation
1432 ///
1433 /// Trying to directly mutate a `const` item is almost always a mistake.
1434 /// What is happening in the example above is that a temporary copy of the
1435 /// `const` is mutated, but the original `const` is not. Each time you
1436 /// refer to the `const` by name (such as `FOO` in the example above), a
1437 /// separate copy of the value is inlined at that location.
1438 ///
1439 /// This lint checks for writing directly to a field (`FOO.field =
1440 /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1441 /// reference to the const item (`&mut FOO`), including through an
1442 /// autoderef (`FOO.some_mut_self_method()`).
1443 ///
1444 /// There are various alternatives depending on what you are trying to
1445 /// accomplish:
1446 ///
1447 /// * First, always reconsider using mutable globals, as they can be
1448 /// difficult to use correctly, and can make the code more difficult to
1449 /// use or understand.
1450 /// * If you are trying to perform a one-time initialization of a global:
1451 /// * If the value can be computed at compile-time, consider using
1452 /// const-compatible values (see [Constant Evaluation]).
1453 /// * For more complex single-initialization cases, consider using
1454 /// [`std::sync::LazyLock`].
1455 /// * If you truly need a mutable global, consider using a [`static`],
1456 /// which has a variety of options:
1457 /// * Simple data types can be directly defined and mutated with an
1458 /// [`atomic`] type.
1459 /// * More complex types can be placed in a synchronization primitive
1460 /// like a [`Mutex`], which can be initialized with one of the options
1461 /// listed above.
1462 /// * A [mutable `static`] is a low-level primitive, requiring unsafe.
1463 /// Typically This should be avoided in preference of something
1464 /// higher-level like one of the above.
1465 ///
1466 /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1467 /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1468 /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1469 /// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
1470 /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1471 /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1472pub CONST_ITEM_MUTATION,
1473 Warn,
1474"detects attempts to mutate a `const` item",
1475}14761477#[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! {
1478/// The `patterns_in_fns_without_body` lint detects `mut` identifier
1479 /// patterns as a parameter in functions without a body.
1480 ///
1481 /// ### Example
1482 ///
1483 /// ```rust,compile_fail
1484 /// trait Trait {
1485 /// fn foo(mut arg: u8);
1486 /// }
1487 /// ```
1488 ///
1489 /// {{produces}}
1490 ///
1491 /// ### Explanation
1492 ///
1493 /// To fix this, remove `mut` from the parameter in the trait definition;
1494 /// it can be used in the implementation. That is, the following is OK:
1495 ///
1496 /// ```rust
1497 /// trait Trait {
1498 /// fn foo(arg: u8); // Removed `mut` here
1499 /// }
1500 ///
1501 /// impl Trait for i32 {
1502 /// fn foo(mut arg: u8) { // `mut` here is OK
1503 ///
1504 /// }
1505 /// }
1506 /// ```
1507 ///
1508 /// Trait definitions can define functions without a body to specify a
1509 /// function that implementors must define. The parameter names in the
1510 /// body-less functions are only allowed to be `_` or an [identifier] for
1511 /// documentation purposes (only the type is relevant). Previous versions
1512 /// of the compiler erroneously allowed [identifier patterns] with the
1513 /// `mut` keyword, but this was not intended to be allowed. This is a
1514 /// [future-incompatible] lint to transition this to a hard error in the
1515 /// future. See [issue #35203] for more details.
1516 ///
1517 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1518 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1519 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1520 /// [future-incompatible]: ../index.md#future-incompatible-lints
1521pub PATTERNS_IN_FNS_WITHOUT_BODY,
1522 Deny,
1523"patterns in functions without body were erroneously allowed",
1524 @future_incompatible = FutureIncompatibleInfo {
1525 reason: fcw!(FutureReleaseError #35203),
1526 };
1527}15281529#[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! {
1530/// The `late_bound_lifetime_arguments` lint detects generic lifetime
1531 /// arguments in path segments with late bound lifetime parameters.
1532 ///
1533 /// ### Example
1534 ///
1535 /// ```rust
1536 /// struct S;
1537 ///
1538 /// impl S {
1539 /// fn late(self, _: &u8, _: &u8) {}
1540 /// }
1541 ///
1542 /// fn main() {
1543 /// S.late::<'static>(&0, &0);
1544 /// }
1545 /// ```
1546 ///
1547 /// {{produces}}
1548 ///
1549 /// ### Explanation
1550 ///
1551 /// It is not clear how to provide arguments for early-bound lifetime
1552 /// parameters if they are intermixed with late-bound parameters in the
1553 /// same list. For now, providing any explicit arguments will trigger this
1554 /// lint if late-bound parameters are present, so in the future a solution
1555 /// can be adopted without hitting backward compatibility issues. This is
1556 /// a [future-incompatible] lint to transition this to a hard error in the
1557 /// future. See [issue #42868] for more details, along with a description
1558 /// of the difference between early and late-bound parameters.
1559 ///
1560 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1561 /// [future-incompatible]: ../index.md#future-incompatible-lints
1562pub LATE_BOUND_LIFETIME_ARGUMENTS,
1563 Warn,
1564"detects generic lifetime arguments in path segments with late bound lifetime parameters",
1565 @future_incompatible = FutureIncompatibleInfo {
1566 reason: fcw!(FutureReleaseError #42868),
1567 };
1568}15691570#[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! {
1571/// The `coherence_leak_check` lint detects conflicting implementations of
1572 /// a trait that are only distinguished by the old leak-check code.
1573 ///
1574 /// ### Example
1575 ///
1576 /// ```rust
1577 /// trait SomeTrait { }
1578 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1579 /// impl<'a> SomeTrait for fn(&'a u8) { }
1580 /// ```
1581 ///
1582 /// {{produces}}
1583 ///
1584 /// ### Explanation
1585 ///
1586 /// In the past, the compiler would accept trait implementations for
1587 /// identical functions that differed only in where the lifetime binder
1588 /// appeared. Due to a change in the borrow checker implementation to fix
1589 /// several bugs, this is no longer allowed. However, since this affects
1590 /// existing code, this is a [future-incompatible] lint to transition this
1591 /// to a hard error in the future.
1592 ///
1593 /// Code relying on this pattern should introduce "[newtypes]",
1594 /// like `struct Foo(for<'a> fn(&'a u8))`.
1595 ///
1596 /// See [issue #56105] for more details.
1597 ///
1598 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1599 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1600 /// [future-incompatible]: ../index.md#future-incompatible-lints
1601pub COHERENCE_LEAK_CHECK,
1602 Warn,
1603"distinct impls distinguished only by the leak-check code",
1604 @future_incompatible = FutureIncompatibleInfo {
1605 reason: fcw!("the behavior may change in a future release" #56105),
1606 };
1607}16081609#[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! {
1610/// The `deprecated` lint detects use of deprecated items.
1611 ///
1612 /// ### Example
1613 ///
1614 /// ```rust
1615 /// #[deprecated]
1616 /// fn foo() {}
1617 ///
1618 /// fn bar() {
1619 /// foo();
1620 /// }
1621 /// ```
1622 ///
1623 /// {{produces}}
1624 ///
1625 /// ### Explanation
1626 ///
1627 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1628 /// indicate that they should no longer be used. Usually the attribute
1629 /// should include a note on what to use instead, or check the
1630 /// documentation.
1631 ///
1632 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1633pub DEPRECATED,
1634 Warn,
1635"detects use of deprecated items",
1636 report_in_external_macro
1637}16381639#[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! {
1640/// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1641 ///
1642 /// ### Example
1643 ///
1644 /// ```rust
1645 /// unsafe {}
1646 /// ```
1647 ///
1648 /// {{produces}}
1649 ///
1650 /// ### Explanation
1651 ///
1652 /// If nothing within the block requires `unsafe`, then remove the
1653 /// `unsafe` marker because it is not required and may cause confusion.
1654pub UNUSED_UNSAFE,
1655 Warn,
1656"unnecessary use of an `unsafe` block"
1657}16581659#[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! {
1660/// The `unused_mut` lint detects mut variables which don't need to be
1661 /// mutable.
1662 ///
1663 /// ### Example
1664 ///
1665 /// ```rust
1666 /// let mut x = 5;
1667 /// ```
1668 ///
1669 /// {{produces}}
1670 ///
1671 /// ### Explanation
1672 ///
1673 /// The preferred style is to only mark variables as `mut` if it is
1674 /// required.
1675pub UNUSED_MUT,
1676 Warn,
1677"detect mut variables which don't need to be mutable"
1678}16791680#[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! {
1681/// The `rust_2024_incompatible_pat` lint
1682 /// detects patterns whose meaning will change in the Rust 2024 edition.
1683 ///
1684 /// ### Example
1685 ///
1686 /// ```rust,edition2021
1687 /// #![warn(rust_2024_incompatible_pat)]
1688 ///
1689 /// if let Some(&a) = &Some(&0u8) {
1690 /// let _: u8 = a;
1691 /// }
1692 /// if let Some(mut _a) = &mut Some(0u8) {
1693 /// _a = 7u8;
1694 /// }
1695 /// ```
1696 ///
1697 /// {{produces}}
1698 ///
1699 /// ### Explanation
1700 ///
1701 /// In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,
1702 /// and nor do `&` or `&mut` patterns. The lint will suggest code that
1703 /// has the same meaning in all editions.
1704pub RUST_2024_INCOMPATIBLE_PAT,
1705 Allow,
1706"detects patterns whose meaning will change in Rust 2024",
1707 @future_incompatible = FutureIncompatibleInfo {
1708 reason: fcw!(EditionSemanticsChange 2024 "match-ergonomics"),
1709 };
1710}17111712#[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! {
1713/// The `unconditional_recursion` lint detects functions that cannot
1714 /// return without calling themselves.
1715 ///
1716 /// ### Example
1717 ///
1718 /// ```rust
1719 /// fn foo() {
1720 /// foo();
1721 /// }
1722 /// ```
1723 ///
1724 /// {{produces}}
1725 ///
1726 /// ### Explanation
1727 ///
1728 /// It is usually a mistake to have a recursive call that does not have
1729 /// some condition to cause it to terminate. If you really intend to have
1730 /// an infinite loop, using a `loop` expression is recommended.
1731pub UNCONDITIONAL_RECURSION,
1732 Warn,
1733"functions that cannot return without calling themselves"
1734}17351736#[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! {
1737/// The `single_use_lifetimes` lint detects lifetimes that are only used
1738 /// once.
1739 ///
1740 /// ### Example
1741 ///
1742 /// ```rust,compile_fail
1743 /// #![deny(single_use_lifetimes)]
1744 ///
1745 /// fn foo<'a>(x: &'a u32) {}
1746 /// ```
1747 ///
1748 /// {{produces}}
1749 ///
1750 /// ### Explanation
1751 ///
1752 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1753 /// should only be used to link together two things. Otherwise, you should
1754 /// just use `'_` to indicate that the lifetime is not linked to anything,
1755 /// or elide the lifetime altogether if possible.
1756 ///
1757 /// This lint is "allow" by default because it was introduced at a time
1758 /// when `'_` and elided lifetimes were first being introduced, and this
1759 /// lint would be too noisy. Also, there are some known false positives
1760 /// that it produces. See [RFC 2115] for historical context, and [issue
1761 /// #44752] for more details.
1762 ///
1763 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1764 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1765pub SINGLE_USE_LIFETIMES,
1766 Allow,
1767"detects lifetime parameters that are only used once"
1768}17691770#[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! {
1771/// The `unused_lifetimes` lint detects lifetime parameters that are never
1772 /// used.
1773 ///
1774 /// ### Example
1775 ///
1776 /// ```rust,compile_fail
1777 /// #[deny(unused_lifetimes)]
1778 ///
1779 /// pub fn foo<'a>() {}
1780 /// ```
1781 ///
1782 /// {{produces}}
1783 ///
1784 /// ### Explanation
1785 ///
1786 /// Unused lifetime parameters may signal a mistake or unfinished code.
1787 /// Consider removing the parameter.
1788pub UNUSED_LIFETIMES,
1789 Allow,
1790"detects lifetime parameters that are never used"
1791}17921793#[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! {
1794/// The `redundant_lifetimes` lint detects lifetime parameters that are
1795 /// redundant because they are equal to another named lifetime.
1796 ///
1797 /// ### Example
1798 ///
1799 /// ```rust,compile_fail
1800 /// #[deny(redundant_lifetimes)]
1801 ///
1802 /// // `'a = 'static`, so all usages of `'a` can be replaced with `'static`
1803 /// pub fn bar<'a: 'static>() {}
1804 ///
1805 /// // `'a = 'b`, so all usages of `'b` can be replaced with `'a`
1806 /// pub fn bar<'a: 'b, 'b: 'a>() {}
1807 /// ```
1808 ///
1809 /// {{produces}}
1810 ///
1811 /// ### Explanation
1812 ///
1813 /// Unused lifetime parameters may signal a mistake or unfinished code.
1814 /// Consider removing the parameter.
1815pub REDUNDANT_LIFETIMES,
1816 Allow,
1817"detects lifetime parameters that are redundant because they are equal to some other named lifetime"
1818}18191820#[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! {
1821/// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1822 /// inference variable.
1823 ///
1824 /// ### Example
1825 ///
1826 /// ```rust,edition2015
1827 /// // edition 2015
1828 /// let data = std::ptr::null();
1829 /// let _ = &data as *const *const ();
1830 ///
1831 /// if data.is_null() {}
1832 /// ```
1833 ///
1834 /// {{produces}}
1835 ///
1836 /// ### Explanation
1837 ///
1838 /// This kind of inference was previously allowed, but with the future
1839 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1840 /// resolve this, use an explicit type instead of relying on type
1841 /// inference.
1842 ///
1843 /// This is a [future-incompatible] lint to transition this to a hard
1844 /// error in the 2018 edition. See [issue #46906] for more details. This
1845 /// is currently a hard-error on the 2018 edition, and is "warn" by
1846 /// default in the 2015 edition.
1847 ///
1848 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1849 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1850 /// [future-incompatible]: ../index.md#future-incompatible-lints
1851pub TYVAR_BEHIND_RAW_POINTER,
1852 Warn,
1853"raw pointer to an inference variable",
1854 @future_incompatible = FutureIncompatibleInfo {
1855 reason: fcw!(EditionError 2018 "tyvar-behind-raw-pointer"),
1856 };
1857}18581859#[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! {
1860/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1861 /// lifetime parameters.
1862 ///
1863 /// ### Example
1864 ///
1865 /// ```rust,compile_fail
1866 /// #![deny(elided_lifetimes_in_paths)]
1867 /// #![deny(warnings)]
1868 /// struct Foo<'a> {
1869 /// x: &'a u32
1870 /// }
1871 ///
1872 /// fn foo(x: &Foo) {
1873 /// }
1874 /// ```
1875 ///
1876 /// {{produces}}
1877 ///
1878 /// ### Explanation
1879 ///
1880 /// Elided lifetime parameters can make it difficult to see at a glance
1881 /// that borrowing is occurring. This lint ensures that lifetime
1882 /// parameters are always explicitly stated, even if it is the `'_`
1883 /// [placeholder lifetime].
1884 ///
1885 /// This lint is "allow" by default because it has some known issues, and
1886 /// may require a significant transition for old code.
1887 ///
1888 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1889pub ELIDED_LIFETIMES_IN_PATHS,
1890 Allow,
1891"hidden lifetime parameters in types are deprecated"
1892}18931894#[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! {
1895/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1896 /// objects.
1897 ///
1898 /// ### Example
1899 ///
1900 /// ```rust,edition2018
1901 /// trait Trait { }
1902 ///
1903 /// fn takes_trait_object(_: Box<Trait>) {
1904 /// }
1905 /// ```
1906 ///
1907 /// {{produces}}
1908 ///
1909 /// ### Explanation
1910 ///
1911 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1912 /// reading code as to whether or not you are looking at a trait object.
1913 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1914 /// with [`impl Trait`].
1915 ///
1916 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1917pub BARE_TRAIT_OBJECTS,
1918 Warn,
1919"suggest using `dyn Trait` for trait objects",
1920 @future_incompatible = FutureIncompatibleInfo {
1921 reason: fcw!(EditionError 2021 "warnings-promoted-to-error"),
1922 };
1923}19241925#[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! {
1926/// The `absolute_paths_not_starting_with_crate` lint detects fully
1927 /// qualified paths that start with a module name instead of `crate`,
1928 /// `self`, or an extern crate name
1929 ///
1930 /// ### Example
1931 ///
1932 /// ```rust,edition2015,compile_fail
1933 /// #![deny(absolute_paths_not_starting_with_crate)]
1934 ///
1935 /// mod foo {
1936 /// pub fn bar() {}
1937 /// }
1938 ///
1939 /// fn main() {
1940 /// ::foo::bar();
1941 /// }
1942 /// ```
1943 ///
1944 /// {{produces}}
1945 ///
1946 /// ### Explanation
1947 ///
1948 /// Rust [editions] allow the language to evolve without breaking
1949 /// backwards compatibility. This lint catches code that uses absolute
1950 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1951 /// paths (those starting with `::`) refer to either the crate root or an
1952 /// external crate. In the 2018 edition it was changed so that they only
1953 /// refer to external crates. The path prefix `crate::` should be used
1954 /// instead to reference items from the crate root.
1955 ///
1956 /// If you switch the compiler from the 2015 to 2018 edition without
1957 /// updating the code, then it will fail to compile if the old style paths
1958 /// are used. You can manually change the paths to use the `crate::`
1959 /// prefix to transition to the 2018 edition.
1960 ///
1961 /// This lint solves the problem automatically. It is "allow" by default
1962 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1963 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1964 /// and automatically apply the suggested fix from the compiler. This
1965 /// provides a completely automated way to update old code to the 2018
1966 /// edition.
1967 ///
1968 /// [editions]: https://doc.rust-lang.org/edition-guide/
1969 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1970pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1971 Allow,
1972"fully qualified paths that start with a module name \
1973 instead of `crate`, `self`, or an extern crate name",
1974 @future_incompatible = FutureIncompatibleInfo {
1975 reason: fcw!(EditionError 2018 "path-changes"),
1976 };
1977}19781979#[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! {
1980/// The `unstable_name_collisions` lint detects that you have used a name
1981 /// that the standard library plans to add in the future.
1982 ///
1983 /// ### Example
1984 ///
1985 /// ```rust
1986 /// trait MyIterator : Iterator {
1987 /// // is_partitioned is an unstable method that already exists on the Iterator trait
1988 /// fn is_partitioned<P>(self, predicate: P) -> bool
1989 /// where
1990 /// Self: Sized,
1991 /// P: FnMut(Self::Item) -> bool,
1992 /// {true}
1993 /// }
1994 ///
1995 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1996 ///
1997 /// let x = vec![1, 2, 3];
1998 /// let _ = x.iter().is_partitioned(|_| true);
1999 /// ```
2000 ///
2001 /// {{produces}}
2002 ///
2003 /// ### Explanation
2004 ///
2005 /// When new methods are added to traits in the standard library, they are
2006 /// usually added in an "unstable" form which is only available on the
2007 /// [nightly channel] with a [`feature` attribute]. If there is any
2008 /// preexisting code which extends a trait to have a method with the same
2009 /// name, then the names will collide. In the future, when the method is
2010 /// stabilized, this will cause an error due to the ambiguity. This lint
2011 /// is an early-warning to let you know that there may be a collision in
2012 /// the future. This can be avoided by adding type annotations to
2013 /// disambiguate which trait method you intend to call, such as
2014 /// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
2015 ///
2016 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2017 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
2018pub UNSTABLE_NAME_COLLISIONS,
2019 Warn,
2020"detects name collision with an existing but unstable method",
2021 @future_incompatible = FutureIncompatibleInfo {
2022 reason: fcw!(
2023"once this associated item is added to the standard library, \
2024 the ambiguity may cause an error or change in behavior!"
2025#48919
2026),
2027// Note: this item represents future incompatibility of all unstable functions in the
2028 // standard library, and thus should never be removed or changed to an error.
2029};
2030}20312032#[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! {
2033/// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
2034 /// in [`if let`]s, [`while let`]s, and `if let` guards.
2035 ///
2036 /// ### Example
2037 ///
2038 /// ```rust
2039 /// if let _ = 123 {
2040 /// println!("always runs!");
2041 /// }
2042 /// ```
2043 ///
2044 /// {{produces}}
2045 ///
2046 /// ### Explanation
2047 ///
2048 /// There usually isn't a reason to have an irrefutable pattern in an
2049 /// `if let` or `while let` statement, because the pattern will always match
2050 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
2051 /// when generating code with a macro, forbidding irrefutable patterns
2052 /// would require awkward workarounds in situations where the macro
2053 /// doesn't know if the pattern is refutable or not. This lint allows
2054 /// macros to accept this form, while alerting for a possibly incorrect
2055 /// use in normal code.
2056 ///
2057 /// See [RFC 2086] for more details.
2058 ///
2059 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
2060 /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
2061 /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
2062 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
2063 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
2064 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
2065pub IRREFUTABLE_LET_PATTERNS,
2066 Warn,
2067"detects irrefutable patterns in `if let` and `while let` statements"
2068}20692070#[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! {
2071/// The `unused_labels` lint detects [labels] that are never used.
2072 ///
2073 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
2074 ///
2075 /// ### Example
2076 ///
2077 /// ```rust,no_run
2078 /// 'unused_label: loop {}
2079 /// ```
2080 ///
2081 /// {{produces}}
2082 ///
2083 /// ### Explanation
2084 ///
2085 /// Unused labels may signal a mistake or unfinished code. To silence the
2086 /// warning for the individual label, prefix it with an underscore such as
2087 /// `'_my_label:`.
2088pub UNUSED_LABELS,
2089 Warn,
2090"detects labels that are never used"
2091}20922093#[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! {
2094/// The `proc_macro_derive_resolution_fallback` lint detects proc macro
2095 /// derives using inaccessible names from parent modules.
2096 ///
2097 /// ### Example
2098 ///
2099 /// ```rust,ignore (proc-macro)
2100 /// // foo.rs
2101 /// #![crate_type = "proc-macro"]
2102 ///
2103 /// extern crate proc_macro;
2104 ///
2105 /// use proc_macro::*;
2106 ///
2107 /// #[proc_macro_derive(Foo)]
2108 /// pub fn foo1(a: TokenStream) -> TokenStream {
2109 /// drop(a);
2110 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2111 /// }
2112 /// ```
2113 ///
2114 /// ```rust,ignore (needs-dependency)
2115 /// // bar.rs
2116 /// #[macro_use]
2117 /// extern crate foo;
2118 ///
2119 /// struct Something;
2120 ///
2121 /// #[derive(Foo)]
2122 /// struct Another;
2123 ///
2124 /// fn main() {}
2125 /// ```
2126 ///
2127 /// This will produce:
2128 ///
2129 /// ```text
2130 /// warning: cannot find type `Something` in this scope
2131 /// --> src/main.rs:8:10
2132 /// |
2133 /// 8 | #[derive(Foo)]
2134 /// | ^^^ names from parent modules are not accessible without an explicit import
2135 /// |
2136 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2137 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2138 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2139 /// ```
2140 ///
2141 /// ### Explanation
2142 ///
2143 /// If a proc-macro generates a module, the compiler unintentionally
2144 /// allowed items in that module to refer to items in the crate root
2145 /// without importing them. This is a [future-incompatible] lint to
2146 /// transition this to a hard error in the future. See [issue #50504] for
2147 /// more details.
2148 ///
2149 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2150 /// [future-incompatible]: ../index.md#future-incompatible-lints
2151pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2152 Deny,
2153"detects proc macro derives using inaccessible names from parent modules",
2154 @future_incompatible = FutureIncompatibleInfo {
2155 reason: fcw!(FutureReleaseError #83583),
2156 report_in_deps: true,
2157 };
2158}21592160#[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! {
2161/// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
2162 ///
2163 /// ### Example
2164 ///
2165 /// ```rust,ignore (needs extern crate)
2166 /// #![deny(macro_use_extern_crate)]
2167 ///
2168 /// #[macro_use]
2169 /// extern crate serde_json;
2170 ///
2171 /// fn main() {
2172 /// let _ = json!{{}};
2173 /// }
2174 /// ```
2175 ///
2176 /// This will produce:
2177 ///
2178 /// ```text
2179 /// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
2180 /// --> src/main.rs:3:1
2181 /// |
2182 /// 3 | #[macro_use]
2183 /// | ^^^^^^^^^^^^
2184 /// |
2185 /// = help: remove it and import macros at use sites with a `use` item instead
2186 /// note: the lint level is defined here
2187 /// --> src/main.rs:1:9
2188 /// |
2189 /// 1 | #![deny(macro_use_extern_crate)]
2190 /// | ^^^^^^^^^^^^^^^^^^^^^^
2191 /// ```
2192 ///
2193 /// ### Explanation
2194 ///
2195 /// The [`macro_use` attribute] on an [`extern crate`] item causes
2196 /// macros in that external crate to be brought into the prelude of the
2197 /// crate, making the macros in scope everywhere. As part of the efforts
2198 /// to simplify handling of dependencies in the [2018 edition], the use of
2199 /// `extern crate` is being phased out. To bring macros from extern crates
2200 /// into scope, it is recommended to use a [`use` import].
2201 ///
2202 /// This lint is "allow" by default because this is a stylistic choice
2203 /// that has not been settled, see [issue #52043] for more information.
2204 ///
2205 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2206 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2207 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2208pub MACRO_USE_EXTERN_CRATE,
2209 Allow,
2210"the `#[macro_use]` attribute is now deprecated in favor of using macros \
2211 via the module system"
2212}22132214#[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! {
2215/// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2216 /// detects macro-expanded [`macro_export`] macros from the current crate
2217 /// that cannot be referred to by absolute paths.
2218 ///
2219 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2220 ///
2221 /// ### Example
2222 ///
2223 /// ```rust,compile_fail
2224 /// macro_rules! define_exported {
2225 /// () => {
2226 /// #[macro_export]
2227 /// macro_rules! exported {
2228 /// () => {};
2229 /// }
2230 /// };
2231 /// }
2232 ///
2233 /// define_exported!();
2234 ///
2235 /// fn main() {
2236 /// crate::exported!();
2237 /// }
2238 /// ```
2239 ///
2240 /// {{produces}}
2241 ///
2242 /// ### Explanation
2243 ///
2244 /// The intent is that all macros marked with the `#[macro_export]`
2245 /// attribute are made available in the root of the crate. However, when a
2246 /// `macro_rules!` definition is generated by another macro, the macro
2247 /// expansion is unable to uphold this rule. This is a
2248 /// [future-incompatible] lint to transition this to a hard error in the
2249 /// future. See [issue #53495] for more details.
2250 ///
2251 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2252 /// [future-incompatible]: ../index.md#future-incompatible-lints
2253pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2254 Deny,
2255"macro-expanded `macro_export` macros from the current crate \
2256 cannot be referred to by absolute paths",
2257 @future_incompatible = FutureIncompatibleInfo {
2258 reason: fcw!(FutureReleaseError #52234),
2259 report_in_deps: true,
2260 };
2261 crate_level_only
2262}22632264#[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! {
2265/// The `explicit_outlives_requirements` lint detects unnecessary
2266 /// lifetime bounds that can be inferred.
2267 ///
2268 /// ### Example
2269 ///
2270 /// ```rust,compile_fail
2271 /// # #![allow(unused)]
2272 /// #![deny(explicit_outlives_requirements)]
2273 /// #![deny(warnings)]
2274 ///
2275 /// struct SharedRef<'a, T>
2276 /// where
2277 /// T: 'a,
2278 /// {
2279 /// data: &'a T,
2280 /// }
2281 /// ```
2282 ///
2283 /// {{produces}}
2284 ///
2285 /// ### Explanation
2286 ///
2287 /// If a `struct` contains a reference, such as `&'a T`, the compiler
2288 /// requires that `T` outlives the lifetime `'a`. This historically
2289 /// required writing an explicit lifetime bound to indicate this
2290 /// requirement. However, this can be overly explicit, causing clutter and
2291 /// unnecessary complexity. The language was changed to automatically
2292 /// infer the bound if it is not specified. Specifically, if the struct
2293 /// contains a reference, directly or indirectly, to `T` with lifetime
2294 /// `'x`, then it will infer that `T: 'x` is a requirement.
2295 ///
2296 /// This lint is "allow" by default because it can be noisy for existing
2297 /// code that already had these requirements. This is a stylistic choice,
2298 /// as it is still valid to explicitly state the bound. It also has some
2299 /// false positives that can cause confusion.
2300 ///
2301 /// See [RFC 2093] for more details.
2302 ///
2303 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2304pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2305 Allow,
2306"outlives requirements can be inferred"
2307}23082309#[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! {
2310/// The `deprecated_in_future` lint is internal to rustc and should not be
2311 /// used by user code.
2312 ///
2313 /// This lint is only enabled in the standard library. It works with the
2314 /// use of `#[deprecated]` with a `since` field of a version in the future.
2315 /// This allows something to be marked as deprecated in a future version,
2316 /// and then this lint will ensure that the item is no longer used in the
2317 /// standard library. See the [stability documentation] for more details.
2318 ///
2319 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2320pub DEPRECATED_IN_FUTURE,
2321 Allow,
2322"detects use of items that will be deprecated in a future version",
2323 report_in_external_macro
2324}23252326#[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! {
2327/// The `ambiguous_associated_items` lint detects ambiguity between
2328 /// [associated items] and [enum variants].
2329 ///
2330 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2331 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2332 ///
2333 /// ### Example
2334 ///
2335 /// ```rust,compile_fail
2336 /// enum E {
2337 /// V
2338 /// }
2339 ///
2340 /// trait Tr {
2341 /// type V;
2342 /// fn foo() -> Self::V;
2343 /// }
2344 ///
2345 /// impl Tr for E {
2346 /// type V = u8;
2347 /// // `Self::V` is ambiguous because it may refer to the associated type or
2348 /// // the enum variant.
2349 /// fn foo() -> Self::V { 0 }
2350 /// }
2351 /// ```
2352 ///
2353 /// {{produces}}
2354 ///
2355 /// ### Explanation
2356 ///
2357 /// Previous versions of Rust did not allow accessing enum variants
2358 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2359 /// introduced some situations where it can be ambiguous what a type
2360 /// was referring to.
2361 ///
2362 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2363 /// state which type to use. For example, in the above example the
2364 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2365 /// specifically refer to the associated type.
2366 ///
2367 /// This is a [future-incompatible] lint to transition this to a hard
2368 /// error in the future. See [issue #57644] for more details.
2369 ///
2370 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2371 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2372 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2373 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2374 /// [future-incompatible]: ../index.md#future-incompatible-lints
2375pub AMBIGUOUS_ASSOCIATED_ITEMS,
2376 Deny,
2377"ambiguous associated items",
2378 @future_incompatible = FutureIncompatibleInfo {
2379 reason: fcw!(FutureReleaseError #57644),
2380 };
2381}23822383#[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! {
2384/// The `inline_no_sanitize` lint detects incompatible use of
2385 /// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
2386 ///
2387 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2388 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2389 ///
2390 /// ### Example
2391 ///
2392 /// ```rust
2393 /// #![feature(sanitize)]
2394 ///
2395 /// #[inline(always)]
2396 /// #[sanitize(address = "off")]
2397 /// fn x() {}
2398 ///
2399 /// fn main() {
2400 /// x()
2401 /// }
2402 /// ```
2403 ///
2404 /// {{produces}}
2405 ///
2406 /// ### Explanation
2407 ///
2408 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2409 /// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
2410 /// Consider temporarily removing `inline` attribute.
2411pub INLINE_NO_SANITIZE,
2412 Warn,
2413r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
2414}24152416#[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! {
2417/// The `rtsan_nonblocking_async` lint detects incompatible use of
2418 /// [`#[sanitize(realtime = "nonblocking")]`][sanitize] on async functions.
2419 ///
2420 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2421 /// ### Example
2422 ///
2423 /// ```rust,no_run
2424 /// #![feature(sanitize)]
2425 ///
2426 /// #[sanitize(realtime = "nonblocking")]
2427 /// async fn x() {}
2428 ///
2429 /// fn main() {
2430 /// x();
2431 /// }
2432 /// ```
2433 ///
2434 /// {{produces}}
2435 ///
2436 /// ### Explanation
2437 ///
2438 /// The sanitizer only considers the async function body nonblocking. The executor, which runs on
2439 /// every `.await` point can run non-realtime code, without the sanitizer catching it.
2440pub RTSAN_NONBLOCKING_ASYNC,
2441 Warn,
2442r#"detects incompatible uses of `#[sanitize(realtime = "nonblocking")]` on async functions"#,
2443}24442445#[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! {
2446/// The `asm_sub_register` lint detects using only a subset of a register
2447 /// for inline asm inputs.
2448 ///
2449 /// ### Example
2450 ///
2451 /// ```rust,ignore (fails on non-x86_64)
2452 /// #[cfg(target_arch="x86_64")]
2453 /// use std::arch::asm;
2454 ///
2455 /// fn main() {
2456 /// #[cfg(target_arch="x86_64")]
2457 /// unsafe {
2458 /// asm!("mov {0}, {0}", in(reg) 0i16);
2459 /// }
2460 /// }
2461 /// ```
2462 ///
2463 /// This will produce:
2464 ///
2465 /// ```text
2466 /// warning: formatting may not be suitable for sub-register argument
2467 /// --> src/main.rs:7:19
2468 /// |
2469 /// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
2470 /// | ^^^ ^^^ ---- for this argument
2471 /// |
2472 /// = note: `#[warn(asm_sub_register)]` on by default
2473 /// = help: use the `x` modifier to have the register formatted as `ax`
2474 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2475 /// ```
2476 ///
2477 /// ### Explanation
2478 ///
2479 /// Registers on some architectures can use different names to refer to a
2480 /// subset of the register. By default, the compiler will use the name for
2481 /// the full register size. To explicitly use a subset of the register,
2482 /// you can override the default by using a modifier on the template
2483 /// string operand to specify when subregister to use. This lint is issued
2484 /// if you pass in a value with a smaller data type than the default
2485 /// register size, to alert you of possibly using the incorrect width. To
2486 /// fix this, add the suggested modifier to the template, or cast the
2487 /// value to the correct size.
2488 ///
2489 /// See [register template modifiers] in the reference for more details.
2490 ///
2491 /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2492pub ASM_SUB_REGISTER,
2493 Warn,
2494"using only a subset of a register for inline asm inputs",
2495}24962497#[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! {
2498/// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2499 /// `.att_syntax` directives.
2500 ///
2501 /// ### Example
2502 ///
2503 /// ```rust,ignore (fails on non-x86_64)
2504 /// #[cfg(target_arch="x86_64")]
2505 /// use std::arch::asm;
2506 ///
2507 /// fn main() {
2508 /// #[cfg(target_arch="x86_64")]
2509 /// unsafe {
2510 /// asm!(
2511 /// ".att_syntax",
2512 /// "movq %{0}, %{0}", in(reg) 0usize
2513 /// );
2514 /// }
2515 /// }
2516 /// ```
2517 ///
2518 /// This will produce:
2519 ///
2520 /// ```text
2521 /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2522 /// --> src/main.rs:8:14
2523 /// |
2524 /// 8 | ".att_syntax",
2525 /// | ^^^^^^^^^^^
2526 /// |
2527 /// = note: `#[warn(bad_asm_style)]` on by default
2528 /// ```
2529 ///
2530 /// ### Explanation
2531 ///
2532 /// On x86, `asm!` uses the intel assembly syntax by default. While this
2533 /// can be switched using assembler directives like `.att_syntax`, using the
2534 /// `att_syntax` option is recommended instead because it will also properly
2535 /// prefix register placeholders with `%` as required by AT&T syntax.
2536pub BAD_ASM_STYLE,
2537 Warn,
2538"incorrect use of inline assembly",
2539}25402541#[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! {
2542/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2543 /// functions without an explicit unsafe block.
2544 ///
2545 /// ### Example
2546 ///
2547 /// ```rust,compile_fail
2548 /// #![deny(unsafe_op_in_unsafe_fn)]
2549 ///
2550 /// unsafe fn foo() {}
2551 ///
2552 /// unsafe fn bar() {
2553 /// foo();
2554 /// }
2555 ///
2556 /// fn main() {}
2557 /// ```
2558 ///
2559 /// {{produces}}
2560 ///
2561 /// ### Explanation
2562 ///
2563 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2564 /// body. However, this can increase the surface area of code that needs
2565 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2566 /// convenient way to make it clear exactly which parts of the code are
2567 /// performing unsafe operations. In the future, it is desired to change
2568 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2569 /// without an `unsafe` block.
2570 ///
2571 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2572 ///
2573 /// This lint is "allow" by default on editions up to 2021, from 2024 it is
2574 /// "warn" by default; the plan for increasing severity further is
2575 /// still being considered. See [RFC #2585] and [issue #71668] for more
2576 /// details.
2577 ///
2578 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2579 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2580 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2581 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2582 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2583pub UNSAFE_OP_IN_UNSAFE_FN,
2584 Allow,
2585"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2586 @future_incompatible = FutureIncompatibleInfo {
2587 reason: fcw!(EditionError 2024 "unsafe-op-in-unsafe-fn"),
2588 explain_reason: false
2589};
2590 @edition Edition2024 => Warn;
2591}25922593#[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! {
2594/// The `const_evaluatable_unchecked` lint detects a generic constant used
2595 /// in a type.
2596 ///
2597 /// ### Example
2598 ///
2599 /// ```rust
2600 /// const fn foo<T>() -> usize {
2601 /// if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2602 /// 4
2603 /// } else {
2604 /// 8
2605 /// }
2606 /// }
2607 ///
2608 /// fn test<T>() {
2609 /// let _ = [0; foo::<T>()];
2610 /// }
2611 /// ```
2612 ///
2613 /// {{produces}}
2614 ///
2615 /// ### Explanation
2616 ///
2617 /// In the 1.43 release, some uses of generic parameters in array repeat
2618 /// expressions were accidentally allowed. This is a [future-incompatible]
2619 /// lint to transition this to a hard error in the future. See [issue
2620 /// #76200] for a more detailed description and possible fixes.
2621 ///
2622 /// [future-incompatible]: ../index.md#future-incompatible-lints
2623 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2624pub CONST_EVALUATABLE_UNCHECKED,
2625 Warn,
2626"detects a generic constant is used in a type without a emitting a warning",
2627 @future_incompatible = FutureIncompatibleInfo {
2628 reason: fcw!(FutureReleaseError #76200),
2629 };
2630}26312632#[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! {
2633/// The `function_item_references` lint detects function references that are
2634 /// formatted with [`fmt::Pointer`] or transmuted.
2635 ///
2636 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2637 ///
2638 /// ### Example
2639 ///
2640 /// ```rust
2641 /// fn foo() { }
2642 ///
2643 /// fn main() {
2644 /// println!("{:p}", &foo);
2645 /// }
2646 /// ```
2647 ///
2648 /// {{produces}}
2649 ///
2650 /// ### Explanation
2651 ///
2652 /// Taking a reference to a function may be mistaken as a way to obtain a
2653 /// pointer to that function. This can give unexpected results when
2654 /// formatting the reference as a pointer or transmuting it. This lint is
2655 /// issued when function references are formatted as pointers, passed as
2656 /// arguments bound by [`fmt::Pointer`] or transmuted.
2657pub FUNCTION_ITEM_REFERENCES,
2658 Warn,
2659"suggest casting to a function pointer when attempting to take references to function items",
2660}26612662#[doc = r" The `uninhabited_static` lint detects uninhabited statics."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[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::Deny,
desc: "uninhabited static",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 74840,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2663/// The `uninhabited_static` lint detects uninhabited statics.
2664 ///
2665 /// ### Example
2666 ///
2667 /// ```rust,compile_fail
2668 /// enum Void {}
2669 /// unsafe extern {
2670 /// static EXTERN: Void;
2671 /// }
2672 /// ```
2673 ///
2674 /// {{produces}}
2675 ///
2676 /// ### Explanation
2677 ///
2678 /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2679 /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2680 /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2681 /// statics). This was accidentally allowed, but is being phased out.
2682pub UNINHABITED_STATIC,
2683 Deny,
2684"uninhabited static",
2685 @future_incompatible = FutureIncompatibleInfo {
2686 reason: fcw!(FutureReleaseError #74840),
2687 report_in_deps: true,
2688 };
2689}26902691#[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! {
2692/// The `unnameable_test_items` lint detects [`#[test]`][test] functions
2693 /// that are not able to be run by the test harness because they are in a
2694 /// position where they are not nameable.
2695 ///
2696 /// [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute
2697 ///
2698 /// ### Example
2699 ///
2700 /// ```rust,test
2701 /// fn main() {
2702 /// #[test]
2703 /// fn foo() {
2704 /// // This test will not fail because it does not run.
2705 /// assert_eq!(1, 2);
2706 /// }
2707 /// }
2708 /// ```
2709 ///
2710 /// {{produces}}
2711 ///
2712 /// ### Explanation
2713 ///
2714 /// In order for the test harness to run a test, the test function must be
2715 /// located in a position where it can be accessed from the crate root.
2716 /// This generally means it must be defined in a module, and not anywhere
2717 /// else such as inside another function. The compiler previously allowed
2718 /// this without an error, so a lint was added as an alert that a test is
2719 /// not being used. Whether or not this should be allowed has not yet been
2720 /// decided, see [RFC 2471] and [issue #36629].
2721 ///
2722 /// [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443
2723 /// [issue #36629]: https://github.com/rust-lang/rust/issues/36629
2724pub UNNAMEABLE_TEST_ITEMS,
2725 Warn,
2726"detects an item that cannot be named being marked as `#[test_case]`",
2727 report_in_external_macro
2728}27292730#[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! {
2731/// The `useless_deprecated` lint detects deprecation attributes with no effect.
2732 ///
2733 /// ### Example
2734 ///
2735 /// ```rust,compile_fail
2736 /// struct X;
2737 ///
2738 /// #[deprecated = "message"]
2739 /// impl Default for X {
2740 /// fn default() -> Self {
2741 /// X
2742 /// }
2743 /// }
2744 /// ```
2745 ///
2746 /// {{produces}}
2747 ///
2748 /// ### Explanation
2749 ///
2750 /// Deprecation attributes have no effect on trait implementations.
2751pub USELESS_DEPRECATED,
2752 Deny,
2753"detects deprecation attributes with no effect",
2754}27552756#[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! {
2757/// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2758 ///
2759 /// ### Example
2760 ///
2761 /// ```rust,compile_fail
2762 /// #![feature(staged_api)]
2763 ///
2764 /// #[derive(Clone)]
2765 /// #[stable(feature = "x", since = "1")]
2766 /// struct S {}
2767 ///
2768 /// #[unstable(feature = "y", issue = "none")]
2769 /// impl Copy for S {}
2770 /// ```
2771 ///
2772 /// {{produces}}
2773 ///
2774 /// ### Explanation
2775 ///
2776 /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2777 /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2778pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2779 Deny,
2780"detects `#[unstable]` on stable trait implementations for stable types"
2781}27822783#[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! {
2784/// The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor
2785 /// was silently allowed due to a bug in the resolver, and which may produce surprising
2786 /// and unintended behavior.
2787 ///
2788 /// Using a `Self` type alias from an outer item was never intended, but was silently allowed.
2789 /// This is deprecated -- and is a hard error when the `Self` type alias references generics
2790 /// that are not in scope.
2791 ///
2792 /// ### Example
2793 ///
2794 /// ```rust,compile_fail
2795 /// #![deny(self_constructor_from_outer_item)]
2796 ///
2797 /// struct S0(usize);
2798 ///
2799 /// impl S0 {
2800 /// fn foo() {
2801 /// const C: S0 = Self(0);
2802 /// fn bar() -> S0 {
2803 /// Self(0)
2804 /// }
2805 /// }
2806 /// }
2807 /// ```
2808 ///
2809 /// {{produces}}
2810 ///
2811 /// ### Explanation
2812 ///
2813 /// The `Self` type alias should not be reachable because nested items are not associated with
2814 /// the scope of the parameters from the parent item.
2815pub SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
2816 Warn,
2817"detect unsupported use of `Self` from outer item",
2818 @future_incompatible = FutureIncompatibleInfo {
2819 reason: fcw!(FutureReleaseError #124186),
2820 };
2821}28222823#[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! {
2824/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2825 /// in macro bodies when the macro is invoked in expression position.
2826 /// This was previous accepted, but is being phased out.
2827 ///
2828 /// ### Example
2829 ///
2830 /// ```rust,compile_fail
2831 /// #![deny(semicolon_in_expressions_from_macros)]
2832 /// macro_rules! foo {
2833 /// () => { true; }
2834 /// }
2835 ///
2836 /// fn main() {
2837 /// let val = match true {
2838 /// true => false,
2839 /// _ => foo!()
2840 /// };
2841 /// }
2842 /// ```
2843 ///
2844 /// {{produces}}
2845 ///
2846 /// ### Explanation
2847 ///
2848 /// Previous, Rust ignored trailing semicolon in a macro
2849 /// body when a macro was invoked in expression position.
2850 /// However, this makes the treatment of semicolons in the language
2851 /// inconsistent, and could lead to unexpected runtime behavior
2852 /// in some circumstances (e.g. if the macro author expects
2853 /// a value to be dropped).
2854 ///
2855 /// This is a [future-incompatible] lint to transition this
2856 /// to a hard error in the future. See [issue #79813] for more details.
2857 ///
2858 /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2859 /// [future-incompatible]: ../index.md#future-incompatible-lints
2860pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2861 Deny,
2862"trailing semicolon in macro body used as expression",
2863 @future_incompatible = FutureIncompatibleInfo {
2864 reason: fcw!(FutureReleaseError #79813),
2865 report_in_deps: true,
2866 };
2867}28682869#[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! {
2870/// The `legacy_derive_helpers` lint detects derive helper attributes
2871 /// that are used before they are introduced.
2872 ///
2873 /// ### Example
2874 ///
2875 /// ```rust,ignore (needs extern crate)
2876 /// #[serde(rename_all = "camelCase")]
2877 /// #[derive(Deserialize)]
2878 /// struct S { /* fields */ }
2879 /// ```
2880 ///
2881 /// produces:
2882 ///
2883 /// ```text
2884 /// warning: derive helper attribute is used before it is introduced
2885 /// --> $DIR/legacy-derive-helpers.rs:1:3
2886 /// |
2887 /// 1 | #[serde(rename_all = "camelCase")]
2888 /// | ^^^^^
2889 /// ...
2890 /// 2 | #[derive(Deserialize)]
2891 /// | ----------- the attribute is introduced here
2892 /// ```
2893 ///
2894 /// ### Explanation
2895 ///
2896 /// Attributes like this work for historical reasons, but attribute expansion works in
2897 /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2898 /// into the future" at not yet expanded part of the item , but such attempts are not always
2899 /// reliable.
2900 ///
2901 /// To fix the warning place the helper attribute after its corresponding derive.
2902 /// ```rust,ignore (needs extern crate)
2903 /// #[derive(Deserialize)]
2904 /// #[serde(rename_all = "camelCase")]
2905 /// struct S { /* fields */ }
2906 /// ```
2907pub LEGACY_DERIVE_HELPERS,
2908 Deny,
2909"detects derive helper attributes that are used before they are introduced",
2910 @future_incompatible = FutureIncompatibleInfo {
2911 reason: fcw!(FutureReleaseError #79202),
2912 report_in_deps: true,
2913 };
2914}29152916#[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! {
2917/// The `large_assignments` lint detects when objects of large
2918 /// types are being moved around.
2919 ///
2920 /// ### Example
2921 ///
2922 /// ```rust,ignore (can crash on some platforms)
2923 /// let x = [0; 50000];
2924 /// let y = x;
2925 /// ```
2926 ///
2927 /// produces:
2928 ///
2929 /// ```text
2930 /// warning: moving a large value
2931 /// --> $DIR/move-large.rs:1:3
2932 /// let y = x;
2933 /// - Copied large value here
2934 /// ```
2935 ///
2936 /// ### Explanation
2937 ///
2938 /// When using a large type in a plain assignment or in a function
2939 /// argument, idiomatic code can be inefficient.
2940 /// Ideally appropriate optimizations would resolve this, but such
2941 /// optimizations are only done in a best-effort manner.
2942 /// This lint will trigger on all sites of large moves and thus allow the
2943 /// user to resolve them in code.
2944pub LARGE_ASSIGNMENTS,
2945 Warn,
2946"detects large moves or copies",
2947}29482949#[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! {
2950/// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
2951 ///
2952 /// ### Example
2953 ///
2954 /// ```text
2955 /// rustc --check-cfg 'cfg()'
2956 /// ```
2957 ///
2958 /// ```rust,ignore (needs command line option)
2959 /// #[cfg(widnows)]
2960 /// fn foo() {}
2961 /// ```
2962 ///
2963 /// This will produce:
2964 ///
2965 /// ```text
2966 /// warning: unexpected `cfg` condition name: `widnows`
2967 /// --> lint_example.rs:1:7
2968 /// |
2969 /// 1 | #[cfg(widnows)]
2970 /// | ^^^^^^^
2971 /// |
2972 /// = note: `#[warn(unexpected_cfgs)]` on by default
2973 /// ```
2974 ///
2975 /// ### Explanation
2976 ///
2977 /// This lint is only active when [`--check-cfg`][check-cfg] arguments are being
2978 /// passed to the compiler and triggers whenever an unexpected condition name or value is
2979 /// used.
2980 ///
2981 /// See the [Checking Conditional Configurations][check-cfg] section for more
2982 /// details.
2983 ///
2984 /// See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in
2985 /// `Cargo.toml`.
2986 ///
2987 /// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
2988 /// [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table
2989pub UNEXPECTED_CFGS,
2990 Warn,
2991"detects unexpected names and values in `#[cfg]` conditions",
2992 report_in_external_macro
2993}29942995#[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! {
2996/// The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.
2997 ///
2998 /// ### Example
2999 ///
3000 /// ```text
3001 /// rustc --cfg unix
3002 /// ```
3003 ///
3004 /// ```rust,ignore (needs command line option)
3005 /// fn main() {}
3006 /// ```
3007 ///
3008 /// This will produce:
3009 ///
3010 /// ```text
3011 /// error: unexpected `--cfg unix` flag
3012 /// |
3013 /// = note: config `unix` is only supposed to be controlled by `--target`
3014 /// = note: manually setting a built-in cfg can and does create incoherent behaviors
3015 /// = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
3016 /// ```
3017 ///
3018 /// ### Explanation
3019 ///
3020 /// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
3021 /// the appropriate `rustc` flag that controls the config. For example setting the `windows`
3022 /// cfg but on Linux based target.
3023pub EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
3024 Deny,
3025"detects builtin cfgs set via the `--cfg`"
3026}30273028#[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(feature = "nightly")]"#]
#[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(feature = "nightly")]"#]
#[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 #154045] for more details."]
#[doc = r""]
#[doc = r" [issue #154045]: https://github.com/rust-lang/rust/issues/154045"]
#[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: 154045,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3029/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3030 /// syntax that is discarded during attribute expansion.
3031 ///
3032 /// ### Example
3033 ///
3034 /// ```rust
3035 /// #[cfg(feature = "nightly")]
3036 /// macro foo() {}
3037 /// ```
3038 ///
3039 /// {{produces}}
3040 ///
3041 /// ### Explanation
3042 ///
3043 /// The input to active attributes such as `#[cfg]` or procedural macro
3044 /// attributes is required to be valid syntax. Previously, the compiler only
3045 /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3046 /// and expanding procedural macros.
3047 ///
3048 /// To avoid relying on unstable syntax, move the use of unstable syntax
3049 /// into a position where the compiler does not parse the syntax, such as a
3050 /// functionlike macro.
3051 ///
3052 /// ```rust
3053 /// # #![deny(unstable_syntax_pre_expansion)]
3054 ///
3055 /// macro_rules! identity {
3056 /// ( $($tokens:tt)* ) => { $($tokens)* }
3057 /// }
3058 ///
3059 /// #[cfg(feature = "nightly")]
3060 /// identity! {
3061 /// macro foo() {}
3062 /// }
3063 /// ```
3064 ///
3065 /// This is a [future-incompatible] lint to transition this
3066 /// to a hard error in the future. See [issue #154045] for more details.
3067 ///
3068 /// [issue #154045]: https://github.com/rust-lang/rust/issues/154045
3069 /// [future-incompatible]: ../index.md#future-incompatible-lints
3070pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3071 Warn,
3072"unstable syntax can change at any point in the future, causing a hard error!",
3073 @future_incompatible = FutureIncompatibleInfo {
3074 reason: fcw!(FutureReleaseError #154045),
3075 };
3076}30773078#[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! {
3079/// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
3080 /// collide. Downstream users trying to use the same name re-exported from multiple globs
3081 /// will receive a warning pointing out redefinition of the same name.
3082 ///
3083 /// ### Example
3084 ///
3085 /// ```rust,compile_fail
3086 /// #![deny(ambiguous_glob_reexports)]
3087 /// pub mod foo {
3088 /// pub type X = u8;
3089 /// }
3090 ///
3091 /// pub mod bar {
3092 /// pub type Y = u8;
3093 /// pub type X = u8;
3094 /// }
3095 ///
3096 /// pub use foo::*;
3097 /// pub use bar::*;
3098 ///
3099 ///
3100 /// pub fn main() {}
3101 /// ```
3102 ///
3103 /// {{produces}}
3104 ///
3105 /// ### Explanation
3106 ///
3107 /// This was previously accepted but it could silently break a crate's downstream users code.
3108 /// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
3109 /// re-exports, down stream users could use `this_crate::X` without problems. However, adding
3110 /// `bar::X` would cause compilation errors in downstream crates because `X` is defined
3111 /// multiple times in the same namespace of `this_crate`.
3112pub AMBIGUOUS_GLOB_REEXPORTS,
3113 Warn,
3114"ambiguous glob re-exports",
3115}31163117#[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! {
3118/// The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by
3119 /// private items.
3120 ///
3121 /// ### Example
3122 ///
3123 /// ```rust,compile_fail
3124 /// #![deny(hidden_glob_reexports)]
3125 ///
3126 /// pub mod upstream {
3127 /// mod inner { pub struct Foo {}; pub struct Bar {}; }
3128 /// pub use self::inner::*;
3129 /// struct Foo {} // private item shadows `inner::Foo`
3130 /// }
3131 ///
3132 /// // mod downstream {
3133 /// // fn test() {
3134 /// // let _ = crate::upstream::Foo; // inaccessible
3135 /// // }
3136 /// // }
3137 ///
3138 /// pub fn main() {}
3139 /// ```
3140 ///
3141 /// {{produces}}
3142 ///
3143 /// ### Explanation
3144 ///
3145 /// This was previously accepted without any errors or warnings but it could silently break a
3146 /// crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would
3147 /// silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at
3148 /// the downstream use site.
3149pub HIDDEN_GLOB_REEXPORTS,
3150 Warn,
3151"name introduced by a private item shadows a name introduced by a public glob re-export",
3152}31533154#[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! {
3155/// The `long_running_const_eval` lint is emitted when const
3156 /// eval is running for a long time to ensure rustc terminates
3157 /// even if you accidentally wrote an infinite loop.
3158 ///
3159 /// ### Example
3160 ///
3161 /// ```rust,compile_fail
3162 /// const FOO: () = loop {};
3163 /// ```
3164 ///
3165 /// {{produces}}
3166 ///
3167 /// ### Explanation
3168 ///
3169 /// Loops allow const evaluation to compute arbitrary code, but may also
3170 /// cause infinite loops or just very long running computations.
3171 /// Users can enable long running computations by allowing the lint
3172 /// on individual constants or for entire crates.
3173 ///
3174 /// ### Unconditional warnings
3175 ///
3176 /// Note that regardless of whether the lint is allowed or set to warn,
3177 /// the compiler will issue warnings if constant evaluation runs significantly
3178 /// longer than this lint's limit. These warnings are also shown to downstream
3179 /// users from crates.io or similar registries. If you are above the lint's limit,
3180 /// both you and downstream users might be exposed to these warnings.
3181 /// They might also appear on compiler updates, as the compiler makes minor changes
3182 /// about how complexity is measured: staying below the limit ensures that there
3183 /// is enough room, and given that the lint is disabled for people who use your
3184 /// dependency it means you will be the only one to get the warning and can put
3185 /// out an update in your own time.
3186pub LONG_RUNNING_CONST_EVAL,
3187 Deny,
3188"detects long const eval operations",
3189 report_in_external_macro
3190}31913192#[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! {
3193/// The `unused_associated_type_bounds` lint is emitted when an
3194 /// associated type bound is added to a trait object, but the associated
3195 /// type has a `where Self: Sized` bound, and is thus unavailable on the
3196 /// trait object anyway.
3197 ///
3198 /// ### Example
3199 ///
3200 /// ```rust
3201 /// trait Foo {
3202 /// type Bar where Self: Sized;
3203 /// }
3204 /// type Mop = dyn Foo<Bar = ()>;
3205 /// ```
3206 ///
3207 /// {{produces}}
3208 ///
3209 /// ### Explanation
3210 ///
3211 /// Just like methods with `Self: Sized` bounds are unavailable on trait
3212 /// objects, associated types can be removed from the trait object.
3213pub UNUSED_ASSOCIATED_TYPE_BOUNDS,
3214 Warn,
3215"detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`"
3216}32173218#[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! {
3219/// The `unused_doc_comments` lint detects doc comments that aren't used
3220 /// by `rustdoc`.
3221 ///
3222 /// ### Example
3223 ///
3224 /// ```rust
3225 /// /// docs for x
3226 /// let x = 12;
3227 /// ```
3228 ///
3229 /// {{produces}}
3230 ///
3231 /// ### Explanation
3232 ///
3233 /// `rustdoc` does not use doc comments in all positions, and so the doc
3234 /// comment will be ignored. Try changing it to a normal comment with `//`
3235 /// to avoid the warning.
3236pub UNUSED_DOC_COMMENTS,
3237 Warn,
3238"detects doc comments that aren't used by rustdoc"
3239}32403241#[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! {
3242/// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3243 /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3244 /// Rust 2018 and 2021.
3245 ///
3246 /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3247 /// and the field is captured by a closure and used with the assumption that said field implements
3248 /// the same trait as the root variable.
3249 ///
3250 /// ### Example of drop reorder
3251 ///
3252 /// ```rust,edition2018,compile_fail
3253 /// #![deny(rust_2021_incompatible_closure_captures)]
3254 /// # #![allow(unused)]
3255 ///
3256 /// struct FancyInteger(i32);
3257 ///
3258 /// impl Drop for FancyInteger {
3259 /// fn drop(&mut self) {
3260 /// println!("Just dropped {}", self.0);
3261 /// }
3262 /// }
3263 ///
3264 /// struct Point { x: FancyInteger, y: FancyInteger }
3265 ///
3266 /// fn main() {
3267 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3268 ///
3269 /// let c = || {
3270 /// let x = p.x;
3271 /// };
3272 ///
3273 /// c();
3274 ///
3275 /// // ... More code ...
3276 /// }
3277 /// ```
3278 ///
3279 /// {{produces}}
3280 ///
3281 /// ### Explanation
3282 ///
3283 /// In the above example, `p.y` will be dropped at the end of `f` instead of
3284 /// with `c` in Rust 2021.
3285 ///
3286 /// ### Example of auto-trait
3287 ///
3288 /// ```rust,edition2018,compile_fail
3289 /// #![deny(rust_2021_incompatible_closure_captures)]
3290 /// use std::thread;
3291 ///
3292 /// struct Pointer(*mut i32);
3293 /// unsafe impl Send for Pointer {}
3294 ///
3295 /// fn main() {
3296 /// let mut f = 10;
3297 /// let fptr = Pointer(&mut f as *mut i32);
3298 /// thread::spawn(move || unsafe {
3299 /// *fptr.0 = 20;
3300 /// });
3301 /// }
3302 /// ```
3303 ///
3304 /// {{produces}}
3305 ///
3306 /// ### Explanation
3307 ///
3308 /// In the above example, only `fptr.0` is captured in Rust 2021.
3309 /// The field is of type `*mut i32`, which doesn't implement `Send`,
3310 /// making the code invalid as the field cannot be sent between threads safely.
3311pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3312 Allow,
3313"detects closures affected by Rust 2021 changes",
3314 @future_incompatible = FutureIncompatibleInfo {
3315 reason: fcw!(EditionSemanticsChange 2021 "disjoint-capture-in-closures"),
3316 explain_reason: false,
3317 };
3318}33193320pub 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 {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[UNUSED_DOC_COMMENTS]))
}
}
impl UnusedDocComment {
#[allow(unused)]
pub fn lint_vec() -> crate::LintVec {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[UNUSED_DOC_COMMENTS]))
}
}declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
33213322#[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! {
3323/// The `missing_abi` lint detects cases where the ABI is omitted from
3324 /// `extern` declarations.
3325 ///
3326 /// ### Example
3327 ///
3328 /// ```rust,compile_fail
3329 /// #![deny(missing_abi)]
3330 ///
3331 /// extern fn foo() {}
3332 /// ```
3333 ///
3334 /// {{produces}}
3335 ///
3336 /// ### Explanation
3337 ///
3338 /// For historic reasons, Rust implicitly selects `C` as the default ABI for
3339 /// `extern` declarations. [Other ABIs] like `C-unwind` and `system` have
3340 /// been added since then, and especially with their addition seeing the ABI
3341 /// easily makes code review easier.
3342 ///
3343 /// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
3344pub MISSING_ABI,
3345 Warn,
3346"No declared ABI for extern declaration"
3347}33483349#[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::Warn,
desc: "detects invalid `#[doc(...)]` attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3350/// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3351 /// misused.
3352 ///
3353 /// ### Example
3354 ///
3355 /// ```rust,compile_fail
3356 /// #![deny(warnings)]
3357 ///
3358 /// pub mod submodule {
3359 /// #![doc(test(no_crate_inject))]
3360 /// }
3361 /// ```
3362 ///
3363 /// {{produces}}
3364 ///
3365 /// ### Explanation
3366 ///
3367 /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
3368 /// being validated. Usually these should be rejected as a hard error,
3369 /// but this lint was introduced to avoid breaking any existing
3370 /// crates which included them.
3371pub INVALID_DOC_ATTRIBUTES,
3372 Warn,
3373"detects invalid `#[doc(...)]` attributes",
3374}33753376#[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! {
3377/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3378 ///
3379 /// ### Example
3380 ///
3381 /// ```rust,edition2018,compile_fail
3382 /// #![deny(rust_2021_incompatible_or_patterns)]
3383 ///
3384 /// macro_rules! match_any {
3385 /// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3386 /// match $expr {
3387 /// $(
3388 /// $( $pat => $expr_arm, )+
3389 /// )+
3390 /// }
3391 /// };
3392 /// }
3393 ///
3394 /// fn main() {
3395 /// let result: Result<i64, i32> = Err(42);
3396 /// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3397 /// assert_eq!(int, 42);
3398 /// }
3399 /// ```
3400 ///
3401 /// {{produces}}
3402 ///
3403 /// ### Explanation
3404 ///
3405 /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3406pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3407 Allow,
3408"detects usage of old versions of or-patterns",
3409 @future_incompatible = FutureIncompatibleInfo {
3410 reason: fcw!(EditionError 2021 "or-patterns-macro-rules"),
3411 };
3412}34133414#[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! {
3415/// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3416 /// with traits added to the prelude in future editions.
3417 ///
3418 /// ### Example
3419 ///
3420 /// ```rust,edition2018,compile_fail
3421 /// #![deny(rust_2021_prelude_collisions)]
3422 ///
3423 /// trait Foo {
3424 /// fn try_into(self) -> Result<String, !>;
3425 /// }
3426 ///
3427 /// impl Foo for &str {
3428 /// fn try_into(self) -> Result<String, !> {
3429 /// Ok(String::from(self))
3430 /// }
3431 /// }
3432 ///
3433 /// fn main() {
3434 /// let x: String = "3".try_into().unwrap();
3435 /// // ^^^^^^^^
3436 /// // This call to try_into matches both Foo::try_into and TryInto::try_into as
3437 /// // `TryInto` has been added to the Rust prelude in 2021 edition.
3438 /// println!("{x}");
3439 /// }
3440 /// ```
3441 ///
3442 /// {{produces}}
3443 ///
3444 /// ### Explanation
3445 ///
3446 /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3447 /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3448 /// results in an ambiguity as to which method/function to call when an existing `try_into`
3449 /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3450 /// is called directly on a type.
3451 ///
3452 /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3453pub RUST_2021_PRELUDE_COLLISIONS,
3454 Allow,
3455"detects the usage of trait methods which are ambiguous with traits added to the \
3456 prelude in future editions",
3457 @future_incompatible = FutureIncompatibleInfo {
3458 reason: fcw!(EditionError 2021 "prelude"),
3459 };
3460}34613462#[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! {
3463/// The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3464 /// with traits added to the prelude in future editions.
3465 ///
3466 /// ### Example
3467 ///
3468 /// ```rust,edition2021,compile_fail
3469 /// #![deny(rust_2024_prelude_collisions)]
3470 /// trait Meow {
3471 /// fn poll(&self) {}
3472 /// }
3473 /// impl<T> Meow for T {}
3474 ///
3475 /// fn main() {
3476 /// core::pin::pin!(async {}).poll();
3477 /// // ^^^^^^
3478 /// // This call to try_into matches both Future::poll and Meow::poll as
3479 /// // `Future` has been added to the Rust prelude in 2024 edition.
3480 /// }
3481 /// ```
3482 ///
3483 /// {{produces}}
3484 ///
3485 /// ### Explanation
3486 ///
3487 /// Rust 2024, introduces two new additions to the standard library's prelude:
3488 /// `Future` and `IntoFuture`. This results in an ambiguity as to which method/function
3489 /// to call when an existing `poll`/`into_future` method is called via dot-call syntax or
3490 /// a `poll`/`into_future` associated function is called directly on a type.
3491 ///
3492pub RUST_2024_PRELUDE_COLLISIONS,
3493 Allow,
3494"detects the usage of trait methods which are ambiguous with traits added to the \
3495 prelude in future editions",
3496 @future_incompatible = FutureIncompatibleInfo {
3497 reason: fcw!(EditionError 2024 "prelude"),
3498 };
3499}35003501#[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! {
3502/// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3503 /// prefix instead in Rust 2021.
3504 ///
3505 /// ### Example
3506 ///
3507 /// ```rust,edition2018,compile_fail
3508 /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3509 ///
3510 /// macro_rules! m {
3511 /// (z $x:expr) => ();
3512 /// }
3513 ///
3514 /// m!(z"hey");
3515 /// ```
3516 ///
3517 /// {{produces}}
3518 ///
3519 /// ### Explanation
3520 ///
3521 /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3522 /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3523 /// considered a prefix for `"hey"`.
3524 ///
3525 /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3526 /// to keep them separated in Rust 2021.
3527// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3528#[allow(rustdoc::invalid_rust_codeblocks)]
3529pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3530 Allow,
3531"identifiers that will be parsed as a prefix in Rust 2021",
3532 @future_incompatible = FutureIncompatibleInfo {
3533 reason: fcw!(EditionError 2021 "reserving-syntax"),
3534 };
3535 crate_level_only
3536}35373538#[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! {
3539/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3540 /// `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind
3541 /// variants) on targets that cannot meaningfully be supported for the requested target.
3542 ///
3543 /// For example, `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3544 /// code, because this calling convention was never specified for those targets.
3545 ///
3546 /// Historically, MSVC toolchains have fallen back to the regular C calling convention for
3547 /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3548 /// hack across many more targets.
3549 ///
3550 /// ### Example
3551 ///
3552 /// ```rust,ignore (needs specific targets)
3553 /// extern "stdcall" fn stdcall() {}
3554 /// ```
3555 ///
3556 /// This will produce:
3557 ///
3558 /// ```text
3559 /// warning: use of calling convention not supported on this target
3560 /// --> $DIR/unsupported.rs:39:1
3561 /// |
3562 /// LL | extern "stdcall" fn stdcall() {}
3563 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3564 /// |
3565 /// = note: `#[warn(unsupported_calling_conventions)]` on by default
3566 /// = warning: this was previously accepted by the compiler but is being phased out;
3567 /// it will become a hard error in a future release!
3568 /// = note: for more information, see issue ...
3569 /// ```
3570 ///
3571 /// ### Explanation
3572 ///
3573 /// On most of the targets, the behaviour of `stdcall` and similar calling conventions is not
3574 /// defined at all, but was previously accepted due to a bug in the implementation of the
3575 /// compiler.
3576pub UNSUPPORTED_CALLING_CONVENTIONS,
3577 Warn,
3578"use of unsupported calling convention",
3579 @future_incompatible = FutureIncompatibleInfo {
3580 reason: fcw!(FutureReleaseError #137018),
3581 report_in_deps: false,
3582 };
3583}35843585#[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! {
3586/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
3587 /// a target dependent calling convention on a target that does not support this calling
3588 /// convention on a function pointer.
3589 ///
3590 /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3591 /// code, because this calling convention was never specified for those targets.
3592 ///
3593 /// ### Example
3594 ///
3595 /// ```rust,ignore (needs specific targets)
3596 /// fn stdcall_ptr(f: extern "stdcall" fn ()) {
3597 /// f()
3598 /// }
3599 /// ```
3600 ///
3601 /// This will produce:
3602 ///
3603 /// ```text
3604 /// warning: the calling convention `"stdcall"` is not supported on this target
3605 /// --> $DIR/unsupported.rs:34:15
3606 /// |
3607 /// LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
3608 /// | ^^^^^^^^^^^^^^^^^^^^^^^^
3609 /// |
3610 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3611 /// = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
3612 /// = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
3613 /// ```
3614 ///
3615 /// ### Explanation
3616 ///
3617 /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3618 /// defined at all, but was previously accepted due to a bug in the implementation of the
3619 /// compiler.
3620pub UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
3621 Warn,
3622"use of unsupported calling convention for function pointer",
3623 @future_incompatible = FutureIncompatibleInfo {
3624 reason: fcw!(FutureReleaseError #130260),
3625 report_in_deps: true,
3626 };
3627}36283629#[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! {
3630/// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3631 /// an unlabeled loop as their value expression.
3632 ///
3633 /// ### Example
3634 ///
3635 /// ```rust
3636 /// 'label: loop {
3637 /// break 'label loop { break 42; };
3638 /// };
3639 /// ```
3640 ///
3641 /// {{produces}}
3642 ///
3643 /// ### Explanation
3644 ///
3645 /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3646 /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3647 /// can also carry a value expression, which can be another loop. A labeled `break` with an
3648 /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3649 /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3650 /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3651 /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3652 /// in parentheses.
3653pub BREAK_WITH_LABEL_AND_LOOP,
3654 Warn,
3655"`break` expression with label and unlabeled loop as value expression"
3656}36573658#[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! {
3659/// The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`
3660 /// struct or enum who want to match all of its fields/variants explicitly.
3661 ///
3662 /// The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness
3663 /// checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy
3664 /// this, this allow-by-default lint warns the user when a match mentions some but not all of
3665 /// the fields/variants of a `#[non_exhaustive]` struct or enum.
3666 ///
3667 /// ### Example
3668 ///
3669 /// ```rust,ignore (needs separate crate)
3670 /// // crate A
3671 /// #[non_exhaustive]
3672 /// pub enum Bar {
3673 /// A,
3674 /// B, // added variant in non breaking change
3675 /// }
3676 ///
3677 /// // in crate B
3678 /// #![feature(non_exhaustive_omitted_patterns_lint)]
3679 /// #[warn(non_exhaustive_omitted_patterns)]
3680 /// match Bar::A {
3681 /// Bar::A => {},
3682 /// _ => {},
3683 /// }
3684 /// ```
3685 ///
3686 /// This will produce:
3687 ///
3688 /// ```text
3689 /// warning: some variants are not matched explicitly
3690 /// --> $DIR/reachable-patterns.rs:70:9
3691 /// |
3692 /// LL | match Bar::A {
3693 /// | ^ pattern `Bar::B` not covered
3694 /// |
3695 /// note: the lint level is defined here
3696 /// --> $DIR/reachable-patterns.rs:69:16
3697 /// |
3698 /// LL | #[warn(non_exhaustive_omitted_patterns)]
3699 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3700 /// = help: ensure that all variants are matched explicitly by adding the suggested match arms
3701 /// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3702 /// ```
3703 ///
3704 /// Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or
3705 /// variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against
3706 /// expected semver behavior.
3707 ///
3708 /// ### Explanation
3709 ///
3710 /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially
3711 /// redundant) wildcard when pattern-matching, to allow for future addition of fields or
3712 /// variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to
3713 /// actually catch some fields/variants. In other words, when the match without the wildcard
3714 /// would not be exhaustive. This lets the user be informed if new fields/variants were added.
3715pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3716 Allow,
3717"detect when patterns of types marked `non_exhaustive` are missed",
3718 @feature_gate = non_exhaustive_omitted_patterns_lint;
3719}37203721#[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! {
3722/// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3723 /// change the visual representation of text on screen in a way that does not correspond to
3724 /// their on memory representation.
3725 ///
3726 /// ### Example
3727 ///
3728 /// ```rust,compile_fail
3729 /// #![deny(text_direction_codepoint_in_comment)]
3730 /// fn main() {
3731#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
3732/// }
3733 /// ```
3734 ///
3735 /// {{produces}}
3736 ///
3737 /// ### Explanation
3738 ///
3739 /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3740 /// are written right-to-left, but a specially crafted comment can make code that will be
3741 /// compiled appear to be part of a comment, depending on the software used to read the code.
3742 /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3743 /// their use.
3744pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3745 Deny,
3746"invisible directionality-changing codepoints in comment",
3747 crate_level_only
3748}37493750#[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! {
3751/// The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the
3752 /// visual representation of text on screen in a way that does not correspond to their on
3753 /// memory representation.
3754 ///
3755 /// ### Explanation
3756 ///
3757 /// The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,
3758 /// `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change
3759 /// its direction on software that supports these codepoints. This makes the text "abc" display
3760 /// as "cba" on screen. By leveraging software that supports these, people can write specially
3761 /// crafted literals that make the surrounding code seem like it's performing one action, when
3762 /// in reality it is performing another. Because of this, we proactively lint against their
3763 /// presence to avoid surprises.
3764 ///
3765 /// ### Example
3766 ///
3767 /// ```rust,compile_fail
3768 /// #![deny(text_direction_codepoint_in_literal)]
3769 /// fn main() {
3770// ` - convince tidy that backticks match
3771#[doc = " println!(\"{:?}\", '\u{202E}');"]
3772// `
3773/// }
3774 /// ```
3775 ///
3776 /// {{produces}}
3777 ///
3778pub TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
3779 Deny,
3780"detect special Unicode codepoints that affect the visual representation of text on screen, \
3781 changing the direction in which text flows",
3782 crate_level_only
3783}37843785#[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! {
3786/// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3787 /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3788 /// and `test_case`.
3789 ///
3790 /// ### Example
3791 ///
3792 /// ```rust,ignore (needs --test)
3793 /// #[test]
3794 /// #[test]
3795 /// fn foo() {}
3796 /// ```
3797 ///
3798 /// This will produce:
3799 ///
3800 /// ```text
3801 /// warning: duplicated attribute
3802 /// --> src/lib.rs:2:1
3803 /// |
3804 /// 2 | #[test]
3805 /// | ^^^^^^^
3806 /// |
3807 /// = note: `#[warn(duplicate_macro_attributes)]` on by default
3808 /// ```
3809 ///
3810 /// ### Explanation
3811 ///
3812 /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3813 /// being duplicated may not be obvious or desirable.
3814 ///
3815 /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3816 /// change to its environment.
3817 ///
3818 /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3819pub DUPLICATE_MACRO_ATTRIBUTES,
3820 Warn,
3821"duplicated attribute"
3822}38233824#[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! {
3825/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3826 /// in an associated type.
3827 ///
3828 /// ### Example
3829 ///
3830 /// ```rust
3831 /// trait Trait {
3832 /// type Assoc<'a> where Self: 'a;
3833 /// }
3834 ///
3835 /// impl Trait for () {
3836 /// type Assoc<'a> where Self: 'a = ();
3837 /// }
3838 /// ```
3839 ///
3840 /// {{produces}}
3841 ///
3842 /// ### Explanation
3843 ///
3844 /// The preferred location for where clauses on associated types
3845 /// is after the type. However, for most of generic associated types development,
3846 /// it was only accepted before the equals. To provide a transition period and
3847 /// further evaluate this change, both are currently accepted. At some point in
3848 /// the future, this may be disallowed at an edition boundary; but, that is
3849 /// undecided currently.
3850pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3851 Warn,
3852"deprecated where clause location"
3853}38543855#[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! {
3856/// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3857 ///
3858 /// ### Example
3859 ///
3860 /// ```rust
3861 /// // This lint is intentionally used to test the compiler's behavior
3862 /// // when an unstable lint is enabled without the corresponding feature gate.
3863 /// #![allow(test_unstable_lint)]
3864 /// ```
3865 ///
3866 /// {{produces}}
3867 ///
3868 /// ### Explanation
3869 ///
3870 /// In order to test the behavior of unstable lints, a permanently-unstable
3871 /// lint is required. This lint can be used to trigger warnings and errors
3872 /// from the compiler related to unstable lints.
3873pub TEST_UNSTABLE_LINT,
3874 Deny,
3875"this unstable lint is only for testing",
3876 @feature_gate = test_unstable_lint;
3877}38783879#[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! {
3880/// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3881 /// `C-unwind` or other FFI-unwind ABIs.
3882 ///
3883 /// ### Example
3884 ///
3885 /// ```rust
3886 /// #![warn(ffi_unwind_calls)]
3887 ///
3888 /// unsafe extern "C-unwind" {
3889 /// fn foo();
3890 /// }
3891 ///
3892 /// fn bar() {
3893 /// unsafe { foo(); }
3894 /// let ptr: unsafe extern "C-unwind" fn() = foo;
3895 /// unsafe { ptr(); }
3896 /// }
3897 /// ```
3898 ///
3899 /// {{produces}}
3900 ///
3901 /// ### Explanation
3902 ///
3903 /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3904 /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3905 /// that desire this ability it is therefore necessary to avoid such calls.
3906pub FFI_UNWIND_CALLS,
3907 Allow,
3908"call to foreign functions or function pointers with FFI-unwind ABI"
3909}39103911#[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::Warn,
desc: "warnings emitted at runtime by the target-specific linker program",
is_externally_loaded: false,
ignore_deny_warnings: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3912/// The `linker_messages` lint forwards warnings from the linker.
3913 ///
3914 /// ### Example
3915 ///
3916 /// ```rust,ignore (needs CLI args, platform-specific)
3917 /// #[warn(linker_messages)]
3918 /// extern "C" {
3919 /// fn foo();
3920 /// }
3921 /// fn main () { unsafe { foo(); } }
3922 /// ```
3923 ///
3924 /// On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce
3925 ///
3926 /// ```text
3927 /// warning: linker stderr: rust-lld: undefined symbol: foo
3928 /// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
3929 /// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
3930 /// |
3931 /// note: the lint level is defined here
3932 /// --> warn.rs:1:9
3933 /// |
3934 /// 1 | #![warn(linker_messages)]
3935 /// | ^^^^^^^^^^^^^^^
3936 /// warning: 1 warning emitted
3937 /// ```
3938 ///
3939 /// ### Explanation
3940 ///
3941 /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
3942 /// advance by the Rust compiler. Such messages are ignored by default for now. While linker
3943 /// warnings could be very useful they have been ignored for many years by essentially all
3944 /// users, so we need to do a bit more work than just surfacing their text to produce a clear
3945 /// and actionable warning of similar quality to our other diagnostics. See this tracking
3946 /// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
3947pub LINKER_MESSAGES,
3948 Warn,
3949"warnings emitted at runtime by the target-specific linker program",
3950// Linker messages don't live up to the high standard people expect of rustc's errors.
3951 // Prevent `-D warnings` from applying to it.
3952 // It's still possible to pass `-D linker-messages` specifically.
3953ignore_deny_warnings
3954}39553956#[doc =
r" The `linker_info` lint forwards warnings from the linker that are known to be informational-only."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs CLI args, platform-specific)"]
#[doc = r" #[warn(linker_info)]"]
#[doc = r" fn main () {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" On MacOS, using `-C link-arg=-lc` and the default linker, this will produce"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: linker stderr: ld: ignoring duplicate libraries: '-lc'"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> ex.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![warn(linker_info)]"]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Many linkers are very "chatty" and print lots of information that is not necessarily"#]
#[doc =
r" indicative of an issue. This output has been ignored for many years and is often not"]
#[doc =
r" actionable by developers. It is silenced unless the developer specifically requests for it"]
#[doc = r" to be printed. See this tracking issue for more details:"]
#[doc = r" <https://github.com/rust-lang/rust/issues/136096>."]
pub static LINKER_INFO: &crate::Lint =
&crate::Lint {
name: "LINKER_INFO",
default_level: crate::Allow,
desc: "linker warnings known to be informational-only and not indicative of a problem",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3957/// The `linker_info` lint forwards warnings from the linker that are known to be informational-only.
3958 ///
3959 /// ### Example
3960 ///
3961 /// ```rust,ignore (needs CLI args, platform-specific)
3962 /// #[warn(linker_info)]
3963 /// fn main () {}
3964 /// ```
3965 ///
3966 /// On MacOS, using `-C link-arg=-lc` and the default linker, this will produce
3967 ///
3968 /// ```text
3969 /// warning: linker stderr: ld: ignoring duplicate libraries: '-lc'
3970 /// |
3971 /// note: the lint level is defined here
3972 /// --> ex.rs:1:9
3973 /// |
3974 /// 1 | #![warn(linker_info)]
3975 /// | ^^^^^^^^^^^^^^^
3976 /// ```
3977 ///
3978 /// ### Explanation
3979 ///
3980 /// Many linkers are very "chatty" and print lots of information that is not necessarily
3981 /// indicative of an issue. This output has been ignored for many years and is often not
3982 /// actionable by developers. It is silenced unless the developer specifically requests for it
3983 /// to be printed. See this tracking issue for more details:
3984 /// <https://github.com/rust-lang/rust/issues/136096>.
3985pub LINKER_INFO,
3986 Allow,
3987"linker warnings known to be informational-only and not indicative of a problem"
3988}39893990#[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! {
3991/// The `named_arguments_used_positionally` lint detects cases where named arguments are only
3992 /// used positionally in format strings. This usage is valid but potentially very confusing.
3993 ///
3994 /// ### Example
3995 ///
3996 /// ```rust,compile_fail
3997 /// #![deny(named_arguments_used_positionally)]
3998 /// fn main() {
3999 /// let _x = 5;
4000 /// println!("{}", _x = 1); // Prints 1, will trigger lint
4001 ///
4002 /// println!("{}", _x); // Prints 5, no lint emitted
4003 /// println!("{_x}", _x = _x); // Prints 5, no lint emitted
4004 /// }
4005 /// ```
4006 ///
4007 /// {{produces}}
4008 ///
4009 /// ### Explanation
4010 ///
4011 /// Rust formatting strings can refer to named arguments by their position, but this usage is
4012 /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4013 /// of named arguments is an assignment (which would produce the unit type).
4014 /// For backwards compatibility, this is not a hard error.
4015pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4016 Warn,
4017"named arguments in format used positionally"
4018}40194020#[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! {
4021/// The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback
4022 /// affects unsafe function calls.
4023 ///
4024 /// ### Never type fallback
4025 ///
4026 /// When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),
4027 /// to allow type check to infer any type:
4028 ///
4029 /// ```ignore (illustrative-and-has-placeholders)
4030 /// // this
4031 /// let x: u8 = panic!();
4032 ///
4033 /// // is (essentially) turned by the compiler into
4034 /// let x: u8 = absurd(panic!());
4035 ///
4036 /// // where absurd is a function with the following signature
4037 /// // (it's sound, because `!` always marks unreachable code):
4038 /// fn absurd<T>(never: !) -> T { ... }
4039 /// ```
4040 ///
4041 /// While it's convenient to be able to use non-diverging code in one of the branches (like
4042 /// `if a { b } else { return }`) this could lead to compilation errors:
4043 ///
4044 /// ```compile_fail
4045 /// // this
4046 /// { panic!() };
4047 ///
4048 /// // gets turned into this
4049 /// { absurd(panic!()) }; // error: can't infer the type of `absurd`
4050 /// ```
4051 ///
4052 /// To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it
4053 /// can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`.
4054 /// This is what is known as "never type fallback".
4055 ///
4056 /// ### Example
4057 ///
4058 /// ```rust,compile_fail
4059 /// fn main() {
4060 /// if true {
4061 /// // return has type `!` which, is some cases, causes never type fallback
4062 /// return
4063 /// } else {
4064 /// // `zeroed` is an unsafe function, which returns an unbounded type
4065 /// unsafe { std::mem::zeroed() }
4066 /// };
4067 /// // depending on the fallback, `zeroed` may create `()` (which is completely sound),
4068 /// // or `!` (which is instant undefined behavior)
4069 /// }
4070 /// ```
4071 ///
4072 /// {{produces}}
4073 ///
4074 /// ### Explanation
4075 ///
4076 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4077 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4078 /// unsound. Instead of depending on the fallback, you should specify the type explicitly:
4079 /// ```
4080 /// if true {
4081 /// return
4082 /// } else {
4083 /// // type is explicitly specified, fallback can't hurt us no more
4084 /// unsafe { std::mem::zeroed::<()>() }
4085 /// };
4086 /// ```
4087 ///
4088 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4089 ///
4090 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4091 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4092pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
4093 Deny,
4094"never type fallback affecting unsafe function calls",
4095 @future_incompatible = FutureIncompatibleInfo {
4096 reason: fcw!(EditionAndFutureReleaseSemanticsChange 2024 "never-type-fallback"),
4097 report_in_deps: true,
4098 };
4099 @edition Edition2024 => Deny;
4100 report_in_external_macro
4101}41024103#[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! {
4104/// The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with
4105 /// [never type fallback] being [`()`], but will stop compiling with fallback being [`!`].
4106 ///
4107 /// [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback
4108 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4109 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4110 ///
4111 /// ### Example
4112 ///
4113 /// ```rust,compile_fail,edition2021
4114 /// # #![deny(dependency_on_unit_never_type_fallback)]
4115 /// fn main() {
4116 /// if true {
4117 /// // return has type `!` which, is some cases, causes never type fallback
4118 /// return
4119 /// } else {
4120 /// // the type produced by this call is not specified explicitly,
4121 /// // so it will be inferred from the previous branch
4122 /// Default::default()
4123 /// };
4124 /// // depending on the fallback, this may compile (because `()` implements `Default`),
4125 /// // or it may not (because `!` does not implement `Default`)
4126 /// }
4127 /// ```
4128 ///
4129 /// {{produces}}
4130 ///
4131 /// ### Explanation
4132 ///
4133 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4134 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4135 /// not compile. Instead of depending on the fallback, you should specify the type explicitly:
4136 /// ```
4137 /// if true {
4138 /// return
4139 /// } else {
4140 /// // type is explicitly specified, fallback can't hurt us no more
4141 /// <() as Default>::default()
4142 /// };
4143 /// ```
4144 ///
4145 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4146pub DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
4147 Deny,
4148"never type fallback affecting unsafe function calls",
4149 @future_incompatible = FutureIncompatibleInfo {
4150 reason: fcw!(EditionAndFutureReleaseError 2024 "never-type-fallback"),
4151 report_in_deps: true,
4152 };
4153 report_in_external_macro
4154}41554156#[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! {
4157/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
4158 ///
4159 /// ### Example
4160 ///
4161 /// ```rust,compile_fail
4162 /// #![deny(invalid_macro_export_arguments)]
4163 ///
4164 /// #[macro_export(invalid_parameter)]
4165 /// macro_rules! myMacro {
4166 /// () => {
4167 /// // [...]
4168 /// }
4169 /// }
4170 ///
4171 /// #[macro_export(too, many, items)]
4172 /// ```
4173 ///
4174 /// {{produces}}
4175 ///
4176 /// ### Explanation
4177 ///
4178 /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
4179 /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
4180 ///
4181pub INVALID_MACRO_EXPORT_ARGUMENTS,
4182 Deny,
4183"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
4184 @future_incompatible = FutureIncompatibleInfo {
4185 reason: fcw!(FutureReleaseError #57571),
4186 report_in_deps: true,
4187 };
4188}41894190#[doc =
r" The `ambiguous_derive_helpers` lint detects cases where a derive macro's helper attribute"]
#[doc = r" is the same name as that of a built-in attribute."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (proc-macro)"]
#[doc = r#" #![crate_type = "proc-macro"]"#]
#[doc = r" #![deny(ambiguous_derive_helpers)]"]
#[doc = r""]
#[doc = r" use proc_macro::TokenStream;"]
#[doc = r""]
#[doc = r" #[proc_macro_derive(Trait, attributes(ignore))]"]
#[doc = r" pub fn example(input: TokenStream) -> TokenStream {"]
#[doc = r" TokenStream::new()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" Produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: there exists a built-in attribute with the same name"]
#[doc = r" --> file.rs:5:39"]
#[doc = r" |"]
#[doc = r" 5 | #[proc_macro_derive(Trait, attributes(ignore))]"]
#[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 #151152 <https://github.com/rust-lang/rust/issues/151152>"]
#[doc =
r" = note: `#[deny(ambiguous_derive_helpers)]` (part of `#[deny(future_incompatible)]`) on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Attempting to use this helper attribute will throw an error:"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" #[derive(Trait)]"]
#[doc = r" struct Example {"]
#[doc = r" #[ignore]"]
#[doc = r" fields: ()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" Produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error[E0659]: `ignore` is ambiguous"]
#[doc = r" --> src/lib.rs:5:7"]
#[doc = r" |"]
#[doc = r" 5 | #[ignore]"]
#[doc = r" | ^^^^^^ ambiguous name"]
#[doc = r" |"]
#[doc =
r" = note: ambiguous because of a name conflict with a builtin attribute"]
#[doc = r" = note: `ignore` could refer to a built-in attribute"]
#[doc =
r" note: `ignore` could also refer to the derive helper attribute defined here"]
#[doc = r" --> src/lib.rs:3:10"]
#[doc = r" |"]
#[doc = r" 3 | #[derive(Trait)]"]
#[doc = r" | ^^^^^"]
#[doc = r" ```"]
pub static AMBIGUOUS_DERIVE_HELPERS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_DERIVE_HELPERS",
default_level: crate::Warn,
desc: "detects derive helper attributes that are ambiguous with built-in attributes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 151276,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4191/// The `ambiguous_derive_helpers` lint detects cases where a derive macro's helper attribute
4192 /// is the same name as that of a built-in attribute.
4193 ///
4194 /// ### Example
4195 ///
4196 /// ```rust,ignore (proc-macro)
4197 /// #![crate_type = "proc-macro"]
4198 /// #![deny(ambiguous_derive_helpers)]
4199 ///
4200 /// use proc_macro::TokenStream;
4201 ///
4202 /// #[proc_macro_derive(Trait, attributes(ignore))]
4203 /// pub fn example(input: TokenStream) -> TokenStream {
4204 /// TokenStream::new()
4205 /// }
4206 /// ```
4207 ///
4208 /// Produces:
4209 ///
4210 /// ```text
4211 /// warning: there exists a built-in attribute with the same name
4212 /// --> file.rs:5:39
4213 /// |
4214 /// 5 | #[proc_macro_derive(Trait, attributes(ignore))]
4215 /// | ^^^^^^
4216 /// |
4217 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4218 /// = note: for more information, see issue #151152 <https://github.com/rust-lang/rust/issues/151152>
4219 /// = note: `#[deny(ambiguous_derive_helpers)]` (part of `#[deny(future_incompatible)]`) on by default
4220 /// ```
4221 ///
4222 /// ### Explanation
4223 ///
4224 /// Attempting to use this helper attribute will throw an error:
4225 ///
4226 /// ```rust,ignore (needs-dependency)
4227 /// #[derive(Trait)]
4228 /// struct Example {
4229 /// #[ignore]
4230 /// fields: ()
4231 /// }
4232 /// ```
4233 ///
4234 /// Produces:
4235 ///
4236 /// ```text
4237 /// error[E0659]: `ignore` is ambiguous
4238 /// --> src/lib.rs:5:7
4239 /// |
4240 /// 5 | #[ignore]
4241 /// | ^^^^^^ ambiguous name
4242 /// |
4243 /// = note: ambiguous because of a name conflict with a builtin attribute
4244 /// = note: `ignore` could refer to a built-in attribute
4245 /// note: `ignore` could also refer to the derive helper attribute defined here
4246 /// --> src/lib.rs:3:10
4247 /// |
4248 /// 3 | #[derive(Trait)]
4249 /// | ^^^^^
4250 /// ```
4251pub AMBIGUOUS_DERIVE_HELPERS,
4252 Warn,
4253"detects derive helper attributes that are ambiguous with built-in attributes",
4254 @future_incompatible = FutureIncompatibleInfo {
4255 reason: fcw!(FutureReleaseError #151276),
4256 };
4257}42584259#[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! {
4260/// The `private_interfaces` lint detects types in a primary interface of an item,
4261 /// that are more private than the item itself. Primary interface of an item is all
4262 /// its interface except for bounds on generic parameters and where clauses.
4263 ///
4264 /// ### Example
4265 ///
4266 /// ```rust,compile_fail
4267 /// # #![allow(unused)]
4268 /// #![deny(private_interfaces)]
4269 /// struct SemiPriv;
4270 ///
4271 /// mod m1 {
4272 /// struct Priv;
4273 /// impl crate::SemiPriv {
4274 /// pub fn f(_: Priv) {}
4275 /// }
4276 /// }
4277 ///
4278 /// # fn main() {}
4279 /// ```
4280 ///
4281 /// {{produces}}
4282 ///
4283 /// ### Explanation
4284 ///
4285 /// Having something private in primary interface guarantees that
4286 /// the item will be unusable from outer modules due to type privacy.
4287pub PRIVATE_INTERFACES,
4288 Warn,
4289"private type in primary interface of an item",
4290}42914292#[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! {
4293/// The `private_bounds` lint detects types in a secondary interface of an item,
4294 /// that are more private than the item itself. Secondary interface of an item consists of
4295 /// bounds on generic parameters and where clauses, including supertraits for trait items.
4296 ///
4297 /// ### Example
4298 ///
4299 /// ```rust,compile_fail
4300 /// # #![allow(unused)]
4301 /// #![deny(private_bounds)]
4302 ///
4303 /// struct PrivTy;
4304 /// pub struct S
4305 /// where PrivTy:
4306 /// {}
4307 /// # fn main() {}
4308 /// ```
4309 ///
4310 /// {{produces}}
4311 ///
4312 /// ### Explanation
4313 ///
4314 /// Having private types or traits in item bounds makes it less clear what interface
4315 /// the item actually provides.
4316pub PRIVATE_BOUNDS,
4317 Warn,
4318"private type in secondary interface of an item",
4319}43204321#[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! {
4322/// The `unnameable_types` lint detects types for which you can get objects of that type,
4323 /// but cannot name the type itself.
4324 ///
4325 /// ### Example
4326 ///
4327 /// ```rust,compile_fail
4328 /// # #![allow(unused)]
4329 /// #![deny(unnameable_types)]
4330 /// mod m {
4331 /// pub struct S;
4332 /// }
4333 ///
4334 /// pub fn get_unnameable() -> m::S { m::S }
4335 /// # fn main() {}
4336 /// ```
4337 ///
4338 /// {{produces}}
4339 ///
4340 /// ### Explanation
4341 ///
4342 /// It is often expected that if you can obtain an object of type `T`, then
4343 /// you can name the type `T` as well; this lint attempts to enforce this rule.
4344 /// The recommended action is to either reexport the type properly to make it nameable,
4345 /// or document that users are not supposed to be able to name it for one reason or another.
4346 ///
4347 /// Besides types, this lint applies to traits because traits can also leak through signatures,
4348 /// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
4349pub UNNAMEABLE_TYPES,
4350 Allow,
4351"effective visibility of a type is larger than the area in which it can be named",
4352}43534354#[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! {
4355/// The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes.
4356 ///
4357 /// ### Example
4358 ///
4359 /// ```rust
4360 /// #[diagnostic::do_not_recommend(message = "message")]
4361 /// trait Trait {}
4362 /// ```
4363 ///
4364 /// {{produces}}
4365 ///
4366 /// ### Explanation
4367 ///
4368 /// It is usually a mistake to use options or syntax that is not supported. Check the spelling,
4369 /// and check the diagnostic attribute listing for the correct name and syntax. Also consider if
4370 /// you are using an old version of the compiler; perhaps the option or syntax is only available
4371 /// in a newer version. See the [reference] for a list of diagnostic attributes and the syntax
4372 /// of each.
4373 ///
4374 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4375pub MALFORMED_DIAGNOSTIC_ATTRIBUTES,
4376 Warn,
4377"detects malformed diagnostic attributes",
4378}43794380#[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! {
4381/// The `misplaced_diagnostic_attributes` lint detects wrongly placed diagnostic attributes.
4382 ///
4383 /// ### Example
4384 ///
4385 /// ```rust
4386 /// #[diagnostic::do_not_recommend]
4387 /// struct NotUserFacing;
4388 /// ```
4389 ///
4390 /// {{produces}}
4391 ///
4392 /// ### Explanation
4393 ///
4394 /// It is usually a mistake to specify a diagnostic attribute on an item it is not meant for.
4395 /// For example, `#[diagnostic::do_not_recommend]` can only be placed on trait implementations,
4396 /// and does nothing if placed elsewhere. See the [reference] for a list of diagnostic
4397 /// attributes and their correct positions.
4398 ///
4399 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4400pub MISPLACED_DIAGNOSTIC_ATTRIBUTES,
4401 Warn,
4402"detects diagnostic attributes that are placed on the wrong item",
4403}44044405#[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! {
4406/// The `unknown_diagnostic_attributes` lint detects unknown diagnostic attributes.
4407 ///
4408 /// ### Example
4409 ///
4410 /// ```rust
4411 /// #[diagnostic::does_not_exist]
4412 /// struct Thing;
4413 /// ```
4414 ///
4415 /// {{produces}}
4416 ///
4417 /// ### Explanation
4418 ///
4419 /// It is usually a mistake to specify a diagnostic attribute that does not exist. Check the
4420 /// spelling, and check the diagnostic attribute listing for the correct name. Also consider if
4421 /// you are using an old version of the compiler and the attribute is only available in a newer
4422 /// version. See the [reference] for the list of diagnostic attributes.
4423 ///
4424 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4425pub UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
4426 Warn,
4427"detects unknown diagnostic attributes",
4428}44294430#[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! {
4431/// The `malformed_diagnostic_format_literals` lint detects malformed diagnostic format
4432 /// literals.
4433 ///
4434 /// ### Example
4435 ///
4436 /// ```rust
4437 /// #[diagnostic::on_unimplemented(message = "{Self}} does not implement `Trait`")]
4438 /// trait Trait {}
4439 /// ```
4440 ///
4441 /// {{produces}}
4442 ///
4443 /// ### Explanation
4444 ///
4445 /// The `#[diagnostic::on_unimplemented]` attribute accepts string literal values that are
4446 /// similar to `format!`'s string literal. See the [reference] for details on what is permitted
4447 /// in this string literal.
4448 ///
4449 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4450pub MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
4451 Warn,
4452"detects diagnostic attribute with malformed diagnostic format literals",
4453}44544455#[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,ignore (needs extern crate)"]
#[doc = r" // library crate `my_library`"]
#[doc = r" mod mod1 { pub const C: u32 = 1; }"]
#[doc = r" mod mod2 { pub const C: u32 = 2; }"]
#[doc = r" pub use mod1::*;"]
#[doc = r" pub use mod2::*;"]
#[doc = r""]
#[doc = r" // another crate using `my_library`"]
#[doc = r" let c = my_library::C; // `C` is ambiguous"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust compile it successfully because"]
#[doc =
r" ambiguous glob imports weren't preserved correctly over crate boundaries."]
#[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::Deny,
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! {
4456/// The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity
4457 /// errors, but previously didn't do that due to rustc bugs.
4458 ///
4459 /// ### Example
4460 ///
4461 /// ```rust,ignore (needs extern crate)
4462 /// // library crate `my_library`
4463 /// mod mod1 { pub const C: u32 = 1; }
4464 /// mod mod2 { pub const C: u32 = 2; }
4465 /// pub use mod1::*;
4466 /// pub use mod2::*;
4467 ///
4468 /// // another crate using `my_library`
4469 /// let c = my_library::C; // `C` is ambiguous
4470 /// ```
4471 ///
4472 /// ### Explanation
4473 ///
4474 /// Previous versions of Rust compile it successfully because
4475 /// ambiguous glob imports weren't preserved correctly over crate boundaries.
4476 ///
4477 /// This is a [future-incompatible] lint to transition this to a
4478 /// hard error in the future.
4479 ///
4480 /// [future-incompatible]: ../index.md#future-incompatible-lints
4481pub AMBIGUOUS_GLOB_IMPORTS,
4482 Deny,
4483"detects certain glob imports that require reporting an ambiguity error",
4484 @future_incompatible = FutureIncompatibleInfo {
4485 reason: fcw!(FutureReleaseError #114095),
4486 report_in_deps: true,
4487 };
4488}44894490#[doc =
r" The `ambiguous_glob_imported_traits` lint reports uses of traits that are"]
#[doc =
r" imported ambiguously via glob imports. Previously, this was not enforced"]
#[doc = r" due to a bug in rustc."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_glob_imported_traits)]"]
#[doc = r" mod m1 {"]
#[doc = r" pub trait Trait {"]
#[doc = r" fn method1(&self) {}"]
#[doc = r" }"]
#[doc = r" impl Trait for u8 {}"]
#[doc = r" }"]
#[doc = r" mod m2 {"]
#[doc = r" pub trait Trait {"]
#[doc = r" fn method2(&self) {}"]
#[doc = r" }"]
#[doc = r" impl Trait for u8 {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" use m1::*;"]
#[doc = r" use m2::*;"]
#[doc = r" 0u8.method1();"]
#[doc = r" 0u8.method2();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When multiple traits with the same name are brought into scope through glob imports,"]
#[doc =
r#" one trait becomes the "primary" one while the others are shadowed. Methods from the"#]
#[doc =
r#" shadowed traits (e.g. `method2`) become inaccessible, while methods from the "primary""#]
#[doc =
r" trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope,"]
#[doc =
r" but we have to allow this for now because of backwards compatibility."]
#[doc =
r#" This lint reports uses of these "primary" traits that are ambiguous."#]
#[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_IMPORTED_TRAITS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_IMPORTED_TRAITS",
default_level: crate::Warn,
desc: "detects uses of ambiguously glob imported traits",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 147992,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4491/// The `ambiguous_glob_imported_traits` lint reports uses of traits that are
4492 /// imported ambiguously via glob imports. Previously, this was not enforced
4493 /// due to a bug in rustc.
4494 ///
4495 /// ### Example
4496 ///
4497 /// ```rust,compile_fail
4498 /// #![deny(ambiguous_glob_imported_traits)]
4499 /// mod m1 {
4500 /// pub trait Trait {
4501 /// fn method1(&self) {}
4502 /// }
4503 /// impl Trait for u8 {}
4504 /// }
4505 /// mod m2 {
4506 /// pub trait Trait {
4507 /// fn method2(&self) {}
4508 /// }
4509 /// impl Trait for u8 {}
4510 /// }
4511 ///
4512 /// fn main() {
4513 /// use m1::*;
4514 /// use m2::*;
4515 /// 0u8.method1();
4516 /// 0u8.method2();
4517 /// }
4518 /// ```
4519 ///
4520 /// {{produces}}
4521 ///
4522 /// ### Explanation
4523 ///
4524 /// When multiple traits with the same name are brought into scope through glob imports,
4525 /// one trait becomes the "primary" one while the others are shadowed. Methods from the
4526 /// shadowed traits (e.g. `method2`) become inaccessible, while methods from the "primary"
4527 /// trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope,
4528 /// but we have to allow this for now because of backwards compatibility.
4529 /// This lint reports uses of these "primary" traits that are ambiguous.
4530 ///
4531 /// This is a [future-incompatible] lint to transition this to a
4532 /// hard error in the future.
4533 ///
4534 /// [future-incompatible]: ../index.md#future-incompatible-lints
4535pub AMBIGUOUS_GLOB_IMPORTED_TRAITS,
4536 Warn,
4537"detects uses of ambiguously glob imported traits",
4538 @future_incompatible = FutureIncompatibleInfo {
4539 reason: fcw!(FutureReleaseError #147992),
4540 report_in_deps: false,
4541 };
4542}45434544#[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! {
4545/// The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but
4546 /// previously didn't do that due to `#[macro_use]` prelude macro import.
4547 ///
4548 /// ### Example
4549 ///
4550 /// ```rust,compile_fail
4551 /// #![deny(ambiguous_panic_imports)]
4552 /// #![no_std]
4553 ///
4554 /// extern crate std;
4555 /// use std::prelude::v1::*;
4556 ///
4557 /// fn xx() {
4558 /// panic!(); // resolves to core::panic
4559 /// }
4560 /// ```
4561 ///
4562 /// {{produces}}
4563 ///
4564 /// ### Explanation
4565 ///
4566 /// Future versions of Rust will no longer accept the ambiguous resolution.
4567 ///
4568 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
4569 ///
4570 /// [future-incompatible]: ../index.md#future-incompatible-lints
4571pub AMBIGUOUS_PANIC_IMPORTS,
4572 Warn,
4573"detects ambiguous core and std panic imports",
4574 @future_incompatible = FutureIncompatibleInfo {
4575 reason: fcw!(FutureReleaseError #147319),
4576 report_in_deps: false,
4577 };
4578}45794580#[doc =
r" The `ambiguous_import_visibilities` lint detects 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(unknown_lints)]"]
#[doc = r" #![deny(ambiguous_import_visibilities)]"]
#[doc = r" mod reexport {"]
#[doc = r" mod m {"]
#[doc = r" pub struct S {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" macro_rules! mac {"]
#[doc = r" () => { use m::S; }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub use m::*;"]
#[doc = r" mac!();"]
#[doc = r""]
#[doc = r" pub use S as Z; // ambiguous visibility"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" reexport::Z {};"]
#[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" fetched the glob import's visibility for `pub use S as Z` import, and ignored the private"]
#[doc = r" `use m::S` import that appeared later."]
#[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_IMPORT_VISIBILITIES: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_IMPORT_VISIBILITIES",
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: 149145,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4581/// The `ambiguous_import_visibilities` lint detects imports that should report ambiguity
4582 /// errors, but previously didn't do that due to rustc bugs.
4583 ///
4584 /// ### Example
4585 ///
4586 /// ```rust,compile_fail
4587 /// #![deny(unknown_lints)]
4588 /// #![deny(ambiguous_import_visibilities)]
4589 /// mod reexport {
4590 /// mod m {
4591 /// pub struct S {}
4592 /// }
4593 ///
4594 /// macro_rules! mac {
4595 /// () => { use m::S; }
4596 /// }
4597 ///
4598 /// pub use m::*;
4599 /// mac!();
4600 ///
4601 /// pub use S as Z; // ambiguous visibility
4602 /// }
4603 ///
4604 /// fn main() {
4605 /// reexport::Z {};
4606 /// }
4607 /// ```
4608 ///
4609 /// {{produces}}
4610 ///
4611 /// ### Explanation
4612 ///
4613 /// Previous versions of Rust compile it successfully because it
4614 /// fetched the glob import's visibility for `pub use S as Z` import, and ignored the private
4615 /// `use m::S` import that appeared later.
4616 ///
4617 /// This is a [future-incompatible] lint to transition this to a
4618 /// hard error in the future.
4619 ///
4620 /// [future-incompatible]: ../index.md#future-incompatible-lints
4621pub AMBIGUOUS_IMPORT_VISIBILITIES,
4622 Warn,
4623"detects certain glob imports that require reporting an ambiguity error",
4624 @future_incompatible = FutureIncompatibleInfo {
4625 reason: fcw!(FutureReleaseError #149145),
4626 };
4627}46284629#[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! {
4630/// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4631 /// types in method signatures that are refined by a publically reachable
4632 /// trait implementation, meaning the implementation adds information about
4633 /// the return type that is not present in the trait.
4634 ///
4635 /// ### Example
4636 ///
4637 /// ```rust,compile_fail
4638 /// #![deny(refining_impl_trait)]
4639 ///
4640 /// use std::fmt::Display;
4641 ///
4642 /// pub trait AsDisplay {
4643 /// fn as_display(&self) -> impl Display;
4644 /// }
4645 ///
4646 /// impl<'s> AsDisplay for &'s str {
4647 /// fn as_display(&self) -> Self {
4648 /// *self
4649 /// }
4650 /// }
4651 ///
4652 /// fn main() {
4653 /// // users can observe that the return type of
4654 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4655 /// let _x: &str = "".as_display();
4656 /// }
4657 /// ```
4658 ///
4659 /// {{produces}}
4660 ///
4661 /// ### Explanation
4662 ///
4663 /// Callers of methods for types where the implementation is known are
4664 /// able to observe the types written in the impl signature. This may be
4665 /// intended behavior, but may also lead to implementation details being
4666 /// revealed unintentionally. In particular, it may pose a semver hazard
4667 /// for authors of libraries who do not wish to make stronger guarantees
4668 /// about the types than what is written in the trait signature.
4669 ///
4670 /// `refining_impl_trait` is a lint group composed of two lints:
4671 ///
4672 /// * `refining_impl_trait_reachable`, for refinements that are publically
4673 /// reachable outside a crate, and
4674 /// * `refining_impl_trait_internal`, for refinements that are only visible
4675 /// within a crate.
4676 ///
4677 /// We are seeking feedback on each of these lints; see issue
4678 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4679 /// information.
4680pub REFINING_IMPL_TRAIT_REACHABLE,
4681 Warn,
4682"impl trait in impl method signature does not match trait method signature",
4683}46844685#[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! {
4686/// The `refining_impl_trait_internal` lint detects `impl Trait` return
4687 /// types in method signatures that are refined by a trait implementation,
4688 /// meaning the implementation adds information about the return type that
4689 /// is not present in the trait.
4690 ///
4691 /// ### Example
4692 ///
4693 /// ```rust,compile_fail
4694 /// #![deny(refining_impl_trait)]
4695 ///
4696 /// use std::fmt::Display;
4697 ///
4698 /// trait AsDisplay {
4699 /// fn as_display(&self) -> impl Display;
4700 /// }
4701 ///
4702 /// impl<'s> AsDisplay for &'s str {
4703 /// fn as_display(&self) -> Self {
4704 /// *self
4705 /// }
4706 /// }
4707 ///
4708 /// fn main() {
4709 /// // users can observe that the return type of
4710 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4711 /// let _x: &str = "".as_display();
4712 /// }
4713 /// ```
4714 ///
4715 /// {{produces}}
4716 ///
4717 /// ### Explanation
4718 ///
4719 /// Callers of methods for types where the implementation is known are
4720 /// able to observe the types written in the impl signature. This may be
4721 /// intended behavior, but may also lead to implementation details being
4722 /// revealed unintentionally. In particular, it may pose a semver hazard
4723 /// for authors of libraries who do not wish to make stronger guarantees
4724 /// about the types than what is written in the trait signature.
4725 ///
4726 /// `refining_impl_trait` is a lint group composed of two lints:
4727 ///
4728 /// * `refining_impl_trait_reachable`, for refinements that are publically
4729 /// reachable outside a crate, and
4730 /// * `refining_impl_trait_internal`, for refinements that are only visible
4731 /// within a crate.
4732 ///
4733 /// We are seeking feedback on each of these lints; see issue
4734 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4735 /// information.
4736pub REFINING_IMPL_TRAIT_INTERNAL,
4737 Warn,
4738"impl trait in impl method signature does not match trait method signature",
4739}47404741#[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! {
4742/// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
4743 /// in associated constants when there are other lifetimes in scope. This was
4744 /// accidentally supported, and this lint was later relaxed to allow eliding
4745 /// lifetimes to `'static` when there are no lifetimes in scope.
4746 ///
4747 /// ### Example
4748 ///
4749 /// ```rust,compile_fail
4750 /// #![deny(elided_lifetimes_in_associated_constant)]
4751 ///
4752 /// struct Foo<'a>(&'a ());
4753 ///
4754 /// impl<'a> Foo<'a> {
4755 /// const STR: &str = "hello, world";
4756 /// }
4757 /// ```
4758 ///
4759 /// {{produces}}
4760 ///
4761 /// ### Explanation
4762 ///
4763 /// Previous version of Rust
4764 ///
4765 /// Implicit static-in-const behavior was decided [against] for associated
4766 /// constants because of ambiguity. This, however, regressed and the compiler
4767 /// erroneously treats elided lifetimes in associated constants as lifetime
4768 /// parameters on the impl.
4769 ///
4770 /// This is a [future-incompatible] lint to transition this to a
4771 /// hard error in the future.
4772 ///
4773 /// [against]: https://github.com/rust-lang/rust/issues/38831
4774 /// [future-incompatible]: ../index.md#future-incompatible-lints
4775pub ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
4776 Deny,
4777"elided lifetimes cannot be used in associated constants in impls",
4778 @future_incompatible = FutureIncompatibleInfo {
4779 reason: fcw!(FutureReleaseError #115010),
4780 };
4781}47824783#[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! {
4784/// The `private_macro_use` lint detects private macros that are imported
4785 /// with `#[macro_use]`.
4786 ///
4787 /// ### Example
4788 ///
4789 /// ```rust,ignore (needs extern crate)
4790 /// // extern_macro.rs
4791 /// macro_rules! foo_ { () => {}; }
4792 /// use foo_ as foo;
4793 ///
4794 /// // code.rs
4795 ///
4796 /// #![deny(private_macro_use)]
4797 ///
4798 /// #[macro_use]
4799 /// extern crate extern_macro;
4800 ///
4801 /// fn main() {
4802 /// foo!();
4803 /// }
4804 /// ```
4805 ///
4806 /// This will produce:
4807 ///
4808 /// ```text
4809 /// error: cannot find macro `foo` in this scope
4810 /// ```
4811 ///
4812 /// ### Explanation
4813 ///
4814 /// This lint arises from overlooking visibility checks for macros
4815 /// in an external crate.
4816 ///
4817 /// This is a [future-incompatible] lint to transition this to a
4818 /// hard error in the future.
4819 ///
4820 /// [future-incompatible]: ../index.md#future-incompatible-lints
4821pub PRIVATE_MACRO_USE,
4822 Deny,
4823"detects certain macro bindings that should not be re-exported",
4824 @future_incompatible = FutureIncompatibleInfo {
4825 reason: fcw!(FutureReleaseError #120192),
4826 report_in_deps: true,
4827 };
4828}48294830#[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! {
4831/// The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for
4832 /// foreign trait implementations that concerns the use of type parameters inside trait associated
4833 /// type paths ("projections") whose output may not be a local type that is mistakenly considered
4834 /// to "cover" said parameters which is **unsound** and which may be rejected by a future version
4835 /// of the compiler.
4836 ///
4837 /// Originally reported in [#99554].
4838 ///
4839 /// [#99554]: https://github.com/rust-lang/rust/issues/99554
4840 ///
4841 /// ### Example
4842 ///
4843 /// ```rust,ignore (dependent)
4844 /// // dependency.rs
4845 /// #![crate_type = "lib"]
4846 ///
4847 /// pub trait Trait<T, U> {}
4848 /// ```
4849 ///
4850 /// ```edition2021,ignore (needs dependency)
4851 /// // dependent.rs
4852 /// trait Identity {
4853 /// type Output;
4854 /// }
4855 ///
4856 /// impl<T> Identity for T {
4857 /// type Output = T;
4858 /// }
4859 ///
4860 /// struct Local;
4861 ///
4862 /// impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4863 ///
4864 /// fn main() {}
4865 /// ```
4866 ///
4867 /// This will produce:
4868 ///
4869 /// ```text
4870 /// warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4871 /// --> dependent.rs:11:6
4872 /// |
4873 /// 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4874 /// | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4875 /// |
4876 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4877 /// = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
4878 /// = 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
4879 /// = 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
4880 /// = note: `#[warn(uncovered_param_in_projection)]` on by default
4881 /// ```
4882 ///
4883 /// ### Explanation
4884 ///
4885 /// FIXME(fmease): Write explainer.
4886pub UNCOVERED_PARAM_IN_PROJECTION,
4887 Warn,
4888"impl contains type parameters that are not covered",
4889 @future_incompatible = FutureIncompatibleInfo {
4890 reason: fcw!(FutureReleaseError #124559),
4891 };
4892}48934894#[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! {
4895/// The `deprecated_safe_2024` lint detects unsafe functions being used as
4896 /// safe functions.
4897 ///
4898 /// ### Example
4899 ///
4900 /// ```rust,edition2021,compile_fail
4901 /// #![deny(deprecated_safe)]
4902 /// // edition 2021
4903 /// use std::env;
4904 /// fn enable_backtrace() {
4905 /// env::set_var("RUST_BACKTRACE", "1");
4906 /// }
4907 /// ```
4908 ///
4909 /// {{produces}}
4910 ///
4911 /// ### Explanation
4912 ///
4913 /// Rust [editions] allow the language to evolve without breaking backward
4914 /// compatibility. This lint catches code that uses `unsafe` functions that
4915 /// were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If
4916 /// you switch the compiler to Rust 2024 without updating the code, then it
4917 /// will fail to compile if you are using a function previously marked as
4918 /// safe.
4919 ///
4920 /// You can audit the code to see if it suffices the preconditions of the
4921 /// `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If
4922 /// you can't fulfill the preconditions, you probably need to switch to a
4923 /// different way of doing what you want to achieve.
4924 ///
4925 /// This lint can automatically wrap the calls in `unsafe` blocks, but this
4926 /// obviously cannot verify that the preconditions of the `unsafe`
4927 /// functions are fulfilled, so that is still up to the user.
4928 ///
4929 /// The lint is currently "allow" by default, but that might change in the
4930 /// future.
4931 ///
4932 /// [editions]: https://doc.rust-lang.org/edition-guide/
4933pub DEPRECATED_SAFE_2024,
4934 Allow,
4935"detects unsafe functions being used as safe functions",
4936 @future_incompatible = FutureIncompatibleInfo {
4937 reason: fcw!(EditionError 2024 "newly-unsafe-functions"),
4938 };
4939}49404941#[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! {
4942/// The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations.
4943 ///
4944 /// ### Example
4945 ///
4946 /// ```rust,edition2021
4947 /// #![warn(missing_unsafe_on_extern)]
4948 /// #![allow(dead_code)]
4949 ///
4950 /// extern "C" {
4951 /// fn foo(_: i32);
4952 /// }
4953 ///
4954 /// fn main() {}
4955 /// ```
4956 ///
4957 /// {{produces}}
4958 ///
4959 /// ### Explanation
4960 ///
4961 /// Declaring extern items, even without ever using them, can cause Undefined Behavior. We
4962 /// should consider all sources of Undefined Behavior to be unsafe.
4963 ///
4964 /// This is a [future-incompatible] lint to transition this to a
4965 /// hard error in the future.
4966 ///
4967 /// [future-incompatible]: ../index.md#future-incompatible-lints
4968pub MISSING_UNSAFE_ON_EXTERN,
4969 Allow,
4970"detects missing unsafe keyword on extern declarations",
4971 @future_incompatible = FutureIncompatibleInfo {
4972 reason: fcw!(EditionError 2024 "unsafe-extern"),
4973 };
4974}49754976#[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! {
4977/// The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword
4978 /// on attributes considered unsafe.
4979 ///
4980 /// ### Example
4981 ///
4982 /// ```rust,edition2021
4983 /// #![warn(unsafe_attr_outside_unsafe)]
4984 ///
4985 /// #[no_mangle]
4986 /// extern "C" fn foo() {}
4987 ///
4988 /// fn main() {}
4989 /// ```
4990 ///
4991 /// {{produces}}
4992 ///
4993 /// ### Explanation
4994 ///
4995 /// Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see
4996 /// [issue #82499] for a more complete list) are considered "unsafe" attributes.
4997 /// An unsafe attribute must only be used inside unsafe(...).
4998 ///
4999 /// This lint can automatically wrap the attributes in `unsafe(...)` , but this
5000 /// obviously cannot verify that the preconditions of the `unsafe`
5001 /// attributes are fulfilled, so that is still up to the user.
5002 ///
5003 /// The lint is currently "allow" by default, but that might change in the
5004 /// future.
5005 ///
5006 /// [editions]: https://doc.rust-lang.org/edition-guide/
5007 /// [issue #82499]: https://github.com/rust-lang/rust/issues/82499
5008pub UNSAFE_ATTR_OUTSIDE_UNSAFE,
5009 Allow,
5010"detects unsafe attributes outside of unsafe",
5011 @future_incompatible = FutureIncompatibleInfo {
5012 reason: fcw!(EditionError 2024 "unsafe-attributes"),
5013 };
5014}50155016#[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! {
5017/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
5018 /// above their definition, which may happen in key-value attributes.
5019 ///
5020 /// ### Example
5021 ///
5022 /// ```rust,compile_fail
5023 /// #![doc = in_root!()]
5024 ///
5025 /// macro_rules! in_root { () => { "" } }
5026 ///
5027 /// fn main() {}
5028 /// ```
5029 ///
5030 /// {{produces}}
5031 ///
5032 /// ### Explanation
5033 ///
5034 /// The scope in which a `macro_rules` item is visible starts at that item and continues
5035 /// below it. This is more similar to `let` than to other items, which are in scope both above
5036 /// and below their definition.
5037 /// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
5038 /// above their definition. The lint catches such cases.
5039 /// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
5040 /// with `use`.
5041 ///
5042 /// This is a [future-incompatible] lint to transition this to a
5043 /// hard error in the future.
5044 ///
5045 /// [future-incompatible]: ../index.md#future-incompatible-lints
5046pub OUT_OF_SCOPE_MACRO_CALLS,
5047 Deny,
5048"detects out of scope calls to `macro_rules` in key-value attributes",
5049 @future_incompatible = FutureIncompatibleInfo {
5050 reason: fcw!(FutureReleaseError #124535),
5051 report_in_deps: true,
5052 };
5053}50545055#[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! {
5056/// The `resolving_to_items_shadowing_supertrait_items` lint detects when the
5057 /// usage of an item that is provided by both a subtrait and supertrait
5058 /// is shadowed, preferring the subtrait.
5059 ///
5060 /// ### Example
5061 ///
5062 /// ```rust,compile_fail
5063 /// #![feature(supertrait_item_shadowing)]
5064 /// #![deny(resolving_to_items_shadowing_supertrait_items)]
5065 ///
5066 /// trait Upstream {
5067 /// fn hello(&self) {}
5068 /// }
5069 /// impl<T> Upstream for T {}
5070 ///
5071 /// trait Downstream: Upstream {
5072 /// fn hello(&self) {}
5073 /// }
5074 /// impl<T> Downstream for T {}
5075 ///
5076 /// struct MyType;
5077 /// MyType.hello();
5078 /// ```
5079 ///
5080 /// {{produces}}
5081 ///
5082 /// ### Explanation
5083 ///
5084 /// RFC 3624 specified a heuristic in which a supertrait item would be
5085 /// shadowed by a subtrait item when ambiguity occurs during item
5086 /// selection. In order to mitigate side-effects of this happening
5087 /// silently, this lint detects these cases when users want to deny them
5088 /// or fix the call sites.
5089pub RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
5090// FIXME(supertrait_item_shadowing): It is not decided if this should
5091 // warn by default at the call site.
5092Allow,
5093"detects when a supertrait item is shadowed by a subtrait item",
5094 @feature_gate = supertrait_item_shadowing;
5095}50965097#[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! {
5098/// The `shadowing_supertrait_items` lint detects when the
5099 /// definition of an item that is provided by both a subtrait and
5100 /// supertrait is shadowed, preferring the subtrait.
5101 ///
5102 /// ### Example
5103 ///
5104 /// ```rust,compile_fail
5105 /// #![feature(supertrait_item_shadowing)]
5106 /// #![deny(shadowing_supertrait_items)]
5107 ///
5108 /// trait Upstream {
5109 /// fn hello(&self) {}
5110 /// }
5111 /// impl<T> Upstream for T {}
5112 ///
5113 /// trait Downstream: Upstream {
5114 /// fn hello(&self) {}
5115 /// }
5116 /// impl<T> Downstream for T {}
5117 /// ```
5118 ///
5119 /// {{produces}}
5120 ///
5121 /// ### Explanation
5122 ///
5123 /// RFC 3624 specified a heuristic in which a supertrait item would be
5124 /// shadowed by a subtrait item when ambiguity occurs during item
5125 /// selection. In order to mitigate side-effects of this happening
5126 /// silently, this lint detects these cases when users want to deny them
5127 /// or fix their trait definitions.
5128pub SHADOWING_SUPERTRAIT_ITEMS,
5129// FIXME(supertrait_item_shadowing): It is not decided if this should
5130 // warn by default at the usage site.
5131Allow,
5132"detects when a supertrait item is shadowed by a subtrait item",
5133 @feature_gate = supertrait_item_shadowing;
5134}51355136#[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! {
5137/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,
5138 /// that runs a custom `Drop` destructor.
5139 /// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior.
5140 /// This lint detects those cases and provides you information on those values and their custom destructor implementations.
5141 /// Your discretion on this information is required.
5142 ///
5143 /// ### Example
5144 /// ```rust,edition2021
5145 /// #![warn(tail_expr_drop_order)]
5146 /// struct Droppy(i32);
5147 /// impl Droppy {
5148 /// fn get(&self) -> i32 {
5149 /// self.0
5150 /// }
5151 /// }
5152 /// impl Drop for Droppy {
5153 /// fn drop(&mut self) {
5154 /// // This is a custom destructor and it induces side-effects that is observable
5155 /// // especially when the drop order at a tail expression changes.
5156 /// println!("loud drop {}", self.0);
5157 /// }
5158 /// }
5159 /// fn edition_2021() -> i32 {
5160 /// let another_droppy = Droppy(0);
5161 /// Droppy(1).get()
5162 /// }
5163 /// fn main() {
5164 /// edition_2021();
5165 /// }
5166 /// ```
5167 ///
5168 /// {{produces}}
5169 ///
5170 /// ### Explanation
5171 ///
5172 /// In tail expression of blocks or function bodies,
5173 /// values of type with significant `Drop` implementation has an ill-specified drop order
5174 /// before Edition 2024 so that they are dropped only after dropping local variables.
5175 /// Edition 2024 introduces a new rule with drop orders for them,
5176 /// so that they are dropped first before dropping local variables.
5177 ///
5178 /// A significant `Drop::drop` destructor here refers to an explicit, arbitrary
5179 /// implementation of the `Drop` trait on the type, with exceptions including `Vec`,
5180 /// `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise
5181 /// so long that the generic types have no significant destructor recursively.
5182 /// In other words, a type has a significant drop destructor when it has a `Drop` implementation
5183 /// or its destructor invokes a significant destructor on a type.
5184 /// Since we cannot completely reason about the change by just inspecting the existence of
5185 /// a significant destructor, this lint remains only a suggestion and is set to `allow` by default.
5186 ///
5187 /// This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`
5188 /// does in Edition 2024.
5189 /// No fix will be proposed by this lint.
5190 /// However, the most probable fix is to hoist `Droppy` into its own local variable binding.
5191 /// ```rust
5192 /// struct Droppy(i32);
5193 /// impl Droppy {
5194 /// fn get(&self) -> i32 {
5195 /// self.0
5196 /// }
5197 /// }
5198 /// fn edition_2024() -> i32 {
5199 /// let value = Droppy(0);
5200 /// let another_droppy = Droppy(1);
5201 /// value.get()
5202 /// }
5203 /// ```
5204pub TAIL_EXPR_DROP_ORDER,
5205 Allow,
5206"Detect and warn on significant change in drop order in tail expression location",
5207 @future_incompatible = FutureIncompatibleInfo {
5208 reason: fcw!(EditionSemanticsChange 2024 "temporary-tail-expr-scope"),
5209 };
5210}52115212#[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! {
5213/// The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens
5214 /// that will be parsed as part of a guarded string literal in Rust 2024.
5215 ///
5216 /// ### Example
5217 ///
5218 /// ```rust,edition2021,compile_fail
5219 /// #![deny(rust_2024_guarded_string_incompatible_syntax)]
5220 ///
5221 /// macro_rules! m {
5222 /// (# $x:expr #) => ();
5223 /// (# $x:expr) => ();
5224 /// }
5225 ///
5226 /// m!(#"hey"#);
5227 /// m!(#"hello");
5228 /// ```
5229 ///
5230 /// {{produces}}
5231 ///
5232 /// ### Explanation
5233 ///
5234 /// Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`
5235 /// followed by the string literal `"hey"` then the final `#`.
5236 /// In Rust 2024, the whole sequence is considered a single token.
5237 ///
5238 /// This lint suggests to add whitespace between the leading `#`
5239 /// and the string to keep them separated in Rust 2024.
5240// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
5241#[allow(rustdoc::invalid_rust_codeblocks)]
5242pub RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
5243 Allow,
5244"will be parsed as a guarded string in Rust 2024",
5245 @future_incompatible = FutureIncompatibleInfo {
5246 reason: fcw!(EditionError 2024 "reserved-syntax"),
5247 };
5248 crate_level_only
5249}52505251#[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! {
5252/// The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on
5253 /// softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of
5254 /// function calls, making this attribute unsound to use.
5255 ///
5256 /// ### Example
5257 ///
5258 /// ```rust,ignore (needs aarch64-unknown-none-softfloat)
5259 /// #[target_feature(enable = "neon")]
5260 /// fn with_neon() {}
5261 /// ```
5262 ///
5263 /// This will produce:
5264 ///
5265 /// ```text
5266 /// error: enabling the `neon` target feature on the current target is unsound due to ABI issues
5267 /// --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
5268 /// |
5269 /// | #[target_feature(enable = "neon")]
5270 /// | ^^^^^^^^^^^^^^^
5271 /// |
5272 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5273 /// = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
5274 /// ```
5275 ///
5276 /// ### Explanation
5277 ///
5278 /// If a function like `with_neon` above ends up containing calls to LLVM builtins, those will
5279 /// not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with
5280 /// and without the `neon` target feature. The target feature should never have been stabilized
5281 /// on this target due to this issue, but the problem was not known at the time of
5282 /// stabilization.
5283pub AARCH64_SOFTFLOAT_NEON,
5284 Warn,
5285"detects code that could be affected by ABI issues on aarch64 softfloat targets",
5286 @future_incompatible = FutureIncompatibleInfo {
5287 reason: fcw!(FutureReleaseError #134375),
5288 report_in_deps: true,
5289 };
5290}52915292#[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! {
5293/// The `tail_call_track_caller` lint detects usage of `become` attempting to tail call
5294 /// a function marked with `#[track_caller]`.
5295 ///
5296 /// ### Example
5297 ///
5298 /// ```rust
5299 /// #![feature(explicit_tail_calls)]
5300 /// #![expect(incomplete_features)]
5301 ///
5302 /// #[track_caller]
5303 /// fn f() {}
5304 ///
5305 /// fn g() {
5306 /// become f();
5307 /// }
5308 ///
5309 /// g();
5310 /// ```
5311 ///
5312 /// {{produces}}
5313 ///
5314 /// ### Explanation
5315 ///
5316 /// Due to implementation details of tail calls and `#[track_caller]` attribute, calls to
5317 /// functions marked with `#[track_caller]` cannot become tail calls. As such using `become`
5318 /// is no different than a normal call (except for changes in drop order).
5319pub TAIL_CALL_TRACK_CALLER,
5320 Warn,
5321"detects tail calls of functions marked with `#[track_caller]`",
5322 @feature_gate = explicit_tail_calls;
5323}5324#[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! {
5325/// The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant
5326 /// values that do not fit into a C `int` or `unsigned int`.
5327 ///
5328 /// ### Example
5329 ///
5330 /// ```rust,ignore (only errors on 64bit)
5331 /// #[repr(C)]
5332 /// enum E {
5333 /// V = 9223372036854775807, // i64::MAX
5334 /// }
5335 /// ```
5336 ///
5337 /// This will produce:
5338 ///
5339 /// ```text
5340 /// error: `repr(C)` enum discriminant does not fit into C `int` nor into C `unsigned int`
5341 /// --> $DIR/repr-c-big-discriminant1.rs:16:5
5342 /// |
5343 /// LL | A = 9223372036854775807, // i64::MAX
5344 /// | ^
5345 /// |
5346 /// = note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
5347 /// = help: use `repr($int_ty)` instead to explicitly set the size of this enum
5348 /// ```
5349 ///
5350 /// ### Explanation
5351 ///
5352 /// In C, enums with discriminants that do not all fit into an `int` or all fit into an
5353 /// `unsigned int` are a portability hazard: such enums are only permitted since C23, and not
5354 /// supported e.g. by MSVC.
5355 ///
5356 /// Furthermore, Rust interprets the discriminant values of `repr(C)` enums as expressions of
5357 /// type `isize`. This makes it impossible to implement the C23 behavior of enums where the enum
5358 /// discriminants have no predefined type and instead the enum uses a type large enough to hold
5359 /// all discriminants.
5360 ///
5361 /// Therefore, `repr(C)` enums in Rust require that either all discriminants to fit into a C
5362 /// `int` or they all fit into an `unsigned int`.
5363pub REPR_C_ENUMS_LARGER_THAN_INT,
5364 Warn,
5365"repr(C) enums with discriminant values that do not fit into a C int",
5366 @future_incompatible = FutureIncompatibleInfo {
5367 reason: fcw!(FutureReleaseError #124403),
5368 report_in_deps: false,
5369 };
5370}53715372#[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,compile_fail"]
#[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::Deny,
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: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5373/// The `varargs_without_pattern` lint detects when `...` is used as an argument to a
5374 /// non-foreign function without any pattern being specified.
5375 ///
5376 /// ### Example
5377 ///
5378 /// ```rust,compile_fail
5379 /// // Using `...` in non-foreign function definitions is unstable, however stability is
5380 /// // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will
5381 /// // allow this to compile on stable Rust.
5382 /// #[cfg(false)]
5383 /// fn foo(...) {
5384 ///
5385 /// }
5386 /// ```
5387 ///
5388 /// {{produces}}
5389 ///
5390 /// ### Explanation
5391 ///
5392 /// Patterns are currently required for all non-`...` arguments in function definitions (with
5393 /// some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in
5394 /// non-foreign function definitions makes the language more consistent, and removes a source of
5395 /// confusion for the unstable C variadic feature. `...` arguments without a pattern are already
5396 /// stable and widely used in foreign function definitions; this lint only affects non-foreign
5397 /// function definitions.
5398 ///
5399 /// Using `...` (C varargs) in a non-foreign function definition is currently unstable. However,
5400 /// stability checking for the `...` syntax in non-foreign function definitions is currently
5401 /// implemented after attributes have been expanded, meaning that if the attribute removes the
5402 /// use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will
5403 /// compile on stable Rust; this is the only situation where this lint affects code that
5404 /// compiles on stable Rust.
5405 ///
5406 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
5407 ///
5408 /// [future-incompatible]: ../index.md#future-incompatible-lints
5409pub VARARGS_WITHOUT_PATTERN,
5410 Deny,
5411"detects usage of `...` arguments without a pattern in non-foreign items",
5412 @future_incompatible = FutureIncompatibleInfo {
5413 reason: fcw!(FutureReleaseError #145544),
5414 report_in_deps: true,
5415 };
5416}54175418#[doc =
r" The `deprecated_llvm_intrinsic` lint detects usage of deprecated LLVM intrinsics."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (requires x86)"]
#[doc = r#" #![cfg(any(target_arch = "x86", target_arch = "x86_64"))]"#]
#[doc = r" #![feature(link_llvm_intrinsics, abi_unadjusted)]"]
#[doc = r" #![deny(deprecated_llvm_intrinsic)]"]
#[doc = r""]
#[doc = r#" unsafe extern "unadjusted" {"#]
#[doc = r#" #[link_name = "llvm.x86.addcarryx.u32"]"#]
#[doc = r" fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[inline(never)]"]
#[doc = r#" #[target_feature(enable = "adx")]"#]
#[doc = r" pub fn bar(a: u8, b: u32, c: u32, d: &mut u32) -> u8 {"]
#[doc = r" unsafe { foo(a, b, c, d) }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: Using deprecated intrinsic `llvm.x86.addcarryx.u32`"]
#[doc = r" --> example.rs:7:5"]
#[doc = r" |"]
#[doc = r" 7 | fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" LLVM periodically updates its list of intrinsics. Deprecated intrinsics are unlikely"]
#[doc =
r" to be removed, but they may optimize less well than their new versions, so it's"]
#[doc =
r" best to use the new version. Also, some deprecated intrinsics might have buggy"]
#[doc = r" behavior."]
#[doc = r""]
#[doc =
r" This `link_llvm_intrinsics` lint is intended to be used internally only, and requires the"]
#[doc =
r" `#![feature(link_llvm_intrinsics)]` internal feature gate. For more information, see [its chapter in"]
#[doc =
r" the Unstable Book](https://doc.rust-lang.org/unstable-book/language-features/link-llvm-intrinsics.html)"]
#[doc =
r" and [its tracking issue](https://github.com/rust-lang/rust/issues/29602)."]
pub static DEPRECATED_LLVM_INTRINSIC: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_LLVM_INTRINSIC",
default_level: crate::Allow,
desc: "detects uses of deprecated LLVM intrinsics",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::link_llvm_intrinsics),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5419/// The `deprecated_llvm_intrinsic` lint detects usage of deprecated LLVM intrinsics.
5420 ///
5421 /// ### Example
5422 ///
5423 /// ```rust,ignore (requires x86)
5424 /// #![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5425 /// #![feature(link_llvm_intrinsics, abi_unadjusted)]
5426 /// #![deny(deprecated_llvm_intrinsic)]
5427 ///
5428 /// unsafe extern "unadjusted" {
5429 /// #[link_name = "llvm.x86.addcarryx.u32"]
5430 /// fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;
5431 /// }
5432 ///
5433 /// #[inline(never)]
5434 /// #[target_feature(enable = "adx")]
5435 /// pub fn bar(a: u8, b: u32, c: u32, d: &mut u32) -> u8 {
5436 /// unsafe { foo(a, b, c, d) }
5437 /// }
5438 /// ```
5439 ///
5440 /// This will produce:
5441 ///
5442 /// ```text
5443 /// error: Using deprecated intrinsic `llvm.x86.addcarryx.u32`
5444 /// --> example.rs:7:5
5445 /// |
5446 /// 7 | fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;
5447 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5448 /// |
5449 /// ```
5450 ///
5451 /// ### Explanation
5452 ///
5453 /// LLVM periodically updates its list of intrinsics. Deprecated intrinsics are unlikely
5454 /// to be removed, but they may optimize less well than their new versions, so it's
5455 /// best to use the new version. Also, some deprecated intrinsics might have buggy
5456 /// behavior.
5457 ///
5458 /// This `link_llvm_intrinsics` lint is intended to be used internally only, and requires the
5459 /// `#![feature(link_llvm_intrinsics)]` internal feature gate. For more information, see [its chapter in
5460 /// the Unstable Book](https://doc.rust-lang.org/unstable-book/language-features/link-llvm-intrinsics.html)
5461 /// and [its tracking issue](https://github.com/rust-lang/rust/issues/29602).
5462pub DEPRECATED_LLVM_INTRINSIC,
5463 Allow,
5464"detects uses of deprecated LLVM intrinsics",
5465 @feature_gate = link_llvm_intrinsics;
5466}54675468#[doc =
r" The `float_literal_f32_fallback` lint detects situations where the type of an unsuffixed"]
#[doc =
r" float literal falls back to `f32` instead of `f64` to avoid a compilation error. This occurs"]
#[doc =
r" when there is a trait bound `f32: From<T>` (or equivalent, such as `T: Into<f32>`) and the"]
#[doc = r" literal is inferred to have the same type as `T`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo(x: impl Into<f32>) -> f32 {"]
#[doc = r" x.into()"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" dbg!(foo(2.5));"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust allows traits that are only implemented for a single floating point type to guide type"]
#[doc =
r" inference for floating point literals. This used to apply in the case of `f32: From<T>`"]
#[doc =
r" (where `T` was inferred to be the same type as a floating point literal), as the only"]
#[doc =
r" floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding"]
#[doc =
r" support for `f16`, there are now two implementations for floating point types:"]
#[doc =
r" `f32: From<f16>` and `f32: From<f32>`. This means that the trait bound `f32: From<T>` can no"]
#[doc =
r" longer guide inference for the type of the floating point literal. The default fallback for"]
#[doc =
r" unsuffixed floating point literals is `f64`. As `f32` does not implement `From<f64>`,"]
#[doc =
r" falling back to `f64` would cause a compilation error; therefore, the float type fallback"]
#[doc =
r" has been tempoarily adjusted to fallback to `f32` in this scenario."]
#[doc = r""]
#[doc =
r" The lint will automatically provide a machine-applicable suggestion to add a `_f32` suffix"]
#[doc = r" to the literal, which will fix the problem."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future. See"]
#[doc = r" [issue #154024] for more details."]
#[doc = r""]
#[doc = r" [issue #154024]: https://github.com/rust-lang/rust/issues/154024"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static FLOAT_LITERAL_F32_FALLBACK: &crate::Lint =
&crate::Lint {
name: "FLOAT_LITERAL_F32_FALLBACK",
default_level: crate::Warn,
desc: "detects unsuffixed floating point literals whose type fallback to `f32`",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 154024,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5469/// The `float_literal_f32_fallback` lint detects situations where the type of an unsuffixed
5470 /// float literal falls back to `f32` instead of `f64` to avoid a compilation error. This occurs
5471 /// when there is a trait bound `f32: From<T>` (or equivalent, such as `T: Into<f32>`) and the
5472 /// literal is inferred to have the same type as `T`.
5473 ///
5474 /// ### Example
5475 ///
5476 /// ```rust
5477 /// fn foo(x: impl Into<f32>) -> f32 {
5478 /// x.into()
5479 /// }
5480 ///
5481 /// fn main() {
5482 /// dbg!(foo(2.5));
5483 /// }
5484 /// ```
5485 ///
5486 /// {{produces}}
5487 ///
5488 /// ### Explanation
5489 ///
5490 /// Rust allows traits that are only implemented for a single floating point type to guide type
5491 /// inference for floating point literals. This used to apply in the case of `f32: From<T>`
5492 /// (where `T` was inferred to be the same type as a floating point literal), as the only
5493 /// floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding
5494 /// support for `f16`, there are now two implementations for floating point types:
5495 /// `f32: From<f16>` and `f32: From<f32>`. This means that the trait bound `f32: From<T>` can no
5496 /// longer guide inference for the type of the floating point literal. The default fallback for
5497 /// unsuffixed floating point literals is `f64`. As `f32` does not implement `From<f64>`,
5498 /// falling back to `f64` would cause a compilation error; therefore, the float type fallback
5499 /// has been tempoarily adjusted to fallback to `f32` in this scenario.
5500 ///
5501 /// The lint will automatically provide a machine-applicable suggestion to add a `_f32` suffix
5502 /// to the literal, which will fix the problem.
5503 ///
5504 /// This is a [future-incompatible] lint to transition this to a hard error in the future. See
5505 /// [issue #154024] for more details.
5506 ///
5507 /// [issue #154024]: https://github.com/rust-lang/rust/issues/154024
5508 /// [future-incompatible]: ../index.md#future-incompatible-lints
5509pub FLOAT_LITERAL_F32_FALLBACK,
5510 Warn,
5511"detects unsuffixed floating point literals whose type fallback to `f32`",
5512 @future_incompatible = FutureIncompatibleInfo {
5513 reason: fcw!(FutureReleaseError #154024),
5514 report_in_deps: false,
5515 };
5516}55175518#[doc = r" The `unsafe_code` lint catches usage of `unsafe` code and other"]
#[doc = r" potentially unsound constructs like `no_mangle`, `export_name`,"]
#[doc = r" and `link_section`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unsafe_code)]"]
#[doc = r" fn main() {"]
#[doc = r" unsafe {"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r" fn func_0() { }"]
#[doc = r""]
#[doc = r#" #[export_name = "exported_symbol_name"]"#]
#[doc = r" pub fn name_in_rust() { }"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r#" #[link_section = ".example_section"]"#]
#[doc = r" pub static VAR1: u32 = 1;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is intended to restrict the usage of `unsafe` blocks and other"]
#[doc =
r" constructs (including, but not limited to `no_mangle`, `link_section`"]
#[doc =
r" and `export_name` attributes) wrong usage of which causes undefined"]
#[doc = r" behavior."]
pub static UNSAFE_CODE: &crate::Lint =
&crate::Lint {
name: "UNSAFE_CODE",
default_level: crate::Allow,
desc: "usage of `unsafe` code and other potentially unsound constructs",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5519/// The `unsafe_code` lint catches usage of `unsafe` code and other
5520 /// potentially unsound constructs like `no_mangle`, `export_name`,
5521 /// and `link_section`.
5522 ///
5523 /// ### Example
5524 ///
5525 /// ```rust,compile_fail
5526 /// #![deny(unsafe_code)]
5527 /// fn main() {
5528 /// unsafe {
5529 ///
5530 /// }
5531 /// }
5532 ///
5533 /// #[no_mangle]
5534 /// fn func_0() { }
5535 ///
5536 /// #[export_name = "exported_symbol_name"]
5537 /// pub fn name_in_rust() { }
5538 ///
5539 /// #[no_mangle]
5540 /// #[link_section = ".example_section"]
5541 /// pub static VAR1: u32 = 1;
5542 /// ```
5543 ///
5544 /// {{produces}}
5545 ///
5546 /// ### Explanation
5547 ///
5548 /// This lint is intended to restrict the usage of `unsafe` blocks and other
5549 /// constructs (including, but not limited to `no_mangle`, `link_section`
5550 /// and `export_name` attributes) wrong usage of which causes undefined
5551 /// behavior.
5552pub UNSAFE_CODE,
5553 Allow,
5554"usage of `unsafe` code and other potentially unsound constructs",
5555 @eval_always = true
5556}