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() {
Some(Token {
kind: TokenKind::Ident(s), 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() {