@@ -175,15 +175,12 @@ class RustMeta(ABC):
175175 pass
176176
177177
178- @dataclass # ASSERT: Immutable class
178+ @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
179179class RustAttribute :
180180 """Represents a Rust attribute (e.g., `#[derive(Debug)]`)."""
181181
182182 meta : RustMeta
183183
184- def __hash__ (self ) -> int :
185- return hash (self .meta )
186-
187184 def __str__ (self ) -> str :
188185 return f"#[{ str (self .meta )} ]"
189186
@@ -196,16 +193,13 @@ def __str__(self) -> str:
196193RustGenericsMut = MutableSequence [Union [RustLifetime , "RustPath" ]] # alias
197194
198195
199- @dataclass # ASSERT: Immutable class
196+ @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
200197class RustPathSegment :
201198 """Represents a segment in a Rust path with optional generics."""
202199
203200 ident : RustIdent
204201 generics : RustGenerics = dataclasses .field (default_factory = tuple )
205202
206- def __hash__ (self ) -> int :
207- return hash ((self .ident , self .generics ))
208-
209203 REX : ClassVar [Pattern [str ]] = re .compile (
210204 r"^([a-zA-Z_]\w*)(?:<([ \w\t,'<>]+)>)?$"
211205 ) # Using `re.Pattern[str]` raise CI build errors
@@ -262,17 +256,14 @@ def parse_generics_string(value_generics: str) -> RustGenerics:
262256RustPathSegmentsMut = MutableSequence [RustPathSegment ] # alias
263257
264258
265- @dataclass # ASSERT: Immutable class
259+ @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
266260class RustPath (RustMeta ):
267261 """Represents a complete Rust path (e.g., `::std::vec::Vec<T>`)."""
268262
269263 # ASSERT: Never initialized with an empty sequence
270264 segments : RustPathSegments
271265 leading_colon : bool = False
272266
273- def __hash__ (self ) -> int :
274- return hash ((self .segments , self .leading_colon ))
275-
276267 def __truediv__ (self , other : Union ["RustPath" , RustPathSegment ]) -> "RustPath" :
277268 if self .segments [- 1 ].generics :
278269 raise ValueError ("Cannot chain to a RustPath with generics." )
@@ -313,16 +304,13 @@ def from_str(cls, value: str) -> "RustPath":
313304 return cls (segments = tuple (segments ), leading_colon = leading_colon )
314305
315306
316- @dataclass # ASSERT: Immutable class
307+ @dataclass ( unsafe_hash = True ) # ASSERT: Immutable class
317308class RustTypeTuple (RustType ):
318309 """Represents a Rust tuple type (e.g., `(T, U)`)."""
319310
320311 # ASSERT: Never initialized with an empty sequence
321312 types : Sequence [RustPath ]
322313
323- def __hash__ (self ) -> int :
324- return hash (self .types )
325-
326314 def __str__ (self ) -> str :
327315 types_str = ", " .join (str (ty ) for ty in self .types )
328316 return f"({ types_str } )"
0 commit comments