Prefer match
over if let
This commit is contained in:
parent
07cb3a4ac7
commit
28050116d3
18
src/main.rs
18
src/main.rs
@ -507,10 +507,9 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
|
||||
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<I: Iterator<Item = Token>>(
|
||||
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)
|
||||
|
34
src/mixin.rs
34
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")));
|
||||
|
Loading…
x
Reference in New Issue
Block a user