@@ -175,12 +175,15 @@ class RustMeta(ABC):
175
175
pass
176
176
177
177
178
- @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
178
+ @dataclass # ASSERT: Immutable class
179
179
class RustAttribute :
180
180
"""Represents a Rust attribute (e.g., `#[derive(Debug)]`)."""
181
181
182
182
meta : RustMeta
183
183
184
+ def __hash__ (self ) -> int :
185
+ return hash (self .meta )
186
+
184
187
def __str__ (self ) -> str :
185
188
return f"#[{ str (self .meta )} ]"
186
189
@@ -193,13 +196,16 @@ def __str__(self) -> str:
193
196
RustGenericsMut = MutableSequence [Union [RustLifetime , "RustPath" ]] # alias
194
197
195
198
196
- @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
199
+ @dataclass # ASSERT: Immutable class
197
200
class RustPathSegment :
198
201
"""Represents a segment in a Rust path with optional generics."""
199
202
200
203
ident : RustIdent
201
204
generics : RustGenerics = dataclasses .field (default_factory = tuple )
202
205
206
+ def __hash__ (self ) -> int :
207
+ return hash ((self .ident , self .generics ))
208
+
203
209
REX : ClassVar [Pattern [str ]] = re .compile (
204
210
r"^([a-zA-Z_]\w*)(?:<([ \w\t,'<>]+)>)?$"
205
211
) # Using `re.Pattern[str]` raise CI build errors
@@ -256,14 +262,17 @@ def parse_generics_string(value_generics: str) -> RustGenerics:
256
262
RustPathSegmentsMut = MutableSequence [RustPathSegment ] # alias
257
263
258
264
259
- @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
265
+ @dataclass # ASSERT: Immutable class
260
266
class RustPath (RustMeta ):
261
267
"""Represents a complete Rust path (e.g., `::std::vec::Vec<T>`)."""
262
268
263
269
# ASSERT: Never initialized with an empty sequence
264
270
segments : RustPathSegments
265
271
leading_colon : bool = False
266
272
273
+ def __hash__ (self ) -> int :
274
+ return hash ((self .segments , self .leading_colon ))
275
+
267
276
def __truediv__ (self , other : Union ["RustPath" , RustPathSegment ]) -> "RustPath" :
268
277
if self .segments [- 1 ].generics :
269
278
raise ValueError ("Cannot chain to a RustPath with generics." )
@@ -304,13 +313,16 @@ def from_str(cls, value: str) -> "RustPath":
304
313
return cls (segments = tuple (segments ), leading_colon = leading_colon )
305
314
306
315
307
- @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
316
+ @dataclass # ASSERT: Immutable class
308
317
class RustTypeTuple (RustType ):
309
318
"""Represents a Rust tuple type (e.g., `(T, U)`)."""
310
319
311
320
# ASSERT: Never initialized with an empty sequence
312
321
types : Sequence [RustPath ]
313
322
323
+ def __hash__ (self ) -> int :
324
+ return hash (self .types )
325
+
314
326
def __str__ (self ) -> str :
315
327
types_str = ", " .join (str (ty ) for ty in self .types )
316
328
return f"({ types_str } )"
0 commit comments