diff --git a/datafusion/common/src/config.rs b/datafusion/common/src/config.rs index 320417c35a798..c9900204b97f2 100644 --- a/datafusion/common/src/config.rs +++ b/datafusion/common/src/config.rs @@ -108,6 +108,7 @@ use crate::{DataFusionError, Result}; /// ``` /// /// NB: Misplaced commas may result in nonsensical errors +#[macro_export] macro_rules! config_namespace { ( $(#[doc = $struct_d:tt])* // Struct-level documentation attributes @@ -138,8 +139,8 @@ macro_rules! config_namespace { )* } - impl ConfigField for $struct_name { - fn set(&mut self, key: &str, value: &str) -> Result<()> { + impl $crate::config::ConfigField for $struct_name { + fn set(&mut self, key: &str, value: &str) -> $crate::error::Result<()> { let (key, rem) = key.split_once('.').unwrap_or((key, "")); match key { $( @@ -154,13 +155,13 @@ macro_rules! config_namespace { } }, )* - _ => return _config_err!( + _ => return $crate::error::_config_err!( "Config value \"{}\" not found on {}", key, stringify!($struct_name) ) } } - fn visit(&self, v: &mut V, key_prefix: &str, _description: &'static str) { + fn visit(&self, v: &mut V, key_prefix: &str, _description: &'static str) { $( let key = format!(concat!("{}.", stringify!($field_name)), key_prefix); let desc = concat!($($d),*).trim(); diff --git a/datafusion/core/tests/macro_hygiene/mod.rs b/datafusion/core/tests/macro_hygiene/mod.rs index 5aff1d5e32961..9196efec972c1 100644 --- a/datafusion/core/tests/macro_hygiene/mod.rs +++ b/datafusion/core/tests/macro_hygiene/mod.rs @@ -49,3 +49,19 @@ mod record_batch { record_batch!(("column_name", Int32, vec![1, 2, 3])).unwrap(); } } + +mod config_namespace { + // NO other imports! + use datafusion_common::config_namespace; + + #[test] + fn test_macro() { + config_namespace! { + /// A config section + pub struct Foo { + /// Some doc comments + pub bar: bool, default = true + } + } + } +}