diff options
| author | Sarthak Singh <ss269@uw.edu> | 2022-11-09 20:39:28 +0530 |
|---|---|---|
| committer | Sarthak Singh <ss269@uw.edu> | 2022-11-28 14:09:00 +0530 |
| commit | 8f705e2425ff459566cd1da0f2c79060fdad9091 (patch) | |
| tree | a89e14443b862c7334dfbaa63f8c2fb9147f4894 /compiler/rustc_parse/src/parser/expr.rs | |
| parent | 872631d0f0fadffe3220ab1bd9c8f1f2342341e2 (diff) | |
| download | rust-8f705e2425ff459566cd1da0f2c79060fdad9091.tar.gz rust-8f705e2425ff459566cd1da0f2c79060fdad9091.zip | |
Keep track of the start of the argument block of a closure
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index dc914f5ea64..a76f0f46716 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2057,7 +2057,7 @@ impl<'a> Parser<'a> { }; let capture_clause = self.parse_capture_clause()?; - let fn_decl = self.parse_fn_block_decl()?; + let (fn_decl, fn_arg_span) = self.parse_fn_block_decl()?; let decl_hi = self.prev_token.span; let mut body = match fn_decl.output { FnRetTy::Default(_) => { @@ -2098,6 +2098,7 @@ impl<'a> Parser<'a> { fn_decl, body, fn_decl_span: lo.to(decl_hi), + fn_arg_span, })), ); @@ -2126,7 +2127,9 @@ impl<'a> Parser<'a> { } /// Parses the `|arg, arg|` header of a closure. - fn parse_fn_block_decl(&mut self) -> PResult<'a, P<FnDecl>> { + fn parse_fn_block_decl(&mut self) -> PResult<'a, (P<FnDecl>, Span)> { + let arg_start = self.token.span.lo(); + let inputs = if self.eat(&token::OrOr) { Vec::new() } else { @@ -2142,10 +2145,11 @@ impl<'a> Parser<'a> { self.expect_or()?; args }; + let arg_span = self.prev_token.span.with_lo(arg_start); let output = self.parse_ret_ty(AllowPlus::Yes, RecoverQPath::Yes, RecoverReturnSign::Yes)?; - Ok(P(FnDecl { inputs, output })) + Ok((P(FnDecl { inputs, output }), arg_span)) } /// Parses a parameter in a closure header (e.g., `|arg, arg|`). |
