Skip to content

Fix config_namespace macro symbol usage #14520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions datafusion/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
$(
Expand All @@ -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<V: Visit>(&self, v: &mut V, key_prefix: &str, _description: &'static str) {
fn visit<V: $crate::config::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();
Expand Down
16 changes: 16 additions & 0 deletions datafusion/core/tests/macro_hygiene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}