From a8c025eed587569b323df5b9b485738c61357018 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Wed, 12 Jun 2019 03:08:38 -0700 Subject: [PATCH] Fix borrow check warning Summary: Previously we had the following warning: ``` warning: cannot borrow `*self` as mutable because it is also borrowed as immutable --> hphp/hack/src/parser/lexer.rs:1956:25 | 1946 | let original_text = self.current_text_as_str(); // | ---- immutable borrow occurs here ... 1956 | self.with_error(Errors::uppercase_kw(original_text)); | ^^^^ mutable borrow occurs here ------------- immutable borrow later used here | = note: #[warn(mutable_borrow_reservation_conflict)] on by default = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future = note: for more information, see issue #59159 ``` Refactor the code so that the scope of `original_text` doesn't extend to `self.with_error`. This is consistent with the vector example given in [Rust issue #59159](https://github.com/rust-lang/rust/issues/59159). Reviewed By: losvald Differential Revision: D15759079 fbshipit-source-id: f5d067f32243abc75c7d2ac35709628ea34a48e9 --- hphp/hack/src/parser/lexer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hphp/hack/src/parser/lexer.rs b/hphp/hack/src/parser/lexer.rs index f9ff990a379c01..9a0597682cff25 100644 --- a/hphp/hack/src/parser/lexer.rs +++ b/hphp/hack/src/parser/lexer.rs @@ -1952,7 +1952,8 @@ impl<'a, Token: LexableToken> Lexer<'a, Token> { Some(TokenKind::Let) if (!(self.is_experimental_mode())) => TokenKind::Name, Some(keyword) => { if self.lowercase_error(original_text, &text) { - self.with_error(Errors::uppercase_kw(original_text)); + let err = Errors::uppercase_kw(original_text); + self.with_error(err); } keyword }