Skip to content

Commit 6347abb

Browse files
bors[bot]lqd
andauthored
Merge #154
154: Work around an eager clippy warning r=nikomatsakis a=lqd As seen in #152 (comment) and #153 (comment), it seems a recent nightly has introduced a false positive in the `needless_match` lint, causing CI to fail as it denies warnings. Just for reference, it looks side-effects in branches are missed, and thought to be replaceable by the matched Option. ```rust pub fn side_effect() -> Option<String> { if let Some(r) = op() { Some(r) } else { println!("side-effect"); None } } ``` We could ignore the lint, much like other lints are sometimes ignored, or work around it like this PR. Which do you prefer ? Co-authored-by: Rémy Rakic <[email protected]>
2 parents df7d88d + f3c6134 commit 6347abb

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

components/dada-parse/src/parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ impl<'me> Parser<'me> {
4848

4949
/// Run `op` -- if it returns `None`, then no tokens are consumed.
5050
/// If it returns `Some`, then the tokens are consumed.
51-
/// use sparingly, and try not to report errors or have side-effects in `op`.
51+
/// Use sparingly, and try not to report errors or have side-effects in `op`.
5252
fn lookahead<R>(&mut self, op: impl FnOnce(&mut Self) -> Option<R>) -> Option<R> {
5353
let tokens = self.tokens;
54-
if let Some(r) = op(self) {
55-
Some(r)
56-
} else {
54+
let r = op(self);
55+
if r.is_none() {
56+
// Restore tokens that `op` may have consumed.
5757
self.tokens = tokens;
58-
None
5958
}
59+
r
6060
}
6161

6262
/// Peek ahead to see if `op` matches the next set of tokens;

0 commit comments

Comments
 (0)