]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_session/src/lint/builtin.rs
New upstream version 1.48.0+dfsg1
[rustc.git] / compiler / rustc_session / src / lint / builtin.rs
CommitLineData
1b1a35ee
XL
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
7use crate::lint::FutureIncompatibleInfo;
8use crate::{declare_lint, declare_lint_pass, declare_tool_lint};
9use rustc_span::edition::Edition;
10use rustc_span::symbol::sym;
11
12declare_lint! {
13 /// The `ill_formed_attribute_input` lint detects ill-formed attribute
14 /// inputs that were previously accepted and used in practice.
15 ///
16 /// ### Example
17 ///
18 /// ```rust,compile_fail
19 /// #[inline = "this is not valid"]
20 /// fn foo() {}
21 /// ```
22 ///
23 /// {{produces}}
24 ///
25 /// ### Explanation
26 ///
27 /// Previously, inputs for many built-in attributes weren't validated and
28 /// nonsensical attribute inputs were accepted. After validation was
29 /// added, it was determined that some existing projects made use of these
30 /// invalid forms. This is a [future-incompatible] lint to transition this
31 /// to a hard error in the future. See [issue #57571] for more details.
32 ///
33 /// Check the [attribute reference] for details on the valid inputs for
34 /// attributes.
35 ///
36 /// [issue #57571]: https://github.com/rust-lang/rust/issues/57571
37 /// [attribute reference]: https://doc.rust-lang.org/nightly/reference/attributes.html
38 /// [future-incompatible]: ../index.md#future-incompatible-lints
39 pub ILL_FORMED_ATTRIBUTE_INPUT,
40 Deny,
41 "ill-formed attribute inputs that were previously accepted and used in practice",
42 @future_incompatible = FutureIncompatibleInfo {
43 reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>",
44 edition: None,
45 };
46 crate_level_only
47}
48
49declare_lint! {
50 /// The `conflicting_repr_hints` lint detects [`repr` attributes] with
51 /// conflicting hints.
52 ///
53 /// [`repr` attributes]: https://doc.rust-lang.org/reference/type-layout.html#representations
54 ///
55 /// ### Example
56 ///
57 /// ```rust,compile_fail
58 /// #[repr(u32, u64)]
59 /// enum Foo {
60 /// Variant1,
61 /// }
62 /// ```
63 ///
64 /// {{produces}}
65 ///
66 /// ### Explanation
67 ///
68 /// The compiler incorrectly accepted these conflicting representations in
69 /// the past. This is a [future-incompatible] lint to transition this to a
70 /// hard error in the future. See [issue #68585] for more details.
71 ///
72 /// To correct the issue, remove one of the conflicting hints.
73 ///
74 /// [issue #68585]: https://github.com/rust-lang/rust/issues/68585
75 /// [future-incompatible]: ../index.md#future-incompatible-lints
76 pub CONFLICTING_REPR_HINTS,
77 Deny,
78 "conflicts between `#[repr(..)]` hints that were previously accepted and used in practice",
79 @future_incompatible = FutureIncompatibleInfo {
80 reference: "issue #68585 <https://github.com/rust-lang/rust/issues/68585>",
81 edition: None,
82 };
83}
84
85declare_lint! {
86 /// The `meta_variable_misuse` lint detects possible meta-variable misuse
87 /// in macro definitions.
88 ///
89 /// ### Example
90 ///
91 /// ```rust,compile_fail
92 /// #![deny(meta_variable_misuse)]
93 ///
94 /// macro_rules! foo {
95 /// () => {};
96 /// ($( $i:ident = $($j:ident),+ );*) => { $( $( $i = $k; )+ )* };
97 /// }
98 ///
99 /// fn main() {
100 /// foo!();
101 /// }
102 /// ```
103 ///
104 /// {{produces}}
105 ///
106 /// ### Explanation
107 ///
108 /// There are quite a few different ways a [`macro_rules`] macro can be
109 /// improperly defined. Many of these errors were previously only detected
110 /// when the macro was expanded or not at all. This lint is an attempt to
111 /// catch some of these problems when the macro is *defined*.
112 ///
113 /// This lint is "allow" by default because it may have false positives
114 /// and other issues. See [issue #61053] for more details.
115 ///
116 /// [`macro_rules`]: https://doc.rust-lang.org/reference/macros-by-example.html
117 /// [issue #61053]: https://github.com/rust-lang/rust/issues/61053
118 pub META_VARIABLE_MISUSE,
119 Allow,
120 "possible meta-variable misuse at macro definition"
121}
122
123declare_lint! {
124 /// The `incomplete_include` lint detects the use of the [`include!`]
125 /// macro with a file that contains more than one expression.
126 ///
127 /// [`include!`]: https://doc.rust-lang.org/std/macro.include.html
128 ///
129 /// ### Example
130 ///
131 /// ```rust,ignore (needs separate file)
132 /// fn main() {
133 /// include!("foo.txt");
134 /// }
135 /// ```
136 ///
137 /// where the file `foo.txt` contains:
138 ///
139 /// ```text
140 /// println!("hi!");
141 /// ```
142 ///
143 /// produces:
144 ///
145 /// ```text
146 /// error: include macro expected single expression in source
147 /// --> foo.txt:1:14
148 /// |
149 /// 1 | println!("1");
150 /// | ^
151 /// |
152 /// = note: `#[deny(incomplete_include)]` on by default
153 /// ```
154 ///
155 /// ### Explanation
156 ///
157 /// The [`include!`] macro is currently only intended to be used to
158 /// include a single [expression] or multiple [items]. Historically it
159 /// would ignore any contents after the first expression, but that can be
160 /// confusing. In the example above, the `println!` expression ends just
161 /// before the semicolon, making the semicolon "extra" information that is
162 /// ignored. Perhaps even more surprising, if the included file had
163 /// multiple print statements, the subsequent ones would be ignored!
164 ///
165 /// One workaround is to place the contents in braces to create a [block
166 /// expression]. Also consider alternatives, like using functions to
167 /// encapsulate the expressions, or use [proc-macros].
168 ///
169 /// This is a lint instead of a hard error because existing projects were
170 /// found to hit this error. To be cautious, it is a lint for now. The
171 /// future semantics of the `include!` macro are also uncertain, see
172 /// [issue #35560].
173 ///
174 /// [items]: https://doc.rust-lang.org/reference/items.html
175 /// [expression]: https://doc.rust-lang.org/reference/expressions.html
176 /// [block expression]: https://doc.rust-lang.org/reference/expressions/block-expr.html
177 /// [proc-macros]: https://doc.rust-lang.org/reference/procedural-macros.html
178 /// [issue #35560]: https://github.com/rust-lang/rust/issues/35560
179 pub INCOMPLETE_INCLUDE,
180 Deny,
181 "trailing content in included file"
182}
183
184declare_lint! {
185 /// The `arithmetic_overflow` lint detects that an arithmetic operation
186 /// will [overflow].
187 ///
188 /// [overflow]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#overflow
189 ///
190 /// ### Example
191 ///
192 /// ```rust,compile_fail
193 /// 1_i32 << 32;
194 /// ```
195 ///
196 /// {{produces}}
197 ///
198 /// ### Explanation
199 ///
200 /// It is very likely a mistake to perform an arithmetic operation that
201 /// overflows its value. If the compiler is able to detect these kinds of
202 /// overflows at compile-time, it will trigger this lint. Consider
203 /// adjusting the expression to avoid overflow, or use a data type that
204 /// will not overflow.
205 pub ARITHMETIC_OVERFLOW,
206 Deny,
207 "arithmetic operation overflows"
208}
209
210declare_lint! {
211 /// The `unconditional_panic` lint detects an operation that will cause a
212 /// panic at runtime.
213 ///
214 /// ### Example
215 ///
216 /// ```rust,compile_fail
217 /// # #![allow(unused)]
218 /// let x = 1 / 0;
219 /// ```
220 ///
221 /// {{produces}}
222 ///
223 /// ### Explanation
224 ///
225 /// This lint detects code that is very likely incorrect. When possible,
226 /// the compiler will attempt to detect situations where code can be
227 /// evaluated at compile-time to generate more efficient code. While
228 /// evaluating such code, if it detects that the code will unconditionally
229 /// panic, this usually indicates that it is doing something incorrectly.
230 /// If this lint is allowed, then the code will not be evaluated at
231 /// compile-time, and instead continue to generate code to evaluate at
232 /// runtime, which may panic during runtime.
233 pub UNCONDITIONAL_PANIC,
234 Deny,
235 "operation will cause a panic at runtime"
236}
237
238declare_lint! {
239 /// The `const_err` lint detects an erroneous expression while doing
240 /// constant evaluation.
241 ///
242 /// ### Example
243 ///
244 /// ```rust,compile_fail
245 /// #![allow(unconditional_panic)]
246 /// let x: &'static i32 = &(1 / 0);
247 /// ```
248 ///
249 /// {{produces}}
250 ///
251 /// ### Explanation
252 ///
253 /// This lint detects code that is very likely incorrect. If this lint is
254 /// allowed, then the code will not be evaluated at compile-time, and
255 /// instead continue to generate code to evaluate at runtime, which may
256 /// panic during runtime.
257 ///
258 /// Note that this lint may trigger in either inside or outside of a
259 /// [const context]. Outside of a [const context], the compiler can
260 /// sometimes evaluate an expression at compile-time in order to generate
261 /// more efficient code. As the compiler becomes better at doing this, it
262 /// needs to decide what to do when it encounters code that it knows for
263 /// certain will panic or is otherwise incorrect. Making this a hard error
264 /// would prevent existing code that exhibited this behavior from
265 /// compiling, breaking backwards-compatibility. However, this is almost
266 /// certainly incorrect code, so this is a deny-by-default lint. For more
267 /// details, see [RFC 1229] and [issue #28238].
268 ///
269 /// Note that there are several other more specific lints associated with
270 /// compile-time evaluation, such as [`arithmetic_overflow`],
271 /// [`unconditional_panic`].
272 ///
273 /// [const context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
274 /// [RFC 1229]: https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
275 /// [issue #28238]: https://github.com/rust-lang/rust/issues/28238
276 /// [`arithmetic_overflow`]: deny-by-default.html#arithmetic-overflow
277 /// [`unconditional_panic`]: deny-by-default.html#unconditional-panic
278 pub CONST_ERR,
279 Deny,
280 "constant evaluation detected erroneous expression",
281 report_in_external_macro
282}
283
284declare_lint! {
285 /// The `unused_imports` lint detects imports that are never used.
286 ///
287 /// ### Example
288 ///
289 /// ```rust
290 /// use std::collections::HashMap;
291 /// ```
292 ///
293 /// {{produces}}
294 ///
295 /// ### Explanation
296 ///
297 /// Unused imports may signal a mistake or unfinished code, and clutter
298 /// the code, and should be removed. If you intended to re-export the item
299 /// to make it available outside of the module, add a visibility modifier
300 /// like `pub`.
301 pub UNUSED_IMPORTS,
302 Warn,
303 "imports that are never used"
304}
305
306declare_lint! {
307 /// The `unused_extern_crates` lint guards against `extern crate` items
308 /// that are never used.
309 ///
310 /// ### Example
311 ///
312 /// ```rust,compile_fail
313 /// #![deny(unused_extern_crates)]
314 /// extern crate proc_macro;
315 /// ```
316 ///
317 /// {{produces}}
318 ///
319 /// ### Explanation
320 ///
321 /// `extern crate` items that are unused have no effect and should be
322 /// removed. Note that there are some cases where specifying an `extern
323 /// crate` is desired for the side effect of ensuring the given crate is
324 /// linked, even though it is not otherwise directly referenced. The lint
325 /// can be silenced by aliasing the crate to an underscore, such as
326 /// `extern crate foo as _`. Also note that it is no longer idiomatic to
327 /// use `extern crate` in the [2018 edition], as extern crates are now
328 /// automatically added in scope.
329 ///
330 /// This lint is "allow" by default because it can be noisy, and produce
331 /// false-positives. If a dependency is being removed from a project, it
332 /// is recommended to remove it from the build configuration (such as
333 /// `Cargo.toml`) to ensure stale build entries aren't left behind.
334 ///
335 /// [2018 edition]: https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
336 pub UNUSED_EXTERN_CRATES,
337 Allow,
338 "extern crates that are never used"
339}
340
341declare_lint! {
342 /// The `unused_crate_dependencies` lint detects crate dependencies that
343 /// are never used.
344 ///
345 /// ### Example
346 ///
347 /// ```rust,ignore (needs extern crate)
348 /// #![deny(unused_crate_dependencies)]
349 /// ```
350 ///
351 /// This will produce:
352 ///
353 /// ```text
354 /// error: external crate `regex` unused in `lint_example`: remove the dependency or add `use regex as _;`
355 /// |
356 /// note: the lint level is defined here
357 /// --> src/lib.rs:1:9
358 /// |
359 /// 1 | #![deny(unused_crate_dependencies)]
360 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^
361 /// ```
362 ///
363 /// ### Explanation
364 ///
365 /// After removing the code that uses a dependency, this usually also
366 /// requires removing the dependency from the build configuration.
367 /// However, sometimes that step can be missed, which leads to time wasted
368 /// building dependencies that are no longer used. This lint can be
369 /// enabled to detect dependencies that are never used (more specifically,
370 /// any dependency passed with the `--extern` command-line flag that is
371 /// never referenced via [`use`], [`extern crate`], or in any [path]).
372 ///
373 /// This lint is "allow" by default because it can provide false positives
374 /// depending on how the build system is configured. For example, when
375 /// using Cargo, a "package" consists of multiple crates (such as a
376 /// library and a binary), but the dependencies are defined for the
377 /// package as a whole. If there is a dependency that is only used in the
378 /// binary, but not the library, then the lint will be incorrectly issued
379 /// in the library.
380 ///
381 /// [path]: https://doc.rust-lang.org/reference/paths.html
382 /// [`use`]: https://doc.rust-lang.org/reference/items/use-declarations.html
383 /// [`extern crate`]: https://doc.rust-lang.org/reference/items/extern-crates.html
384 pub UNUSED_CRATE_DEPENDENCIES,
385 Allow,
386 "crate dependencies that are never used",
387 crate_level_only
388}
389
390declare_lint! {
391 /// The `unused_qualifications` lint detects unnecessarily qualified
392 /// names.
393 ///
394 /// ### Example
395 ///
396 /// ```rust,compile_fail
397 /// #![deny(unused_qualifications)]
398 /// mod foo {
399 /// pub fn bar() {}
400 /// }
401 ///
402 /// fn main() {
403 /// use foo::bar;
404 /// foo::bar();
405 /// }
406 /// ```
407 ///
408 /// {{produces}}
409 ///
410 /// ### Explanation
411 ///
412 /// If an item from another module is already brought into scope, then
413 /// there is no need to qualify it in this case. You can call `bar()`
414 /// directly, without the `foo::`.
415 ///
416 /// This lint is "allow" by default because it is somewhat pedantic, and
417 /// doesn't indicate an actual problem, but rather a stylistic choice, and
418 /// can be noisy when refactoring or moving around code.
419 pub UNUSED_QUALIFICATIONS,
420 Allow,
421 "detects unnecessarily qualified names"
422}
423
424declare_lint! {
425 /// The `unknown_lints` lint detects unrecognized lint attribute.
426 ///
427 /// ### Example
428 ///
429 /// ```rust
430 /// #![allow(not_a_real_lint)]
431 /// ```
432 ///
433 /// {{produces}}
434 ///
435 /// ### Explanation
436 ///
437 /// It is usually a mistake to specify a lint that does not exist. Check
438 /// the spelling, and check the lint listing for the correct name. Also
439 /// consider if you are using an old version of the compiler, and the lint
440 /// is only available in a newer version.
441 pub UNKNOWN_LINTS,
442 Warn,
443 "unrecognized lint attribute"
444}
445
446declare_lint! {
447 /// The `unused_variables` lint detects variables which are not used in
448 /// any way.
449 ///
450 /// ### Example
451 ///
452 /// ```rust
453 /// let x = 5;
454 /// ```
455 ///
456 /// {{produces}}
457 ///
458 /// ### Explanation
459 ///
460 /// Unused variables may signal a mistake or unfinished code. To silence
461 /// the warning for the individual variable, prefix it with an underscore
462 /// such as `_x`.
463 pub UNUSED_VARIABLES,
464 Warn,
465 "detect variables which are not used in any way"
466}
467
468declare_lint! {
469 /// The `unused_assignments` lint detects assignments that will never be read.
470 ///
471 /// ### Example
472 ///
473 /// ```rust
474 /// let mut x = 5;
475 /// x = 6;
476 /// ```
477 ///
478 /// {{produces}}
479 ///
480 /// ### Explanation
481 ///
482 /// Unused assignments may signal a mistake or unfinished code. If the
483 /// variable is never used after being assigned, then the assignment can
484 /// be removed. Variables with an underscore prefix such as `_x` will not
485 /// trigger this lint.
486 pub UNUSED_ASSIGNMENTS,
487 Warn,
488 "detect assignments that will never be read"
489}
490
491declare_lint! {
492 /// The `dead_code` lint detects unused, unexported items.
493 ///
494 /// ### Example
495 ///
496 /// ```rust
497 /// fn foo() {}
498 /// ```
499 ///
500 /// {{produces}}
501 ///
502 /// ### Explanation
503 ///
504 /// Dead code may signal a mistake or unfinished code. To silence the
505 /// warning for individual items, prefix the name with an underscore such
506 /// as `_foo`. If it was intended to expose the item outside of the crate,
507 /// consider adding a visibility modifier like `pub`. Otherwise consider
508 /// removing the unused code.
509 pub DEAD_CODE,
510 Warn,
511 "detect unused, unexported items"
512}
513
514declare_lint! {
515 /// The `unused_attributes` lint detects attributes that were not used by
516 /// the compiler.
517 ///
518 /// ### Example
519 ///
520 /// ```rust
521 /// #![macro_export]
522 /// ```
523 ///
524 /// {{produces}}
525 ///
526 /// ### Explanation
527 ///
528 /// Unused [attributes] may indicate the attribute is placed in the wrong
529 /// position. Consider removing it, or placing it in the correct position.
530 /// Also consider if you intended to use an _inner attribute_ (with a `!`
531 /// such as `#![allow(unused)]`) which applies to the item the attribute
532 /// is within, or an _outer attribute_ (without a `!` such as
533 /// `#[allow(unsued)]`) which applies to the item *following* the
534 /// attribute.
535 ///
536 /// [attributes]: https://doc.rust-lang.org/reference/attributes.html
537 pub UNUSED_ATTRIBUTES,
538 Warn,
539 "detects attributes that were not used by the compiler"
540}
541
542declare_lint! {
543 /// The `unreachable_code` lint detects unreachable code paths.
544 ///
545 /// ### Example
546 ///
547 /// ```rust,no_run
548 /// panic!("we never go past here!");
549 ///
550 /// let x = 5;
551 /// ```
552 ///
553 /// {{produces}}
554 ///
555 /// ### Explanation
556 ///
557 /// Unreachable code may signal a mistake or unfinished code. If the code
558 /// is no longer in use, consider removing it.
559 pub UNREACHABLE_CODE,
560 Warn,
561 "detects unreachable code paths",
562 report_in_external_macro
563}
564
565declare_lint! {
566 /// The `unreachable_patterns` lint detects unreachable patterns.
567 ///
568 /// ### Example
569 ///
570 /// ```rust
571 /// let x = 5;
572 /// match x {
573 /// y => (),
574 /// 5 => (),
575 /// }
576 /// ```
577 ///
578 /// {{produces}}
579 ///
580 /// ### Explanation
581 ///
582 /// This usually indicates a mistake in how the patterns are specified or
583 /// ordered. In this example, the `y` pattern will always match, so the
584 /// five is impossible to reach. Remember, match arms match in order, you
585 /// probably wanted to put the `5` case above the `y` case.
586 pub UNREACHABLE_PATTERNS,
587 Warn,
588 "detects unreachable patterns"
589}
590
591declare_lint! {
592 /// The `overlapping_patterns` lint detects `match` arms that have
593 /// [range patterns] that overlap.
594 ///
595 /// [range patterns]: https://doc.rust-lang.org/nightly/reference/patterns.html#range-patterns
596 ///
597 /// ### Example
598 ///
599 /// ```rust
600 /// let x = 123u8;
601 /// match x {
602 /// 0..=100 => { println!("small"); }
603 /// 100..=255 => { println!("large"); }
604 /// }
605 /// ```
606 ///
607 /// {{produces}}
608 ///
609 /// ### Explanation
610 ///
611 /// It is likely a mistake to have range patterns in a match expression
612 /// that overlap. Check that the beginning and end values are what you
613 /// expect, and keep in mind that with `..=` the left and right bounds are
614 /// inclusive.
615 pub OVERLAPPING_PATTERNS,
616 Warn,
617 "detects overlapping patterns"
618}
619
620declare_lint! {
621 /// The `bindings_with_variant_name` lint detects pattern bindings with
622 /// the same name as one of the matched variants.
623 ///
624 /// ### Example
625 ///
626 /// ```rust
627 /// pub enum Enum {
628 /// Foo,
629 /// Bar,
630 /// }
631 ///
632 /// pub fn foo(x: Enum) {
633 /// match x {
634 /// Foo => {}
635 /// Bar => {}
636 /// }
637 /// }
638 /// ```
639 ///
640 /// {{produces}}
641 ///
642 /// ### Explanation
643 ///
644 /// It is usually a mistake to specify an enum variant name as an
645 /// [identifier pattern]. In the example above, the `match` arms are
646 /// specifying a variable name to bind the value of `x` to. The second arm
647 /// is ignored because the first one matches *all* values. The likely
648 /// intent is that the arm was intended to match on the enum variant.
649 ///
650 /// Two possible solutions are:
651 ///
652 /// * Specify the enum variant using a [path pattern], such as
653 /// `Enum::Foo`.
654 /// * Bring the enum variants into local scope, such as adding `use
655 /// Enum::*;` to the beginning of the `foo` function in the example
656 /// above.
657 ///
658 /// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
659 /// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
660 pub BINDINGS_WITH_VARIANT_NAME,
661 Warn,
662 "detects pattern bindings with the same name as one of the matched variants"
663}
664
665declare_lint! {
666 /// The `unused_macros` lint detects macros that were not used.
667 ///
668 /// ### Example
669 ///
670 /// ```rust
671 /// macro_rules! unused {
672 /// () => {};
673 /// }
674 ///
675 /// fn main() {
676 /// }
677 /// ```
678 ///
679 /// {{produces}}
680 ///
681 /// ### Explanation
682 ///
683 /// Unused macros may signal a mistake or unfinished code. To silence the
684 /// warning for the individual macro, prefix the name with an underscore
685 /// such as `_my_macro`. If you intended to export the macro to make it
686 /// available outside of the crate, use the [`macro_export` attribute].
687 ///
688 /// [`macro_export` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
689 pub UNUSED_MACROS,
690 Warn,
691 "detects macros that were not used"
692}
693
694declare_lint! {
695 /// The `warnings` lint allows you to change the level of other
696 /// lints which produce warnings.
697 ///
698 /// ### Example
699 ///
700 /// ```rust
701 /// #![deny(warnings)]
702 /// fn foo() {}
703 /// ```
704 ///
705 /// {{produces}}
706 ///
707 /// ### Explanation
708 ///
709 /// The `warnings` lint is a bit special; by changing its level, you
710 /// change every other warning that would produce a warning to whatever
711 /// value you'd like. As such, you won't ever trigger this lint in your
712 /// code directly.
713 pub WARNINGS,
714 Warn,
715 "mass-change the level for lints which produce warnings"
716}
717
718declare_lint! {
719 /// The `unused_features` lint detects unused or unknown features found in
720 /// crate-level [`feature` attributes].
721 ///
722 /// [`feature` attributes]: https://doc.rust-lang.org/nightly/unstable-book/
723 ///
724 /// Note: This lint is currently not functional, see [issue #44232] for
725 /// more details.
726 ///
727 /// [issue #44232]: https://github.com/rust-lang/rust/issues/44232
728 pub UNUSED_FEATURES,
729 Warn,
730 "unused features found in crate-level `#[feature]` directives"
731}
732
733declare_lint! {
734 /// The `stable_features` lint detects a [`feature` attribute] that
735 /// has since been made stable.
736 ///
737 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
738 ///
739 /// ### Example
740 ///
741 /// ```rust
742 /// #![feature(test_accepted_feature)]
743 /// fn main() {}
744 /// ```
745 ///
746 /// {{produces}}
747 ///
748 /// ### Explanation
749 ///
750 /// When a feature is stabilized, it is no longer necessary to include a
751 /// `#![feature]` attribute for it. To fix, simply remove the
752 /// `#![feature]` attribute.
753 pub STABLE_FEATURES,
754 Warn,
755 "stable features found in `#[feature]` directive"
756}
757
758declare_lint! {
759 /// The `unknown_crate_types` lint detects an unknown crate type found in
760 /// a [`crate_type` attribute].
761 ///
762 /// ### Example
763 ///
764 /// ```rust,compile_fail
765 /// #![crate_type="lol"]
766 /// fn main() {}
767 /// ```
768 ///
769 /// {{produces}}
770 ///
771 /// ### Explanation
772 ///
773 /// An unknown value give to the `crate_type` attribute is almost
774 /// certainly a mistake.
775 ///
776 /// [`crate_type` attribute]: https://doc.rust-lang.org/reference/linkage.html
777 pub UNKNOWN_CRATE_TYPES,
778 Deny,
779 "unknown crate type found in `#[crate_type]` directive",
780 crate_level_only
781}
782
783declare_lint! {
784 /// The `trivial_casts` lint detects trivial casts which could be replaced
785 /// with coercion, which may require [type ascription] or a temporary
786 /// variable.
787 ///
788 /// ### Example
789 ///
790 /// ```rust,compile_fail
791 /// #![deny(trivial_casts)]
792 /// let x: &u32 = &42;
793 /// let y = x as *const u32;
794 /// ```
795 ///
796 /// {{produces}}
797 ///
798 /// ### Explanation
799 ///
800 /// A trivial cast is a cast `e as T` where `e` has type `U` and `U` is a
801 /// subtype of `T`. This type of cast is usually unnecessary, as it can be
802 /// usually be inferred.
803 ///
804 /// This lint is "allow" by default because there are situations, such as
805 /// with FFI interfaces or complex type aliases, where it triggers
806 /// incorrectly, or in situations where it will be more difficult to
807 /// clearly express the intent. It may be possible that this will become a
808 /// warning in the future, possibly with [type ascription] providing a
809 /// convenient way to work around the current issues. See [RFC 401] for
810 /// historical context.
811 ///
812 /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
813 /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
814 pub TRIVIAL_CASTS,
815 Allow,
816 "detects trivial casts which could be removed"
817}
818
819declare_lint! {
820 /// The `trivial_numeric_casts` lint detects trivial numeric casts of types
821 /// which could be removed.
822 ///
823 /// ### Example
824 ///
825 /// ```rust,compile_fail
826 /// #![deny(trivial_numeric_casts)]
827 /// let x = 42_i32 as i32;
828 /// ```
829 ///
830 /// {{produces}}
831 ///
832 /// ### Explanation
833 ///
834 /// A trivial numeric cast is a cast of a numeric type to the same numeric
835 /// type. This type of cast is usually unnecessary.
836 ///
837 /// This lint is "allow" by default because there are situations, such as
838 /// with FFI interfaces or complex type aliases, where it triggers
839 /// incorrectly, or in situations where it will be more difficult to
840 /// clearly express the intent. It may be possible that this will become a
841 /// warning in the future, possibly with [type ascription] providing a
842 /// convenient way to work around the current issues. See [RFC 401] for
843 /// historical context.
844 ///
845 /// [type ascription]: https://github.com/rust-lang/rust/issues/23416
846 /// [RFC 401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
847 pub TRIVIAL_NUMERIC_CASTS,
848 Allow,
849 "detects trivial casts of numeric types which could be removed"
850}
851
852declare_lint! {
853 /// The `private_in_public` lint detects private items in public
854 /// interfaces not caught by the old implementation.
855 ///
856 /// ### Example
857 ///
858 /// ```rust
859 /// # #![allow(unused)]
860 /// struct SemiPriv;
861 ///
862 /// mod m1 {
863 /// struct Priv;
864 /// impl super::SemiPriv {
865 /// pub fn f(_: Priv) {}
866 /// }
867 /// }
868 /// # fn main() {}
869 /// ```
870 ///
871 /// {{produces}}
872 ///
873 /// ### Explanation
874 ///
875 /// The visibility rules are intended to prevent exposing private items in
876 /// public interfaces. This is a [future-incompatible] lint to transition
877 /// this to a hard error in the future. See [issue #34537] for more
878 /// details.
879 ///
880 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
881 /// [future-incompatible]: ../index.md#future-incompatible-lints
882 pub PRIVATE_IN_PUBLIC,
883 Warn,
884 "detect private items in public interfaces not caught by the old implementation",
885 @future_incompatible = FutureIncompatibleInfo {
886 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
887 edition: None,
888 };
889}
890
891declare_lint! {
892 /// The `exported_private_dependencies` lint detects private dependencies
893 /// that are exposed in a public interface.
894 ///
895 /// ### Example
896 ///
897 /// ```rust,ignore (needs-dependency)
898 /// pub fn foo() -> Option<some_private_dependency::Thing> {
899 /// None
900 /// }
901 /// ```
902 ///
903 /// This will produce:
904 ///
905 /// ```text
906 /// warning: type `bar::Thing` from private dependency 'bar' in public interface
907 /// --> src/lib.rs:3:1
908 /// |
909 /// 3 | pub fn foo() -> Option<bar::Thing> {
910 /// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
911 /// |
912 /// = note: `#[warn(exported_private_dependencies)]` on by default
913 /// ```
914 ///
915 /// ### Explanation
916 ///
917 /// Dependencies can be marked as "private" to indicate that they are not
918 /// exposed in the public interface of a crate. This can be used by Cargo
919 /// to independently resolve those dependencies because it can assume it
920 /// does not need to unify them with other packages using that same
921 /// dependency. This lint is an indication of a violation of that
922 /// contract.
923 ///
924 /// To fix this, avoid exposing the dependency in your public interface.
925 /// Or, switch the dependency to a public dependency.
926 ///
927 /// Note that support for this is only available on the nightly channel.
928 /// See [RFC 1977] for more details, as well as the [Cargo documentation].
929 ///
930 /// [RFC 1977]: https://github.com/rust-lang/rfcs/blob/master/text/1977-public-private-dependencies.md
931 /// [Cargo documentation]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#public-dependency
932 pub EXPORTED_PRIVATE_DEPENDENCIES,
933 Warn,
934 "public interface leaks type from a private dependency"
935}
936
937declare_lint! {
938 /// The `pub_use_of_private_extern_crate` lint detects a specific
939 /// situation of re-exporting a private `extern crate`.
940 ///
941 /// ### Example
942 ///
943 /// ```rust,compile_fail
944 /// extern crate core;
945 /// pub use core as reexported_core;
946 /// ```
947 ///
948 /// {{produces}}
949 ///
950 /// ### Explanation
951 ///
952 /// A public `use` declaration should not be used to publicly re-export a
953 /// private `extern crate`. `pub extern crate` should be used instead.
954 ///
955 /// This was historically allowed, but is not the intended behavior
956 /// according to the visibility rules. This is a [future-incompatible]
957 /// lint to transition this to a hard error in the future. See [issue
958 /// #34537] for more details.
959 ///
960 /// [issue #34537]: https://github.com/rust-lang/rust/issues/34537
961 /// [future-incompatible]: ../index.md#future-incompatible-lints
962 pub PUB_USE_OF_PRIVATE_EXTERN_CRATE,
963 Deny,
964 "detect public re-exports of private extern crates",
965 @future_incompatible = FutureIncompatibleInfo {
966 reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
967 edition: None,
968 };
969}
970
971declare_lint! {
972 /// The `invalid_type_param_default` lint detects type parameter defaults
973 /// erroneously allowed in an invalid location.
974 ///
975 /// ### Example
976 ///
977 /// ```rust,compile_fail
978 /// fn foo<T=i32>(t: T) {}
979 /// ```
980 ///
981 /// {{produces}}
982 ///
983 /// ### Explanation
984 ///
985 /// Default type parameters were only intended to be allowed in certain
986 /// situations, but historically the compiler allowed them everywhere.
987 /// This is a [future-incompatible] lint to transition this to a hard
988 /// error in the future. See [issue #36887] for more details.
989 ///
990 /// [issue #36887]: https://github.com/rust-lang/rust/issues/36887
991 /// [future-incompatible]: ../index.md#future-incompatible-lints
992 pub INVALID_TYPE_PARAM_DEFAULT,
993 Deny,
994 "type parameter default erroneously allowed in invalid location",
995 @future_incompatible = FutureIncompatibleInfo {
996 reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
997 edition: None,
998 };
999}
1000
1001declare_lint! {
1002 /// The `renamed_and_removed_lints` lint detects lints that have been
1003 /// renamed or removed.
1004 ///
1005 /// ### Example
1006 ///
1007 /// ```rust
1008 /// #![deny(raw_pointer_derive)]
1009 /// ```
1010 ///
1011 /// {{produces}}
1012 ///
1013 /// ### Explanation
1014 ///
1015 /// To fix this, either remove the lint or use the new name. This can help
1016 /// avoid confusion about lints that are no longer valid, and help
1017 /// maintain consistency for renamed lints.
1018 pub RENAMED_AND_REMOVED_LINTS,
1019 Warn,
1020 "lints that have been renamed or removed"
1021}
1022
1023declare_lint! {
1024 /// The `unaligned_references` lint detects unaligned references to fields
1025 /// of [packed] structs.
1026 ///
1027 /// [packed]: https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers
1028 ///
1029 /// ### Example
1030 ///
1031 /// ```rust,compile_fail
1032 /// #![deny(unaligned_references)]
1033 ///
1034 /// #[repr(packed)]
1035 /// pub struct Foo {
1036 /// field1: u64,
1037 /// field2: u8,
1038 /// }
1039 ///
1040 /// fn main() {
1041 /// unsafe {
1042 /// let foo = Foo { field1: 0, field2: 0 };
1043 /// let _ = &foo.field1;
1044 /// }
1045 /// }
1046 /// ```
1047 ///
1048 /// {{produces}}
1049 ///
1050 /// ### Explanation
1051 ///
1052 /// Creating a reference to an insufficiently aligned packed field is
1053 /// [undefined behavior] and should be disallowed.
1054 ///
1055 /// This lint is "allow" by default because there is no stable
1056 /// alternative, and it is not yet certain how widespread existing code
1057 /// will trigger this lint.
1058 ///
1059 /// See [issue #27060] for more discussion.
1060 ///
1061 /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1062 /// [issue #27060]: https://github.com/rust-lang/rust/issues/27060
1063 pub UNALIGNED_REFERENCES,
1064 Allow,
1065 "detects unaligned references to fields of packed structs",
1066}
1067
1068declare_lint! {
1069 /// The `const_item_mutation` lint detects attempts to mutate a `const`
1070 /// item.
1071 ///
1072 /// ### Example
1073 ///
1074 /// ```rust
1075 /// const FOO: [i32; 1] = [0];
1076 ///
1077 /// fn main() {
1078 /// FOO[0] = 1;
1079 /// // This will print "[0]".
1080 /// println!("{:?}", FOO);
1081 /// }
1082 /// ```
1083 ///
1084 /// {{produces}}
1085 ///
1086 /// ### Explanation
1087 ///
1088 /// Trying to directly mutate a `const` item is almost always a mistake.
1089 /// What is happening in the example above is that a temporary copy of the
1090 /// `const` is mutated, but the original `const` is not. Each time you
1091 /// refer to the `const` by name (such as `FOO` in the example above), a
1092 /// separate copy of the value is inlined at that location.
1093 ///
1094 /// This lint checks for writing directly to a field (`FOO.field =
1095 /// some_value`) or array entry (`FOO[0] = val`), or taking a mutable
1096 /// reference to the const item (`&mut FOO`), including through an
1097 /// autoderef (`FOO.some_mut_self_method()`).
1098 ///
1099 /// There are various alternatives depending on what you are trying to
1100 /// accomplish:
1101 ///
1102 /// * First, always reconsider using mutable globals, as they can be
1103 /// difficult to use correctly, and can make the code more difficult to
1104 /// use or understand.
1105 /// * If you are trying to perform a one-time initialization of a global:
1106 /// * If the value can be computed at compile-time, consider using
1107 /// const-compatible values (see [Constant Evaluation]).
1108 /// * For more complex single-initialization cases, consider using a
1109 /// third-party crate, such as [`lazy_static`] or [`once_cell`].
1110 /// * If you are using the [nightly channel], consider the new
1111 /// [`lazy`] module in the standard library.
1112 /// * If you truly need a mutable global, consider using a [`static`],
1113 /// which has a variety of options:
1114 /// * Simple data types can be directly defined and mutated with an
1115 /// [`atomic`] type.
1116 /// * More complex types can be placed in a synchronization primitive
1117 /// like a [`Mutex`], which can be initialized with one of the options
1118 /// listed above.
1119 /// * A [mutable `static`] is a low-level primitive, requiring unsafe.
1120 /// Typically This should be avoided in preference of something
1121 /// higher-level like one of the above.
1122 ///
1123 /// [Constant Evaluation]: https://doc.rust-lang.org/reference/const_eval.html
1124 /// [`static`]: https://doc.rust-lang.org/reference/items/static-items.html
1125 /// [mutable `static`]: https://doc.rust-lang.org/reference/items/static-items.html#mutable-statics
1126 /// [`lazy`]: https://doc.rust-lang.org/nightly/std/lazy/index.html
1127 /// [`lazy_static`]: https://crates.io/crates/lazy_static
1128 /// [`once_cell`]: https://crates.io/crates/once_cell
1129 /// [`atomic`]: https://doc.rust-lang.org/std/sync/atomic/index.html
1130 /// [`Mutex`]: https://doc.rust-lang.org/std/sync/struct.Mutex.html
1131 pub CONST_ITEM_MUTATION,
1132 Warn,
1133 "detects attempts to mutate a `const` item",
1134}
1135
1136declare_lint! {
1137 /// The `safe_packed_borrows` lint detects borrowing a field in the
1138 /// interior of a packed structure with alignment other than 1.
1139 ///
1140 /// ### Example
1141 ///
1142 /// ```rust
1143 /// #[repr(packed)]
1144 /// pub struct Unaligned<T>(pub T);
1145 ///
1146 /// pub struct Foo {
1147 /// start: u8,
1148 /// data: Unaligned<u32>,
1149 /// }
1150 ///
1151 /// fn main() {
1152 /// let x = Foo { start: 0, data: Unaligned(1) };
1153 /// let y = &x.data.0;
1154 /// }
1155 /// ```
1156 ///
1157 /// {{produces}}
1158 ///
1159 /// ### Explanation
1160 ///
1161 /// This type of borrow is unsafe and can cause errors on some platforms
1162 /// and violates some assumptions made by the compiler. This was
1163 /// previously allowed unintentionally. This is a [future-incompatible]
1164 /// lint to transition this to a hard error in the future. See [issue
1165 /// #46043] for more details, including guidance on how to solve the
1166 /// problem.
1167 ///
1168 /// [issue #46043]: https://github.com/rust-lang/rust/issues/46043
1169 /// [future-incompatible]: ../index.md#future-incompatible-lints
1170 pub SAFE_PACKED_BORROWS,
1171 Warn,
1172 "safe borrows of fields of packed structs were erroneously allowed",
1173 @future_incompatible = FutureIncompatibleInfo {
1174 reference: "issue #46043 <https://github.com/rust-lang/rust/issues/46043>",
1175 edition: None,
1176 };
1177}
1178
1179declare_lint! {
1180 /// The `patterns_in_fns_without_body` lint detects `mut` identifier
1181 /// patterns as a parameter in functions without a body.
1182 ///
1183 /// ### Example
1184 ///
1185 /// ```rust,compile_fail
1186 /// trait Trait {
1187 /// fn foo(mut arg: u8);
1188 /// }
1189 /// ```
1190 ///
1191 /// {{produces}}
1192 ///
1193 /// ### Explanation
1194 ///
1195 /// To fix this, remove `mut` from the parameter in the trait definition;
1196 /// it can be used in the implementation. That is, the following is OK:
1197 ///
1198 /// ```rust
1199 /// trait Trait {
1200 /// fn foo(arg: u8); // Removed `mut` here
1201 /// }
1202 ///
1203 /// impl Trait for i32 {
1204 /// fn foo(mut arg: u8) { // `mut` here is OK
1205 ///
1206 /// }
1207 /// }
1208 /// ```
1209 ///
1210 /// Trait definitions can define functions without a body to specify a
1211 /// function that implementors must define. The parameter names in the
1212 /// body-less functions are only allowed to be `_` or an [identifier] for
1213 /// documentation purposes (only the type is relevant). Previous versions
1214 /// of the compiler erroneously allowed [identifier patterns] with the
1215 /// `mut` keyword, but this was not intended to be allowed. This is a
1216 /// [future-incompatible] lint to transition this to a hard error in the
1217 /// future. See [issue #35203] for more details.
1218 ///
1219 /// [identifier]: https://doc.rust-lang.org/reference/identifiers.html
1220 /// [identifier patterns]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
1221 /// [issue #35203]: https://github.com/rust-lang/rust/issues/35203
1222 /// [future-incompatible]: ../index.md#future-incompatible-lints
1223 pub PATTERNS_IN_FNS_WITHOUT_BODY,
1224 Deny,
1225 "patterns in functions without body were erroneously allowed",
1226 @future_incompatible = FutureIncompatibleInfo {
1227 reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
1228 edition: None,
1229 };
1230}
1231
1232declare_lint! {
1233 /// The `missing_fragment_specifier` lint is issued when an unused pattern
1234 /// in a `macro_rules!` macro definition has a meta-variable (e.g. `$e`)
1235 /// that is not followed by a fragment specifier (e.g. `:expr`).
1236 ///
1237 /// This warning can always be fixed by removing the unused pattern in the
1238 /// `macro_rules!` macro definition.
1239 ///
1240 /// ### Example
1241 ///
1242 /// ```rust,compile_fail
1243 /// macro_rules! foo {
1244 /// ($e) => {}
1245 /// }
1246 /// ```
1247 ///
1248 /// {{produces}}
1249 ///
1250 ///
1251 /// ### Explanation
1252 ///
1253 /// The meta-variable (`$e` above) lacks a fragment specifier, which is a
1254 /// malformed input. It can be fixed by adding a fragment specifier.
1255 pub MISSING_FRAGMENT_SPECIFIER,
1256 Deny,
1257 "detects missing fragment specifiers in unused `macro_rules!` patterns",
1258 @future_incompatible = FutureIncompatibleInfo {
1259 reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
1260 edition: None,
1261 };
1262}
1263
1264declare_lint! {
1265 /// The `late_bound_lifetime_arguments` lint detects generic lifetime
1266 /// arguments in path segments with late bound lifetime parameters.
1267 ///
1268 /// ### Example
1269 ///
1270 /// ```rust
1271 /// struct S;
1272 ///
1273 /// impl S {
1274 /// fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {}
1275 /// }
1276 ///
1277 /// fn main() {
1278 /// S.late::<'static>(&0, &0);
1279 /// }
1280 /// ```
1281 ///
1282 /// {{produces}}
1283 ///
1284 /// ### Explanation
1285 ///
1286 /// It is not clear how to provide arguments for early-bound lifetime
1287 /// parameters if they are intermixed with late-bound parameters in the
1288 /// same list. For now, providing any explicit arguments will trigger this
1289 /// lint if late-bound parameters are present, so in the future a solution
1290 /// can be adopted without hitting backward compatibility issues. This is
1291 /// a [future-incompatible] lint to transition this to a hard error in the
1292 /// future. See [issue #42868] for more details, along with a description
1293 /// of the difference between early and late-bound parameters.
1294 ///
1295 /// [issue #42868]: https://github.com/rust-lang/rust/issues/42868
1296 /// [future-incompatible]: ../index.md#future-incompatible-lints
1297 pub LATE_BOUND_LIFETIME_ARGUMENTS,
1298 Warn,
1299 "detects generic lifetime arguments in path segments with late bound lifetime parameters",
1300 @future_incompatible = FutureIncompatibleInfo {
1301 reference: "issue #42868 <https://github.com/rust-lang/rust/issues/42868>",
1302 edition: None,
1303 };
1304}
1305
1306declare_lint! {
1307 /// The `order_dependent_trait_objects` lint detects a trait coherency
1308 /// violation that would allow creating two trait impls for the same
1309 /// dynamic trait object involving marker traits.
1310 ///
1311 /// ### Example
1312 ///
1313 /// ```rust,compile_fail
1314 /// pub trait Trait {}
1315 ///
1316 /// impl Trait for dyn Send + Sync { }
1317 /// impl Trait for dyn Sync + Send { }
1318 /// ```
1319 ///
1320 /// {{produces}}
1321 ///
1322 /// ### Explanation
1323 ///
1324 /// A previous bug caused the compiler to interpret traits with different
1325 /// orders (such as `Send + Sync` and `Sync + Send`) as distinct types
1326 /// when they were intended to be treated the same. This allowed code to
1327 /// define separate trait implementations when there should be a coherence
1328 /// error. This is a [future-incompatible] lint to transition this to a
1329 /// hard error in the future. See [issue #56484] for more details.
1330 ///
1331 /// [issue #56484]: https://github.com/rust-lang/rust/issues/56484
1332 /// [future-incompatible]: ../index.md#future-incompatible-lints
1333 pub ORDER_DEPENDENT_TRAIT_OBJECTS,
1334 Deny,
1335 "trait-object types were treated as different depending on marker-trait order",
1336 @future_incompatible = FutureIncompatibleInfo {
1337 reference: "issue #56484 <https://github.com/rust-lang/rust/issues/56484>",
1338 edition: None,
1339 };
1340}
1341
1342declare_lint! {
1343 /// The `coherence_leak_check` lint detects conflicting implementations of
1344 /// a trait that are only distinguished by the old leak-check code.
1345 ///
1346 /// ### Example
1347 ///
1348 /// ```rust
1349 /// trait SomeTrait { }
1350 /// impl SomeTrait for for<'a> fn(&'a u8) { }
1351 /// impl<'a> SomeTrait for fn(&'a u8) { }
1352 /// ```
1353 ///
1354 /// {{produces}}
1355 ///
1356 /// ### Explanation
1357 ///
1358 /// In the past, the compiler would accept trait implementations for
1359 /// identical functions that differed only in where the lifetime binder
1360 /// appeared. Due to a change in the borrow checker implementation to fix
1361 /// several bugs, this is no longer allowed. However, since this affects
1362 /// existing code, this is a [future-incompatible] lint to transition this
1363 /// to a hard error in the future.
1364 ///
1365 /// Code relying on this pattern should introduce "[newtypes]",
1366 /// like `struct Foo(for<'a> fn(&'a u8))`.
1367 ///
1368 /// See [issue #56105] for more details.
1369 ///
1370 /// [issue #56105]: https://github.com/rust-lang/rust/issues/56105
1371 /// [newtypes]: https://doc.rust-lang.org/book/ch19-04-advanced-types.html#using-the-newtype-pattern-for-type-safety-and-abstraction
1372 /// [future-incompatible]: ../index.md#future-incompatible-lints
1373 pub COHERENCE_LEAK_CHECK,
1374 Warn,
1375 "distinct impls distinguished only by the leak-check code",
1376 @future_incompatible = FutureIncompatibleInfo {
1377 reference: "issue #56105 <https://github.com/rust-lang/rust/issues/56105>",
1378 edition: None,
1379 };
1380}
1381
1382declare_lint! {
1383 /// The `deprecated` lint detects use of deprecated items.
1384 ///
1385 /// ### Example
1386 ///
1387 /// ```rust
1388 /// #[deprecated]
1389 /// fn foo() {}
1390 ///
1391 /// fn bar() {
1392 /// foo();
1393 /// }
1394 /// ```
1395 ///
1396 /// {{produces}}
1397 ///
1398 /// ### Explanation
1399 ///
1400 /// Items may be marked "deprecated" with the [`deprecated` attribute] to
1401 /// indicate that they should no longer be used. Usually the attribute
1402 /// should include a note on what to use instead, or check the
1403 /// documentation.
1404 ///
1405 /// [`deprecated` attribute]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute
1406 pub DEPRECATED,
1407 Warn,
1408 "detects use of deprecated items",
1409 report_in_external_macro
1410}
1411
1412declare_lint! {
1413 /// The `unused_unsafe` lint detects unnecessary use of an `unsafe` block.
1414 ///
1415 /// ### Example
1416 ///
1417 /// ```rust
1418 /// unsafe {}
1419 /// ```
1420 ///
1421 /// {{produces}}
1422 ///
1423 /// ### Explanation
1424 ///
1425 /// If nothing within the block requires `unsafe`, then remove the
1426 /// `unsafe` marker because it is not required and may cause confusion.
1427 pub UNUSED_UNSAFE,
1428 Warn,
1429 "unnecessary use of an `unsafe` block"
1430}
1431
1432declare_lint! {
1433 /// The `unused_mut` lint detects mut variables which don't need to be
1434 /// mutable.
1435 ///
1436 /// ### Example
1437 ///
1438 /// ```rust
1439 /// let mut x = 5;
1440 /// ```
1441 ///
1442 /// {{produces}}
1443 ///
1444 /// ### Explanation
1445 ///
1446 /// The preferred style is to only mark variables as `mut` if it is
1447 /// required.
1448 pub UNUSED_MUT,
1449 Warn,
1450 "detect mut variables which don't need to be mutable"
1451}
1452
1453declare_lint! {
1454 /// The `unconditional_recursion` lint detects functions that cannot
1455 /// return without calling themselves.
1456 ///
1457 /// ### Example
1458 ///
1459 /// ```rust
1460 /// fn foo() {
1461 /// foo();
1462 /// }
1463 /// ```
1464 ///
1465 /// {{produces}}
1466 ///
1467 /// ### Explanation
1468 ///
1469 /// It is usually a mistake to have a recursive call that does not have
1470 /// some condition to cause it to terminate. If you really intend to have
1471 /// an infinite loop, using a `loop` expression is recommended.
1472 pub UNCONDITIONAL_RECURSION,
1473 Warn,
1474 "functions that cannot return without calling themselves"
1475}
1476
1477declare_lint! {
1478 /// The `single_use_lifetimes` lint detects lifetimes that are only used
1479 /// once.
1480 ///
1481 /// ### Example
1482 ///
1483 /// ```rust,compile_fail
1484 /// #![deny(single_use_lifetimes)]
1485 ///
1486 /// fn foo<'a>(x: &'a u32) {}
1487 /// ```
1488 ///
1489 /// {{produces}}
1490 ///
1491 /// ### Explanation
1492 ///
1493 /// Specifying an explicit lifetime like `'a` in a function or `impl`
1494 /// should only be used to link together two things. Otherwise, you should
1495 /// just use `'_` to indicate that the lifetime is not linked to anything,
1496 /// or elide the lifetime altogether if possible.
1497 ///
1498 /// This lint is "allow" by default because it was introduced at a time
1499 /// when `'_` and elided lifetimes were first being introduced, and this
1500 /// lint would be too noisy. Also, there are some known false positives
1501 /// that it produces. See [RFC 2115] for historical context, and [issue
1502 /// #44752] for more details.
1503 ///
1504 /// [RFC 2115]: https://github.com/rust-lang/rfcs/blob/master/text/2115-argument-lifetimes.md
1505 /// [issue #44752]: https://github.com/rust-lang/rust/issues/44752
1506 pub SINGLE_USE_LIFETIMES,
1507 Allow,
1508 "detects lifetime parameters that are only used once"
1509}
1510
1511declare_lint! {
1512 /// The `unused_lifetimes` lint detects lifetime parameters that are never
1513 /// used.
1514 ///
1515 /// ### Example
1516 ///
1517 /// ```rust,compile_fail
1518 /// #[deny(unused_lifetimes)]
1519 ///
1520 /// pub fn foo<'a>() {}
1521 /// ```
1522 ///
1523 /// {{produces}}
1524 ///
1525 /// ### Explanation
1526 ///
1527 /// Unused lifetime parameters may signal a mistake or unfinished code.
1528 /// Consider removing the parameter.
1529 pub UNUSED_LIFETIMES,
1530 Allow,
1531 "detects lifetime parameters that are never used"
1532}
1533
1534declare_lint! {
1535 /// The `tyvar_behind_raw_pointer` lint detects raw pointer to an
1536 /// inference variable.
1537 ///
1538 /// ### Example
1539 ///
1540 /// ```rust,edition2015
1541 /// // edition 2015
1542 /// let data = std::ptr::null();
1543 /// let _ = &data as *const *const ();
1544 ///
1545 /// if data.is_null() {}
1546 /// ```
1547 ///
1548 /// {{produces}}
1549 ///
1550 /// ### Explanation
1551 ///
1552 /// This kind of inference was previously allowed, but with the future
1553 /// arrival of [arbitrary self types], this can introduce ambiguity. To
1554 /// resolve this, use an explicit type instead of relying on type
1555 /// inference.
1556 ///
1557 /// This is a [future-incompatible] lint to transition this to a hard
1558 /// error in the 2018 edition. See [issue #46906] for more details. This
1559 /// is currently a hard-error on the 2018 edition, and is "warn" by
1560 /// default in the 2015 edition.
1561 ///
1562 /// [arbitrary self types]: https://github.com/rust-lang/rust/issues/44874
1563 /// [issue #46906]: https://github.com/rust-lang/rust/issues/46906
1564 /// [future-incompatible]: ../index.md#future-incompatible-lints
1565 pub TYVAR_BEHIND_RAW_POINTER,
1566 Warn,
1567 "raw pointer to an inference variable",
1568 @future_incompatible = FutureIncompatibleInfo {
1569 reference: "issue #46906 <https://github.com/rust-lang/rust/issues/46906>",
1570 edition: Some(Edition::Edition2018),
1571 };
1572}
1573
1574declare_lint! {
1575 /// The `elided_lifetimes_in_paths` lint detects the use of hidden
1576 /// lifetime parameters.
1577 ///
1578 /// ### Example
1579 ///
1580 /// ```rust,compile_fail
1581 /// #![deny(elided_lifetimes_in_paths)]
1582 /// struct Foo<'a> {
1583 /// x: &'a u32
1584 /// }
1585 ///
1586 /// fn foo(x: &Foo) {
1587 /// }
1588 /// ```
1589 ///
1590 /// {{produces}}
1591 ///
1592 /// ### Explanation
1593 ///
1594 /// Elided lifetime parameters can make it difficult to see at a glance
1595 /// that borrowing is occurring. This lint ensures that lifetime
1596 /// parameters are always explicitly stated, even if it is the `'_`
1597 /// [placeholder lifetime].
1598 ///
1599 /// This lint is "allow" by default because it has some known issues, and
1600 /// may require a significant transition for old code.
1601 ///
1602 /// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1603 pub ELIDED_LIFETIMES_IN_PATHS,
1604 Allow,
1605 "hidden lifetime parameters in types are deprecated",
1606 crate_level_only
1607}
1608
1609declare_lint! {
1610 /// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
1611 /// objects.
1612 ///
1613 /// ### Example
1614 ///
1615 /// ```rust
1616 /// trait Trait { }
1617 ///
1618 /// fn takes_trait_object(_: Box<Trait>) {
1619 /// }
1620 /// ```
1621 ///
1622 /// {{produces}}
1623 ///
1624 /// ### Explanation
1625 ///
1626 /// Without the `dyn` indicator, it can be ambiguous or confusing when
1627 /// reading code as to whether or not you are looking at a trait object.
1628 /// The `dyn` keyword makes it explicit, and adds a symmetry to contrast
1629 /// with [`impl Trait`].
1630 ///
1631 /// [`impl Trait`]: https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
1632 pub BARE_TRAIT_OBJECTS,
1633 Warn,
1634 "suggest using `dyn Trait` for trait objects"
1635}
1636
1637declare_lint! {
1638 /// The `absolute_paths_not_starting_with_crate` lint detects fully
1639 /// qualified paths that start with a module name instead of `crate`,
1640 /// `self`, or an extern crate name
1641 ///
1642 /// ### Example
1643 ///
1644 /// ```rust,edition2015,compile_fail
1645 /// #![deny(absolute_paths_not_starting_with_crate)]
1646 ///
1647 /// mod foo {
1648 /// pub fn bar() {}
1649 /// }
1650 ///
1651 /// fn main() {
1652 /// ::foo::bar();
1653 /// }
1654 /// ```
1655 ///
1656 /// {{produces}}
1657 ///
1658 /// ### Explanation
1659 ///
1660 /// Rust [editions] allow the language to evolve without breaking
1661 /// backwards compatibility. This lint catches code that uses absolute
1662 /// paths in the style of the 2015 edition. In the 2015 edition, absolute
1663 /// paths (those starting with `::`) refer to either the crate root or an
1664 /// external crate. In the 2018 edition it was changed so that they only
1665 /// refer to external crates. The path prefix `crate::` should be used
1666 /// instead to reference items from the crate root.
1667 ///
1668 /// If you switch the compiler from the 2015 to 2018 edition without
1669 /// updating the code, then it will fail to compile if the old style paths
1670 /// are used. You can manually change the paths to use the `crate::`
1671 /// prefix to transition to the 2018 edition.
1672 ///
1673 /// This lint solves the problem automatically. It is "allow" by default
1674 /// because the code is perfectly valid in the 2015 edition. The [`cargo
1675 /// fix`] tool with the `--edition` flag will switch this lint to "warn"
1676 /// and automatically apply the suggested fix from the compiler. This
1677 /// provides a completely automated way to update old code to the 2018
1678 /// edition.
1679 ///
1680 /// [editions]: https://doc.rust-lang.org/edition-guide/
1681 /// [`cargo fix`]: https://doc.rust-lang.org/cargo/commands/cargo-fix.html
1682 pub ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
1683 Allow,
1684 "fully qualified paths that start with a module name \
1685 instead of `crate`, `self`, or an extern crate name",
1686 @future_incompatible = FutureIncompatibleInfo {
1687 reference: "issue #53130 <https://github.com/rust-lang/rust/issues/53130>",
1688 edition: Some(Edition::Edition2018),
1689 };
1690}
1691
1692declare_lint! {
1693 /// The `illegal_floating_point_literal_pattern` lint detects
1694 /// floating-point literals used in patterns.
1695 ///
1696 /// ### Example
1697 ///
1698 /// ```rust
1699 /// let x = 42.0;
1700 ///
1701 /// match x {
1702 /// 5.0 => {}
1703 /// _ => {}
1704 /// }
1705 /// ```
1706 ///
1707 /// {{produces}}
1708 ///
1709 /// ### Explanation
1710 ///
1711 /// Previous versions of the compiler accepted floating-point literals in
1712 /// patterns, but it was later determined this was a mistake. The
1713 /// semantics of comparing floating-point values may not be clear in a
1714 /// pattern when contrasted with "structural equality". Typically you can
1715 /// work around this by using a [match guard], such as:
1716 ///
1717 /// ```rust
1718 /// # let x = 42.0;
1719 ///
1720 /// match x {
1721 /// y if y == 5.0 => {}
1722 /// _ => {}
1723 /// }
1724 /// ```
1725 ///
1726 /// This is a [future-incompatible] lint to transition this to a hard
1727 /// error in the future. See [issue #41620] for more details.
1728 ///
1729 /// [issue #41620]: https://github.com/rust-lang/rust/issues/41620
1730 /// [match guard]: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards
1731 /// [future-incompatible]: ../index.md#future-incompatible-lints
1732 pub ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
1733 Warn,
1734 "floating-point literals cannot be used in patterns",
1735 @future_incompatible = FutureIncompatibleInfo {
1736 reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
1737 edition: None,
1738 };
1739}
1740
1741declare_lint! {
1742 /// The `unstable_name_collisions` lint detects that you have used a name
1743 /// that the standard library plans to add in the future.
1744 ///
1745 /// ### Example
1746 ///
1747 /// ```rust
1748 /// trait MyIterator : Iterator {
1749 /// // is_sorted is an unstable method that already exists on the Iterator trait
1750 /// fn is_sorted(self) -> bool where Self: Sized {true}
1751 /// }
1752 ///
1753 /// impl<T: ?Sized> MyIterator for T where T: Iterator { }
1754 ///
1755 /// let x = vec![1,2,3];
1756 /// let _ = x.iter().is_sorted();
1757 /// ```
1758 ///
1759 /// {{produces}}
1760 ///
1761 /// ### Explanation
1762 ///
1763 /// When new methods are added to traits in the standard library, they are
1764 /// usually added in an "unstable" form which is only available on the
1765 /// [nightly channel] with a [`feature` attribute]. If there is any
1766 /// pre-existing code which extends a trait to have a method with the same
1767 /// name, then the names will collide. In the future, when the method is
1768 /// stabilized, this will cause an error due to the ambiguity. This lint
1769 /// is an early-warning to let you know that there may be a collision in
1770 /// the future. This can be avoided by adding type annotations to
1771 /// disambiguate which trait method you intend to call, such as
1772 /// `MyIterator::is_sorted(my_iter)` or renaming or removing the method.
1773 ///
1774 /// [nightly channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
1775 /// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
1776 pub UNSTABLE_NAME_COLLISIONS,
1777 Warn,
1778 "detects name collision with an existing but unstable method",
1779 @future_incompatible = FutureIncompatibleInfo {
1780 reference: "issue #48919 <https://github.com/rust-lang/rust/issues/48919>",
1781 edition: None,
1782 // Note: this item represents future incompatibility of all unstable functions in the
1783 // standard library, and thus should never be removed or changed to an error.
1784 };
1785}
1786
1787declare_lint! {
1788 /// The `irrefutable_let_patterns` lint detects detects [irrefutable
1789 /// patterns] in [if-let] and [while-let] statements.
1790 ///
1791 ///
1792 ///
1793 /// ### Example
1794 ///
1795 /// ```rust
1796 /// if let _ = 123 {
1797 /// println!("always runs!");
1798 /// }
1799 /// ```
1800 ///
1801 /// {{produces}}
1802 ///
1803 /// ### Explanation
1804 ///
1805 /// There usually isn't a reason to have an irrefutable pattern in an
1806 /// if-let or while-let statement, because the pattern will always match
1807 /// successfully. A [`let`] or [`loop`] statement will suffice. However,
1808 /// when generating code with a macro, forbidding irrefutable patterns
1809 /// would require awkward workarounds in situations where the macro
1810 /// doesn't know if the pattern is refutable or not. This lint allows
1811 /// macros to accept this form, while alerting for a possibly incorrect
1812 /// use in normal code.
1813 ///
1814 /// See [RFC 2086] for more details.
1815 ///
1816 /// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
1817 /// [if-let]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
1818 /// [while-let]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
1819 /// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
1820 /// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
1821 /// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
1822 pub IRREFUTABLE_LET_PATTERNS,
1823 Warn,
1824 "detects irrefutable patterns in if-let and while-let statements"
1825}
1826
1827declare_lint! {
1828 /// The `unused_labels` lint detects [labels] that are never used.
1829 ///
1830 /// [labels]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#loop-labels
1831 ///
1832 /// ### Example
1833 ///
1834 /// ```rust,no_run
1835 /// 'unused_label: loop {}
1836 /// ```
1837 ///
1838 /// {{produces}}
1839 ///
1840 /// ### Explanation
1841 ///
1842 /// Unused labels may signal a mistake or unfinished code. To silence the
1843 /// warning for the individual label, prefix it with an underscore such as
1844 /// `'_my_label:`.
1845 pub UNUSED_LABELS,
1846 Warn,
1847 "detects labels that are never used"
1848}
1849
1850declare_lint! {
1851 /// The `broken_intra_doc_links` lint detects failures in resolving
1852 /// intra-doc link targets. This is a `rustdoc` only lint, see the
1853 /// documentation in the [rustdoc book].
1854 ///
1855 /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
1856 pub BROKEN_INTRA_DOC_LINKS,
1857 Warn,
1858 "failures in resolving intra-doc link targets"
1859}
1860
1861declare_lint! {
1862 /// This is a subset of `broken_intra_doc_links` that warns when linking from
1863 /// a public item to a private one. This is a `rustdoc` only lint, see the
1864 /// documentation in the [rustdoc book].
1865 ///
1866 /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
1867 pub PRIVATE_INTRA_DOC_LINKS,
1868 Warn,
1869 "linking from a public item to a private one"
1870}
1871
1872declare_lint! {
1873 /// The `invalid_codeblock_attributes` lint detects code block attributes
1874 /// in documentation examples that have potentially mis-typed values. This
1875 /// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
1876 ///
1877 /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
1878 pub INVALID_CODEBLOCK_ATTRIBUTES,
1879 Warn,
1880 "codeblock attribute looks a lot like a known one"
1881}
1882
1883declare_lint! {
1884 /// The `missing_crate_level_docs` lint detects if documentation is
1885 /// missing at the crate root. This is a `rustdoc` only lint, see the
1886 /// documentation in the [rustdoc book].
1887 ///
1888 /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
1889 pub MISSING_CRATE_LEVEL_DOCS,
1890 Allow,
1891 "detects crates with no crate-level documentation"
1892}
1893
1894declare_lint! {
1895 /// The `missing_doc_code_examples` lint detects publicly-exported items
1896 /// without code samples in their documentation. This is a `rustdoc` only
1897 /// lint, see the documentation in the [rustdoc book].
1898 ///
1899 /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
1900 pub MISSING_DOC_CODE_EXAMPLES,
1901 Allow,
1902 "detects publicly-exported items without code samples in their documentation"
1903}
1904
1905declare_lint! {
1906 /// The `private_doc_tests` lint detects code samples in docs of private
1907 /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
1908 /// the documentation in the [rustdoc book].
1909 ///
1910 /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
1911 pub PRIVATE_DOC_TESTS,
1912 Allow,
1913 "detects code samples in docs of private items not documented by rustdoc"
1914}
1915
1916declare_lint! {
1917 /// The `where_clauses_object_safety` lint detects for [object safety] of
1918 /// [where clauses].
1919 ///
1920 /// [object safety]: https://doc.rust-lang.org/reference/items/traits.html#object-safety
1921 /// [where clauses]: https://doc.rust-lang.org/reference/items/generics.html#where-clauses
1922 ///
1923 /// ### Example
1924 ///
1925 /// ```rust,no_run
1926 /// trait Trait {}
1927 ///
1928 /// trait X { fn foo(&self) where Self: Trait; }
1929 ///
1930 /// impl X for () { fn foo(&self) {} }
1931 ///
1932 /// impl Trait for dyn X {}
1933 ///
1934 /// // Segfault at opt-level 0, SIGILL otherwise.
1935 /// pub fn main() { <dyn X as X>::foo(&()); }
1936 /// ```
1937 ///
1938 /// {{produces}}
1939 ///
1940 /// ### Explanation
1941 ///
1942 /// The compiler previously allowed these object-unsafe bounds, which was
1943 /// incorrect. This is a [future-incompatible] lint to transition this to
1944 /// a hard error in the future. See [issue #51443] for more details.
1945 ///
1946 /// [issue #51443]: https://github.com/rust-lang/rust/issues/51443
1947 /// [future-incompatible]: ../index.md#future-incompatible-lints
1948 pub WHERE_CLAUSES_OBJECT_SAFETY,
1949 Warn,
1950 "checks the object safety of where clauses",
1951 @future_incompatible = FutureIncompatibleInfo {
1952 reference: "issue #51443 <https://github.com/rust-lang/rust/issues/51443>",
1953 edition: None,
1954 };
1955}
1956
1957declare_lint! {
1958 /// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1959 /// derives using inaccessible names from parent modules.
1960 ///
1961 /// ### Example
1962 ///
1963 /// ```rust,ignore (proc-macro)
1964 /// // foo.rs
1965 /// #![crate_type = "proc-macro"]
1966 ///
1967 /// extern crate proc_macro;
1968 ///
1969 /// use proc_macro::*;
1970 ///
1971 /// #[proc_macro_derive(Foo)]
1972 /// pub fn foo1(a: TokenStream) -> TokenStream {
1973 /// drop(a);
1974 /// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
1975 /// }
1976 /// ```
1977 ///
1978 /// ```rust,ignore (needs-dependency)
1979 /// // bar.rs
1980 /// #[macro_use]
1981 /// extern crate foo;
1982 ///
1983 /// struct Something;
1984 ///
1985 /// #[derive(Foo)]
1986 /// struct Another;
1987 ///
1988 /// fn main() {}
1989 /// ```
1990 ///
1991 /// This will produce:
1992 ///
1993 /// ```text
1994 /// warning: cannot find type `Something` in this scope
1995 /// --> src/main.rs:8:10
1996 /// |
1997 /// 8 | #[derive(Foo)]
1998 /// | ^^^ names from parent modules are not accessible without an explicit import
1999 /// |
2000 /// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2001 /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2002 /// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2003 /// ```
2004 ///
2005 /// ### Explanation
2006 ///
2007 /// If a proc-macro generates a module, the compiler unintentionally
2008 /// allowed items in that module to refer to items in the crate root
2009 /// without importing them. This is a [future-incompatible] lint to
2010 /// transition this to a hard error in the future. See [issue #50504] for
2011 /// more details.
2012 ///
2013 /// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2014 /// [future-incompatible]: ../index.md#future-incompatible-lints
2015 pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2016 Warn,
2017 "detects proc macro derives using inaccessible names from parent modules",
2018 @future_incompatible = FutureIncompatibleInfo {
2019 reference: "issue #50504 <https://github.com/rust-lang/rust/issues/50504>",
2020 edition: None,
2021 };
2022}
2023
2024declare_lint! {
2025 /// The `macro_use_extern_crate` lint detects the use of the
2026 /// [`macro_use` attribute].
2027 ///
2028 /// ### Example
2029 ///
2030 /// ```rust,ignore (needs extern crate)
2031 /// #![deny(macro_use_extern_crate)]
2032 ///
2033 /// #[macro_use]
2034 /// extern crate serde_json;
2035 ///
2036 /// fn main() {
2037 /// let _ = json!{{}};
2038 /// }
2039 /// ```
2040 ///
2041 /// This will produce:
2042 ///
2043 /// ```text
2044 /// error: deprecated `#[macro_use]` attribute used to import macros should be replaced at use sites with a `use` item to import the macro instead
2045 /// --> src/main.rs:3:1
2046 /// |
2047 /// 3 | #[macro_use]
2048 /// | ^^^^^^^^^^^^
2049 /// |
2050 /// note: the lint level is defined here
2051 /// --> src/main.rs:1:9
2052 /// |
2053 /// 1 | #![deny(macro_use_extern_crate)]
2054 /// | ^^^^^^^^^^^^^^^^^^^^^^
2055 /// ```
2056 ///
2057 /// ### Explanation
2058 ///
2059 /// The [`macro_use` attribute] on an [`extern crate`] item causes
2060 /// macros in that external crate to be brought into the prelude of the
2061 /// crate, making the macros in scope everywhere. As part of the efforts
2062 /// to simplify handling of dependencies in the [2018 edition], the use of
2063 /// `extern crate` is being phased out. To bring macros from extern crates
2064 /// into scope, it is recommended to use a [`use` import].
2065 ///
2066 /// This lint is "allow" by default because this is a stylistic choice
2067 /// that has not been settled, see [issue #52043] for more information.
2068 ///
2069 /// [`macro_use` attribute]: https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute
2070 /// [`use` import]: https://doc.rust-lang.org/reference/items/use-declarations.html
2071 /// [issue #52043]: https://github.com/rust-lang/rust/issues/52043
2072 pub MACRO_USE_EXTERN_CRATE,
2073 Allow,
2074 "the `#[macro_use]` attribute is now deprecated in favor of using macros \
2075 via the module system"
2076}
2077
2078declare_lint! {
2079 /// The `macro_expanded_macro_exports_accessed_by_absolute_paths` lint
2080 /// detects macro-expanded [`macro_export`] macros from the current crate
2081 /// that cannot be referred to by absolute paths.
2082 ///
2083 /// [`macro_export`]: https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope
2084 ///
2085 /// ### Example
2086 ///
2087 /// ```rust,compile_fail
2088 /// macro_rules! define_exported {
2089 /// () => {
2090 /// #[macro_export]
2091 /// macro_rules! exported {
2092 /// () => {};
2093 /// }
2094 /// };
2095 /// }
2096 ///
2097 /// define_exported!();
2098 ///
2099 /// fn main() {
2100 /// crate::exported!();
2101 /// }
2102 /// ```
2103 ///
2104 /// {{produces}}
2105 ///
2106 /// ### Explanation
2107 ///
2108 /// The intent is that all macros marked with the `#[macro_export]`
2109 /// attribute are made available in the root of the crate. However, when a
2110 /// `macro_rules!` definition is generated by another macro, the macro
2111 /// expansion is unable to uphold this rule. This is a
2112 /// [future-incompatible] lint to transition this to a hard error in the
2113 /// future. See [issue #53495] for more details.
2114 ///
2115 /// [issue #53495]: https://github.com/rust-lang/rust/issues/53495
2116 /// [future-incompatible]: ../index.md#future-incompatible-lints
2117 pub MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2118 Deny,
2119 "macro-expanded `macro_export` macros from the current crate \
2120 cannot be referred to by absolute paths",
2121 @future_incompatible = FutureIncompatibleInfo {
2122 reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
2123 edition: None,
2124 };
2125 crate_level_only
2126}
2127
2128declare_lint! {
2129 /// The `explicit_outlives_requirements` lint detects unnecessary
2130 /// lifetime bounds that can be inferred.
2131 ///
2132 /// ### Example
2133 ///
2134 /// ```rust,compile_fail
2135 /// # #![allow(unused)]
2136 /// #![deny(explicit_outlives_requirements)]
2137 ///
2138 /// struct SharedRef<'a, T>
2139 /// where
2140 /// T: 'a,
2141 /// {
2142 /// data: &'a T,
2143 /// }
2144 /// ```
2145 ///
2146 /// {{produces}}
2147 ///
2148 /// ### Explanation
2149 ///
2150 /// If a `struct` contains a reference, such as `&'a T`, the compiler
2151 /// requires that `T` outlives the lifetime `'a`. This historically
2152 /// required writing an explicit lifetime bound to indicate this
2153 /// requirement. However, this can be overly explicit, causing clutter and
2154 /// unnecessary complexity. The language was changed to automatically
2155 /// infer the bound if it is not specified. Specifically, if the struct
2156 /// contains a reference, directly or indirectly, to `T` with lifetime
2157 /// `'x`, then it will infer that `T: 'x` is a requirement.
2158 ///
2159 /// This lint is "allow" by default because it can be noisy for existing
2160 /// code that already had these requirements. This is a stylistic choice,
2161 /// as it is still valid to explicitly state the bound. It also has some
2162 /// false positives that can cause confusion.
2163 ///
2164 /// See [RFC 2093] for more details.
2165 ///
2166 /// [RFC 2093]: https://github.com/rust-lang/rfcs/blob/master/text/2093-infer-outlives.md
2167 pub EXPLICIT_OUTLIVES_REQUIREMENTS,
2168 Allow,
2169 "outlives requirements can be inferred"
2170}
2171
2172declare_lint! {
2173 /// The `indirect_structural_match` lint detects a `const` in a pattern
2174 /// that manually implements [`PartialEq`] and [`Eq`].
2175 ///
2176 /// [`PartialEq`]: https://doc.rust-lang.org/std/cmp/trait.PartialEq.html
2177 /// [`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
2178 ///
2179 /// ### Example
2180 ///
2181 /// ```rust,compile_fail
2182 /// #![deny(indirect_structural_match)]
2183 ///
2184 /// struct NoDerive(i32);
2185 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2186 /// impl Eq for NoDerive { }
2187 /// #[derive(PartialEq, Eq)]
2188 /// struct WrapParam<T>(T);
2189 /// const WRAP_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(NoDerive(0));
2190 /// fn main() {
2191 /// match WRAP_INDIRECT_PARAM {
2192 /// WRAP_INDIRECT_PARAM => { }
2193 /// _ => { }
2194 /// }
2195 /// }
2196 /// ```
2197 ///
2198 /// {{produces}}
2199 ///
2200 /// ### Explanation
2201 ///
2202 /// The compiler unintentionally accepted this form in the past. This is a
2203 /// [future-incompatible] lint to transition this to a hard error in the
2204 /// future. See [issue #62411] for a complete description of the problem,
2205 /// and some possible solutions.
2206 ///
2207 /// [issue #62411]: https://github.com/rust-lang/rust/issues/62411
2208 /// [future-incompatible]: ../index.md#future-incompatible-lints
2209 pub INDIRECT_STRUCTURAL_MATCH,
2210 Warn,
2211 "constant used in pattern contains value of non-structural-match type in a field or a variant",
2212 @future_incompatible = FutureIncompatibleInfo {
2213 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/62411>",
2214 edition: None,
2215 };
2216}
2217
2218declare_lint! {
2219 /// The `deprecated_in_future` lint is internal to rustc and should not be
2220 /// used by user code.
2221 ///
2222 /// This lint is only enabled in the standard library. It works with the
2223 /// use of `#[rustc_deprecated]` with a `since` field of a version in the
2224 /// future. This allows something to be marked as deprecated in a future
2225 /// version, and then this lint will ensure that the item is no longer
2226 /// used in the standard library. See the [stability documentation] for
2227 /// more details.
2228 ///
2229 /// [stability documentation]: https://rustc-dev-guide.rust-lang.org/stability.html#rustc_deprecated
2230 pub DEPRECATED_IN_FUTURE,
2231 Allow,
2232 "detects use of items that will be deprecated in a future version",
2233 report_in_external_macro
2234}
2235
2236declare_lint! {
2237 /// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2238 /// cannot be relied upon across compiler versions and optimization levels.
2239 ///
2240 /// ### Example
2241 ///
2242 /// ```rust,compile_fail
2243 /// #![deny(pointer_structural_match)]
2244 /// fn foo(a: usize, b: usize) -> usize { a + b }
2245 /// const FOO: fn(usize, usize) -> usize = foo;
2246 /// fn main() {
2247 /// match FOO {
2248 /// FOO => {},
2249 /// _ => {},
2250 /// }
2251 /// }
2252 /// ```
2253 ///
2254 /// {{produces}}
2255 ///
2256 /// ### Explanation
2257 ///
2258 /// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2259 /// While these work in many cases as expected by users, it is possible that due to
2260 /// optimizations pointers are "not equal to themselves" or pointers to different functions
2261 /// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2262 /// functions if their bodies are the same, thus also making pointers to these functions point
2263 /// to the same location. Additionally functions may get duplicated if they are instantiated
2264 /// in different crates and not deduplicated again via LTO.
2265 pub POINTER_STRUCTURAL_MATCH,
2266 Allow,
2267 "pointers are not structural-match",
2268 @future_incompatible = FutureIncompatibleInfo {
2269 reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2270 edition: None,
2271 };
2272}
2273
2274declare_lint! {
2275 /// The `nontrivial_structural_match` lint detects constants that are used in patterns,
2276 /// whose type is not structural-match and whose initializer body actually uses values
2277 /// that are not structural-match. So `Option<NotStruturalMatch>` is ok if the constant
2278 /// is just `None`.
2279 ///
2280 /// ### Example
2281 ///
2282 /// ```rust,compile_fail
2283 /// #![deny(nontrivial_structural_match)]
2284 ///
2285 /// #[derive(Copy, Clone, Debug)]
2286 /// struct NoDerive(u32);
2287 /// impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
2288 /// impl Eq for NoDerive { }
2289 /// fn main() {
2290 /// const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
2291 /// match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
2292 /// }
2293 /// ```
2294 ///
2295 /// {{produces}}
2296 ///
2297 /// ### Explanation
2298 ///
2299 /// Previous versions of Rust accepted constants in patterns, even if those constants's types
2300 /// did not have `PartialEq` derived. Thus the compiler falls back to runtime execution of
2301 /// `PartialEq`, which can report that two constants are not equal even if they are
2302 /// bit-equivalent.
2303 pub NONTRIVIAL_STRUCTURAL_MATCH,
2304 Warn,
2305 "constant used in pattern of non-structural-match type and the constant's initializer \
2306 expression contains values of non-structural-match types",
2307 @future_incompatible = FutureIncompatibleInfo {
2308 reference: "issue #73448 <https://github.com/rust-lang/rust/issues/73448>",
2309 edition: None,
2310 };
2311}
2312
2313declare_lint! {
2314 /// The `ambiguous_associated_items` lint detects ambiguity between
2315 /// [associated items] and [enum variants].
2316 ///
2317 /// [associated items]: https://doc.rust-lang.org/reference/items/associated-items.html
2318 /// [enum variants]: https://doc.rust-lang.org/reference/items/enumerations.html
2319 ///
2320 /// ### Example
2321 ///
2322 /// ```rust,compile_fail
2323 /// enum E {
2324 /// V
2325 /// }
2326 ///
2327 /// trait Tr {
2328 /// type V;
2329 /// fn foo() -> Self::V;
2330 /// }
2331 ///
2332 /// impl Tr for E {
2333 /// type V = u8;
2334 /// // `Self::V` is ambiguous because it may refer to the associated type or
2335 /// // the enum variant.
2336 /// fn foo() -> Self::V { 0 }
2337 /// }
2338 /// ```
2339 ///
2340 /// {{produces}}
2341 ///
2342 /// ### Explanation
2343 ///
2344 /// Previous versions of Rust did not allow accessing enum variants
2345 /// through [type aliases]. When this ability was added (see [RFC 2338]), this
2346 /// introduced some situations where it can be ambiguous what a type
2347 /// was referring to.
2348 ///
2349 /// To fix this ambiguity, you should use a [qualified path] to explicitly
2350 /// state which type to use. For example, in the above example the
2351 /// function can be written as `fn f() -> <Self as Tr>::V { 0 }` to
2352 /// specifically refer to the associated type.
2353 ///
2354 /// This is a [future-incompatible] lint to transition this to a hard
2355 /// error in the future. See [issue #57644] for more details.
2356 ///
2357 /// [issue #57644]: https://github.com/rust-lang/rust/issues/57644
2358 /// [type aliases]: https://doc.rust-lang.org/reference/items/type-aliases.html#type-aliases
2359 /// [RFC 2338]: https://github.com/rust-lang/rfcs/blob/master/text/2338-type-alias-enum-variants.md
2360 /// [qualified path]: https://doc.rust-lang.org/reference/paths.html#qualified-paths
2361 /// [future-incompatible]: ../index.md#future-incompatible-lints
2362 pub AMBIGUOUS_ASSOCIATED_ITEMS,
2363 Deny,
2364 "ambiguous associated items",
2365 @future_incompatible = FutureIncompatibleInfo {
2366 reference: "issue #57644 <https://github.com/rust-lang/rust/issues/57644>",
2367 edition: None,
2368 };
2369}
2370
2371declare_lint! {
2372 /// The `mutable_borrow_reservation_conflict` lint detects the reservation
2373 /// of a two-phased borrow that conflicts with other shared borrows.
2374 ///
2375 /// ### Example
2376 ///
2377 /// ```rust
2378 /// let mut v = vec![0, 1, 2];
2379 /// let shared = &v;
2380 /// v.push(shared.len());
2381 /// ```
2382 ///
2383 /// {{produces}}
2384 ///
2385 /// ### Explanation
2386 ///
2387 /// This is a [future-incompatible] lint to transition this to a hard error
2388 /// in the future. See [issue #59159] for a complete description of the
2389 /// problem, and some possible solutions.
2390 ///
2391 /// [issue #59159]: https://github.com/rust-lang/rust/issues/59159
2392 /// [future-incompatible]: ../index.md#future-incompatible-lints
2393 pub MUTABLE_BORROW_RESERVATION_CONFLICT,
2394 Warn,
2395 "reservation of a two-phased borrow conflicts with other shared borrows",
2396 @future_incompatible = FutureIncompatibleInfo {
2397 reference: "issue #59159 <https://github.com/rust-lang/rust/issues/59159>",
2398 edition: None,
2399 };
2400}
2401
2402declare_lint! {
2403 /// The `soft_unstable` lint detects unstable features that were
2404 /// unintentionally allowed on stable.
2405 ///
2406 /// ### Example
2407 ///
2408 /// ```rust,compile_fail
2409 /// #[cfg(test)]
2410 /// extern crate test;
2411 ///
2412 /// #[bench]
2413 /// fn name(b: &mut test::Bencher) {
2414 /// b.iter(|| 123)
2415 /// }
2416 /// ```
2417 ///
2418 /// {{produces}}
2419 ///
2420 /// ### Explanation
2421 ///
2422 /// The [`bench` attribute] was accidentally allowed to be specified on
2423 /// the [stable release channel]. Turning this to a hard error would have
2424 /// broken some projects. This lint allows those projects to continue to
2425 /// build correctly when [`--cap-lints`] is used, but otherwise signal an
2426 /// error that `#[bench]` should not be used on the stable channel. This
2427 /// is a [future-incompatible] lint to transition this to a hard error in
2428 /// the future. See [issue #64266] for more details.
2429 ///
2430 /// [issue #64266]: https://github.com/rust-lang/rust/issues/64266
2431 /// [`bench` attribute]: https://doc.rust-lang.org/nightly/unstable-book/library-features/test.html
2432 /// [stable release channel]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2433 /// [`--cap-lints`]: https://doc.rust-lang.org/rustc/lints/levels.html#capping-lints
2434 /// [future-incompatible]: ../index.md#future-incompatible-lints
2435 pub SOFT_UNSTABLE,
2436 Deny,
2437 "a feature gate that doesn't break dependent crates",
2438 @future_incompatible = FutureIncompatibleInfo {
2439 reference: "issue #64266 <https://github.com/rust-lang/rust/issues/64266>",
2440 edition: None,
2441 };
2442}
2443
2444declare_lint! {
2445 /// The `inline_no_sanitize` lint detects incompatible use of
2446 /// [`#[inline(always)]`][inline] and [`#[no_sanitize(...)]`][no_sanitize].
2447 ///
2448 /// [inline]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute
2449 /// [no_sanitize]: https://doc.rust-lang.org/nightly/unstable-book/language-features/no-sanitize.html
2450 ///
2451 /// ### Example
2452 ///
2453 /// ```rust
2454 /// #![feature(no_sanitize)]
2455 ///
2456 /// #[inline(always)]
2457 /// #[no_sanitize(address)]
2458 /// fn x() {}
2459 ///
2460 /// fn main() {
2461 /// x()
2462 /// }
2463 /// ```
2464 ///
2465 /// {{produces}}
2466 ///
2467 /// ### Explanation
2468 ///
2469 /// The use of the [`#[inline(always)]`][inline] attribute prevents the
2470 /// the [`#[no_sanitize(...)]`][no_sanitize] attribute from working.
2471 /// Consider temporarily removing `inline` attribute.
2472 pub INLINE_NO_SANITIZE,
2473 Warn,
2474 "detects incompatible use of `#[inline(always)]` and `#[no_sanitize(...)]`",
2475}
2476
2477declare_lint! {
2478 /// The `asm_sub_register` lint detects using only a subset of a register
2479 /// for inline asm inputs.
2480 ///
2481 /// ### Example
2482 ///
2483 /// ```rust,ignore (fails on system llvm)
2484 /// #![feature(asm)]
2485 ///
2486 /// fn main() {
2487 /// #[cfg(target_arch="x86_64")]
2488 /// unsafe {
2489 /// asm!("mov {0}, {0}", in(reg) 0i16);
2490 /// }
2491 /// }
2492 /// ```
2493 ///
2494 /// This will produce:
2495 ///
2496 /// ```text
2497 /// warning: formatting may not be suitable for sub-register argument
2498 /// --> src/main.rs:6:19
2499 /// |
2500 /// 6 | asm!("mov {0}, {0}", in(reg) 0i16);
2501 /// | ^^^ ^^^ ---- for this argument
2502 /// |
2503 /// = note: `#[warn(asm_sub_register)]` on by default
2504 /// = help: use the `x` modifier to have the register formatted as `ax`
2505 /// = help: or use the `r` modifier to keep the default formatting of `rax`
2506 /// ```
2507 ///
2508 /// ### Explanation
2509 ///
2510 /// Registers on some architectures can use different names to refer to a
2511 /// subset of the register. By default, the compiler will use the name for
2512 /// the full register size. To explicitly use a subset of the register,
2513 /// you can override the default by using a modifier on the template
2514 /// string operand to specify when subregister to use. This lint is issued
2515 /// if you pass in a value with a smaller data type than the default
2516 /// register size, to alert you of possibly using the incorrect width. To
2517 /// fix this, add the suggested modifier to the template, or cast the
2518 /// value to the correct size.
2519 ///
2520 /// See [register template modifiers] for more details.
2521 ///
2522 /// [register template modifiers]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#register-template-modifiers
2523 pub ASM_SUB_REGISTER,
2524 Warn,
2525 "using only a subset of a register for inline asm inputs",
2526}
2527
2528declare_lint! {
2529 /// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
2530 /// functions without an explicit unsafe block. This lint only works on
2531 /// the [**nightly channel**] with the
2532 /// `#![feature(unsafe_block_in_unsafe_fn)]` feature.
2533 ///
2534 /// [**nightly channel**]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
2535 ///
2536 /// ### Example
2537 ///
2538 /// ```rust,compile_fail
2539 /// #![feature(unsafe_block_in_unsafe_fn)]
2540 /// #![deny(unsafe_op_in_unsafe_fn)]
2541 ///
2542 /// unsafe fn foo() {}
2543 ///
2544 /// unsafe fn bar() {
2545 /// foo();
2546 /// }
2547 ///
2548 /// fn main() {}
2549 /// ```
2550 ///
2551 /// {{produces}}
2552 ///
2553 /// ### Explanation
2554 ///
2555 /// Currently, an [`unsafe fn`] allows any [unsafe] operation within its
2556 /// body. However, this can increase the surface area of code that needs
2557 /// to be scrutinized for proper behavior. The [`unsafe` block] provides a
2558 /// convenient way to make it clear exactly which parts of the code are
2559 /// performing unsafe operations. In the future, it is desired to change
2560 /// it so that unsafe operations cannot be performed in an `unsafe fn`
2561 /// without an `unsafe` block.
2562 ///
2563 /// The fix to this is to wrap the unsafe code in an `unsafe` block.
2564 ///
2565 /// This lint is "allow" by default because it has not yet been
2566 /// stabilized, and is not yet complete. See [RFC #2585] and [issue
2567 /// #71668] for more details
2568 ///
2569 /// [`unsafe fn`]: https://doc.rust-lang.org/reference/unsafe-functions.html
2570 /// [`unsafe` block]: https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks
2571 /// [unsafe]: https://doc.rust-lang.org/reference/unsafety.html
2572 /// [RFC #2585]: https://github.com/rust-lang/rfcs/blob/master/text/2585-unsafe-block-in-unsafe-fn.md
2573 /// [issue #71668]: https://github.com/rust-lang/rust/issues/71668
2574 pub UNSAFE_OP_IN_UNSAFE_FN,
2575 Allow,
2576 "unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
2577 @feature_gate = sym::unsafe_block_in_unsafe_fn;
2578}
2579
2580declare_lint! {
2581 /// The `cenum_impl_drop_cast` lint detects an `as` cast of a field-less
2582 /// `enum` that implements [`Drop`].
2583 ///
2584 /// [`Drop`]: https://doc.rust-lang.org/std/ops/trait.Drop.html
2585 ///
2586 /// ### Example
2587 ///
2588 /// ```rust
2589 /// # #![allow(unused)]
2590 /// enum E {
2591 /// A,
2592 /// }
2593 ///
2594 /// impl Drop for E {
2595 /// fn drop(&mut self) {
2596 /// println!("Drop");
2597 /// }
2598 /// }
2599 ///
2600 /// fn main() {
2601 /// let e = E::A;
2602 /// let i = e as u32;
2603 /// }
2604 /// ```
2605 ///
2606 /// {{produces}}
2607 ///
2608 /// ### Explanation
2609 ///
2610 /// Casting a field-less `enum` that does not implement [`Copy`] to an
2611 /// integer moves the value without calling `drop`. This can result in
2612 /// surprising behavior if it was expected that `drop` should be called.
2613 /// Calling `drop` automatically would be inconsistent with other move
2614 /// operations. Since neither behavior is clear or consistent, it was
2615 /// decided that a cast of this nature will no longer be allowed.
2616 ///
2617 /// This is a [future-incompatible] lint to transition this to a hard error
2618 /// in the future. See [issue #73333] for more details.
2619 ///
2620 /// [future-incompatible]: ../index.md#future-incompatible-lints
2621 /// [issue #73333]: https://github.com/rust-lang/rust/issues/73333
2622 /// [`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html
2623 pub CENUM_IMPL_DROP_CAST,
2624 Warn,
2625 "a C-like enum implementing Drop is cast",
2626 @future_incompatible = FutureIncompatibleInfo {
2627 reference: "issue #73333 <https://github.com/rust-lang/rust/issues/73333>",
2628 edition: None,
2629 };
2630}
2631
2632declare_lint! {
2633 /// The `const_evaluatable_unchecked` lint detects a generic constant used
2634 /// in a type.
2635 ///
2636 /// ### Example
2637 ///
2638 /// ```rust
2639 /// const fn foo<T>() -> usize {
2640 /// if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
2641 /// 4
2642 /// } else {
2643 /// 8
2644 /// }
2645 /// }
2646 ///
2647 /// fn test<T>() {
2648 /// let _ = [0; foo::<T>()];
2649 /// }
2650 /// ```
2651 ///
2652 /// {{produces}}
2653 ///
2654 /// ### Explanation
2655 ///
2656 /// In the 1.43 release, some uses of generic parameters in array repeat
2657 /// expressions were accidentally allowed. This is a [future-incompatible]
2658 /// lint to transition this to a hard error in the future. See [issue
2659 /// #76200] for a more detailed description and possible fixes.
2660 ///
2661 /// [future-incompatible]: ../index.md#future-incompatible-lints
2662 /// [issue #76200]: https://github.com/rust-lang/rust/issues/76200
2663 pub CONST_EVALUATABLE_UNCHECKED,
2664 Warn,
2665 "detects a generic constant is used in a type without a emitting a warning",
2666 @future_incompatible = FutureIncompatibleInfo {
2667 reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
2668 edition: None,
2669 };
2670}
2671
2672declare_tool_lint! {
2673 pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2674 Deny,
2675 "detects `#[unstable]` on stable trait implementations for stable types"
2676}
2677
2678declare_lint_pass! {
2679 /// Does nothing as a lint pass, but registers some `Lint`s
2680 /// that are used by other parts of the compiler.
2681 HardwiredLints => [
2682 ILLEGAL_FLOATING_POINT_LITERAL_PATTERN,
2683 ARITHMETIC_OVERFLOW,
2684 UNCONDITIONAL_PANIC,
2685 UNUSED_IMPORTS,
2686 UNUSED_EXTERN_CRATES,
2687 UNUSED_CRATE_DEPENDENCIES,
2688 UNUSED_QUALIFICATIONS,
2689 UNKNOWN_LINTS,
2690 UNUSED_VARIABLES,
2691 UNUSED_ASSIGNMENTS,
2692 DEAD_CODE,
2693 UNREACHABLE_CODE,
2694 UNREACHABLE_PATTERNS,
2695 OVERLAPPING_PATTERNS,
2696 BINDINGS_WITH_VARIANT_NAME,
2697 UNUSED_MACROS,
2698 WARNINGS,
2699 UNUSED_FEATURES,
2700 STABLE_FEATURES,
2701 UNKNOWN_CRATE_TYPES,
2702 TRIVIAL_CASTS,
2703 TRIVIAL_NUMERIC_CASTS,
2704 PRIVATE_IN_PUBLIC,
2705 EXPORTED_PRIVATE_DEPENDENCIES,
2706 PUB_USE_OF_PRIVATE_EXTERN_CRATE,
2707 INVALID_TYPE_PARAM_DEFAULT,
2708 CONST_ERR,
2709 RENAMED_AND_REMOVED_LINTS,
2710 UNALIGNED_REFERENCES,
2711 CONST_ITEM_MUTATION,
2712 SAFE_PACKED_BORROWS,
2713 PATTERNS_IN_FNS_WITHOUT_BODY,
2714 LATE_BOUND_LIFETIME_ARGUMENTS,
2715 ORDER_DEPENDENT_TRAIT_OBJECTS,
2716 COHERENCE_LEAK_CHECK,
2717 DEPRECATED,
2718 UNUSED_UNSAFE,
2719 UNUSED_MUT,
2720 UNCONDITIONAL_RECURSION,
2721 SINGLE_USE_LIFETIMES,
2722 UNUSED_LIFETIMES,
2723 UNUSED_LABELS,
2724 TYVAR_BEHIND_RAW_POINTER,
2725 ELIDED_LIFETIMES_IN_PATHS,
2726 BARE_TRAIT_OBJECTS,
2727 ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
2728 UNSTABLE_NAME_COLLISIONS,
2729 IRREFUTABLE_LET_PATTERNS,
2730 BROKEN_INTRA_DOC_LINKS,
2731 INVALID_CODEBLOCK_ATTRIBUTES,
2732 MISSING_CRATE_LEVEL_DOCS,
2733 MISSING_DOC_CODE_EXAMPLES,
2734 PRIVATE_DOC_TESTS,
2735 WHERE_CLAUSES_OBJECT_SAFETY,
2736 PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2737 MACRO_USE_EXTERN_CRATE,
2738 MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
2739 ILL_FORMED_ATTRIBUTE_INPUT,
2740 CONFLICTING_REPR_HINTS,
2741 META_VARIABLE_MISUSE,
2742 DEPRECATED_IN_FUTURE,
2743 AMBIGUOUS_ASSOCIATED_ITEMS,
2744 MUTABLE_BORROW_RESERVATION_CONFLICT,
2745 INDIRECT_STRUCTURAL_MATCH,
2746 POINTER_STRUCTURAL_MATCH,
2747 NONTRIVIAL_STRUCTURAL_MATCH,
2748 SOFT_UNSTABLE,
2749 INLINE_NO_SANITIZE,
2750 ASM_SUB_REGISTER,
2751 UNSAFE_OP_IN_UNSAFE_FN,
2752 INCOMPLETE_INCLUDE,
2753 CENUM_IMPL_DROP_CAST,
2754 CONST_EVALUATABLE_UNCHECKED,
2755 INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
2756 MISSING_FRAGMENT_SPECIFIER,
2757 ]
2758}
2759
2760declare_lint! {
2761 /// The `unused_doc_comments` lint detects doc comments that aren't used
2762 /// by `rustdoc`.
2763 ///
2764 /// ### Example
2765 ///
2766 /// ```rust
2767 /// /// docs for x
2768 /// let x = 12;
2769 /// ```
2770 ///
2771 /// {{produces}}
2772 ///
2773 /// ### Explanation
2774 ///
2775 /// `rustdoc` does not use doc comments in all positions, and so the doc
2776 /// comment will be ignored. Try changing it to a normal comment with `//`
2777 /// to avoid the warning.
2778 pub UNUSED_DOC_COMMENTS,
2779 Warn,
2780 "detects doc comments that aren't used by rustdoc"
2781}
2782
2783declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);