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