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