From 9e72af2593ceb76ccde7710408f1177635697ece Mon Sep 17 00:00:00 2001 From: Martin Tzvetanov Grigorov Date: Mon, 26 Feb 2024 13:24:43 +0200 Subject: [PATCH] NO-JIRA: [Rust] Fix build errors with 1.78.0-nightly (0ecbd0605 2024-02-25) Extract the test trait impls out of the test function body. No user facing changes! ``` error: non-local `impl` definition, they should be avoided as they go against expectation --> avro/tests/validators.rs:42:5 | 42 | / impl SchemaNamespaceValidator for CustomValidator { 43 | | fn validate(&self, _ns: &str) -> AvroResult<()> { 44 | | Ok(()) 45 | | } 46 | | } | |_____^ | = help: move this `impl` block outside the of the current function `avro_3900_custom_validator_with_spec_invalid_names` = note: an `impl` definition is non-local if it is nested inside an item and neither the type nor the trait are at the same nesting level as the `impl` block = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue ``` Signed-off-by: Martin Tzvetanov Grigorov --- lang/rust/avro/tests/validators.rs | 42 +++++++++++++-------------- lang/rust/avro_test_helper/src/lib.rs | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lang/rust/avro/tests/validators.rs b/lang/rust/avro/tests/validators.rs index 941ffc3e7d7..fc45353a8d6 100644 --- a/lang/rust/avro/tests/validators.rs +++ b/lang/rust/avro/tests/validators.rs @@ -28,35 +28,35 @@ use apache_avro_test_helper::TestResult; struct CustomValidator; -#[test] -fn avro_3900_custom_validator_with_spec_invalid_names() -> TestResult { - // Setup the custom validators before the schema is parsed - // because the parsing will trigger the validation and will - // setup the default validator (SpecificationValidator)! - impl SchemaNameValidator for CustomValidator { - fn validate(&self, schema_name: &str) -> AvroResult<(String, Namespace)> { - Ok((schema_name.to_string(), None)) - } +// Setup the custom validators before the schema is parsed +// because the parsing will trigger the validation and will +// setup the default validator (SpecificationValidator)! +impl SchemaNameValidator for CustomValidator { + fn validate(&self, schema_name: &str) -> AvroResult<(String, Namespace)> { + Ok((schema_name.to_string(), None)) } +} - impl SchemaNamespaceValidator for CustomValidator { - fn validate(&self, _ns: &str) -> AvroResult<()> { - Ok(()) - } +impl SchemaNamespaceValidator for CustomValidator { + fn validate(&self, _ns: &str) -> AvroResult<()> { + Ok(()) } +} - impl EnumSymbolNameValidator for CustomValidator { - fn validate(&self, _ns: &str) -> AvroResult<()> { - Ok(()) - } +impl EnumSymbolNameValidator for CustomValidator { + fn validate(&self, _ns: &str) -> AvroResult<()> { + Ok(()) } +} - impl RecordFieldNameValidator for CustomValidator { - fn validate(&self, _ns: &str) -> AvroResult<()> { - Ok(()) - } +impl RecordFieldNameValidator for CustomValidator { + fn validate(&self, _ns: &str) -> AvroResult<()> { + Ok(()) } +} +#[test] +fn avro_3900_custom_validator_with_spec_invalid_names() -> TestResult { assert!(set_schema_name_validator(Box::new(CustomValidator)).is_ok()); assert!(set_schema_namespace_validator(Box::new(CustomValidator)).is_ok()); assert!(set_enum_symbol_name_validator(Box::new(CustomValidator)).is_ok()); diff --git a/lang/rust/avro_test_helper/src/lib.rs b/lang/rust/avro_test_helper/src/lib.rs index 5e1e04b50ae..e316dc818d4 100644 --- a/lang/rust/avro_test_helper/src/lib.rs +++ b/lang/rust/avro_test_helper/src/lib.rs @@ -23,7 +23,7 @@ thread_local! { // The unit tests run in parallel // We need to keep the log messages in a thread-local variable // and clear them after assertion - pub(crate) static LOG_MESSAGES: RefCell> = RefCell::new(Vec::new()); + pub(crate) static LOG_MESSAGES: RefCell> = const { RefCell::new(Vec::new()) }; } pub mod logger;