Skip to content

Commit

Permalink
NO-JIRA: [Rust] Fix build errors with 1.78.0-nightly (0ecbd0605 2024-…
Browse files Browse the repository at this point in the history
…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 <rust-lang/rust#120363>
```

Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
(cherry picked from commit 9e72af2)
  • Loading branch information
martin-g committed Feb 26, 2024
1 parent d889e04 commit 3eaa056
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions lang/rust/avro/tests/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lang/rust/avro_test_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<String>> = RefCell::new(Vec::new());
pub(crate) static LOG_MESSAGES: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
}

pub mod logger;
Expand Down

0 comments on commit 3eaa056

Please sign in to comment.