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,
AMBIGUOUS_ASSOCIATED_ITEMS, AMBIGUOUS_DERIVE_HELPERS,
AMBIGUOUS_GLOB_IMPORTED_TRAITS, AMBIGUOUS_GLOB_IMPORTS,
AMBIGUOUS_GLOB_REEXPORTS, AMBIGUOUS_IMPORT_VISIBILITIES,
AMBIGUOUS_PANIC_IMPORTS, ARITHMETIC_OVERFLOW,
ASM_SUB_REGISTER, BAD_ASM_STYLE, BARE_TRAIT_OBJECTS,
BINDINGS_WITH_VARIANT_NAME, BREAK_WITH_LABEL_AND_LOOP,
COHERENCE_LEAK_CHECK, CONFLICTING_REPR_HINTS,
CONST_EVALUATABLE_UNCHECKED, CONST_ITEM_MUTATION, DEAD_CODE,
DEAD_CODE_PUB_IN_BINARY,
DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK, DEPRECATED,
DEPRECATED_IN_FUTURE, DEPRECATED_LLVM_INTRINSIC,
DEPRECATED_SAFE_2024, DEPRECATED_WHERE_CLAUSE_LOCATION,
DUPLICATE_FEATURES, DUPLICATE_MACRO_ATTRIBUTES,
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
EXPORTED_PRIVATE_DEPENDENCIES, FFI_UNWIND_CALLS,
FLOAT_LITERAL_F32_FALLBACK, FORBIDDEN_LINT_GROUPS,
FUNCTION_ITEM_REFERENCES, HIDDEN_GLOB_REEXPORTS,
ILL_FORMED_ATTRIBUTE_INPUT, INCOMPLETE_INCLUDE,
INEFFECTIVE_UNSTABLE_TRAIT_IMPL, INLINE_NO_SANITIZE,
INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS,
INVALID_TYPE_PARAM_DEFAULT, IRREFUTABLE_LET_PATTERNS,
LARGE_ASSIGNMENTS, LATE_BOUND_LIFETIME_ARGUMENTS,
LEGACY_DERIVE_HELPERS, LINKER_INFO, LINKER_MESSAGES,
LONG_RUNNING_CONST_EVAL,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
MACRO_USE_EXTERN_CRATE, MALFORMED_DIAGNOSTIC_ATTRIBUTES,
MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, META_VARIABLE_MISUSE,
MISPLACED_DIAGNOSTIC_ATTRIBUTES, MISSING_ABI,
MISSING_UNSAFE_ON_EXTERN, MUST_NOT_SUSPEND,
NAMED_ARGUMENTS_USED_POSITIONALLY,
NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
NON_CONTIGUOUS_RANGE_ENDPOINTS,
NON_EXHAUSTIVE_OMITTED_PATTERNS, OUT_OF_SCOPE_MACRO_CALLS,
OVERLAPPING_RANGE_ENDPOINTS, PATTERNS_IN_FNS_WITHOUT_BODY,
PRIVATE_BOUNDS, PRIVATE_INTERFACES,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
PUB_USE_OF_PRIVATE_EXTERN_CRATE, REDUNDANT_IMPORTS,
REDUNDANT_LIFETIMES, REFINING_IMPL_TRAIT_INTERNAL,
REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS,
REPR_C_ENUMS_LARGER_THAN_INT,
RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
RTSAN_NONBLOCKING_ASYNC,
RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
RUST_2021_INCOMPATIBLE_OR_PATTERNS,
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
RUST_2021_PRELUDE_COLLISIONS,
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
RUST_2024_INCOMPATIBLE_PAT, RUST_2024_PRELUDE_COLLISIONS,
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
SHADOWING_SUPERTRAIT_ITEMS, SINGLE_USE_LIFETIMES,
STABLE_FEATURES, TAIL_CALL_TRACK_CALLER, TAIL_EXPR_DROP_ORDER,
TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TEXT_DIRECTION_CODEPOINT_IN_LITERAL, TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS, TYVAR_BEHIND_RAW_POINTER,
UNCONDITIONAL_PANIC, UNCONDITIONAL_RECURSION,
UNCOVERED_PARAM_IN_PROJECTION, UNEXPECTED_CFGS,
UNFULFILLED_LINT_EXPECTATIONS, UNINHABITED_STATIC,
UNKNOWN_CRATE_TYPES, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
UNKNOWN_LINTS, UNNAMEABLE_TEST_ITEMS, UNNAMEABLE_TYPES,
UNREACHABLE_CFG_SELECT_PREDICATES, UNREACHABLE_CODE,
UNREACHABLE_PATTERNS, UNSAFE_ATTR_OUTSIDE_UNSAFE,
UNSAFE_OP_IN_UNSAFE_FN, UNSTABLE_NAME_COLLISIONS,
UNSTABLE_SYNTAX_PRE_EXPANSION,
UNSUPPORTED_CALLING_CONVENTIONS, UNUSED_ASSIGNMENTS,
UNUSED_ASSOCIATED_TYPE_BOUNDS, UNUSED_ATTRIBUTES,
UNUSED_CRATE_DEPENDENCIES, UNUSED_EXTERN_CRATES,
UNUSED_FEATURES, UNUSED_IMPORTS, UNUSED_LABELS,
UNUSED_LIFETIMES, UNUSED_MACROS, UNUSED_MACRO_RULES,
UNUSED_MUT, UNUSED_QUALIFICATIONS, UNUSED_UNSAFE,
UNUSED_VARIABLES, UNUSED_VISIBILITIES, USELESS_DEPRECATED,
VARARGS_WITHOUT_PATTERN, WARNINGS]))vec![
17// tidy-alphabetical-start
18AARCH64_SOFTFLOAT_NEON,
19 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
20 AMBIGUOUS_ASSOCIATED_ITEMS,
21 AMBIGUOUS_DERIVE_HELPERS,
22 AMBIGUOUS_GLOB_IMPORTED_TRAITS,
23 AMBIGUOUS_GLOB_IMPORTS,
24 AMBIGUOUS_GLOB_REEXPORTS,
25 AMBIGUOUS_IMPORT_VISIBILITIES,
26 AMBIGUOUS_PANIC_IMPORTS,
27 ARITHMETIC_OVERFLOW,
28 ASM_SUB_REGISTER,
29 BAD_ASM_STYLE,
30 BARE_TRAIT_OBJECTS,
31 BINDINGS_WITH_VARIANT_NAME,
32 BREAK_WITH_LABEL_AND_LOOP,
33 COHERENCE_LEAK_CHECK,
34 CONFLICTING_REPR_HINTS,
35 CONST_EVALUATABLE_UNCHECKED,
36 CONST_ITEM_MUTATION,
37 DEAD_CODE,
38 DEAD_CODE_PUB_IN_BINARY,
39 DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
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 ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
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_TRAIT_IMPL,
59 INLINE_NO_SANITIZE,
60 INVALID_DOC_ATTRIBUTES,
61 INVALID_MACRO_EXPORT_ARGUMENTS,
62 INVALID_TYPE_PARAM_DEFAULT,
63 IRREFUTABLE_LET_PATTERNS,
64 LARGE_ASSIGNMENTS,
65 LATE_BOUND_LIFETIME_ARGUMENTS,
66 LEGACY_DERIVE_HELPERS,
67 LINKER_INFO,
68 LINKER_MESSAGES,
69 LONG_RUNNING_CONST_EVAL,
70 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
71 MACRO_USE_EXTERN_CRATE,
72 MALFORMED_DIAGNOSTIC_ATTRIBUTES,
73 MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
74 META_VARIABLE_MISUSE,
75 MISPLACED_DIAGNOSTIC_ATTRIBUTES,
76 MISSING_ABI,
77 MISSING_UNSAFE_ON_EXTERN,
78 MUST_NOT_SUSPEND,
79 NAMED_ARGUMENTS_USED_POSITIONALLY,
80 NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
81 NON_CONTIGUOUS_RANGE_ENDPOINTS,
82 NON_EXHAUSTIVE_OMITTED_PATTERNS,
83 OUT_OF_SCOPE_MACRO_CALLS,
84 OVERLAPPING_RANGE_ENDPOINTS,
85 PATTERNS_IN_FNS_WITHOUT_BODY,
86 PRIVATE_BOUNDS,
87 PRIVATE_INTERFACES,
88 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
89 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
90 REDUNDANT_IMPORTS,
91 REDUNDANT_LIFETIMES,
92 REFINING_IMPL_TRAIT_INTERNAL,
93 REFINING_IMPL_TRAIT_REACHABLE,
94 RENAMED_AND_REMOVED_LINTS,
95 REPR_C_ENUMS_LARGER_THAN_INT,
96 RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
97 RTSAN_NONBLOCKING_ASYNC,
98 RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
99 RUST_2021_INCOMPATIBLE_OR_PATTERNS,
100 RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
101 RUST_2021_PRELUDE_COLLISIONS,
102 RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
103 RUST_2024_INCOMPATIBLE_PAT,
104 RUST_2024_PRELUDE_COLLISIONS,
105 SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
106 SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
107 SHADOWING_SUPERTRAIT_ITEMS,
108 SINGLE_USE_LIFETIMES,
109 STABLE_FEATURES,
110 TAIL_CALL_TRACK_CALLER,
111 TAIL_EXPR_DROP_ORDER,
112 TEST_UNSTABLE_LINT,
113 TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
114 TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
115 TRIVIAL_CASTS,
116 TRIVIAL_NUMERIC_CASTS,
117 TYVAR_BEHIND_RAW_POINTER,
118 UNCONDITIONAL_PANIC,
119 UNCONDITIONAL_RECURSION,
120 UNCOVERED_PARAM_IN_PROJECTION,
121 UNEXPECTED_CFGS,
122 UNFULFILLED_LINT_EXPECTATIONS,
123 UNINHABITED_STATIC,
124 UNKNOWN_CRATE_TYPES,
125 UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
126 UNKNOWN_LINTS,
127 UNNAMEABLE_TEST_ITEMS,
128 UNNAMEABLE_TYPES,
129 UNREACHABLE_CFG_SELECT_PREDICATES,
130 UNREACHABLE_CODE,
131 UNREACHABLE_PATTERNS,
132 UNSAFE_ATTR_OUTSIDE_UNSAFE,
133 UNSAFE_OP_IN_UNSAFE_FN,
134 UNSTABLE_NAME_COLLISIONS,
135 UNSTABLE_SYNTAX_PRE_EXPANSION,
136 UNSUPPORTED_CALLING_CONVENTIONS,
137 UNUSED_ASSIGNMENTS,
138 UNUSED_ASSOCIATED_TYPE_BOUNDS,
139 UNUSED_ATTRIBUTES,
140 UNUSED_CRATE_DEPENDENCIES,
141 UNUSED_EXTERN_CRATES,
142 UNUSED_FEATURES,
143 UNUSED_IMPORTS,
144 UNUSED_LABELS,
145 UNUSED_LIFETIMES,
146 UNUSED_MACROS,
147 UNUSED_MACRO_RULES,
148 UNUSED_MUT,
149 UNUSED_QUALIFICATIONS,
150 UNUSED_UNSAFE,
151 UNUSED_VARIABLES,
152 UNUSED_VISIBILITIES,
153 USELESS_DEPRECATED,
154 VARARGS_WITHOUT_PATTERN,
155 WARNINGS,
156// tidy-alphabetical-end
157]158 }
159}
160161#[doc = r" The `forbidden_lint_groups` lint detects violations of"]
#[doc = r" `forbid` applied to a lint group. Due to a bug in the compiler,"]
#[doc =
r" these used to be overlooked entirely. They now generate a warning."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![forbid(warnings)]"]
#[doc = r" #![warn(bad_style)]"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Recommended fix"]
#[doc = r""]
#[doc = r" If your crate is using `#![forbid(warnings)]`,"]
#[doc = r" we recommend that you change to `#![deny(warnings)]`."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Due to a compiler bug, applying `forbid` to lint groups"]
#[doc = r" previously had no effect. The bug is now fixed but instead of"]
#[doc = r" enforcing `forbid` we issue this future-compatibility warning"]
#[doc = r" to avoid breaking existing crates."]
pub static FORBIDDEN_LINT_GROUPS: &crate::Lint =
&crate::Lint {
name: "FORBIDDEN_LINT_GROUPS",
default_level: crate::Warn,
desc: "applying forbid to lint-groups",
is_externally_loaded: false,
ignore_deny_warnings: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 81670,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
162/// The `forbidden_lint_groups` lint detects violations of
163 /// `forbid` applied to a lint group. Due to a bug in the compiler,
164 /// these used to be overlooked entirely. They now generate a warning.
165 ///
166 /// ### Example
167 ///
168 /// ```rust
169 /// #![forbid(warnings)]
170 /// #![warn(bad_style)]
171 ///
172 /// fn main() {}
173 /// ```
174 ///
175 /// {{produces}}
176 ///
177 /// ### Recommended fix
178 ///
179 /// If your crate is using `#![forbid(warnings)]`,
180 /// we recommend that you change to `#![deny(warnings)]`.
181 ///
182 /// ### Explanation
183 ///
184 /// Due to a compiler bug, applying `forbid` to lint groups
185 /// previously had no effect. The bug is now fixed but instead of
186 /// enforcing `forbid` we issue this future-compatibility warning
187 /// to avoid breaking existing crates.
188pub FORBIDDEN_LINT_GROUPS,
189 Warn,
190"applying forbid to lint-groups",
191 @future_incompatible = FutureIncompatibleInfo {
192 reason: fcw!(FutureReleaseError #81670),
193 report_in_deps: true,
194 };
195// We exempt `FORBIDDEN_LINT_GROUPS` from `-Dwarnings` because it specifically
196 // triggers in cases (like #80988) where you have `forbid(warnings)`,
197 // and so if we turned that into an error, it'd defeat the purpose of the
198 // future compatibility warning.
199ignore_deny_warnings
200}201202#[doc =
r" The `ill_formed_attribute_input` lint detects ill-formed attribute"]
#[doc = r" inputs that were previously accepted and used in practice."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r#" #[inline = "this is not valid"]"#]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Previously, inputs for many built-in attributes weren't validated and"]
#[doc = r" nonsensical attribute inputs were accepted. After validation was"]
#[doc =
r" added, it was determined that some existing projects made use of these"]
#[doc =
r" invalid forms. This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #57571] for more details."]
#[doc = r""]
#[doc =
r" Check the [attribute reference] for details on the valid inputs for"]
#[doc = r" attributes."]
#[doc = r""]
#[doc = r" [issue #57571]: https://github.com/rust-lang/rust/issues/57571"]
#[doc =
r" [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static ILL_FORMED_ATTRIBUTE_INPUT: &crate::Lint =
&crate::Lint {
name: "ILL_FORMED_ATTRIBUTE_INPUT",
default_level: crate::Deny,
desc: "ill-formed attribute inputs that were previously accepted and used in practice",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57571,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
203/// The `ill_formed_attribute_input` lint detects ill-formed attribute
204 /// inputs that were previously accepted and used in practice.
205 ///
206 /// ### Example
207 ///
208 /// ```rust,compile_fail
209 /// #[inline = "this is not valid"]
210 /// fn foo() {}
211 /// ```
212 ///
213 /// {{produces}}
214 ///
215 /// ### Explanation
216 ///
217 /// Previously, inputs for many built-in attributes weren't validated and
218 /// nonsensical attribute inputs were accepted. After validation was
219 /// added, it was determined that some existing projects made use of these
220 /// invalid forms. This is a [future-incompatible] lint to transition this
221 /// to a hard error in the future. See [issue #57571] for more details.
222 ///
223 /// Check the [attribute reference] for details on the valid inputs for
224 /// attributes.
225 ///
226 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
227 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
228 /// [future-incompatible]: ../index.md#future-incompatible-lints
229pub ILL_FORMED_ATTRIBUTE_INPUT,
230 Deny,
231"ill-formed attribute inputs that were previously accepted and used in practice",
232 @future_incompatible = FutureIncompatibleInfo {
233 reason: fcw!(FutureReleaseError #57571),
234 report_in_deps: true,
235 };
236 crate_level_only
237}238239#[doc =
r" The `conflicting_repr_hints` lint detects [`repr` attributes] with"]
#[doc = r" conflicting hints."]
#[doc = r""]
#[doc =
r" [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[repr(u32, u64)]"]
#[doc = r" enum Foo {"]
#[doc = r" Variant1,"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The compiler incorrectly accepted these conflicting representations in"]
#[doc =
r" the past. This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future. See [issue #68585] for more details."]
#[doc = r""]
#[doc = r" To correct the issue, remove one of the conflicting hints."]
#[doc = r""]
#[doc = r" [issue #68585]: https://github.com/rust-lang/rust/issues/68585"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static CONFLICTING_REPR_HINTS: &crate::Lint =
&crate::Lint {
name: "CONFLICTING_REPR_HINTS",
default_level: crate::Deny,
desc: "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 68585,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
240/// The `conflicting_repr_hints` lint detects [`repr` attributes] with
241 /// conflicting hints.
242 ///
243 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
244 ///
245 /// ### Example
246 ///
247 /// ```rust,compile_fail
248 /// #[repr(u32, u64)]
249 /// enum Foo {
250 /// Variant1,
251 /// }
252 /// ```
253 ///
254 /// {{produces}}
255 ///
256 /// ### Explanation
257 ///
258 /// The compiler incorrectly accepted these conflicting representations in
259 /// the past. This is a [future-incompatible] lint to transition this to a
260 /// hard error in the future. See [issue #68585] for more details.
261 ///
262 /// To correct the issue, remove one of the conflicting hints.
263 ///
264 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
265 /// [future-incompatible]: ../index.md#future-incompatible-lints
266pub CONFLICTING_REPR_HINTS,
267 Deny,
268"conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
269 @future_incompatible = FutureIncompatibleInfo {
270 reason: fcw!(FutureReleaseError #68585),
271 report_in_deps: true,
272 };
273}274275#[doc =
r" The `meta_variable_misuse` lint detects possible meta-variable misuse"]
#[doc = r" in macro definitions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(meta_variable_misuse)]"]
#[doc = r""]
#[doc = r" macro_rules! foo {"]
#[doc = r" () => {};"]
#[doc =
r" ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" foo!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" There are quite a few different ways a [`macro_rules`] macro can be"]
#[doc =
r" improperly defined. Many of these errors were previously only detected"]
#[doc =
r" when the macro was expanded or not at all. This lint is an attempt to"]
#[doc = r" catch some of these problems when the macro is *defined*."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it may have false positives"#]
#[doc = r" and other issues. See [issue #61053] for more details."]
#[doc = r""]
#[doc =
r" [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html"]
#[doc = r" [issue #61053]: https://github.com/rust-lang/rust/issues/61053"]
pub static META_VARIABLE_MISUSE: &crate::Lint =
&crate::Lint {
name: "META_VARIABLE_MISUSE",
default_level: crate::Allow,
desc: "possible meta-variable misuse at macro definition",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
276/// The `meta_variable_misuse` lint detects possible meta-variable misuse
277 /// in macro definitions.
278 ///
279 /// ### Example
280 ///
281 /// ```rust,compile_fail
282 /// #![deny(meta_variable_misuse)]
283 ///
284 /// macro_rules! foo {
285 /// () => {};
286 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
287 /// }
288 ///
289 /// fn main() {
290 /// foo!();
291 /// }
292 /// ```
293 ///
294 /// {{produces}}
295 ///
296 /// ### Explanation
297 ///
298 /// There are quite a few different ways a [`macro_rules`] macro can be
299 /// improperly defined. Many of these errors were previously only detected
300 /// when the macro was expanded or not at all. This lint is an attempt to
301 /// catch some of these problems when the macro is *defined*.
302 ///
303 /// This lint is "allow" by default because it may have false positives
304 /// and other issues. See [issue #61053] for more details.
305 ///
306 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
307 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
308pub META_VARIABLE_MISUSE,
309 Allow,
310"possible meta-variable misuse at macro definition"
311}312313#[doc = r" The `incomplete_include` lint detects the use of the [`include!`]"]
#[doc = r" macro with a file that contains more than one expression."]
#[doc = r""]
#[doc = r" [`include!`]: https://doc.rust-lang.org/std/macro.include.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs separate file)"]
#[doc = r" fn main() {"]
#[doc = r#" include!("foo.txt");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" where the file `foo.txt` contains:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r#" println!("hi!");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: include macro expected single expression in source"]
#[doc = r" --> foo.txt:1:14"]
#[doc = r" |"]
#[doc = r#" 1 | println!("1");"#]
#[doc = r" | ^"]
#[doc = r" |"]
#[doc = r" = note: `#[deny(incomplete_include)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The [`include!`] macro is currently only intended to be used to"]
#[doc =
r" include a single [expression] or multiple [items]. Historically it"]
#[doc =
r" would ignore any contents after the first expression, but that can be"]
#[doc =
r" confusing. In the example above, the `println!` expression ends just"]
#[doc =
r#" before the semicolon, making the semicolon "extra" information that is"#]
#[doc = r" ignored. Perhaps even more surprising, if the included file had"]
#[doc = r" multiple print statements, the subsequent ones would be ignored!"]
#[doc = r""]
#[doc =
r" One workaround is to place the contents in braces to create a [block"]
#[doc = r" expression]. Also consider alternatives, like using functions to"]
#[doc = r" encapsulate the expressions, or use [proc-macros]."]
#[doc = r""]
#[doc =
r" This is a lint instead of a hard error because existing projects were"]
#[doc =
r" found to hit this error. To be cautious, it is a lint for now. The"]
#[doc = r" future semantics of the `include!` macro are also uncertain, see"]
#[doc = r" [issue #35560]."]
#[doc = r""]
#[doc = r" [items]: https://doc.rust-lang.org/reference/items.html"]
#[doc =
r" [expression]: https://doc.rust-lang.org/reference/expressions.html"]
#[doc =
r" [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html"]
#[doc =
r" [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html"]
#[doc = r" [issue #35560]: https://github.com/rust-lang/rust/issues/35560"]
pub static INCOMPLETE_INCLUDE: &crate::Lint =
&crate::Lint {
name: "INCOMPLETE_INCLUDE",
default_level: crate::Deny,
desc: "trailing content in included file",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
314/// The `incomplete_include` lint detects the use of the [`include!`]
315 /// macro with a file that contains more than one expression.
316 ///
317 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
318 ///
319 /// ### Example
320 ///
321 /// ```rust,ignore (needs separate file)
322 /// fn main() {
323 /// include!("foo.txt");
324 /// }
325 /// ```
326 ///
327 /// where the file `foo.txt` contains:
328 ///
329 /// ```text
330 /// println!("hi!");
331 /// ```
332 ///
333 /// produces:
334 ///
335 /// ```text
336 /// error: include macro expected single expression in source
337 /// --> foo.txt:1:14
338 /// |
339 /// 1 | println!("1");
340 /// | ^
341 /// |
342 /// = note: `#[deny(incomplete_include)]` on by default
343 /// ```
344 ///
345 /// ### Explanation
346 ///
347 /// The [`include!`] macro is currently only intended to be used to
348 /// include a single [expression] or multiple [items]. Historically it
349 /// would ignore any contents after the first expression, but that can be
350 /// confusing. In the example above, the `println!` expression ends just
351 /// before the semicolon, making the semicolon "extra" information that is
352 /// ignored. Perhaps even more surprising, if the included file had
353 /// multiple print statements, the subsequent ones would be ignored!
354 ///
355 /// One workaround is to place the contents in braces to create a [block
356 /// expression]. Also consider alternatives, like using functions to
357 /// encapsulate the expressions, or use [proc-macros].
358 ///
359 /// This is a lint instead of a hard error because existing projects were
360 /// found to hit this error. To be cautious, it is a lint for now. The
361 /// future semantics of the `include!` macro are also uncertain, see
362 /// [issue #35560].
363 ///
364 /// [items]: https://doc.rust-lang.org/reference/items.html
365 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
366 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
367 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
368 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
369pub INCOMPLETE_INCLUDE,
370 Deny,
371"trailing content in included file"
372}373374#[doc =
r" The `arithmetic_overflow` lint detects that an arithmetic operation"]
#[doc = r" will [overflow]."]
#[doc = r""]
#[doc =
r" [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" 1_i32 << 32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is very likely a mistake to perform an arithmetic operation that"]
#[doc =
r" overflows its value. If the compiler is able to detect these kinds of"]
#[doc = r" overflows at compile-time, it will trigger this lint. Consider"]
#[doc =
r" adjusting the expression to avoid overflow, or use a data type that"]
#[doc = r" will not overflow."]
pub static ARITHMETIC_OVERFLOW: &crate::Lint =
&crate::Lint {
name: "ARITHMETIC_OVERFLOW",
default_level: crate::Deny,
desc: "arithmetic operation overflows",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
375/// The `arithmetic_overflow` lint detects that an arithmetic operation
376 /// will [overflow].
377 ///
378 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
379 ///
380 /// ### Example
381 ///
382 /// ```rust,compile_fail
383 /// 1_i32 << 32;
384 /// ```
385 ///
386 /// {{produces}}
387 ///
388 /// ### Explanation
389 ///
390 /// It is very likely a mistake to perform an arithmetic operation that
391 /// overflows its value. If the compiler is able to detect these kinds of
392 /// overflows at compile-time, it will trigger this lint. Consider
393 /// adjusting the expression to avoid overflow, or use a data type that
394 /// will not overflow.
395pub ARITHMETIC_OVERFLOW,
396 Deny,
397"arithmetic operation overflows",
398 @eval_always = true
399}400401#[doc =
r" The `unconditional_panic` lint detects an operation that will cause a"]
#[doc = r" panic at runtime."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" let x = 1 / 0;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint detects code that is very likely incorrect because it will"]
#[doc = r" always panic, such as division by zero and out-of-bounds array"]
#[doc =
r" accesses. Consider adjusting your code if this is a bug, or using the"]
#[doc =
r" `panic!` or `unreachable!` macro instead in case the panic is intended."]
pub static UNCONDITIONAL_PANIC: &crate::Lint =
&crate::Lint {
name: "UNCONDITIONAL_PANIC",
default_level: crate::Deny,
desc: "operation will cause a panic at runtime",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
402/// The `unconditional_panic` lint detects an operation that will cause a
403 /// panic at runtime.
404 ///
405 /// ### Example
406 ///
407 /// ```rust,compile_fail
408 /// # #![allow(unused)]
409 /// let x = 1 / 0;
410 /// ```
411 ///
412 /// {{produces}}
413 ///
414 /// ### Explanation
415 ///
416 /// This lint detects code that is very likely incorrect because it will
417 /// always panic, such as division by zero and out-of-bounds array
418 /// accesses. Consider adjusting your code if this is a bug, or using the
419 /// `panic!` or `unreachable!` macro instead in case the panic is intended.
420pub UNCONDITIONAL_PANIC,
421 Deny,
422"operation will cause a panic at runtime",
423 @eval_always = true
424}425426#[doc = r" The `unused_imports` lint detects imports that are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" use std::collections::HashMap;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused imports may signal a mistake or unfinished code, and clutter"]
#[doc =
r" the code, and should be removed. If you intended to re-export the item"]
#[doc =
r" to make it available outside of the module, add a visibility modifier"]
#[doc = r" like `pub`."]
pub static UNUSED_IMPORTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_IMPORTS",
default_level: crate::Warn,
desc: "imports that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
427/// The `unused_imports` lint detects imports that are never used.
428 ///
429 /// ### Example
430 ///
431 /// ```rust
432 /// use std::collections::HashMap;
433 /// ```
434 ///
435 /// {{produces}}
436 ///
437 /// ### Explanation
438 ///
439 /// Unused imports may signal a mistake or unfinished code, and clutter
440 /// the code, and should be removed. If you intended to re-export the item
441 /// to make it available outside of the module, add a visibility modifier
442 /// like `pub`.
443pub UNUSED_IMPORTS,
444 Warn,
445"imports that are never used"
446}447448#[doc =
r" The `redundant_imports` lint detects imports that are redundant due to being"]
#[doc =
r" imported already; either through a previous import, or being present in"]
#[doc = r" the prelude."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(redundant_imports)]"]
#[doc = r" use std::option::Option::None;"]
#[doc = r" fn foo() -> Option<i32> { None }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Redundant imports are unnecessary and can be removed to simplify code."]
#[doc =
r" If you intended to re-export the item to make it available outside of the"]
#[doc = r" module, add a visibility modifier like `pub`."]
pub static REDUNDANT_IMPORTS: &crate::Lint =
&crate::Lint {
name: "REDUNDANT_IMPORTS",
default_level: crate::Allow,
desc: "imports that are redundant due to being imported already",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
449/// The `redundant_imports` lint detects imports that are redundant due to being
450 /// imported already; either through a previous import, or being present in
451 /// the prelude.
452 ///
453 /// ### Example
454 ///
455 /// ```rust,compile_fail
456 /// #![deny(redundant_imports)]
457 /// use std::option::Option::None;
458 /// fn foo() -> Option<i32> { None }
459 /// ```
460 ///
461 /// {{produces}}
462 ///
463 /// ### Explanation
464 ///
465 /// Redundant imports are unnecessary and can be removed to simplify code.
466 /// If you intended to re-export the item to make it available outside of the
467 /// module, add a visibility modifier like `pub`.
468pub REDUNDANT_IMPORTS,
469 Allow,
470"imports that are redundant due to being imported already"
471}472473#[doc =
r" The `must_not_suspend` lint guards against values that shouldn't be held across suspend points"]
#[doc = r" (`.await`)"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(must_not_suspend)]"]
#[doc = r" #![warn(must_not_suspend)]"]
#[doc = r""]
#[doc = r" #[must_not_suspend]"]
#[doc = r" struct SyncThing {}"]
#[doc = r""]
#[doc = r" async fn yield_now() {}"]
#[doc = r""]
#[doc = r" pub async fn uhoh() {"]
#[doc = r" let guard = SyncThing {};"]
#[doc = r" yield_now().await;"]
#[doc = r" let _guard = guard;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`"]
#[doc =
r#" attribute being held across suspend points. A "suspend" point is usually a `.await` in an async"#]
#[doc = r" function."]
#[doc = r""]
#[doc =
r" This attribute can be used to mark values that are semantically incorrect across suspends"]
#[doc =
r" (like certain types of timers), values that have async alternatives, and values that"]
#[doc =
r" regularly cause problems with the `Send`-ness of async fn's returned futures (like"]
#[doc = r" `MutexGuard`'s)"]
#[doc = r""]
pub static MUST_NOT_SUSPEND: &crate::Lint =
&crate::Lint {
name: "MUST_NOT_SUSPEND",
default_level: crate::Allow,
desc: "use of a `#[must_not_suspend]` value across a yield point",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::must_not_suspend),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
474/// The `must_not_suspend` lint guards against values that shouldn't be held across suspend points
475 /// (`.await`)
476 ///
477 /// ### Example
478 ///
479 /// ```rust
480 /// #![feature(must_not_suspend)]
481 /// #![warn(must_not_suspend)]
482 ///
483 /// #[must_not_suspend]
484 /// struct SyncThing {}
485 ///
486 /// async fn yield_now() {}
487 ///
488 /// pub async fn uhoh() {
489 /// let guard = SyncThing {};
490 /// yield_now().await;
491 /// let _guard = guard;
492 /// }
493 /// ```
494 ///
495 /// {{produces}}
496 ///
497 /// ### Explanation
498 ///
499 /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
500 /// attribute being held across suspend points. A "suspend" point is usually a `.await` in an async
501 /// function.
502 ///
503 /// This attribute can be used to mark values that are semantically incorrect across suspends
504 /// (like certain types of timers), values that have async alternatives, and values that
505 /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
506 /// `MutexGuard`'s)
507 ///
508pub MUST_NOT_SUSPEND,
509 Allow,
510"use of a `#[must_not_suspend]` value across a yield point",
511 @feature_gate = must_not_suspend;
512}513514#[doc =
r" The `unused_extern_crates` lint guards against `extern crate` items"]
#[doc = r" that are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unused_extern_crates)]"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" extern crate proc_macro;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" `extern crate` items that are unused have no effect and should be"]
#[doc =
r" removed. Note that there are some cases where specifying an `extern"]
#[doc =
r" crate` is desired for the side effect of ensuring the given crate is"]
#[doc =
r" linked, even though it is not otherwise directly referenced. The lint"]
#[doc = r" can be silenced by aliasing the crate to an underscore, such as"]
#[doc =
r" `extern crate foo as _`. Also note that it is no longer idiomatic to"]
#[doc =
r" use `extern crate` in the [2018 edition], as extern crates are now"]
#[doc = r" automatically added in scope."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it can be noisy, and produce"#]
#[doc =
r" false-positives. If a dependency is being removed from a project, it"]
#[doc = r" is recommended to remove it from the build configuration (such as"]
#[doc = r" `Cargo.toml`) to ensure stale build entries aren't left behind."]
#[doc = r""]
#[doc =
r" [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate"]
pub static UNUSED_EXTERN_CRATES: &crate::Lint =
&crate::Lint {
name: "UNUSED_EXTERN_CRATES",
default_level: crate::Allow,
desc: "extern crates that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
515/// The `unused_extern_crates` lint guards against `extern crate` items
516 /// that are never used.
517 ///
518 /// ### Example
519 ///
520 /// ```rust,compile_fail
521 /// #![deny(unused_extern_crates)]
522 /// #![deny(warnings)]
523 /// extern crate proc_macro;
524 /// ```
525 ///
526 /// {{produces}}
527 ///
528 /// ### Explanation
529 ///
530 /// `extern crate` items that are unused have no effect and should be
531 /// removed. Note that there are some cases where specifying an `extern
532 /// crate` is desired for the side effect of ensuring the given crate is
533 /// linked, even though it is not otherwise directly referenced. The lint
534 /// can be silenced by aliasing the crate to an underscore, such as
535 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
536 /// use `extern crate` in the [2018 edition], as extern crates are now
537 /// automatically added in scope.
538 ///
539 /// This lint is "allow" by default because it can be noisy, and produce
540 /// false-positives. If a dependency is being removed from a project, it
541 /// is recommended to remove it from the build configuration (such as
542 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
543 ///
544 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
545pub UNUSED_EXTERN_CRATES,
546 Allow,
547"extern crates that are never used"
548}549550#[doc =
r" The `unused_crate_dependencies` lint detects crate dependencies that"]
#[doc = r" are never used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #![deny(unused_crate_dependencies)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: extern crate `regex` is unused in crate `lint_example`"]
#[doc = r" |"]
#[doc =
r" = help: remove the dependency or add `use regex as _;` to the crate root"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> src/lib.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![deny(unused_crate_dependencies)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" After removing the code that uses a dependency, this usually also"]
#[doc = r" requires removing the dependency from the build configuration."]
#[doc =
r" However, sometimes that step can be missed, which leads to time wasted"]
#[doc = r" building dependencies that are no longer used. This lint can be"]
#[doc =
r" enabled to detect dependencies that are never used (more specifically,"]
#[doc =
r" any dependency passed with the `--extern` command-line flag that is"]
#[doc =
r" never referenced via [`use`], [`extern crate`], or in any [path])."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it can provide false positives"#]
#[doc =
r" depending on how the build system is configured. For example, when"]
#[doc = r#" using Cargo, a "package" consists of multiple crates (such as a"#]
#[doc = r" library and a binary), but the dependencies are defined for the"]
#[doc =
r" package as a whole. If there is a dependency that is only used in the"]
#[doc =
r" binary, but not the library, then the lint will be incorrectly issued"]
#[doc = r" in the library."]
#[doc = r""]
#[doc = r" [path]: https://doc.rust-lang.org/reference/paths.html"]
#[doc =
r" [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html"]
#[doc =
r" [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html"]
pub static UNUSED_CRATE_DEPENDENCIES: &crate::Lint =
&crate::Lint {
name: "UNUSED_CRATE_DEPENDENCIES",
default_level: crate::Allow,
desc: "crate dependencies that are never used",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
551/// The `unused_crate_dependencies` lint detects crate dependencies that
552 /// are never used.
553 ///
554 /// ### Example
555 ///
556 /// ```rust,ignore (needs extern crate)
557 /// #![deny(unused_crate_dependencies)]
558 /// ```
559 ///
560 /// This will produce:
561 ///
562 /// ```text
563 /// error: extern crate `regex` is unused in crate `lint_example`
564 /// |
565 /// = help: remove the dependency or add `use regex as _;` to the crate root
566 /// note: the lint level is defined here
567 /// --> src/lib.rs:1:9
568 /// |
569 /// 1 | #![deny(unused_crate_dependencies)]
570 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
571 /// ```
572 ///
573 /// ### Explanation
574 ///
575 /// After removing the code that uses a dependency, this usually also
576 /// requires removing the dependency from the build configuration.
577 /// However, sometimes that step can be missed, which leads to time wasted
578 /// building dependencies that are no longer used. This lint can be
579 /// enabled to detect dependencies that are never used (more specifically,
580 /// any dependency passed with the `--extern` command-line flag that is
581 /// never referenced via [`use`], [`extern crate`], or in any [path]).
582 ///
583 /// This lint is "allow" by default because it can provide false positives
584 /// depending on how the build system is configured. For example, when
585 /// using Cargo, a "package" consists of multiple crates (such as a
586 /// library and a binary), but the dependencies are defined for the
587 /// package as a whole. If there is a dependency that is only used in the
588 /// binary, but not the library, then the lint will be incorrectly issued
589 /// in the library.
590 ///
591 /// [path]: https://doc.rust-lang.org/reference/paths.html
592 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
593 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
594pub UNUSED_CRATE_DEPENDENCIES,
595 Allow,
596"crate dependencies that are never used",
597 crate_level_only
598}599600#[doc = r" The `unused_qualifications` lint detects unnecessarily qualified"]
#[doc = r" names."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unused_qualifications)]"]
#[doc = r" mod foo {"]
#[doc = r" pub fn bar() {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" use foo::bar;"]
#[doc = r" foo::bar();"]
#[doc = r" bar();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" If an item from another module is already brought into scope, then"]
#[doc = r" there is no need to qualify it in this case. You can call `bar()`"]
#[doc = r" directly, without the `foo::`."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it is somewhat pedantic, and"#]
#[doc =
r" doesn't indicate an actual problem, but rather a stylistic choice, and"]
#[doc = r" can be noisy when refactoring or moving around code."]
pub static UNUSED_QUALIFICATIONS: &crate::Lint =
&crate::Lint {
name: "UNUSED_QUALIFICATIONS",
default_level: crate::Allow,
desc: "detects unnecessarily qualified names",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
601/// The `unused_qualifications` lint detects unnecessarily qualified
602 /// names.
603 ///
604 /// ### Example
605 ///
606 /// ```rust,compile_fail
607 /// #![deny(unused_qualifications)]
608 /// mod foo {
609 /// pub fn bar() {}
610 /// }
611 ///
612 /// fn main() {
613 /// use foo::bar;
614 /// foo::bar();
615 /// bar();
616 /// }
617 /// ```
618 ///
619 /// {{produces}}
620 ///
621 /// ### Explanation
622 ///
623 /// If an item from another module is already brought into scope, then
624 /// there is no need to qualify it in this case. You can call `bar()`
625 /// directly, without the `foo::`.
626 ///
627 /// This lint is "allow" by default because it is somewhat pedantic, and
628 /// doesn't indicate an actual problem, but rather a stylistic choice, and
629 /// can be noisy when refactoring or moving around code.
630pub UNUSED_QUALIFICATIONS,
631 Allow,
632"detects unnecessarily qualified names"
633}634635#[doc = r" The `unknown_lints` lint detects unrecognized lint attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![allow(not_a_real_lint)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a lint that does not exist. Check"]
#[doc =
r" the spelling, and check the lint listing for the correct name. Also"]
#[doc =
r" consider if you are using an old version of the compiler, and the lint"]
#[doc = r" is only available in a newer version."]
pub static UNKNOWN_LINTS: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_LINTS",
default_level: crate::Warn,
desc: "unrecognized lint attribute",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
636/// The `unknown_lints` lint detects unrecognized lint attributes.
637 ///
638 /// ### Example
639 ///
640 /// ```rust
641 /// #![allow(not_a_real_lint)]
642 /// ```
643 ///
644 /// {{produces}}
645 ///
646 /// ### Explanation
647 ///
648 /// It is usually a mistake to specify a lint that does not exist. Check
649 /// the spelling, and check the lint listing for the correct name. Also
650 /// consider if you are using an old version of the compiler, and the lint
651 /// is only available in a newer version.
652pub UNKNOWN_LINTS,
653 Warn,
654"unrecognized lint attribute",
655 @eval_always = true
656}657658#[doc =
r" The `unfulfilled_lint_expectations` lint detects when a lint expectation is"]
#[doc = r" unfulfilled."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[expect(unused_variables)]"]
#[doc = r" let x = 10;"]
#[doc = r#" println!("{}", x);"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `#[expect]` attribute can be used to create a lint expectation. The"]
#[doc =
r" expectation is fulfilled, if a `#[warn]` attribute at the same location"]
#[doc =
r" would result in a lint emission. If the expectation is unfulfilled,"]
#[doc =
r" because no lint was emitted, this lint will be emitted on the attribute."]
#[doc = r""]
pub static UNFULFILLED_LINT_EXPECTATIONS: &crate::Lint =
&crate::Lint {
name: "UNFULFILLED_LINT_EXPECTATIONS",
default_level: crate::Warn,
desc: "unfulfilled lint expectation",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
659/// The `unfulfilled_lint_expectations` lint detects when a lint expectation is
660 /// unfulfilled.
661 ///
662 /// ### Example
663 ///
664 /// ```rust
665 /// #[expect(unused_variables)]
666 /// let x = 10;
667 /// println!("{}", x);
668 /// ```
669 ///
670 /// {{produces}}
671 ///
672 /// ### Explanation
673 ///
674 /// The `#[expect]` attribute can be used to create a lint expectation. The
675 /// expectation is fulfilled, if a `#[warn]` attribute at the same location
676 /// would result in a lint emission. If the expectation is unfulfilled,
677 /// because no lint was emitted, this lint will be emitted on the attribute.
678 ///
679pub UNFULFILLED_LINT_EXPECTATIONS,
680 Warn,
681"unfulfilled lint expectation"
682}683684#[doc =
r" The `unused_variables` lint detects variables which are not used in"]
#[doc = r" any way."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused variables may signal a mistake or unfinished code. To silence"]
#[doc =
r" the warning for the individual variable, prefix it with an underscore"]
#[doc = r" such as `_x`."]
pub static UNUSED_VARIABLES: &crate::Lint =
&crate::Lint {
name: "UNUSED_VARIABLES",
default_level: crate::Warn,
desc: "detect variables which are not used in any way",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
685/// The `unused_variables` lint detects variables which are not used in
686 /// any way.
687 ///
688 /// ### Example
689 ///
690 /// ```rust
691 /// let x = 5;
692 /// ```
693 ///
694 /// {{produces}}
695 ///
696 /// ### Explanation
697 ///
698 /// Unused variables may signal a mistake or unfinished code. To silence
699 /// the warning for the individual variable, prefix it with an underscore
700 /// such as `_x`.
701pub UNUSED_VARIABLES,
702 Warn,
703"detect variables which are not used in any way"
704}705706#[doc =
r" The `unused_visibilities` lint detects visibility qualifiers (like `pub`)"]
#[doc = r" on a `const _` item."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" pub const _: () = {};"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" These qualifiers have no effect, as `const _` items are unnameable."]
pub static UNUSED_VISIBILITIES: &crate::Lint =
&crate::Lint {
name: "UNUSED_VISIBILITIES",
default_level: crate::Warn,
desc: "detect visibility qualifiers on `const _` items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
707/// The `unused_visibilities` lint detects visibility qualifiers (like `pub`)
708 /// on a `const _` item.
709 ///
710 /// ### Example
711 ///
712 /// ```rust
713 /// pub const _: () = {};
714 /// ```
715 ///
716 /// {{produces}}
717 ///
718 /// ### Explanation
719 ///
720 /// These qualifiers have no effect, as `const _` items are unnameable.
721pub UNUSED_VISIBILITIES,
722 Warn,
723"detect visibility qualifiers on `const _` items"
724}725726#[doc =
r" The `unused_assignments` lint detects assignments that will never be read."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let mut x = 5;"]
#[doc = r" x = 6;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused assignments may signal a mistake or unfinished code. If the"]
#[doc =
r" variable is never used after being assigned, then the assignment can"]
#[doc =
r" be removed. Variables with an underscore prefix such as `_x` will not"]
#[doc = r" trigger this lint."]
pub static UNUSED_ASSIGNMENTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_ASSIGNMENTS",
default_level: crate::Warn,
desc: "detect assignments that will never be read",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
727/// The `unused_assignments` lint detects assignments that will never be read.
728 ///
729 /// ### Example
730 ///
731 /// ```rust
732 /// let mut x = 5;
733 /// x = 6;
734 /// ```
735 ///
736 /// {{produces}}
737 ///
738 /// ### Explanation
739 ///
740 /// Unused assignments may signal a mistake or unfinished code. If the
741 /// variable is never used after being assigned, then the assignment can
742 /// be removed. Variables with an underscore prefix such as `_x` will not
743 /// trigger this lint.
744pub UNUSED_ASSIGNMENTS,
745 Warn,
746"detect assignments that will never be read"
747}748749#[doc = r" The `dead_code` lint detects unused, unexported items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Dead code may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for individual items, prefix the name with an underscore such"]
#[doc =
r" as `_foo`. If it was intended to expose the item outside of the crate,"]
#[doc = r" consider adding a visibility modifier like `pub`."]
#[doc = r""]
#[doc = r" To preserve the numbering of tuple structs with unused fields,"]
#[doc = r" change the unused fields to have unit type or use"]
#[doc = r" `PhantomData`."]
#[doc = r""]
#[doc = r" Otherwise consider removing the unused code."]
#[doc = r""]
#[doc = r" ### Limitations"]
#[doc = r""]
#[doc = r" Removing fields that are only used for side-effects and never"]
#[doc = r" read will result in behavioral changes. Examples of this"]
#[doc = r" include:"]
#[doc = r""]
#[doc = r" - If a field's value performs an action when it is dropped."]
#[doc = r" - If a field's type does not implement an auto trait"]
#[doc = r" (e.g. `Send`, `Sync`, `Unpin`)."]
#[doc = r""]
#[doc = r" For side-effects from dropping field values, this lint should"]
#[doc = r" be allowed on those fields. For side-effects from containing"]
#[doc = r" field types, `PhantomData` should be used."]
pub static DEAD_CODE: &crate::Lint =
&crate::Lint {
name: "DEAD_CODE",
default_level: crate::Warn,
desc: "detect unused, unexported items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
750/// The `dead_code` lint detects unused, unexported items.
751 ///
752 /// ### Example
753 ///
754 /// ```rust
755 /// fn foo() {}
756 /// ```
757 ///
758 /// {{produces}}
759 ///
760 /// ### Explanation
761 ///
762 /// Dead code may signal a mistake or unfinished code. To silence the
763 /// warning for individual items, prefix the name with an underscore such
764 /// as `_foo`. If it was intended to expose the item outside of the crate,
765 /// consider adding a visibility modifier like `pub`.
766 ///
767 /// To preserve the numbering of tuple structs with unused fields,
768 /// change the unused fields to have unit type or use
769 /// `PhantomData`.
770 ///
771 /// Otherwise consider removing the unused code.
772 ///
773 /// ### Limitations
774 ///
775 /// Removing fields that are only used for side-effects and never
776 /// read will result in behavioral changes. Examples of this
777 /// include:
778 ///
779 /// - If a field's value performs an action when it is dropped.
780 /// - If a field's type does not implement an auto trait
781 /// (e.g. `Send`, `Sync`, `Unpin`).
782 ///
783 /// For side-effects from dropping field values, this lint should
784 /// be allowed on those fields. For side-effects from containing
785 /// field types, `PhantomData` should be used.
786pub DEAD_CODE,
787 Warn,
788"detect unused, unexported items"
789}790791#[doc = r" The `dead_code_pub_in_binary` lint detects unused `pub` items in"]
#[doc = r" executable crates."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(dead_code_pub_in_binary)]"]
#[doc = r""]
#[doc = r" pub fn unused_pub_fn() {}"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In executable crates, `pub` items are often implementation details"]
#[doc =
r" rather than part of an external API. This lint helps find those items"]
#[doc = r" when they are never used."]
#[doc = r""]
#[doc =
r" This lint only applies to executable crates. In library crates, public"]
#[doc =
r" items are considered part of the crate's API and are not reported by"]
#[doc = r" this lint."]
pub static DEAD_CODE_PUB_IN_BINARY: &crate::Lint =
&crate::Lint {
name: "DEAD_CODE_PUB_IN_BINARY",
default_level: crate::Allow,
desc: "detect public items in executable crates that are never used",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
792/// The `dead_code_pub_in_binary` lint detects unused `pub` items in
793 /// executable crates.
794 ///
795 /// ### Example
796 ///
797 /// ```rust
798 /// #![deny(dead_code_pub_in_binary)]
799 ///
800 /// pub fn unused_pub_fn() {}
801 ///
802 /// fn main() {}
803 /// ```
804 ///
805 /// {{produces}}
806 ///
807 /// ### Explanation
808 ///
809 /// In executable crates, `pub` items are often implementation details
810 /// rather than part of an external API. This lint helps find those items
811 /// when they are never used.
812 ///
813 /// This lint only applies to executable crates. In library crates, public
814 /// items are considered part of the crate's API and are not reported by
815 /// this lint.
816pub DEAD_CODE_PUB_IN_BINARY,
817 Allow,
818"detect public items in executable crates that are never used",
819 crate_level_only
820}821822#[doc =
r" The `unused_attributes` lint detects attributes that were not used by"]
#[doc = r" the compiler."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![ignore]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused [attributes] may indicate the attribute is placed in the wrong"]
#[doc =
r" position. Consider removing it, or placing it in the correct position."]
#[doc =
r" Also consider if you intended to use an _inner attribute_ (with a `!`"]
#[doc =
r" such as `#![allow(unused)]`) which applies to the item the attribute"]
#[doc = r" is within, or an _outer attribute_ (without a `!` such as"]
#[doc = r" `#[allow(unused)]`) which applies to the item *following* the"]
#[doc = r" attribute."]
#[doc = r""]
#[doc = r" [attributes]: https://doc.rust-lang.org/reference/attributes.html"]
pub static UNUSED_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "UNUSED_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects attributes that were not used by the compiler",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
823/// The `unused_attributes` lint detects attributes that were not used by
824 /// the compiler.
825 ///
826 /// ### Example
827 ///
828 /// ```rust
829 /// #![ignore]
830 /// ```
831 ///
832 /// {{produces}}
833 ///
834 /// ### Explanation
835 ///
836 /// Unused [attributes] may indicate the attribute is placed in the wrong
837 /// position. Consider removing it, or placing it in the correct position.
838 /// Also consider if you intended to use an _inner attribute_ (with a `!`
839 /// such as `#![allow(unused)]`) which applies to the item the attribute
840 /// is within, or an _outer attribute_ (without a `!` such as
841 /// `#[allow(unused)]`) which applies to the item *following* the
842 /// attribute.
843 ///
844 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
845pub UNUSED_ATTRIBUTES,
846 Warn,
847"detects attributes that were not used by the compiler"
848}849850#[doc = r" The `unreachable_code` lint detects unreachable code paths."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r#" panic!("we never go past here!");"#]
#[doc = r""]
#[doc = r" let x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unreachable code may signal a mistake or unfinished code. If the code"]
#[doc = r" is no longer in use, consider removing it."]
pub static UNREACHABLE_CODE: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_CODE",
default_level: crate::Warn,
desc: "detects unreachable code paths",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
851/// The `unreachable_code` lint detects unreachable code paths.
852 ///
853 /// ### Example
854 ///
855 /// ```rust,no_run
856 /// panic!("we never go past here!");
857 ///
858 /// let x = 5;
859 /// ```
860 ///
861 /// {{produces}}
862 ///
863 /// ### Explanation
864 ///
865 /// Unreachable code may signal a mistake or unfinished code. If the code
866 /// is no longer in use, consider removing it.
867pub UNREACHABLE_CODE,
868 Warn,
869"detects unreachable code paths",
870 report_in_external_macro
871}872873#[doc = r" The `unreachable_patterns` lint detects unreachable patterns."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 5;"]
#[doc = r" match x {"]
#[doc = r" y => (),"]
#[doc = r" 5 => (),"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This usually indicates a mistake in how the patterns are specified or"]
#[doc =
r" ordered. In this example, the `y` pattern will always match, so the"]
#[doc =
r" five is impossible to reach. Remember, match arms match in order, you"]
#[doc = r" probably wanted to put the `5` case above the `y` case."]
pub static UNREACHABLE_PATTERNS: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_PATTERNS",
default_level: crate::Warn,
desc: "detects unreachable patterns",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
874/// The `unreachable_patterns` lint detects unreachable patterns.
875 ///
876 /// ### Example
877 ///
878 /// ```rust
879 /// let x = 5;
880 /// match x {
881 /// y => (),
882 /// 5 => (),
883 /// }
884 /// ```
885 ///
886 /// {{produces}}
887 ///
888 /// ### Explanation
889 ///
890 /// This usually indicates a mistake in how the patterns are specified or
891 /// ordered. In this example, the `y` pattern will always match, so the
892 /// five is impossible to reach. Remember, match arms match in order, you
893 /// probably wanted to put the `5` case above the `y` case.
894pub UNREACHABLE_PATTERNS,
895 Warn,
896"detects unreachable patterns"
897}898899#[doc =
r" The `unreachable_cfg_select_predicates` lint detects unreachable configuration"]
#[doc = r" predicates in the `cfg_select!` macro."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" cfg_select! {"]
#[doc = r" _ => (),"]
#[doc = r" windows => (),"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This usually indicates a mistake in how the predicates are specified or"]
#[doc =
r" ordered. In this example, the `_` predicate will always match, so the"]
#[doc =
r" `windows` is impossible to reach. Remember, arms match in order, you"]
#[doc = r" probably wanted to put the `windows` case above the `_` case."]
pub static UNREACHABLE_CFG_SELECT_PREDICATES: &crate::Lint =
&crate::Lint {
name: "UNREACHABLE_CFG_SELECT_PREDICATES",
default_level: crate::Warn,
desc: "detects unreachable configuration predicates in the cfg_select macro",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
900/// The `unreachable_cfg_select_predicates` lint detects unreachable configuration
901 /// predicates in the `cfg_select!` macro.
902 ///
903 /// ### Example
904 ///
905 /// ```rust
906 /// cfg_select! {
907 /// _ => (),
908 /// windows => (),
909 /// }
910 /// ```
911 ///
912 /// {{produces}}
913 ///
914 /// ### Explanation
915 ///
916 /// This usually indicates a mistake in how the predicates are specified or
917 /// ordered. In this example, the `_` predicate will always match, so the
918 /// `windows` is impossible to reach. Remember, arms match in order, you
919 /// probably wanted to put the `windows` case above the `_` case.
920pub UNREACHABLE_CFG_SELECT_PREDICATES,
921 Warn,
922"detects unreachable configuration predicates in the cfg_select macro",
923}924925#[doc =
r" The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that"]
#[doc = r" overlap on their endpoints."]
#[doc = r""]
#[doc =
r" [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 123u8;"]
#[doc = r" match x {"]
#[doc = r#" 0..=100 => { println!("small"); }"#]
#[doc = r#" 100..=255 => { println!("large"); }"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is likely a mistake to have range patterns in a match expression that overlap in this"]
#[doc =
r" way. Check that the beginning and end values are what you expect, and keep in mind that"]
#[doc = r" with `..=` the left and right bounds are inclusive."]
pub static OVERLAPPING_RANGE_ENDPOINTS: &crate::Lint =
&crate::Lint {
name: "OVERLAPPING_RANGE_ENDPOINTS",
default_level: crate::Warn,
desc: "detects range patterns with overlapping endpoints",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
926/// The `overlapping_range_endpoints` lint detects `match` arms that have [range patterns] that
927 /// overlap on their endpoints.
928 ///
929 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
930 ///
931 /// ### Example
932 ///
933 /// ```rust
934 /// let x = 123u8;
935 /// match x {
936 /// 0..=100 => { println!("small"); }
937 /// 100..=255 => { println!("large"); }
938 /// }
939 /// ```
940 ///
941 /// {{produces}}
942 ///
943 /// ### Explanation
944 ///
945 /// It is likely a mistake to have range patterns in a match expression that overlap in this
946 /// way. Check that the beginning and end values are what you expect, and keep in mind that
947 /// with `..=` the left and right bounds are inclusive.
948pub OVERLAPPING_RANGE_ENDPOINTS,
949 Warn,
950"detects range patterns with overlapping endpoints"
951}952953#[doc =
r" The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using"]
#[doc = r" exclusive [range patterns]."]
#[doc = r""]
#[doc =
r" [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let x = 123u32;"]
#[doc = r" match x {"]
#[doc = r#" 0..100 => { println!("small"); }"#]
#[doc = r#" 101..1000 => { println!("large"); }"#]
#[doc = r#" _ => { println!("larger"); }"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is likely a mistake to have range patterns in a match expression that miss out a single"]
#[doc =
r" number. Check that the beginning and end values are what you expect, and keep in mind that"]
#[doc =
r" with `..=` the right bound is inclusive, and with `..` it is exclusive."]
pub static NON_CONTIGUOUS_RANGE_ENDPOINTS: &crate::Lint =
&crate::Lint {
name: "NON_CONTIGUOUS_RANGE_ENDPOINTS",
default_level: crate::Warn,
desc: "detects off-by-one errors with exclusive range patterns",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
954/// The `non_contiguous_range_endpoints` lint detects likely off-by-one errors when using
955 /// exclusive [range patterns].
956 ///
957 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
958 ///
959 /// ### Example
960 ///
961 /// ```rust
962 /// let x = 123u32;
963 /// match x {
964 /// 0..100 => { println!("small"); }
965 /// 101..1000 => { println!("large"); }
966 /// _ => { println!("larger"); }
967 /// }
968 /// ```
969 ///
970 /// {{produces}}
971 ///
972 /// ### Explanation
973 ///
974 /// It is likely a mistake to have range patterns in a match expression that miss out a single
975 /// number. Check that the beginning and end values are what you expect, and keep in mind that
976 /// with `..=` the right bound is inclusive, and with `..` it is exclusive.
977pub NON_CONTIGUOUS_RANGE_ENDPOINTS,
978 Warn,
979"detects off-by-one errors with exclusive range patterns"
980}981982#[doc =
r" The `bindings_with_variant_name` lint detects pattern bindings with"]
#[doc = r" the same name as one of the matched variants."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" pub enum Enum {"]
#[doc = r" Foo,"]
#[doc = r" Bar,"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub fn foo(x: Enum) {"]
#[doc = r" match x {"]
#[doc = r" Foo => {}"]
#[doc = r" Bar => {}"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" It is usually a mistake to specify an enum variant name as an"]
#[doc = r" [identifier pattern]. In the example above, the `match` arms are"]
#[doc =
r" specifying a variable name to bind the value of `x` to. The second arm"]
#[doc = r" is ignored because the first one matches *all* values. The likely"]
#[doc = r" intent is that the arm was intended to match on the enum variant."]
#[doc = r""]
#[doc = r" Two possible solutions are:"]
#[doc = r""]
#[doc = r" * Specify the enum variant using a [path pattern], such as"]
#[doc = r" `Enum::Foo`."]
#[doc = r" * Bring the enum variants into local scope, such as adding `use"]
#[doc = r" Enum::*;` to the beginning of the `foo` function in the example"]
#[doc = r" above."]
#[doc = r""]
#[doc =
r" [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns"]
#[doc =
r" [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns"]
pub static BINDINGS_WITH_VARIANT_NAME: &crate::Lint =
&crate::Lint {
name: "BINDINGS_WITH_VARIANT_NAME",
default_level: crate::Deny,
desc: "detects pattern bindings with the same name as one of the matched variants",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
983/// The `bindings_with_variant_name` lint detects pattern bindings with
984 /// the same name as one of the matched variants.
985 ///
986 /// ### Example
987 ///
988 /// ```rust,compile_fail
989 /// pub enum Enum {
990 /// Foo,
991 /// Bar,
992 /// }
993 ///
994 /// pub fn foo(x: Enum) {
995 /// match x {
996 /// Foo => {}
997 /// Bar => {}
998 /// }
999 /// }
1000 /// ```
1001 ///
1002 /// {{produces}}
1003 ///
1004 /// ### Explanation
1005 ///
1006 /// It is usually a mistake to specify an enum variant name as an
1007 /// [identifier pattern]. In the example above, the `match` arms are
1008 /// specifying a variable name to bind the value of `x` to. The second arm
1009 /// is ignored because the first one matches *all* values. The likely
1010 /// intent is that the arm was intended to match on the enum variant.
1011 ///
1012 /// Two possible solutions are:
1013 ///
1014 /// * Specify the enum variant using a [path pattern], such as
1015 /// `Enum::Foo`.
1016 /// * Bring the enum variants into local scope, such as adding `use
1017 /// Enum::*;` to the beginning of the `foo` function in the example
1018 /// above.
1019 ///
1020 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1021 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
1022pub BINDINGS_WITH_VARIANT_NAME,
1023 Deny,
1024"detects pattern bindings with the same name as one of the matched variants"
1025}10261027#[doc = r" The `unused_macros` lint detects macros that were not used."]
#[doc = r""]
#[doc =
r" Note that this lint is distinct from the `unused_macro_rules` lint,"]
#[doc =
r" which checks for single rules that never match of an otherwise used"]
#[doc = r" macro, and thus never expand."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" macro_rules! unused {"]
#[doc = r" () => {};"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused macros may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for the individual macro, prefix the name with an underscore"]
#[doc =
r" such as `_my_macro`. If you intended to export the macro to make it"]
#[doc =
r" available outside of the crate, use the [`macro_export` attribute]."]
#[doc = r""]
#[doc =
r" [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
pub static UNUSED_MACROS: &crate::Lint =
&crate::Lint {
name: "UNUSED_MACROS",
default_level: crate::Warn,
desc: "detects macros that were not used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1028/// The `unused_macros` lint detects macros that were not used.
1029 ///
1030 /// Note that this lint is distinct from the `unused_macro_rules` lint,
1031 /// which checks for single rules that never match of an otherwise used
1032 /// macro, and thus never expand.
1033 ///
1034 /// ### Example
1035 ///
1036 /// ```rust
1037 /// macro_rules! unused {
1038 /// () => {};
1039 /// }
1040 ///
1041 /// fn main() {
1042 /// }
1043 /// ```
1044 ///
1045 /// {{produces}}
1046 ///
1047 /// ### Explanation
1048 ///
1049 /// Unused macros may signal a mistake or unfinished code. To silence the
1050 /// warning for the individual macro, prefix the name with an underscore
1051 /// such as `_my_macro`. If you intended to export the macro to make it
1052 /// available outside of the crate, use the [`macro_export` attribute].
1053 ///
1054 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1055pub UNUSED_MACROS,
1056 Warn,
1057"detects macros that were not used"
1058}10591060#[doc =
r" The `unused_macro_rules` lint detects macro rules that were not used."]
#[doc = r""]
#[doc =
r" Note that the lint is distinct from the `unused_macros` lint, which"]
#[doc =
r" fires if the entire macro is never called, while this lint fires for"]
#[doc = r" single unused rules of the macro that is otherwise used."]
#[doc = r" `unused_macro_rules` fires only if `unused_macros` wouldn't fire."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[warn(unused_macro_rules)]"]
#[doc = r" macro_rules! unused_empty {"]
#[doc =
r#" (hello) => { println!("Hello, world!") }; // This rule is used"#]
#[doc = r#" () => { println!("empty") }; // This rule is unused"#]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" unused_empty!(hello);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused macro rules may signal a mistake or unfinished code. Furthermore,"]
#[doc =
r" they slow down compilation. Right now, silencing the warning is not"]
#[doc =
r" supported on a single rule level, so you have to add an allow to the"]
#[doc = r" entire macro definition."]
#[doc = r""]
#[doc = r" If you intended to export the macro to make it"]
#[doc =
r" available outside of the crate, use the [`macro_export` attribute]."]
#[doc = r""]
#[doc =
r" [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
pub static UNUSED_MACRO_RULES: &crate::Lint =
&crate::Lint {
name: "UNUSED_MACRO_RULES",
default_level: crate::Allow,
desc: "detects macro rules that were not used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1061/// The `unused_macro_rules` lint detects macro rules that were not used.
1062 ///
1063 /// Note that the lint is distinct from the `unused_macros` lint, which
1064 /// fires if the entire macro is never called, while this lint fires for
1065 /// single unused rules of the macro that is otherwise used.
1066 /// `unused_macro_rules` fires only if `unused_macros` wouldn't fire.
1067 ///
1068 /// ### Example
1069 ///
1070 /// ```rust
1071 /// #[warn(unused_macro_rules)]
1072 /// macro_rules! unused_empty {
1073 /// (hello) => { println!("Hello, world!") }; // This rule is used
1074 /// () => { println!("empty") }; // This rule is unused
1075 /// }
1076 ///
1077 /// fn main() {
1078 /// unused_empty!(hello);
1079 /// }
1080 /// ```
1081 ///
1082 /// {{produces}}
1083 ///
1084 /// ### Explanation
1085 ///
1086 /// Unused macro rules may signal a mistake or unfinished code. Furthermore,
1087 /// they slow down compilation. Right now, silencing the warning is not
1088 /// supported on a single rule level, so you have to add an allow to the
1089 /// entire macro definition.
1090 ///
1091 /// If you intended to export the macro to make it
1092 /// available outside of the crate, use the [`macro_export` attribute].
1093 ///
1094 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
1095pub UNUSED_MACRO_RULES,
1096 Allow,
1097"detects macro rules that were not used"
1098}10991100#[doc = r" The `warnings` lint allows you to change the level of other"]
#[doc = r" lints which produce warnings."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The `warnings` lint is a bit special; by changing its level, you"]
#[doc =
r" change every other warning that would produce a warning to whatever"]
#[doc =
r" value you'd like. As such, you won't ever trigger this lint in your"]
#[doc = r" code directly."]
pub static WARNINGS: &crate::Lint =
&crate::Lint {
name: "WARNINGS",
default_level: crate::Warn,
desc: "mass-change the level for lints which produce warnings",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1101/// The `warnings` lint allows you to change the level of other
1102 /// lints which produce warnings.
1103 ///
1104 /// ### Example
1105 ///
1106 /// ```rust
1107 /// #![deny(warnings)]
1108 /// fn foo() {}
1109 /// ```
1110 ///
1111 /// {{produces}}
1112 ///
1113 /// ### Explanation
1114 ///
1115 /// The `warnings` lint is a bit special; by changing its level, you
1116 /// change every other warning that would produce a warning to whatever
1117 /// value you'd like. As such, you won't ever trigger this lint in your
1118 /// code directly.
1119pub WARNINGS,
1120 Warn,
1121"mass-change the level for lints which produce warnings"
1122}11231124#[doc =
r" The `unused_features` lint detects unused or unknown features found in"]
#[doc = r" crate-level [`feature` attributes]."]
#[doc = r""]
#[doc =
r" [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/"]
pub static UNUSED_FEATURES: &crate::Lint =
&crate::Lint {
name: "UNUSED_FEATURES",
default_level: crate::Warn,
desc: "unused features found in crate-level `#[feature]` directives",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1125/// The `unused_features` lint detects unused or unknown features found in
1126 /// crate-level [`feature` attributes].
1127 ///
1128 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1129pub UNUSED_FEATURES,
1130 Warn,
1131"unused features found in crate-level `#[feature]` directives"
1132}11331134#[doc = r" The `duplicate_features` lint detects duplicate features found in"]
#[doc = r" crate-level [`feature` attributes]."]
#[doc = r""]
#[doc = r" Note: This lint used to be a hard error (E0636)."]
#[doc = r""]
#[doc =
r" [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(internal_features)]"]
#[doc = r" #![feature(rustc_attrs)]"]
#[doc = r" #![feature(rustc_attrs)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Enabling a feature more than once is a no-op."]
#[doc = r" To avoid this warning, remove the second `feature()` attribute."]
pub static DUPLICATE_FEATURES: &crate::Lint =
&crate::Lint {
name: "DUPLICATE_FEATURES",
default_level: crate::Deny,
desc: "duplicate features found in crate-level `#[feature]` directives",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1135/// The `duplicate_features` lint detects duplicate features found in
1136 /// crate-level [`feature` attributes].
1137 ///
1138 /// Note: This lint used to be a hard error (E0636).
1139 ///
1140 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
1141 ///
1142 /// ### Example
1143 ///
1144 /// ```rust,compile_fail
1145 /// # #![allow(internal_features)]
1146 /// #![feature(rustc_attrs)]
1147 /// #![feature(rustc_attrs)]
1148 /// ```
1149 ///
1150 /// {{produces}}
1151 ///
1152 /// ### Explanation
1153 ///
1154 /// Enabling a feature more than once is a no-op.
1155 /// To avoid this warning, remove the second `feature()` attribute.
1156pub DUPLICATE_FEATURES,
1157 Deny,
1158"duplicate features found in crate-level `#[feature]` directives"
1159}11601161#[doc = r" The `stable_features` lint detects a [`feature` attribute] that"]
#[doc = r" has since been made stable."]
#[doc = r""]
#[doc =
r" [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(test_accepted_feature)]"]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When a feature is stabilized, it is no longer necessary to include a"]
#[doc = r" `#![feature]` attribute for it. To fix, simply remove the"]
#[doc = r" `#![feature]` attribute."]
pub static STABLE_FEATURES: &crate::Lint =
&crate::Lint {
name: "STABLE_FEATURES",
default_level: crate::Warn,
desc: "stable features found in `#[feature]` directive",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1162/// The `stable_features` lint detects a [`feature` attribute] that
1163 /// has since been made stable.
1164 ///
1165 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1166 ///
1167 /// ### Example
1168 ///
1169 /// ```rust
1170 /// #![feature(test_accepted_feature)]
1171 /// fn main() {}
1172 /// ```
1173 ///
1174 /// {{produces}}
1175 ///
1176 /// ### Explanation
1177 ///
1178 /// When a feature is stabilized, it is no longer necessary to include a
1179 /// `#![feature]` attribute for it. To fix, simply remove the
1180 /// `#![feature]` attribute.
1181pub STABLE_FEATURES,
1182 Warn,
1183"stable features found in `#[feature]` directive"
1184}11851186#[doc =
r" The `unknown_crate_types` lint detects an unknown crate type found in"]
#[doc = r" a [`crate_type` attribute]."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r#" #![crate_type="lol"]"#]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" An unknown value give to the `crate_type` attribute is almost"]
#[doc = r" certainly a mistake."]
#[doc = r""]
#[doc =
r" [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html"]
pub static UNKNOWN_CRATE_TYPES: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_CRATE_TYPES",
default_level: crate::Deny,
desc: "unknown crate type found in `#[crate_type]` directive",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1187/// The `unknown_crate_types` lint detects an unknown crate type found in
1188 /// a [`crate_type` attribute].
1189 ///
1190 /// ### Example
1191 ///
1192 /// ```rust,compile_fail
1193 /// #![crate_type="lol"]
1194 /// fn main() {}
1195 /// ```
1196 ///
1197 /// {{produces}}
1198 ///
1199 /// ### Explanation
1200 ///
1201 /// An unknown value give to the `crate_type` attribute is almost
1202 /// certainly a mistake.
1203 ///
1204 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
1205pub UNKNOWN_CRATE_TYPES,
1206 Deny,
1207"unknown crate type found in `#[crate_type]` directive",
1208 crate_level_only
1209}12101211#[doc =
r" The `trivial_casts` lint detects trivial casts which could be replaced"]
#[doc = r" with coercion, which may require a temporary variable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(trivial_casts)]"]
#[doc = r" let x: &u32 = &42;"]
#[doc = r" let y = x as *const u32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a"]
#[doc =
r" subtype of `T`. This type of cast is usually unnecessary, as it can be"]
#[doc = r" usually be inferred."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because there are situations, such as"#]
#[doc = r" with FFI interfaces or complex type aliases, where it triggers"]
#[doc = r" incorrectly, or in situations where it will be more difficult to"]
#[doc =
r" clearly express the intent. It may be possible that this will become a"]
#[doc =
r" warning in the future, possibly with an explicit syntax for coercions"]
#[doc = r" providing a convenient way to work around the current issues."]
#[doc =
r" See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and"]
#[doc =
r" [RFC 3307 (remove type ascription)][rfc-3307] for historical context."]
#[doc = r""]
#[doc =
r" [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md"]
#[doc =
r" [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md"]
#[doc =
r" [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md"]
pub static TRIVIAL_CASTS: &crate::Lint =
&crate::Lint {
name: "TRIVIAL_CASTS",
default_level: crate::Allow,
desc: "detects trivial casts which could be removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1212/// The `trivial_casts` lint detects trivial casts which could be replaced
1213 /// with coercion, which may require a temporary variable.
1214 ///
1215 /// ### Example
1216 ///
1217 /// ```rust,compile_fail
1218 /// #![deny(trivial_casts)]
1219 /// let x: &u32 = &42;
1220 /// let y = x as *const u32;
1221 /// ```
1222 ///
1223 /// {{produces}}
1224 ///
1225 /// ### Explanation
1226 ///
1227 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
1228 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
1229 /// usually be inferred.
1230 ///
1231 /// This lint is "allow" by default because there are situations, such as
1232 /// with FFI interfaces or complex type aliases, where it triggers
1233 /// incorrectly, or in situations where it will be more difficult to
1234 /// clearly express the intent. It may be possible that this will become a
1235 /// warning in the future, possibly with an explicit syntax for coercions
1236 /// providing a convenient way to work around the current issues.
1237 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1238 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1239 ///
1240 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1241 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1242 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1243pub TRIVIAL_CASTS,
1244 Allow,
1245"detects trivial casts which could be removed"
1246}12471248#[doc =
r" The `trivial_numeric_casts` lint detects trivial numeric casts of types"]
#[doc = r" which could be removed."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(trivial_numeric_casts)]"]
#[doc = r" let x = 42_i32 as i32;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A trivial numeric cast is a cast of a numeric type to the same numeric"]
#[doc = r" type. This type of cast is usually unnecessary."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because there are situations, such as"#]
#[doc = r" with FFI interfaces or complex type aliases, where it triggers"]
#[doc = r" incorrectly, or in situations where it will be more difficult to"]
#[doc =
r" clearly express the intent. It may be possible that this will become a"]
#[doc =
r" warning in the future, possibly with an explicit syntax for coercions"]
#[doc = r" providing a convenient way to work around the current issues."]
#[doc =
r" See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and"]
#[doc =
r" [RFC 3307 (remove type ascription)][rfc-3307] for historical context."]
#[doc = r""]
#[doc =
r" [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md"]
#[doc =
r" [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md"]
#[doc =
r" [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md"]
pub static TRIVIAL_NUMERIC_CASTS: &crate::Lint =
&crate::Lint {
name: "TRIVIAL_NUMERIC_CASTS",
default_level: crate::Allow,
desc: "detects trivial casts of numeric types which could be removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1249/// The `trivial_numeric_casts` lint detects trivial numeric casts of types
1250 /// which could be removed.
1251 ///
1252 /// ### Example
1253 ///
1254 /// ```rust,compile_fail
1255 /// #![deny(trivial_numeric_casts)]
1256 /// let x = 42_i32 as i32;
1257 /// ```
1258 ///
1259 /// {{produces}}
1260 ///
1261 /// ### Explanation
1262 ///
1263 /// A trivial numeric cast is a cast of a numeric type to the same numeric
1264 /// type. This type of cast is usually unnecessary.
1265 ///
1266 /// This lint is "allow" by default because there are situations, such as
1267 /// with FFI interfaces or complex type aliases, where it triggers
1268 /// incorrectly, or in situations where it will be more difficult to
1269 /// clearly express the intent. It may be possible that this will become a
1270 /// warning in the future, possibly with an explicit syntax for coercions
1271 /// providing a convenient way to work around the current issues.
1272 /// See [RFC 401 (coercions)][rfc-401], [RFC 803 (type ascription)][rfc-803] and
1273 /// [RFC 3307 (remove type ascription)][rfc-3307] for historical context.
1274 ///
1275 /// [rfc-401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1276 /// [rfc-803]: https://github.com/rust-lang/rfcs/blob/master/text/0803-type-ascription.md
1277 /// [rfc-3307]: https://github.com/rust-lang/rfcs/blob/master/text/3307-de-rfc-type-ascription.md
1278pub TRIVIAL_NUMERIC_CASTS,
1279 Allow,
1280"detects trivial casts of numeric types which could be removed"
1281}12821283#[doc =
r" The `exported_private_dependencies` lint detects private dependencies"]
#[doc = r" that are exposed in a public interface."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" pub fn foo() -> Option<some_private_dependency::Thing> {"]
#[doc = r" None"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning: type `bar::Thing` from private dependency 'bar' in public interface"]
#[doc = r" --> src/lib.rs:3:1"]
#[doc = r" |"]
#[doc = r" 3 | pub fn foo() -> Option<bar::Thing> {"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(exported_private_dependencies)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Dependencies can be marked as "private" to indicate that they are not"#]
#[doc =
r" exposed in the public interface of a crate. This can be used by Cargo"]
#[doc =
r" to independently resolve those dependencies because it can assume it"]
#[doc = r" does not need to unify them with other packages using that same"]
#[doc = r" dependency. This lint is an indication of a violation of that"]
#[doc = r" contract."]
#[doc = r""]
#[doc =
r" To fix this, avoid exposing the dependency in your public interface."]
#[doc = r" Or, switch the dependency to a public dependency."]
#[doc = r""]
#[doc =
r" Note that support for this is only available on the nightly channel."]
#[doc =
r" See [RFC 1977] for more details, as well as the [Cargo documentation]."]
#[doc = r""]
#[doc =
r" [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md"]
#[doc =
r" [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency"]
pub static EXPORTED_PRIVATE_DEPENDENCIES: &crate::Lint =
&crate::Lint {
name: "EXPORTED_PRIVATE_DEPENDENCIES",
default_level: crate::Warn,
desc: "public interface leaks type from a private dependency",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1284/// The `exported_private_dependencies` lint detects private dependencies
1285 /// that are exposed in a public interface.
1286 ///
1287 /// ### Example
1288 ///
1289 /// ```rust,ignore (needs-dependency)
1290 /// pub fn foo() -> Option<some_private_dependency::Thing> {
1291 /// None
1292 /// }
1293 /// ```
1294 ///
1295 /// This will produce:
1296 ///
1297 /// ```text
1298 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
1299 /// --> src/lib.rs:3:1
1300 /// |
1301 /// 3 | pub fn foo() -> Option<bar::Thing> {
1302 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1303 /// |
1304 /// = note: `#[warn(exported_private_dependencies)]` on by default
1305 /// ```
1306 ///
1307 /// ### Explanation
1308 ///
1309 /// Dependencies can be marked as "private" to indicate that they are not
1310 /// exposed in the public interface of a crate. This can be used by Cargo
1311 /// to independently resolve those dependencies because it can assume it
1312 /// does not need to unify them with other packages using that same
1313 /// dependency. This lint is an indication of a violation of that
1314 /// contract.
1315 ///
1316 /// To fix this, avoid exposing the dependency in your public interface.
1317 /// Or, switch the dependency to a public dependency.
1318 ///
1319 /// Note that support for this is only available on the nightly channel.
1320 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
1321 ///
1322 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
1323 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
1324pub EXPORTED_PRIVATE_DEPENDENCIES,
1325 Warn,
1326"public interface leaks type from a private dependency"
1327}13281329#[doc = r" The `pub_use_of_private_extern_crate` lint detects a specific"]
#[doc = r" situation of re-exporting a private `extern crate`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" extern crate core;"]
#[doc = r" pub use core as reexported_core;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A public `use` declaration should not be used to publically re-export a"]
#[doc =
r" private `extern crate`. `pub extern crate` should be used instead."]
#[doc = r""]
#[doc = r" This was historically allowed, but is not the intended behavior"]
#[doc =
r" according to the visibility rules. This is a [future-incompatible]"]
#[doc = r" lint to transition this to a hard error in the future. See [issue"]
#[doc = r" #127909] for more details."]
#[doc = r""]
#[doc = r" [issue #127909]: https://github.com/rust-lang/rust/issues/127909"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PUB_USE_OF_PRIVATE_EXTERN_CRATE: &crate::Lint =
&crate::Lint {
name: "PUB_USE_OF_PRIVATE_EXTERN_CRATE",
default_level: crate::Deny,
desc: "detect public re-exports of private extern crates",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 127909,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1330/// The `pub_use_of_private_extern_crate` lint detects a specific
1331 /// situation of re-exporting a private `extern crate`.
1332 ///
1333 /// ### Example
1334 ///
1335 /// ```rust,compile_fail
1336 /// extern crate core;
1337 /// pub use core as reexported_core;
1338 /// ```
1339 ///
1340 /// {{produces}}
1341 ///
1342 /// ### Explanation
1343 ///
1344 /// A public `use` declaration should not be used to publically re-export a
1345 /// private `extern crate`. `pub extern crate` should be used instead.
1346 ///
1347 /// This was historically allowed, but is not the intended behavior
1348 /// according to the visibility rules. This is a [future-incompatible]
1349 /// lint to transition this to a hard error in the future. See [issue
1350 /// #127909] for more details.
1351 ///
1352 /// [issue #127909]: https://github.com/rust-lang/rust/issues/127909
1353 /// [future-incompatible]: ../index.md#future-incompatible-lints
1354pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
1355 Deny,
1356"detect public re-exports of private extern crates",
1357 @future_incompatible = FutureIncompatibleInfo {
1358 reason: fcw!(FutureReleaseError #127909),
1359 report_in_deps: true,
1360 };
1361}13621363#[doc =
r" The `invalid_type_param_default` lint detects type parameter defaults"]
#[doc = r" erroneously allowed in an invalid location."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" fn foo<T=i32>(t: T) {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Default type parameters were only intended to be allowed in certain"]
#[doc =
r" situations, but historically the compiler allowed them everywhere."]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc = r" error in the future. See [issue #36887] for more details."]
#[doc = r""]
#[doc = r" [issue #36887]: https://github.com/rust-lang/rust/issues/36887"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static INVALID_TYPE_PARAM_DEFAULT: &crate::Lint =
&crate::Lint {
name: "INVALID_TYPE_PARAM_DEFAULT",
default_level: crate::Deny,
desc: "type parameter default erroneously allowed in invalid location",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 36887,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1364/// The `invalid_type_param_default` lint detects type parameter defaults
1365 /// erroneously allowed in an invalid location.
1366 ///
1367 /// ### Example
1368 ///
1369 /// ```rust,compile_fail
1370 /// fn foo<T=i32>(t: T) {}
1371 /// ```
1372 ///
1373 /// {{produces}}
1374 ///
1375 /// ### Explanation
1376 ///
1377 /// Default type parameters were only intended to be allowed in certain
1378 /// situations, but historically the compiler allowed them everywhere.
1379 /// This is a [future-incompatible] lint to transition this to a hard
1380 /// error in the future. See [issue #36887] for more details.
1381 ///
1382 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
1383 /// [future-incompatible]: ../index.md#future-incompatible-lints
1384pub INVALID_TYPE_PARAM_DEFAULT,
1385 Deny,
1386"type parameter default erroneously allowed in invalid location",
1387 @future_incompatible = FutureIncompatibleInfo {
1388 reason: fcw!(FutureReleaseError #36887),
1389 report_in_deps: true,
1390 };
1391}13921393#[doc = r" The `renamed_and_removed_lints` lint detects lints that have been"]
#[doc = r" renamed or removed."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![deny(raw_pointer_derive)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" To fix this, either remove the lint or use the new name. This can help"]
#[doc = r" avoid confusion about lints that are no longer valid, and help"]
#[doc = r" maintain consistency for renamed lints."]
pub static RENAMED_AND_REMOVED_LINTS: &crate::Lint =
&crate::Lint {
name: "RENAMED_AND_REMOVED_LINTS",
default_level: crate::Warn,
desc: "lints that have been renamed or removed",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1394/// The `renamed_and_removed_lints` lint detects lints that have been
1395 /// renamed or removed.
1396 ///
1397 /// ### Example
1398 ///
1399 /// ```rust
1400 /// #![deny(raw_pointer_derive)]
1401 /// ```
1402 ///
1403 /// {{produces}}
1404 ///
1405 /// ### Explanation
1406 ///
1407 /// To fix this, either remove the lint or use the new name. This can help
1408 /// avoid confusion about lints that are no longer valid, and help
1409 /// maintain consistency for renamed lints.
1410pub RENAMED_AND_REMOVED_LINTS,
1411 Warn,
1412"lints that have been renamed or removed"
1413}14141415#[doc =
r" The `const_item_mutation` lint detects attempts to mutate a `const`"]
#[doc = r" item."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" const FOO: [i32; 1] = [0];"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" FOO[0] = 1;"]
#[doc = r#" // This will print "[0]"."#]
#[doc = r#" println!("{:?}", FOO);"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Trying to directly mutate a `const` item is almost always a mistake."]
#[doc =
r" What is happening in the example above is that a temporary copy of the"]
#[doc =
r" `const` is mutated, but the original `const` is not. Each time you"]
#[doc =
r" refer to the `const` by name (such as `FOO` in the example above), a"]
#[doc = r" separate copy of the value is inlined at that location."]
#[doc = r""]
#[doc = r" This lint checks for writing directly to a field (`FOO.field ="]
#[doc = r" some_value`) or array entry (`FOO[0] = val`), or taking a mutable"]
#[doc = r" reference to the const item (`&mut FOO`), including through an"]
#[doc = r" autoderef (`FOO.some_mut_self_method()`)."]
#[doc = r""]
#[doc =
r" There are various alternatives depending on what you are trying to"]
#[doc = r" accomplish:"]
#[doc = r""]
#[doc = r" * First, always reconsider using mutable globals, as they can be"]
#[doc =
r" difficult to use correctly, and can make the code more difficult to"]
#[doc = r" use or understand."]
#[doc =
r" * If you are trying to perform a one-time initialization of a global:"]
#[doc =
r" * If the value can be computed at compile-time, consider using"]
#[doc = r" const-compatible values (see [Constant Evaluation])."]
#[doc =
r" * For more complex single-initialization cases, consider using"]
#[doc = r" [`std::sync::LazyLock`]."]
#[doc =
r" * If you truly need a mutable global, consider using a [`static`],"]
#[doc = r" which has a variety of options:"]
#[doc = r" * Simple data types can be directly defined and mutated with an"]
#[doc = r" [`atomic`] type."]
#[doc =
r" * More complex types can be placed in a synchronization primitive"]
#[doc =
r" like a [`Mutex`], which can be initialized with one of the options"]
#[doc = r" listed above."]
#[doc =
r" * A [mutable `static`] is a low-level primitive, requiring unsafe."]
#[doc = r" Typically This should be avoided in preference of something"]
#[doc = r" higher-level like one of the above."]
#[doc = r""]
#[doc =
r" [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html"]
#[doc =
r" [`static`]: https://doc.rust-lang.org/reference/items/static-items.html"]
#[doc =
r" [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics"]
#[doc =
r" [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html"]
#[doc = r" [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html"]
#[doc = r" [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html"]
pub static CONST_ITEM_MUTATION: &crate::Lint =
&crate::Lint {
name: "CONST_ITEM_MUTATION",
default_level: crate::Warn,
desc: "detects attempts to mutate a `const` item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1416/// The `const_item_mutation` lint detects attempts to mutate a `const`
1417 /// item.
1418 ///
1419 /// ### Example
1420 ///
1421 /// ```rust
1422 /// const FOO: [i32; 1] = [0];
1423 ///
1424 /// fn main() {
1425 /// FOO[0] = 1;
1426 /// // This will print "[0]".
1427 /// println!("{:?}", FOO);
1428 /// }
1429 /// ```
1430 ///
1431 /// {{produces}}
1432 ///
1433 /// ### Explanation
1434 ///
1435 /// Trying to directly mutate a `const` item is almost always a mistake.
1436 /// What is happening in the example above is that a temporary copy of the
1437 /// `const` is mutated, but the original `const` is not. Each time you
1438 /// refer to the `const` by name (such as `FOO` in the example above), a
1439 /// separate copy of the value is inlined at that location.
1440 ///
1441 /// This lint checks for writing directly to a field (`FOO.field =
1442 /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1443 /// reference to the const item (`&mut FOO`), including through an
1444 /// autoderef (`FOO.some_mut_self_method()`).
1445 ///
1446 /// There are various alternatives depending on what you are trying to
1447 /// accomplish:
1448 ///
1449 /// * First, always reconsider using mutable globals, as they can be
1450 /// difficult to use correctly, and can make the code more difficult to
1451 /// use or understand.
1452 /// * If you are trying to perform a one-time initialization of a global:
1453 /// * If the value can be computed at compile-time, consider using
1454 /// const-compatible values (see [Constant Evaluation]).
1455 /// * For more complex single-initialization cases, consider using
1456 /// [`std::sync::LazyLock`].
1457 /// * If you truly need a mutable global, consider using a [`static`],
1458 /// which has a variety of options:
1459 /// * Simple data types can be directly defined and mutated with an
1460 /// [`atomic`] type.
1461 /// * More complex types can be placed in a synchronization primitive
1462 /// like a [`Mutex`], which can be initialized with one of the options
1463 /// listed above.
1464 /// * A [mutable `static`] is a low-level primitive, requiring unsafe.
1465 /// Typically This should be avoided in preference of something
1466 /// higher-level like one of the above.
1467 ///
1468 /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1469 /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1470 /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1471 /// [`std::sync::LazyLock`]: https://doc.rust-lang.org/stable/std/sync/struct.LazyLock.html
1472 /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1473 /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1474pub CONST_ITEM_MUTATION,
1475 Warn,
1476"detects attempts to mutate a `const` item",
1477}14781479#[doc = r" The `patterns_in_fns_without_body` lint detects `mut` identifier"]
#[doc = r" patterns as a parameter in functions without a body."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" trait Trait {"]
#[doc = r" fn foo(mut arg: u8);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" To fix this, remove `mut` from the parameter in the trait definition;"]
#[doc =
r" it can be used in the implementation. That is, the following is OK:"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Trait {"]
#[doc = r" fn foo(arg: u8); // Removed `mut` here"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Trait for i32 {"]
#[doc = r" fn foo(mut arg: u8) { // `mut` here is OK"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" Trait definitions can define functions without a body to specify a"]
#[doc =
r" function that implementors must define. The parameter names in the"]
#[doc =
r" body-less functions are only allowed to be `_` or an [identifier] for"]
#[doc =
r" documentation purposes (only the type is relevant). Previous versions"]
#[doc =
r" of the compiler erroneously allowed [identifier patterns] with the"]
#[doc = r" `mut` keyword, but this was not intended to be allowed. This is a"]
#[doc =
r" [future-incompatible] lint to transition this to a hard error in the"]
#[doc = r" future. See [issue #35203] for more details."]
#[doc = r""]
#[doc =
r" [identifier]: https://doc.rust-lang.org/reference/identifiers.html"]
#[doc =
r" [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns"]
#[doc = r" [issue #35203]: https://github.com/rust-lang/rust/issues/35203"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PATTERNS_IN_FNS_WITHOUT_BODY: &crate::Lint =
&crate::Lint {
name: "PATTERNS_IN_FNS_WITHOUT_BODY",
default_level: crate::Deny,
desc: "patterns in functions without body were erroneously allowed",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 35203,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1480/// The `patterns_in_fns_without_body` lint detects `mut` identifier
1481 /// patterns as a parameter in functions without a body.
1482 ///
1483 /// ### Example
1484 ///
1485 /// ```rust,compile_fail
1486 /// trait Trait {
1487 /// fn foo(mut arg: u8);
1488 /// }
1489 /// ```
1490 ///
1491 /// {{produces}}
1492 ///
1493 /// ### Explanation
1494 ///
1495 /// To fix this, remove `mut` from the parameter in the trait definition;
1496 /// it can be used in the implementation. That is, the following is OK:
1497 ///
1498 /// ```rust
1499 /// trait Trait {
1500 /// fn foo(arg: u8); // Removed `mut` here
1501 /// }
1502 ///
1503 /// impl Trait for i32 {
1504 /// fn foo(mut arg: u8) { // `mut` here is OK
1505 ///
1506 /// }
1507 /// }
1508 /// ```
1509 ///
1510 /// Trait definitions can define functions without a body to specify a
1511 /// function that implementors must define. The parameter names in the
1512 /// body-less functions are only allowed to be `_` or an [identifier] for
1513 /// documentation purposes (only the type is relevant). Previous versions
1514 /// of the compiler erroneously allowed [identifier patterns] with the
1515 /// `mut` keyword, but this was not intended to be allowed. This is a
1516 /// [future-incompatible] lint to transition this to a hard error in the
1517 /// future. See [issue #35203] for more details.
1518 ///
1519 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1520 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1521 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1522 /// [future-incompatible]: ../index.md#future-incompatible-lints
1523pub PATTERNS_IN_FNS_WITHOUT_BODY,
1524 Deny,
1525"patterns in functions without body were erroneously allowed",
1526 @future_incompatible = FutureIncompatibleInfo {
1527 reason: fcw!(FutureReleaseError #35203),
1528 };
1529}15301531#[doc = r" The `late_bound_lifetime_arguments` lint detects generic lifetime"]
#[doc = r" arguments in path segments with late bound lifetime parameters."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" struct S;"]
#[doc = r""]
#[doc = r" impl S {"]
#[doc = r" fn late(self, _: &u8, _: &u8) {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" S.late::<'static>(&0, &0);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" It is not clear how to provide arguments for early-bound lifetime"]
#[doc =
r" parameters if they are intermixed with late-bound parameters in the"]
#[doc =
r" same list. For now, providing any explicit arguments will trigger this"]
#[doc =
r" lint if late-bound parameters are present, so in the future a solution"]
#[doc =
r" can be adopted without hitting backward compatibility issues. This is"]
#[doc =
r" a [future-incompatible] lint to transition this to a hard error in the"]
#[doc =
r" future. See [issue #42868] for more details, along with a description"]
#[doc = r" of the difference between early and late-bound parameters."]
#[doc = r""]
#[doc = r" [issue #42868]: https://github.com/rust-lang/rust/issues/42868"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static LATE_BOUND_LIFETIME_ARGUMENTS: &crate::Lint =
&crate::Lint {
name: "LATE_BOUND_LIFETIME_ARGUMENTS",
default_level: crate::Warn,
desc: "detects generic lifetime arguments in path segments with late bound lifetime parameters",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 42868,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1532/// The `late_bound_lifetime_arguments` lint detects generic lifetime
1533 /// arguments in path segments with late bound lifetime parameters.
1534 ///
1535 /// ### Example
1536 ///
1537 /// ```rust
1538 /// struct S;
1539 ///
1540 /// impl S {
1541 /// fn late(self, _: &u8, _: &u8) {}
1542 /// }
1543 ///
1544 /// fn main() {
1545 /// S.late::<'static>(&0, &0);
1546 /// }
1547 /// ```
1548 ///
1549 /// {{produces}}
1550 ///
1551 /// ### Explanation
1552 ///
1553 /// It is not clear how to provide arguments for early-bound lifetime
1554 /// parameters if they are intermixed with late-bound parameters in the
1555 /// same list. For now, providing any explicit arguments will trigger this
1556 /// lint if late-bound parameters are present, so in the future a solution
1557 /// can be adopted without hitting backward compatibility issues. This is
1558 /// a [future-incompatible] lint to transition this to a hard error in the
1559 /// future. See [issue #42868] for more details, along with a description
1560 /// of the difference between early and late-bound parameters.
1561 ///
1562 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1563 /// [future-incompatible]: ../index.md#future-incompatible-lints
1564pub LATE_BOUND_LIFETIME_ARGUMENTS,
1565 Warn,
1566"detects generic lifetime arguments in path segments with late bound lifetime parameters",
1567 @future_incompatible = FutureIncompatibleInfo {
1568 reason: fcw!(FutureReleaseError #42868),
1569 };
1570}15711572#[doc =
r" The `coherence_leak_check` lint detects conflicting implementations of"]
#[doc = r" a trait that are only distinguished by the old leak-check code."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait SomeTrait { }"]
#[doc = r" impl SomeTrait for for<'a> fn(&'a u8) { }"]
#[doc = r" impl<'a> SomeTrait for fn(&'a u8) { }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In the past, the compiler would accept trait implementations for"]
#[doc =
r" identical functions that differed only in where the lifetime binder"]
#[doc =
r" appeared. Due to a change in the borrow checker implementation to fix"]
#[doc =
r" several bugs, this is no longer allowed. However, since this affects"]
#[doc =
r" existing code, this is a [future-incompatible] lint to transition this"]
#[doc = r" to a hard error in the future."]
#[doc = r""]
#[doc = r#" Code relying on this pattern should introduce "[newtypes]","#]
#[doc = r" like `struct Foo(for<'a> fn(&'a u8))`."]
#[doc = r""]
#[doc = r" See [issue #56105] for more details."]
#[doc = r""]
#[doc = r" [issue #56105]: https://github.com/rust-lang/rust/issues/56105"]
#[doc =
r" [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static COHERENCE_LEAK_CHECK: &crate::Lint =
&crate::Lint {
name: "COHERENCE_LEAK_CHECK",
default_level: crate::Warn,
desc: "distinct impls distinguished only by the leak-check code",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::Custom("the behavior may change in a future release",
crate::ReleaseFcw { issue_number: 56105 }),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1573/// The `coherence_leak_check` lint detects conflicting implementations of
1574 /// a trait that are only distinguished by the old leak-check code.
1575 ///
1576 /// ### Example
1577 ///
1578 /// ```rust
1579 /// trait SomeTrait { }
1580 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1581 /// impl<'a> SomeTrait for fn(&'a u8) { }
1582 /// ```
1583 ///
1584 /// {{produces}}
1585 ///
1586 /// ### Explanation
1587 ///
1588 /// In the past, the compiler would accept trait implementations for
1589 /// identical functions that differed only in where the lifetime binder
1590 /// appeared. Due to a change in the borrow checker implementation to fix
1591 /// several bugs, this is no longer allowed. However, since this affects
1592 /// existing code, this is a [future-incompatible] lint to transition this
1593 /// to a hard error in the future.
1594 ///
1595 /// Code relying on this pattern should introduce "[newtypes]",
1596 /// like `struct Foo(for<'a> fn(&'a u8))`.
1597 ///
1598 /// See [issue #56105] for more details.
1599 ///
1600 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1601 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1602 /// [future-incompatible]: ../index.md#future-incompatible-lints
1603pub COHERENCE_LEAK_CHECK,
1604 Warn,
1605"distinct impls distinguished only by the leak-check code",
1606 @future_incompatible = FutureIncompatibleInfo {
1607 reason: fcw!("the behavior may change in a future release" #56105),
1608 };
1609}16101611#[doc = r" The `deprecated` lint detects use of deprecated items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[deprecated]"]
#[doc = r" fn foo() {}"]
#[doc = r""]
#[doc = r" fn bar() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Items may be marked "deprecated" with the [`deprecated` attribute] to"#]
#[doc =
r" indicate that they should no longer be used. Usually the attribute"]
#[doc = r" should include a note on what to use instead, or check the"]
#[doc = r" documentation."]
#[doc = r""]
#[doc =
r" [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"]
pub static DEPRECATED: &crate::Lint =
&crate::Lint {
name: "DEPRECATED",
default_level: crate::Warn,
desc: "detects use of deprecated items",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1612/// The `deprecated` lint detects use of deprecated items.
1613 ///
1614 /// ### Example
1615 ///
1616 /// ```rust
1617 /// #[deprecated]
1618 /// fn foo() {}
1619 ///
1620 /// fn bar() {
1621 /// foo();
1622 /// }
1623 /// ```
1624 ///
1625 /// {{produces}}
1626 ///
1627 /// ### Explanation
1628 ///
1629 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1630 /// indicate that they should no longer be used. Usually the attribute
1631 /// should include a note on what to use instead, or check the
1632 /// documentation.
1633 ///
1634 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1635pub DEPRECATED,
1636 Warn,
1637"detects use of deprecated items",
1638 report_in_external_macro
1639}16401641#[doc =
r" The `unused_unsafe` lint detects unnecessary use of an `unsafe` block."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" unsafe {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" If nothing within the block requires `unsafe`, then remove the"]
#[doc =
r" `unsafe` marker because it is not required and may cause confusion."]
pub static UNUSED_UNSAFE: &crate::Lint =
&crate::Lint {
name: "UNUSED_UNSAFE",
default_level: crate::Warn,
desc: "unnecessary use of an `unsafe` block",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1642/// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1643 ///
1644 /// ### Example
1645 ///
1646 /// ```rust
1647 /// unsafe {}
1648 /// ```
1649 ///
1650 /// {{produces}}
1651 ///
1652 /// ### Explanation
1653 ///
1654 /// If nothing within the block requires `unsafe`, then remove the
1655 /// `unsafe` marker because it is not required and may cause confusion.
1656pub UNUSED_UNSAFE,
1657 Warn,
1658"unnecessary use of an `unsafe` block"
1659}16601661#[doc =
r" The `unused_mut` lint detects mut variables which don't need to be"]
#[doc = r" mutable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" let mut x = 5;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The preferred style is to only mark variables as `mut` if it is"]
#[doc = r" required."]
pub static UNUSED_MUT: &crate::Lint =
&crate::Lint {
name: "UNUSED_MUT",
default_level: crate::Warn,
desc: "detect mut variables which don't need to be mutable",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1662/// The `unused_mut` lint detects mut variables which don't need to be
1663 /// mutable.
1664 ///
1665 /// ### Example
1666 ///
1667 /// ```rust
1668 /// let mut x = 5;
1669 /// ```
1670 ///
1671 /// {{produces}}
1672 ///
1673 /// ### Explanation
1674 ///
1675 /// The preferred style is to only mark variables as `mut` if it is
1676 /// required.
1677pub UNUSED_MUT,
1678 Warn,
1679"detect mut variables which don't need to be mutable"
1680}16811682#[doc = r" The `rust_2024_incompatible_pat` lint"]
#[doc =
r" detects patterns whose meaning will change in the Rust 2024 edition."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(rust_2024_incompatible_pat)]"]
#[doc = r""]
#[doc = r" if let Some(&a) = &Some(&0u8) {"]
#[doc = r" let _: u8 = a;"]
#[doc = r" }"]
#[doc = r" if let Some(mut _a) = &mut Some(0u8) {"]
#[doc = r" _a = 7u8;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,"]
#[doc =
r" and nor do `&` or `&mut` patterns. The lint will suggest code that"]
#[doc = r" has the same meaning in all editions."]
pub static RUST_2024_INCOMPATIBLE_PAT: &crate::Lint =
&crate::Lint {
name: "RUST_2024_INCOMPATIBLE_PAT",
default_level: crate::Allow,
desc: "detects patterns whose meaning will change in Rust 2024",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "match-ergonomics",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1683/// The `rust_2024_incompatible_pat` lint
1684 /// detects patterns whose meaning will change in the Rust 2024 edition.
1685 ///
1686 /// ### Example
1687 ///
1688 /// ```rust,edition2021
1689 /// #![warn(rust_2024_incompatible_pat)]
1690 ///
1691 /// if let Some(&a) = &Some(&0u8) {
1692 /// let _: u8 = a;
1693 /// }
1694 /// if let Some(mut _a) = &mut Some(0u8) {
1695 /// _a = 7u8;
1696 /// }
1697 /// ```
1698 ///
1699 /// {{produces}}
1700 ///
1701 /// ### Explanation
1702 ///
1703 /// In Rust 2024 and above, the `mut` keyword does not reset the pattern binding mode,
1704 /// and nor do `&` or `&mut` patterns. The lint will suggest code that
1705 /// has the same meaning in all editions.
1706pub RUST_2024_INCOMPATIBLE_PAT,
1707 Allow,
1708"detects patterns whose meaning will change in Rust 2024",
1709 @future_incompatible = FutureIncompatibleInfo {
1710 reason: fcw!(EditionSemanticsChange 2024 "match-ergonomics"),
1711 };
1712}17131714#[doc = r" The `unconditional_recursion` lint detects functions that cannot"]
#[doc = r" return without calling themselves."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to have a recursive call that does not have"]
#[doc =
r" some condition to cause it to terminate. If you really intend to have"]
#[doc = r" an infinite loop, using a `loop` expression is recommended."]
pub static UNCONDITIONAL_RECURSION: &crate::Lint =
&crate::Lint {
name: "UNCONDITIONAL_RECURSION",
default_level: crate::Warn,
desc: "functions that cannot return without calling themselves",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1715/// The `unconditional_recursion` lint detects functions that cannot
1716 /// return without calling themselves.
1717 ///
1718 /// ### Example
1719 ///
1720 /// ```rust
1721 /// fn foo() {
1722 /// foo();
1723 /// }
1724 /// ```
1725 ///
1726 /// {{produces}}
1727 ///
1728 /// ### Explanation
1729 ///
1730 /// It is usually a mistake to have a recursive call that does not have
1731 /// some condition to cause it to terminate. If you really intend to have
1732 /// an infinite loop, using a `loop` expression is recommended.
1733pub UNCONDITIONAL_RECURSION,
1734 Warn,
1735"functions that cannot return without calling themselves"
1736}17371738#[doc =
r" The `single_use_lifetimes` lint detects lifetimes that are only used"]
#[doc = r" once."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(single_use_lifetimes)]"]
#[doc = r""]
#[doc = r" fn foo<'a>(x: &'a u32) {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Specifying an explicit lifetime like `'a` in a function or `impl`"]
#[doc =
r" should only be used to link together two things. Otherwise, you should"]
#[doc =
r" just use `'_` to indicate that the lifetime is not linked to anything,"]
#[doc = r" or elide the lifetime altogether if possible."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it was introduced at a time"#]
#[doc =
r" when `'_` and elided lifetimes were first being introduced, and this"]
#[doc =
r" lint would be too noisy. Also, there are some known false positives"]
#[doc =
r" that it produces. See [RFC 2115] for historical context, and [issue"]
#[doc = r" #44752] for more details."]
#[doc = r""]
#[doc =
r" [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md"]
#[doc = r" [issue #44752]: https://github.com/rust-lang/rust/issues/44752"]
pub static SINGLE_USE_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "SINGLE_USE_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are only used once",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1739/// The `single_use_lifetimes` lint detects lifetimes that are only used
1740 /// once.
1741 ///
1742 /// ### Example
1743 ///
1744 /// ```rust,compile_fail
1745 /// #![deny(single_use_lifetimes)]
1746 ///
1747 /// fn foo<'a>(x: &'a u32) {}
1748 /// ```
1749 ///
1750 /// {{produces}}
1751 ///
1752 /// ### Explanation
1753 ///
1754 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1755 /// should only be used to link together two things. Otherwise, you should
1756 /// just use `'_` to indicate that the lifetime is not linked to anything,
1757 /// or elide the lifetime altogether if possible.
1758 ///
1759 /// This lint is "allow" by default because it was introduced at a time
1760 /// when `'_` and elided lifetimes were first being introduced, and this
1761 /// lint would be too noisy. Also, there are some known false positives
1762 /// that it produces. See [RFC 2115] for historical context, and [issue
1763 /// #44752] for more details.
1764 ///
1765 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1766 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1767pub SINGLE_USE_LIFETIMES,
1768 Allow,
1769"detects lifetime parameters that are only used once"
1770}17711772#[doc =
r" The `unused_lifetimes` lint detects lifetime parameters that are never"]
#[doc = r" used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[deny(unused_lifetimes)]"]
#[doc = r""]
#[doc = r" pub fn foo<'a>() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused lifetime parameters may signal a mistake or unfinished code."]
#[doc = r" Consider removing the parameter."]
pub static UNUSED_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "UNUSED_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1773/// The `unused_lifetimes` lint detects lifetime parameters that are never
1774 /// used.
1775 ///
1776 /// ### Example
1777 ///
1778 /// ```rust,compile_fail
1779 /// #[deny(unused_lifetimes)]
1780 ///
1781 /// pub fn foo<'a>() {}
1782 /// ```
1783 ///
1784 /// {{produces}}
1785 ///
1786 /// ### Explanation
1787 ///
1788 /// Unused lifetime parameters may signal a mistake or unfinished code.
1789 /// Consider removing the parameter.
1790pub UNUSED_LIFETIMES,
1791 Allow,
1792"detects lifetime parameters that are never used"
1793}17941795#[doc =
r" The `redundant_lifetimes` lint detects lifetime parameters that are"]
#[doc = r" redundant because they are equal to another named lifetime."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #[deny(redundant_lifetimes)]"]
#[doc = r""]
#[doc =
r" // `'a = 'static`, so all usages of `'a` can be replaced with `'static`"]
#[doc = r" pub fn bar<'a: 'static>() {}"]
#[doc = r""]
#[doc = r" // `'a = 'b`, so all usages of `'b` can be replaced with `'a`"]
#[doc = r" pub fn bar<'a: 'b, 'b: 'a>() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused lifetime parameters may signal a mistake or unfinished code."]
#[doc = r" Consider removing the parameter."]
pub static REDUNDANT_LIFETIMES: &crate::Lint =
&crate::Lint {
name: "REDUNDANT_LIFETIMES",
default_level: crate::Allow,
desc: "detects lifetime parameters that are redundant because they are equal to some other named lifetime",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1796/// The `redundant_lifetimes` lint detects lifetime parameters that are
1797 /// redundant because they are equal to another named lifetime.
1798 ///
1799 /// ### Example
1800 ///
1801 /// ```rust,compile_fail
1802 /// #[deny(redundant_lifetimes)]
1803 ///
1804 /// // `'a = 'static`, so all usages of `'a` can be replaced with `'static`
1805 /// pub fn bar<'a: 'static>() {}
1806 ///
1807 /// // `'a = 'b`, so all usages of `'b` can be replaced with `'a`
1808 /// pub fn bar<'a: 'b, 'b: 'a>() {}
1809 /// ```
1810 ///
1811 /// {{produces}}
1812 ///
1813 /// ### Explanation
1814 ///
1815 /// Unused lifetime parameters may signal a mistake or unfinished code.
1816 /// Consider removing the parameter.
1817pub REDUNDANT_LIFETIMES,
1818 Allow,
1819"detects lifetime parameters that are redundant because they are equal to some other named lifetime"
1820}18211822#[doc = r" The `tyvar_behind_raw_pointer` lint detects raw pointer to an"]
#[doc = r" inference variable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2015"]
#[doc = r" // edition 2015"]
#[doc = r" let data = std::ptr::null();"]
#[doc = r" let _ = &data as *const *const ();"]
#[doc = r""]
#[doc = r" if data.is_null() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This kind of inference was previously allowed, but with the future"]
#[doc =
r" arrival of [arbitrary self types], this can introduce ambiguity. To"]
#[doc = r" resolve this, use an explicit type instead of relying on type"]
#[doc = r" inference."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc =
r" error in the 2018 edition. See [issue #46906] for more details. This"]
#[doc = r#" is currently a hard-error on the 2018 edition, and is "warn" by"#]
#[doc = r" default in the 2015 edition."]
#[doc = r""]
#[doc =
r" [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874"]
#[doc = r" [issue #46906]: https://github.com/rust-lang/rust/issues/46906"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static TYVAR_BEHIND_RAW_POINTER: &crate::Lint =
&crate::Lint {
name: "TYVAR_BEHIND_RAW_POINTER",
default_level: crate::Warn,
desc: "raw pointer to an inference variable",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2018,
page_slug: "tyvar-behind-raw-pointer",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1823/// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1824 /// inference variable.
1825 ///
1826 /// ### Example
1827 ///
1828 /// ```rust,edition2015
1829 /// // edition 2015
1830 /// let data = std::ptr::null();
1831 /// let _ = &data as *const *const ();
1832 ///
1833 /// if data.is_null() {}
1834 /// ```
1835 ///
1836 /// {{produces}}
1837 ///
1838 /// ### Explanation
1839 ///
1840 /// This kind of inference was previously allowed, but with the future
1841 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1842 /// resolve this, use an explicit type instead of relying on type
1843 /// inference.
1844 ///
1845 /// This is a [future-incompatible] lint to transition this to a hard
1846 /// error in the 2018 edition. See [issue #46906] for more details. This
1847 /// is currently a hard-error on the 2018 edition, and is "warn" by
1848 /// default in the 2015 edition.
1849 ///
1850 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1851 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1852 /// [future-incompatible]: ../index.md#future-incompatible-lints
1853pub TYVAR_BEHIND_RAW_POINTER,
1854 Warn,
1855"raw pointer to an inference variable",
1856 @future_incompatible = FutureIncompatibleInfo {
1857 reason: fcw!(EditionError 2018 "tyvar-behind-raw-pointer"),
1858 };
1859}18601861#[doc = r" The `elided_lifetimes_in_paths` lint detects the use of hidden"]
#[doc = r" lifetime parameters."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(elided_lifetimes_in_paths)]"]
#[doc = r" #![deny(warnings)]"]
#[doc = r" struct Foo<'a> {"]
#[doc = r" x: &'a u32"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn foo(x: &Foo) {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Elided lifetime parameters can make it difficult to see at a glance"]
#[doc = r" that borrowing is occurring. This lint ensures that lifetime"]
#[doc = r" parameters are always explicitly stated, even if it is the `'_`"]
#[doc = r" [placeholder lifetime]."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because it has some known issues, and"#]
#[doc = r" may require a significant transition for old code."]
#[doc = r""]
#[doc =
r" [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions"]
pub static ELIDED_LIFETIMES_IN_PATHS: &crate::Lint =
&crate::Lint {
name: "ELIDED_LIFETIMES_IN_PATHS",
default_level: crate::Allow,
desc: "hidden lifetime parameters in types are deprecated",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1862/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1863 /// lifetime parameters.
1864 ///
1865 /// ### Example
1866 ///
1867 /// ```rust,compile_fail
1868 /// #![deny(elided_lifetimes_in_paths)]
1869 /// #![deny(warnings)]
1870 /// struct Foo<'a> {
1871 /// x: &'a u32
1872 /// }
1873 ///
1874 /// fn foo(x: &Foo) {
1875 /// }
1876 /// ```
1877 ///
1878 /// {{produces}}
1879 ///
1880 /// ### Explanation
1881 ///
1882 /// Elided lifetime parameters can make it difficult to see at a glance
1883 /// that borrowing is occurring. This lint ensures that lifetime
1884 /// parameters are always explicitly stated, even if it is the `'_`
1885 /// [placeholder lifetime].
1886 ///
1887 /// This lint is "allow" by default because it has some known issues, and
1888 /// may require a significant transition for old code.
1889 ///
1890 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1891pub ELIDED_LIFETIMES_IN_PATHS,
1892 Allow,
1893"hidden lifetime parameters in types are deprecated"
1894}18951896#[doc =
r" The `bare_trait_objects` lint suggests using `dyn Trait` for trait"]
#[doc = r" objects."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018"]
#[doc = r" trait Trait { }"]
#[doc = r""]
#[doc = r" fn takes_trait_object(_: Box<Trait>) {"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Without the `dyn` indicator, it can be ambiguous or confusing when"]
#[doc =
r" reading code as to whether or not you are looking at a trait object."]
#[doc =
r" The `dyn` keyword makes it explicit, and adds a symmetry to contrast"]
#[doc = r" with [`impl Trait`]."]
#[doc = r""]
#[doc =
r" [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters"]
pub static BARE_TRAIT_OBJECTS: &crate::Lint =
&crate::Lint {
name: "BARE_TRAIT_OBJECTS",
default_level: crate::Warn,
desc: "suggest using `dyn Trait` for trait objects",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "warnings-promoted-to-error",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1897/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1898 /// objects.
1899 ///
1900 /// ### Example
1901 ///
1902 /// ```rust,edition2018
1903 /// trait Trait { }
1904 ///
1905 /// fn takes_trait_object(_: Box<Trait>) {
1906 /// }
1907 /// ```
1908 ///
1909 /// {{produces}}
1910 ///
1911 /// ### Explanation
1912 ///
1913 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1914 /// reading code as to whether or not you are looking at a trait object.
1915 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1916 /// with [`impl Trait`].
1917 ///
1918 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1919pub BARE_TRAIT_OBJECTS,
1920 Warn,
1921"suggest using `dyn Trait` for trait objects",
1922 @future_incompatible = FutureIncompatibleInfo {
1923 reason: fcw!(EditionError 2021 "warnings-promoted-to-error"),
1924 };
1925}19261927#[doc = r" The `absolute_paths_not_starting_with_crate` lint detects fully"]
#[doc = r" qualified paths that start with a module name instead of `crate`,"]
#[doc = r" `self`, or an extern crate name"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2015,compile_fail"]
#[doc = r" #![deny(absolute_paths_not_starting_with_crate)]"]
#[doc = r""]
#[doc = r" mod foo {"]
#[doc = r" pub fn bar() {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" ::foo::bar();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Rust [editions] allow the language to evolve without breaking"]
#[doc =
r" backwards compatibility. This lint catches code that uses absolute"]
#[doc =
r" paths in the style of the 2015 edition. In the 2015 edition, absolute"]
#[doc =
r" paths (those starting with `::`) refer to either the crate root or an"]
#[doc =
r" external crate. In the 2018 edition it was changed so that they only"]
#[doc =
r" refer to external crates. The path prefix `crate::` should be used"]
#[doc = r" instead to reference items from the crate root."]
#[doc = r""]
#[doc = r" If you switch the compiler from the 2015 to 2018 edition without"]
#[doc =
r" updating the code, then it will fail to compile if the old style paths"]
#[doc = r" are used. You can manually change the paths to use the `crate::`"]
#[doc = r" prefix to transition to the 2018 edition."]
#[doc = r""]
#[doc =
r#" This lint solves the problem automatically. It is "allow" by default"#]
#[doc =
r" because the code is perfectly valid in the 2015 edition. The [`cargo"]
#[doc =
r#" fix`] tool with the `--edition` flag will switch this lint to "warn""#]
#[doc = r" and automatically apply the suggested fix from the compiler. This"]
#[doc =
r" provides a completely automated way to update old code to the 2018"]
#[doc = r" edition."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
#[doc =
r" [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html"]
pub static ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE: &crate::Lint =
&crate::Lint {
name: "ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE",
default_level: crate::Allow,
desc: "fully qualified paths that start with a module name \
instead of `crate`, `self`, or an extern crate name",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2018,
page_slug: "path-changes",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1928/// The `absolute_paths_not_starting_with_crate` lint detects fully
1929 /// qualified paths that start with a module name instead of `crate`,
1930 /// `self`, or an extern crate name
1931 ///
1932 /// ### Example
1933 ///
1934 /// ```rust,edition2015,compile_fail
1935 /// #![deny(absolute_paths_not_starting_with_crate)]
1936 ///
1937 /// mod foo {
1938 /// pub fn bar() {}
1939 /// }
1940 ///
1941 /// fn main() {
1942 /// ::foo::bar();
1943 /// }
1944 /// ```
1945 ///
1946 /// {{produces}}
1947 ///
1948 /// ### Explanation
1949 ///
1950 /// Rust [editions] allow the language to evolve without breaking
1951 /// backwards compatibility. This lint catches code that uses absolute
1952 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1953 /// paths (those starting with `::`) refer to either the crate root or an
1954 /// external crate. In the 2018 edition it was changed so that they only
1955 /// refer to external crates. The path prefix `crate::` should be used
1956 /// instead to reference items from the crate root.
1957 ///
1958 /// If you switch the compiler from the 2015 to 2018 edition without
1959 /// updating the code, then it will fail to compile if the old style paths
1960 /// are used. You can manually change the paths to use the `crate::`
1961 /// prefix to transition to the 2018 edition.
1962 ///
1963 /// This lint solves the problem automatically. It is "allow" by default
1964 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1965 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1966 /// and automatically apply the suggested fix from the compiler. This
1967 /// provides a completely automated way to update old code to the 2018
1968 /// edition.
1969 ///
1970 /// [editions]: https://doc.rust-lang.org/edition-guide/
1971 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1972pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1973 Allow,
1974"fully qualified paths that start with a module name \
1975 instead of `crate`, `self`, or an extern crate name",
1976 @future_incompatible = FutureIncompatibleInfo {
1977 reason: fcw!(EditionError 2018 "path-changes"),
1978 };
1979}19801981#[doc =
r" The `unstable_name_collisions` lint detects that you have used a name"]
#[doc = r" that the standard library plans to add in the future."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait MyIterator : Iterator {"]
#[doc =
r" // is_partitioned is an unstable method that already exists on the Iterator trait"]
#[doc = r" fn is_partitioned<P>(self, predicate: P) -> bool"]
#[doc = r" where"]
#[doc = r" Self: Sized,"]
#[doc = r" P: FnMut(Self::Item) -> bool,"]
#[doc = r" {true}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<T: ?Sized> MyIterator for T where T: Iterator { }"]
#[doc = r""]
#[doc = r" let x = vec![1, 2, 3];"]
#[doc = r" let _ = x.iter().is_partitioned(|_| true);"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When new methods are added to traits in the standard library, they are"]
#[doc =
r#" usually added in an "unstable" form which is only available on the"#]
#[doc = r" [nightly channel] with a [`feature` attribute]. If there is any"]
#[doc =
r" preexisting code which extends a trait to have a method with the same"]
#[doc =
r" name, then the names will collide. In the future, when the method is"]
#[doc =
r" stabilized, this will cause an error due to the ambiguity. This lint"]
#[doc =
r" is an early-warning to let you know that there may be a collision in"]
#[doc = r" the future. This can be avoided by adding type annotations to"]
#[doc = r" disambiguate which trait method you intend to call, such as"]
#[doc =
r" `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method."]
#[doc = r""]
#[doc =
r" [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html"]
#[doc =
r" [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/"]
pub static UNSTABLE_NAME_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "UNSTABLE_NAME_COLLISIONS",
default_level: crate::Warn,
desc: "detects name collision with an existing but unstable method",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::Custom("once this associated item is added to the standard library, \
the ambiguity may cause an error or change in behavior!",
crate::ReleaseFcw { issue_number: 48919 }),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
1982/// The `unstable_name_collisions` lint detects that you have used a name
1983 /// that the standard library plans to add in the future.
1984 ///
1985 /// ### Example
1986 ///
1987 /// ```rust
1988 /// trait MyIterator : Iterator {
1989 /// // is_partitioned is an unstable method that already exists on the Iterator trait
1990 /// fn is_partitioned<P>(self, predicate: P) -> bool
1991 /// where
1992 /// Self: Sized,
1993 /// P: FnMut(Self::Item) -> bool,
1994 /// {true}
1995 /// }
1996 ///
1997 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1998 ///
1999 /// let x = vec![1, 2, 3];
2000 /// let _ = x.iter().is_partitioned(|_| true);
2001 /// ```
2002 ///
2003 /// {{produces}}
2004 ///
2005 /// ### Explanation
2006 ///
2007 /// When new methods are added to traits in the standard library, they are
2008 /// usually added in an "unstable" form which is only available on the
2009 /// [nightly channel] with a [`feature` attribute]. If there is any
2010 /// preexisting code which extends a trait to have a method with the same
2011 /// name, then the names will collide. In the future, when the method is
2012 /// stabilized, this will cause an error due to the ambiguity. This lint
2013 /// is an early-warning to let you know that there may be a collision in
2014 /// the future. This can be avoided by adding type annotations to
2015 /// disambiguate which trait method you intend to call, such as
2016 /// `MyIterator::is_partitioned(my_iter, my_predicate)` or renaming or removing the method.
2017 ///
2018 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2019 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
2020pub UNSTABLE_NAME_COLLISIONS,
2021 Warn,
2022"detects name collision with an existing but unstable method",
2023 @future_incompatible = FutureIncompatibleInfo {
2024 reason: fcw!(
2025"once this associated item is added to the standard library, \
2026 the ambiguity may cause an error or change in behavior!"
2027#48919
2028),
2029// Note: this item represents future incompatibility of all unstable functions in the
2030 // standard library, and thus should never be removed or changed to an error.
2031};
2032}20332034#[doc =
r" The `irrefutable_let_patterns` lint detects [irrefutable patterns]"]
#[doc = r" in [`if let`]s, [`while let`]s, and `if let` guards."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" if let _ = 123 {"]
#[doc = r#" println!("always runs!");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" There usually isn't a reason to have an irrefutable pattern in an"]
#[doc =
r" `if let` or `while let` statement, because the pattern will always match"]
#[doc =
r" successfully. A [`let`] or [`loop`] statement will suffice. However,"]
#[doc =
r" when generating code with a macro, forbidding irrefutable patterns"]
#[doc = r" would require awkward workarounds in situations where the macro"]
#[doc = r" doesn't know if the pattern is refutable or not. This lint allows"]
#[doc =
r" macros to accept this form, while alerting for a possibly incorrect"]
#[doc = r" use in normal code."]
#[doc = r""]
#[doc = r" See [RFC 2086] for more details."]
#[doc = r""]
#[doc =
r" [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability"]
#[doc =
r" [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions"]
#[doc =
r" [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops"]
#[doc =
r" [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements"]
#[doc =
r" [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops"]
#[doc =
r" [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md"]
pub static IRREFUTABLE_LET_PATTERNS: &crate::Lint =
&crate::Lint {
name: "IRREFUTABLE_LET_PATTERNS",
default_level: crate::Warn,
desc: "detects irrefutable patterns in `if let` and `while let` statements",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2035/// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
2036 /// in [`if let`]s, [`while let`]s, and `if let` guards.
2037 ///
2038 /// ### Example
2039 ///
2040 /// ```rust
2041 /// if let _ = 123 {
2042 /// println!("always runs!");
2043 /// }
2044 /// ```
2045 ///
2046 /// {{produces}}
2047 ///
2048 /// ### Explanation
2049 ///
2050 /// There usually isn't a reason to have an irrefutable pattern in an
2051 /// `if let` or `while let` statement, because the pattern will always match
2052 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
2053 /// when generating code with a macro, forbidding irrefutable patterns
2054 /// would require awkward workarounds in situations where the macro
2055 /// doesn't know if the pattern is refutable or not. This lint allows
2056 /// macros to accept this form, while alerting for a possibly incorrect
2057 /// use in normal code.
2058 ///
2059 /// See [RFC 2086] for more details.
2060 ///
2061 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
2062 /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
2063 /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
2064 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
2065 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
2066 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
2067pub IRREFUTABLE_LET_PATTERNS,
2068 Warn,
2069"detects irrefutable patterns in `if let` and `while let` statements"
2070}20712072#[doc = r" The `unused_labels` lint detects [labels] that are never used."]
#[doc = r""]
#[doc =
r" [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r" 'unused_label: loop {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unused labels may signal a mistake or unfinished code. To silence the"]
#[doc =
r" warning for the individual label, prefix it with an underscore such as"]
#[doc = r" `'_my_label:`."]
pub static UNUSED_LABELS: &crate::Lint =
&crate::Lint {
name: "UNUSED_LABELS",
default_level: crate::Warn,
desc: "detects labels that are never used",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2073/// The `unused_labels` lint detects [labels] that are never used.
2074 ///
2075 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
2076 ///
2077 /// ### Example
2078 ///
2079 /// ```rust,no_run
2080 /// 'unused_label: loop {}
2081 /// ```
2082 ///
2083 /// {{produces}}
2084 ///
2085 /// ### Explanation
2086 ///
2087 /// Unused labels may signal a mistake or unfinished code. To silence the
2088 /// warning for the individual label, prefix it with an underscore such as
2089 /// `'_my_label:`.
2090pub UNUSED_LABELS,
2091 Warn,
2092"detects labels that are never used"
2093}20942095#[doc =
r" The `proc_macro_derive_resolution_fallback` lint detects proc macro"]
#[doc = r" derives using inaccessible names from parent modules."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (proc-macro)"]
#[doc = r" // foo.rs"]
#[doc = r#" #![crate_type = "proc-macro"]"#]
#[doc = r""]
#[doc = r" extern crate proc_macro;"]
#[doc = r""]
#[doc = r" use proc_macro::*;"]
#[doc = r""]
#[doc = r" #[proc_macro_derive(Foo)]"]
#[doc = r" pub fn foo1(a: TokenStream) -> TokenStream {"]
#[doc = r" drop(a);"]
#[doc =
r#" "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" // bar.rs"]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate foo;"]
#[doc = r""]
#[doc = r" struct Something;"]
#[doc = r""]
#[doc = r" #[derive(Foo)]"]
#[doc = r" struct Another;"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: cannot find type `Something` in this scope"]
#[doc = r" --> src/main.rs:8:10"]
#[doc = r" |"]
#[doc = r" 8 | #[derive(Foo)]"]
#[doc =
r" | ^^^ names from parent modules are not accessible without an explicit import"]
#[doc = r" |"]
#[doc =
r" = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" If a proc-macro generates a module, the compiler unintentionally"]
#[doc = r" allowed items in that module to refer to items in the crate root"]
#[doc = r" without importing them. This is a [future-incompatible] lint to"]
#[doc =
r" transition this to a hard error in the future. See [issue #50504] for"]
#[doc = r" more details."]
#[doc = r""]
#[doc = r" [issue #50504]: https://github.com/rust-lang/rust/issues/50504"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PROC_MACRO_DERIVE_RESOLUTION_FALLBACK: &crate::Lint =
&crate::Lint {
name: "PROC_MACRO_DERIVE_RESOLUTION_FALLBACK",
default_level: crate::Deny,
desc: "detects proc macro derives using inaccessible names from parent modules",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 83583,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2096/// The `proc_macro_derive_resolution_fallback` lint detects proc macro
2097 /// derives using inaccessible names from parent modules.
2098 ///
2099 /// ### Example
2100 ///
2101 /// ```rust,ignore (proc-macro)
2102 /// // foo.rs
2103 /// #![crate_type = "proc-macro"]
2104 ///
2105 /// extern crate proc_macro;
2106 ///
2107 /// use proc_macro::*;
2108 ///
2109 /// #[proc_macro_derive(Foo)]
2110 /// pub fn foo1(a: TokenStream) -> TokenStream {
2111 /// drop(a);
2112 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2113 /// }
2114 /// ```
2115 ///
2116 /// ```rust,ignore (needs-dependency)
2117 /// // bar.rs
2118 /// #[macro_use]
2119 /// extern crate foo;
2120 ///
2121 /// struct Something;
2122 ///
2123 /// #[derive(Foo)]
2124 /// struct Another;
2125 ///
2126 /// fn main() {}
2127 /// ```
2128 ///
2129 /// This will produce:
2130 ///
2131 /// ```text
2132 /// warning: cannot find type `Something` in this scope
2133 /// --> src/main.rs:8:10
2134 /// |
2135 /// 8 | #[derive(Foo)]
2136 /// | ^^^ names from parent modules are not accessible without an explicit import
2137 /// |
2138 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2139 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2140 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2141 /// ```
2142 ///
2143 /// ### Explanation
2144 ///
2145 /// If a proc-macro generates a module, the compiler unintentionally
2146 /// allowed items in that module to refer to items in the crate root
2147 /// without importing them. This is a [future-incompatible] lint to
2148 /// transition this to a hard error in the future. See [issue #50504] for
2149 /// more details.
2150 ///
2151 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2152 /// [future-incompatible]: ../index.md#future-incompatible-lints
2153pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2154 Deny,
2155"detects proc macro derives using inaccessible names from parent modules",
2156 @future_incompatible = FutureIncompatibleInfo {
2157 reason: fcw!(FutureReleaseError #83583),
2158 report_in_deps: true,
2159 };
2160}21612162#[doc =
r" The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute]."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #![deny(macro_use_extern_crate)]"]
#[doc = r""]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate serde_json;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let _ = json!{{}};"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated"]
#[doc = r" --> src/main.rs:3:1"]
#[doc = r" |"]
#[doc = r" 3 | #[macro_use]"]
#[doc = r" | ^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = help: remove it and import macros at use sites with a `use` item instead"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> src/main.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![deny(macro_use_extern_crate)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The [`macro_use` attribute] on an [`extern crate`] item causes"]
#[doc =
r" macros in that external crate to be brought into the prelude of the"]
#[doc =
r" crate, making the macros in scope everywhere. As part of the efforts"]
#[doc =
r" to simplify handling of dependencies in the [2018 edition], the use of"]
#[doc =
r" `extern crate` is being phased out. To bring macros from extern crates"]
#[doc = r" into scope, it is recommended to use a [`use` import]."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default because this is a stylistic choice"#]
#[doc =
r" that has not been settled, see [issue #52043] for more information."]
#[doc = r""]
#[doc =
r" [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute"]
#[doc =
r" [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html"]
#[doc = r" [issue #52043]: https://github.com/rust-lang/rust/issues/52043"]
pub static MACRO_USE_EXTERN_CRATE: &crate::Lint =
&crate::Lint {
name: "MACRO_USE_EXTERN_CRATE",
default_level: crate::Allow,
desc: "the `#[macro_use]` attribute is now deprecated in favor of using macros \
via the module system",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2163/// The `macro_use_extern_crate` lint detects the use of the [`macro_use` attribute].
2164 ///
2165 /// ### Example
2166 ///
2167 /// ```rust,ignore (needs extern crate)
2168 /// #![deny(macro_use_extern_crate)]
2169 ///
2170 /// #[macro_use]
2171 /// extern crate serde_json;
2172 ///
2173 /// fn main() {
2174 /// let _ = json!{{}};
2175 /// }
2176 /// ```
2177 ///
2178 /// This will produce:
2179 ///
2180 /// ```text
2181 /// error: applying the `#[macro_use]` attribute to an `extern crate` item is deprecated
2182 /// --> src/main.rs:3:1
2183 /// |
2184 /// 3 | #[macro_use]
2185 /// | ^^^^^^^^^^^^
2186 /// |
2187 /// = help: remove it and import macros at use sites with a `use` item instead
2188 /// note: the lint level is defined here
2189 /// --> src/main.rs:1:9
2190 /// |
2191 /// 1 | #![deny(macro_use_extern_crate)]
2192 /// | ^^^^^^^^^^^^^^^^^^^^^^
2193 /// ```
2194 ///
2195 /// ### Explanation
2196 ///
2197 /// The [`macro_use` attribute] on an [`extern crate`] item causes
2198 /// macros in that external crate to be brought into the prelude of the
2199 /// crate, making the macros in scope everywhere. As part of the efforts
2200 /// to simplify handling of dependencies in the [2018 edition], the use of
2201 /// `extern crate` is being phased out. To bring macros from extern crates
2202 /// into scope, it is recommended to use a [`use` import].
2203 ///
2204 /// This lint is "allow" by default because this is a stylistic choice
2205 /// that has not been settled, see [issue #52043] for more information.
2206 ///
2207 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2208 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2209 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2210pub MACRO_USE_EXTERN_CRATE,
2211 Allow,
2212"the `#[macro_use]` attribute is now deprecated in favor of using macros \
2213 via the module system"
2214}22152216#[doc =
r" The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint"]
#[doc =
r" detects macro-expanded [`macro_export`] macros from the current crate"]
#[doc = r" that cannot be referred to by absolute paths."]
#[doc = r""]
#[doc =
r" [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" macro_rules! define_exported {"]
#[doc = r" () => {"]
#[doc = r" #[macro_export]"]
#[doc = r" macro_rules! exported {"]
#[doc = r" () => {};"]
#[doc = r" }"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" define_exported!();"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" crate::exported!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The intent is that all macros marked with the `#[macro_export]`"]
#[doc =
r" attribute are made available in the root of the crate. However, when a"]
#[doc =
r" `macro_rules!` definition is generated by another macro, the macro"]
#[doc = r" expansion is unable to uphold this rule. This is a"]
#[doc =
r" [future-incompatible] lint to transition this to a hard error in the"]
#[doc = r" future. See [issue #53495] for more details."]
#[doc = r""]
#[doc = r" [issue #53495]: https://github.com/rust-lang/rust/issues/53495"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS:
&crate::Lint =
&crate::Lint {
name: "MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS",
default_level: crate::Deny,
desc: "macro-expanded `macro_export` macros from the current crate \
cannot be referred to by absolute paths",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 52234,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2217/// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2218 /// detects macro-expanded [`macro_export`] macros from the current crate
2219 /// that cannot be referred to by absolute paths.
2220 ///
2221 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2222 ///
2223 /// ### Example
2224 ///
2225 /// ```rust,compile_fail
2226 /// macro_rules! define_exported {
2227 /// () => {
2228 /// #[macro_export]
2229 /// macro_rules! exported {
2230 /// () => {};
2231 /// }
2232 /// };
2233 /// }
2234 ///
2235 /// define_exported!();
2236 ///
2237 /// fn main() {
2238 /// crate::exported!();
2239 /// }
2240 /// ```
2241 ///
2242 /// {{produces}}
2243 ///
2244 /// ### Explanation
2245 ///
2246 /// The intent is that all macros marked with the `#[macro_export]`
2247 /// attribute are made available in the root of the crate. However, when a
2248 /// `macro_rules!` definition is generated by another macro, the macro
2249 /// expansion is unable to uphold this rule. This is a
2250 /// [future-incompatible] lint to transition this to a hard error in the
2251 /// future. See [issue #53495] for more details.
2252 ///
2253 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2254 /// [future-incompatible]: ../index.md#future-incompatible-lints
2255pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2256 Deny,
2257"macro-expanded `macro_export` macros from the current crate \
2258 cannot be referred to by absolute paths",
2259 @future_incompatible = FutureIncompatibleInfo {
2260 reason: fcw!(FutureReleaseError #52234),
2261 report_in_deps: true,
2262 };
2263 crate_level_only
2264}22652266#[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" > [!WARNING]"]
#[doc =
r" > Implicit lifetime bounds are not semantically equivalent to explicit ones since the latter"]
#[doc =
r" > may affect the implicit lifetime bound of trait object types that are passed as arguments"]
#[doc = r" > to the overarching struct, enum or union."]
#[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" > Consequently, removing explicit outlives-bounds on type parameters of publicly reachable types"]
#[doc =
r" > constitutes a **breaking change** if the lifetime refers to a lifetime parameter and"]
#[doc =
r" > the type parameter is not bounded by `Sized` (thereby admitting trait object types)."]
#[doc = r""]
#[doc =
r" [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md"]
#[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",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2267/// The `explicit_outlives_requirements` lint detects unnecessary
2268 /// lifetime bounds that can be inferred.
2269 ///
2270 /// ### Example
2271 ///
2272 /// ```rust,compile_fail
2273 /// # #![allow(unused)]
2274 /// #![deny(explicit_outlives_requirements)]
2275 /// #![deny(warnings)]
2276 ///
2277 /// struct SharedRef<'a, T>
2278 /// where
2279 /// T: 'a,
2280 /// {
2281 /// data: &'a T,
2282 /// }
2283 /// ```
2284 ///
2285 /// {{produces}}
2286 ///
2287 /// ### Explanation
2288 ///
2289 /// If a struct, enum or union contains a reference, such as `&'a T`,
2290 /// the compiler requires that `T` outlives the lifetime `'a`.
2291 /// This historically required writing an explicit lifetime bound to indicate this requirement.
2292 /// However, this can be overly explicit, causing clutter and unnecessary complexity.
2293 /// The language was changed to automatically infer some classes of lifetime bounds
2294 /// if they are not specified.
2295 /// Specifically, if a struct, enum or union contains a reference, directly or indirectly,
2296 /// to `T` with lifetime `'x` and `'x` refers to a lifetime parameter,
2297 /// then it will infer that `T: 'x` is a requirement.
2298 ///
2299 /// See [RFC 2093] for more details.
2300 ///
2301 /// > [!WARNING]
2302 /// > Implicit lifetime bounds are not semantically equivalent to explicit ones since the latter
2303 /// > may affect the implicit lifetime bound of trait object types that are passed as arguments
2304 /// > to the overarching struct, enum or union.
2305 /// > Rephrased, they participate in [trait object lifetime defaulting][TOLD].
2306 /// >
2307 /// > Consider the following piece of code where removing bound `T: 'a` would lead to a lifetime
2308 /// > error in function `scope`:
2309 /// >
2310 /// > ```rust,no_run
2311 /// > struct Ref<'a, T: ?Sized + 'a>(&'a T);
2312 /// >
2313 /// > fn scope() {
2314 /// > let buf = String::new();
2315 /// > let str = buf.as_str();
2316 /// > render(Ref(&str));
2317 /// > }
2318 /// >
2319 /// > fn render(_: Ref<dyn std::fmt::Display>) {}
2320 /// > ```
2321 /// >
2322 /// > Consequently, removing explicit outlives-bounds on type parameters of publicly reachable types
2323 /// > constitutes a **breaking change** if the lifetime refers to a lifetime parameter and
2324 /// > the type parameter is not bounded by `Sized` (thereby admitting trait object types).
2325 ///
2326 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2327 /// [TOLD]: https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes
2328pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2329 Allow,
2330"outlives requirements can be inferred"
2331}23322333#[doc =
r" The `deprecated_in_future` lint is internal to rustc and should not be"]
#[doc = r" used by user code."]
#[doc = r""]
#[doc =
r" This lint is only enabled in the standard library. It works with the"]
#[doc =
r" use of `#[deprecated]` with a `since` field of a version in the future."]
#[doc =
r" This allows something to be marked as deprecated in a future version,"]
#[doc =
r" and then this lint will ensure that the item is no longer used in the"]
#[doc =
r" standard library. See the [stability documentation] for more details."]
#[doc = r""]
#[doc =
r" [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated"]
pub static DEPRECATED_IN_FUTURE: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_IN_FUTURE",
default_level: crate::Allow,
desc: "detects use of items that will be deprecated in a future version",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2334/// The `deprecated_in_future` lint is internal to rustc and should not be
2335 /// used by user code.
2336 ///
2337 /// This lint is only enabled in the standard library. It works with the
2338 /// use of `#[deprecated]` with a `since` field of a version in the future.
2339 /// This allows something to be marked as deprecated in a future version,
2340 /// and then this lint will ensure that the item is no longer used in the
2341 /// standard library. See the [stability documentation] for more details.
2342 ///
2343 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#deprecated
2344pub DEPRECATED_IN_FUTURE,
2345 Allow,
2346"detects use of items that will be deprecated in a future version",
2347 report_in_external_macro
2348}23492350#[doc = r" The `ambiguous_associated_items` lint detects ambiguity between"]
#[doc = r" [associated items] and [enum variants]."]
#[doc = r""]
#[doc =
r" [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html"]
#[doc =
r" [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" enum E {"]
#[doc = r" V"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" trait Tr {"]
#[doc = r" type V;"]
#[doc = r" fn foo() -> Self::V;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Tr for E {"]
#[doc = r" type V = u8;"]
#[doc =
r" // `Self::V` is ambiguous because it may refer to the associated type or"]
#[doc = r" // the enum variant."]
#[doc = r" fn foo() -> Self::V { 0 }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust did not allow accessing enum variants"]
#[doc =
r" through [type aliases]. When this ability was added (see [RFC 2338]), this"]
#[doc = r" introduced some situations where it can be ambiguous what a type"]
#[doc = r" was referring to."]
#[doc = r""]
#[doc =
r" To fix this ambiguity, you should use a [qualified path] to explicitly"]
#[doc = r" state which type to use. For example, in the above example the"]
#[doc = r" function can be written as `fn f() -> <Self as Tr>::V { 0 }` to"]
#[doc = r" specifically refer to the associated type."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a hard"]
#[doc = r" error in the future. See [issue #57644] for more details."]
#[doc = r""]
#[doc = r" [issue #57644]: https://github.com/rust-lang/rust/issues/57644"]
#[doc =
r" [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases"]
#[doc =
r" [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md"]
#[doc =
r" [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_ASSOCIATED_ITEMS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_ASSOCIATED_ITEMS",
default_level: crate::Deny,
desc: "ambiguous associated items",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57644,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2351/// The `ambiguous_associated_items` lint detects ambiguity between
2352 /// [associated items] and [enum variants].
2353 ///
2354 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2355 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2356 ///
2357 /// ### Example
2358 ///
2359 /// ```rust,compile_fail
2360 /// enum E {
2361 /// V
2362 /// }
2363 ///
2364 /// trait Tr {
2365 /// type V;
2366 /// fn foo() -> Self::V;
2367 /// }
2368 ///
2369 /// impl Tr for E {
2370 /// type V = u8;
2371 /// // `Self::V` is ambiguous because it may refer to the associated type or
2372 /// // the enum variant.
2373 /// fn foo() -> Self::V { 0 }
2374 /// }
2375 /// ```
2376 ///
2377 /// {{produces}}
2378 ///
2379 /// ### Explanation
2380 ///
2381 /// Previous versions of Rust did not allow accessing enum variants
2382 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2383 /// introduced some situations where it can be ambiguous what a type
2384 /// was referring to.
2385 ///
2386 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2387 /// state which type to use. For example, in the above example the
2388 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2389 /// specifically refer to the associated type.
2390 ///
2391 /// This is a [future-incompatible] lint to transition this to a hard
2392 /// error in the future. See [issue #57644] for more details.
2393 ///
2394 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2395 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2396 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2397 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2398 /// [future-incompatible]: ../index.md#future-incompatible-lints
2399pub AMBIGUOUS_ASSOCIATED_ITEMS,
2400 Deny,
2401"ambiguous associated items",
2402 @future_incompatible = FutureIncompatibleInfo {
2403 reason: fcw!(FutureReleaseError #57644),
2404 };
2405}24062407#[doc = r" The `inline_no_sanitize` lint detects incompatible use of"]
#[doc =
r#" [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize]."#]
#[doc = r""]
#[doc =
r" [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute"]
#[doc =
r" [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(sanitize)]"]
#[doc = r""]
#[doc = r" #[inline(always)]"]
#[doc = r#" #[sanitize(address = "off")]"#]
#[doc = r" fn x() {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" x()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The use of the [`#[inline(always)]`][inline] attribute prevents the"]
#[doc =
r#" the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working."#]
#[doc = r" Consider temporarily removing `inline` attribute."]
pub static INLINE_NO_SANITIZE: &crate::Lint =
&crate::Lint {
name: "INLINE_NO_SANITIZE",
default_level: crate::Warn,
desc: r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2408/// The `inline_no_sanitize` lint detects incompatible use of
2409 /// [`#[inline(always)]`][inline] and [`#[sanitize(xyz = "off")]`][sanitize].
2410 ///
2411 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2412 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2413 ///
2414 /// ### Example
2415 ///
2416 /// ```rust
2417 /// #![feature(sanitize)]
2418 ///
2419 /// #[inline(always)]
2420 /// #[sanitize(address = "off")]
2421 /// fn x() {}
2422 ///
2423 /// fn main() {
2424 /// x()
2425 /// }
2426 /// ```
2427 ///
2428 /// {{produces}}
2429 ///
2430 /// ### Explanation
2431 ///
2432 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2433 /// the [`#[sanitize(xyz = "off")]`][sanitize] attribute from working.
2434 /// Consider temporarily removing `inline` attribute.
2435pub INLINE_NO_SANITIZE,
2436 Warn,
2437r#"detects incompatible use of `#[inline(always)]` and `#[sanitize(... = "off")]`"#,
2438}24392440#[doc = r" The `rtsan_nonblocking_async` lint detects incompatible use of"]
#[doc =
r#" [`#[sanitize(realtime = "nonblocking")]`][sanitize] on async functions."#]
#[doc = r""]
#[doc =
r" [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html"]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,no_run"]
#[doc = r" #![feature(sanitize)]"]
#[doc = r""]
#[doc = r#" #[sanitize(realtime = "nonblocking")]"#]
#[doc = r" async fn x() {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" x();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The sanitizer only considers the async function body nonblocking. The executor, which runs on"]
#[doc =
r" every `.await` point can run non-realtime code, without the sanitizer catching it."]
pub static RTSAN_NONBLOCKING_ASYNC: &crate::Lint =
&crate::Lint {
name: "RTSAN_NONBLOCKING_ASYNC",
default_level: crate::Warn,
desc: r#"detects incompatible uses of `#[sanitize(realtime = "nonblocking")]` on async functions"#,
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2441/// The `rtsan_nonblocking_async` lint detects incompatible use of
2442 /// [`#[sanitize(realtime = "nonblocking")]`][sanitize] on async functions.
2443 ///
2444 /// [sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2445 /// ### Example
2446 ///
2447 /// ```rust,no_run
2448 /// #![feature(sanitize)]
2449 ///
2450 /// #[sanitize(realtime = "nonblocking")]
2451 /// async fn x() {}
2452 ///
2453 /// fn main() {
2454 /// x();
2455 /// }
2456 /// ```
2457 ///
2458 /// {{produces}}
2459 ///
2460 /// ### Explanation
2461 ///
2462 /// The sanitizer only considers the async function body nonblocking. The executor, which runs on
2463 /// every `.await` point can run non-realtime code, without the sanitizer catching it.
2464pub RTSAN_NONBLOCKING_ASYNC,
2465 Warn,
2466r#"detects incompatible uses of `#[sanitize(realtime = "nonblocking")]` on async functions"#,
2467}24682469#[doc =
r" The `asm_sub_register` lint detects using only a subset of a register"]
#[doc = r" for inline asm inputs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (fails on non-x86_64)"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" use std::arch::asm;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" unsafe {"]
#[doc = r#" asm!("mov {0}, {0}", in(reg) 0i16);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: formatting may not be suitable for sub-register argument"]
#[doc = r" --> src/main.rs:7:19"]
#[doc = r" |"]
#[doc = r#" 7 | asm!("mov {0}, {0}", in(reg) 0i16);"#]
#[doc = r" | ^^^ ^^^ ---- for this argument"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(asm_sub_register)]` on by default"]
#[doc =
r" = help: use the `x` modifier to have the register formatted as `ax`"]
#[doc =
r" = help: or use the `r` modifier to keep the default formatting of `rax`"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Registers on some architectures can use different names to refer to a"]
#[doc =
r" subset of the register. By default, the compiler will use the name for"]
#[doc =
r" the full register size. To explicitly use a subset of the register,"]
#[doc = r" you can override the default by using a modifier on the template"]
#[doc =
r" string operand to specify when subregister to use. This lint is issued"]
#[doc = r" if you pass in a value with a smaller data type than the default"]
#[doc =
r" register size, to alert you of possibly using the incorrect width. To"]
#[doc = r" fix this, add the suggested modifier to the template, or cast the"]
#[doc = r" value to the correct size."]
#[doc = r""]
#[doc =
r" See [register template modifiers] in the reference for more details."]
#[doc = r""]
#[doc =
r" [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers"]
pub static ASM_SUB_REGISTER: &crate::Lint =
&crate::Lint {
name: "ASM_SUB_REGISTER",
default_level: crate::Warn,
desc: "using only a subset of a register for inline asm inputs",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2470/// The `asm_sub_register` lint detects using only a subset of a register
2471 /// for inline asm inputs.
2472 ///
2473 /// ### Example
2474 ///
2475 /// ```rust,ignore (fails on non-x86_64)
2476 /// #[cfg(target_arch="x86_64")]
2477 /// use std::arch::asm;
2478 ///
2479 /// fn main() {
2480 /// #[cfg(target_arch="x86_64")]
2481 /// unsafe {
2482 /// asm!("mov {0}, {0}", in(reg) 0i16);
2483 /// }
2484 /// }
2485 /// ```
2486 ///
2487 /// This will produce:
2488 ///
2489 /// ```text
2490 /// warning: formatting may not be suitable for sub-register argument
2491 /// --> src/main.rs:7:19
2492 /// |
2493 /// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
2494 /// | ^^^ ^^^ ---- for this argument
2495 /// |
2496 /// = note: `#[warn(asm_sub_register)]` on by default
2497 /// = help: use the `x` modifier to have the register formatted as `ax`
2498 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2499 /// ```
2500 ///
2501 /// ### Explanation
2502 ///
2503 /// Registers on some architectures can use different names to refer to a
2504 /// subset of the register. By default, the compiler will use the name for
2505 /// the full register size. To explicitly use a subset of the register,
2506 /// you can override the default by using a modifier on the template
2507 /// string operand to specify when subregister to use. This lint is issued
2508 /// if you pass in a value with a smaller data type than the default
2509 /// register size, to alert you of possibly using the incorrect width. To
2510 /// fix this, add the suggested modifier to the template, or cast the
2511 /// value to the correct size.
2512 ///
2513 /// See [register template modifiers] in the reference for more details.
2514 ///
2515 /// [register template modifiers]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#template-modifiers
2516pub ASM_SUB_REGISTER,
2517 Warn,
2518"using only a subset of a register for inline asm inputs",
2519}25202521#[doc =
r" The `bad_asm_style` lint detects the use of the `.intel_syntax` and"]
#[doc = r" `.att_syntax` directives."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (fails on non-x86_64)"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" use std::arch::asm;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" #[cfg(target_arch="x86_64")]"#]
#[doc = r" unsafe {"]
#[doc = r" asm!("]
#[doc = r#" ".att_syntax","#]
#[doc = r#" "movq %{0}, %{0}", in(reg) 0usize"#]
#[doc = r" );"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead"]
#[doc = r" --> src/main.rs:8:14"]
#[doc = r" |"]
#[doc = r#" 8 | ".att_syntax","#]
#[doc = r" | ^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(bad_asm_style)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On x86, `asm!` uses the intel assembly syntax by default. While this"]
#[doc =
r" can be switched using assembler directives like `.att_syntax`, using the"]
#[doc =
r" `att_syntax` option is recommended instead because it will also properly"]
#[doc = r" prefix register placeholders with `%` as required by AT&T syntax."]
pub static BAD_ASM_STYLE: &crate::Lint =
&crate::Lint {
name: "BAD_ASM_STYLE",
default_level: crate::Warn,
desc: "incorrect use of inline assembly",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2522/// The `bad_asm_style` lint detects the use of the `.intel_syntax` and
2523 /// `.att_syntax` directives.
2524 ///
2525 /// ### Example
2526 ///
2527 /// ```rust,ignore (fails on non-x86_64)
2528 /// #[cfg(target_arch="x86_64")]
2529 /// use std::arch::asm;
2530 ///
2531 /// fn main() {
2532 /// #[cfg(target_arch="x86_64")]
2533 /// unsafe {
2534 /// asm!(
2535 /// ".att_syntax",
2536 /// "movq %{0}, %{0}", in(reg) 0usize
2537 /// );
2538 /// }
2539 /// }
2540 /// ```
2541 ///
2542 /// This will produce:
2543 ///
2544 /// ```text
2545 /// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2546 /// --> src/main.rs:8:14
2547 /// |
2548 /// 8 | ".att_syntax",
2549 /// | ^^^^^^^^^^^
2550 /// |
2551 /// = note: `#[warn(bad_asm_style)]` on by default
2552 /// ```
2553 ///
2554 /// ### Explanation
2555 ///
2556 /// On x86, `asm!` uses the intel assembly syntax by default. While this
2557 /// can be switched using assembler directives like `.att_syntax`, using the
2558 /// `att_syntax` option is recommended instead because it will also properly
2559 /// prefix register placeholders with `%` as required by AT&T syntax.
2560pub BAD_ASM_STYLE,
2561 Warn,
2562"incorrect use of inline assembly",
2563}25642565#[doc =
r" The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe"]
#[doc = r" functions without an explicit unsafe block."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unsafe_op_in_unsafe_fn)]"]
#[doc = r""]
#[doc = r" unsafe fn foo() {}"]
#[doc = r""]
#[doc = r" unsafe fn bar() {"]
#[doc = r" foo();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Currently, an [`unsafe fn`] allows any [unsafe] operation within its"]
#[doc =
r" body. However, this can increase the surface area of code that needs"]
#[doc =
r" to be scrutinized for proper behavior. The [`unsafe` block] provides a"]
#[doc =
r" convenient way to make it clear exactly which parts of the code are"]
#[doc =
r" performing unsafe operations. In the future, it is desired to change"]
#[doc =
r" it so that unsafe operations cannot be performed in an `unsafe fn`"]
#[doc = r" without an `unsafe` block."]
#[doc = r""]
#[doc = r" The fix to this is to wrap the unsafe code in an `unsafe` block."]
#[doc = r""]
#[doc =
r#" This lint is "allow" by default on editions up to 2021, from 2024 it is"#]
#[doc = r#" "warn" by default; the plan for increasing severity further is"#]
#[doc =
r" still being considered. See [RFC #2585] and [issue #71668] for more"]
#[doc = r" details."]
#[doc = r""]
#[doc =
r" [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html"]
#[doc =
r" [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks"]
#[doc = r" [unsafe]: https://doc.rust-lang.org/reference/unsafety.html"]
#[doc =
r" [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md"]
#[doc = r" [issue #71668]: https://github.com/rust-lang/rust/issues/71668"]
pub static UNSAFE_OP_IN_UNSAFE_FN: &crate::Lint =
&crate::Lint {
name: "UNSAFE_OP_IN_UNSAFE_FN",
default_level: crate::Allow,
desc: "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-op-in-unsafe-fn",
}),
explain_reason: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
edition_lint_opts: Some((crate::Edition::Edition2024,
crate::Warn)),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2566/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2567 /// functions without an explicit unsafe block.
2568 ///
2569 /// ### Example
2570 ///
2571 /// ```rust,compile_fail
2572 /// #![deny(unsafe_op_in_unsafe_fn)]
2573 ///
2574 /// unsafe fn foo() {}
2575 ///
2576 /// unsafe fn bar() {
2577 /// foo();
2578 /// }
2579 ///
2580 /// fn main() {}
2581 /// ```
2582 ///
2583 /// {{produces}}
2584 ///
2585 /// ### Explanation
2586 ///
2587 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2588 /// body. However, this can increase the surface area of code that needs
2589 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2590 /// convenient way to make it clear exactly which parts of the code are
2591 /// performing unsafe operations. In the future, it is desired to change
2592 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2593 /// without an `unsafe` block.
2594 ///
2595 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2596 ///
2597 /// This lint is "allow" by default on editions up to 2021, from 2024 it is
2598 /// "warn" by default; the plan for increasing severity further is
2599 /// still being considered. See [RFC #2585] and [issue #71668] for more
2600 /// details.
2601 ///
2602 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2603 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2604 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2605 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2606 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2607pub UNSAFE_OP_IN_UNSAFE_FN,
2608 Allow,
2609"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2610 @future_incompatible = FutureIncompatibleInfo {
2611 reason: fcw!(EditionError 2024 "unsafe-op-in-unsafe-fn"),
2612 explain_reason: false
2613};
2614 @edition Edition2024 => Warn;
2615}26162617#[doc =
r" The `const_evaluatable_unchecked` lint detects a generic constant used"]
#[doc = r" in a type."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" const fn foo<T>() -> usize {"]
#[doc =
r" if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T"]
#[doc = r" 4"]
#[doc = r" } else {"]
#[doc = r" 8"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn test<T>() {"]
#[doc = r" let _ = [0; foo::<T>()];"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In the 1.43 release, some uses of generic parameters in array repeat"]
#[doc =
r" expressions were accidentally allowed. This is a [future-incompatible]"]
#[doc = r" lint to transition this to a hard error in the future. See [issue"]
#[doc = r" #76200] for a more detailed description and possible fixes."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
#[doc = r" [issue #76200]: https://github.com/rust-lang/rust/issues/76200"]
pub static CONST_EVALUATABLE_UNCHECKED: &crate::Lint =
&crate::Lint {
name: "CONST_EVALUATABLE_UNCHECKED",
default_level: crate::Warn,
desc: "detects a generic constant is used in a type without a emitting a warning",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 76200,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2618/// The `const_evaluatable_unchecked` lint detects a generic constant used
2619 /// in a type.
2620 ///
2621 /// ### Example
2622 ///
2623 /// ```rust
2624 /// const fn foo<T>() -> usize {
2625 /// if size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2626 /// 4
2627 /// } else {
2628 /// 8
2629 /// }
2630 /// }
2631 ///
2632 /// fn test<T>() {
2633 /// let _ = [0; foo::<T>()];
2634 /// }
2635 /// ```
2636 ///
2637 /// {{produces}}
2638 ///
2639 /// ### Explanation
2640 ///
2641 /// In the 1.43 release, some uses of generic parameters in array repeat
2642 /// expressions were accidentally allowed. This is a [future-incompatible]
2643 /// lint to transition this to a hard error in the future. See [issue
2644 /// #76200] for a more detailed description and possible fixes.
2645 ///
2646 /// [future-incompatible]: ../index.md#future-incompatible-lints
2647 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2648pub CONST_EVALUATABLE_UNCHECKED,
2649 Warn,
2650"detects a generic constant is used in a type without a emitting a warning",
2651 @future_incompatible = FutureIncompatibleInfo {
2652 reason: fcw!(FutureReleaseError #76200),
2653 };
2654}26552656#[doc =
r" The `function_item_references` lint detects function references that are"]
#[doc = r" formatted with [`fmt::Pointer`] or transmuted."]
#[doc = r""]
#[doc =
r" [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo() { }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" println!("{:p}", &foo);"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Taking a reference to a function may be mistaken as a way to obtain a"]
#[doc = r" pointer to that function. This can give unexpected results when"]
#[doc =
r" formatting the reference as a pointer or transmuting it. This lint is"]
#[doc =
r" issued when function references are formatted as pointers, passed as"]
#[doc = r" arguments bound by [`fmt::Pointer`] or transmuted."]
pub static FUNCTION_ITEM_REFERENCES: &crate::Lint =
&crate::Lint {
name: "FUNCTION_ITEM_REFERENCES",
default_level: crate::Warn,
desc: "suggest casting to a function pointer when attempting to take references to function items",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2657/// The `function_item_references` lint detects function references that are
2658 /// formatted with [`fmt::Pointer`] or transmuted.
2659 ///
2660 /// [`fmt::Pointer`]: https://doc.rust-lang.org/std/fmt/trait.Pointer.html
2661 ///
2662 /// ### Example
2663 ///
2664 /// ```rust
2665 /// fn foo() { }
2666 ///
2667 /// fn main() {
2668 /// println!("{:p}", &foo);
2669 /// }
2670 /// ```
2671 ///
2672 /// {{produces}}
2673 ///
2674 /// ### Explanation
2675 ///
2676 /// Taking a reference to a function may be mistaken as a way to obtain a
2677 /// pointer to that function. This can give unexpected results when
2678 /// formatting the reference as a pointer or transmuting it. This lint is
2679 /// issued when function references are formatted as pointers, passed as
2680 /// arguments bound by [`fmt::Pointer`] or transmuted.
2681pub FUNCTION_ITEM_REFERENCES,
2682 Warn,
2683"suggest casting to a function pointer when attempting to take references to function items",
2684}26852686#[doc = r" The `uninhabited_static` lint detects uninhabited statics."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" enum Void {}"]
#[doc = r" unsafe extern {"]
#[doc = r" static EXTERN: Void;"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Statics with an uninhabited type can never be initialized, so they are impossible to define."]
#[doc =
r" However, this can be side-stepped with an `extern static`, leading to problems later in the"]
#[doc =
r" compiler which assumes that there are no initialized uninhabited places (such as locals or"]
#[doc = r" statics). This was accidentally allowed, but is being phased out."]
pub static UNINHABITED_STATIC: &crate::Lint =
&crate::Lint {
name: "UNINHABITED_STATIC",
default_level: crate::Deny,
desc: "uninhabited static",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 74840,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2687/// The `uninhabited_static` lint detects uninhabited statics.
2688 ///
2689 /// ### Example
2690 ///
2691 /// ```rust,compile_fail
2692 /// enum Void {}
2693 /// unsafe extern {
2694 /// static EXTERN: Void;
2695 /// }
2696 /// ```
2697 ///
2698 /// {{produces}}
2699 ///
2700 /// ### Explanation
2701 ///
2702 /// Statics with an uninhabited type can never be initialized, so they are impossible to define.
2703 /// However, this can be side-stepped with an `extern static`, leading to problems later in the
2704 /// compiler which assumes that there are no initialized uninhabited places (such as locals or
2705 /// statics). This was accidentally allowed, but is being phased out.
2706pub UNINHABITED_STATIC,
2707 Deny,
2708"uninhabited static",
2709 @future_incompatible = FutureIncompatibleInfo {
2710 reason: fcw!(FutureReleaseError #74840),
2711 report_in_deps: true,
2712 };
2713}27142715#[doc =
r" The `unnameable_test_items` lint detects [`#[test]`][test] functions"]
#[doc =
r" that are not able to be run by the test harness because they are in a"]
#[doc = r" position where they are not nameable."]
#[doc = r""]
#[doc =
r" [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,test"]
#[doc = r" fn main() {"]
#[doc = r" #[test]"]
#[doc = r" fn foo() {"]
#[doc = r" // This test will not fail because it does not run."]
#[doc = r" assert_eq!(1, 2);"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In order for the test harness to run a test, the test function must be"]
#[doc =
r" located in a position where it can be accessed from the crate root."]
#[doc =
r" This generally means it must be defined in a module, and not anywhere"]
#[doc =
r" else such as inside another function. The compiler previously allowed"]
#[doc =
r" this without an error, so a lint was added as an alert that a test is"]
#[doc =
r" not being used. Whether or not this should be allowed has not yet been"]
#[doc = r" decided, see [RFC 2471] and [issue #36629]."]
#[doc = r""]
#[doc =
r" [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443"]
#[doc = r" [issue #36629]: https://github.com/rust-lang/rust/issues/36629"]
pub static UNNAMEABLE_TEST_ITEMS: &crate::Lint =
&crate::Lint {
name: "UNNAMEABLE_TEST_ITEMS",
default_level: crate::Warn,
desc: "detects an item that cannot be named being marked as `#[test_case]`",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2716/// The `unnameable_test_items` lint detects [`#[test]`][test] functions
2717 /// that are not able to be run by the test harness because they are in a
2718 /// position where they are not nameable.
2719 ///
2720 /// [test]: https://doc.rust-lang.org/reference/attributes/testing.html#the-test-attribute
2721 ///
2722 /// ### Example
2723 ///
2724 /// ```rust,test
2725 /// fn main() {
2726 /// #[test]
2727 /// fn foo() {
2728 /// // This test will not fail because it does not run.
2729 /// assert_eq!(1, 2);
2730 /// }
2731 /// }
2732 /// ```
2733 ///
2734 /// {{produces}}
2735 ///
2736 /// ### Explanation
2737 ///
2738 /// In order for the test harness to run a test, the test function must be
2739 /// located in a position where it can be accessed from the crate root.
2740 /// This generally means it must be defined in a module, and not anywhere
2741 /// else such as inside another function. The compiler previously allowed
2742 /// this without an error, so a lint was added as an alert that a test is
2743 /// not being used. Whether or not this should be allowed has not yet been
2744 /// decided, see [RFC 2471] and [issue #36629].
2745 ///
2746 /// [RFC 2471]: https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397414443
2747 /// [issue #36629]: https://github.com/rust-lang/rust/issues/36629
2748pub UNNAMEABLE_TEST_ITEMS,
2749 Warn,
2750"detects an item that cannot be named being marked as `#[test_case]`",
2751 report_in_external_macro
2752}27532754#[doc =
r" The `useless_deprecated` lint detects deprecation attributes with no effect."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" struct X;"]
#[doc = r""]
#[doc = r#" #[deprecated = "message"]"#]
#[doc = r" impl Default for X {"]
#[doc = r" fn default() -> Self {"]
#[doc = r" X"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Deprecation attributes have no effect on trait implementations."]
pub static USELESS_DEPRECATED: &crate::Lint =
&crate::Lint {
name: "USELESS_DEPRECATED",
default_level: crate::Deny,
desc: "detects deprecation attributes with no effect",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2755/// The `useless_deprecated` lint detects deprecation attributes with no effect.
2756 ///
2757 /// ### Example
2758 ///
2759 /// ```rust,compile_fail
2760 /// struct X;
2761 ///
2762 /// #[deprecated = "message"]
2763 /// impl Default for X {
2764 /// fn default() -> Self {
2765 /// X
2766 /// }
2767 /// }
2768 /// ```
2769 ///
2770 /// {{produces}}
2771 ///
2772 /// ### Explanation
2773 ///
2774 /// Deprecation attributes have no effect on trait implementations.
2775pub USELESS_DEPRECATED,
2776 Deny,
2777"detects deprecation attributes with no effect",
2778}27792780#[doc =
r" The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(staged_api)]"]
#[doc = r""]
#[doc = r" #[derive(Clone)]"]
#[doc = r#" #[stable(feature = "x", since = "1")]"#]
#[doc = r" struct S {}"]
#[doc = r""]
#[doc = r#" #[unstable(feature = "y", issue = "none")]"#]
#[doc = r" impl Copy for S {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" `staged_api` does not currently support using a stability attribute on `impl` blocks."]
#[doc =
r" `impl`s are always stable if both the type and trait are stable, and always unstable otherwise."]
pub static INEFFECTIVE_UNSTABLE_TRAIT_IMPL: &crate::Lint =
&crate::Lint {
name: "INEFFECTIVE_UNSTABLE_TRAIT_IMPL",
default_level: crate::Deny,
desc: "detects `#[unstable]` on stable trait implementations for stable types",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2781/// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
2782 ///
2783 /// ### Example
2784 ///
2785 /// ```rust,compile_fail
2786 /// #![feature(staged_api)]
2787 ///
2788 /// #[derive(Clone)]
2789 /// #[stable(feature = "x", since = "1")]
2790 /// struct S {}
2791 ///
2792 /// #[unstable(feature = "y", issue = "none")]
2793 /// impl Copy for S {}
2794 /// ```
2795 ///
2796 /// {{produces}}
2797 ///
2798 /// ### Explanation
2799 ///
2800 /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
2801 /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
2802pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2803 Deny,
2804"detects `#[unstable]` on stable trait implementations for stable types"
2805}28062807#[doc =
r" The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor"]
#[doc =
r" was silently allowed due to a bug in the resolver, and which may produce surprising"]
#[doc = r" and unintended behavior."]
#[doc = r""]
#[doc =
r" Using a `Self` type alias from an outer item was never intended, but was silently allowed."]
#[doc =
r" This is deprecated -- and is a hard error when the `Self` type alias references generics"]
#[doc = r" that are not in scope."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(self_constructor_from_outer_item)]"]
#[doc = r""]
#[doc = r" struct S0(usize);"]
#[doc = r""]
#[doc = r" impl S0 {"]
#[doc = r" fn foo() {"]
#[doc = r" const C: S0 = Self(0);"]
#[doc = r" fn bar() -> S0 {"]
#[doc = r" Self(0)"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `Self` type alias should not be reachable because nested items are not associated with"]
#[doc = r" the scope of the parameters from the parent item."]
pub static SELF_CONSTRUCTOR_FROM_OUTER_ITEM: &crate::Lint =
&crate::Lint {
name: "SELF_CONSTRUCTOR_FROM_OUTER_ITEM",
default_level: crate::Warn,
desc: "detect unsupported use of `Self` from outer item",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124186,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2808/// The `self_constructor_from_outer_item` lint detects cases where the `Self` constructor
2809 /// was silently allowed due to a bug in the resolver, and which may produce surprising
2810 /// and unintended behavior.
2811 ///
2812 /// Using a `Self` type alias from an outer item was never intended, but was silently allowed.
2813 /// This is deprecated -- and is a hard error when the `Self` type alias references generics
2814 /// that are not in scope.
2815 ///
2816 /// ### Example
2817 ///
2818 /// ```rust,compile_fail
2819 /// #![deny(self_constructor_from_outer_item)]
2820 ///
2821 /// struct S0(usize);
2822 ///
2823 /// impl S0 {
2824 /// fn foo() {
2825 /// const C: S0 = Self(0);
2826 /// fn bar() -> S0 {
2827 /// Self(0)
2828 /// }
2829 /// }
2830 /// }
2831 /// ```
2832 ///
2833 /// {{produces}}
2834 ///
2835 /// ### Explanation
2836 ///
2837 /// The `Self` type alias should not be reachable because nested items are not associated with
2838 /// the scope of the parameters from the parent item.
2839pub SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
2840 Warn,
2841"detect unsupported use of `Self` from outer item",
2842 @future_incompatible = FutureIncompatibleInfo {
2843 reason: fcw!(FutureReleaseError #124186),
2844 };
2845}28462847#[doc =
r" The `semicolon_in_expressions_from_macros` lint detects trailing semicolons"]
#[doc = r" in macro bodies when the macro is invoked in expression position."]
#[doc = r" This was previous accepted, but is being phased out."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(semicolon_in_expressions_from_macros)]"]
#[doc = r" macro_rules! foo {"]
#[doc = r" () => { true; }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let val = match true {"]
#[doc = r" true => false,"]
#[doc = r" _ => foo!()"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous, Rust ignored trailing semicolon in a macro"]
#[doc = r" body when a macro was invoked in expression position."]
#[doc = r" However, this makes the treatment of semicolons in the language"]
#[doc = r" inconsistent, and could lead to unexpected runtime behavior"]
#[doc = r" in some circumstances (e.g. if the macro author expects"]
#[doc = r" a value to be dropped)."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #79813] for more details."]
#[doc = r""]
#[doc = r" [issue #79813]: https://github.com/rust-lang/rust/issues/79813"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static SEMICOLON_IN_EXPRESSIONS_FROM_MACROS: &crate::Lint =
&crate::Lint {
name: "SEMICOLON_IN_EXPRESSIONS_FROM_MACROS",
default_level: crate::Deny,
desc: "trailing semicolon in macro body used as expression",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 79813,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2848/// The `semicolon_in_expressions_from_macros` lint detects trailing semicolons
2849 /// in macro bodies when the macro is invoked in expression position.
2850 /// This was previous accepted, but is being phased out.
2851 ///
2852 /// ### Example
2853 ///
2854 /// ```rust,compile_fail
2855 /// #![deny(semicolon_in_expressions_from_macros)]
2856 /// macro_rules! foo {
2857 /// () => { true; }
2858 /// }
2859 ///
2860 /// fn main() {
2861 /// let val = match true {
2862 /// true => false,
2863 /// _ => foo!()
2864 /// };
2865 /// }
2866 /// ```
2867 ///
2868 /// {{produces}}
2869 ///
2870 /// ### Explanation
2871 ///
2872 /// Previous, Rust ignored trailing semicolon in a macro
2873 /// body when a macro was invoked in expression position.
2874 /// However, this makes the treatment of semicolons in the language
2875 /// inconsistent, and could lead to unexpected runtime behavior
2876 /// in some circumstances (e.g. if the macro author expects
2877 /// a value to be dropped).
2878 ///
2879 /// This is a [future-incompatible] lint to transition this
2880 /// to a hard error in the future. See [issue #79813] for more details.
2881 ///
2882 /// [issue #79813]: https://github.com/rust-lang/rust/issues/79813
2883 /// [future-incompatible]: ../index.md#future-incompatible-lints
2884pub SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
2885 Deny,
2886"trailing semicolon in macro body used as expression",
2887 @future_incompatible = FutureIncompatibleInfo {
2888 reason: fcw!(FutureReleaseError #79813),
2889 report_in_deps: true,
2890 };
2891}28922893#[doc = r" The `legacy_derive_helpers` lint detects derive helper attributes"]
#[doc = r" that are used before they are introduced."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r#" #[serde(rename_all = "camelCase")]"#]
#[doc = r" #[derive(Deserialize)]"]
#[doc = r" struct S { /* fields */ }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: derive helper attribute is used before it is introduced"]
#[doc = r" --> $DIR/legacy-derive-helpers.rs:1:3"]
#[doc = r" |"]
#[doc = r#" 1 | #[serde(rename_all = "camelCase")]"#]
#[doc = r" | ^^^^^"]
#[doc = r" ..."]
#[doc = r" 2 | #[derive(Deserialize)]"]
#[doc = r" | ----------- the attribute is introduced here"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Attributes like this work for historical reasons, but attribute expansion works in"]
#[doc =
r#" left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look"#]
#[doc =
r#" into the future" at not yet expanded part of the item , but such attempts are not always"#]
#[doc = r" reliable."]
#[doc = r""]
#[doc =
r" To fix the warning place the helper attribute after its corresponding derive."]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" #[derive(Deserialize)]"]
#[doc = r#" #[serde(rename_all = "camelCase")]"#]
#[doc = r" struct S { /* fields */ }"]
#[doc = r" ```"]
pub static LEGACY_DERIVE_HELPERS: &crate::Lint =
&crate::Lint {
name: "LEGACY_DERIVE_HELPERS",
default_level: crate::Deny,
desc: "detects derive helper attributes that are used before they are introduced",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 79202,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2894/// The `legacy_derive_helpers` lint detects derive helper attributes
2895 /// that are used before they are introduced.
2896 ///
2897 /// ### Example
2898 ///
2899 /// ```rust,ignore (needs extern crate)
2900 /// #[serde(rename_all = "camelCase")]
2901 /// #[derive(Deserialize)]
2902 /// struct S { /* fields */ }
2903 /// ```
2904 ///
2905 /// produces:
2906 ///
2907 /// ```text
2908 /// warning: derive helper attribute is used before it is introduced
2909 /// --> $DIR/legacy-derive-helpers.rs:1:3
2910 /// |
2911 /// 1 | #[serde(rename_all = "camelCase")]
2912 /// | ^^^^^
2913 /// ...
2914 /// 2 | #[derive(Deserialize)]
2915 /// | ----------- the attribute is introduced here
2916 /// ```
2917 ///
2918 /// ### Explanation
2919 ///
2920 /// Attributes like this work for historical reasons, but attribute expansion works in
2921 /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
2922 /// into the future" at not yet expanded part of the item , but such attempts are not always
2923 /// reliable.
2924 ///
2925 /// To fix the warning place the helper attribute after its corresponding derive.
2926 /// ```rust,ignore (needs extern crate)
2927 /// #[derive(Deserialize)]
2928 /// #[serde(rename_all = "camelCase")]
2929 /// struct S { /* fields */ }
2930 /// ```
2931pub LEGACY_DERIVE_HELPERS,
2932 Deny,
2933"detects derive helper attributes that are used before they are introduced",
2934 @future_incompatible = FutureIncompatibleInfo {
2935 reason: fcw!(FutureReleaseError #79202),
2936 report_in_deps: true,
2937 };
2938}29392940#[doc = r" The `large_assignments` lint detects when objects of large"]
#[doc = r" types are being moved around."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (can crash on some platforms)"]
#[doc = r" let x = [0; 50000];"]
#[doc = r" let y = x;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: moving a large value"]
#[doc = r" --> $DIR/move-large.rs:1:3"]
#[doc = r" let y = x;"]
#[doc = r" - Copied large value here"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" When using a large type in a plain assignment or in a function"]
#[doc = r" argument, idiomatic code can be inefficient."]
#[doc = r" Ideally appropriate optimizations would resolve this, but such"]
#[doc = r" optimizations are only done in a best-effort manner."]
#[doc =
r" This lint will trigger on all sites of large moves and thus allow the"]
#[doc = r" user to resolve them in code."]
pub static LARGE_ASSIGNMENTS: &crate::Lint =
&crate::Lint {
name: "LARGE_ASSIGNMENTS",
default_level: crate::Warn,
desc: "detects large moves or copies",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2941/// The `large_assignments` lint detects when objects of large
2942 /// types are being moved around.
2943 ///
2944 /// ### Example
2945 ///
2946 /// ```rust,ignore (can crash on some platforms)
2947 /// let x = [0; 50000];
2948 /// let y = x;
2949 /// ```
2950 ///
2951 /// produces:
2952 ///
2953 /// ```text
2954 /// warning: moving a large value
2955 /// --> $DIR/move-large.rs:1:3
2956 /// let y = x;
2957 /// - Copied large value here
2958 /// ```
2959 ///
2960 /// ### Explanation
2961 ///
2962 /// When using a large type in a plain assignment or in a function
2963 /// argument, idiomatic code can be inefficient.
2964 /// Ideally appropriate optimizations would resolve this, but such
2965 /// optimizations are only done in a best-effort manner.
2966 /// This lint will trigger on all sites of large moves and thus allow the
2967 /// user to resolve them in code.
2968pub LARGE_ASSIGNMENTS,
2969 Warn,
2970"detects large moves or copies",
2971}29722973#[doc =
r" The `unexpected_cfgs` lint detects unexpected conditional compilation conditions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" rustc --check-cfg 'cfg()'"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs command line option)"]
#[doc = r" #[cfg(widnows)]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: unexpected `cfg` condition name: `widnows`"]
#[doc = r" --> lint_example.rs:1:7"]
#[doc = r" |"]
#[doc = r" 1 | #[cfg(widnows)]"]
#[doc = r" | ^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(unexpected_cfgs)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is only active when [`--check-cfg`][check-cfg] arguments are being"]
#[doc =
r" passed to the compiler and triggers whenever an unexpected condition name or value is"]
#[doc = r" used."]
#[doc = r""]
#[doc =
r" See the [Checking Conditional Configurations][check-cfg] section for more"]
#[doc = r" details."]
#[doc = r""]
#[doc =
r" See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in"]
#[doc = r" `Cargo.toml`."]
#[doc = r""]
#[doc =
r" [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html"]
#[doc =
r" [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table"]
pub static UNEXPECTED_CFGS: &crate::Lint =
&crate::Lint {
name: "UNEXPECTED_CFGS",
default_level: crate::Warn,
desc: "detects unexpected names and values in `#[cfg]` conditions",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
2974/// The `unexpected_cfgs` lint detects unexpected conditional compilation conditions.
2975 ///
2976 /// ### Example
2977 ///
2978 /// ```text
2979 /// rustc --check-cfg 'cfg()'
2980 /// ```
2981 ///
2982 /// ```rust,ignore (needs command line option)
2983 /// #[cfg(widnows)]
2984 /// fn foo() {}
2985 /// ```
2986 ///
2987 /// This will produce:
2988 ///
2989 /// ```text
2990 /// warning: unexpected `cfg` condition name: `widnows`
2991 /// --> lint_example.rs:1:7
2992 /// |
2993 /// 1 | #[cfg(widnows)]
2994 /// | ^^^^^^^
2995 /// |
2996 /// = note: `#[warn(unexpected_cfgs)]` on by default
2997 /// ```
2998 ///
2999 /// ### Explanation
3000 ///
3001 /// This lint is only active when [`--check-cfg`][check-cfg] arguments are being
3002 /// passed to the compiler and triggers whenever an unexpected condition name or value is
3003 /// used.
3004 ///
3005 /// See the [Checking Conditional Configurations][check-cfg] section for more
3006 /// details.
3007 ///
3008 /// See the [Cargo Specifics][unexpected_cfgs_lint_config] section for configuring this lint in
3009 /// `Cargo.toml`.
3010 ///
3011 /// [check-cfg]: https://doc.rust-lang.org/nightly/rustc/check-cfg.html
3012 /// [unexpected_cfgs_lint_config]: https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html#check-cfg-in-lintsrust-table
3013pub UNEXPECTED_CFGS,
3014 Warn,
3015"detects unexpected names and values in `#[cfg]` conditions",
3016 report_in_external_macro
3017}30183019#[doc =
r" The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" rustc --cfg unix"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs command line option)"]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: unexpected `--cfg unix` flag"]
#[doc = r" |"]
#[doc =
r" = note: config `unix` is only supposed to be controlled by `--target`"]
#[doc =
r" = note: manually setting a built-in cfg can and does create incoherent behaviors"]
#[doc = r" = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Setting builtin cfgs can and does produce incoherent behavior, it's better to the use"]
#[doc =
r" the appropriate `rustc` flag that controls the config. For example setting the `windows`"]
#[doc = r" cfg but on Linux based target."]
pub static EXPLICIT_BUILTIN_CFGS_IN_FLAGS: &crate::Lint =
&crate::Lint {
name: "EXPLICIT_BUILTIN_CFGS_IN_FLAGS",
default_level: crate::Deny,
desc: "detects builtin cfgs set via the `--cfg`",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3020/// The `explicit_builtin_cfgs_in_flags` lint detects builtin cfgs set via the `--cfg` flag.
3021 ///
3022 /// ### Example
3023 ///
3024 /// ```text
3025 /// rustc --cfg unix
3026 /// ```
3027 ///
3028 /// ```rust,ignore (needs command line option)
3029 /// fn main() {}
3030 /// ```
3031 ///
3032 /// This will produce:
3033 ///
3034 /// ```text
3035 /// error: unexpected `--cfg unix` flag
3036 /// |
3037 /// = note: config `unix` is only supposed to be controlled by `--target`
3038 /// = note: manually setting a built-in cfg can and does create incoherent behaviors
3039 /// = note: `#[deny(explicit_builtin_cfgs_in_flags)]` on by default
3040 /// ```
3041 ///
3042 /// ### Explanation
3043 ///
3044 /// Setting builtin cfgs can and does produce incoherent behavior, it's better to the use
3045 /// the appropriate `rustc` flag that controls the config. For example setting the `windows`
3046 /// cfg but on Linux based target.
3047pub EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
3048 Deny,
3049"detects builtin cfgs set via the `--cfg`"
3050}30513052#[doc =
r" The `unstable_syntax_pre_expansion` lint detects the use of unstable"]
#[doc = r" syntax that is discarded during attribute expansion."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r#" #[cfg(feature = "nightly")]"#]
#[doc = r" macro foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The input to active attributes such as `#[cfg]` or procedural macro"]
#[doc =
r" attributes is required to be valid syntax. Previously, the compiler only"]
#[doc =
r" gated the use of unstable syntax features after resolving `#[cfg]` gates"]
#[doc = r" and expanding procedural macros."]
#[doc = r""]
#[doc =
r" To avoid relying on unstable syntax, move the use of unstable syntax"]
#[doc =
r" into a position where the compiler does not parse the syntax, such as a"]
#[doc = r" functionlike macro."]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" # #![deny(unstable_syntax_pre_expansion)]"]
#[doc = r""]
#[doc = r" macro_rules! identity {"]
#[doc = r" ( $($tokens:tt)* ) => { $($tokens)* }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r#" #[cfg(feature = "nightly")]"#]
#[doc = r" identity! {"]
#[doc = r" macro foo() {}"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this"]
#[doc =
r" to a hard error in the future. See [issue #154045] for more details."]
#[doc = r""]
#[doc = r" [issue #154045]: https://github.com/rust-lang/rust/issues/154045"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static UNSTABLE_SYNTAX_PRE_EXPANSION: &crate::Lint =
&crate::Lint {
name: "UNSTABLE_SYNTAX_PRE_EXPANSION",
default_level: crate::Warn,
desc: "unstable syntax can change at any point in the future, causing a hard error!",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 154045,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3053/// The `unstable_syntax_pre_expansion` lint detects the use of unstable
3054 /// syntax that is discarded during attribute expansion.
3055 ///
3056 /// ### Example
3057 ///
3058 /// ```rust
3059 /// #[cfg(feature = "nightly")]
3060 /// macro foo() {}
3061 /// ```
3062 ///
3063 /// {{produces}}
3064 ///
3065 /// ### Explanation
3066 ///
3067 /// The input to active attributes such as `#[cfg]` or procedural macro
3068 /// attributes is required to be valid syntax. Previously, the compiler only
3069 /// gated the use of unstable syntax features after resolving `#[cfg]` gates
3070 /// and expanding procedural macros.
3071 ///
3072 /// To avoid relying on unstable syntax, move the use of unstable syntax
3073 /// into a position where the compiler does not parse the syntax, such as a
3074 /// functionlike macro.
3075 ///
3076 /// ```rust
3077 /// # #![deny(unstable_syntax_pre_expansion)]
3078 ///
3079 /// macro_rules! identity {
3080 /// ( $($tokens:tt)* ) => { $($tokens)* }
3081 /// }
3082 ///
3083 /// #[cfg(feature = "nightly")]
3084 /// identity! {
3085 /// macro foo() {}
3086 /// }
3087 /// ```
3088 ///
3089 /// This is a [future-incompatible] lint to transition this
3090 /// to a hard error in the future. See [issue #154045] for more details.
3091 ///
3092 /// [issue #154045]: https://github.com/rust-lang/rust/issues/154045
3093 /// [future-incompatible]: ../index.md#future-incompatible-lints
3094pub UNSTABLE_SYNTAX_PRE_EXPANSION,
3095 Warn,
3096"unstable syntax can change at any point in the future, causing a hard error!",
3097 @future_incompatible = FutureIncompatibleInfo {
3098 reason: fcw!(FutureReleaseError #154045),
3099 };
3100}31013102#[doc =
r" The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs"]
#[doc =
r" collide. Downstream users trying to use the same name re-exported from multiple globs"]
#[doc =
r" will receive a warning pointing out redefinition of the same name."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_glob_reexports)]"]
#[doc = r" pub mod foo {"]
#[doc = r" pub type X = u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub mod bar {"]
#[doc = r" pub type Y = u8;"]
#[doc = r" pub type X = u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub use foo::*;"]
#[doc = r" pub use bar::*;"]
#[doc = r""]
#[doc = r""]
#[doc = r" pub fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This was previously accepted but it could silently break a crate's downstream users code."]
#[doc =
r" For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the"]
#[doc =
r" re-exports, down stream users could use `this_crate::X` without problems. However, adding"]
#[doc =
r" `bar::X` would cause compilation errors in downstream crates because `X` is defined"]
#[doc = r" multiple times in the same namespace of `this_crate`."]
pub static AMBIGUOUS_GLOB_REEXPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_REEXPORTS",
default_level: crate::Warn,
desc: "ambiguous glob re-exports",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3103/// The `ambiguous_glob_reexports` lint detects cases where names re-exported via globs
3104 /// collide. Downstream users trying to use the same name re-exported from multiple globs
3105 /// will receive a warning pointing out redefinition of the same name.
3106 ///
3107 /// ### Example
3108 ///
3109 /// ```rust,compile_fail
3110 /// #![deny(ambiguous_glob_reexports)]
3111 /// pub mod foo {
3112 /// pub type X = u8;
3113 /// }
3114 ///
3115 /// pub mod bar {
3116 /// pub type Y = u8;
3117 /// pub type X = u8;
3118 /// }
3119 ///
3120 /// pub use foo::*;
3121 /// pub use bar::*;
3122 ///
3123 ///
3124 /// pub fn main() {}
3125 /// ```
3126 ///
3127 /// {{produces}}
3128 ///
3129 /// ### Explanation
3130 ///
3131 /// This was previously accepted but it could silently break a crate's downstream users code.
3132 /// For example, if `foo::*` and `bar::*` were re-exported before `bar::X` was added to the
3133 /// re-exports, down stream users could use `this_crate::X` without problems. However, adding
3134 /// `bar::X` would cause compilation errors in downstream crates because `X` is defined
3135 /// multiple times in the same namespace of `this_crate`.
3136pub AMBIGUOUS_GLOB_REEXPORTS,
3137 Warn,
3138"ambiguous glob re-exports",
3139}31403141#[doc =
r" The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by"]
#[doc = r" private items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(hidden_glob_reexports)]"]
#[doc = r""]
#[doc = r" pub mod upstream {"]
#[doc = r" mod inner { pub struct Foo {}; pub struct Bar {}; }"]
#[doc = r" pub use self::inner::*;"]
#[doc = r" struct Foo {} // private item shadows `inner::Foo`"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" // mod downstream {"]
#[doc = r" // fn test() {"]
#[doc = r" // let _ = crate::upstream::Foo; // inaccessible"]
#[doc = r" // }"]
#[doc = r" // }"]
#[doc = r""]
#[doc = r" pub fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This was previously accepted without any errors or warnings but it could silently break a"]
#[doc =
r" crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would"]
#[doc =
r#" silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at"#]
#[doc = r" the downstream use site."]
pub static HIDDEN_GLOB_REEXPORTS: &crate::Lint =
&crate::Lint {
name: "HIDDEN_GLOB_REEXPORTS",
default_level: crate::Warn,
desc: "name introduced by a private item shadows a name introduced by a public glob re-export",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3142/// The `hidden_glob_reexports` lint detects cases where glob re-export items are shadowed by
3143 /// private items.
3144 ///
3145 /// ### Example
3146 ///
3147 /// ```rust,compile_fail
3148 /// #![deny(hidden_glob_reexports)]
3149 ///
3150 /// pub mod upstream {
3151 /// mod inner { pub struct Foo {}; pub struct Bar {}; }
3152 /// pub use self::inner::*;
3153 /// struct Foo {} // private item shadows `inner::Foo`
3154 /// }
3155 ///
3156 /// // mod downstream {
3157 /// // fn test() {
3158 /// // let _ = crate::upstream::Foo; // inaccessible
3159 /// // }
3160 /// // }
3161 ///
3162 /// pub fn main() {}
3163 /// ```
3164 ///
3165 /// {{produces}}
3166 ///
3167 /// ### Explanation
3168 ///
3169 /// This was previously accepted without any errors or warnings but it could silently break a
3170 /// crate's downstream user code. If the `struct Foo` was added, `dep::inner::Foo` would
3171 /// silently become inaccessible and trigger a "`struct `Foo` is private`" visibility error at
3172 /// the downstream use site.
3173pub HIDDEN_GLOB_REEXPORTS,
3174 Warn,
3175"name introduced by a private item shadows a name introduced by a public glob re-export",
3176}31773178#[doc = r" The `long_running_const_eval` lint is emitted when const"]
#[doc = r" eval is running for a long time to ensure rustc terminates"]
#[doc = r" even if you accidentally wrote an infinite loop."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" const FOO: () = loop {};"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Loops allow const evaluation to compute arbitrary code, but may also"]
#[doc = r" cause infinite loops or just very long running computations."]
#[doc = r" Users can enable long running computations by allowing the lint"]
#[doc = r" on individual constants or for entire crates."]
#[doc = r""]
#[doc = r" ### Unconditional warnings"]
#[doc = r""]
#[doc =
r" Note that regardless of whether the lint is allowed or set to warn,"]
#[doc =
r" the compiler will issue warnings if constant evaluation runs significantly"]
#[doc =
r" longer than this lint's limit. These warnings are also shown to downstream"]
#[doc =
r" users from crates.io or similar registries. If you are above the lint's limit,"]
#[doc = r" both you and downstream users might be exposed to these warnings."]
#[doc =
r" They might also appear on compiler updates, as the compiler makes minor changes"]
#[doc =
r" about how complexity is measured: staying below the limit ensures that there"]
#[doc =
r" is enough room, and given that the lint is disabled for people who use your"]
#[doc =
r" dependency it means you will be the only one to get the warning and can put"]
#[doc = r" out an update in your own time."]
pub static LONG_RUNNING_CONST_EVAL: &crate::Lint =
&crate::Lint {
name: "LONG_RUNNING_CONST_EVAL",
default_level: crate::Deny,
desc: "detects long const eval operations",
is_externally_loaded: false,
report_in_external_macro: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3179/// The `long_running_const_eval` lint is emitted when const
3180 /// eval is running for a long time to ensure rustc terminates
3181 /// even if you accidentally wrote an infinite loop.
3182 ///
3183 /// ### Example
3184 ///
3185 /// ```rust,compile_fail
3186 /// const FOO: () = loop {};
3187 /// ```
3188 ///
3189 /// {{produces}}
3190 ///
3191 /// ### Explanation
3192 ///
3193 /// Loops allow const evaluation to compute arbitrary code, but may also
3194 /// cause infinite loops or just very long running computations.
3195 /// Users can enable long running computations by allowing the lint
3196 /// on individual constants or for entire crates.
3197 ///
3198 /// ### Unconditional warnings
3199 ///
3200 /// Note that regardless of whether the lint is allowed or set to warn,
3201 /// the compiler will issue warnings if constant evaluation runs significantly
3202 /// longer than this lint's limit. These warnings are also shown to downstream
3203 /// users from crates.io or similar registries. If you are above the lint's limit,
3204 /// both you and downstream users might be exposed to these warnings.
3205 /// They might also appear on compiler updates, as the compiler makes minor changes
3206 /// about how complexity is measured: staying below the limit ensures that there
3207 /// is enough room, and given that the lint is disabled for people who use your
3208 /// dependency it means you will be the only one to get the warning and can put
3209 /// out an update in your own time.
3210pub LONG_RUNNING_CONST_EVAL,
3211 Deny,
3212"detects long const eval operations",
3213 report_in_external_macro
3214}32153216#[doc = r" The `unused_associated_type_bounds` lint is emitted when an"]
#[doc =
r" associated type bound is added to a trait object, but the associated"]
#[doc =
r" type has a `where Self: Sized` bound, and is thus unavailable on the"]
#[doc = r" trait object anyway."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Foo {"]
#[doc = r" type Bar where Self: Sized;"]
#[doc = r" }"]
#[doc = r" type Mop = dyn Foo<Bar = ()>;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Just like methods with `Self: Sized` bounds are unavailable on trait"]
#[doc = r" objects, associated types can be removed from the trait object."]
pub static UNUSED_ASSOCIATED_TYPE_BOUNDS: &crate::Lint =
&crate::Lint {
name: "UNUSED_ASSOCIATED_TYPE_BOUNDS",
default_level: crate::Warn,
desc: "detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3217/// The `unused_associated_type_bounds` lint is emitted when an
3218 /// associated type bound is added to a trait object, but the associated
3219 /// type has a `where Self: Sized` bound, and is thus unavailable on the
3220 /// trait object anyway.
3221 ///
3222 /// ### Example
3223 ///
3224 /// ```rust
3225 /// trait Foo {
3226 /// type Bar where Self: Sized;
3227 /// }
3228 /// type Mop = dyn Foo<Bar = ()>;
3229 /// ```
3230 ///
3231 /// {{produces}}
3232 ///
3233 /// ### Explanation
3234 ///
3235 /// Just like methods with `Self: Sized` bounds are unavailable on trait
3236 /// objects, associated types can be removed from the trait object.
3237pub UNUSED_ASSOCIATED_TYPE_BOUNDS,
3238 Warn,
3239"detects unused `Foo = Bar` bounds in `dyn Trait<Foo = Bar>`"
3240}32413242#[doc =
r" The `unused_doc_comments` lint detects doc comments that aren't used"]
#[doc = r" by `rustdoc`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" /// docs for x"]
#[doc = r" let x = 12;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" `rustdoc` does not use doc comments in all positions, and so the doc"]
#[doc =
r" comment will be ignored. Try changing it to a normal comment with `//`"]
#[doc = r" to avoid the warning."]
pub static UNUSED_DOC_COMMENTS: &crate::Lint =
&crate::Lint {
name: "UNUSED_DOC_COMMENTS",
default_level: crate::Warn,
desc: "detects doc comments that aren't used by rustdoc",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3243/// The `unused_doc_comments` lint detects doc comments that aren't used
3244 /// by `rustdoc`.
3245 ///
3246 /// ### Example
3247 ///
3248 /// ```rust
3249 /// /// docs for x
3250 /// let x = 12;
3251 /// ```
3252 ///
3253 /// {{produces}}
3254 ///
3255 /// ### Explanation
3256 ///
3257 /// `rustdoc` does not use doc comments in all positions, and so the doc
3258 /// comment will be ignored. Try changing it to a normal comment with `//`
3259 /// to avoid the warning.
3260pub UNUSED_DOC_COMMENTS,
3261 Warn,
3262"detects doc comments that aren't used by rustdoc"
3263}32643265#[doc =
r" The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely"]
#[doc =
r" captured in Rust 2021, such that the `Drop` order of their fields may differ between"]
#[doc = r" Rust 2018 and 2021."]
#[doc = r""]
#[doc =
r" It can also detect when a variable implements a trait like `Send`, but one of its fields does not,"]
#[doc =
r" and the field is captured by a closure and used with the assumption that said field implements"]
#[doc = r" the same trait as the root variable."]
#[doc = r""]
#[doc = r" ### Example of drop reorder"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_closure_captures)]"]
#[doc = r" # #![allow(unused)]"]
#[doc = r""]
#[doc = r" struct FancyInteger(i32);"]
#[doc = r""]
#[doc = r" impl Drop for FancyInteger {"]
#[doc = r" fn drop(&mut self) {"]
#[doc = r#" println!("Just dropped {}", self.0);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" struct Point { x: FancyInteger, y: FancyInteger }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let p = Point { x: FancyInteger(10), y: FancyInteger(20) };"]
#[doc = r""]
#[doc = r" let c = || {"]
#[doc = r" let x = p.x;"]
#[doc = r" };"]
#[doc = r""]
#[doc = r" c();"]
#[doc = r""]
#[doc = r" // ... More code ..."]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In the above example, `p.y` will be dropped at the end of `f` instead of"]
#[doc = r" with `c` in Rust 2021."]
#[doc = r""]
#[doc = r" ### Example of auto-trait"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_closure_captures)]"]
#[doc = r" use std::thread;"]
#[doc = r""]
#[doc = r" struct Pointer(*mut i32);"]
#[doc = r" unsafe impl Send for Pointer {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let mut f = 10;"]
#[doc = r" let fptr = Pointer(&mut f as *mut i32);"]
#[doc = r" thread::spawn(move || unsafe {"]
#[doc = r" *fptr.0 = 20;"]
#[doc = r" });"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In the above example, only `fptr.0` is captured in Rust 2021."]
#[doc = r" The field is of type `*mut i32`, which doesn't implement `Send`,"]
#[doc =
r" making the code invalid as the field cannot be sent between threads safely."]
pub static RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES: &crate::Lint =
&crate::Lint {
name: "RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES",
default_level: crate::Allow,
desc: "detects closures affected by Rust 2021 changes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "disjoint-capture-in-closures",
}),
explain_reason: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3266/// The `rust_2021_incompatible_closure_captures` lint detects variables that aren't completely
3267 /// captured in Rust 2021, such that the `Drop` order of their fields may differ between
3268 /// Rust 2018 and 2021.
3269 ///
3270 /// It can also detect when a variable implements a trait like `Send`, but one of its fields does not,
3271 /// and the field is captured by a closure and used with the assumption that said field implements
3272 /// the same trait as the root variable.
3273 ///
3274 /// ### Example of drop reorder
3275 ///
3276 /// ```rust,edition2018,compile_fail
3277 /// #![deny(rust_2021_incompatible_closure_captures)]
3278 /// # #![allow(unused)]
3279 ///
3280 /// struct FancyInteger(i32);
3281 ///
3282 /// impl Drop for FancyInteger {
3283 /// fn drop(&mut self) {
3284 /// println!("Just dropped {}", self.0);
3285 /// }
3286 /// }
3287 ///
3288 /// struct Point { x: FancyInteger, y: FancyInteger }
3289 ///
3290 /// fn main() {
3291 /// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
3292 ///
3293 /// let c = || {
3294 /// let x = p.x;
3295 /// };
3296 ///
3297 /// c();
3298 ///
3299 /// // ... More code ...
3300 /// }
3301 /// ```
3302 ///
3303 /// {{produces}}
3304 ///
3305 /// ### Explanation
3306 ///
3307 /// In the above example, `p.y` will be dropped at the end of `f` instead of
3308 /// with `c` in Rust 2021.
3309 ///
3310 /// ### Example of auto-trait
3311 ///
3312 /// ```rust,edition2018,compile_fail
3313 /// #![deny(rust_2021_incompatible_closure_captures)]
3314 /// use std::thread;
3315 ///
3316 /// struct Pointer(*mut i32);
3317 /// unsafe impl Send for Pointer {}
3318 ///
3319 /// fn main() {
3320 /// let mut f = 10;
3321 /// let fptr = Pointer(&mut f as *mut i32);
3322 /// thread::spawn(move || unsafe {
3323 /// *fptr.0 = 20;
3324 /// });
3325 /// }
3326 /// ```
3327 ///
3328 /// {{produces}}
3329 ///
3330 /// ### Explanation
3331 ///
3332 /// In the above example, only `fptr.0` is captured in Rust 2021.
3333 /// The field is of type `*mut i32`, which doesn't implement `Send`,
3334 /// making the code invalid as the field cannot be sent between threads safely.
3335pub RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES,
3336 Allow,
3337"detects closures affected by Rust 2021 changes",
3338 @future_incompatible = FutureIncompatibleInfo {
3339 reason: fcw!(EditionSemanticsChange 2021 "disjoint-capture-in-closures"),
3340 explain_reason: false,
3341 };
3342}33433344pub struct UnusedDocComment;
#[automatically_derived]
impl ::core::marker::Copy for UnusedDocComment { }
#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for UnusedDocComment { }
#[automatically_derived]
impl ::core::clone::Clone for UnusedDocComment {
#[inline]
fn clone(&self) -> UnusedDocComment { *self }
}
impl crate::LintPass for UnusedDocComment {
fn name(&self) -> &'static str { "UnusedDocComment" }
fn get_lints(&self) -> crate::LintVec {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[UNUSED_DOC_COMMENTS]))
}
}
impl UnusedDocComment {
#[allow(unused)]
pub fn lint_vec() -> crate::LintVec {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[UNUSED_DOC_COMMENTS]))
}
}declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
33453346#[doc =
r" The `missing_abi` lint detects cases where the ABI is omitted from"]
#[doc = r" `extern` declarations."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(missing_abi)]"]
#[doc = r""]
#[doc = r" extern fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" For historic reasons, Rust implicitly selects `C` as the default ABI for"]
#[doc =
r" `extern` declarations. [Other ABIs] like `C-unwind` and `system` have"]
#[doc =
r" been added since then, and especially with their addition seeing the ABI"]
#[doc = r" easily makes code review easier."]
#[doc = r""]
#[doc =
r" [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi"]
pub static MISSING_ABI: &crate::Lint =
&crate::Lint {
name: "MISSING_ABI",
default_level: crate::Warn,
desc: "No declared ABI for extern declaration",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3347/// The `missing_abi` lint detects cases where the ABI is omitted from
3348 /// `extern` declarations.
3349 ///
3350 /// ### Example
3351 ///
3352 /// ```rust,compile_fail
3353 /// #![deny(missing_abi)]
3354 ///
3355 /// extern fn foo() {}
3356 /// ```
3357 ///
3358 /// {{produces}}
3359 ///
3360 /// ### Explanation
3361 ///
3362 /// For historic reasons, Rust implicitly selects `C` as the default ABI for
3363 /// `extern` declarations. [Other ABIs] like `C-unwind` and `system` have
3364 /// been added since then, and especially with their addition seeing the ABI
3365 /// easily makes code review easier.
3366 ///
3367 /// [Other ABIs]: https://doc.rust-lang.org/reference/items/external-blocks.html#abi
3368pub MISSING_ABI,
3369 Warn,
3370"No declared ABI for extern declaration"
3371}33723373#[doc =
r" The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is"]
#[doc = r" misused."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(warnings)]"]
#[doc = r""]
#[doc = r" pub mod submodule {"]
#[doc = r" #![doc(test(no_crate_inject))]"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previously, incorrect usage of the `#[doc(..)]` attribute was not"]
#[doc =
r" being validated. Usually these should be rejected as a hard error,"]
#[doc = r" but this lint was introduced to avoid breaking any existing"]
#[doc = r" crates which included them."]
pub static INVALID_DOC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "INVALID_DOC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects invalid `#[doc(...)]` attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3374/// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
3375 /// misused.
3376 ///
3377 /// ### Example
3378 ///
3379 /// ```rust,compile_fail
3380 /// #![deny(warnings)]
3381 ///
3382 /// pub mod submodule {
3383 /// #![doc(test(no_crate_inject))]
3384 /// }
3385 /// ```
3386 ///
3387 /// {{produces}}
3388 ///
3389 /// ### Explanation
3390 ///
3391 /// Previously, incorrect usage of the `#[doc(..)]` attribute was not
3392 /// being validated. Usually these should be rejected as a hard error,
3393 /// but this lint was introduced to avoid breaking any existing
3394 /// crates which included them.
3395pub INVALID_DOC_ATTRIBUTES,
3396 Warn,
3397"detects invalid `#[doc(...)]` attributes",
3398}33993400#[doc =
r" The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_incompatible_or_patterns)]"]
#[doc = r""]
#[doc = r" macro_rules! match_any {"]
#[doc =
r" ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {"]
#[doc = r" match $expr {"]
#[doc = r" $("]
#[doc = r" $( $pat => $expr_arm, )+"]
#[doc = r" )+"]
#[doc = r" }"]
#[doc = r" };"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" let result: Result<i64, i32> = Err(42);"]
#[doc =
r" let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());"]
#[doc = r" assert_eq!(int, 42);"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character."]
pub static RUST_2021_INCOMPATIBLE_OR_PATTERNS: &crate::Lint =
&crate::Lint {
name: "RUST_2021_INCOMPATIBLE_OR_PATTERNS",
default_level: crate::Allow,
desc: "detects usage of old versions of or-patterns",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "or-patterns-macro-rules",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3401/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
3402 ///
3403 /// ### Example
3404 ///
3405 /// ```rust,edition2018,compile_fail
3406 /// #![deny(rust_2021_incompatible_or_patterns)]
3407 ///
3408 /// macro_rules! match_any {
3409 /// ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => {
3410 /// match $expr {
3411 /// $(
3412 /// $( $pat => $expr_arm, )+
3413 /// )+
3414 /// }
3415 /// };
3416 /// }
3417 ///
3418 /// fn main() {
3419 /// let result: Result<i64, i32> = Err(42);
3420 /// let int: i64 = match_any!(result, Ok(i) | Err(i) => i.into());
3421 /// assert_eq!(int, 42);
3422 /// }
3423 /// ```
3424 ///
3425 /// {{produces}}
3426 ///
3427 /// ### Explanation
3428 ///
3429 /// In Rust 2021, the `pat` matcher will match additional patterns, which include the `|` character.
3430pub RUST_2021_INCOMPATIBLE_OR_PATTERNS,
3431 Allow,
3432"detects usage of old versions of or-patterns",
3433 @future_incompatible = FutureIncompatibleInfo {
3434 reason: fcw!(EditionError 2021 "or-patterns-macro-rules"),
3435 };
3436}34373438#[doc =
r" The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous"]
#[doc = r" with traits added to the prelude in future editions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_prelude_collisions)]"]
#[doc = r""]
#[doc = r" trait Foo {"]
#[doc = r" fn try_into(self) -> Result<String, !>;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Foo for &str {"]
#[doc = r" fn try_into(self) -> Result<String, !> {"]
#[doc = r" Ok(String::from(self))"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r#" let x: String = "3".try_into().unwrap();"#]
#[doc = r" // ^^^^^^^^"]
#[doc =
r" // This call to try_into matches both Foo::try_into and TryInto::try_into as"]
#[doc =
r" // `TryInto` has been added to the Rust prelude in 2021 edition."]
#[doc = r#" println!("{x}");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust 2021, one of the important introductions is the [prelude changes], which add"]
#[doc =
r" `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this"]
#[doc =
r" results in an ambiguity as to which method/function to call when an existing `try_into`"]
#[doc =
r" method is called via dot-call syntax or a `try_from`/`from_iter` associated function"]
#[doc = r" is called directly on a type."]
#[doc = r""]
#[doc =
r" [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes"]
pub static RUST_2021_PRELUDE_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "RUST_2021_PRELUDE_COLLISIONS",
default_level: crate::Allow,
desc: "detects the usage of trait methods which are ambiguous with traits added to the \
prelude in future editions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "prelude",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3439/// The `rust_2021_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3440 /// with traits added to the prelude in future editions.
3441 ///
3442 /// ### Example
3443 ///
3444 /// ```rust,edition2018,compile_fail
3445 /// #![deny(rust_2021_prelude_collisions)]
3446 ///
3447 /// trait Foo {
3448 /// fn try_into(self) -> Result<String, !>;
3449 /// }
3450 ///
3451 /// impl Foo for &str {
3452 /// fn try_into(self) -> Result<String, !> {
3453 /// Ok(String::from(self))
3454 /// }
3455 /// }
3456 ///
3457 /// fn main() {
3458 /// let x: String = "3".try_into().unwrap();
3459 /// // ^^^^^^^^
3460 /// // This call to try_into matches both Foo::try_into and TryInto::try_into as
3461 /// // `TryInto` has been added to the Rust prelude in 2021 edition.
3462 /// println!("{x}");
3463 /// }
3464 /// ```
3465 ///
3466 /// {{produces}}
3467 ///
3468 /// ### Explanation
3469 ///
3470 /// In Rust 2021, one of the important introductions is the [prelude changes], which add
3471 /// `TryFrom`, `TryInto`, and `FromIterator` into the standard library's prelude. Since this
3472 /// results in an ambiguity as to which method/function to call when an existing `try_into`
3473 /// method is called via dot-call syntax or a `try_from`/`from_iter` associated function
3474 /// is called directly on a type.
3475 ///
3476 /// [prelude changes]: https://blog.rust-lang.org/inside-rust/2021/03/04/planning-rust-2021.html#prelude-changes
3477pub RUST_2021_PRELUDE_COLLISIONS,
3478 Allow,
3479"detects the usage of trait methods which are ambiguous with traits added to the \
3480 prelude in future editions",
3481 @future_incompatible = FutureIncompatibleInfo {
3482 reason: fcw!(EditionError 2021 "prelude"),
3483 };
3484}34853486#[doc =
r" The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous"]
#[doc = r" with traits added to the prelude in future editions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(rust_2024_prelude_collisions)]"]
#[doc = r" trait Meow {"]
#[doc = r" fn poll(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Meow for T {}"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" core::pin::pin!(async {}).poll();"]
#[doc = r" // ^^^^^^"]
#[doc =
r" // This call to try_into matches both Future::poll and Meow::poll as"]
#[doc =
r" // `Future` has been added to the Rust prelude in 2024 edition."]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust 2024, introduces two new additions to the standard library's prelude:"]
#[doc =
r" `Future` and `IntoFuture`. This results in an ambiguity as to which method/function"]
#[doc =
r" to call when an existing `poll`/`into_future` method is called via dot-call syntax or"]
#[doc =
r" a `poll`/`into_future` associated function is called directly on a type."]
#[doc = r""]
pub static RUST_2024_PRELUDE_COLLISIONS: &crate::Lint =
&crate::Lint {
name: "RUST_2024_PRELUDE_COLLISIONS",
default_level: crate::Allow,
desc: "detects the usage of trait methods which are ambiguous with traits added to the \
prelude in future editions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "prelude",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3487/// The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3488 /// with traits added to the prelude in future editions.
3489 ///
3490 /// ### Example
3491 ///
3492 /// ```rust,edition2021,compile_fail
3493 /// #![deny(rust_2024_prelude_collisions)]
3494 /// trait Meow {
3495 /// fn poll(&self) {}
3496 /// }
3497 /// impl<T> Meow for T {}
3498 ///
3499 /// fn main() {
3500 /// core::pin::pin!(async {}).poll();
3501 /// // ^^^^^^
3502 /// // This call to try_into matches both Future::poll and Meow::poll as
3503 /// // `Future` has been added to the Rust prelude in 2024 edition.
3504 /// }
3505 /// ```
3506 ///
3507 /// {{produces}}
3508 ///
3509 /// ### Explanation
3510 ///
3511 /// Rust 2024, introduces two new additions to the standard library's prelude:
3512 /// `Future` and `IntoFuture`. This results in an ambiguity as to which method/function
3513 /// to call when an existing `poll`/`into_future` method is called via dot-call syntax or
3514 /// a `poll`/`into_future` associated function is called directly on a type.
3515 ///
3516pub RUST_2024_PRELUDE_COLLISIONS,
3517 Allow,
3518"detects the usage of trait methods which are ambiguous with traits added to the \
3519 prelude in future editions",
3520 @future_incompatible = FutureIncompatibleInfo {
3521 reason: fcw!(EditionError 2024 "prelude"),
3522 };
3523}35243525#[doc =
r" The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a"]
#[doc = r" prefix instead in Rust 2021."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2018,compile_fail"]
#[doc = r" #![deny(rust_2021_prefixes_incompatible_syntax)]"]
#[doc = r""]
#[doc = r" macro_rules! m {"]
#[doc = r" (z $x:expr) => ();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r#" m!(z"hey");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`"#]
#[doc =
r#" followed by the string literal `"hey"`. In Rust 2021, the `z` is"#]
#[doc = r#" considered a prefix for `"hey"`."#]
#[doc = r""]
#[doc =
r#" This lint suggests to add whitespace between the `z` and `"hey"` tokens"#]
#[doc = r" to keep them separated in Rust 2021."]
#[allow(rustdoc::invalid_rust_codeblocks)]
pub static RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX: &crate::Lint =
&crate::Lint {
name: "RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX",
default_level: crate::Allow,
desc: "identifiers that will be parsed as a prefix in Rust 2021",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2021,
page_slug: "reserving-syntax",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3526/// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
3527 /// prefix instead in Rust 2021.
3528 ///
3529 /// ### Example
3530 ///
3531 /// ```rust,edition2018,compile_fail
3532 /// #![deny(rust_2021_prefixes_incompatible_syntax)]
3533 ///
3534 /// macro_rules! m {
3535 /// (z $x:expr) => ();
3536 /// }
3537 ///
3538 /// m!(z"hey");
3539 /// ```
3540 ///
3541 /// {{produces}}
3542 ///
3543 /// ### Explanation
3544 ///
3545 /// In Rust 2015 and 2018, `z"hey"` is two tokens: the identifier `z`
3546 /// followed by the string literal `"hey"`. In Rust 2021, the `z` is
3547 /// considered a prefix for `"hey"`.
3548 ///
3549 /// This lint suggests to add whitespace between the `z` and `"hey"` tokens
3550 /// to keep them separated in Rust 2021.
3551// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
3552#[allow(rustdoc::invalid_rust_codeblocks)]
3553pub RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
3554 Allow,
3555"identifiers that will be parsed as a prefix in Rust 2021",
3556 @future_incompatible = FutureIncompatibleInfo {
3557 reason: fcw!(EditionError 2021 "reserving-syntax"),
3558 };
3559 crate_level_only
3560}35613562#[doc =
r" The `unsupported_calling_conventions` lint is output whenever there is a use of the"]
#[doc =
r" `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind"]
#[doc =
r" variants) on targets that cannot meaningfully be supported for the requested target."]
#[doc = r""]
#[doc =
r" For example, `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc"]
#[doc =
r" code, because this calling convention was never specified for those targets."]
#[doc = r""]
#[doc =
r" Historically, MSVC toolchains have fallen back to the regular C calling convention for"]
#[doc =
r" targets other than x86, but Rust doesn't really see a similar need to introduce a similar"]
#[doc = r" hack across many more targets."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs specific targets)"]
#[doc = r#" extern "stdcall" fn stdcall() {}"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: use of calling convention not supported on this target"]
#[doc = r" --> $DIR/unsupported.rs:39:1"]
#[doc = r" |"]
#[doc = r#" LL | extern "stdcall" fn stdcall() {}"#]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = note: `#[warn(unsupported_calling_conventions)]` on by default"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out;"]
#[doc = r" it will become a hard error in a future release!"]
#[doc = r" = note: for more information, see issue ..."]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On most of the targets, the behaviour of `stdcall` and similar calling conventions is not"]
#[doc =
r" defined at all, but was previously accepted due to a bug in the implementation of the"]
#[doc = r" compiler."]
pub static UNSUPPORTED_CALLING_CONVENTIONS: &crate::Lint =
&crate::Lint {
name: "UNSUPPORTED_CALLING_CONVENTIONS",
default_level: crate::Warn,
desc: "use of unsupported calling convention",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 137018,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3563/// The `unsupported_calling_conventions` lint is output whenever there is a use of the
3564 /// `stdcall`, `fastcall`, and `cdecl` calling conventions (or their unwind
3565 /// variants) on targets that cannot meaningfully be supported for the requested target.
3566 ///
3567 /// For example, `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3568 /// code, because this calling convention was never specified for those targets.
3569 ///
3570 /// Historically, MSVC toolchains have fallen back to the regular C calling convention for
3571 /// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3572 /// hack across many more targets.
3573 ///
3574 /// ### Example
3575 ///
3576 /// ```rust,ignore (needs specific targets)
3577 /// extern "stdcall" fn stdcall() {}
3578 /// ```
3579 ///
3580 /// This will produce:
3581 ///
3582 /// ```text
3583 /// warning: use of calling convention not supported on this target
3584 /// --> $DIR/unsupported.rs:39:1
3585 /// |
3586 /// LL | extern "stdcall" fn stdcall() {}
3587 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3588 /// |
3589 /// = note: `#[warn(unsupported_calling_conventions)]` on by default
3590 /// = warning: this was previously accepted by the compiler but is being phased out;
3591 /// it will become a hard error in a future release!
3592 /// = note: for more information, see issue ...
3593 /// ```
3594 ///
3595 /// ### Explanation
3596 ///
3597 /// On most of the targets, the behaviour of `stdcall` and similar calling conventions is not
3598 /// defined at all, but was previously accepted due to a bug in the implementation of the
3599 /// compiler.
3600pub UNSUPPORTED_CALLING_CONVENTIONS,
3601 Warn,
3602"use of unsupported calling convention",
3603 @future_incompatible = FutureIncompatibleInfo {
3604 reason: fcw!(FutureReleaseError #137018),
3605 report_in_deps: false,
3606 };
3607}36083609#[doc =
r" The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of"]
#[doc =
r" a target dependent calling convention on a target that does not support this calling"]
#[doc = r" convention on a function pointer."]
#[doc = r""]
#[doc =
r" For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc"]
#[doc =
r" code, because this calling convention was never specified for those targets."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs specific targets)"]
#[doc = r#" fn stdcall_ptr(f: extern "stdcall" fn ()) {"#]
#[doc = r" f()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r#" warning: the calling convention `"stdcall"` is not supported on this target"#]
#[doc = r" --> $DIR/unsupported.rs:34:15"]
#[doc = r" |"]
#[doc = r#" LL | fn stdcall_ptr(f: extern "stdcall" fn()) {"#]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>"]
#[doc =
r" = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" On most of the targets the behaviour of `stdcall` and similar calling conventions is not"]
#[doc =
r" defined at all, but was previously accepted due to a bug in the implementation of the"]
#[doc = r" compiler."]
pub static UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS: &crate::Lint =
&crate::Lint {
name: "UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS",
default_level: crate::Warn,
desc: "use of unsupported calling convention for function pointer",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 130260,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3610/// The `unsupported_fn_ptr_calling_conventions` lint is output whenever there is a use of
3611 /// a target dependent calling convention on a target that does not support this calling
3612 /// convention on a function pointer.
3613 ///
3614 /// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3615 /// code, because this calling convention was never specified for those targets.
3616 ///
3617 /// ### Example
3618 ///
3619 /// ```rust,ignore (needs specific targets)
3620 /// fn stdcall_ptr(f: extern "stdcall" fn ()) {
3621 /// f()
3622 /// }
3623 /// ```
3624 ///
3625 /// This will produce:
3626 ///
3627 /// ```text
3628 /// warning: the calling convention `"stdcall"` is not supported on this target
3629 /// --> $DIR/unsupported.rs:34:15
3630 /// |
3631 /// LL | fn stdcall_ptr(f: extern "stdcall" fn()) {
3632 /// | ^^^^^^^^^^^^^^^^^^^^^^^^
3633 /// |
3634 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3635 /// = note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
3636 /// = note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
3637 /// ```
3638 ///
3639 /// ### Explanation
3640 ///
3641 /// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3642 /// defined at all, but was previously accepted due to a bug in the implementation of the
3643 /// compiler.
3644pub UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS,
3645 Warn,
3646"use of unsupported calling convention for function pointer",
3647 @future_incompatible = FutureIncompatibleInfo {
3648 reason: fcw!(FutureReleaseError #130260),
3649 report_in_deps: true,
3650 };
3651}36523653#[doc =
r" The `break_with_label_and_loop` lint detects labeled `break` expressions with"]
#[doc = r" an unlabeled loop as their value expression."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" 'label: loop {"]
#[doc = r" break 'label loop { break 42; };"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In Rust, loops can have a label, and `break` expressions can refer to that label to"]
#[doc =
r" break out of specific loops (and not necessarily the innermost one). `break` expressions"]
#[doc =
r" can also carry a value expression, which can be another loop. A labeled `break` with an"]
#[doc =
r" unlabeled loop as its value expression is easy to confuse with an unlabeled break with"]
#[doc =
r" a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses"]
#[doc =
r" around the loop expression to silence this warning. Unlabeled `break` expressions with"]
#[doc =
r" labeled loops yield a hard error, which can also be silenced by wrapping the expression"]
#[doc = r" in parentheses."]
pub static BREAK_WITH_LABEL_AND_LOOP: &crate::Lint =
&crate::Lint {
name: "BREAK_WITH_LABEL_AND_LOOP",
default_level: crate::Warn,
desc: "`break` expression with label and unlabeled loop as value expression",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3654/// The `break_with_label_and_loop` lint detects labeled `break` expressions with
3655 /// an unlabeled loop as their value expression.
3656 ///
3657 /// ### Example
3658 ///
3659 /// ```rust
3660 /// 'label: loop {
3661 /// break 'label loop { break 42; };
3662 /// };
3663 /// ```
3664 ///
3665 /// {{produces}}
3666 ///
3667 /// ### Explanation
3668 ///
3669 /// In Rust, loops can have a label, and `break` expressions can refer to that label to
3670 /// break out of specific loops (and not necessarily the innermost one). `break` expressions
3671 /// can also carry a value expression, which can be another loop. A labeled `break` with an
3672 /// unlabeled loop as its value expression is easy to confuse with an unlabeled break with
3673 /// a labeled loop and is thus discouraged (but allowed for compatibility); use parentheses
3674 /// around the loop expression to silence this warning. Unlabeled `break` expressions with
3675 /// labeled loops yield a hard error, which can also be silenced by wrapping the expression
3676 /// in parentheses.
3677pub BREAK_WITH_LABEL_AND_LOOP,
3678 Warn,
3679"`break` expression with label and unlabeled loop as value expression"
3680}36813682#[doc =
r" The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`"]
#[doc =
r" struct or enum who want to match all of its fields/variants explicitly."]
#[doc = r""]
#[doc =
r" The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness"]
#[doc =
r" checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy"]
#[doc =
r" this, this allow-by-default lint warns the user when a match mentions some but not all of"]
#[doc = r" the fields/variants of a `#[non_exhaustive]` struct or enum."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs separate crate)"]
#[doc = r" // crate A"]
#[doc = r" #[non_exhaustive]"]
#[doc = r" pub enum Bar {"]
#[doc = r" A,"]
#[doc = r" B, // added variant in non breaking change"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" // in crate B"]
#[doc = r" #![feature(non_exhaustive_omitted_patterns_lint)]"]
#[doc = r" #[warn(non_exhaustive_omitted_patterns)]"]
#[doc = r" match Bar::A {"]
#[doc = r" Bar::A => {},"]
#[doc = r" _ => {},"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: some variants are not matched explicitly"]
#[doc = r" --> $DIR/reachable-patterns.rs:70:9"]
#[doc = r" |"]
#[doc = r" LL | match Bar::A {"]
#[doc = r" | ^ pattern `Bar::B` not covered"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> $DIR/reachable-patterns.rs:69:16"]
#[doc = r" |"]
#[doc = r" LL | #[warn(non_exhaustive_omitted_patterns)]"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc =
r" = help: ensure that all variants are matched explicitly by adding the suggested match arms"]
#[doc =
r" = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or"]
#[doc =
r" variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against"]
#[doc = r" expected semver behavior."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially"]
#[doc =
r" redundant) wildcard when pattern-matching, to allow for future addition of fields or"]
#[doc =
r" variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to"]
#[doc =
r" actually catch some fields/variants. In other words, when the match without the wildcard"]
#[doc =
r" would not be exhaustive. This lets the user be informed if new fields/variants were added."]
pub static NON_EXHAUSTIVE_OMITTED_PATTERNS: &crate::Lint =
&crate::Lint {
name: "NON_EXHAUSTIVE_OMITTED_PATTERNS",
default_level: crate::Allow,
desc: "detect when patterns of types marked `non_exhaustive` are missed",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::non_exhaustive_omitted_patterns_lint),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3683/// The `non_exhaustive_omitted_patterns` lint aims to help consumers of a `#[non_exhaustive]`
3684 /// struct or enum who want to match all of its fields/variants explicitly.
3685 ///
3686 /// The `#[non_exhaustive]` annotation forces matches to use wildcards, so exhaustiveness
3687 /// checking cannot be used to ensure that all fields/variants are matched explicitly. To remedy
3688 /// this, this allow-by-default lint warns the user when a match mentions some but not all of
3689 /// the fields/variants of a `#[non_exhaustive]` struct or enum.
3690 ///
3691 /// ### Example
3692 ///
3693 /// ```rust,ignore (needs separate crate)
3694 /// // crate A
3695 /// #[non_exhaustive]
3696 /// pub enum Bar {
3697 /// A,
3698 /// B, // added variant in non breaking change
3699 /// }
3700 ///
3701 /// // in crate B
3702 /// #![feature(non_exhaustive_omitted_patterns_lint)]
3703 /// #[warn(non_exhaustive_omitted_patterns)]
3704 /// match Bar::A {
3705 /// Bar::A => {},
3706 /// _ => {},
3707 /// }
3708 /// ```
3709 ///
3710 /// This will produce:
3711 ///
3712 /// ```text
3713 /// warning: some variants are not matched explicitly
3714 /// --> $DIR/reachable-patterns.rs:70:9
3715 /// |
3716 /// LL | match Bar::A {
3717 /// | ^ pattern `Bar::B` not covered
3718 /// |
3719 /// note: the lint level is defined here
3720 /// --> $DIR/reachable-patterns.rs:69:16
3721 /// |
3722 /// LL | #[warn(non_exhaustive_omitted_patterns)]
3723 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3724 /// = help: ensure that all variants are matched explicitly by adding the suggested match arms
3725 /// = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found
3726 /// ```
3727 ///
3728 /// Warning: setting this to `deny` will make upstream non-breaking changes (adding fields or
3729 /// variants to a `#[non_exhaustive]` struct or enum) break your crate. This goes against
3730 /// expected semver behavior.
3731 ///
3732 /// ### Explanation
3733 ///
3734 /// Structs and enums tagged with `#[non_exhaustive]` force the user to add a (potentially
3735 /// redundant) wildcard when pattern-matching, to allow for future addition of fields or
3736 /// variants. The `non_exhaustive_omitted_patterns` lint detects when such a wildcard happens to
3737 /// actually catch some fields/variants. In other words, when the match without the wildcard
3738 /// would not be exhaustive. This lets the user be informed if new fields/variants were added.
3739pub NON_EXHAUSTIVE_OMITTED_PATTERNS,
3740 Allow,
3741"detect when patterns of types marked `non_exhaustive` are missed",
3742 @feature_gate = non_exhaustive_omitted_patterns_lint;
3743}37443745#[doc =
r" The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that"]
#[doc =
r" change the visual representation of text on screen in a way that does not correspond to"]
#[doc = r" their on memory representation."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(text_direction_codepoint_in_comment)]"]
#[doc = r" fn main() {"]
#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Unicode allows changing the visual flow of text on screen in order to support scripts that"]
#[doc =
r" are written right-to-left, but a specially crafted comment can make code that will be"]
#[doc =
r" compiled appear to be part of a comment, depending on the software used to read the code."]
#[doc =
r" To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny"]
#[doc = r" their use."]
pub static TEXT_DIRECTION_CODEPOINT_IN_COMMENT: &crate::Lint =
&crate::Lint {
name: "TEXT_DIRECTION_CODEPOINT_IN_COMMENT",
default_level: crate::Deny,
desc: "invisible directionality-changing codepoints in comment",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3746/// The `text_direction_codepoint_in_comment` lint detects Unicode codepoints in comments that
3747 /// change the visual representation of text on screen in a way that does not correspond to
3748 /// their on memory representation.
3749 ///
3750 /// ### Example
3751 ///
3752 /// ```rust,compile_fail
3753 /// #![deny(text_direction_codepoint_in_comment)]
3754 /// fn main() {
3755#[doc = " println!(\"{:?}\"); // '\u{202E}');"]
3756/// }
3757 /// ```
3758 ///
3759 /// {{produces}}
3760 ///
3761 /// ### Explanation
3762 ///
3763 /// Unicode allows changing the visual flow of text on screen in order to support scripts that
3764 /// are written right-to-left, but a specially crafted comment can make code that will be
3765 /// compiled appear to be part of a comment, depending on the software used to read the code.
3766 /// To avoid potential problems or confusion, such as in CVE-2021-42574, by default we deny
3767 /// their use.
3768pub TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
3769 Deny,
3770"invisible directionality-changing codepoints in comment",
3771 crate_level_only
3772}37733774#[doc =
r" The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the"]
#[doc =
r" visual representation of text on screen in a way that does not correspond to their on"]
#[doc = r" memory representation."]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,"]
#[doc =
r" `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change"]
#[doc =
r#" its direction on software that supports these codepoints. This makes the text "abc" display"#]
#[doc =
r#" as "cba" on screen. By leveraging software that supports these, people can write specially"#]
#[doc =
r" crafted literals that make the surrounding code seem like it's performing one action, when"]
#[doc =
r" in reality it is performing another. Because of this, we proactively lint against their"]
#[doc = r" presence to avoid surprises."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(text_direction_codepoint_in_literal)]"]
#[doc = r" fn main() {"]
#[doc = " println!(\"{:?}\", '\u{202E}');"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
pub static TEXT_DIRECTION_CODEPOINT_IN_LITERAL: &crate::Lint =
&crate::Lint {
name: "TEXT_DIRECTION_CODEPOINT_IN_LITERAL",
default_level: crate::Deny,
desc: "detect special Unicode codepoints that affect the visual representation of text on screen, \
changing the direction in which text flows",
is_externally_loaded: false,
crate_level_only: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3775/// The `text_direction_codepoint_in_literal` lint detects Unicode codepoints that change the
3776 /// visual representation of text on screen in a way that does not correspond to their on
3777 /// memory representation.
3778 ///
3779 /// ### Explanation
3780 ///
3781 /// The unicode characters `\u{202A}`, `\u{202B}`, `\u{202D}`, `\u{202E}`, `\u{2066}`,
3782 /// `\u{2067}`, `\u{2068}`, `\u{202C}` and `\u{2069}` make the flow of text on screen change
3783 /// its direction on software that supports these codepoints. This makes the text "abc" display
3784 /// as "cba" on screen. By leveraging software that supports these, people can write specially
3785 /// crafted literals that make the surrounding code seem like it's performing one action, when
3786 /// in reality it is performing another. Because of this, we proactively lint against their
3787 /// presence to avoid surprises.
3788 ///
3789 /// ### Example
3790 ///
3791 /// ```rust,compile_fail
3792 /// #![deny(text_direction_codepoint_in_literal)]
3793 /// fn main() {
3794// ` - convince tidy that backticks match
3795#[doc = " println!(\"{:?}\", '\u{202E}');"]
3796// `
3797/// }
3798 /// ```
3799 ///
3800 /// {{produces}}
3801 ///
3802pub TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
3803 Deny,
3804"detect special Unicode codepoints that affect the visual representation of text on screen, \
3805 changing the direction in which text flows",
3806 crate_level_only
3807}38083809#[doc =
r" The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro"]
#[doc =
r" attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`"]
#[doc = r" and `test_case`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs --test)"]
#[doc = r" #[test]"]
#[doc = r" #[test]"]
#[doc = r" fn foo() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: duplicated attribute"]
#[doc = r" --> src/lib.rs:2:1"]
#[doc = r" |"]
#[doc = r" 2 | #[test]"]
#[doc = r" | ^^^^^^^"]
#[doc = r" |"]
#[doc = r" = note: `#[warn(duplicate_macro_attributes)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" A duplicated attribute may erroneously originate from a copy-paste and the effect of it"]
#[doc = r" being duplicated may not be obvious or desirable."]
#[doc = r""]
#[doc =
r" For instance, doubling the `#[test]` attributes registers the test to be run twice with no"]
#[doc = r" change to its environment."]
#[doc = r""]
#[doc = r" [issue #90979]: https://github.com/rust-lang/rust/issues/90979"]
pub static DUPLICATE_MACRO_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "DUPLICATE_MACRO_ATTRIBUTES",
default_level: crate::Warn,
desc: "duplicated attribute",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3810/// The `duplicate_macro_attributes` lint detects when a `#[test]`-like built-in macro
3811 /// attribute is duplicated on an item. This lint may trigger on `bench`, `cfg_eval`, `test`
3812 /// and `test_case`.
3813 ///
3814 /// ### Example
3815 ///
3816 /// ```rust,ignore (needs --test)
3817 /// #[test]
3818 /// #[test]
3819 /// fn foo() {}
3820 /// ```
3821 ///
3822 /// This will produce:
3823 ///
3824 /// ```text
3825 /// warning: duplicated attribute
3826 /// --> src/lib.rs:2:1
3827 /// |
3828 /// 2 | #[test]
3829 /// | ^^^^^^^
3830 /// |
3831 /// = note: `#[warn(duplicate_macro_attributes)]` on by default
3832 /// ```
3833 ///
3834 /// ### Explanation
3835 ///
3836 /// A duplicated attribute may erroneously originate from a copy-paste and the effect of it
3837 /// being duplicated may not be obvious or desirable.
3838 ///
3839 /// For instance, doubling the `#[test]` attributes registers the test to be run twice with no
3840 /// change to its environment.
3841 ///
3842 /// [issue #90979]: https://github.com/rust-lang/rust/issues/90979
3843pub DUPLICATE_MACRO_ATTRIBUTES,
3844 Warn,
3845"duplicated attribute"
3846}38473848#[doc =
r" The `deprecated_where_clause_location` lint detects when a where clause in front of the equals"]
#[doc = r" in an associated type."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" trait Trait {"]
#[doc = r" type Assoc<'a> where Self: 'a;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Trait for () {"]
#[doc = r" type Assoc<'a> where Self: 'a = ();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" The preferred location for where clauses on associated types"]
#[doc =
r" is after the type. However, for most of generic associated types development,"]
#[doc =
r" it was only accepted before the equals. To provide a transition period and"]
#[doc =
r" further evaluate this change, both are currently accepted. At some point in"]
#[doc =
r" the future, this may be disallowed at an edition boundary; but, that is"]
#[doc = r" undecided currently."]
pub static DEPRECATED_WHERE_CLAUSE_LOCATION: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_WHERE_CLAUSE_LOCATION",
default_level: crate::Warn,
desc: "deprecated where clause location",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3849/// The `deprecated_where_clause_location` lint detects when a where clause in front of the equals
3850 /// in an associated type.
3851 ///
3852 /// ### Example
3853 ///
3854 /// ```rust
3855 /// trait Trait {
3856 /// type Assoc<'a> where Self: 'a;
3857 /// }
3858 ///
3859 /// impl Trait for () {
3860 /// type Assoc<'a> where Self: 'a = ();
3861 /// }
3862 /// ```
3863 ///
3864 /// {{produces}}
3865 ///
3866 /// ### Explanation
3867 ///
3868 /// The preferred location for where clauses on associated types
3869 /// is after the type. However, for most of generic associated types development,
3870 /// it was only accepted before the equals. To provide a transition period and
3871 /// further evaluate this change, both are currently accepted. At some point in
3872 /// the future, this may be disallowed at an edition boundary; but, that is
3873 /// undecided currently.
3874pub DEPRECATED_WHERE_CLAUSE_LOCATION,
3875 Warn,
3876"deprecated where clause location"
3877}38783879#[doc =
r" The `test_unstable_lint` lint tests unstable lints and is perma-unstable."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc =
r" // This lint is intentionally used to test the compiler's behavior"]
#[doc =
r" // when an unstable lint is enabled without the corresponding feature gate."]
#[doc = r" #![allow(test_unstable_lint)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In order to test the behavior of unstable lints, a permanently-unstable"]
#[doc =
r" lint is required. This lint can be used to trigger warnings and errors"]
#[doc = r" from the compiler related to unstable lints."]
pub static TEST_UNSTABLE_LINT: &crate::Lint =
&crate::Lint {
name: "TEST_UNSTABLE_LINT",
default_level: crate::Deny,
desc: "this unstable lint is only for testing",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::test_unstable_lint),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3880/// The `test_unstable_lint` lint tests unstable lints and is perma-unstable.
3881 ///
3882 /// ### Example
3883 ///
3884 /// ```rust
3885 /// // This lint is intentionally used to test the compiler's behavior
3886 /// // when an unstable lint is enabled without the corresponding feature gate.
3887 /// #![allow(test_unstable_lint)]
3888 /// ```
3889 ///
3890 /// {{produces}}
3891 ///
3892 /// ### Explanation
3893 ///
3894 /// In order to test the behavior of unstable lints, a permanently-unstable
3895 /// lint is required. This lint can be used to trigger warnings and errors
3896 /// from the compiler related to unstable lints.
3897pub TEST_UNSTABLE_LINT,
3898 Deny,
3899"this unstable lint is only for testing",
3900 @feature_gate = test_unstable_lint;
3901}39023903#[doc =
r" The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with"]
#[doc = r" `C-unwind` or other FFI-unwind ABIs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![warn(ffi_unwind_calls)]"]
#[doc = r""]
#[doc = r#" unsafe extern "C-unwind" {"#]
#[doc = r" fn foo();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn bar() {"]
#[doc = r" unsafe { foo(); }"]
#[doc = r#" let ptr: unsafe extern "C-unwind" fn() = foo;"#]
#[doc = r" unsafe { ptr(); }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" For crates containing such calls, if they are compiled with `-C panic=unwind` then the"]
#[doc =
r" produced library cannot be linked with crates compiled with `-C panic=abort`. For crates"]
#[doc =
r" that desire this ability it is therefore necessary to avoid such calls."]
pub static FFI_UNWIND_CALLS: &crate::Lint =
&crate::Lint {
name: "FFI_UNWIND_CALLS",
default_level: crate::Allow,
desc: "call to foreign functions or function pointers with FFI-unwind ABI",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3904/// The `ffi_unwind_calls` lint detects calls to foreign functions or function pointers with
3905 /// `C-unwind` or other FFI-unwind ABIs.
3906 ///
3907 /// ### Example
3908 ///
3909 /// ```rust
3910 /// #![warn(ffi_unwind_calls)]
3911 ///
3912 /// unsafe extern "C-unwind" {
3913 /// fn foo();
3914 /// }
3915 ///
3916 /// fn bar() {
3917 /// unsafe { foo(); }
3918 /// let ptr: unsafe extern "C-unwind" fn() = foo;
3919 /// unsafe { ptr(); }
3920 /// }
3921 /// ```
3922 ///
3923 /// {{produces}}
3924 ///
3925 /// ### Explanation
3926 ///
3927 /// For crates containing such calls, if they are compiled with `-C panic=unwind` then the
3928 /// produced library cannot be linked with crates compiled with `-C panic=abort`. For crates
3929 /// that desire this ability it is therefore necessary to avoid such calls.
3930pub FFI_UNWIND_CALLS,
3931 Allow,
3932"call to foreign functions or function pointers with FFI-unwind ABI"
3933}39343935#[doc = r" The `linker_messages` lint forwards warnings from the linker."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs CLI args, platform-specific)"]
#[doc = r" #[warn(linker_messages)]"]
#[doc = r#" extern "C" {"#]
#[doc = r" fn foo();"]
#[doc = r" }"]
#[doc = r" fn main () { unsafe { foo(); } }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: linker stderr: rust-lld: undefined symbol: foo"]
#[doc = r" >>> referenced by rust_out.69edbd30df4ae57d-cgu.0"]
#[doc =
r" >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> warn.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![warn(linker_messages)]"]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" warning: 1 warning emitted"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Linkers emit platform-specific and program-specific warnings that cannot be predicted in"]
#[doc =
r" advance by the Rust compiler. Such messages are ignored by default for now. While linker"]
#[doc =
r" warnings could be very useful they have been ignored for many years by essentially all"]
#[doc =
r" users, so we need to do a bit more work than just surfacing their text to produce a clear"]
#[doc =
r" and actionable warning of similar quality to our other diagnostics. See this tracking"]
#[doc =
r" issue for more details: <https://github.com/rust-lang/rust/issues/136096>."]
pub static LINKER_MESSAGES: &crate::Lint =
&crate::Lint {
name: "LINKER_MESSAGES",
default_level: crate::Warn,
desc: "warnings emitted at runtime by the target-specific linker program",
is_externally_loaded: false,
ignore_deny_warnings: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3936/// The `linker_messages` lint forwards warnings from the linker.
3937 ///
3938 /// ### Example
3939 ///
3940 /// ```rust,ignore (needs CLI args, platform-specific)
3941 /// #[warn(linker_messages)]
3942 /// extern "C" {
3943 /// fn foo();
3944 /// }
3945 /// fn main () { unsafe { foo(); } }
3946 /// ```
3947 ///
3948 /// On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce
3949 ///
3950 /// ```text
3951 /// warning: linker stderr: rust-lld: undefined symbol: foo
3952 /// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
3953 /// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
3954 /// |
3955 /// note: the lint level is defined here
3956 /// --> warn.rs:1:9
3957 /// |
3958 /// 1 | #![warn(linker_messages)]
3959 /// | ^^^^^^^^^^^^^^^
3960 /// warning: 1 warning emitted
3961 /// ```
3962 ///
3963 /// ### Explanation
3964 ///
3965 /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
3966 /// advance by the Rust compiler. Such messages are ignored by default for now. While linker
3967 /// warnings could be very useful they have been ignored for many years by essentially all
3968 /// users, so we need to do a bit more work than just surfacing their text to produce a clear
3969 /// and actionable warning of similar quality to our other diagnostics. See this tracking
3970 /// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
3971pub LINKER_MESSAGES,
3972 Warn,
3973"warnings emitted at runtime by the target-specific linker program",
3974// Linker messages don't live up to the high standard people expect of rustc's errors.
3975 // Prevent `-D warnings` from applying to it.
3976 // It's still possible to pass `-D linker-messages` specifically.
3977ignore_deny_warnings
3978}39793980#[doc =
r" The `linker_info` lint forwards warnings from the linker that are known to be informational-only."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs CLI args, platform-specific)"]
#[doc = r" #[warn(linker_info)]"]
#[doc = r" fn main () {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" On MacOS, using `-C link-arg=-lc` and the default linker, this will produce"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: linker stderr: ld: ignoring duplicate libraries: '-lc'"]
#[doc = r" |"]
#[doc = r" note: the lint level is defined here"]
#[doc = r" --> ex.rs:1:9"]
#[doc = r" |"]
#[doc = r" 1 | #![warn(linker_info)]"]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r#" Many linkers are very "chatty" and print lots of information that is not necessarily"#]
#[doc =
r" indicative of an issue. This output has been ignored for many years and is often not"]
#[doc =
r" actionable by developers. It is silenced unless the developer specifically requests for it"]
#[doc = r" to be printed. See this tracking issue for more details:"]
#[doc = r" <https://github.com/rust-lang/rust/issues/136096>."]
pub static LINKER_INFO: &crate::Lint =
&crate::Lint {
name: "LINKER_INFO",
default_level: crate::Allow,
desc: "linker warnings known to be informational-only and not indicative of a problem",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
3981/// The `linker_info` lint forwards warnings from the linker that are known to be informational-only.
3982 ///
3983 /// ### Example
3984 ///
3985 /// ```rust,ignore (needs CLI args, platform-specific)
3986 /// #[warn(linker_info)]
3987 /// fn main () {}
3988 /// ```
3989 ///
3990 /// On MacOS, using `-C link-arg=-lc` and the default linker, this will produce
3991 ///
3992 /// ```text
3993 /// warning: linker stderr: ld: ignoring duplicate libraries: '-lc'
3994 /// |
3995 /// note: the lint level is defined here
3996 /// --> ex.rs:1:9
3997 /// |
3998 /// 1 | #![warn(linker_info)]
3999 /// | ^^^^^^^^^^^^^^^
4000 /// ```
4001 ///
4002 /// ### Explanation
4003 ///
4004 /// Many linkers are very "chatty" and print lots of information that is not necessarily
4005 /// indicative of an issue. This output has been ignored for many years and is often not
4006 /// actionable by developers. It is silenced unless the developer specifically requests for it
4007 /// to be printed. See this tracking issue for more details:
4008 /// <https://github.com/rust-lang/rust/issues/136096>.
4009pub LINKER_INFO,
4010 Allow,
4011"linker warnings known to be informational-only and not indicative of a problem"
4012}40134014#[doc =
r" The `named_arguments_used_positionally` lint detects cases where named arguments are only"]
#[doc =
r" used positionally in format strings. This usage is valid but potentially very confusing."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(named_arguments_used_positionally)]"]
#[doc = r" fn main() {"]
#[doc = r" let _x = 5;"]
#[doc = r#" println!("{}", _x = 1); // Prints 1, will trigger lint"#]
#[doc = r""]
#[doc = r#" println!("{}", _x); // Prints 5, no lint emitted"#]
#[doc = r#" println!("{_x}", _x = _x); // Prints 5, no lint emitted"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust formatting strings can refer to named arguments by their position, but this usage is"]
#[doc =
r" potentially confusing. In particular, readers can incorrectly assume that the declaration"]
#[doc =
r" of named arguments is an assignment (which would produce the unit type)."]
#[doc = r" For backwards compatibility, this is not a hard error."]
pub static NAMED_ARGUMENTS_USED_POSITIONALLY: &crate::Lint =
&crate::Lint {
name: "NAMED_ARGUMENTS_USED_POSITIONALLY",
default_level: crate::Warn,
desc: "named arguments in format used positionally",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4015/// The `named_arguments_used_positionally` lint detects cases where named arguments are only
4016 /// used positionally in format strings. This usage is valid but potentially very confusing.
4017 ///
4018 /// ### Example
4019 ///
4020 /// ```rust,compile_fail
4021 /// #![deny(named_arguments_used_positionally)]
4022 /// fn main() {
4023 /// let _x = 5;
4024 /// println!("{}", _x = 1); // Prints 1, will trigger lint
4025 ///
4026 /// println!("{}", _x); // Prints 5, no lint emitted
4027 /// println!("{_x}", _x = _x); // Prints 5, no lint emitted
4028 /// }
4029 /// ```
4030 ///
4031 /// {{produces}}
4032 ///
4033 /// ### Explanation
4034 ///
4035 /// Rust formatting strings can refer to named arguments by their position, but this usage is
4036 /// potentially confusing. In particular, readers can incorrectly assume that the declaration
4037 /// of named arguments is an assignment (which would produce the unit type).
4038 /// For backwards compatibility, this is not a hard error.
4039pub NAMED_ARGUMENTS_USED_POSITIONALLY,
4040 Warn,
4041"named arguments in format used positionally"
4042}40434044#[doc =
r" The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback"]
#[doc = r" affects unsafe function calls."]
#[doc = r""]
#[doc = r" ### Never type fallback"]
#[doc = r""]
#[doc =
r" When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),"]
#[doc = r" to allow type check to infer any type:"]
#[doc = r""]
#[doc = r" ```ignore (illustrative-and-has-placeholders)"]
#[doc = r" // this"]
#[doc = r" let x: u8 = panic!();"]
#[doc = r""]
#[doc = r" // is (essentially) turned by the compiler into"]
#[doc = r" let x: u8 = absurd(panic!());"]
#[doc = r""]
#[doc = r" // where absurd is a function with the following signature"]
#[doc = r" // (it's sound, because `!` always marks unreachable code):"]
#[doc = r" fn absurd<T>(never: !) -> T { ... }"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" While it's convenient to be able to use non-diverging code in one of the branches (like"]
#[doc =
r" `if a { b } else { return }`) this could lead to compilation errors:"]
#[doc = r""]
#[doc = r" ```compile_fail"]
#[doc = r" // this"]
#[doc = r" { panic!() };"]
#[doc = r""]
#[doc = r" // gets turned into this"]
#[doc = r" { absurd(panic!()) }; // error: can't infer the type of `absurd`"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it"]
#[doc =
r" can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`."]
#[doc = r#" This is what is known as "never type fallback"."#]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" fn main() {"]
#[doc = r" if true {"]
#[doc =
r" // return has type `!` which, is some cases, causes never type fallback"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // `zeroed` is an unsafe function, which returns an unbounded type"]
#[doc = r" unsafe { std::mem::zeroed() }"]
#[doc = r" };"]
#[doc =
r" // depending on the fallback, `zeroed` may create `()` (which is completely sound),"]
#[doc = r" // or `!` (which is instant undefined behavior)"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously"]
#[doc =
r" coerced to `()`. There are plans to change that, but they may make the code such as above"]
#[doc =
r" unsound. Instead of depending on the fallback, you should specify the type explicitly:"]
#[doc = r" ```"]
#[doc = r" if true {"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // type is explicitly specified, fallback can't hurt us no more"]
#[doc = r" unsafe { std::mem::zeroed::<()>() }"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748)."]
#[doc = r""]
#[doc = r" [`!`]: https://doc.rust-lang.org/core/primitive.never.html"]
#[doc = r" [`()`]: https://doc.rust-lang.org/core/primitive.unit.html"]
pub static NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE: &crate::Lint =
&crate::Lint {
name: "NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE",
default_level: crate::Deny,
desc: "never type fallback affecting unsafe function calls",
is_externally_loaded: false,
report_in_external_macro: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "never-type-fallback",
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
edition_lint_opts: Some((crate::Edition::Edition2024,
crate::Deny)),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4045/// The `never_type_fallback_flowing_into_unsafe` lint detects cases where never type fallback
4046 /// affects unsafe function calls.
4047 ///
4048 /// ### Never type fallback
4049 ///
4050 /// When the compiler sees a value of type [`!`] it implicitly inserts a coercion (if possible),
4051 /// to allow type check to infer any type:
4052 ///
4053 /// ```ignore (illustrative-and-has-placeholders)
4054 /// // this
4055 /// let x: u8 = panic!();
4056 ///
4057 /// // is (essentially) turned by the compiler into
4058 /// let x: u8 = absurd(panic!());
4059 ///
4060 /// // where absurd is a function with the following signature
4061 /// // (it's sound, because `!` always marks unreachable code):
4062 /// fn absurd<T>(never: !) -> T { ... }
4063 /// ```
4064 ///
4065 /// While it's convenient to be able to use non-diverging code in one of the branches (like
4066 /// `if a { b } else { return }`) this could lead to compilation errors:
4067 ///
4068 /// ```compile_fail
4069 /// // this
4070 /// { panic!() };
4071 ///
4072 /// // gets turned into this
4073 /// { absurd(panic!()) }; // error: can't infer the type of `absurd`
4074 /// ```
4075 ///
4076 /// To prevent such errors, compiler remembers where it inserted `absurd` calls, and if it
4077 /// can't infer their type, it sets the type to fallback. `{ absurd::<Fallback>(panic!()) };`.
4078 /// This is what is known as "never type fallback".
4079 ///
4080 /// ### Example
4081 ///
4082 /// ```rust,compile_fail
4083 /// fn main() {
4084 /// if true {
4085 /// // return has type `!` which, is some cases, causes never type fallback
4086 /// return
4087 /// } else {
4088 /// // `zeroed` is an unsafe function, which returns an unbounded type
4089 /// unsafe { std::mem::zeroed() }
4090 /// };
4091 /// // depending on the fallback, `zeroed` may create `()` (which is completely sound),
4092 /// // or `!` (which is instant undefined behavior)
4093 /// }
4094 /// ```
4095 ///
4096 /// {{produces}}
4097 ///
4098 /// ### Explanation
4099 ///
4100 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4101 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4102 /// unsound. Instead of depending on the fallback, you should specify the type explicitly:
4103 /// ```
4104 /// if true {
4105 /// return
4106 /// } else {
4107 /// // type is explicitly specified, fallback can't hurt us no more
4108 /// unsafe { std::mem::zeroed::<()>() }
4109 /// };
4110 /// ```
4111 ///
4112 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4113 ///
4114 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4115 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4116pub NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE,
4117 Deny,
4118"never type fallback affecting unsafe function calls",
4119 @future_incompatible = FutureIncompatibleInfo {
4120 reason: fcw!(EditionAndFutureReleaseSemanticsChange 2024 "never-type-fallback"),
4121 report_in_deps: true,
4122 };
4123 @edition Edition2024 => Deny;
4124 report_in_external_macro
4125}41264127#[doc =
r" The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with"]
#[doc =
r" [never type fallback] being [`()`], but will stop compiling with fallback being [`!`]."]
#[doc = r""]
#[doc =
r" [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback"]
#[doc = r" [`!`]: https://doc.rust-lang.org/core/primitive.never.html"]
#[doc = r" [`()`]: https://doc.rust-lang.org/core/primitive.unit.html"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail,edition2021"]
#[doc = r" # #![deny(dependency_on_unit_never_type_fallback)]"]
#[doc = r" fn main() {"]
#[doc = r" if true {"]
#[doc =
r" // return has type `!` which, is some cases, causes never type fallback"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // the type produced by this call is not specified explicitly,"]
#[doc = r" // so it will be inferred from the previous branch"]
#[doc = r" Default::default()"]
#[doc = r" };"]
#[doc =
r" // depending on the fallback, this may compile (because `()` implements `Default`),"]
#[doc = r" // or it may not (because `!` does not implement `Default`)"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously"]
#[doc =
r" coerced to `()`. There are plans to change that, but they may make the code such as above"]
#[doc =
r" not compile. Instead of depending on the fallback, you should specify the type explicitly:"]
#[doc = r" ```"]
#[doc = r" if true {"]
#[doc = r" return"]
#[doc = r" } else {"]
#[doc =
r" // type is explicitly specified, fallback can't hurt us no more"]
#[doc = r" <() as Default>::default()"]
#[doc = r" };"]
#[doc = r" ```"]
#[doc = r""]
#[doc =
r" See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748)."]
pub static DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK: &crate::Lint =
&crate::Lint {
name: "DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK",
default_level: crate::Deny,
desc: "never type fallback affecting unsafe function calls",
is_externally_loaded: false,
report_in_external_macro: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionAndFutureReleaseError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "never-type-fallback",
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4128/// The `dependency_on_unit_never_type_fallback` lint detects cases where code compiles with
4129 /// [never type fallback] being [`()`], but will stop compiling with fallback being [`!`].
4130 ///
4131 /// [never type fallback]: https://doc.rust-lang.org/nightly/core/primitive.never.html#never-type-fallback
4132 /// [`!`]: https://doc.rust-lang.org/core/primitive.never.html
4133 /// [`()`]: https://doc.rust-lang.org/core/primitive.unit.html
4134 ///
4135 /// ### Example
4136 ///
4137 /// ```rust,compile_fail,edition2021
4138 /// # #![deny(dependency_on_unit_never_type_fallback)]
4139 /// fn main() {
4140 /// if true {
4141 /// // return has type `!` which, is some cases, causes never type fallback
4142 /// return
4143 /// } else {
4144 /// // the type produced by this call is not specified explicitly,
4145 /// // so it will be inferred from the previous branch
4146 /// Default::default()
4147 /// };
4148 /// // depending on the fallback, this may compile (because `()` implements `Default`),
4149 /// // or it may not (because `!` does not implement `Default`)
4150 /// }
4151 /// ```
4152 ///
4153 /// {{produces}}
4154 ///
4155 /// ### Explanation
4156 ///
4157 /// Due to historic reasons never type fallback was `()`, meaning that `!` got spontaneously
4158 /// coerced to `()`. There are plans to change that, but they may make the code such as above
4159 /// not compile. Instead of depending on the fallback, you should specify the type explicitly:
4160 /// ```
4161 /// if true {
4162 /// return
4163 /// } else {
4164 /// // type is explicitly specified, fallback can't hurt us no more
4165 /// <() as Default>::default()
4166 /// };
4167 /// ```
4168 ///
4169 /// See [Tracking Issue for making `!` fall back to `!`](https://github.com/rust-lang/rust/issues/123748).
4170pub DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK,
4171 Deny,
4172"never type fallback affecting unsafe function calls",
4173 @future_incompatible = FutureIncompatibleInfo {
4174 reason: fcw!(EditionAndFutureReleaseError 2024 "never-type-fallback"),
4175 report_in_deps: true,
4176 };
4177 report_in_external_macro
4178}41794180#[doc =
r" The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(invalid_macro_export_arguments)]"]
#[doc = r""]
#[doc = r" #[macro_export(invalid_parameter)]"]
#[doc = r" macro_rules! myMacro {"]
#[doc = r" () => {"]
#[doc = r" // [...]"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[macro_export(too, many, items)]"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`)."]
#[doc =
r" You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`."]
#[doc = r""]
pub static INVALID_MACRO_EXPORT_ARGUMENTS: &crate::Lint =
&crate::Lint {
name: "INVALID_MACRO_EXPORT_ARGUMENTS",
default_level: crate::Deny,
desc: "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 57571,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4181/// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments.
4182 ///
4183 /// ### Example
4184 ///
4185 /// ```rust,compile_fail
4186 /// #![deny(invalid_macro_export_arguments)]
4187 ///
4188 /// #[macro_export(invalid_parameter)]
4189 /// macro_rules! myMacro {
4190 /// () => {
4191 /// // [...]
4192 /// }
4193 /// }
4194 ///
4195 /// #[macro_export(too, many, items)]
4196 /// ```
4197 ///
4198 /// {{produces}}
4199 ///
4200 /// ### Explanation
4201 ///
4202 /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`).
4203 /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`.
4204 ///
4205pub INVALID_MACRO_EXPORT_ARGUMENTS,
4206 Deny,
4207"\"invalid_parameter\" isn't a valid argument for `#[macro_export]`",
4208 @future_incompatible = FutureIncompatibleInfo {
4209 reason: fcw!(FutureReleaseError #57571),
4210 report_in_deps: true,
4211 };
4212}42134214#[doc =
r" The `ambiguous_derive_helpers` lint detects cases where a derive macro's helper attribute"]
#[doc = r" is the same name as that of a built-in attribute."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (proc-macro)"]
#[doc = r#" #![crate_type = "proc-macro"]"#]
#[doc = r" #![deny(ambiguous_derive_helpers)]"]
#[doc = r""]
#[doc = r" use proc_macro::TokenStream;"]
#[doc = r""]
#[doc = r" #[proc_macro_derive(Trait, attributes(ignore))]"]
#[doc = r" pub fn example(input: TokenStream) -> TokenStream {"]
#[doc = r" TokenStream::new()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" Produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" warning: there exists a built-in attribute with the same name"]
#[doc = r" --> file.rs:5:39"]
#[doc = r" |"]
#[doc = r" 5 | #[proc_macro_derive(Trait, attributes(ignore))]"]
#[doc = r" | ^^^^^^"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #151152 <https://github.com/rust-lang/rust/issues/151152>"]
#[doc =
r" = note: `#[deny(ambiguous_derive_helpers)]` (part of `#[deny(future_incompatible)]`) on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Attempting to use this helper attribute will throw an error:"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs-dependency)"]
#[doc = r" #[derive(Trait)]"]
#[doc = r" struct Example {"]
#[doc = r" #[ignore]"]
#[doc = r" fields: ()"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" Produces:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error[E0659]: `ignore` is ambiguous"]
#[doc = r" --> src/lib.rs:5:7"]
#[doc = r" |"]
#[doc = r" 5 | #[ignore]"]
#[doc = r" | ^^^^^^ ambiguous name"]
#[doc = r" |"]
#[doc =
r" = note: ambiguous because of a name conflict with a builtin attribute"]
#[doc = r" = note: `ignore` could refer to a built-in attribute"]
#[doc =
r" note: `ignore` could also refer to the derive helper attribute defined here"]
#[doc = r" --> src/lib.rs:3:10"]
#[doc = r" |"]
#[doc = r" 3 | #[derive(Trait)]"]
#[doc = r" | ^^^^^"]
#[doc = r" ```"]
pub static AMBIGUOUS_DERIVE_HELPERS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_DERIVE_HELPERS",
default_level: crate::Warn,
desc: "detects derive helper attributes that are ambiguous with built-in attributes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 151276,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4215/// The `ambiguous_derive_helpers` lint detects cases where a derive macro's helper attribute
4216 /// is the same name as that of a built-in attribute.
4217 ///
4218 /// ### Example
4219 ///
4220 /// ```rust,ignore (proc-macro)
4221 /// #![crate_type = "proc-macro"]
4222 /// #![deny(ambiguous_derive_helpers)]
4223 ///
4224 /// use proc_macro::TokenStream;
4225 ///
4226 /// #[proc_macro_derive(Trait, attributes(ignore))]
4227 /// pub fn example(input: TokenStream) -> TokenStream {
4228 /// TokenStream::new()
4229 /// }
4230 /// ```
4231 ///
4232 /// Produces:
4233 ///
4234 /// ```text
4235 /// warning: there exists a built-in attribute with the same name
4236 /// --> file.rs:5:39
4237 /// |
4238 /// 5 | #[proc_macro_derive(Trait, attributes(ignore))]
4239 /// | ^^^^^^
4240 /// |
4241 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4242 /// = note: for more information, see issue #151152 <https://github.com/rust-lang/rust/issues/151152>
4243 /// = note: `#[deny(ambiguous_derive_helpers)]` (part of `#[deny(future_incompatible)]`) on by default
4244 /// ```
4245 ///
4246 /// ### Explanation
4247 ///
4248 /// Attempting to use this helper attribute will throw an error:
4249 ///
4250 /// ```rust,ignore (needs-dependency)
4251 /// #[derive(Trait)]
4252 /// struct Example {
4253 /// #[ignore]
4254 /// fields: ()
4255 /// }
4256 /// ```
4257 ///
4258 /// Produces:
4259 ///
4260 /// ```text
4261 /// error[E0659]: `ignore` is ambiguous
4262 /// --> src/lib.rs:5:7
4263 /// |
4264 /// 5 | #[ignore]
4265 /// | ^^^^^^ ambiguous name
4266 /// |
4267 /// = note: ambiguous because of a name conflict with a builtin attribute
4268 /// = note: `ignore` could refer to a built-in attribute
4269 /// note: `ignore` could also refer to the derive helper attribute defined here
4270 /// --> src/lib.rs:3:10
4271 /// |
4272 /// 3 | #[derive(Trait)]
4273 /// | ^^^^^
4274 /// ```
4275pub AMBIGUOUS_DERIVE_HELPERS,
4276 Warn,
4277"detects derive helper attributes that are ambiguous with built-in attributes",
4278 @future_incompatible = FutureIncompatibleInfo {
4279 reason: fcw!(FutureReleaseError #151276),
4280 };
4281}42824283#[doc =
r" The `private_interfaces` lint detects types in a primary interface of an item,"]
#[doc =
r" that are more private than the item itself. Primary interface of an item is all"]
#[doc =
r" its interface except for bounds on generic parameters and where clauses."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(private_interfaces)]"]
#[doc = r" struct SemiPriv;"]
#[doc = r""]
#[doc = r" mod m1 {"]
#[doc = r" struct Priv;"]
#[doc = r" impl crate::SemiPriv {"]
#[doc = r" pub fn f(_: Priv) {}"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Having something private in primary interface guarantees that"]
#[doc = r" the item will be unusable from outer modules due to type privacy."]
pub static PRIVATE_INTERFACES: &crate::Lint =
&crate::Lint {
name: "PRIVATE_INTERFACES",
default_level: crate::Warn,
desc: "private type in primary interface of an item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4284/// The `private_interfaces` lint detects types in a primary interface of an item,
4285 /// that are more private than the item itself. Primary interface of an item is all
4286 /// its interface except for bounds on generic parameters and where clauses.
4287 ///
4288 /// ### Example
4289 ///
4290 /// ```rust,compile_fail
4291 /// # #![allow(unused)]
4292 /// #![deny(private_interfaces)]
4293 /// struct SemiPriv;
4294 ///
4295 /// mod m1 {
4296 /// struct Priv;
4297 /// impl crate::SemiPriv {
4298 /// pub fn f(_: Priv) {}
4299 /// }
4300 /// }
4301 ///
4302 /// # fn main() {}
4303 /// ```
4304 ///
4305 /// {{produces}}
4306 ///
4307 /// ### Explanation
4308 ///
4309 /// Having something private in primary interface guarantees that
4310 /// the item will be unusable from outer modules due to type privacy.
4311pub PRIVATE_INTERFACES,
4312 Warn,
4313"private type in primary interface of an item",
4314}43154316#[doc =
r" The `private_bounds` lint detects types in a secondary interface of an item,"]
#[doc =
r" that are more private than the item itself. Secondary interface of an item consists of"]
#[doc =
r" bounds on generic parameters and where clauses, including supertraits for trait items."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(private_bounds)]"]
#[doc = r""]
#[doc = r" struct PrivTy;"]
#[doc = r" pub struct S"]
#[doc = r" where PrivTy:"]
#[doc = r" {}"]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Having private types or traits in item bounds makes it less clear what interface"]
#[doc = r" the item actually provides."]
pub static PRIVATE_BOUNDS: &crate::Lint =
&crate::Lint {
name: "PRIVATE_BOUNDS",
default_level: crate::Warn,
desc: "private type in secondary interface of an item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4317/// The `private_bounds` lint detects types in a secondary interface of an item,
4318 /// that are more private than the item itself. Secondary interface of an item consists of
4319 /// bounds on generic parameters and where clauses, including supertraits for trait items.
4320 ///
4321 /// ### Example
4322 ///
4323 /// ```rust,compile_fail
4324 /// # #![allow(unused)]
4325 /// #![deny(private_bounds)]
4326 ///
4327 /// struct PrivTy;
4328 /// pub struct S
4329 /// where PrivTy:
4330 /// {}
4331 /// # fn main() {}
4332 /// ```
4333 ///
4334 /// {{produces}}
4335 ///
4336 /// ### Explanation
4337 ///
4338 /// Having private types or traits in item bounds makes it less clear what interface
4339 /// the item actually provides.
4340pub PRIVATE_BOUNDS,
4341 Warn,
4342"private type in secondary interface of an item",
4343}43444345#[doc =
r" The `unnameable_types` lint detects types for which you can get objects of that type,"]
#[doc = r" but cannot name the type itself."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" # #![allow(unused)]"]
#[doc = r" #![deny(unnameable_types)]"]
#[doc = r" mod m {"]
#[doc = r" pub struct S;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub fn get_unnameable() -> m::S { m::S }"]
#[doc = r" # fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is often expected that if you can obtain an object of type `T`, then"]
#[doc =
r" you can name the type `T` as well; this lint attempts to enforce this rule."]
#[doc =
r" The recommended action is to either reexport the type properly to make it nameable,"]
#[doc =
r" or document that users are not supposed to be able to name it for one reason or another."]
#[doc = r""]
#[doc =
r" Besides types, this lint applies to traits because traits can also leak through signatures,"]
#[doc =
r" and you may obtain objects of their `dyn Trait` or `impl Trait` types."]
pub static UNNAMEABLE_TYPES: &crate::Lint =
&crate::Lint {
name: "UNNAMEABLE_TYPES",
default_level: crate::Allow,
desc: "effective visibility of a type is larger than the area in which it can be named",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4346/// The `unnameable_types` lint detects types for which you can get objects of that type,
4347 /// but cannot name the type itself.
4348 ///
4349 /// ### Example
4350 ///
4351 /// ```rust,compile_fail
4352 /// # #![allow(unused)]
4353 /// #![deny(unnameable_types)]
4354 /// mod m {
4355 /// pub struct S;
4356 /// }
4357 ///
4358 /// pub fn get_unnameable() -> m::S { m::S }
4359 /// # fn main() {}
4360 /// ```
4361 ///
4362 /// {{produces}}
4363 ///
4364 /// ### Explanation
4365 ///
4366 /// It is often expected that if you can obtain an object of type `T`, then
4367 /// you can name the type `T` as well; this lint attempts to enforce this rule.
4368 /// The recommended action is to either reexport the type properly to make it nameable,
4369 /// or document that users are not supposed to be able to name it for one reason or another.
4370 ///
4371 /// Besides types, this lint applies to traits because traits can also leak through signatures,
4372 /// and you may obtain objects of their `dyn Trait` or `impl Trait` types.
4373pub UNNAMEABLE_TYPES,
4374 Allow,
4375"effective visibility of a type is larger than the area in which it can be named",
4376}43774378#[doc =
r" The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r#" #[diagnostic::do_not_recommend(message = "message")]"#]
#[doc = r" trait Trait {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to use options or syntax that is not supported. Check the spelling,"]
#[doc =
r" and check the diagnostic attribute listing for the correct name and syntax. Also consider if"]
#[doc =
r" you are using an old version of the compiler; perhaps the option or syntax is only available"]
#[doc =
r" in a newer version. See the [reference] for a list of diagnostic attributes and the syntax"]
#[doc = r" of each."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MALFORMED_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "MALFORMED_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects malformed diagnostic attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4379/// The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes.
4380 ///
4381 /// ### Example
4382 ///
4383 /// ```rust
4384 /// #[diagnostic::do_not_recommend(message = "message")]
4385 /// trait Trait {}
4386 /// ```
4387 ///
4388 /// {{produces}}
4389 ///
4390 /// ### Explanation
4391 ///
4392 /// It is usually a mistake to use options or syntax that is not supported. Check the spelling,
4393 /// and check the diagnostic attribute listing for the correct name and syntax. Also consider if
4394 /// you are using an old version of the compiler; perhaps the option or syntax is only available
4395 /// in a newer version. See the [reference] for a list of diagnostic attributes and the syntax
4396 /// of each.
4397 ///
4398 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4399pub MALFORMED_DIAGNOSTIC_ATTRIBUTES,
4400 Warn,
4401"detects malformed diagnostic attributes",
4402}44034404#[doc =
r" The `misplaced_diagnostic_attributes` lint detects wrongly placed diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[diagnostic::do_not_recommend]"]
#[doc = r" struct NotUserFacing;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a diagnostic attribute on an item it is not meant for."]
#[doc =
r" For example, `#[diagnostic::do_not_recommend]` can only be placed on trait implementations,"]
#[doc =
r" and does nothing if placed elsewhere. See the [reference] for a list of diagnostic"]
#[doc = r" attributes and their correct positions."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MISPLACED_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "MISPLACED_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects diagnostic attributes that are placed on the wrong item",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4405/// The `misplaced_diagnostic_attributes` lint detects wrongly placed diagnostic attributes.
4406 ///
4407 /// ### Example
4408 ///
4409 /// ```rust
4410 /// #[diagnostic::do_not_recommend]
4411 /// struct NotUserFacing;
4412 /// ```
4413 ///
4414 /// {{produces}}
4415 ///
4416 /// ### Explanation
4417 ///
4418 /// It is usually a mistake to specify a diagnostic attribute on an item it is not meant for.
4419 /// For example, `#[diagnostic::do_not_recommend]` can only be placed on trait implementations,
4420 /// and does nothing if placed elsewhere. See the [reference] for a list of diagnostic
4421 /// attributes and their correct positions.
4422 ///
4423 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4424pub MISPLACED_DIAGNOSTIC_ATTRIBUTES,
4425 Warn,
4426"detects diagnostic attributes that are placed on the wrong item",
4427}44284429#[doc =
r" The `unknown_diagnostic_attributes` lint detects unknown diagnostic attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #[diagnostic::does_not_exist]"]
#[doc = r" struct Thing;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" It is usually a mistake to specify a diagnostic attribute that does not exist. Check the"]
#[doc =
r" spelling, and check the diagnostic attribute listing for the correct name. Also consider if"]
#[doc =
r" you are using an old version of the compiler and the attribute is only available in a newer"]
#[doc =
r" version. See the [reference] for the list of diagnostic attributes."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static UNKNOWN_DIAGNOSTIC_ATTRIBUTES: &crate::Lint =
&crate::Lint {
name: "UNKNOWN_DIAGNOSTIC_ATTRIBUTES",
default_level: crate::Warn,
desc: "detects unknown diagnostic attributes",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4430/// The `unknown_diagnostic_attributes` lint detects unknown diagnostic attributes.
4431 ///
4432 /// ### Example
4433 ///
4434 /// ```rust
4435 /// #[diagnostic::does_not_exist]
4436 /// struct Thing;
4437 /// ```
4438 ///
4439 /// {{produces}}
4440 ///
4441 /// ### Explanation
4442 ///
4443 /// It is usually a mistake to specify a diagnostic attribute that does not exist. Check the
4444 /// spelling, and check the diagnostic attribute listing for the correct name. Also consider if
4445 /// you are using an old version of the compiler and the attribute is only available in a newer
4446 /// version. See the [reference] for the list of diagnostic attributes.
4447 ///
4448 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4449pub UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
4450 Warn,
4451"detects unknown diagnostic attributes",
4452}44534454#[doc =
r" The `malformed_diagnostic_format_literals` lint detects malformed diagnostic format"]
#[doc = r" literals."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc =
r#" #[diagnostic::on_unimplemented(message = "{Self}} does not implement `Trait`")]"#]
#[doc = r" trait Trait {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The `#[diagnostic::on_unimplemented]` attribute accepts string literal values that are"]
#[doc =
r" similar to `format!`'s string literal. See the [reference] for details on what is permitted"]
#[doc = r" in this string literal."]
#[doc = r""]
#[doc =
r" [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace"]
pub static MALFORMED_DIAGNOSTIC_FORMAT_LITERALS: &crate::Lint =
&crate::Lint {
name: "MALFORMED_DIAGNOSTIC_FORMAT_LITERALS",
default_level: crate::Warn,
desc: "detects diagnostic attribute with malformed diagnostic format literals",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4455/// The `malformed_diagnostic_format_literals` lint detects malformed diagnostic format
4456 /// literals.
4457 ///
4458 /// ### Example
4459 ///
4460 /// ```rust
4461 /// #[diagnostic::on_unimplemented(message = "{Self}} does not implement `Trait`")]
4462 /// trait Trait {}
4463 /// ```
4464 ///
4465 /// {{produces}}
4466 ///
4467 /// ### Explanation
4468 ///
4469 /// The `#[diagnostic::on_unimplemented]` attribute accepts string literal values that are
4470 /// similar to `format!`'s string literal. See the [reference] for details on what is permitted
4471 /// in this string literal.
4472 ///
4473 /// [reference]: https://doc.rust-lang.org/nightly/reference/attributes/diagnostics.html#the-diagnostic-tool-attribute-namespace
4474pub MALFORMED_DIAGNOSTIC_FORMAT_LITERALS,
4475 Warn,
4476"detects diagnostic attribute with malformed diagnostic format literals",
4477}44784479#[doc =
r" The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity"]
#[doc = r" errors, but previously didn't do that due to rustc bugs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" // library crate `my_library`"]
#[doc = r" mod mod1 { pub const C: u32 = 1; }"]
#[doc = r" mod mod2 { pub const C: u32 = 2; }"]
#[doc = r" pub use mod1::*;"]
#[doc = r" pub use mod2::*;"]
#[doc = r""]
#[doc = r" // another crate using `my_library`"]
#[doc = r" let c = my_library::C; // `C` is ambiguous"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust compile it successfully because"]
#[doc =
r" ambiguous glob imports weren't preserved correctly over crate boundaries."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_GLOB_IMPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_IMPORTS",
default_level: crate::Deny,
desc: "detects certain glob imports that require reporting an ambiguity error",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 114095,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4480/// The `ambiguous_glob_imports` lint detects glob imports that should report ambiguity
4481 /// errors, but previously didn't do that due to rustc bugs.
4482 ///
4483 /// ### Example
4484 ///
4485 /// ```rust,ignore (needs extern crate)
4486 /// // library crate `my_library`
4487 /// mod mod1 { pub const C: u32 = 1; }
4488 /// mod mod2 { pub const C: u32 = 2; }
4489 /// pub use mod1::*;
4490 /// pub use mod2::*;
4491 ///
4492 /// // another crate using `my_library`
4493 /// let c = my_library::C; // `C` is ambiguous
4494 /// ```
4495 ///
4496 /// ### Explanation
4497 ///
4498 /// Previous versions of Rust compile it successfully because
4499 /// ambiguous glob imports weren't preserved correctly over crate boundaries.
4500 ///
4501 /// This is a [future-incompatible] lint to transition this to a
4502 /// hard error in the future.
4503 ///
4504 /// [future-incompatible]: ../index.md#future-incompatible-lints
4505pub AMBIGUOUS_GLOB_IMPORTS,
4506 Deny,
4507"detects certain glob imports that require reporting an ambiguity error",
4508 @future_incompatible = FutureIncompatibleInfo {
4509 reason: fcw!(FutureReleaseError #114095),
4510 report_in_deps: true,
4511 };
4512}45134514#[doc =
r" The `ambiguous_glob_imported_traits` lint reports uses of traits that are"]
#[doc =
r" imported ambiguously via glob imports. Previously, this was not enforced"]
#[doc = r" due to a bug in rustc."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_glob_imported_traits)]"]
#[doc = r" mod m1 {"]
#[doc = r" pub trait Trait {"]
#[doc = r" fn method1(&self) {}"]
#[doc = r" }"]
#[doc = r" impl Trait for u8 {}"]
#[doc = r" }"]
#[doc = r" mod m2 {"]
#[doc = r" pub trait Trait {"]
#[doc = r" fn method2(&self) {}"]
#[doc = r" }"]
#[doc = r" impl Trait for u8 {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" use m1::*;"]
#[doc = r" use m2::*;"]
#[doc = r" 0u8.method1();"]
#[doc = r" 0u8.method2();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" When multiple traits with the same name are brought into scope through glob imports,"]
#[doc =
r#" one trait becomes the "primary" one while the others are shadowed. Methods from the"#]
#[doc =
r#" shadowed traits (e.g. `method2`) become inaccessible, while methods from the "primary""#]
#[doc =
r" trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope,"]
#[doc =
r" but we have to allow this for now because of backwards compatibility."]
#[doc =
r#" This lint reports uses of these "primary" traits that are ambiguous."#]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_GLOB_IMPORTED_TRAITS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_GLOB_IMPORTED_TRAITS",
default_level: crate::Warn,
desc: "detects uses of ambiguously glob imported traits",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 147992,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4515/// The `ambiguous_glob_imported_traits` lint reports uses of traits that are
4516 /// imported ambiguously via glob imports. Previously, this was not enforced
4517 /// due to a bug in rustc.
4518 ///
4519 /// ### Example
4520 ///
4521 /// ```rust,compile_fail
4522 /// #![deny(ambiguous_glob_imported_traits)]
4523 /// mod m1 {
4524 /// pub trait Trait {
4525 /// fn method1(&self) {}
4526 /// }
4527 /// impl Trait for u8 {}
4528 /// }
4529 /// mod m2 {
4530 /// pub trait Trait {
4531 /// fn method2(&self) {}
4532 /// }
4533 /// impl Trait for u8 {}
4534 /// }
4535 ///
4536 /// fn main() {
4537 /// use m1::*;
4538 /// use m2::*;
4539 /// 0u8.method1();
4540 /// 0u8.method2();
4541 /// }
4542 /// ```
4543 ///
4544 /// {{produces}}
4545 ///
4546 /// ### Explanation
4547 ///
4548 /// When multiple traits with the same name are brought into scope through glob imports,
4549 /// one trait becomes the "primary" one while the others are shadowed. Methods from the
4550 /// shadowed traits (e.g. `method2`) become inaccessible, while methods from the "primary"
4551 /// trait (e.g. `method1`) still resolve. Ideally, none of the ambiguous traits would be in scope,
4552 /// but we have to allow this for now because of backwards compatibility.
4553 /// This lint reports uses of these "primary" traits that are ambiguous.
4554 ///
4555 /// This is a [future-incompatible] lint to transition this to a
4556 /// hard error in the future.
4557 ///
4558 /// [future-incompatible]: ../index.md#future-incompatible-lints
4559pub AMBIGUOUS_GLOB_IMPORTED_TRAITS,
4560 Warn,
4561"detects uses of ambiguously glob imported traits",
4562 @future_incompatible = FutureIncompatibleInfo {
4563 reason: fcw!(FutureReleaseError #147992),
4564 report_in_deps: false,
4565 };
4566}45674568#[doc =
r" The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but"]
#[doc =
r" previously didn't do that due to `#[macro_use]` prelude macro import."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(ambiguous_panic_imports)]"]
#[doc = r" #![no_std]"]
#[doc = r""]
#[doc = r" extern crate std;"]
#[doc = r" use std::prelude::v1::*;"]
#[doc = r""]
#[doc = r" fn xx() {"]
#[doc = r" panic!(); // resolves to core::panic"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Future versions of Rust will no longer accept the ambiguous resolution."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_PANIC_IMPORTS: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_PANIC_IMPORTS",
default_level: crate::Warn,
desc: "detects ambiguous core and std panic imports",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 147319,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4569/// The `ambiguous_panic_imports` lint detects ambiguous core and std panic imports, but
4570 /// previously didn't do that due to `#[macro_use]` prelude macro import.
4571 ///
4572 /// ### Example
4573 ///
4574 /// ```rust,compile_fail
4575 /// #![deny(ambiguous_panic_imports)]
4576 /// #![no_std]
4577 ///
4578 /// extern crate std;
4579 /// use std::prelude::v1::*;
4580 ///
4581 /// fn xx() {
4582 /// panic!(); // resolves to core::panic
4583 /// }
4584 /// ```
4585 ///
4586 /// {{produces}}
4587 ///
4588 /// ### Explanation
4589 ///
4590 /// Future versions of Rust will no longer accept the ambiguous resolution.
4591 ///
4592 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
4593 ///
4594 /// [future-incompatible]: ../index.md#future-incompatible-lints
4595pub AMBIGUOUS_PANIC_IMPORTS,
4596 Warn,
4597"detects ambiguous core and std panic imports",
4598 @future_incompatible = FutureIncompatibleInfo {
4599 reason: fcw!(FutureReleaseError #147319),
4600 report_in_deps: false,
4601 };
4602}46034604#[doc =
r" The `ambiguous_import_visibilities` lint detects imports that should report ambiguity"]
#[doc = r" errors, but previously didn't do that due to rustc bugs."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unknown_lints)]"]
#[doc = r" #![deny(ambiguous_import_visibilities)]"]
#[doc = r" mod reexport {"]
#[doc = r" mod m {"]
#[doc = r" pub struct S {}"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" macro_rules! mac {"]
#[doc = r" () => { use m::S; }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" pub use m::*;"]
#[doc = r" mac!();"]
#[doc = r""]
#[doc = r" pub use S as Z; // ambiguous visibility"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" reexport::Z {};"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous versions of Rust compile it successfully because it"]
#[doc =
r" fetched the glob import's visibility for `pub use S as Z` import, and ignored the private"]
#[doc = r" `use m::S` import that appeared later."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static AMBIGUOUS_IMPORT_VISIBILITIES: &crate::Lint =
&crate::Lint {
name: "AMBIGUOUS_IMPORT_VISIBILITIES",
default_level: crate::Warn,
desc: "detects certain glob imports that require reporting an ambiguity error",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 149145,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4605/// The `ambiguous_import_visibilities` lint detects imports that should report ambiguity
4606 /// errors, but previously didn't do that due to rustc bugs.
4607 ///
4608 /// ### Example
4609 ///
4610 /// ```rust,compile_fail
4611 /// #![deny(unknown_lints)]
4612 /// #![deny(ambiguous_import_visibilities)]
4613 /// mod reexport {
4614 /// mod m {
4615 /// pub struct S {}
4616 /// }
4617 ///
4618 /// macro_rules! mac {
4619 /// () => { use m::S; }
4620 /// }
4621 ///
4622 /// pub use m::*;
4623 /// mac!();
4624 ///
4625 /// pub use S as Z; // ambiguous visibility
4626 /// }
4627 ///
4628 /// fn main() {
4629 /// reexport::Z {};
4630 /// }
4631 /// ```
4632 ///
4633 /// {{produces}}
4634 ///
4635 /// ### Explanation
4636 ///
4637 /// Previous versions of Rust compile it successfully because it
4638 /// fetched the glob import's visibility for `pub use S as Z` import, and ignored the private
4639 /// `use m::S` import that appeared later.
4640 ///
4641 /// This is a [future-incompatible] lint to transition this to a
4642 /// hard error in the future.
4643 ///
4644 /// [future-incompatible]: ../index.md#future-incompatible-lints
4645pub AMBIGUOUS_IMPORT_VISIBILITIES,
4646 Warn,
4647"detects certain glob imports that require reporting an ambiguity error",
4648 @future_incompatible = FutureIncompatibleInfo {
4649 reason: fcw!(FutureReleaseError #149145),
4650 };
4651}46524653#[doc =
r" The `refining_impl_trait_reachable` lint detects `impl Trait` return"]
#[doc =
r" types in method signatures that are refined by a publically reachable"]
#[doc =
r" trait implementation, meaning the implementation adds information about"]
#[doc = r" the return type that is not present in the trait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(refining_impl_trait)]"]
#[doc = r""]
#[doc = r" use std::fmt::Display;"]
#[doc = r""]
#[doc = r" pub trait AsDisplay {"]
#[doc = r" fn as_display(&self) -> impl Display;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<'s> AsDisplay for &'s str {"]
#[doc = r" fn as_display(&self) -> Self {"]
#[doc = r" *self"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" // users can observe that the return type of"]
#[doc = r" // `<&str as AsDisplay>::as_display()` is `&str`."]
#[doc = r#" let _x: &str = "".as_display();"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Callers of methods for types where the implementation is known are"]
#[doc =
r" able to observe the types written in the impl signature. This may be"]
#[doc =
r" intended behavior, but may also lead to implementation details being"]
#[doc =
r" revealed unintentionally. In particular, it may pose a semver hazard"]
#[doc =
r" for authors of libraries who do not wish to make stronger guarantees"]
#[doc = r" about the types than what is written in the trait signature."]
#[doc = r""]
#[doc = r" `refining_impl_trait` is a lint group composed of two lints:"]
#[doc = r""]
#[doc =
r" * `refining_impl_trait_reachable`, for refinements that are publically"]
#[doc = r" reachable outside a crate, and"]
#[doc =
r" * `refining_impl_trait_internal`, for refinements that are only visible"]
#[doc = r" within a crate."]
#[doc = r""]
#[doc = r" We are seeking feedback on each of these lints; see issue"]
#[doc =
r" [#121718](https://github.com/rust-lang/rust/issues/121718) for more"]
#[doc = r" information."]
pub static REFINING_IMPL_TRAIT_REACHABLE: &crate::Lint =
&crate::Lint {
name: "REFINING_IMPL_TRAIT_REACHABLE",
default_level: crate::Warn,
desc: "impl trait in impl method signature does not match trait method signature",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4654/// The `refining_impl_trait_reachable` lint detects `impl Trait` return
4655 /// types in method signatures that are refined by a publically reachable
4656 /// trait implementation, meaning the implementation adds information about
4657 /// the return type that is not present in the trait.
4658 ///
4659 /// ### Example
4660 ///
4661 /// ```rust,compile_fail
4662 /// #![deny(refining_impl_trait)]
4663 ///
4664 /// use std::fmt::Display;
4665 ///
4666 /// pub trait AsDisplay {
4667 /// fn as_display(&self) -> impl Display;
4668 /// }
4669 ///
4670 /// impl<'s> AsDisplay for &'s str {
4671 /// fn as_display(&self) -> Self {
4672 /// *self
4673 /// }
4674 /// }
4675 ///
4676 /// fn main() {
4677 /// // users can observe that the return type of
4678 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4679 /// let _x: &str = "".as_display();
4680 /// }
4681 /// ```
4682 ///
4683 /// {{produces}}
4684 ///
4685 /// ### Explanation
4686 ///
4687 /// Callers of methods for types where the implementation is known are
4688 /// able to observe the types written in the impl signature. This may be
4689 /// intended behavior, but may also lead to implementation details being
4690 /// revealed unintentionally. In particular, it may pose a semver hazard
4691 /// for authors of libraries who do not wish to make stronger guarantees
4692 /// about the types than what is written in the trait signature.
4693 ///
4694 /// `refining_impl_trait` is a lint group composed of two lints:
4695 ///
4696 /// * `refining_impl_trait_reachable`, for refinements that are publically
4697 /// reachable outside a crate, and
4698 /// * `refining_impl_trait_internal`, for refinements that are only visible
4699 /// within a crate.
4700 ///
4701 /// We are seeking feedback on each of these lints; see issue
4702 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4703 /// information.
4704pub REFINING_IMPL_TRAIT_REACHABLE,
4705 Warn,
4706"impl trait in impl method signature does not match trait method signature",
4707}47084709#[doc =
r" The `refining_impl_trait_internal` lint detects `impl Trait` return"]
#[doc =
r" types in method signatures that are refined by a trait implementation,"]
#[doc =
r" meaning the implementation adds information about the return type that"]
#[doc = r" is not present in the trait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(refining_impl_trait)]"]
#[doc = r""]
#[doc = r" use std::fmt::Display;"]
#[doc = r""]
#[doc = r" trait AsDisplay {"]
#[doc = r" fn as_display(&self) -> impl Display;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<'s> AsDisplay for &'s str {"]
#[doc = r" fn as_display(&self) -> Self {"]
#[doc = r" *self"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" // users can observe that the return type of"]
#[doc = r" // `<&str as AsDisplay>::as_display()` is `&str`."]
#[doc = r#" let _x: &str = "".as_display();"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Callers of methods for types where the implementation is known are"]
#[doc =
r" able to observe the types written in the impl signature. This may be"]
#[doc =
r" intended behavior, but may also lead to implementation details being"]
#[doc =
r" revealed unintentionally. In particular, it may pose a semver hazard"]
#[doc =
r" for authors of libraries who do not wish to make stronger guarantees"]
#[doc = r" about the types than what is written in the trait signature."]
#[doc = r""]
#[doc = r" `refining_impl_trait` is a lint group composed of two lints:"]
#[doc = r""]
#[doc =
r" * `refining_impl_trait_reachable`, for refinements that are publically"]
#[doc = r" reachable outside a crate, and"]
#[doc =
r" * `refining_impl_trait_internal`, for refinements that are only visible"]
#[doc = r" within a crate."]
#[doc = r""]
#[doc = r" We are seeking feedback on each of these lints; see issue"]
#[doc =
r" [#121718](https://github.com/rust-lang/rust/issues/121718) for more"]
#[doc = r" information."]
pub static REFINING_IMPL_TRAIT_INTERNAL: &crate::Lint =
&crate::Lint {
name: "REFINING_IMPL_TRAIT_INTERNAL",
default_level: crate::Warn,
desc: "impl trait in impl method signature does not match trait method signature",
is_externally_loaded: false,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4710/// The `refining_impl_trait_internal` lint detects `impl Trait` return
4711 /// types in method signatures that are refined by a trait implementation,
4712 /// meaning the implementation adds information about the return type that
4713 /// is not present in the trait.
4714 ///
4715 /// ### Example
4716 ///
4717 /// ```rust,compile_fail
4718 /// #![deny(refining_impl_trait)]
4719 ///
4720 /// use std::fmt::Display;
4721 ///
4722 /// trait AsDisplay {
4723 /// fn as_display(&self) -> impl Display;
4724 /// }
4725 ///
4726 /// impl<'s> AsDisplay for &'s str {
4727 /// fn as_display(&self) -> Self {
4728 /// *self
4729 /// }
4730 /// }
4731 ///
4732 /// fn main() {
4733 /// // users can observe that the return type of
4734 /// // `<&str as AsDisplay>::as_display()` is `&str`.
4735 /// let _x: &str = "".as_display();
4736 /// }
4737 /// ```
4738 ///
4739 /// {{produces}}
4740 ///
4741 /// ### Explanation
4742 ///
4743 /// Callers of methods for types where the implementation is known are
4744 /// able to observe the types written in the impl signature. This may be
4745 /// intended behavior, but may also lead to implementation details being
4746 /// revealed unintentionally. In particular, it may pose a semver hazard
4747 /// for authors of libraries who do not wish to make stronger guarantees
4748 /// about the types than what is written in the trait signature.
4749 ///
4750 /// `refining_impl_trait` is a lint group composed of two lints:
4751 ///
4752 /// * `refining_impl_trait_reachable`, for refinements that are publically
4753 /// reachable outside a crate, and
4754 /// * `refining_impl_trait_internal`, for refinements that are only visible
4755 /// within a crate.
4756 ///
4757 /// We are seeking feedback on each of these lints; see issue
4758 /// [#121718](https://github.com/rust-lang/rust/issues/121718) for more
4759 /// information.
4760pub REFINING_IMPL_TRAIT_INTERNAL,
4761 Warn,
4762"impl trait in impl method signature does not match trait method signature",
4763}47644765#[doc =
r" The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes"]
#[doc =
r" in associated constants when there are other lifetimes in scope. This was"]
#[doc =
r" accidentally supported, and this lint was later relaxed to allow eliding"]
#[doc = r" lifetimes to `'static` when there are no lifetimes in scope."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(elided_lifetimes_in_associated_constant)]"]
#[doc = r""]
#[doc = r" struct Foo<'a>(&'a ());"]
#[doc = r""]
#[doc = r" impl<'a> Foo<'a> {"]
#[doc = r#" const STR: &str = "hello, world";"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" Previous version of Rust"]
#[doc = r""]
#[doc =
r" Implicit static-in-const behavior was decided [against] for associated"]
#[doc =
r" constants because of ambiguity. This, however, regressed and the compiler"]
#[doc =
r" erroneously treats elided lifetimes in associated constants as lifetime"]
#[doc = r" parameters on the impl."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [against]: https://github.com/rust-lang/rust/issues/38831"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT: &crate::Lint =
&crate::Lint {
name: "ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT",
default_level: crate::Deny,
desc: "elided lifetimes cannot be used in associated constants in impls",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 115010,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4766/// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes
4767 /// in associated constants when there are other lifetimes in scope. This was
4768 /// accidentally supported, and this lint was later relaxed to allow eliding
4769 /// lifetimes to `'static` when there are no lifetimes in scope.
4770 ///
4771 /// ### Example
4772 ///
4773 /// ```rust,compile_fail
4774 /// #![deny(elided_lifetimes_in_associated_constant)]
4775 ///
4776 /// struct Foo<'a>(&'a ());
4777 ///
4778 /// impl<'a> Foo<'a> {
4779 /// const STR: &str = "hello, world";
4780 /// }
4781 /// ```
4782 ///
4783 /// {{produces}}
4784 ///
4785 /// ### Explanation
4786 ///
4787 /// Previous version of Rust
4788 ///
4789 /// Implicit static-in-const behavior was decided [against] for associated
4790 /// constants because of ambiguity. This, however, regressed and the compiler
4791 /// erroneously treats elided lifetimes in associated constants as lifetime
4792 /// parameters on the impl.
4793 ///
4794 /// This is a [future-incompatible] lint to transition this to a
4795 /// hard error in the future.
4796 ///
4797 /// [against]: https://github.com/rust-lang/rust/issues/38831
4798 /// [future-incompatible]: ../index.md#future-incompatible-lints
4799pub ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
4800 Deny,
4801"elided lifetimes cannot be used in associated constants in impls",
4802 @future_incompatible = FutureIncompatibleInfo {
4803 reason: fcw!(FutureReleaseError #115010),
4804 };
4805}48064807#[doc =
r" The `private_macro_use` lint detects private macros that are imported"]
#[doc = r" with `#[macro_use]`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs extern crate)"]
#[doc = r" // extern_macro.rs"]
#[doc = r" macro_rules! foo_ { () => {}; }"]
#[doc = r" use foo_ as foo;"]
#[doc = r""]
#[doc = r" // code.rs"]
#[doc = r""]
#[doc = r" #![deny(private_macro_use)]"]
#[doc = r""]
#[doc = r" #[macro_use]"]
#[doc = r" extern crate extern_macro;"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" foo!();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: cannot find macro `foo` in this scope"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" This lint arises from overlooking visibility checks for macros"]
#[doc = r" in an external crate."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static PRIVATE_MACRO_USE: &crate::Lint =
&crate::Lint {
name: "PRIVATE_MACRO_USE",
default_level: crate::Deny,
desc: "detects certain macro bindings that should not be re-exported",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 120192,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4808/// The `private_macro_use` lint detects private macros that are imported
4809 /// with `#[macro_use]`.
4810 ///
4811 /// ### Example
4812 ///
4813 /// ```rust,ignore (needs extern crate)
4814 /// // extern_macro.rs
4815 /// macro_rules! foo_ { () => {}; }
4816 /// use foo_ as foo;
4817 ///
4818 /// // code.rs
4819 ///
4820 /// #![deny(private_macro_use)]
4821 ///
4822 /// #[macro_use]
4823 /// extern crate extern_macro;
4824 ///
4825 /// fn main() {
4826 /// foo!();
4827 /// }
4828 /// ```
4829 ///
4830 /// This will produce:
4831 ///
4832 /// ```text
4833 /// error: cannot find macro `foo` in this scope
4834 /// ```
4835 ///
4836 /// ### Explanation
4837 ///
4838 /// This lint arises from overlooking visibility checks for macros
4839 /// in an external crate.
4840 ///
4841 /// This is a [future-incompatible] lint to transition this to a
4842 /// hard error in the future.
4843 ///
4844 /// [future-incompatible]: ../index.md#future-incompatible-lints
4845pub PRIVATE_MACRO_USE,
4846 Deny,
4847"detects certain macro bindings that should not be re-exported",
4848 @future_incompatible = FutureIncompatibleInfo {
4849 reason: fcw!(FutureReleaseError #120192),
4850 report_in_deps: true,
4851 };
4852}48534854#[doc =
r" The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for"]
#[doc =
r" foreign trait implementations that concerns the use of type parameters inside trait associated"]
#[doc =
r#" type paths ("projections") whose output may not be a local type that is mistakenly considered"#]
#[doc =
r#" to "cover" said parameters which is **unsound** and which may be rejected by a future version"#]
#[doc = r" of the compiler."]
#[doc = r""]
#[doc = r" Originally reported in [#99554]."]
#[doc = r""]
#[doc = r" [#99554]: https://github.com/rust-lang/rust/issues/99554"]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (dependent)"]
#[doc = r" // dependency.rs"]
#[doc = r#" #![crate_type = "lib"]"#]
#[doc = r""]
#[doc = r" pub trait Trait<T, U> {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ```edition2021,ignore (needs dependency)"]
#[doc = r" // dependent.rs"]
#[doc = r" trait Identity {"]
#[doc = r" type Output;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl<T> Identity for T {"]
#[doc = r" type Output = T;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" struct Local;"]
#[doc = r""]
#[doc =
r" impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)"]
#[doc = r" --> dependent.rs:11:6"]
#[doc = r" |"]
#[doc =
r" 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}"]
#[doc =
r" | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>"]
#[doc =
r" = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type"]
#[doc =
r" = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last"]
#[doc = r" = note: `#[warn(uncovered_param_in_projection)]` on by default"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" FIXME(fmease): Write explainer."]
pub static UNCOVERED_PARAM_IN_PROJECTION: &crate::Lint =
&crate::Lint {
name: "UNCOVERED_PARAM_IN_PROJECTION",
default_level: crate::Warn,
desc: "impl contains type parameters that are not covered",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124559,
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4855/// The `uncovered_param_in_projection` lint detects a violation of one of Rust's orphan rules for
4856 /// foreign trait implementations that concerns the use of type parameters inside trait associated
4857 /// type paths ("projections") whose output may not be a local type that is mistakenly considered
4858 /// to "cover" said parameters which is **unsound** and which may be rejected by a future version
4859 /// of the compiler.
4860 ///
4861 /// Originally reported in [#99554].
4862 ///
4863 /// [#99554]: https://github.com/rust-lang/rust/issues/99554
4864 ///
4865 /// ### Example
4866 ///
4867 /// ```rust,ignore (dependent)
4868 /// // dependency.rs
4869 /// #![crate_type = "lib"]
4870 ///
4871 /// pub trait Trait<T, U> {}
4872 /// ```
4873 ///
4874 /// ```edition2021,ignore (needs dependency)
4875 /// // dependent.rs
4876 /// trait Identity {
4877 /// type Output;
4878 /// }
4879 ///
4880 /// impl<T> Identity for T {
4881 /// type Output = T;
4882 /// }
4883 ///
4884 /// struct Local;
4885 ///
4886 /// impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4887 ///
4888 /// fn main() {}
4889 /// ```
4890 ///
4891 /// This will produce:
4892 ///
4893 /// ```text
4894 /// warning[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4895 /// --> dependent.rs:11:6
4896 /// |
4897 /// 11 | impl<T> dependency::Trait<Local, T> for <T as Identity>::Output {}
4898 /// | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`)
4899 /// |
4900 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4901 /// = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
4902 /// = 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
4903 /// = 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
4904 /// = note: `#[warn(uncovered_param_in_projection)]` on by default
4905 /// ```
4906 ///
4907 /// ### Explanation
4908 ///
4909 /// FIXME(fmease): Write explainer.
4910pub UNCOVERED_PARAM_IN_PROJECTION,
4911 Warn,
4912"impl contains type parameters that are not covered",
4913 @future_incompatible = FutureIncompatibleInfo {
4914 reason: fcw!(FutureReleaseError #124559),
4915 };
4916}49174918#[doc =
r" The `deprecated_safe_2024` lint detects unsafe functions being used as"]
#[doc = r" safe functions."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(deprecated_safe)]"]
#[doc = r" // edition 2021"]
#[doc = r" use std::env;"]
#[doc = r" fn enable_backtrace() {"]
#[doc = r#" env::set_var("RUST_BACKTRACE", "1");"#]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust [editions] allow the language to evolve without breaking backward"]
#[doc =
r" compatibility. This lint catches code that uses `unsafe` functions that"]
#[doc =
r" were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If"]
#[doc =
r" you switch the compiler to Rust 2024 without updating the code, then it"]
#[doc =
r" will fail to compile if you are using a function previously marked as"]
#[doc = r" safe."]
#[doc = r""]
#[doc =
r" You can audit the code to see if it suffices the preconditions of the"]
#[doc =
r" `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If"]
#[doc =
r" you can't fulfill the preconditions, you probably need to switch to a"]
#[doc = r" different way of doing what you want to achieve."]
#[doc = r""]
#[doc =
r" This lint can automatically wrap the calls in `unsafe` blocks, but this"]
#[doc = r" obviously cannot verify that the preconditions of the `unsafe`"]
#[doc = r" functions are fulfilled, so that is still up to the user."]
#[doc = r""]
#[doc =
r#" The lint is currently "allow" by default, but that might change in the"#]
#[doc = r" future."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
pub static DEPRECATED_SAFE_2024: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_SAFE_2024",
default_level: crate::Allow,
desc: "detects unsafe functions being used as safe functions",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "newly-unsafe-functions",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4919/// The `deprecated_safe_2024` lint detects unsafe functions being used as
4920 /// safe functions.
4921 ///
4922 /// ### Example
4923 ///
4924 /// ```rust,edition2021,compile_fail
4925 /// #![deny(deprecated_safe)]
4926 /// // edition 2021
4927 /// use std::env;
4928 /// fn enable_backtrace() {
4929 /// env::set_var("RUST_BACKTRACE", "1");
4930 /// }
4931 /// ```
4932 ///
4933 /// {{produces}}
4934 ///
4935 /// ### Explanation
4936 ///
4937 /// Rust [editions] allow the language to evolve without breaking backward
4938 /// compatibility. This lint catches code that uses `unsafe` functions that
4939 /// were declared as safe (non-`unsafe`) in editions prior to Rust 2024. If
4940 /// you switch the compiler to Rust 2024 without updating the code, then it
4941 /// will fail to compile if you are using a function previously marked as
4942 /// safe.
4943 ///
4944 /// You can audit the code to see if it suffices the preconditions of the
4945 /// `unsafe` code, and if it does, you can wrap it in an `unsafe` block. If
4946 /// you can't fulfill the preconditions, you probably need to switch to a
4947 /// different way of doing what you want to achieve.
4948 ///
4949 /// This lint can automatically wrap the calls in `unsafe` blocks, but this
4950 /// obviously cannot verify that the preconditions of the `unsafe`
4951 /// functions are fulfilled, so that is still up to the user.
4952 ///
4953 /// The lint is currently "allow" by default, but that might change in the
4954 /// future.
4955 ///
4956 /// [editions]: https://doc.rust-lang.org/edition-guide/
4957pub DEPRECATED_SAFE_2024,
4958 Allow,
4959"detects unsafe functions being used as safe functions",
4960 @future_incompatible = FutureIncompatibleInfo {
4961 reason: fcw!(EditionError 2024 "newly-unsafe-functions"),
4962 };
4963}49644965#[doc =
r" The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(missing_unsafe_on_extern)]"]
#[doc = r" #![allow(dead_code)]"]
#[doc = r""]
#[doc = r#" extern "C" {"#]
#[doc = r" fn foo(_: i32);"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Declaring extern items, even without ever using them, can cause Undefined Behavior. We"]
#[doc = r" should consider all sources of Undefined Behavior to be unsafe."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static MISSING_UNSAFE_ON_EXTERN: &crate::Lint =
&crate::Lint {
name: "MISSING_UNSAFE_ON_EXTERN",
default_level: crate::Allow,
desc: "detects missing unsafe keyword on extern declarations",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-extern",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
4966/// The `missing_unsafe_on_extern` lint detects missing unsafe keyword on extern declarations.
4967 ///
4968 /// ### Example
4969 ///
4970 /// ```rust,edition2021
4971 /// #![warn(missing_unsafe_on_extern)]
4972 /// #![allow(dead_code)]
4973 ///
4974 /// extern "C" {
4975 /// fn foo(_: i32);
4976 /// }
4977 ///
4978 /// fn main() {}
4979 /// ```
4980 ///
4981 /// {{produces}}
4982 ///
4983 /// ### Explanation
4984 ///
4985 /// Declaring extern items, even without ever using them, can cause Undefined Behavior. We
4986 /// should consider all sources of Undefined Behavior to be unsafe.
4987 ///
4988 /// This is a [future-incompatible] lint to transition this to a
4989 /// hard error in the future.
4990 ///
4991 /// [future-incompatible]: ../index.md#future-incompatible-lints
4992pub MISSING_UNSAFE_ON_EXTERN,
4993 Allow,
4994"detects missing unsafe keyword on extern declarations",
4995 @future_incompatible = FutureIncompatibleInfo {
4996 reason: fcw!(EditionError 2024 "unsafe-extern"),
4997 };
4998}49995000#[doc =
r" The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword"]
#[doc = r" on attributes considered unsafe."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(unsafe_attr_outside_unsafe)]"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r#" extern "C" fn foo() {}"#]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see"]
#[doc =
r#" [issue #82499] for a more complete list) are considered "unsafe" attributes."#]
#[doc = r" An unsafe attribute must only be used inside unsafe(...)."]
#[doc = r""]
#[doc =
r" This lint can automatically wrap the attributes in `unsafe(...)` , but this"]
#[doc = r" obviously cannot verify that the preconditions of the `unsafe`"]
#[doc = r" attributes are fulfilled, so that is still up to the user."]
#[doc = r""]
#[doc =
r#" The lint is currently "allow" by default, but that might change in the"#]
#[doc = r" future."]
#[doc = r""]
#[doc = r" [editions]: https://doc.rust-lang.org/edition-guide/"]
#[doc = r" [issue #82499]: https://github.com/rust-lang/rust/issues/82499"]
pub static UNSAFE_ATTR_OUTSIDE_UNSAFE: &crate::Lint =
&crate::Lint {
name: "UNSAFE_ATTR_OUTSIDE_UNSAFE",
default_level: crate::Allow,
desc: "detects unsafe attributes outside of unsafe",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "unsafe-attributes",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5001/// The `unsafe_attr_outside_unsafe` lint detects a missing unsafe keyword
5002 /// on attributes considered unsafe.
5003 ///
5004 /// ### Example
5005 ///
5006 /// ```rust,edition2021
5007 /// #![warn(unsafe_attr_outside_unsafe)]
5008 ///
5009 /// #[no_mangle]
5010 /// extern "C" fn foo() {}
5011 ///
5012 /// fn main() {}
5013 /// ```
5014 ///
5015 /// {{produces}}
5016 ///
5017 /// ### Explanation
5018 ///
5019 /// Some attributes (e.g. `no_mangle`, `export_name`, `link_section` -- see
5020 /// [issue #82499] for a more complete list) are considered "unsafe" attributes.
5021 /// An unsafe attribute must only be used inside unsafe(...).
5022 ///
5023 /// This lint can automatically wrap the attributes in `unsafe(...)` , but this
5024 /// obviously cannot verify that the preconditions of the `unsafe`
5025 /// attributes are fulfilled, so that is still up to the user.
5026 ///
5027 /// The lint is currently "allow" by default, but that might change in the
5028 /// future.
5029 ///
5030 /// [editions]: https://doc.rust-lang.org/edition-guide/
5031 /// [issue #82499]: https://github.com/rust-lang/rust/issues/82499
5032pub UNSAFE_ATTR_OUTSIDE_UNSAFE,
5033 Allow,
5034"detects unsafe attributes outside of unsafe",
5035 @future_incompatible = FutureIncompatibleInfo {
5036 reason: fcw!(EditionError 2024 "unsafe-attributes"),
5037 };
5038}50395040#[doc =
r" The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,"]
#[doc = r" above their definition, which may happen in key-value attributes."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![doc = in_root!()]"]
#[doc = r""]
#[doc = r#" macro_rules! in_root { () => { "" } }"#]
#[doc = r""]
#[doc = r" fn main() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" The scope in which a `macro_rules` item is visible starts at that item and continues"]
#[doc =
r" below it. This is more similar to `let` than to other items, which are in scope both above"]
#[doc = r" and below their definition."]
#[doc =
r" Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes"]
#[doc = r" above their definition. The lint catches such cases."]
#[doc =
r" To address the issue turn the `macro_rules` into a regularly scoped item by importing it"]
#[doc = r" with `use`."]
#[doc = r""]
#[doc = r" This is a [future-incompatible] lint to transition this to a"]
#[doc = r" hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static OUT_OF_SCOPE_MACRO_CALLS: &crate::Lint =
&crate::Lint {
name: "OUT_OF_SCOPE_MACRO_CALLS",
default_level: crate::Deny,
desc: "detects out of scope calls to `macro_rules` in key-value attributes",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124535,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5041/// The `out_of_scope_macro_calls` lint detects `macro_rules` called when they are not in scope,
5042 /// above their definition, which may happen in key-value attributes.
5043 ///
5044 /// ### Example
5045 ///
5046 /// ```rust,compile_fail
5047 /// #![doc = in_root!()]
5048 ///
5049 /// macro_rules! in_root { () => { "" } }
5050 ///
5051 /// fn main() {}
5052 /// ```
5053 ///
5054 /// {{produces}}
5055 ///
5056 /// ### Explanation
5057 ///
5058 /// The scope in which a `macro_rules` item is visible starts at that item and continues
5059 /// below it. This is more similar to `let` than to other items, which are in scope both above
5060 /// and below their definition.
5061 /// Due to a bug `macro_rules` were accidentally in scope inside some key-value attributes
5062 /// above their definition. The lint catches such cases.
5063 /// To address the issue turn the `macro_rules` into a regularly scoped item by importing it
5064 /// with `use`.
5065 ///
5066 /// This is a [future-incompatible] lint to transition this to a
5067 /// hard error in the future.
5068 ///
5069 /// [future-incompatible]: ../index.md#future-incompatible-lints
5070pub OUT_OF_SCOPE_MACRO_CALLS,
5071 Deny,
5072"detects out of scope calls to `macro_rules` in key-value attributes",
5073 @future_incompatible = FutureIncompatibleInfo {
5074 reason: fcw!(FutureReleaseError #124535),
5075 report_in_deps: true,
5076 };
5077}50785079#[doc =
r" The `resolving_to_items_shadowing_supertrait_items` lint detects when the"]
#[doc =
r" usage of an item that is provided by both a subtrait and supertrait"]
#[doc = r" is shadowed, preferring the subtrait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(supertrait_item_shadowing)]"]
#[doc = r" #![deny(resolving_to_items_shadowing_supertrait_items)]"]
#[doc = r""]
#[doc = r" trait Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Upstream for T {}"]
#[doc = r""]
#[doc = r" trait Downstream: Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Downstream for T {}"]
#[doc = r""]
#[doc = r" struct MyType;"]
#[doc = r" MyType.hello();"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" RFC 3624 specified a heuristic in which a supertrait item would be"]
#[doc = r" shadowed by a subtrait item when ambiguity occurs during item"]
#[doc = r" selection. In order to mitigate side-effects of this happening"]
#[doc =
r" silently, this lint detects these cases when users want to deny them"]
#[doc = r" or fix the call sites."]
pub static RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS: &crate::Lint =
&crate::Lint {
name: "RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS",
default_level: crate::Allow,
desc: "detects when a supertrait item is shadowed by a subtrait item",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::supertrait_item_shadowing),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5080/// The `resolving_to_items_shadowing_supertrait_items` lint detects when the
5081 /// usage of an item that is provided by both a subtrait and supertrait
5082 /// is shadowed, preferring the subtrait.
5083 ///
5084 /// ### Example
5085 ///
5086 /// ```rust,compile_fail
5087 /// #![feature(supertrait_item_shadowing)]
5088 /// #![deny(resolving_to_items_shadowing_supertrait_items)]
5089 ///
5090 /// trait Upstream {
5091 /// fn hello(&self) {}
5092 /// }
5093 /// impl<T> Upstream for T {}
5094 ///
5095 /// trait Downstream: Upstream {
5096 /// fn hello(&self) {}
5097 /// }
5098 /// impl<T> Downstream for T {}
5099 ///
5100 /// struct MyType;
5101 /// MyType.hello();
5102 /// ```
5103 ///
5104 /// {{produces}}
5105 ///
5106 /// ### Explanation
5107 ///
5108 /// RFC 3624 specified a heuristic in which a supertrait item would be
5109 /// shadowed by a subtrait item when ambiguity occurs during item
5110 /// selection. In order to mitigate side-effects of this happening
5111 /// silently, this lint detects these cases when users want to deny them
5112 /// or fix the call sites.
5113pub RESOLVING_TO_ITEMS_SHADOWING_SUPERTRAIT_ITEMS,
5114// FIXME(supertrait_item_shadowing): It is not decided if this should
5115 // warn by default at the call site.
5116Allow,
5117"detects when a supertrait item is shadowed by a subtrait item",
5118 @feature_gate = supertrait_item_shadowing;
5119}51205121#[doc = r" The `shadowing_supertrait_items` lint detects when the"]
#[doc = r" definition of an item that is provided by both a subtrait and"]
#[doc = r" supertrait is shadowed, preferring the subtrait."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![feature(supertrait_item_shadowing)]"]
#[doc = r" #![deny(shadowing_supertrait_items)]"]
#[doc = r""]
#[doc = r" trait Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Upstream for T {}"]
#[doc = r""]
#[doc = r" trait Downstream: Upstream {"]
#[doc = r" fn hello(&self) {}"]
#[doc = r" }"]
#[doc = r" impl<T> Downstream for T {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" RFC 3624 specified a heuristic in which a supertrait item would be"]
#[doc = r" shadowed by a subtrait item when ambiguity occurs during item"]
#[doc = r" selection. In order to mitigate side-effects of this happening"]
#[doc =
r" silently, this lint detects these cases when users want to deny them"]
#[doc = r" or fix their trait definitions."]
pub static SHADOWING_SUPERTRAIT_ITEMS: &crate::Lint =
&crate::Lint {
name: "SHADOWING_SUPERTRAIT_ITEMS",
default_level: crate::Allow,
desc: "detects when a supertrait item is shadowed by a subtrait item",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::supertrait_item_shadowing),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5122/// The `shadowing_supertrait_items` lint detects when the
5123 /// definition of an item that is provided by both a subtrait and
5124 /// supertrait is shadowed, preferring the subtrait.
5125 ///
5126 /// ### Example
5127 ///
5128 /// ```rust,compile_fail
5129 /// #![feature(supertrait_item_shadowing)]
5130 /// #![deny(shadowing_supertrait_items)]
5131 ///
5132 /// trait Upstream {
5133 /// fn hello(&self) {}
5134 /// }
5135 /// impl<T> Upstream for T {}
5136 ///
5137 /// trait Downstream: Upstream {
5138 /// fn hello(&self) {}
5139 /// }
5140 /// impl<T> Downstream for T {}
5141 /// ```
5142 ///
5143 /// {{produces}}
5144 ///
5145 /// ### Explanation
5146 ///
5147 /// RFC 3624 specified a heuristic in which a supertrait item would be
5148 /// shadowed by a subtrait item when ambiguity occurs during item
5149 /// selection. In order to mitigate side-effects of this happening
5150 /// silently, this lint detects these cases when users want to deny them
5151 /// or fix their trait definitions.
5152pub SHADOWING_SUPERTRAIT_ITEMS,
5153// FIXME(supertrait_item_shadowing): It is not decided if this should
5154 // warn by default at the usage site.
5155Allow,
5156"detects when a supertrait item is shadowed by a subtrait item",
5157 @feature_gate = supertrait_item_shadowing;
5158}51595160#[doc =
r" The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,"]
#[doc = r" that runs a custom `Drop` destructor."]
#[doc =
r" Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior."]
#[doc =
r" This lint detects those cases and provides you information on those values and their custom destructor implementations."]
#[doc = r" Your discretion on this information is required."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r" ```rust,edition2021"]
#[doc = r" #![warn(tail_expr_drop_order)]"]
#[doc = r" struct Droppy(i32);"]
#[doc = r" impl Droppy {"]
#[doc = r" fn get(&self) -> i32 {"]
#[doc = r" self.0"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" impl Drop for Droppy {"]
#[doc = r" fn drop(&mut self) {"]
#[doc =
r" // This is a custom destructor and it induces side-effects that is observable"]
#[doc =
r" // especially when the drop order at a tail expression changes."]
#[doc = r#" println!("loud drop {}", self.0);"#]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" fn edition_2021() -> i32 {"]
#[doc = r" let another_droppy = Droppy(0);"]
#[doc = r" Droppy(1).get()"]
#[doc = r" }"]
#[doc = r" fn main() {"]
#[doc = r" edition_2021();"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r" In tail expression of blocks or function bodies,"]
#[doc =
r" values of type with significant `Drop` implementation has an ill-specified drop order"]
#[doc =
r" before Edition 2024 so that they are dropped only after dropping local variables."]
#[doc = r" Edition 2024 introduces a new rule with drop orders for them,"]
#[doc = r" so that they are dropped first before dropping local variables."]
#[doc = r""]
#[doc =
r" A significant `Drop::drop` destructor here refers to an explicit, arbitrary"]
#[doc =
r" implementation of the `Drop` trait on the type, with exceptions including `Vec`,"]
#[doc =
r" `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise"]
#[doc =
r" so long that the generic types have no significant destructor recursively."]
#[doc =
r" In other words, a type has a significant drop destructor when it has a `Drop` implementation"]
#[doc = r" or its destructor invokes a significant destructor on a type."]
#[doc =
r" Since we cannot completely reason about the change by just inspecting the existence of"]
#[doc =
r" a significant destructor, this lint remains only a suggestion and is set to `allow` by default."]
#[doc = r""]
#[doc =
r" This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`"]
#[doc = r" does in Edition 2024."]
#[doc = r" No fix will be proposed by this lint."]
#[doc =
r" However, the most probable fix is to hoist `Droppy` into its own local variable binding."]
#[doc = r" ```rust"]
#[doc = r" struct Droppy(i32);"]
#[doc = r" impl Droppy {"]
#[doc = r" fn get(&self) -> i32 {"]
#[doc = r" self.0"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" fn edition_2024() -> i32 {"]
#[doc = r" let value = Droppy(0);"]
#[doc = r" let another_droppy = Droppy(1);"]
#[doc = r" value.get()"]
#[doc = r" }"]
#[doc = r" ```"]
pub static TAIL_EXPR_DROP_ORDER: &crate::Lint =
&crate::Lint {
name: "TAIL_EXPR_DROP_ORDER",
default_level: crate::Allow,
desc: "Detect and warn on significant change in drop order in tail expression location",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionSemanticsChange(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "temporary-tail-expr-scope",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5161/// The `tail_expr_drop_order` lint looks for those values generated at the tail expression location,
5162 /// that runs a custom `Drop` destructor.
5163 /// Some of them may be dropped earlier in Edition 2024 that they used to in Edition 2021 and prior.
5164 /// This lint detects those cases and provides you information on those values and their custom destructor implementations.
5165 /// Your discretion on this information is required.
5166 ///
5167 /// ### Example
5168 /// ```rust,edition2021
5169 /// #![warn(tail_expr_drop_order)]
5170 /// struct Droppy(i32);
5171 /// impl Droppy {
5172 /// fn get(&self) -> i32 {
5173 /// self.0
5174 /// }
5175 /// }
5176 /// impl Drop for Droppy {
5177 /// fn drop(&mut self) {
5178 /// // This is a custom destructor and it induces side-effects that is observable
5179 /// // especially when the drop order at a tail expression changes.
5180 /// println!("loud drop {}", self.0);
5181 /// }
5182 /// }
5183 /// fn edition_2021() -> i32 {
5184 /// let another_droppy = Droppy(0);
5185 /// Droppy(1).get()
5186 /// }
5187 /// fn main() {
5188 /// edition_2021();
5189 /// }
5190 /// ```
5191 ///
5192 /// {{produces}}
5193 ///
5194 /// ### Explanation
5195 ///
5196 /// In tail expression of blocks or function bodies,
5197 /// values of type with significant `Drop` implementation has an ill-specified drop order
5198 /// before Edition 2024 so that they are dropped only after dropping local variables.
5199 /// Edition 2024 introduces a new rule with drop orders for them,
5200 /// so that they are dropped first before dropping local variables.
5201 ///
5202 /// A significant `Drop::drop` destructor here refers to an explicit, arbitrary
5203 /// implementation of the `Drop` trait on the type, with exceptions including `Vec`,
5204 /// `Box`, `Rc`, `BTreeMap` and `HashMap` that are marked by the compiler otherwise
5205 /// so long that the generic types have no significant destructor recursively.
5206 /// In other words, a type has a significant drop destructor when it has a `Drop` implementation
5207 /// or its destructor invokes a significant destructor on a type.
5208 /// Since we cannot completely reason about the change by just inspecting the existence of
5209 /// a significant destructor, this lint remains only a suggestion and is set to `allow` by default.
5210 ///
5211 /// This lint only points out the issue with `Droppy`, which will be dropped before `another_droppy`
5212 /// does in Edition 2024.
5213 /// No fix will be proposed by this lint.
5214 /// However, the most probable fix is to hoist `Droppy` into its own local variable binding.
5215 /// ```rust
5216 /// struct Droppy(i32);
5217 /// impl Droppy {
5218 /// fn get(&self) -> i32 {
5219 /// self.0
5220 /// }
5221 /// }
5222 /// fn edition_2024() -> i32 {
5223 /// let value = Droppy(0);
5224 /// let another_droppy = Droppy(1);
5225 /// value.get()
5226 /// }
5227 /// ```
5228pub TAIL_EXPR_DROP_ORDER,
5229 Allow,
5230"Detect and warn on significant change in drop order in tail expression location",
5231 @future_incompatible = FutureIncompatibleInfo {
5232 reason: fcw!(EditionSemanticsChange 2024 "temporary-tail-expr-scope"),
5233 };
5234}52355236#[doc =
r" The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens"]
#[doc =
r" that will be parsed as part of a guarded string literal in Rust 2024."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,edition2021,compile_fail"]
#[doc = r" #![deny(rust_2024_guarded_string_incompatible_syntax)]"]
#[doc = r""]
#[doc = r" macro_rules! m {"]
#[doc = r" (# $x:expr #) => ();"]
#[doc = r" (# $x:expr) => ();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r##" m!(#"hey"#);"##]
#[doc = r#" m!(#"hello");"#]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc = r##" Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`"##]
#[doc = r#" followed by the string literal `"hey"` then the final `#`."#]
#[doc = r" In Rust 2024, the whole sequence is considered a single token."]
#[doc = r""]
#[doc = r" This lint suggests to add whitespace between the leading `#`"]
#[doc = r" and the string to keep them separated in Rust 2024."]
#[allow(rustdoc::invalid_rust_codeblocks)]
pub static RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX: &crate::Lint =
&crate::Lint {
name: "RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX",
default_level: crate::Allow,
desc: "will be parsed as a guarded string in Rust 2024",
is_externally_loaded: false,
crate_level_only: true,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::EditionError(crate::EditionFcw {
edition: rustc_span::edition::Edition::Edition2024,
page_slug: "reserved-syntax",
}),
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5237/// The `rust_2024_guarded_string_incompatible_syntax` lint detects `#` tokens
5238 /// that will be parsed as part of a guarded string literal in Rust 2024.
5239 ///
5240 /// ### Example
5241 ///
5242 /// ```rust,edition2021,compile_fail
5243 /// #![deny(rust_2024_guarded_string_incompatible_syntax)]
5244 ///
5245 /// macro_rules! m {
5246 /// (# $x:expr #) => ();
5247 /// (# $x:expr) => ();
5248 /// }
5249 ///
5250 /// m!(#"hey"#);
5251 /// m!(#"hello");
5252 /// ```
5253 ///
5254 /// {{produces}}
5255 ///
5256 /// ### Explanation
5257 ///
5258 /// Prior to Rust 2024, `#"hey"#` is three tokens: the first `#`
5259 /// followed by the string literal `"hey"` then the final `#`.
5260 /// In Rust 2024, the whole sequence is considered a single token.
5261 ///
5262 /// This lint suggests to add whitespace between the leading `#`
5263 /// and the string to keep them separated in Rust 2024.
5264// Allow this lint -- rustdoc doesn't yet support threading edition into this lint's parser.
5265#[allow(rustdoc::invalid_rust_codeblocks)]
5266pub RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
5267 Allow,
5268"will be parsed as a guarded string in Rust 2024",
5269 @future_incompatible = FutureIncompatibleInfo {
5270 reason: fcw!(EditionError 2024 "reserved-syntax"),
5271 };
5272 crate_level_only
5273}52745275#[doc =
r#" The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on"#]
#[doc =
r" softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of"]
#[doc = r" function calls, making this attribute unsound to use."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (needs aarch64-unknown-none-softfloat)"]
#[doc = r#" #[target_feature(enable = "neon")]"#]
#[doc = r" fn with_neon() {}"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: enabling the `neon` target feature on the current target is unsound due to ABI issues"]
#[doc = r" --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18"]
#[doc = r" |"]
#[doc = r#" | #[target_feature(enable = "neon")]"#]
#[doc = r" | ^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc =
r" = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"]
#[doc =
r" = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" If a function like `with_neon` above ends up containing calls to LLVM builtins, those will"]
#[doc =
r" not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with"]
#[doc =
r" and without the `neon` target feature. The target feature should never have been stabilized"]
#[doc =
r" on this target due to this issue, but the problem was not known at the time of"]
#[doc = r" stabilization."]
pub static AARCH64_SOFTFLOAT_NEON: &crate::Lint =
&crate::Lint {
name: "AARCH64_SOFTFLOAT_NEON",
default_level: crate::Warn,
desc: "detects code that could be affected by ABI issues on aarch64 softfloat targets",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 134375,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5276/// The `aarch64_softfloat_neon` lint detects usage of `#[target_feature(enable = "neon")]` on
5277 /// softfloat aarch64 targets. Enabling this target feature causes LLVM to alter the ABI of
5278 /// function calls, making this attribute unsound to use.
5279 ///
5280 /// ### Example
5281 ///
5282 /// ```rust,ignore (needs aarch64-unknown-none-softfloat)
5283 /// #[target_feature(enable = "neon")]
5284 /// fn with_neon() {}
5285 /// ```
5286 ///
5287 /// This will produce:
5288 ///
5289 /// ```text
5290 /// error: enabling the `neon` target feature on the current target is unsound due to ABI issues
5291 /// --> $DIR/abi-incompatible-target-feature-attribute-fcw.rs:11:18
5292 /// |
5293 /// | #[target_feature(enable = "neon")]
5294 /// | ^^^^^^^^^^^^^^^
5295 /// |
5296 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5297 /// = note: for more information, see issue #134375 <https://github.com/rust-lang/rust/issues/134375>
5298 /// ```
5299 ///
5300 /// ### Explanation
5301 ///
5302 /// If a function like `with_neon` above ends up containing calls to LLVM builtins, those will
5303 /// not use the correct ABI. This is caused by a lack of support in LLVM for mixing code with
5304 /// and without the `neon` target feature. The target feature should never have been stabilized
5305 /// on this target due to this issue, but the problem was not known at the time of
5306 /// stabilization.
5307pub AARCH64_SOFTFLOAT_NEON,
5308 Warn,
5309"detects code that could be affected by ABI issues on aarch64 softfloat targets",
5310 @future_incompatible = FutureIncompatibleInfo {
5311 reason: fcw!(FutureReleaseError #134375),
5312 report_in_deps: true,
5313 };
5314}53155316#[doc =
r" The `tail_call_track_caller` lint detects usage of `become` attempting to tail call"]
#[doc = r" a function marked with `#[track_caller]`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" #![feature(explicit_tail_calls)]"]
#[doc = r" #![expect(incomplete_features)]"]
#[doc = r""]
#[doc = r" #[track_caller]"]
#[doc = r" fn f() {}"]
#[doc = r""]
#[doc = r" fn g() {"]
#[doc = r" become f();"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" g();"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Due to implementation details of tail calls and `#[track_caller]` attribute, calls to"]
#[doc =
r" functions marked with `#[track_caller]` cannot become tail calls. As such using `become`"]
#[doc =
r" is no different than a normal call (except for changes in drop order)."]
pub static TAIL_CALL_TRACK_CALLER: &crate::Lint =
&crate::Lint {
name: "TAIL_CALL_TRACK_CALLER",
default_level: crate::Warn,
desc: "detects tail calls of functions marked with `#[track_caller]`",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::explicit_tail_calls),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5317/// The `tail_call_track_caller` lint detects usage of `become` attempting to tail call
5318 /// a function marked with `#[track_caller]`.
5319 ///
5320 /// ### Example
5321 ///
5322 /// ```rust
5323 /// #![feature(explicit_tail_calls)]
5324 /// #![expect(incomplete_features)]
5325 ///
5326 /// #[track_caller]
5327 /// fn f() {}
5328 ///
5329 /// fn g() {
5330 /// become f();
5331 /// }
5332 ///
5333 /// g();
5334 /// ```
5335 ///
5336 /// {{produces}}
5337 ///
5338 /// ### Explanation
5339 ///
5340 /// Due to implementation details of tail calls and `#[track_caller]` attribute, calls to
5341 /// functions marked with `#[track_caller]` cannot become tail calls. As such using `become`
5342 /// is no different than a normal call (except for changes in drop order).
5343pub TAIL_CALL_TRACK_CALLER,
5344 Warn,
5345"detects tail calls of functions marked with `#[track_caller]`",
5346 @feature_gate = explicit_tail_calls;
5347}5348#[doc =
r" The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant"]
#[doc = r" values that do not fit into a C `int` or `unsigned int`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (only errors on 64bit)"]
#[doc = r" #[repr(C)]"]
#[doc = r" enum E {"]
#[doc = r" V = 9223372036854775807, // i64::MAX"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc =
r" error: `repr(C)` enum discriminant does not fit into C `int` nor into C `unsigned int`"]
#[doc = r" --> $DIR/repr-c-big-discriminant1.rs:16:5"]
#[doc = r" |"]
#[doc = r" LL | A = 9223372036854775807, // i64::MAX"]
#[doc = r" | ^"]
#[doc = r" |"]
#[doc =
r" = note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C"]
#[doc =
r" = help: use `repr($int_ty)` instead to explicitly set the size of this enum"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" In C, enums with discriminants that do not all fit into an `int` or all fit into an"]
#[doc =
r" `unsigned int` are a portability hazard: such enums are only permitted since C23, and not"]
#[doc = r" supported e.g. by MSVC."]
#[doc = r""]
#[doc =
r" Furthermore, Rust interprets the discriminant values of `repr(C)` enums as expressions of"]
#[doc =
r" type `isize`. This makes it impossible to implement the C23 behavior of enums where the enum"]
#[doc =
r" discriminants have no predefined type and instead the enum uses a type large enough to hold"]
#[doc = r" all discriminants."]
#[doc = r""]
#[doc =
r" Therefore, `repr(C)` enums in Rust require that either all discriminants to fit into a C"]
#[doc = r" `int` or they all fit into an `unsigned int`."]
pub static REPR_C_ENUMS_LARGER_THAN_INT: &crate::Lint =
&crate::Lint {
name: "REPR_C_ENUMS_LARGER_THAN_INT",
default_level: crate::Warn,
desc: "repr(C) enums with discriminant values that do not fit into a C int",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 124403,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5349/// The `repr_c_enums_larger_than_int` lint detects `repr(C)` enums with discriminant
5350 /// values that do not fit into a C `int` or `unsigned int`.
5351 ///
5352 /// ### Example
5353 ///
5354 /// ```rust,ignore (only errors on 64bit)
5355 /// #[repr(C)]
5356 /// enum E {
5357 /// V = 9223372036854775807, // i64::MAX
5358 /// }
5359 /// ```
5360 ///
5361 /// This will produce:
5362 ///
5363 /// ```text
5364 /// error: `repr(C)` enum discriminant does not fit into C `int` nor into C `unsigned int`
5365 /// --> $DIR/repr-c-big-discriminant1.rs:16:5
5366 /// |
5367 /// LL | A = 9223372036854775807, // i64::MAX
5368 /// | ^
5369 /// |
5370 /// = note: `repr(C)` enums with big discriminants are non-portable, and their size in Rust might not match their size in C
5371 /// = help: use `repr($int_ty)` instead to explicitly set the size of this enum
5372 /// ```
5373 ///
5374 /// ### Explanation
5375 ///
5376 /// In C, enums with discriminants that do not all fit into an `int` or all fit into an
5377 /// `unsigned int` are a portability hazard: such enums are only permitted since C23, and not
5378 /// supported e.g. by MSVC.
5379 ///
5380 /// Furthermore, Rust interprets the discriminant values of `repr(C)` enums as expressions of
5381 /// type `isize`. This makes it impossible to implement the C23 behavior of enums where the enum
5382 /// discriminants have no predefined type and instead the enum uses a type large enough to hold
5383 /// all discriminants.
5384 ///
5385 /// Therefore, `repr(C)` enums in Rust require that either all discriminants to fit into a C
5386 /// `int` or they all fit into an `unsigned int`.
5387pub REPR_C_ENUMS_LARGER_THAN_INT,
5388 Warn,
5389"repr(C) enums with discriminant values that do not fit into a C int",
5390 @future_incompatible = FutureIncompatibleInfo {
5391 reason: fcw!(FutureReleaseError #124403),
5392 report_in_deps: false,
5393 };
5394}53955396#[doc =
r" The `varargs_without_pattern` lint detects when `...` is used as an argument to a"]
#[doc = r" non-foreign function without any pattern being specified."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc =
r" // Using `...` in non-foreign function definitions is unstable, however stability is"]
#[doc =
r" // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will"]
#[doc = r" // allow this to compile on stable Rust."]
#[doc = r" #[cfg(false)]"]
#[doc = r" fn foo(...) {"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Patterns are currently required for all non-`...` arguments in function definitions (with"]
#[doc =
r" some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in"]
#[doc =
r" non-foreign function definitions makes the language more consistent, and removes a source of"]
#[doc =
r" confusion for the unstable C variadic feature. `...` arguments without a pattern are already"]
#[doc =
r" stable and widely used in foreign function definitions; this lint only affects non-foreign"]
#[doc = r" function definitions."]
#[doc = r""]
#[doc =
r" Using `...` (C varargs) in a non-foreign function definition is currently unstable. However,"]
#[doc =
r" stability checking for the `...` syntax in non-foreign function definitions is currently"]
#[doc =
r" implemented after attributes have been expanded, meaning that if the attribute removes the"]
#[doc =
r" use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will"]
#[doc =
r" compile on stable Rust; this is the only situation where this lint affects code that"]
#[doc = r" compiles on stable Rust."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future."]
#[doc = r""]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static VARARGS_WITHOUT_PATTERN: &crate::Lint =
&crate::Lint {
name: "VARARGS_WITHOUT_PATTERN",
default_level: crate::Deny,
desc: "detects usage of `...` arguments without a pattern in non-foreign items",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 145544,
}),
report_in_deps: true,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5397/// The `varargs_without_pattern` lint detects when `...` is used as an argument to a
5398 /// non-foreign function without any pattern being specified.
5399 ///
5400 /// ### Example
5401 ///
5402 /// ```rust,compile_fail
5403 /// // Using `...` in non-foreign function definitions is unstable, however stability is
5404 /// // currently only checked after attributes are expanded, so using `#[cfg(false)]` here will
5405 /// // allow this to compile on stable Rust.
5406 /// #[cfg(false)]
5407 /// fn foo(...) {
5408 ///
5409 /// }
5410 /// ```
5411 ///
5412 /// {{produces}}
5413 ///
5414 /// ### Explanation
5415 ///
5416 /// Patterns are currently required for all non-`...` arguments in function definitions (with
5417 /// some exceptions in the 2015 edition). Requiring `...` arguments to have patterns in
5418 /// non-foreign function definitions makes the language more consistent, and removes a source of
5419 /// confusion for the unstable C variadic feature. `...` arguments without a pattern are already
5420 /// stable and widely used in foreign function definitions; this lint only affects non-foreign
5421 /// function definitions.
5422 ///
5423 /// Using `...` (C varargs) in a non-foreign function definition is currently unstable. However,
5424 /// stability checking for the `...` syntax in non-foreign function definitions is currently
5425 /// implemented after attributes have been expanded, meaning that if the attribute removes the
5426 /// use of the unstable syntax (e.g. `#[cfg(false)]`, or a procedural macro), the code will
5427 /// compile on stable Rust; this is the only situation where this lint affects code that
5428 /// compiles on stable Rust.
5429 ///
5430 /// This is a [future-incompatible] lint to transition this to a hard error in the future.
5431 ///
5432 /// [future-incompatible]: ../index.md#future-incompatible-lints
5433pub VARARGS_WITHOUT_PATTERN,
5434 Deny,
5435"detects usage of `...` arguments without a pattern in non-foreign items",
5436 @future_incompatible = FutureIncompatibleInfo {
5437 reason: fcw!(FutureReleaseError #145544),
5438 report_in_deps: true,
5439 };
5440}54415442#[doc =
r" The `deprecated_llvm_intrinsic` lint detects usage of deprecated LLVM intrinsics."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,ignore (requires x86)"]
#[doc = r#" #![cfg(any(target_arch = "x86", target_arch = "x86_64"))]"#]
#[doc = r" #![feature(link_llvm_intrinsics, abi_unadjusted)]"]
#[doc = r" #![deny(deprecated_llvm_intrinsic)]"]
#[doc = r""]
#[doc = r#" unsafe extern "unadjusted" {"#]
#[doc = r#" #[link_name = "llvm.x86.addcarryx.u32"]"#]
#[doc = r" fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[inline(never)]"]
#[doc = r#" #[target_feature(enable = "adx")]"#]
#[doc = r" pub fn bar(a: u8, b: u32, c: u32, d: &mut u32) -> u8 {"]
#[doc = r" unsafe { foo(a, b, c, d) }"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" This will produce:"]
#[doc = r""]
#[doc = r" ```text"]
#[doc = r" error: Using deprecated intrinsic `llvm.x86.addcarryx.u32`"]
#[doc = r" --> example.rs:7:5"]
#[doc = r" |"]
#[doc = r" 7 | fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;"]
#[doc = r" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"]
#[doc = r" |"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" LLVM periodically updates its list of intrinsics. Deprecated intrinsics are unlikely"]
#[doc =
r" to be removed, but they may optimize less well than their new versions, so it's"]
#[doc =
r" best to use the new version. Also, some deprecated intrinsics might have buggy"]
#[doc = r" behavior."]
#[doc = r""]
#[doc =
r" This `link_llvm_intrinsics` lint is intended to be used internally only, and requires the"]
#[doc =
r" `#![feature(link_llvm_intrinsics)]` internal feature gate. For more information, see [its chapter in"]
#[doc =
r" the Unstable Book](https://doc.rust-lang.org/unstable-book/language-features/link-llvm-intrinsics.html)"]
#[doc =
r" and [its tracking issue](https://github.com/rust-lang/rust/issues/29602)."]
pub static DEPRECATED_LLVM_INTRINSIC: &crate::Lint =
&crate::Lint {
name: "DEPRECATED_LLVM_INTRINSIC",
default_level: crate::Allow,
desc: "detects uses of deprecated LLVM intrinsics",
is_externally_loaded: false,
feature_gate: Some(rustc_span::sym::link_llvm_intrinsics),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5443/// The `deprecated_llvm_intrinsic` lint detects usage of deprecated LLVM intrinsics.
5444 ///
5445 /// ### Example
5446 ///
5447 /// ```rust,ignore (requires x86)
5448 /// #![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5449 /// #![feature(link_llvm_intrinsics, abi_unadjusted)]
5450 /// #![deny(deprecated_llvm_intrinsic)]
5451 ///
5452 /// unsafe extern "unadjusted" {
5453 /// #[link_name = "llvm.x86.addcarryx.u32"]
5454 /// fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;
5455 /// }
5456 ///
5457 /// #[inline(never)]
5458 /// #[target_feature(enable = "adx")]
5459 /// pub fn bar(a: u8, b: u32, c: u32, d: &mut u32) -> u8 {
5460 /// unsafe { foo(a, b, c, d) }
5461 /// }
5462 /// ```
5463 ///
5464 /// This will produce:
5465 ///
5466 /// ```text
5467 /// error: Using deprecated intrinsic `llvm.x86.addcarryx.u32`
5468 /// --> example.rs:7:5
5469 /// |
5470 /// 7 | fn foo(a: u8, b: u32, c: u32, d: &mut u32) -> u8;
5471 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5472 /// |
5473 /// ```
5474 ///
5475 /// ### Explanation
5476 ///
5477 /// LLVM periodically updates its list of intrinsics. Deprecated intrinsics are unlikely
5478 /// to be removed, but they may optimize less well than their new versions, so it's
5479 /// best to use the new version. Also, some deprecated intrinsics might have buggy
5480 /// behavior.
5481 ///
5482 /// This `link_llvm_intrinsics` lint is intended to be used internally only, and requires the
5483 /// `#![feature(link_llvm_intrinsics)]` internal feature gate. For more information, see [its chapter in
5484 /// the Unstable Book](https://doc.rust-lang.org/unstable-book/language-features/link-llvm-intrinsics.html)
5485 /// and [its tracking issue](https://github.com/rust-lang/rust/issues/29602).
5486pub DEPRECATED_LLVM_INTRINSIC,
5487 Allow,
5488"detects uses of deprecated LLVM intrinsics",
5489 @feature_gate = link_llvm_intrinsics;
5490}54915492#[doc =
r" The `float_literal_f32_fallback` lint detects situations where the type of an unsuffixed"]
#[doc =
r" float literal falls back to `f32` instead of `f64` to avoid a compilation error. This occurs"]
#[doc =
r" when there is a trait bound `f32: From<T>` (or equivalent, such as `T: Into<f32>`) and the"]
#[doc = r" literal is inferred to have the same type as `T`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust"]
#[doc = r" fn foo(x: impl Into<f32>) -> f32 {"]
#[doc = r" x.into()"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn main() {"]
#[doc = r" dbg!(foo(2.5));"]
#[doc = r" }"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" Rust allows traits that are only implemented for a single floating point type to guide type"]
#[doc =
r" inference for floating point literals. This used to apply in the case of `f32: From<T>`"]
#[doc =
r" (where `T` was inferred to be the same type as a floating point literal), as the only"]
#[doc =
r" floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding"]
#[doc =
r" support for `f16`, there are now two implementations for floating point types:"]
#[doc =
r" `f32: From<f16>` and `f32: From<f32>`. This means that the trait bound `f32: From<T>` can no"]
#[doc =
r" longer guide inference for the type of the floating point literal. The default fallback for"]
#[doc =
r" unsuffixed floating point literals is `f64`. As `f32` does not implement `From<f64>`,"]
#[doc =
r" falling back to `f64` would cause a compilation error; therefore, the float type fallback"]
#[doc =
r" has been tempoarily adjusted to fallback to `f32` in this scenario."]
#[doc = r""]
#[doc =
r" The lint will automatically provide a machine-applicable suggestion to add a `_f32` suffix"]
#[doc = r" to the literal, which will fix the problem."]
#[doc = r""]
#[doc =
r" This is a [future-incompatible] lint to transition this to a hard error in the future. See"]
#[doc = r" [issue #154024] for more details."]
#[doc = r""]
#[doc = r" [issue #154024]: https://github.com/rust-lang/rust/issues/154024"]
#[doc = r" [future-incompatible]: ../index.md#future-incompatible-lints"]
pub static FLOAT_LITERAL_F32_FALLBACK: &crate::Lint =
&crate::Lint {
name: "FLOAT_LITERAL_F32_FALLBACK",
default_level: crate::Warn,
desc: "detects unsuffixed floating point literals whose type fallback to `f32`",
is_externally_loaded: false,
future_incompatible: Some(crate::FutureIncompatibleInfo {
reason: crate::FutureIncompatibilityReason::FutureReleaseError(crate::ReleaseFcw {
issue_number: 154024,
}),
report_in_deps: false,
..crate::FutureIncompatibleInfo::default_fields_for_macro()
}),
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5493/// The `float_literal_f32_fallback` lint detects situations where the type of an unsuffixed
5494 /// float literal falls back to `f32` instead of `f64` to avoid a compilation error. This occurs
5495 /// when there is a trait bound `f32: From<T>` (or equivalent, such as `T: Into<f32>`) and the
5496 /// literal is inferred to have the same type as `T`.
5497 ///
5498 /// ### Example
5499 ///
5500 /// ```rust
5501 /// fn foo(x: impl Into<f32>) -> f32 {
5502 /// x.into()
5503 /// }
5504 ///
5505 /// fn main() {
5506 /// dbg!(foo(2.5));
5507 /// }
5508 /// ```
5509 ///
5510 /// {{produces}}
5511 ///
5512 /// ### Explanation
5513 ///
5514 /// Rust allows traits that are only implemented for a single floating point type to guide type
5515 /// inference for floating point literals. This used to apply in the case of `f32: From<T>`
5516 /// (where `T` was inferred to be the same type as a floating point literal), as the only
5517 /// floating point type impl was `f32: From<f32>`. However, as Rust is in the process of adding
5518 /// support for `f16`, there are now two implementations for floating point types:
5519 /// `f32: From<f16>` and `f32: From<f32>`. This means that the trait bound `f32: From<T>` can no
5520 /// longer guide inference for the type of the floating point literal. The default fallback for
5521 /// unsuffixed floating point literals is `f64`. As `f32` does not implement `From<f64>`,
5522 /// falling back to `f64` would cause a compilation error; therefore, the float type fallback
5523 /// has been tempoarily adjusted to fallback to `f32` in this scenario.
5524 ///
5525 /// The lint will automatically provide a machine-applicable suggestion to add a `_f32` suffix
5526 /// to the literal, which will fix the problem.
5527 ///
5528 /// This is a [future-incompatible] lint to transition this to a hard error in the future. See
5529 /// [issue #154024] for more details.
5530 ///
5531 /// [issue #154024]: https://github.com/rust-lang/rust/issues/154024
5532 /// [future-incompatible]: ../index.md#future-incompatible-lints
5533pub FLOAT_LITERAL_F32_FALLBACK,
5534 Warn,
5535"detects unsuffixed floating point literals whose type fallback to `f32`",
5536 @future_incompatible = FutureIncompatibleInfo {
5537 reason: fcw!(FutureReleaseError #154024),
5538 report_in_deps: false,
5539 };
5540}55415542#[doc = r" The `unsafe_code` lint catches usage of `unsafe` code and other"]
#[doc = r" potentially unsound constructs like `no_mangle`, `export_name`,"]
#[doc = r" and `link_section`."]
#[doc = r""]
#[doc = r" ### Example"]
#[doc = r""]
#[doc = r" ```rust,compile_fail"]
#[doc = r" #![deny(unsafe_code)]"]
#[doc = r" fn main() {"]
#[doc = r" unsafe {"]
#[doc = r""]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r" fn func_0() { }"]
#[doc = r""]
#[doc = r#" #[export_name = "exported_symbol_name"]"#]
#[doc = r" pub fn name_in_rust() { }"]
#[doc = r""]
#[doc = r" #[no_mangle]"]
#[doc = r#" #[link_section = ".example_section"]"#]
#[doc = r" pub static VAR1: u32 = 1;"]
#[doc = r" ```"]
#[doc = r""]
#[doc = r" {{produces}}"]
#[doc = r""]
#[doc = r" ### Explanation"]
#[doc = r""]
#[doc =
r" This lint is intended to restrict the usage of `unsafe` blocks and other"]
#[doc =
r" constructs (including, but not limited to `no_mangle`, `link_section`"]
#[doc =
r" and `export_name` attributes) wrong usage of which causes undefined"]
#[doc = r" behavior."]
pub static UNSAFE_CODE: &crate::Lint =
&crate::Lint {
name: "UNSAFE_CODE",
default_level: crate::Allow,
desc: "usage of `unsafe` code and other potentially unsound constructs",
is_externally_loaded: false,
eval_always: true,
..crate::Lint::default_fields_for_macro()
};declare_lint! {
5543/// The `unsafe_code` lint catches usage of `unsafe` code and other
5544 /// potentially unsound constructs like `no_mangle`, `export_name`,
5545 /// and `link_section`.
5546 ///
5547 /// ### Example
5548 ///
5549 /// ```rust,compile_fail
5550 /// #![deny(unsafe_code)]
5551 /// fn main() {
5552 /// unsafe {
5553 ///
5554 /// }
5555 /// }
5556 ///
5557 /// #[no_mangle]
5558 /// fn func_0() { }
5559 ///
5560 /// #[export_name = "exported_symbol_name"]
5561 /// pub fn name_in_rust() { }
5562 ///
5563 /// #[no_mangle]
5564 /// #[link_section = ".example_section"]
5565 /// pub static VAR1: u32 = 1;
5566 /// ```
5567 ///
5568 /// {{produces}}
5569 ///
5570 /// ### Explanation
5571 ///
5572 /// This lint is intended to restrict the usage of `unsafe` blocks and other
5573 /// constructs (including, but not limited to `no_mangle`, `link_section`
5574 /// and `export_name` attributes) wrong usage of which causes undefined
5575 /// behavior.
5576pub UNSAFE_CODE,
5577 Allow,
5578"usage of `unsafe` code and other potentially unsound constructs",
5579 @eval_always = true
5580}