diff options
| author | Michael Goulet <michael@errs.io> | 2024-04-03 21:47:02 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-04-15 16:45:01 -0400 |
| commit | fc9e344874ce718c951016ba29f7fcabb36f26c3 (patch) | |
| tree | 1cae9eb09014780dca10ad0bc019aa94bcae3847 /compiler/rustc_parse/src/parser | |
| parent | 647b672f16f6db2f156b69668ca963ec28016464 (diff) | |
| download | rust-fc9e344874ce718c951016ba29f7fcabb36f26c3.tar.gz rust-fc9e344874ce718c951016ba29f7fcabb36f26c3.zip | |
Use dedicated PreciseCapturingArg for representing what goes in use<>
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 5d6c4f39ae1..62f0602e1fa 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -1,4 +1,4 @@ -use super::{Parser, PathStyle, TokenType, Trailing}; +use super::{Parser, PathStyle, SeqSep, TokenType, Trailing}; use crate::errors::{ self, DynAfterMut, ExpectedFnPathFoundFnKeyword, ExpectedMutOrConstInRawPointerType, @@ -14,7 +14,7 @@ use rustc_ast::util::case::Case; use rustc_ast::{ self as ast, BareFnTy, BoundAsyncness, BoundConstness, BoundPolarity, FnRetTy, GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability, PolyTraitRef, - TraitBoundModifiers, TraitObjectSyntax, Ty, TyKind, DUMMY_NODE_ID, + PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty, TyKind, DUMMY_NODE_ID, }; use rustc_errors::{Applicability, PResult}; use rustc_span::symbol::{kw, sym, Ident}; @@ -671,13 +671,10 @@ impl<'a> Parser<'a> { // parse precise captures, if any. let precise_capturing = if self.eat_keyword(kw::Use) { - self.expect_lt()?; let use_span = self.prev_token.span; self.psess.gated_spans.gate(sym::precise_capturing, use_span); - let lo = self.token.span; - let args = self.parse_angle_args(None)?; - self.expect_gt()?; - Some(ast::AngleBracketedArgs { args, span: lo.to(self.prev_token.span) }.into()) + let args = self.parse_precise_capturing_args()?; + Some(args) } else { None }; @@ -690,6 +687,25 @@ impl<'a> Parser<'a> { Ok(TyKind::ImplTrait(ast::DUMMY_NODE_ID, bounds, precise_capturing)) } + fn parse_precise_capturing_args(&mut self) -> PResult<'a, ThinVec<PreciseCapturingArg>> { + Ok(self + .parse_unspanned_seq( + &TokenKind::Lt, + &TokenKind::Gt, + SeqSep::trailing_allowed(token::Comma), + |self_| { + if self_.check_ident() { + Ok(PreciseCapturingArg::Arg(self_.parse_ident().unwrap(), DUMMY_NODE_ID)) + } else if self_.check_lifetime() { + Ok(PreciseCapturingArg::Lifetime(self_.expect_lifetime())) + } else { + self_.unexpected_any() + } + }, + )? + .0) + } + /// Is a `dyn B0 + ... + Bn` type allowed here? fn is_explicit_dyn_type(&mut self) -> bool { self.check_keyword(kw::Dyn) |
