You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a few places where we call peek() to check an upcoming token's kind, and then peek_data().unwrap() to check its value. For example, to identify what type of definition is coming up: type, union, or something else. This is an actual self-contained snippet showing what I mean:
The unwrap() call is valid in those cases, but a bit icky. For it to be valid, the current token must not change between those calls, and this is not statically verifiable. A mistake in a refactor could disconnect the peek() and peek_data() calls and then the unwrap could panic.
I'd like to see these refactored to use let Some(token) = peek_token() where possible, and then use token.kind / token.data directly, so there is no way that it could ever panic.
The text was updated successfully, but these errors were encountered:
We have a few places where we call
peek()
to check an upcoming token's kind, and thenpeek_data().unwrap()
to check its value. For example, to identify what type of definition is coming up:type
,union
, or something else. This is an actual self-contained snippet showing what I mean:apollo-rs/crates/apollo-parser/src/parser/grammar/object.rs
Lines 27 to 33 in 6c9adc4
The
unwrap()
call is valid in those cases, but a bit icky. For it to be valid, the current token must not change between those calls, and this is not statically verifiable. A mistake in a refactor could disconnect thepeek()
andpeek_data()
calls and then the unwrap could panic.I'd like to see these refactored to use
let Some(token) = peek_token()
where possible, and then usetoken.kind
/token.data
directly, so there is no way that it could ever panic.The text was updated successfully, but these errors were encountered: