mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-05 01:24:03 +00:00
Fix handling of weak keyword `pin` Part of https://github.com/rust-lang/rust/issues/130494. On main, we use `is_ident_named` to detect weak keyword `pin` which is incorrect since it doesn't account for whether the identifier in question is raw (`r#`) or not. Namely, `r#pin` should *never* be considered (yes, even if it's followed by the disambiguator `const` or `mut`). As it stands, (1) we accept more code than we should (2) we're prone to rightfully triggering internal assertions thus ICE'ing. Just use `is_keyword`&co which do those checks (indeed, it's also used for weak keywords). Furthermore, move `Symbol` `sym::pin` to `kw::Pin` and officially mark it as weak. This doesn't have any semantic effect, it's still a `Symbol`, but it's more conventional. For reference, on main we ICE with `assertion failed: self.eat_keyword(expr!(Pin))` on inputs like the following: * `type X = &r#pin const ();` (type) * `fn scope() { let _ = &r#pin mut (); }` (expr) * `fn scope() { let &r#pin const (); }` (pat) Moreover, on main we wrongfully accept code like `trait Trait { fn f(&r#pin mut self); }` (assuming the feature is enabled). <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>