From 28050116d3eeb09567c93be14d76089973d8a2d4 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 19 Jan 2020 01:01:02 -0500 Subject: [PATCH] Prefer `match` over `if let` --- src/main.rs | 18 +++++++----------- src/mixin.rs | 34 +++++++++++++++++----------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main.rs b/src/main.rs index c060452..21cd850 100644 --- a/src/main.rs +++ b/src/main.rs @@ -507,10 +507,9 @@ pub(crate) fn eat_expr>( let tok = toks .next() .expect("this must exist because we have already peeked"); - let name = if let TokenKind::Variable(n) = tok.kind { - n - } else { - unsafe { std::hint::unreachable_unchecked() } + let name = match tok.kind { + TokenKind::Variable(n) => n, + _ => unsafe { std::hint::unreachable_unchecked() }, }; if let TokenKind::Symbol(Symbol::Colon) = toks.peek().expect("expected something after variable").kind @@ -578,13 +577,10 @@ pub(crate) fn eat_expr>( values.push(tok); } } - _ => { - if let Some(tok) = toks.next() { - values.push(tok) - } else { - unsafe { std::hint::unreachable_unchecked() } - } - } + _ => match toks.next() { + Some(tok) => values.push(tok), + _ => unsafe { std::hint::unreachable_unchecked() }, + }, }; } Ok(None) diff --git a/src/mixin.rs b/src/mixin.rs index 35d8adb..479ea73 100644 --- a/src/mixin.rs +++ b/src/mixin.rs @@ -28,17 +28,17 @@ impl Mixin { .next() .expect("this must exist because we have already peeked"); devour_whitespace(toks); - let name = if let Some(Token { - kind: TokenKind::Ident(s), - .. - }) = toks.next() - { - s - } else { - return Err(Printer::Error( - pos, - String::from("expected identifier after mixin declaration"), - )); + let name = match toks.next() { + Some(Token { + kind: TokenKind::Ident(s), + .. + }) => s, + _ => { + return Err(Printer::Error( + pos, + String::from("expected identifier after mixin declaration"), + )) + } }; devour_whitespace(toks); let args = match toks.next() { @@ -59,12 +59,12 @@ impl Mixin { while nesting > 0 { if let Some(tok) = toks.next() { match &tok.kind { - TokenKind::Symbol(Symbol::OpenCurlyBrace) - // interpolation token eats the opening brace but not the closing - | TokenKind::Interpolation => nesting += 1, - TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1, - _ => {} - } + TokenKind::Symbol(Symbol::OpenCurlyBrace) + // interpolation token eats the opening brace but not the closing + | TokenKind::Interpolation => nesting += 1, + TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1, + _ => {} + } body.push(tok) } else { return Err(Printer::Error(pos, String::from("unexpected EOF")));