@@ -203,11 +203,13 @@ fn analyze_program(
203203 diagnostics
204204}
205205
206- /// `__TupleN` (N digits) is the synthetic tuple struct injected by the tuple
207- /// desugar, not a user declaration, so it is exempt from the reserved-name rule.
208- fn is_synthetic_tuple_name ( name : & str ) -> bool {
209- name. strip_prefix ( "__Tuple" )
210- . is_some_and ( |n| !n. is_empty ( ) && n. bytes ( ) . all ( |b| b. is_ascii_digit ( ) ) )
206+ /// Namespaces that the compiler generates and a user declaration must not claim:
207+ /// desugaring temporaries (`__rss_*`) and runtime helpers (`__rsscript_*`). Other
208+ /// `__`-prefixed names (Python-style dunders like `__hash__`, `__eq__`, and the
209+ /// synthetic `__TupleN` structs the tuple desugar injects) are legal — they don't
210+ /// collide with any generated namespace.
211+ fn is_reserved_generated_name ( leaf : & str ) -> bool {
212+ leaf. starts_with ( "__rss_" ) || leaf. starts_with ( "__rsscript_" )
211213}
212214
213215fn type_aliases_from_program (
@@ -1257,11 +1259,11 @@ impl Analyzer<'_> {
12571259 }
12581260 }
12591261
1260- /// Identifiers beginning with `__` are reserved for compiler-generated
1261- /// symbols (tuple structs `__TupleN`, desugaring temporaries `__rss_*`,
1262- /// runtime helpers `__rsscript_*`). Reject user declarations that claim a
1263- /// reserved name so generated helpers can never collide with source symbols.
1264- /// The synthetic `__TupleN` structs the tuple desugar injects are exempt .
1262+ /// The `__rss_*` and `__rsscript_*` namespaces are reserved for
1263+ /// compiler-generated desugaring temporaries and runtime helpers. Reject user
1264+ /// declarations that claim one so generated helpers can never collide with
1265+ /// source symbols. Other `__`-prefixed names (Python-style dunders like
1266+ /// `__hash__`, and the synthetic `__TupleN` tuple structs) are left legal .
12651267 fn check_reserved_declaration_names ( & mut self ) {
12661268 use crate :: syntax:: ast:: Item ;
12671269 for item in self . syntax_program . items . clone ( ) {
@@ -1275,11 +1277,11 @@ impl Analyzer<'_> {
12751277 } ;
12761278 // `Type.method` reserves on the member, not the (user) type prefix.
12771279 let leaf = name. rsplit ( '.' ) . next ( ) . unwrap_or ( name) ;
1278- if leaf . starts_with ( "__" ) && ! is_synthetic_tuple_name ( leaf) {
1280+ if is_reserved_generated_name ( leaf) {
12791281 self . unsupported_syntax (
12801282 span. clone ( ) ,
12811283 "reserved declaration name" ,
1282- "Identifiers beginning with `__` are reserved for compiler-generated symbols; rename this declaration." ,
1284+ "The `__rss_` and `__rsscript_` prefixes are reserved for compiler-generated symbols; rename this declaration." ,
12831285 ) ;
12841286 }
12851287 }
0 commit comments