diff options
| author | bors <bors@rust-lang.org> | 2025-03-06 23:39:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-03-06 23:39:38 +0000 |
| commit | 98a48781feb1220c0cf2feea23f9ef92cdfa7437 (patch) | |
| tree | 81bce0037094da6e658bb51e00f5ef929e3e6361 /compiler/rustc_parse/src/parser | |
| parent | b74da9613a8cb5ba67a985f71325be0b7b16c0dd (diff) | |
| parent | 071bc4688076e6d18cbba3778af2e171dbf8f4c1 (diff) | |
| download | rust-98a48781feb1220c0cf2feea23f9ef92cdfa7437.tar.gz rust-98a48781feb1220c0cf2feea23f9ef92cdfa7437.zip | |
Auto merge of #138114 - compiler-errors:rollup-7xr4b69, r=compiler-errors
Rollup of 25 pull requests Successful merges: - #135733 (Implement `&pin const self` and `&pin mut self` sugars) - #135895 (Document workings of successors more clearly) - #136922 (Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR) - #137303 (Remove `MaybeForgetReturn` suggestion) - #137327 (Undeprecate env::home_dir) - #137358 (Match Ergonomics 2024: add context and examples to the unstable book) - #137534 ([rustdoc] hide item that is not marked as doc(inline) and whose src is doc(hidden)) - #137565 (Try to point of macro expansion from resolver and method errors if it involves macro var) - #137637 (Check dyn flavor before registering upcast goal on wide pointer cast in MIR typeck) - #137643 (Add DWARF test case for non-C-like `repr128` enums) - #137744 (Re-add `Clone`-derive on `Thir`) - #137758 (fix usage of ty decl macro fragments in attributes) - #137764 (Ensure that negative auto impls are always applicable) - #137772 (Fix char count in `Display` for `ByteStr`) - #137798 (ci: use ubuntu 24 on arm large runner) - #137802 (miri native-call support: all previously exposed provenance is accessible to the callee) - #137805 (adjust Layout debug printing to match the internal field name) - #137808 (Do not require that unsafe fields lack drop glue) - #137820 (Clarify why InhabitedPredicate::instantiate_opt exists) - #137825 (Provide more context on resolve error caused from incorrect RTN) - #137834 (rustc_fluent_macro: use CARGO_CRATE_NAME instead of CARGO_PKG_NAME) - #137868 (Add minimal platform support documentation for powerpc-unknown-linux-gnuspe) - #137910 (Improve error message for `AsyncFn` trait failure for RPIT) - #137920 (interpret/provenance_map: consistently use range_is_empty) - #138038 (Update `compiler-builtins` to 0.1.151) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 3f642a7ac1f..c3b1956ad2e 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -2954,14 +2954,27 @@ impl<'a> Parser<'a> { } _ => unreachable!(), }; + // is lifetime `n` tokens ahead? + let is_lifetime = |this: &Self, n| this.look_ahead(n, |t| t.is_lifetime()); // Is `self` `n` tokens ahead? let is_isolated_self = |this: &Self, n| { this.is_keyword_ahead(n, &[kw::SelfLower]) && this.look_ahead(n + 1, |t| t != &token::PathSep) }; + // Is `pin const self` `n` tokens ahead? + let is_isolated_pin_const_self = |this: &Self, n| { + this.look_ahead(n, |token| token.is_ident_named(sym::pin)) + && this.is_keyword_ahead(n + 1, &[kw::Const]) + && is_isolated_self(this, n + 2) + }; // Is `mut self` `n` tokens ahead? let is_isolated_mut_self = |this: &Self, n| this.is_keyword_ahead(n, &[kw::Mut]) && is_isolated_self(this, n + 1); + // Is `pin mut self` `n` tokens ahead? + let is_isolated_pin_mut_self = |this: &Self, n| { + this.look_ahead(n, |token| token.is_ident_named(sym::pin)) + && is_isolated_mut_self(this, n + 1) + }; // Parse `self` or `self: TYPE`. We already know the current token is `self`. let parse_self_possibly_typed = |this: &mut Self, m| { let eself_ident = expect_self_ident(this); @@ -3012,26 +3025,35 @@ impl<'a> Parser<'a> { let eself_lo = self.token.span; let (eself, eself_ident, eself_hi) = match self.token.uninterpolate().kind { token::And => { - let eself = if is_isolated_self(self, 1) { - // `&self` - self.bump(); - SelfKind::Region(None, Mutability::Not) - } else if is_isolated_mut_self(self, 1) { - // `&mut self` - self.bump(); - self.bump(); - SelfKind::Region(None, Mutability::Mut) - } else if self.look_ahead(1, |t| t.is_lifetime()) && is_isolated_self(self, 2) { - // `&'lt self` - self.bump(); - let lt = self.expect_lifetime(); - SelfKind::Region(Some(lt), Mutability::Not) - } else if self.look_ahead(1, |t| t.is_lifetime()) && is_isolated_mut_self(self, 2) { - // `&'lt mut self` - self.bump(); - let lt = self.expect_lifetime(); - self.bump(); - SelfKind::Region(Some(lt), Mutability::Mut) + let has_lifetime = is_lifetime(self, 1); + let skip_lifetime_count = has_lifetime as usize; + let eself = if is_isolated_self(self, skip_lifetime_count + 1) { + // `&{'lt} self` + self.bump(); // & + let lifetime = has_lifetime.then(|| self.expect_lifetime()); + SelfKind::Region(lifetime, Mutability::Not) + } else if is_isolated_mut_self(self, skip_lifetime_count + 1) { + // `&{'lt} mut self` + self.bump(); // & + let lifetime = has_lifetime.then(|| self.expect_lifetime()); + self.bump(); // mut + SelfKind::Region(lifetime, Mutability::Mut) + } else if is_isolated_pin_const_self(self, skip_lifetime_count + 1) { + // `&{'lt} pin const self` + self.bump(); // & + let lifetime = has_lifetime.then(|| self.expect_lifetime()); + self.psess.gated_spans.gate(sym::pin_ergonomics, self.token.span); + self.bump(); // pin + self.bump(); // const + SelfKind::Pinned(lifetime, Mutability::Not) + } else if is_isolated_pin_mut_self(self, skip_lifetime_count + 1) { + // `&{'lt} pin mut self` + self.bump(); // & + let lifetime = has_lifetime.then(|| self.expect_lifetime()); + self.psess.gated_spans.gate(sym::pin_ergonomics, self.token.span); + self.bump(); // pin + self.bump(); // mut + SelfKind::Pinned(lifetime, Mutability::Mut) } else { // `¬_self` return Ok(None); |
