Skip to content

Commit 3c98d22

Browse files
committed
Fix a future-compat warning
``` warning[E0506]: cannot assign to `self.input.cached_token` because it is borrowed --> src/parser.rs:591:17 | 566 | pub fn next_including_whitespace_and_comments(&mut self) -> Result<&Token<'i>, BasicParseError<'i>> { | - let's call the lifetime of this reference `'1` ... 579 | Some(ref cached_token) | ---------------- borrow of `self.input.cached_token` occurs here ... 591 | self.input.cached_token = Some(CachedToken { | ^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `self.input.cached_token` occurs here ... 603 | Ok(token) | --------- returning this value requires that `self.input.cached_token.0` is borrowed for `'1` | = warning: this error has been downgraded to a warning for backwards compatibility with previous releases = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future ```
1 parent eef8622 commit 3c98d22

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/parser.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -587,30 +587,34 @@ impl<'i: 't, 't> Parser<'i, 't> {
587587
}
588588

589589
let token_start_position = self.input.tokenizer.position();
590-
let token;
591-
match self.input.cached_token {
592-
Some(ref cached_token) if cached_token.start_position == token_start_position => {
593-
self.input.tokenizer.reset(&cached_token.end_state);
594-
match cached_token.token {
595-
Token::Function(ref name) => self.input.tokenizer.see_function(name),
596-
_ => {}
597-
}
598-
token = &cached_token.token
599-
}
600-
_ => {
601-
let new_token = self
602-
.input
603-
.tokenizer
604-
.next()
605-
.map_err(|()| self.new_basic_error(BasicParseErrorKind::EndOfInput))?;
606-
self.input.cached_token = Some(CachedToken {
607-
token: new_token,
608-
start_position: token_start_position,
609-
end_state: self.input.tokenizer.state(),
610-
});
611-
token = self.input.cached_token_ref()
590+
let using_cached_token = self
591+
.input
592+
.cached_token
593+
.as_ref()
594+
.map_or(false, |cached_token| {
595+
cached_token.start_position == token_start_position
596+
});
597+
let token = if using_cached_token {
598+
let cached_token = self.input.cached_token.as_ref().unwrap();
599+
self.input.tokenizer.reset(&cached_token.end_state);
600+
match cached_token.token {
601+
Token::Function(ref name) => self.input.tokenizer.see_function(name),
602+
_ => {}
612603
}
613-
}
604+
&cached_token.token
605+
} else {
606+
let new_token = self
607+
.input
608+
.tokenizer
609+
.next()
610+
.map_err(|()| self.new_basic_error(BasicParseErrorKind::EndOfInput))?;
611+
self.input.cached_token = Some(CachedToken {
612+
token: new_token,
613+
start_position: token_start_position,
614+
end_state: self.input.tokenizer.state(),
615+
});
616+
self.input.cached_token_ref()
617+
};
614618

615619
if let Some(block_type) = BlockType::opening(token) {
616620
self.at_start_of = Some(block_type);

0 commit comments

Comments
 (0)