Coverage Report

Created: 2026-10-28 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/oxc_index-5.0.0/src/macros.rs
Line
Count
Source
1
/// Generate the boilerplate for a newtyped index struct, for use with
2
/// `IndexVec`.
3
///
4
/// In the future, if the compile-time overhead of doing so is reduced, this may
5
/// be replaced with a proc macro.
6
///
7
/// ## Usage
8
///
9
/// ### Standard
10
///
11
/// The rough usage pattern of this macro is:
12
///
13
/// ```rust,no_run
14
/// oxc_index::define_index_type! {
15
///     // Note that isn't actually a type alias, `MyIndex` is
16
///     // actually defined as a struct. XXX is this too confusing?
17
///     pub struct MyIndex = u32;
18
///     // optional extra configuration here of the form:
19
///     // `OPTION_NAME = stuff;`
20
///     // See below for details.
21
/// }
22
/// ```
23
///
24
/// Note that you can use other index types than `u32`, and you can set it to be
25
/// `MyIndex(pub u32)` as well. Currently, the wrapped item be a tuple struct,
26
/// however (patches welcome).
27
///
28
/// ### Customization
29
///
30
/// After the struct declaration, there are a number of configuration options
31
/// the macro uses to customize how the type it generates behaves. For example:
32
///
33
/// ```rust,no_run
34
/// oxc_index::define_index_type! {
35
///     pub struct Span = u32;
36
///
37
///     // Don't allow any spans with values higher this.
38
///     MAX_INDEX = 0x7fff_ff00;
39
///
40
///     // But I also am not too worried about it, so only
41
///     // perform the asserts in debug builds.
42
///     DISABLE_MAX_INDEX_CHECK = cfg!(not(debug_assertions));
43
/// }
44
/// ```
45
///
46
/// ## Configuration options
47
///
48
/// This macro has a few ways you can customize it's output behavior. There's
49
/// not really any great syntax I can think of for them, but, well.
50
///
51
/// #### `MAX_INDEX = <expr producing usize>`
52
///
53
/// Assert if anything tries to construct an index above that value.
54
///
55
/// By default, this is `$raw_type::max_value() as usize`, e.g. we check that
56
/// our cast from `usize` to our wrapper is lossless, but we assume any all
57
/// instance of `$raw_type` is valid in this index domain.
58
///
59
/// Note that these tests can be disabled entirely, or conditionally, with
60
/// `DISABLE_MAX_INDEX_CHECK`. Additionally, the generated type has
61
/// `from_usize_unchecked` and `from_raw_unchecked` functions which can be used
62
/// to ignore these checks.
63
///
64
/// #### `DISABLE_MAX_INDEX_CHECK = <expr>;`
65
///
66
/// Set to true to disable the assertions mentioned above. False by default.
67
///
68
/// To be clear, if this is set to false, we blindly assume all casts between
69
/// `usize` and `$raw_type` succeed.
70
///
71
/// A common use is setting `DISABLE_MAX_INDEX_CHECK = !cfg!(debug_assertions)`
72
/// to avoid the tests at compile time
73
///
74
/// For the sake of clarity, disabling this cannot lead to memory unsafety -- we
75
/// still go through bounds checks when accessing slices, and no unsafe code
76
/// should rely on on these checks (unless you write some, and don't! only use
77
/// this for correctness!).
78
///
79
/// #### `DEFAULT = <expr>;`
80
/// If provided, we'll implement `Default` for the index type using this
81
/// expression.
82
///
83
/// Example:
84
///
85
/// ```rust,no_run
86
/// oxc_index::define_index_type! {
87
///     pub struct MyIdx = u16;
88
///     MAX_INDEX = (u16::max_value() - 1) as usize;
89
///     // Set the default index to be an invalid index, as
90
///     // a hacky way of having this type behave somewhat
91
///     // like it were an Option<MyIdx> without consuming
92
///     // extra space.
93
///     DEFAULT = (MyIdx::from_raw_unchecked(u16::max_value()));
94
/// }
95
/// ```
96
///
97
/// #### `DEBUG_FORMAT = <expr>;`
98
///
99
/// By default we write the underlying integer out in a Debug implementation
100
/// with `{:?}`. Sometimes you'd like more info though. For example, the type of
101
/// the index. This can be done via `DEBUG_FORMAT`:
102
///
103
/// ```rust
104
/// oxc_index::define_index_type! {
105
///     struct FooIdx = usize;
106
///     DEBUG_FORMAT = "Foo({})";
107
/// }
108
/// // Then ...
109
/// # fn main() {
110
/// let v = FooIdx::new(10);
111
/// assert_eq!("Foo(10)", format!("{:?}", v));
112
/// # }
113
/// ```
114
///
115
/// #### `DISPLAY_FORMAT = <expr>;`
116
///
117
/// Similarly to `DEBUG_FORMAT`, we can implement Display for you. Unlike
118
/// `DEBUG_FORMAT`, if you do not set this, we will not implement `Display` for
119
/// the index type.
120
///
121
/// ```rust
122
/// oxc_index::define_index_type! {
123
///     struct FooIdx = usize;
124
///     DISPLAY_FORMAT = "{}";
125
///     // Note that you can use both DEBUG_FORMAT and DISPLAY_FORMAT.
126
///     DEBUG_FORMAT = "#<foo {}>";
127
/// }
128
/// // Then ...
129
/// # fn main() {
130
/// let v = FooIdx::new(10);
131
/// assert_eq!("10", format!("{}", v));
132
/// assert_eq!("#<foo 10>", format!("{:?}", v));
133
/// # }
134
/// ```
135
///
136
/// #### `IMPL_RAW_CONVERSIONS = true;`
137
///
138
/// We always automatically implement `From<usize> for YourIndex` and
139
/// `From<YourIndex> for usize`. We don't do this for the "raw" type (e.g. `u32`
140
/// if your type is declared as `struct FooIdx = u32;`), unless you request it
141
/// via this option. It's an error to use this if your raw type is usize.
142
///
143
/// ```rust
144
/// oxc_index::define_index_type! {
145
///     struct FooIdx = u32;
146
///     IMPL_RAW_CONVERSIONS = true;
147
/// }
148
///
149
/// # fn main() {
150
/// let as_index = FooIdx::from(5u32);
151
/// let as_u32 = u32::from(as_index);
152
/// assert_eq!(as_u32, 5);
153
/// # }
154
/// ```
155
#[macro_export]
156
macro_rules! define_index_type {
157
    // public api for primitive types (u8, u16, u32, usize, etc.)
158
    (
159
        $(#[$attrs:meta])*
160
        $v:vis struct $type:ident = $raw:ident;
161
        $($CONFIG_NAME:ident = $value:expr_2021;)* $(;)?
162
    ) => {
163
        $crate::__define_index_type_inner!{
164
            @configs [$(($CONFIG_NAME; $value))*]
165
            @attrs [$(#[$attrs])*]
166
            @derives [#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]]
167
            @decl [$v struct $type ($raw)]
168
            @debug_fmt ["{}"]
169
            @max [(<$raw>::max_value() as usize)]
170
            @no_check_max [false]
171
        }
172
    };
173
    // public api for complex types (NonMaxU32, etc.) - requires explicit MAX_INDEX
174
    (
175
        $(#[$attrs:meta])*
176
        $v:vis struct $type:ident = $raw:ty;
177
        $($CONFIG_NAME:ident = $value:expr_2021;)+ $(;)?
178
    ) => {
179
        $crate::__define_index_type_inner!{
180
            @configs [$(($CONFIG_NAME; $value))*]
181
            @attrs [$(#[$attrs])*]
182
            @derives [#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]]
183
            @decl [$v struct $type ($raw)]
184
            @debug_fmt ["{}"]
185
            @max [(usize::MAX)]
186
            @no_check_max [false]
187
        }
188
    };
189
}
190
191
#[macro_export]
192
#[doc(hidden)]
193
macro_rules! unknown_define_index_type_option {
194
    () => {};
195
}
196
197
/// Generate the boilerplate for a newtyped index struct using NonMaxU32.
198
/// This is a specialized version of `define_index_type!` for use with `NonMaxU32` from the `nonmax` crate.
199
///
200
/// ## Usage
201
///
202
/// ```rust,ignore
203
/// oxc_index::define_nonmax_u32_index_type! {
204
///     pub struct MyIndex;
205
/// }
206
/// ```
207
///
208
/// This creates a tuple struct `pub struct MyIndex(NonMaxU32)` with all the necessary trait
209
/// implementations. The type is backed by `NonMaxU32`, which has the same size as `u32` but
210
/// can represent values from `0` to `u32::MAX - 1`.
211
///
212
/// ## Custom Attributes and Proc Macros
213
///
214
/// You can add custom attributes, including proc macros, to the generated struct:
215
///
216
/// ```rust,ignore
217
/// oxc_index::define_nonmax_u32_index_type! {
218
///     /// Documentation for MyIndex
219
///     #[ast]  // Proc macros work correctly
220
///     #[builder(default)]
221
///     #[allow(dead_code)]
222
///     pub struct MyIndex;
223
/// }
224
/// ```
225
///
226
/// **Attribute Ordering:** The macro applies attributes in this order:
227
/// 1. Built-in derives: `#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]`
228
/// 2. Your custom attributes (including proc macros)
229
///
230
/// This ordering ensures proc macros can properly process the struct with all standard derives already applied.
231
///
232
/// **Note:** The macro automatically provides:
233
/// - Derives: `Copy`, `Clone`, `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`
234
/// - Manual implementations: `Debug`, `From<usize>`, `From<MyIndex> for usize`, and arithmetic ops
235
///
236
/// Do not add `#[derive(Debug)]` or other conflicting derives/impls as they are already provided.
237
#[cfg(feature = "nonmax")]
238
#[macro_export]
239
macro_rules! define_nonmax_u32_index_type {
240
    (
241
        $(#[$attrs:meta])*
242
        $v:vis struct $type:ident;
243
        $($CONFIG_NAME:ident = $value:expr_2021;)* $(;)?
244
    ) => {
245
        #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
246
        $(#[$attrs])*
247
        $v struct $type($crate::nonmax::NonMaxU32);
248
249
        impl $type {
250
            /// The maximum representable index value.
251
            $v const MAX_INDEX: usize = (u32::MAX - 1) as usize;
252
253
            /// Whether this index type performs bounds checking.
254
            $v const CHECKS_MAX_INDEX: bool = true;
255
256
            /// Create a new index from a `usize` value.
257
            ///
258
            /// # Panics
259
            /// Panics if `value > MAX_INDEX`.
260
            #[inline(always)]
261
193M
            $v const fn new(value: usize) -> Self {
262
193M
                Self::from_usize(value)
263
193M
            }
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::new
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::new
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::new
<oxc_syntax::node::NodeId>::new
Line
Count
Source
261
193M
            $v const fn new(value: usize) -> Self {
262
193M
                Self::from_usize(value)
263
193M
            }
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::new
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::new
264
265
            /// Create an index from a raw `NonMaxU32` value.
266
            #[inline(always)]
267
0
            $v const fn from_raw(value: $crate::nonmax::NonMaxU32) -> Self {
268
0
                Self(value)
269
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::from_raw
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_raw
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::from_raw
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::from_raw
Unexecuted instantiation: <oxc_syntax::node::NodeId>::from_raw
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::from_raw
270
271
            /// Convert an index from another index type.
272
            #[inline(always)]
273
0
            $v fn from_foreign<F: $crate::Idx>(value: F) -> Self {
274
0
                Self::from_usize(value.index())
275
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::node::NodeId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::from_foreign::<_>
276
277
            /// Create an index from a `usize` without bounds checking.
278
            ///
279
            /// # SAFETY
280
            /// The caller must ensure `value < (u32::MAX as usize)`.
281
            #[inline(always)]
282
11.8M
            $v const unsafe fn from_usize_unchecked(value: usize) -> Self {
283
11.8M
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(value as u32) })
284
11.8M
            }
<oxc_syntax::symbol::SymbolId>::from_usize_unchecked
Line
Count
Source
282
2.71M
            $v const unsafe fn from_usize_unchecked(value: usize) -> Self {
283
2.71M
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(value as u32) })
284
2.71M
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::from_usize_unchecked
<oxc_syntax::scope::ScopeId>::from_usize_unchecked
Line
Count
Source
282
530k
            $v const unsafe fn from_usize_unchecked(value: usize) -> Self {
283
530k
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(value as u32) })
284
530k
            }
<oxc_syntax::reference::ReferenceId>::from_usize_unchecked
Line
Count
Source
282
550k
            $v const unsafe fn from_usize_unchecked(value: usize) -> Self {
283
550k
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(value as u32) })
284
550k
            }
<oxc_syntax::node::NodeId>::from_usize_unchecked
Line
Count
Source
282
8.07M
            $v const unsafe fn from_usize_unchecked(value: usize) -> Self {
283
8.07M
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(value as u32) })
284
8.07M
            }
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::from_usize_unchecked
285
286
            /// Create an index from a raw `u32` without bounds checking.
287
            ///
288
            /// # SAFETY
289
            /// The caller must ensure the value is not `u32::MAX`.
290
            #[inline(always)]
291
0
            $v const unsafe fn from_raw_unchecked(raw: u32) -> Self {
292
0
                Self(unsafe { $crate::nonmax::NonMaxU32::new_unchecked(raw) })
293
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::node::NodeId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::from_raw_unchecked
294
295
            /// Create an index from a `usize` with bounds checking.
296
            ///
297
            /// # Panics
298
            /// Panics if `value > MAX_INDEX`.
299
            #[inline]
300
193M
            $v const fn from_usize(value: usize) -> Self {
301
193M
                Self::check_index(value);
302
193M
                match $crate::nonmax::NonMaxU32::new(value as u32) {
303
193M
                    Some(raw) => Self(raw),
304
0
                    None => panic!("index_vec index overflow"),
305
                }
306
193M
            }
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_usize
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::from_usize
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_usize
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::from_usize
<oxc_syntax::node::NodeId>::from_usize
Line
Count
Source
300
3.92M
            $v const fn from_usize(value: usize) -> Self {
301
3.92M
                Self::check_index(value);
302
3.92M
                match $crate::nonmax::NonMaxU32::new(value as u32) {
303
3.92M
                    Some(raw) => Self(raw),
304
0
                    None => panic!("index_vec index overflow"),
305
                }
306
3.92M
            }
<oxc_syntax::node::NodeId>::from_usize
Line
Count
Source
300
190M
            $v const fn from_usize(value: usize) -> Self {
301
190M
                Self::check_index(value);
302
190M
                match $crate::nonmax::NonMaxU32::new(value as u32) {
303
190M
                    Some(raw) => Self(raw),
304
0
                    None => panic!("index_vec index overflow"),
305
                }
306
190M
            }
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::from_usize
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::from_usize
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::from_usize
Unexecuted instantiation: <oxc_syntax::node::NodeId>::from_usize
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::from_usize
307
308
            /// Get the index value as a `usize`.
309
            #[inline(always)]
310
18.1M
            $v const fn index(self) -> usize {
311
18.1M
                self.0.get() as usize
312
18.1M
            }
<oxc_syntax::symbol::SymbolId>::index
Line
Count
Source
310
6.13M
            $v const fn index(self) -> usize {
311
6.13M
                self.0.get() as usize
312
6.13M
            }
<oxc_syntax::scope::ScopeId>::index
Line
Count
Source
310
2.39M
            $v const fn index(self) -> usize {
311
2.39M
                self.0.get() as usize
312
2.39M
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::index
<oxc_syntax::reference::ReferenceId>::index
Line
Count
Source
310
4.19M
            $v const fn index(self) -> usize {
311
4.19M
                self.0.get() as usize
312
4.19M
            }
<oxc_syntax::node::NodeId>::index
Line
Count
Source
310
5.45M
            $v const fn index(self) -> usize {
311
5.45M
                self.0.get() as usize
312
5.45M
            }
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::index
313
314
            /// Get the raw `NonMaxU32` value.
315
            #[inline(always)]
316
0
            $v const fn raw(self) -> $crate::nonmax::NonMaxU32 {
317
0
                self.0
318
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::raw
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::raw
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::raw
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::raw
Unexecuted instantiation: <oxc_syntax::node::NodeId>::raw
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::raw
319
320
            #[doc(hidden)]
321
            #[inline]
322
193M
            $v const fn check_index(v: usize) {
323
193M
                if Self::CHECKS_MAX_INDEX && (v > Self::MAX_INDEX) {
324
0
                    panic!("index_vec index overflow");
325
193M
                }
326
193M
            }
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::check_index
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::check_index
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::check_index
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId>::check_index
<oxc_syntax::node::NodeId>::check_index
Line
Count
Source
322
3.92M
            $v const fn check_index(v: usize) {
323
3.92M
                if Self::CHECKS_MAX_INDEX && (v > Self::MAX_INDEX) {
324
0
                    panic!("index_vec index overflow");
325
3.92M
                }
326
3.92M
            }
<oxc_syntax::node::NodeId>::check_index
Line
Count
Source
322
190M
            $v const fn check_index(v: usize) {
323
190M
                if Self::CHECKS_MAX_INDEX && (v > Self::MAX_INDEX) {
324
0
                    panic!("index_vec index overflow");
325
190M
                }
326
190M
            }
Unexecuted instantiation: <oxc_syntax::scope::ScopeId>::check_index
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId>::check_index
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId>::check_index
Unexecuted instantiation: <oxc_syntax::node::NodeId>::check_index
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId>::check_index
327
        }
328
329
        impl core::fmt::Debug for $type {
330
0
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
331
0
                write!(f, "{}({})", stringify!($type), self.index())
332
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::fmt::Debug>::fmt
333
        }
334
335
        impl core::cmp::PartialOrd<usize> for $type {
336
            #[inline]
337
0
            fn partial_cmp(&self, other: &usize) -> Option<core::cmp::Ordering> {
338
0
                self.index().partial_cmp(other)
339
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::cmp::PartialOrd<usize>>::partial_cmp
340
        }
341
342
        impl core::cmp::PartialOrd<$type> for usize {
343
            #[inline]
344
0
            fn partial_cmp(&self, other: &$type) -> Option<core::cmp::Ordering> {
345
0
                self.partial_cmp(&other.index())
346
0
            }
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_codegen::sourcemap_builder::ColumnOffsetsId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::scope::ScopeId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::symbol::SymbolId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::reference::ReferenceId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::node::NodeId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::symbol::RedeclarationId>>::partial_cmp
347
        }
348
349
        impl PartialEq<usize> for $type {
350
            #[inline]
351
0
            fn eq(&self, other: &usize) -> bool {
352
0
                self.index() == *other
353
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::cmp::PartialEq<usize>>::eq
354
        }
355
356
        impl PartialEq<$type> for usize {
357
            #[inline]
358
0
            fn eq(&self, other: &$type) -> bool {
359
0
                *self == other.index()
360
0
            }
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_codegen::sourcemap_builder::ColumnOffsetsId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::scope::ScopeId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::symbol::SymbolId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::reference::ReferenceId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::node::NodeId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::symbol::RedeclarationId>>::eq
361
        }
362
363
        impl core::ops::Add<usize> for $type {
364
            type Output = Self;
365
            #[inline]
366
0
            fn add(self, other: usize) -> Self {
367
0
                Self::new(self.index().wrapping_add(other))
368
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::Add<usize>>::add
369
        }
370
371
        impl core::ops::Sub<usize> for $type {
372
            type Output = Self;
373
            #[inline]
374
0
            fn sub(self, other: usize) -> Self {
375
0
                Self::new(self.index().wrapping_sub(other))
376
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::Sub<usize>>::sub
377
        }
378
379
        impl core::ops::AddAssign<usize> for $type {
380
            #[inline]
381
0
            fn add_assign(&mut self, other: usize) {
382
0
                *self = *self + other
383
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::AddAssign<usize>>::add_assign
384
        }
385
386
        impl core::ops::SubAssign<usize> for $type {
387
            #[inline]
388
0
            fn sub_assign(&mut self, other: usize) {
389
0
                *self = *self - other;
390
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::SubAssign<usize>>::sub_assign
391
        }
392
393
        impl core::ops::Rem<usize> for $type {
394
            type Output = Self;
395
            #[inline]
396
0
            fn rem(self, other: usize) -> Self {
397
0
                Self::new(self.index() % other)
398
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::Rem<usize>>::rem
399
        }
400
401
        impl core::ops::Add<$type> for usize {
402
            type Output = $type;
403
            #[inline]
404
0
            fn add(self, other: $type) -> $type {
405
0
                other + self
406
0
            }
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_codegen::sourcemap_builder::ColumnOffsetsId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::symbol::RedeclarationId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::scope::ScopeId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::symbol::SymbolId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::reference::ReferenceId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::node::NodeId>>::add
407
        }
408
409
        impl core::ops::Sub<$type> for usize {
410
            type Output = $type;
411
            #[inline]
412
0
            fn sub(self, other: $type) -> $type {
413
0
                $type::new(self.wrapping_sub(other.index()))
414
0
            }
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_codegen::sourcemap_builder::ColumnOffsetsId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::symbol::RedeclarationId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::scope::ScopeId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::symbol::SymbolId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::reference::ReferenceId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::node::NodeId>>::sub
415
        }
416
417
        impl core::ops::Add for $type {
418
            type Output = $type;
419
            #[inline]
420
0
            fn add(self, other: $type) -> $type {
421
0
                $type::new(other.index() + self.index())
422
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::Add>::add
423
        }
424
425
        impl core::ops::Sub for $type {
426
            type Output = $type;
427
            #[inline]
428
0
            fn sub(self, other: $type) -> $type {
429
0
                $type::new(self.index().wrapping_sub(other.index()))
430
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::Sub>::sub
431
        }
432
433
        impl core::ops::AddAssign for $type {
434
            #[inline]
435
0
            fn add_assign(&mut self, other: $type) {
436
0
                *self = *self + other
437
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::AddAssign>::add_assign
438
        }
439
440
        impl core::ops::SubAssign for $type {
441
            #[inline]
442
0
            fn sub_assign(&mut self, other: $type) {
443
0
                *self = *self - other;
444
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::ops::arith::SubAssign>::sub_assign
445
        }
446
447
        impl $crate::Idx for $type {
448
            const MAX: usize = Self::MAX_INDEX;
449
450
            #[inline]
451
11.8M
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
11.8M
                unsafe { Self::from_usize_unchecked(idx) }
453
11.8M
            }
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as oxc_index::Idx>::from_usize_unchecked
<oxc_syntax::symbol::SymbolId as oxc_index::Idx>::from_usize_unchecked
Line
Count
Source
451
2.53M
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
2.53M
                unsafe { Self::from_usize_unchecked(idx) }
453
2.53M
            }
<oxc_syntax::scope::ScopeId as oxc_index::Idx>::from_usize_unchecked
Line
Count
Source
451
530k
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
530k
                unsafe { Self::from_usize_unchecked(idx) }
453
530k
            }
<oxc_syntax::symbol::SymbolId as oxc_index::Idx>::from_usize_unchecked
Line
Count
Source
451
181k
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
181k
                unsafe { Self::from_usize_unchecked(idx) }
453
181k
            }
<oxc_syntax::reference::ReferenceId as oxc_index::Idx>::from_usize_unchecked
Line
Count
Source
451
550k
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
550k
                unsafe { Self::from_usize_unchecked(idx) }
453
550k
            }
<oxc_syntax::node::NodeId as oxc_index::Idx>::from_usize_unchecked
Line
Count
Source
451
8.07M
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
452
8.07M
                unsafe { Self::from_usize_unchecked(idx) }
453
8.07M
            }
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::node::NodeId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::node::NodeId as oxc_index::Idx>::from_usize_unchecked
454
455
            #[inline]
456
15.1M
            fn index(self) -> usize {
457
15.1M
                usize::from(self)
458
15.1M
            }
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as oxc_index::Idx>::index
<oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Line
Count
Source
456
1.80M
            fn index(self) -> usize {
457
1.80M
                usize::from(self)
458
1.80M
            }
<oxc_syntax::scope::ScopeId as oxc_index::Idx>::index
Line
Count
Source
456
2.39M
            fn index(self) -> usize {
457
2.39M
                usize::from(self)
458
2.39M
            }
<oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Line
Count
Source
456
1.32M
            fn index(self) -> usize {
457
1.32M
                usize::from(self)
458
1.32M
            }
<oxc_syntax::reference::ReferenceId as oxc_index::Idx>::index
Line
Count
Source
456
4.19M
            fn index(self) -> usize {
457
4.19M
                usize::from(self)
458
4.19M
            }
<oxc_syntax::node::NodeId as oxc_index::Idx>::index
Line
Count
Source
456
5.45M
            fn index(self) -> usize {
457
5.45M
                usize::from(self)
458
5.45M
            }
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::node::NodeId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::node::NodeId as oxc_index::Idx>::index
459
        }
460
461
        impl From<$type> for usize {
462
            #[inline]
463
15.1M
            fn from(v: $type) -> usize {
464
15.1M
                v.index()
465
15.1M
            }
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::scope::ScopeId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::scope::ScopeId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_codegen::sourcemap_builder::ColumnOffsetsId>>::from
<usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Line
Count
Source
463
1.80M
            fn from(v: $type) -> usize {
464
1.80M
                v.index()
465
1.80M
            }
<usize as core::convert::From<oxc_syntax::scope::ScopeId>>::from
Line
Count
Source
463
2.39M
            fn from(v: $type) -> usize {
464
2.39M
                v.index()
465
2.39M
            }
<usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Line
Count
Source
463
1.32M
            fn from(v: $type) -> usize {
464
1.32M
                v.index()
465
1.32M
            }
<usize as core::convert::From<oxc_syntax::reference::ReferenceId>>::from
Line
Count
Source
463
4.19M
            fn from(v: $type) -> usize {
464
4.19M
                v.index()
465
4.19M
            }
<usize as core::convert::From<oxc_syntax::node::NodeId>>::from
Line
Count
Source
463
5.45M
            fn from(v: $type) -> usize {
464
5.45M
                v.index()
465
5.45M
            }
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::reference::ReferenceId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::node::NodeId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::scope::ScopeId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::symbol::RedeclarationId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::scope::ScopeId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::symbol::SymbolId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::reference::ReferenceId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::node::NodeId>>::from
466
        }
467
468
        impl From<usize> for $type {
469
            #[inline]
470
0
            fn from(value: usize) -> Self {
471
0
                $type::from_usize(value)
472
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::node::NodeId as core::convert::From<usize>>::from
473
        }
474
475
        $crate::__internal_maybe_index_impl_serde!($type);
476
    };
477
}
478
479
#[cfg(feature = "serde")]
480
#[macro_export]
481
#[doc(hidden)]
482
macro_rules! __internal_maybe_index_impl_serde {
483
    ($type:ident) => {
484
        impl $crate::serde::ser::Serialize for $type {
485
0
            fn serialize<S: $crate::serde::ser::Serializer>(
486
0
                &self,
487
0
                serializer: S,
488
0
            ) -> Result<S::Ok, S::Error> {
489
0
                self.index().serialize(serializer)
490
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::class::ElementId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::class::ClassId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as serde_core::ser::Serialize>::serialize::<_>
Unexecuted instantiation: <oxc_syntax::node::NodeId as serde_core::ser::Serialize>::serialize::<_>
491
        }
492
493
        impl<'de> $crate::serde::de::Deserialize<'de> for $type {
494
0
            fn deserialize<D: $crate::serde::de::Deserializer<'de>>(
495
0
                deserializer: D,
496
0
            ) -> Result<Self, D::Error> {
497
0
                usize::deserialize(deserializer).map(Self::from_usize)
498
0
            }
Unexecuted instantiation: <oxc_codegen::sourcemap_builder::ColumnOffsetsId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::symbol::RedeclarationId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::class::ElementId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::class::ClassId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::scope::ScopeId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::symbol::SymbolId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::reference::ReferenceId as serde_core::de::Deserialize>::deserialize::<_>
Unexecuted instantiation: <oxc_syntax::node::NodeId as serde_core::de::Deserialize>::deserialize::<_>
499
        }
500
    };
501
}
502
503
#[cfg(not(feature = "serde"))]
504
#[macro_export]
505
#[doc(hidden)]
506
macro_rules! __internal_maybe_index_impl_serde {
507
    ($type:ident) => {};
508
}
509
510
#[macro_export]
511
#[doc(hidden)]
512
macro_rules! __define_index_type_inner {
513
    // DISABLE_MAX_INDEX_CHECK
514
    (
515
        @configs [(DISABLE_MAX_INDEX_CHECK; $no_check_max:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
516
        @attrs [$(#[$attrs:meta])*]
517
        @derives [$(#[$derive:meta])*]
518
        @decl [$v:vis struct $type:ident ($raw:ty)]
519
        @debug_fmt [$dbg:expr_2021]
520
        @max [$max:expr_2021]
521
        @no_check_max [$_old_no_check_max:expr_2021]
522
    ) => {
523
        $crate::__define_index_type_inner!{
524
            @configs [$(($CONFIG_NAME; $value))*]
525
            @attrs [$(#[$attrs])*]
526
            @derives [$(#[$derive])*]
527
            @decl [$v struct $type ($raw)]
528
            @debug_fmt [$dbg]
529
            @max [$max]
530
            @no_check_max [$no_check_max]
531
        }
532
    };
533
534
    // MAX_INDEX
535
    (
536
        @configs [(MAX_INDEX; $new_max:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
537
        @attrs [$(#[$attrs:meta])*]
538
        @derives [$(#[$derive:meta])*]
539
        @decl [$v:vis struct $type:ident ($raw:ty)]
540
        @debug_fmt [$dbg:expr_2021]
541
        @max [$max:expr_2021]
542
        @no_check_max [$cm:expr_2021]
543
    ) => {
544
        $crate::__define_index_type_inner!{
545
            @configs [$(($CONFIG_NAME; $value))*]
546
            @attrs [$(#[$attrs])*]
547
            @derives [$(#[$derive])*]
548
            @decl [$v struct $type ($raw)]
549
            @debug_fmt [$dbg]
550
            @max [$new_max]
551
            @no_check_max [$cm]
552
        }
553
    };
554
555
    // DEFAULT
556
    (
557
        @configs [(DEFAULT; $default_expr:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
558
        @attrs [$(#[$attrs:meta])*]
559
        @derives [$(#[$derive:meta])*]
560
        @decl [$v:vis struct $type:ident ($raw:ty)]
561
        @debug_fmt [$dbg:expr_2021]
562
        @max [$max:expr_2021]
563
        @no_check_max [$no_check_max:expr_2021]
564
    ) => {
565
        $crate::__define_index_type_inner!{
566
            @configs [$(($CONFIG_NAME; $value))*]
567
            @attrs [$(#[$attrs])*]
568
            @derives [$(#[$derive])*]
569
            @decl [$v struct $type ($raw)]
570
            @debug_fmt [$dbg]
571
            @max [$max]
572
            @no_check_max [$no_check_max]
573
        }
574
        impl Default for $type {
575
            #[inline]
576
            fn default() -> Self {
577
                $default_expr
578
            }
579
        }
580
    };
581
582
    // DEBUG_FORMAT
583
    (
584
        @configs [(DEBUG_FORMAT; $dbg:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
585
        @attrs [$(#[$attrs:meta])*]
586
        @derives [$(#[$derive:meta])*]
587
        @decl [$v:vis struct $type:ident ($raw:ty)]
588
        @debug_fmt [$old_dbg:expr_2021]
589
        @max [$max:expr_2021]
590
        @no_check_max [$no_check_max:expr_2021]
591
    ) => {
592
        $crate::__define_index_type_inner!{
593
            @configs [$(($CONFIG_NAME; $value))*]
594
            @attrs [$(#[$attrs])*]
595
            @derives [$(#[$derive])*]
596
            @decl [$v struct $type ($raw)]
597
            @debug_fmt [$dbg]
598
            @max [$max]
599
            @no_check_max [$no_check_max]
600
        }
601
    };
602
603
    // DISPLAY_FORMAT
604
    (
605
        @configs [(DISPLAY_FORMAT; $format:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
606
        @attrs [$(#[$attrs:meta])*]
607
        @derives [$(#[$derive:meta])*]
608
        @decl [$v:vis struct $type:ident ($raw:ty)]
609
        @debug_fmt [$dbg:expr_2021]
610
        @max [$max:expr_2021]
611
        @no_check_max [$no_check_max:expr_2021]
612
    ) => {
613
        $crate::__define_index_type_inner!{
614
            @configs [$(($CONFIG_NAME; $value))*]
615
            @attrs [$(#[$attrs])*]
616
            @derives [$(#[$derive])*]
617
            @decl [$v struct $type ($raw)]
618
            @debug_fmt [$dbg]
619
            @max [$max]
620
            @no_check_max [$no_check_max]
621
        }
622
623
        impl core::fmt::Display for $type {
624
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
625
                write!(f, $format, self.index())
626
            }
627
        }
628
    };
629
630
    // IMPL_RAW_CONVERSIONS
631
    (
632
        @configs [(IMPL_RAW_CONVERSIONS; $val:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
633
        @attrs [$(#[$attrs:meta])*]
634
        @derives [$(#[$derive:meta])*]
635
        @decl [$v:vis struct $type:ident ($raw:ty)]
636
        @debug_fmt [$dbg:expr_2021]
637
        @max [$max:expr_2021]
638
        @no_check_max [$no_check_max:expr_2021]
639
    ) => {
640
        $crate::__define_index_type_inner!{
641
            @configs [$(($CONFIG_NAME; $value))*]
642
            @attrs [$(#[$attrs])*]
643
            @derives [$(#[$derive])*]
644
            @decl [$v struct $type ($raw)]
645
            @debug_fmt [$dbg]
646
            @max [$max]
647
            @no_check_max [$no_check_max]
648
        }
649
        // Ensure they passed in true. This is... cludgey.
650
        const _: [(); 1] = [(); $val as usize];
651
652
        impl From<$type> for $raw {
653
            #[inline]
654
            fn from(v: $type) -> $raw {
655
                v.raw()
656
            }
657
        }
658
659
        impl From<$raw> for $type {
660
            #[inline]
661
            fn from(value: $raw) -> Self {
662
                Self::from_raw(value)
663
            }
664
        }
665
    };
666
    // Try to make rust emit a decent error message...
667
    (
668
        @configs [($other:ident; $format:expr_2021) $(($CONFIG_NAME:ident; $value:expr_2021))*]
669
        @attrs [$(#[$attrs:meta])*]
670
        @derives [$(#[$derive:meta])*]
671
        @decl [$v:vis struct $type:ident ($raw:ty)]
672
        @debug_fmt [$dbg:expr_2021]
673
        @max [$max:expr_2021]
674
        @no_check_max [$no_check_max:expr_2021]
675
    ) => {
676
        $crate::unknown_define_index_type_option!($other);
677
    };
678
    // finish
679
    (
680
        @configs []
681
        @attrs [$(#[$attrs:meta])*]
682
        @derives [$(#[$derive:meta])*]
683
        @decl [$v:vis struct $type:ident ($raw:ty)]
684
        @debug_fmt [$dbg:expr_2021]
685
        @max [$max:expr_2021]
686
        @no_check_max [$no_check_max:expr_2021]
687
    ) => {
688
689
        $(#[$derive])*
690
        $(#[$attrs])*
691
        $v struct $type($raw);
692
693
        impl $type {
694
            /// If `Self::CHECKS_MAX_INDEX` is true, we'll assert if trying to
695
            /// produce a value larger than this in any of the ctors that don't
696
            /// have `unchecked` in their name.
697
            $v const MAX_INDEX: usize = $max;
698
699
            /// Does this index type assert if asked to construct an index
700
            /// larger than MAX_INDEX?
701
            $v const CHECKS_MAX_INDEX: bool = !$no_check_max;
702
703
            /// Construct this index type from a usize. Alias for `from_usize`.
704
            #[inline(always)]
705
0
            $v const fn new(value: usize) -> Self {
706
0
                Self::from_usize(value)
707
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::new
Unexecuted instantiation: <oxc_syntax::class::ElementId>::new
708
709
            /// Construct this index type from the wrapped integer type.
710
            #[inline(always)]
711
0
            $v const fn from_raw(value: $raw) -> Self {
712
0
                Self::from_usize(value as usize)
713
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_raw
Unexecuted instantiation: <oxc_syntax::class::ElementId>::from_raw
714
715
            /// Construct this index type from one in a different domain
716
            #[inline(always)]
717
0
            $v fn from_foreign<F: $crate::Idx>(value: F) -> Self {
718
0
                Self::from_usize(value.index())
719
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_foreign::<_>
Unexecuted instantiation: <oxc_syntax::class::ElementId>::from_foreign::<_>
720
721
            /// Construct from a usize without any checks.
722
            #[expect(clippy::cast_possible_truncation)]
723
            #[inline(always)]
724
0
            $v const fn from_usize_unchecked(value: usize) -> Self {
725
0
                Self(value as $raw)
726
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::class::ElementId>::from_usize_unchecked
727
728
            /// Construct from the underlying type without any checks.
729
            #[inline(always)]
730
0
            $v const fn from_raw_unchecked(raw: $raw) -> Self {
731
0
                Self(raw)
732
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_raw_unchecked
Unexecuted instantiation: <oxc_syntax::class::ElementId>::from_raw_unchecked
733
734
            /// Construct this index type from a usize.
735
            #[expect(clippy::cast_possible_truncation)]
736
            #[inline]
737
0
            $v const fn from_usize(value: usize) -> Self {
738
0
                Self::check_index(value as usize);
739
0
                Self(value as $raw)
740
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_usize
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_usize
Unexecuted instantiation: <oxc_syntax::class::ClassId>::from_usize
Unexecuted instantiation: <oxc_syntax::class::ElementId>::from_usize
741
742
            /// Get the wrapped index as a usize.
743
            #[inline(always)]
744
0
            $v const fn index(self) -> usize {
745
0
                self.0 as usize
746
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::index
Unexecuted instantiation: <oxc_syntax::class::ElementId>::index
747
748
            /// Get the wrapped index.
749
            #[inline(always)]
750
0
            $v const fn raw(self) -> $raw {
751
0
                self.0
752
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::raw
Unexecuted instantiation: <oxc_syntax::class::ElementId>::raw
753
754
            #[doc(hidden)]
755
            #[inline]
756
0
            $v const fn check_index(v: usize) {
757
0
                if Self::CHECKS_MAX_INDEX && (v > Self::MAX_INDEX) {
758
0
                    panic!("index_vec index overflow");
759
0
                }
760
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId>::check_index
Unexecuted instantiation: <oxc_syntax::class::ClassId>::check_index
Unexecuted instantiation: <oxc_syntax::class::ClassId>::check_index
Unexecuted instantiation: <oxc_syntax::class::ElementId>::check_index
761
        }
762
763
        impl core::fmt::Debug for $type {
764
0
            fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
765
0
                write!(f, $dbg, self.index())
766
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::fmt::Debug>::fmt
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::fmt::Debug>::fmt
767
        }
768
769
        impl core::cmp::PartialOrd<usize> for $type {
770
            #[inline]
771
0
            fn partial_cmp(&self, other: &usize) -> Option<core::cmp::Ordering> {
772
0
                self.index().partial_cmp(other)
773
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::cmp::PartialOrd<usize>>::partial_cmp
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::cmp::PartialOrd<usize>>::partial_cmp
774
        }
775
776
        impl core::cmp::PartialOrd<$type> for usize {
777
            #[inline]
778
0
            fn partial_cmp(&self, other: &$type) -> Option<core::cmp::Ordering> {
779
0
                self.partial_cmp(&other.index())
780
0
            }
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::class::ClassId>>::partial_cmp
Unexecuted instantiation: <usize as core::cmp::PartialOrd<oxc_syntax::class::ElementId>>::partial_cmp
781
        }
782
783
        impl PartialEq<usize> for $type {
784
            #[inline]
785
0
            fn eq(&self, other: &usize) -> bool {
786
0
                self.index() == *other
787
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::cmp::PartialEq<usize>>::eq
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::cmp::PartialEq<usize>>::eq
788
        }
789
790
        impl PartialEq<$type> for usize {
791
            #[inline]
792
0
            fn eq(&self, other: &$type) -> bool {
793
0
                *self == other.index()
794
0
            }
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::class::ClassId>>::eq
Unexecuted instantiation: <usize as core::cmp::PartialEq<oxc_syntax::class::ElementId>>::eq
795
        }
796
797
        impl core::ops::Add<usize> for $type {
798
            type Output = Self;
799
            #[inline]
800
0
            fn add(self, other: usize) -> Self {
801
                // use wrapping add so that it's up to the index type whether or
802
                // not to check -- e.g. if checks are disabled, they're disabled
803
                // on both debug and release.
804
0
                Self::new(self.index().wrapping_add(other))
805
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::Add<usize>>::add
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::Add<usize>>::add
806
        }
807
808
        impl core::ops::Sub<usize> for $type {
809
            type Output = Self;
810
            #[inline]
811
0
            fn sub(self, other: usize) -> Self {
812
                // use wrapping sub so that it's up to the index type whether or
813
                // not to check -- e.g. if checks are disabled, they're disabled
814
                // on both debug and release.
815
0
                Self::new(self.index().wrapping_sub(other))
816
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::Sub<usize>>::sub
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::Sub<usize>>::sub
817
        }
818
819
        impl core::ops::AddAssign<usize> for $type {
820
            #[inline]
821
0
            fn add_assign(&mut self, other: usize) {
822
0
                *self = *self + other
823
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::AddAssign<usize>>::add_assign
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::AddAssign<usize>>::add_assign
824
        }
825
826
        impl core::ops::SubAssign<usize> for $type {
827
            #[inline]
828
0
            fn sub_assign(&mut self, other: usize) {
829
0
                *self = *self - other;
830
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::SubAssign<usize>>::sub_assign
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::SubAssign<usize>>::sub_assign
831
        }
832
833
        impl core::ops::Rem<usize> for $type {
834
            type Output = Self;
835
            #[inline]
836
0
            fn rem(self, other: usize) -> Self {
837
0
                Self::new(self.index() % other)
838
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::Rem<usize>>::rem
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::Rem<usize>>::rem
839
        }
840
841
        impl core::ops::Add<$type> for usize {
842
            type Output = $type;
843
            #[inline]
844
0
            fn add(self, other: $type) -> $type {
845
0
                other + self
846
0
            }
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::class::ElementId>>::add
Unexecuted instantiation: <usize as core::ops::arith::Add<oxc_syntax::class::ClassId>>::add
847
        }
848
849
        impl core::ops::Sub<$type> for usize {
850
            type Output = $type;
851
            #[inline]
852
0
            fn sub(self, other: $type) -> $type {
853
0
                $type::new(self.wrapping_sub(other.index()))
854
0
            }
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::class::ElementId>>::sub
Unexecuted instantiation: <usize as core::ops::arith::Sub<oxc_syntax::class::ClassId>>::sub
855
        }
856
857
        impl core::ops::Add for $type {
858
            type Output = $type;
859
            #[inline]
860
0
            fn add(self, other: $type) -> $type {
861
0
                $type::new(other.index() + self.index())
862
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::Add>::add
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::Add>::add
863
        }
864
865
        impl core::ops::Sub for $type {
866
            type Output = $type;
867
            #[inline]
868
0
            fn sub(self, other: $type) -> $type {
869
0
                $type::new(self.index().wrapping_sub(other.index()))
870
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::Sub>::sub
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::Sub>::sub
871
        }
872
873
        impl core::ops::AddAssign for $type {
874
            #[inline]
875
0
            fn add_assign(&mut self, other: $type) {
876
0
                *self = *self + other
877
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::AddAssign>::add_assign
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::AddAssign>::add_assign
878
        }
879
880
        impl core::ops::SubAssign for $type {
881
            #[inline]
882
0
            fn sub_assign(&mut self, other: $type) {
883
0
                *self = *self - other;
884
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::ops::arith::SubAssign>::sub_assign
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::ops::arith::SubAssign>::sub_assign
885
        }
886
887
        impl $crate::Idx for $type {
888
            const MAX: usize = Self::MAX_INDEX;
889
890
            #[inline]
891
0
            unsafe fn from_usize_unchecked(idx: usize) -> Self {
892
0
                Self::from_usize_unchecked(idx)
893
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::class::ClassId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::class::ElementId as oxc_index::Idx>::from_usize_unchecked
Unexecuted instantiation: <oxc_syntax::class::ClassId as oxc_index::Idx>::from_usize_unchecked
894
895
            #[inline]
896
0
            fn index(self) -> usize {
897
0
                usize::from(self)
898
0
            }
Unexecuted instantiation: <oxc_syntax::class::ClassId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::class::ElementId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::class::ClassId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::class::ElementId as oxc_index::Idx>::index
Unexecuted instantiation: <oxc_syntax::class::ClassId as oxc_index::Idx>::index
899
        }
900
901
        impl From<$type> for usize {
902
            #[inline]
903
0
            fn from(v: $type) -> usize {
904
0
                v.index()
905
0
            }
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::class::ClassId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::class::ElementId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::class::ClassId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::class::ElementId>>::from
Unexecuted instantiation: <usize as core::convert::From<oxc_syntax::class::ClassId>>::from
906
        }
907
908
        impl From<usize> for $type {
909
            #[inline]
910
0
            fn from(value: usize) -> Self {
911
0
                $type::from_usize(value)
912
0
            }
Unexecuted instantiation: <oxc_syntax::class::ElementId as core::convert::From<usize>>::from
Unexecuted instantiation: <oxc_syntax::class::ClassId as core::convert::From<usize>>::from
913
        }
914
915
        $crate::__internal_maybe_index_impl_serde!($type);
916
    };
917
}