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