Skip to content

Commit d03800c

Browse files
macisamuelemeta-codesync[bot]
authored andcommitted
Add use super::* to define_stats! generated module for type hygiene
Summary: The `define_stats!` macro generates a `pub(crate) mod STATS { ... }` block. Type parameters in dynamic stat definitions (e.g. `region: String`) are forwarded as `tt` token trees and only parsed as types inside this generated module. This means custom types from the caller's scope were not resolvable — only primitive types and `&'static str` worked. Adding `use super::*;` to the generated module makes all of the caller's imports visible, so types like `dba_common_types::Region` can be used directly in stat definitions: ```rust use dba_common_types::Region; define_stats! { prefix = "my.prefix"; my_stat: dynamic_timeseries("{}", (region: Region); Count), } ``` All three resolution paths now work: - Direct name: `region: Region` (via `use super::*`) - Explicit super: `region: super::Region` - Fully qualified: `region: ::dba_common_types::Region` This is backward-compatible — existing code using `String`, `u64`, `&'static str` etc. continues to work unchanged. Reviewed By: dtolnay Differential Revision: D99868296 fbshipit-source-id: 30a75bb943d86751c6a28a79a85d50885921abaa
1 parent 33062b7 commit d03800c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

common/rust/shed/stats/src/macros.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ macro_rules! define_stats {
202202
#[allow(non_snake_case, non_upper_case_globals, unused_imports, clippy::redundant_pub_crate)]
203203
pub(crate) mod STATS {
204204
use $crate::macros::common_macro_prelude::*;
205+
// Import caller's symbols so that custom types (e.g. newtypes implementing
206+
// Display) can be used as dynamic stat key parameters without requiring
207+
// `super::` or fully qualified paths.
208+
use super::*;
205209

206210
static STATS_MAP: LazyLock<Arc<ThreadMap<BoxStatsManager>>> = LazyLock::new(|| create_map());
207211
static STATS_MANAGER: LazyLock<BoxStatsManager> = LazyLock::new(|| create_stats_manager());

0 commit comments

Comments
 (0)