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