Auto merge of #13510 - alex-semenyuk:cleanup_const_float_classify, r=llogiq
Cleanup `const_float_classify` As mentioned at #13508 `const_float_classify` has been stabilized recently in https://github.com/rust-lang/rust/pull/130157 and can be cleanup Close #13508 changelog: [none]
This commit is contained in:
commit
04849bd7d9
5 changed files with 32 additions and 8 deletions
|
|
@ -903,7 +903,7 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
|
|||
store.register_late_pass(|_| Box::new(manual_range_patterns::ManualRangePatterns));
|
||||
store.register_early_pass(|| Box::new(visibility::Visibility));
|
||||
store.register_late_pass(move |_| Box::new(tuple_array_conversions::TupleArrayConversions::new(conf)));
|
||||
store.register_late_pass(|_| Box::new(manual_float_methods::ManualFloatMethods));
|
||||
store.register_late_pass(move |_| Box::new(manual_float_methods::ManualFloatMethods::new(conf)));
|
||||
store.register_late_pass(|_| Box::new(four_forward_slashes::FourForwardSlashes));
|
||||
store.register_late_pass(|_| Box::new(error_impl_error::ErrorImplError));
|
||||
store.register_late_pass(move |_| Box::new(absolute_paths::AbsolutePaths::new(conf)));
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
use clippy_config::msrvs::Msrv;
|
||||
use clippy_config::{Conf, msrvs};
|
||||
use clippy_utils::consts::{ConstEvalCtxt, Constant};
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::source::SpanRangeExt;
|
||||
|
|
@ -6,7 +8,7 @@ use rustc_errors::Applicability;
|
|||
use rustc_hir::{BinOpKind, Constness, Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass, Lint, LintContext};
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_session::impl_lint_pass;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
|
|
@ -56,7 +58,7 @@ declare_clippy_lint! {
|
|||
style,
|
||||
"use dedicated method to check if a float is finite"
|
||||
}
|
||||
declare_lint_pass!(ManualFloatMethods => [MANUAL_IS_INFINITE, MANUAL_IS_FINITE]);
|
||||
impl_lint_pass!(ManualFloatMethods => [MANUAL_IS_INFINITE, MANUAL_IS_FINITE]);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Variant {
|
||||
|
|
@ -80,6 +82,18 @@ impl Variant {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ManualFloatMethods {
|
||||
msrv: Msrv,
|
||||
}
|
||||
|
||||
impl ManualFloatMethods {
|
||||
pub fn new(conf: &'static Conf) -> Self {
|
||||
Self {
|
||||
msrv: conf.msrv.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
if let ExprKind::Binary(kind, lhs, rhs) = expr.kind
|
||||
|
|
@ -92,7 +106,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
|
|||
&& !in_external_macro(cx.sess(), expr.span)
|
||||
&& (
|
||||
matches!(cx.tcx.constness(cx.tcx.hir().enclosing_body_owner(expr.hir_id)), Constness::NotConst)
|
||||
|| cx.tcx.features().declared(sym!(const_float_classify))
|
||||
|| self.msrv.meets(msrvs::CONST_FLOAT_CLASSIFY)
|
||||
)
|
||||
&& let [first, second, const_1, const_2] = exprs
|
||||
&& let ecx = ConstEvalCtxt::new(cx)
|
||||
|
|
@ -150,6 +164,8 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
extract_msrv_attr!(LateContext);
|
||||
}
|
||||
|
||||
fn is_infinity(constant: &Constant<'_>) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue