From 963dce3e2852bddefe46baf834e9a49e37aaf1d1 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 11 Oct 2024 17:53:42 +0300 Subject: [PATCH] Fix new lints. --- .github/workflows/ci.yml | 2 ++ Cargo.toml | 3 +++ src/context/predefined/mod.rs | 1 + src/function/builtin.rs | 4 ++-- src/function/mod.rs | 2 ++ tests/integration.rs | 34 +++++++--------------------------- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b4bc6c..4df51a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,6 +154,8 @@ jobs: - name: Install toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable - name: Install cargo-sync-readme run: cargo install cargo-sync-readme diff --git a/Cargo.toml b/Cargo.toml index 4fba2c1..ba48e8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,3 +36,6 @@ regex_support = ["regex"] ron = "0.7.0" rand = "0.8.5" rand_pcg = "0.3.1" + +[lints.rust] + unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] } \ No newline at end of file diff --git a/src/context/predefined/mod.rs b/src/context/predefined/mod.rs index 1b1f4b6..ad8e785 100644 --- a/src/context/predefined/mod.rs +++ b/src/context/predefined/mod.rs @@ -1,4 +1,5 @@ /// Context with all Rust's constants in `f64::consts` available by default. +/// /// Alternatively, specifiy constants with `math_consts_context!(E, PI, TAU, ...)` /// Available constants can be found in the [`core::f64::consts module`](https://doc.rust-lang.org/nightly/core/f64/consts/index.html). #[macro_export] diff --git a/src/function/builtin.rs b/src/function/builtin.rs index be55e93..da543bc 100644 --- a/src/function/builtin.rs +++ b/src/function/builtin.rs @@ -110,7 +110,7 @@ pub fn builtin_function(identifier: &str) -> Option { })), "min" => Some(Function::new(|argument| { let arguments = argument.as_tuple()?; - let mut min_int = IntType::max_value(); + let mut min_int = IntType::MAX; let mut min_float: FloatType = 1.0 / 0.0; debug_assert!(min_float.is_infinite()); @@ -132,7 +132,7 @@ pub fn builtin_function(identifier: &str) -> Option { })), "max" => Some(Function::new(|argument| { let arguments = argument.as_tuple()?; - let mut max_int = IntType::min_value(); + let mut max_int = IntType::MIN; let mut max_float: FloatType = -1.0 / 0.0; debug_assert!(max_float.is_infinite()); diff --git a/src/function/mod.rs b/src/function/mod.rs index 75d5a4c..c590107 100644 --- a/src/function/mod.rs +++ b/src/function/mod.rs @@ -78,6 +78,8 @@ impl fmt::Debug for Function { /// A trait to ensure a type is `Send` and `Sync`. /// If implemented for a type, the crate will not compile if the type is not `Send` and `Sync`. +#[allow(dead_code)] +#[doc(hidden)] trait IsSendAndSync: Send + Sync {} impl IsSendAndSync for Function {} diff --git a/tests/integration.rs b/tests/integration.rs index 695056b..f63acec 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -583,33 +583,13 @@ fn test_errors() { #[test] fn test_no_panic() { - assert!(eval(&format!( - "{} + {}", - IntType::max_value(), - IntType::max_value() - )) - .is_err()); - assert!(eval(&format!( - "-{} - {}", - IntType::max_value(), - IntType::max_value() - )) - .is_err()); - assert!(eval(&format!("-(-{} - 1)", IntType::max_value())).is_err()); - assert!(eval(&format!( - "{} * {}", - IntType::max_value(), - IntType::max_value() - )) - .is_err()); - assert!(eval(&format!("{} / {}", IntType::max_value(), 0)).is_err()); - assert!(eval(&format!("{} % {}", IntType::max_value(), 0)).is_err()); - assert!(eval(&format!( - "{} ^ {}", - IntType::max_value(), - IntType::max_value() - )) - .is_ok()); + assert!(eval(&format!("{} + {}", IntType::MAX, IntType::MAX)).is_err()); + assert!(eval(&format!("-{} - {}", IntType::MAX, IntType::MAX)).is_err()); + assert!(eval(&format!("-(-{} - 1)", IntType::MAX)).is_err()); + assert!(eval(&format!("{} * {}", IntType::MAX, IntType::MAX)).is_err()); + assert!(eval(&format!("{} / {}", IntType::MAX, 0)).is_err()); + assert!(eval(&format!("{} % {}", IntType::MAX, 0)).is_err()); + assert!(eval(&format!("{} ^ {}", IntType::MAX, IntType::MAX)).is_ok()); assert!(eval("if").is_err()); assert!(eval("if()").is_err()); assert!(eval("if(true, 1)").is_err());