Skip to content

Commit

Permalink
Fix borrow check warning
Browse files Browse the repository at this point in the history
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 <rust-lang/rust#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](rust-lang/rust#59159).

Reviewed By: losvald

Differential Revision: D15759079

fbshipit-source-id: f5d067f32243abc75c7d2ac35709628ea34a48e9
  • Loading branch information
Wilfred authored and hhvm-bot committed Jun 12, 2019
1 parent 11f48fc commit a8c025e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hphp/hack/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a8c025e

Please sign in to comment.