From 80d482d6402c665b7f7334c09fa769dd0301df34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Arg=C3=A9rus?= Date: Tue, 5 Sep 2023 16:54:35 +0200 Subject: [PATCH] Fix clippy warnings/errors introduced by Rust 1.70 (#649) --- kuksa_databroker/databroker-cli/src/main.rs | 35 +-- .../databroker/src/query/executor.rs | 4 +- kuksa_databroker/databroker/src/types.rs | 295 ++++++++---------- 3 files changed, 135 insertions(+), 199 deletions(-) diff --git a/kuksa_databroker/databroker-cli/src/main.rs b/kuksa_databroker/databroker-cli/src/main.rs index 704f90c3e..36b2a3d02 100644 --- a/kuksa_databroker/databroker-cli/src/main.rs +++ b/kuksa_databroker/databroker-cli/src/main.rs @@ -1467,10 +1467,7 @@ mod test { try_into_data_value("false", proto::v1::DataType::Bool), Ok(proto::v1::datapoint::Value::BoolValue(value)) if !value )); - assert!(matches!( - try_into_data_value("truefalse", proto::v1::DataType::Bool), - Err(_) - )); + assert!(try_into_data_value("truefalse", proto::v1::DataType::Bool).is_err()); // BoolArray assert!(matches!( try_into_data_value("[true, false, true]", proto::v1::DataType::BoolArray), @@ -1486,18 +1483,9 @@ mod test { try_into_data_value("-100", proto::v1::DataType::Int8), Ok(proto::v1::datapoint::Value::Int32Value(value)) if value == -100 )); - assert!(matches!( - try_into_data_value("300", proto::v1::DataType::Int8), - Err(_) - )); - assert!(matches!( - try_into_data_value("-300", proto::v1::DataType::Int8), - Err(_) - )); - assert!(matches!( - try_into_data_value("-100.1", proto::v1::DataType::Int8), - Err(_) - )); + assert!(try_into_data_value("300", proto::v1::DataType::Int8).is_err()); + assert!(try_into_data_value("-300", proto::v1::DataType::Int8).is_err()); + assert!(try_into_data_value("-100.1", proto::v1::DataType::Int8).is_err()); // Int16 assert!(matches!( @@ -1516,18 +1504,9 @@ mod test { try_into_data_value("-32000", proto::v1::DataType::Int16), Ok(proto::v1::datapoint::Value::Int32Value(value)) if value == -32000 )); - assert!(matches!( - try_into_data_value("33000", proto::v1::DataType::Int16), - Err(_) - )); - assert!(matches!( - try_into_data_value("-33000", proto::v1::DataType::Int16), - Err(_) - )); - assert!(matches!( - try_into_data_value("-32000.1", proto::v1::DataType::Int16), - Err(_) - )); + assert!(try_into_data_value("33000", proto::v1::DataType::Int16).is_err()); + assert!(try_into_data_value("-33000", proto::v1::DataType::Int16).is_err()); + assert!(try_into_data_value("-32000.1", proto::v1::DataType::Int16).is_err()); } #[test] diff --git a/kuksa_databroker/databroker/src/query/executor.rs b/kuksa_databroker/databroker/src/query/executor.rs index e28f7305b..013fea6a6 100644 --- a/kuksa_databroker/databroker/src/query/executor.rs +++ b/kuksa_databroker/databroker/src/query/executor.rs @@ -378,7 +378,7 @@ fn executor_test() { DataValue::NotAvailable, ), ]; - assert!(matches!(res, Some(_))); + assert!(res.is_some()); if let Some(fields) = &res { assert_eq!(fields.len(), 2); for (i, (name, value)) in fields.iter().enumerate() { @@ -396,5 +396,5 @@ fn executor_test() { }; let res = compiled_query.execute(&execution_input1).unwrap(); - assert!(matches!(res, None)); + assert!(res.is_none()); } diff --git a/kuksa_databroker/databroker/src/types.rs b/kuksa_databroker/databroker/src/types.rs index d65121084..d950f5b82 100644 --- a/kuksa_databroker/databroker/src/types.rs +++ b/kuksa_databroker/databroker/src/types.rs @@ -562,141 +562,110 @@ impl DataValue { #[test] fn test_string_greater_than() { - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Bool(false)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()) - .greater_than(&DataValue::String("string2".to_owned())), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Int32(100)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Int64(100)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Uint32(100)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Uint64(100)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Float(100.0)), - Err(_) - )); - assert!(matches!( - DataValue::String("string".to_owned()).greater_than(&DataValue::Double(100.0)), - Err(_) - )); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Bool(false)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::String("string2".to_owned())) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Int32(100)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Int64(100)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Uint32(100)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Uint64(100)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Float(100.0)) + .is_err()); + assert!(DataValue::String("string".to_owned()) + .greater_than(&DataValue::Double(100.0)) + .is_err()); } #[test] fn test_not_available_greater_than() { - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Bool(false)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Int32(100)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Int64(100)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Uint32(100)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Uint64(100)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Float(100.0)), - Err(_) - )); - assert!(matches!( - DataValue::NotAvailable.greater_than(&DataValue::Double(100.0)), - Err(_) - )); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Bool(false)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Int32(100)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Int64(100)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Uint32(100)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Uint64(100)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Float(100.0)) + .is_err()); + assert!(DataValue::NotAvailable + .greater_than(&DataValue::Double(100.0)) + .is_err()); } #[test] fn test_bool_greater_than() { - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Bool(false)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Int32(100)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Int64(100)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Uint32(100)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Uint64(100)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Float(100.0)), - Err(_) - )); - assert!(matches!( - DataValue::Bool(false).greater_than(&DataValue::Double(100.0)), - Err(_) - )); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Bool(false)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Int32(100)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Int64(100)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Uint32(100)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Uint64(100)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Float(100.0)) + .is_err()); + assert!(DataValue::Bool(false) + .greater_than(&DataValue::Double(100.0)) + .is_err()); } #[test] fn test_int32_greater_than() { // Comparison not possible // - assert!(matches!( - DataValue::Int32(5000).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Int32(5000).greater_than(&DataValue::Bool(true)), - Err(_) - )); - assert!(matches!( - DataValue::Int32(5000).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); + assert!(DataValue::Int32(5000) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Int32(5000) + .greater_than(&DataValue::Bool(true)) + .is_err()); + assert!(DataValue::Int32(5000) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); // Should be greater than // @@ -772,18 +741,15 @@ fn test_int64_greater_than() { // Comparison not possible // - assert!(matches!( - DataValue::Int64(5000).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Int64(5000).greater_than(&DataValue::Bool(true)), - Err(_) - )); - assert!(matches!( - DataValue::Int64(5000).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); + assert!(DataValue::Int64(5000) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Int64(5000) + .greater_than(&DataValue::Bool(true)) + .is_err()); + assert!(DataValue::Int64(5000) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); // Should be greater than // @@ -860,18 +826,15 @@ fn test_uint32_greater_than() { // Comparison not possible // - assert!(matches!( - DataValue::Uint32(5000).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Uint32(5000).greater_than(&DataValue::Bool(true)), - Err(_) - )); - assert!(matches!( - DataValue::Uint32(5000).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); + assert!(DataValue::Uint32(5000) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Uint32(5000) + .greater_than(&DataValue::Bool(true)) + .is_err()); + assert!(DataValue::Uint32(5000) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); // Should be greater than // @@ -951,18 +914,15 @@ fn test_uint64_greater_than() { // Comparison not possible // - assert!(matches!( - DataValue::Uint64(5000).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Uint64(5000).greater_than(&DataValue::Bool(true)), - Err(_) - )); - assert!(matches!( - DataValue::Uint64(5000).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); + assert!(DataValue::Uint64(5000) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Uint64(5000) + .greater_than(&DataValue::Bool(true)) + .is_err()); + assert!(DataValue::Uint64(5000) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); // Should be greater than // @@ -1054,18 +1014,15 @@ fn test_double_less_than() {} #[test] fn test_float_equals() { - assert!(matches!( - DataValue::Float(5000.0).greater_than(&DataValue::NotAvailable), - Err(_) - )); - assert!(matches!( - DataValue::Float(5000.0).greater_than(&DataValue::Bool(true)), - Err(_) - )); - assert!(matches!( - DataValue::Float(5000.0).greater_than(&DataValue::String("string".to_owned())), - Err(_) - )); + assert!(DataValue::Float(5000.0) + .greater_than(&DataValue::NotAvailable) + .is_err()); + assert!(DataValue::Float(5000.0) + .greater_than(&DataValue::Bool(true)) + .is_err()); + assert!(DataValue::Float(5000.0) + .greater_than(&DataValue::String("string".to_owned())) + .is_err()); assert!(matches!( DataValue::Float(32.0).equals(&DataValue::Int32(32)),