// ignore-tidy-filelength
+
//! Some lints that are built in to the compiler.
//!
//! These are the built-in lints that are emitted direct in the main
//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
-// ignore-tidy-filelength
-
-use crate::{declare_lint, declare_lint_pass};
+use crate::{declare_lint, declare_lint_pass, FutureBreakage};
use rustc_span::edition::Edition;
-use rustc_span::symbol::sym;
declare_lint! {
/// The `forbidden_lint_groups` lint detects violations of
pub UNALIGNED_REFERENCES,
Allow,
"detects unaligned references to fields of packed structs",
+ report_in_external_macro
}
declare_lint! {
}
declare_lint! {
- /// The `irrefutable_let_patterns` lint detects detects [irrefutable
- /// patterns] in [if-let] and [while-let] statements.
- ///
- ///
+ /// The `irrefutable_let_patterns` lint detects [irrefutable patterns]
+ /// in [`if let`]s, [`while let`]s, and `if let` guards.
///
/// ### Example
///
- /// ```rust
+ /// ```
/// if let _ = 123 {
/// println!("always runs!");
/// }
/// ### Explanation
///
/// There usually isn't a reason to have an irrefutable pattern in an
- /// if-let or while-let statement, because the pattern will always match
+ /// `if let` or `while let` statement, because the pattern will always match
/// successfully. A [`let`] or [`loop`] statement will suffice. However,
/// when generating code with a macro, forbidding irrefutable patterns
/// would require awkward workarounds in situations where the macro
/// See [RFC 2086] for more details.
///
/// [irrefutable patterns]: https://doc.rust-lang.org/reference/patterns.html#refutability
- /// [if-let]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
- /// [while-let]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
+ /// [`if let`]: https://doc.rust-lang.org/reference/expressions/if-expr.html#if-let-expressions
+ /// [`while let`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-pattern-loops
/// [`let`]: https://doc.rust-lang.org/reference/statements.html#let-statements
/// [`loop`]: https://doc.rust-lang.org/reference/expressions/loop-expr.html#infinite-loops
/// [RFC 2086]: https://github.com/rust-lang/rfcs/blob/master/text/2086-allow-if-let-irrefutables.md
pub IRREFUTABLE_LET_PATTERNS,
Warn,
- "detects irrefutable patterns in if-let and while-let statements"
+ "detects irrefutable patterns in `if let` and `while let` statements"
}
declare_lint! {
"detects labels that are never used"
}
-declare_lint! {
- /// The `broken_intra_doc_links` lint detects failures in resolving
- /// intra-doc link targets. This is a `rustdoc` only lint, see the
- /// documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
- pub BROKEN_INTRA_DOC_LINKS,
- Warn,
- "failures in resolving intra-doc link targets"
-}
-
-declare_lint! {
- /// This is a subset of `broken_intra_doc_links` that warns when linking from
- /// a public item to a private one. This is a `rustdoc` only lint, see the
- /// documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
- pub PRIVATE_INTRA_DOC_LINKS,
- Warn,
- "linking from a public item to a private one"
-}
-
-declare_lint! {
- /// The `invalid_codeblock_attributes` lint detects code block attributes
- /// in documentation examples that have potentially mis-typed values. This
- /// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
- pub INVALID_CODEBLOCK_ATTRIBUTES,
- Warn,
- "codeblock attribute looks a lot like a known one"
-}
-
-declare_lint! {
- /// The `missing_crate_level_docs` lint detects if documentation is
- /// missing at the crate root. This is a `rustdoc` only lint, see the
- /// documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
- pub MISSING_CRATE_LEVEL_DOCS,
- Allow,
- "detects crates with no crate-level documentation"
-}
-
-declare_lint! {
- /// The `missing_doc_code_examples` lint detects publicly-exported items
- /// without code samples in their documentation. This is a `rustdoc` only
- /// lint, see the documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
- pub MISSING_DOC_CODE_EXAMPLES,
- Allow,
- "detects publicly-exported items without code samples in their documentation"
-}
-
-declare_lint! {
- /// The `private_doc_tests` lint detects code samples in docs of private
- /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
- /// the documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
- pub PRIVATE_DOC_TESTS,
- Allow,
- "detects code samples in docs of private items not documented by rustdoc"
-}
-
-declare_lint! {
- /// The `invalid_html_tags` lint detects invalid HTML tags. This is a
- /// `rustdoc` only lint, see the documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
- pub INVALID_HTML_TAGS,
- Allow,
- "detects invalid HTML tags in doc comments"
-}
-
-declare_lint! {
- /// The `non_autolinks` lint detects when a URL could be written using
- /// only angle brackets. This is a `rustdoc` only lint, see the
- /// documentation in the [rustdoc book].
- ///
- /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
- pub NON_AUTOLINKS,
- Warn,
- "detects URLs that could be written using only angle brackets"
-}
-
declare_lint! {
/// The `where_clauses_object_safety` lint detects for [object safety] of
/// [where clauses].
declare_lint! {
/// The `unsafe_op_in_unsafe_fn` lint detects unsafe operations in unsafe
- /// functions without an explicit unsafe block. This lint only works on
- /// the [**nightly channel**] with the
- /// `#![feature(unsafe_block_in_unsafe_fn)]` feature.
- ///
- /// [**nightly channel**]: https://doc.rust-lang.org/book/appendix-07-nightly-rust.html
+ /// functions without an explicit unsafe block.
///
/// ### Example
///
/// ```rust,compile_fail
- /// #![feature(unsafe_block_in_unsafe_fn)]
/// #![deny(unsafe_op_in_unsafe_fn)]
///
/// unsafe fn foo() {}
pub UNSAFE_OP_IN_UNSAFE_FN,
Allow,
"unsafe operations in unsafe functions without an explicit unsafe block are deprecated",
- @feature_gate = sym::unsafe_block_in_unsafe_fn;
}
declare_lint! {
};
}
+declare_lint! {
+ /// The `legacy_derive_helpers` lint detects derive helper attributes
+ /// that are used before they are introduced.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,ignore (needs extern crate)
+ /// #[serde(rename_all = "camelCase")]
+ /// #[derive(Deserialize)]
+ /// struct S { /* fields */ }
+ /// ```
+ ///
+ /// produces:
+ ///
+ /// ```text
+ /// warning: derive helper attribute is used before it is introduced
+ /// --> $DIR/legacy-derive-helpers.rs:1:3
+ /// |
+ /// 1 | #[serde(rename_all = "camelCase")]
+ /// | ^^^^^
+ /// ...
+ /// 2 | #[derive(Deserialize)]
+ /// | ----------- the attribute is introduced here
+ /// ```
+ ///
+ /// ### Explanation
+ ///
+ /// Attributes like this work for historical reasons, but attribute expansion works in
+ /// left-to-right order in general, so, to resolve `#[serde]`, compiler has to try to "look
+ /// into the future" at not yet expanded part of the item , but such attempts are not always
+ /// reliable.
+ ///
+ /// To fix the warning place the helper attribute after its corresponding derive.
+ /// ```rust,ignore (needs extern crate)
+ /// #[derive(Deserialize)]
+ /// #[serde(rename_all = "camelCase")]
+ /// struct S { /* fields */ }
+ /// ```
+ pub LEGACY_DERIVE_HELPERS,
+ Warn,
+ "detects derive helper attributes that are used before they are introduced",
+ @future_incompatible = FutureIncompatibleInfo {
+ reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
+ };
+}
+
declare_lint_pass! {
/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
UNSTABLE_NAME_COLLISIONS,
IRREFUTABLE_LET_PATTERNS,
- BROKEN_INTRA_DOC_LINKS,
- PRIVATE_INTRA_DOC_LINKS,
- INVALID_CODEBLOCK_ATTRIBUTES,
- MISSING_CRATE_LEVEL_DOCS,
- MISSING_DOC_CODE_EXAMPLES,
- INVALID_HTML_TAGS,
- PRIVATE_DOC_TESTS,
- NON_AUTOLINKS,
WHERE_CLAUSES_OBJECT_SAFETY,
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
MACRO_USE_EXTERN_CRATE,
MISSING_ABI,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
DISJOINT_CAPTURE_DROP_REORDER,
+ LEGACY_DERIVE_HELPERS,
+ PROC_MACRO_BACK_COMPAT,
]
}
Allow,
"No declared ABI for extern declaration"
}
+
+declare_lint! {
+ /// The `invalid_doc_attributes` lint detects when the `#[doc(...)]` is
+ /// misused.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,compile_fail
+ /// #![deny(warnings)]
+ ///
+ /// pub mod submodule {
+ /// #![doc(test(no_crate_inject))]
+ /// }
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// Previously, there were very like checks being performed on `#[doc(..)]`
+ /// unlike the other attributes. It'll now catch all the issues that it
+ /// silently ignored previously.
+ pub INVALID_DOC_ATTRIBUTES,
+ Warn,
+ "detects invalid `#[doc(...)]` attributes",
+ @future_incompatible = FutureIncompatibleInfo {
+ reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
+ edition: None,
+ };
+}
+
+declare_lint! {
+ /// The `proc_macro_back_compat` lint detects uses of old versions of certain
+ /// proc-macro crates, which have hardcoded workarounds in the compiler.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,ignore (needs-dependency)
+ ///
+ /// use time_macros_impl::impl_macros;
+ /// struct Foo;
+ /// impl_macros!(Foo);
+ /// ```
+ ///
+ /// This will produce:
+ ///
+ /// ```text
+ /// warning: using an old version of `time-macros-impl`
+ /// ::: $DIR/group-compat-hack.rs:27:5
+ /// |
+ /// LL | impl_macros!(Foo);
+ /// | ------------------ in this macro invocation
+ /// |
+ /// = note: `#[warn(proc_macro_back_compat)]` on by default
+ /// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ /// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
+ /// = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
+ /// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+ /// ```
+ ///
+ /// ### Explanation
+ ///
+ /// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
+ /// causing older versions of certain crates to stop compiling.
+ /// This is a [future-incompatible] lint to ease the transition to an error.
+ /// See [issue #83125] for more details.
+ ///
+ /// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
+ /// [future-incompatible]: ../index.md#future-incompatible-lints
+ pub PROC_MACRO_BACK_COMPAT,
+ Warn,
+ "detects usage of old versions of certain proc-macro crates",
+ @future_incompatible = FutureIncompatibleInfo {
+ reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
+ edition: None,
+ future_breakage: Some(FutureBreakage {
+ date: None
+ })
+ };
+}