Prefer match over if let

This commit is contained in:
ConnorSkees 2020-01-19 01:01:02 -05:00
parent 07cb3a4ac7
commit 28050116d3
2 changed files with 24 additions and 28 deletions

View File

@ -507,10 +507,9 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
let tok = toks let tok = toks
.next() .next()
.expect("this must exist because we have already peeked"); .expect("this must exist because we have already peeked");
let name = if let TokenKind::Variable(n) = tok.kind { let name = match tok.kind {
n TokenKind::Variable(n) => n,
} else { _ => unsafe { std::hint::unreachable_unchecked() },
unsafe { std::hint::unreachable_unchecked() }
}; };
if let TokenKind::Symbol(Symbol::Colon) = if let TokenKind::Symbol(Symbol::Colon) =
toks.peek().expect("expected something after variable").kind toks.peek().expect("expected something after variable").kind
@ -578,13 +577,10 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
values.push(tok); values.push(tok);
} }
} }
_ => { _ => match toks.next() {
if let Some(tok) = toks.next() { Some(tok) => values.push(tok),
values.push(tok) _ => unsafe { std::hint::unreachable_unchecked() },
} else { },
unsafe { std::hint::unreachable_unchecked() }
}
}
}; };
} }
Ok(None) Ok(None)

View File

@ -28,17 +28,17 @@ impl Mixin {
.next() .next()
.expect("this must exist because we have already peeked"); .expect("this must exist because we have already peeked");
devour_whitespace(toks); devour_whitespace(toks);
let name = if let Some(Token { let name = match toks.next() {
kind: TokenKind::Ident(s), Some(Token {
.. kind: TokenKind::Ident(s),
}) = toks.next() ..
{ }) => s,
s _ => {
} else { return Err(Printer::Error(
return Err(Printer::Error( pos,
pos, String::from("expected identifier after mixin declaration"),
String::from("expected identifier after mixin declaration"), ))
)); }
}; };
devour_whitespace(toks); devour_whitespace(toks);
let args = match toks.next() { let args = match toks.next() {
@ -59,12 +59,12 @@ impl Mixin {
while nesting > 0 { while nesting > 0 {
if let Some(tok) = toks.next() { if let Some(tok) = toks.next() {
match &tok.kind { match &tok.kind {
TokenKind::Symbol(Symbol::OpenCurlyBrace) TokenKind::Symbol(Symbol::OpenCurlyBrace)
// interpolation token eats the opening brace but not the closing // interpolation token eats the opening brace but not the closing
| TokenKind::Interpolation => nesting += 1, | TokenKind::Interpolation => nesting += 1,
TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1, TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1,
_ => {} _ => {}
} }
body.push(tok) body.push(tok)
} else { } else {
return Err(Printer::Error(pos, String::from("unexpected EOF"))); return Err(Printer::Error(pos, String::from("unexpected EOF")));