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