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