clippy: Use if lets and remove redundant returns

This commit is contained in:
Alan Du 2018-10-16 11:51:58 -04:00
parent 5db663d61f
commit d493a4476c
11 changed files with 22 additions and 29 deletions

View file

@ -30,7 +30,8 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
let left = children.next().unwrap();
let right = children.next();
assert!(children.next().is_none());
return if let Some(right) = right {
if let Some(right) = right {
match (
find_leaf_at_offset(left, offset),
find_leaf_at_offset(right, offset),
@ -42,7 +43,7 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
}
} else {
find_leaf_at_offset(left, offset)
};
}
}
#[derive(Clone, Copy, Debug)]

View file

@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
type Item = N;
fn next(&mut self) -> Option<N> {
loop {
match N::cast(self.inner.next()?) {
Some(n) => return Some(n),
None => (),
if let Some(n) = N::cast(self.inner.next()?) {
return Some(n);
}
}
}

View file

@ -62,9 +62,8 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
match literal(p) {
Some(m) => return Some(m),
None => (),
if let Some(m) = literal(p) {
return Some(m);
}
if paths::is_path_start(p) || p.at(L_ANGLE) {
return Some(path_expr(p, r));

View file

@ -352,7 +352,7 @@ fn macro_call(p: &mut Parser) -> BlockLike {
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
p.expect(EXCL);
p.eat(IDENT);
let flavor = match p.current() {
match p.current() {
L_CURLY => {
token_tree(p);
BlockLike::Block
@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
p.error("expected `{`, `[`, `(`");
BlockLike::NotBlock
}
};
flavor
}
}
pub(crate) fn token_tree(p: &mut Parser) {

View file

@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
// "hello" => (),
// }
// }
match expressions::literal(p) {
Some(m) => return Some(m),
None => (),
if let Some(m) = expressions::literal(p) {
return Some(m);
}
let m = match la0 {

View file

@ -42,7 +42,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
writeln!(buf, "err: `{}`", err.msg).unwrap();
}
return buf;
buf
}
pub fn check_fuzz_invariants(text: &str) {