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