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