//! compiler code, rather than using their own custom pass. Those
//! lints are all available in `rustc_lint::builtin`.
-use crate::{declare_lint, declare_lint_pass, declare_tool_lint};
+use crate::{declare_lint, declare_lint_pass};
use rustc_span::edition::Edition;
use rustc_span::symbol::sym;
///
/// ```rust,compile_fail
/// #![allow(unconditional_panic)]
- /// let x: &'static i32 = &(1 / 0);
+ /// const C: i32 = 1/0;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
- /// This lint detects code that is very likely incorrect. If this lint is
- /// allowed, then the code will not be evaluated at compile-time, and
- /// instead continue to generate code to evaluate at runtime, which may
- /// panic during runtime.
+ /// This lint detects constants that fail to evaluate. Allowing the lint will accept the
+ /// constant declaration, but any use of this constant will still lead to a hard error. This is
+ /// a future incompatibility lint; the plan is to eventually entirely forbid even declaring
+ /// constants that cannot be evaluated. See [issue #71800] for more details.
///
- /// Note that this lint may trigger in either inside or outside of a
- /// [const context]. Outside of a [const context], the compiler can
- /// sometimes evaluate an expression at compile-time in order to generate
- /// more efficient code. As the compiler becomes better at doing this, it
- /// needs to decide what to do when it encounters code that it knows for
- /// certain will panic or is otherwise incorrect. Making this a hard error
- /// would prevent existing code that exhibited this behavior from
- /// compiling, breaking backwards-compatibility. However, this is almost
- /// certainly incorrect code, so this is a deny-by-default lint. For more
- /// details, see [RFC 1229] and [issue #28238].
- ///
- /// Note that there are several other more specific lints associated with
- /// compile-time evaluation, such as [`arithmetic_overflow`],
- /// [`unconditional_panic`].
- ///
- /// [const context]: https://doc.rust-lang.org/reference/const_eval.html#const-context
- /// [RFC 1229]: https://github.com/rust-lang/rfcs/blob/master/text/1229-compile-time-asserts.md
- /// [issue #28238]: https://github.com/rust-lang/rust/issues/28238
- /// [`arithmetic_overflow`]: deny-by-default.html#arithmetic-overflow
- /// [`unconditional_panic`]: deny-by-default.html#unconditional-panic
+ /// [issue #71800]: https://github.com/rust-lang/rust/issues/71800
pub CONST_ERR,
Deny,
- "constant evaluation detected erroneous expression",
+ "constant evaluation encountered erroneous expression",
report_in_external_macro
}
};
}
-declare_tool_lint! {
- pub rustc::INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
+declare_lint! {
+ /// The `ineffective_unstable_trait_impl` lint detects `#[unstable]` attributes which are not used.
+ ///
+ /// ### Example
+ ///
+ /// ```compile_fail
+ /// #![feature(staged_api)]
+ ///
+ /// #[derive(Clone)]
+ /// #[stable(feature = "x", since = "1")]
+ /// struct S {}
+ ///
+ /// #[unstable(feature = "y", issue = "none")]
+ /// impl Copy for S {}
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// `staged_api` does not currently support using a stability attribute on `impl` blocks.
+ /// `impl`s are always stable if both the type and trait are stable, and always unstable otherwise.
+ pub INEFFECTIVE_UNSTABLE_TRAIT_IMPL,
Deny,
"detects `#[unstable]` on stable trait implementations for stable types"
}
FUNCTION_ITEM_REFERENCES,
USELESS_DEPRECATED,
UNSUPPORTED_NAKED_FUNCTIONS,
+ MISSING_ABI,
]
}
}
declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);
+
+declare_lint! {
+ /// The `missing_abi` lint detects cases where the ABI is omitted from
+ /// extern declarations.
+ ///
+ /// ### Example
+ ///
+ /// ```rust,compile_fail
+ /// #![deny(missing_abi)]
+ ///
+ /// extern fn foo() {}
+ /// ```
+ ///
+ /// {{produces}}
+ ///
+ /// ### Explanation
+ ///
+ /// Historically, Rust implicitly selected C as the ABI for extern
+ /// declarations. We expect to add new ABIs, like `C-unwind`, in the future,
+ /// though this has not yet happened, and especially with their addition
+ /// seeing the ABI easily will make code review easier.
+ pub MISSING_ABI,
+ Allow,
+ "No declared ABI for extern declaration"
+}