clippy: Use if lets and remove redundant returns
This commit is contained in:
parent
5db663d61f
commit
d493a4476c
11 changed files with 22 additions and 29 deletions
crates
ra_editor/src
ra_lsp_server/src
ra_syntax/src
tools/src
|
@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec<Fold> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if node.kind() == COMMENT {
|
if node.kind() == COMMENT {
|
||||||
contiguous_range_for_comment(node, &mut visited_comments).map(|range| {
|
if let Some(range) = contiguous_range_for_comment(node, &mut visited_comments) {
|
||||||
res.push(Fold {
|
res.push(Fold {
|
||||||
range,
|
range,
|
||||||
kind: FoldKind::Comment,
|
kind: FoldKind::Comment,
|
||||||
})
|
})
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ impl LineIndex {
|
||||||
let line = self.newlines.upper_bound(&offset) - 1;
|
let line = self.newlines.upper_bound(&offset) - 1;
|
||||||
let line_start_offset = self.newlines[line];
|
let line_start_offset = self.newlines[line];
|
||||||
let col = offset - line_start_offset;
|
let col = offset - line_start_offset;
|
||||||
return LineCol {
|
LineCol {
|
||||||
line: line as u32,
|
line: line as u32,
|
||||||
col,
|
col,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offset(&self, line_col: LineCol) -> TextUnit {
|
pub fn offset(&self, line_col: LineCol) -> TextUnit {
|
||||||
|
|
|
@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec<StructureNode> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut stack = Vec::new();
|
let mut stack = Vec::new();
|
||||||
|
|
||||||
|
|
||||||
for event in file.syntax().preorder() {
|
for event in file.syntax().preorder() {
|
||||||
match event {
|
match event {
|
||||||
WalkEvent::Enter(node) => match structure_node(node) {
|
WalkEvent::Enter(node) => {
|
||||||
Some(mut symbol) => {
|
if let Some(mut symbol) = structure_node(node) {
|
||||||
symbol.parent = stack.last().map(|&n| n);
|
symbol.parent = stack.last().map(|&n| n);
|
||||||
stack.push(res.len());
|
stack.push(res.len());
|
||||||
res.push(symbol);
|
res.push(symbol);
|
||||||
}
|
}
|
||||||
None => (),
|
|
||||||
},
|
},
|
||||||
WalkEvent::Leave(node) => {
|
WalkEvent::Leave(node) => {
|
||||||
if structure_node(node).is_some() {
|
if structure_node(node).is_some() {
|
||||||
|
|
|
@ -73,9 +73,7 @@ impl ServerWorldState {
|
||||||
events
|
events
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|event| {
|
.map(|event| {
|
||||||
let text = match event.kind {
|
let FileEventKind::Add(text) = event.kind;
|
||||||
FileEventKind::Add(text) => text,
|
|
||||||
};
|
|
||||||
(event.path, text)
|
(event.path, text)
|
||||||
})
|
})
|
||||||
.map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text))
|
.map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text))
|
||||||
|
|
|
@ -30,7 +30,8 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
|
||||||
let left = children.next().unwrap();
|
let left = children.next().unwrap();
|
||||||
let right = children.next();
|
let right = children.next();
|
||||||
assert!(children.next().is_none());
|
assert!(children.next().is_none());
|
||||||
return if let Some(right) = right {
|
|
||||||
|
if let Some(right) = right {
|
||||||
match (
|
match (
|
||||||
find_leaf_at_offset(left, offset),
|
find_leaf_at_offset(left, offset),
|
||||||
find_leaf_at_offset(right, offset),
|
find_leaf_at_offset(right, offset),
|
||||||
|
@ -42,7 +43,7 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
find_leaf_at_offset(left, offset)
|
find_leaf_at_offset(left, offset)
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
|
|
@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> {
|
||||||
type Item = N;
|
type Item = N;
|
||||||
fn next(&mut self) -> Option<N> {
|
fn next(&mut self) -> Option<N> {
|
||||||
loop {
|
loop {
|
||||||
match N::cast(self.inner.next()?) {
|
if let Some(n) = N::cast(self.inner.next()?) {
|
||||||
Some(n) => return Some(n),
|
return Some(n);
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,8 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![
|
||||||
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
|
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
|
||||||
|
|
||||||
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
||||||
match literal(p) {
|
if let Some(m) = literal(p) {
|
||||||
Some(m) => return Some(m),
|
return Some(m);
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
if paths::is_path_start(p) || p.at(L_ANGLE) {
|
if paths::is_path_start(p) || p.at(L_ANGLE) {
|
||||||
return Some(path_expr(p, r));
|
return Some(path_expr(p, r));
|
||||||
|
|
|
@ -352,7 +352,7 @@ fn macro_call(p: &mut Parser) -> BlockLike {
|
||||||
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
|
pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
|
||||||
p.expect(EXCL);
|
p.expect(EXCL);
|
||||||
p.eat(IDENT);
|
p.eat(IDENT);
|
||||||
let flavor = match p.current() {
|
match p.current() {
|
||||||
L_CURLY => {
|
L_CURLY => {
|
||||||
token_tree(p);
|
token_tree(p);
|
||||||
BlockLike::Block
|
BlockLike::Block
|
||||||
|
@ -365,9 +365,7 @@ pub(super) fn macro_call_after_excl(p: &mut Parser) -> BlockLike {
|
||||||
p.error("expected `{`, `[`, `(`");
|
p.error("expected `{`, `[`, `(`");
|
||||||
BlockLike::NotBlock
|
BlockLike::NotBlock
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
flavor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn token_tree(p: &mut Parser) {
|
pub(crate) fn token_tree(p: &mut Parser) {
|
||||||
|
|
|
@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
|
||||||
// "hello" => (),
|
// "hello" => (),
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
match expressions::literal(p) {
|
if let Some(m) = expressions::literal(p) {
|
||||||
Some(m) => return Some(m),
|
return Some(m);
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let m = match la0 {
|
let m = match la0 {
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String {
|
||||||
writeln!(buf, "err: `{}`", err.msg).unwrap();
|
writeln!(buf, "err: `{}`", err.msg).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf;
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_fuzz_invariants(text: &str) {
|
pub fn check_fuzz_invariants(text: &str) {
|
||||||
|
|
|
@ -112,9 +112,8 @@ fn existing_tests(dir: &Path) -> Result<HashMap<String, (PathBuf, Test)>> {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
text,
|
text,
|
||||||
};
|
};
|
||||||
match res.insert(name, (path, test)) {
|
if let Some(old) = res.insert(name, (path, test)) {
|
||||||
Some(old) => println!("Duplicate test: {:?}", old),
|
println!("Duplicate test: {:?}", old);
|
||||||
None => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|
Loading…
Add table
Reference in a new issue