feat(hir): Store the Span of the move keyword

This commit is contained in:
Dinu Blanovschi 2023-11-04 19:39:32 +01:00
parent f81d6f0cb0
commit 8de489918b
2 changed files with 8 additions and 2 deletions

View File

@ -1548,7 +1548,10 @@ pub struct QSelf {
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum CaptureBy {
/// `move |x| y + x`.
Value,
Value {
/// The span of the `move` keyword.
move_kw: Span,
},
/// `move` keyword was not specified.
Ref,
}

View File

@ -2303,13 +2303,16 @@ impl<'a> Parser<'a> {
/// Parses an optional `move` prefix to a closure-like construct.
fn parse_capture_clause(&mut self) -> PResult<'a, CaptureBy> {
if self.eat_keyword(kw::Move) {
let move_kw_span = self.prev_token.span;
// Check for `move async` and recover
if self.check_keyword(kw::Async) {
let move_async_span = self.token.span.with_lo(self.prev_token.span.data().lo);
Err(errors::AsyncMoveOrderIncorrect { span: move_async_span }
.into_diagnostic(&self.sess.span_diagnostic))
} else {
Ok(CaptureBy::Value)
Ok(CaptureBy::Value {
move_kw: move_kw_span,
})
}
} else {
Ok(CaptureBy::Ref)