Skip to content

Commit 3b6234a

Browse files
authored
Tweak the declare_builtin_index macro (#11534)
This allows for specifying custom meta attributes (additionaly derives, docs, etc). This functionality is not yet used now, but will be in future commits. Also makes the macro syntax more similar to a regular struct definition, which allows for easier `grep`-ability.
1 parent 41e7169 commit 3b6234a

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

crates/environ/src/builtin.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,11 @@ macro_rules! foreach_builtin_function {
255255
/// `ComponentBuiltinFunctionIndex` using the iterator macro, e.g.
256256
/// `foreach_builtin_function`, as the way to generate accessor methods.
257257
macro_rules! declare_builtin_index {
258-
($index_name:ident, $iter:ident) => {
259-
/// An index type for builtin functions.
258+
(
259+
$(#[$attr:meta])*
260+
pub struct $index_name:ident : $for_each_builtin:ident ;
261+
) => {
262+
$(#[$attr])*
260263
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
261264
pub struct $index_name(u32);
262265

@@ -272,7 +275,7 @@ macro_rules! declare_builtin_index {
272275
self.0
273276
}
274277

275-
$iter!(declare_builtin_index_constructors);
278+
$for_each_builtin!(declare_builtin_index_constructors);
276279
}
277280
};
278281
}
@@ -340,7 +343,10 @@ macro_rules! declare_builtin_index_constructors {
340343
}
341344

342345
// Define `struct BuiltinFunctionIndex`
343-
declare_builtin_index!(BuiltinFunctionIndex, foreach_builtin_function);
346+
declare_builtin_index! {
347+
/// An index type for builtin functions.
348+
pub struct BuiltinFunctionIndex : foreach_builtin_function;
349+
}
344350

345351
/// Return value of [`BuiltinFunctionIndex::trap_sentinel`].
346352
pub enum TrapSentinel {

crates/environ/src/component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ macro_rules! foreach_builtin_component_function {
205205
}
206206

207207
// Define `struct ComponentBuiltinFunctionIndex`
208-
declare_builtin_index!(
209-
ComponentBuiltinFunctionIndex,
210-
foreach_builtin_component_function
211-
);
208+
declare_builtin_index! {
209+
/// An index type for component builtin functions.
210+
pub struct ComponentBuiltinFunctionIndex: foreach_builtin_component_function;
211+
}

0 commit comments

Comments
 (0)