Auto merge of #8905 - c410-f3r:arith, r=llogiq
[1/N] Implement Arithmetic lint Assuming that https://github.com/rust-lang/rust-clippy/issues/8903 is OK, this PR starts the creation of the `Arithmetic` lint with configurable types. My current struggle to get a rustc review inspired me to create smaller PRs in order to easy review and make merges as fast as possible. So the first step here only moves the `arithmetic.rs` file to `numeric_arithmetic.rs` to make room for the new lint. -- changelog: none
This commit is contained in:
commit
9428e2e25e
@ -36,8 +36,6 @@ store.register_lints(&[
|
|||||||
absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS,
|
absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS,
|
||||||
almost_complete_letter_range::ALMOST_COMPLETE_LETTER_RANGE,
|
almost_complete_letter_range::ALMOST_COMPLETE_LETTER_RANGE,
|
||||||
approx_const::APPROX_CONSTANT,
|
approx_const::APPROX_CONSTANT,
|
||||||
arithmetic::FLOAT_ARITHMETIC,
|
|
||||||
arithmetic::INTEGER_ARITHMETIC,
|
|
||||||
as_conversions::AS_CONVERSIONS,
|
as_conversions::AS_CONVERSIONS,
|
||||||
asm_syntax::INLINE_ASM_X86_ATT_SYNTAX,
|
asm_syntax::INLINE_ASM_X86_ATT_SYNTAX,
|
||||||
asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX,
|
asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX,
|
||||||
@ -423,6 +421,8 @@ store.register_lints(&[
|
|||||||
non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS,
|
non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS,
|
||||||
non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY,
|
non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY,
|
||||||
nonstandard_macro_braces::NONSTANDARD_MACRO_BRACES,
|
nonstandard_macro_braces::NONSTANDARD_MACRO_BRACES,
|
||||||
|
numeric_arithmetic::FLOAT_ARITHMETIC,
|
||||||
|
numeric_arithmetic::INTEGER_ARITHMETIC,
|
||||||
octal_escapes::OCTAL_ESCAPES,
|
octal_escapes::OCTAL_ESCAPES,
|
||||||
only_used_in_recursion::ONLY_USED_IN_RECURSION,
|
only_used_in_recursion::ONLY_USED_IN_RECURSION,
|
||||||
open_options::NONSENSICAL_OPEN_OPTIONS,
|
open_options::NONSENSICAL_OPEN_OPTIONS,
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
// Manual edits will be overwritten.
|
// Manual edits will be overwritten.
|
||||||
|
|
||||||
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
|
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
|
||||||
LintId::of(arithmetic::FLOAT_ARITHMETIC),
|
|
||||||
LintId::of(arithmetic::INTEGER_ARITHMETIC),
|
|
||||||
LintId::of(as_conversions::AS_CONVERSIONS),
|
LintId::of(as_conversions::AS_CONVERSIONS),
|
||||||
LintId::of(asm_syntax::INLINE_ASM_X86_ATT_SYNTAX),
|
LintId::of(asm_syntax::INLINE_ASM_X86_ATT_SYNTAX),
|
||||||
LintId::of(asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX),
|
LintId::of(asm_syntax::INLINE_ASM_X86_INTEL_SYNTAX),
|
||||||
@ -50,6 +48,8 @@ store.register_group(true, "clippy::restriction", Some("clippy_restriction"), ve
|
|||||||
LintId::of(module_style::MOD_MODULE_FILES),
|
LintId::of(module_style::MOD_MODULE_FILES),
|
||||||
LintId::of(module_style::SELF_NAMED_MODULE_FILES),
|
LintId::of(module_style::SELF_NAMED_MODULE_FILES),
|
||||||
LintId::of(modulo_arithmetic::MODULO_ARITHMETIC),
|
LintId::of(modulo_arithmetic::MODULO_ARITHMETIC),
|
||||||
|
LintId::of(numeric_arithmetic::FLOAT_ARITHMETIC),
|
||||||
|
LintId::of(numeric_arithmetic::INTEGER_ARITHMETIC),
|
||||||
LintId::of(panic_in_result_fn::PANIC_IN_RESULT_FN),
|
LintId::of(panic_in_result_fn::PANIC_IN_RESULT_FN),
|
||||||
LintId::of(panic_unimplemented::PANIC),
|
LintId::of(panic_unimplemented::PANIC),
|
||||||
LintId::of(panic_unimplemented::TODO),
|
LintId::of(panic_unimplemented::TODO),
|
||||||
|
@ -170,7 +170,6 @@ mod renamed_lints;
|
|||||||
mod absurd_extreme_comparisons;
|
mod absurd_extreme_comparisons;
|
||||||
mod almost_complete_letter_range;
|
mod almost_complete_letter_range;
|
||||||
mod approx_const;
|
mod approx_const;
|
||||||
mod arithmetic;
|
|
||||||
mod as_conversions;
|
mod as_conversions;
|
||||||
mod asm_syntax;
|
mod asm_syntax;
|
||||||
mod assertions_on_constants;
|
mod assertions_on_constants;
|
||||||
@ -331,6 +330,7 @@ mod non_expressive_names;
|
|||||||
mod non_octal_unix_permissions;
|
mod non_octal_unix_permissions;
|
||||||
mod non_send_fields_in_send_ty;
|
mod non_send_fields_in_send_ty;
|
||||||
mod nonstandard_macro_braces;
|
mod nonstandard_macro_braces;
|
||||||
|
mod numeric_arithmetic;
|
||||||
mod octal_escapes;
|
mod octal_escapes;
|
||||||
mod only_used_in_recursion;
|
mod only_used_in_recursion;
|
||||||
mod open_options;
|
mod open_options;
|
||||||
@ -683,7 +683,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
|
store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
|
||||||
store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
|
store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
|
||||||
store.register_late_pass(|| Box::new(mem_forget::MemForget));
|
store.register_late_pass(|| Box::new(mem_forget::MemForget));
|
||||||
store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default()));
|
store.register_late_pass(|| Box::new(numeric_arithmetic::NumericArithmetic::default()));
|
||||||
store.register_late_pass(|| Box::new(assign_ops::AssignOps));
|
store.register_late_pass(|| Box::new(assign_ops::AssignOps));
|
||||||
store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq));
|
store.register_late_pass(|| Box::new(let_if_seq::LetIfSeq));
|
||||||
store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
|
store.register_late_pass(|| Box::new(mixed_read_write_in_expression::EvalOrderDependence));
|
||||||
|
@ -51,16 +51,16 @@ declare_clippy_lint! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default)]
|
#[derive(Copy, Clone, Default)]
|
||||||
pub struct Arithmetic {
|
pub struct NumericArithmetic {
|
||||||
expr_span: Option<Span>,
|
expr_span: Option<Span>,
|
||||||
/// This field is used to check whether expressions are constants, such as in enum discriminants
|
/// This field is used to check whether expressions are constants, such as in enum discriminants
|
||||||
/// and consts
|
/// and consts
|
||||||
const_span: Option<Span>,
|
const_span: Option<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_lint_pass!(Arithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
|
impl_lint_pass!(NumericArithmetic => [INTEGER_ARITHMETIC, FLOAT_ARITHMETIC]);
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for Arithmetic {
|
impl<'tcx> LateLintPass<'tcx> for NumericArithmetic {
|
||||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
||||||
if self.expr_span.is_some() {
|
if self.expr_span.is_some() {
|
||||||
return;
|
return;
|
Loading…
x
Reference in New Issue
Block a user