From 5db663d61fb8b006e3b84ef3bcc9cddbe94e5f49 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 11:45:10 -0400 Subject: Clippy lint: single-character string constant --- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_editor/src/extend_selection.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 4 ++-- crates/tools/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index f1403cb5d..9b0d935af 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -388,7 +388,7 @@ impl AnalysisImpl { .text() .slice(range_search) .to_string() - .matches(",") + .matches(',') .count(); // If we have a method call eat the first param since it's just self. diff --git a/crates/ra_editor/src/extend_selection.rs b/crates/ra_editor/src/extend_selection.rs index 9ee1df281..9d8df25c3 100644 --- a/crates/ra_editor/src/extend_selection.rs +++ b/crates/ra_editor/src/extend_selection.rs @@ -63,7 +63,7 @@ fn extend_ws(root: SyntaxNodeRef, ws: SyntaxNodeRef, offset: TextUnit) -> TextRa let prefix = TextRange::from_to(ws.range().start(), offset) - ws.range().start(); let ws_suffix = &ws_text.as_str()[suffix]; let ws_prefix = &ws_text.as_str()[prefix]; - if ws_text.contains("\n") && !ws_suffix.contains("\n") { + if ws_text.contains('\n') && !ws_suffix.contains('\n') { if let Some(node) = ws.next_sibling() { let start = match ws_prefix.rfind('\n') { Some(idx) => ws.range().start() + TextUnit::from((idx + 1) as u32), diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c25b63852..49bd7895a 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -160,8 +160,8 @@ pub fn handle_workspace_symbol( params: req::WorkspaceSymbolParams, token: JobToken, ) -> Result>> { - let all_symbols = params.query.contains("#"); - let libs = params.query.contains("*"); + let all_symbols = params.query.contains('#'); + let libs = params.query.contains('*'); let query = { let query: String = params .query diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rs index 444745be5..7c5410d3c 100644 --- a/crates/tools/src/lib.rs +++ b/crates/tools/src/lib.rs @@ -50,7 +50,7 @@ pub fn collect_tests(s: &str) -> Vec<(usize, Test)> { block.map(|(_, line)| line).chain(::std::iter::once("")), "\n", ); - assert!(!text.trim().is_empty() && text.ends_with("\n")); + assert!(!text.trim().is_empty() && text.ends_with('\n')); res.push((start_line, Test { name, text })) } res -- cgit v1.2.3 From d493a4476c2059924d032fbf01dda091601f9667 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 11:51:58 -0400 Subject: clippy: Use if lets and remove redundant returns --- crates/ra_editor/src/folding_ranges.rs | 4 ++-- crates/ra_editor/src/line_index.rs | 4 ++-- crates/ra_editor/src/symbols.rs | 6 +++--- crates/ra_lsp_server/src/server_world.rs | 4 +--- crates/ra_syntax/src/algo/mod.rs | 5 +++-- crates/ra_syntax/src/ast/mod.rs | 5 ++--- crates/ra_syntax/src/grammar/expressions/atom.rs | 5 ++--- crates/ra_syntax/src/grammar/items/mod.rs | 6 ++---- crates/ra_syntax/src/grammar/patterns.rs | 5 ++--- crates/ra_syntax/src/utils.rs | 2 +- crates/tools/src/main.rs | 5 ++--- 11 files changed, 22 insertions(+), 29 deletions(-) diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index e5bc0c4ee..d0d4ed3d3 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs @@ -38,12 +38,12 @@ pub fn folding_ranges(file: &File) -> Vec { continue; } 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 { range, kind: FoldKind::Comment, }) - }); + } } } diff --git a/crates/ra_editor/src/line_index.rs b/crates/ra_editor/src/line_index.rs index da0f2a7f7..9abbb0d09 100644 --- a/crates/ra_editor/src/line_index.rs +++ b/crates/ra_editor/src/line_index.rs @@ -29,10 +29,10 @@ impl LineIndex { let line = self.newlines.upper_bound(&offset) - 1; let line_start_offset = self.newlines[line]; let col = offset - line_start_offset; - return LineCol { + LineCol { line: line as u32, col, - }; + } } pub fn offset(&self, line_col: LineCol) -> TextUnit { diff --git a/crates/ra_editor/src/symbols.rs b/crates/ra_editor/src/symbols.rs index c3c66680d..0bab9dd67 100644 --- a/crates/ra_editor/src/symbols.rs +++ b/crates/ra_editor/src/symbols.rs @@ -54,15 +54,15 @@ pub fn file_structure(file: &File) -> Vec { let mut res = Vec::new(); let mut stack = Vec::new(); + for event in file.syntax().preorder() { match event { - WalkEvent::Enter(node) => match structure_node(node) { - Some(mut symbol) => { + WalkEvent::Enter(node) => { + if let Some(mut symbol) = structure_node(node) { symbol.parent = stack.last().map(|&n| n); stack.push(res.len()); res.push(symbol); } - None => (), }, WalkEvent::Leave(node) => { if structure_node(node).is_some() { diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 35ff65ea1..69b2a1cd1 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -73,9 +73,7 @@ impl ServerWorldState { events .into_iter() .map(|event| { - let text = match event.kind { - FileEventKind::Add(text) => text, - }; + let FileEventKind::Add(text) = event.kind; (event.path, text) }) .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 9d2014bc7..87f1250bc 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -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)] diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index 34958b6cb..900426a8a 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs @@ -259,9 +259,8 @@ impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { type Item = N; fn next(&mut self) -> Option { 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); } } } diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs index 11f766d33..04087fd60 100644 --- a/crates/ra_syntax/src/grammar/expressions/atom.rs +++ b/crates/ra_syntax/src/grammar/expressions/atom.rs @@ -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 { - 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)); diff --git a/crates/ra_syntax/src/grammar/items/mod.rs b/crates/ra_syntax/src/grammar/items/mod.rs index dc4742bce..06c6b5e6e 100644 --- a/crates/ra_syntax/src/grammar/items/mod.rs +++ b/crates/ra_syntax/src/grammar/items/mod.rs @@ -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) { diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs index 9d35dbb3d..10fa0e0be 100644 --- a/crates/ra_syntax/src/grammar/patterns.rs +++ b/crates/ra_syntax/src/grammar/patterns.rs @@ -49,9 +49,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option { // "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 { diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 7d0ef2fa2..ca4160378 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs @@ -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) { diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 152298014..fdb443690 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs @@ -112,9 +112,8 @@ fn existing_tests(dir: &Path) -> Result> { name: name.clone(), text, }; - match res.insert(name, (path, test)) { - Some(old) => println!("Duplicate test: {:?}", old), - None => (), + if let Some(old) = res.insert(name, (path, test)) { + println!("Duplicate test: {:?}", old); } } Ok(res) -- cgit v1.2.3 From 4e8ea94e2b72a3e927c8ff1b5f3fe2413ccc79a7 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 11:54:29 -0400 Subject: Remove Copy trait on LeafAtOffset Because it's a stateful iterator, it's easier to explicitly clone it when necesary. Fixes clippy:clone_on_copy --- crates/ra_syntax/src/algo/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index 87f1250bc..d82c42b3e 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs @@ -46,7 +46,7 @@ pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffse } } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub enum LeafAtOffset<'a> { None, Single(SyntaxNodeRef<'a>), -- cgit v1.2.3 From 2268a2f8c6557301ecdcaeb4074331a0bd37dccd Mon Sep 17 00:00:00 2001 From: Alan Du Date: Wed, 17 Oct 2018 19:15:22 -0400 Subject: Silence clippy::derive_hash_xor_eq Manually implement PartialEq --- crates/ra_analysis/src/db.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 042dde1ac..99d40a269 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -76,12 +76,18 @@ salsa::query_group! { } } -#[derive(Default, Debug, PartialEq, Eq)] +#[derive(Default, Debug, Eq)] pub(crate) struct FileSet { pub(crate) files: FxHashSet, pub(crate) resolver: FileResolverImp, } +impl PartialEq for FileSet { + fn eq(&self, other: &FileSet) -> bool { + self.files == other.files && self.resolver == other.resolver + } +} + impl Hash for FileSet { fn hash(&self, hasher: &mut H) { let mut files = self.files.iter().cloned().collect::>(); -- cgit v1.2.3 From 2ae9dfa812ccf18867373f77a106161378a6d91d Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 13:31:16 -0400 Subject: clippy: Fix new_ret_no_self --- crates/ra_analysis/src/descriptors.rs | 2 +- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_analysis/src/job.rs | 2 +- crates/ra_analysis/tests/tests.rs | 4 ++-- crates/ra_editor/src/scope/fn_scope.rs | 4 ++-- crates/ra_editor/src/scope/mod_scope.rs | 18 +++++++++--------- crates/ra_lsp_server/src/main_loop/mod.rs | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs index 6f26f9935..f64fcee16 100644 --- a/crates/ra_analysis/src/descriptors.rs +++ b/crates/ra_analysis/src/descriptors.rs @@ -233,7 +233,7 @@ pub struct FnDescriptor { } impl FnDescriptor { - pub fn new(node: ast::FnDef) -> Option { + pub fn new_opt(node: ast::FnDef) -> Option { let name = node.name()?.text().to_string(); // Strip the body out for the label. diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 9b0d935af..1c16852b8 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -362,7 +362,7 @@ impl AnalysisImpl { for (_, fs) in file_symbols { if fs.kind == FN_DEF { if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { - if let Some(descriptor) = FnDescriptor::new(fn_def) { + if let Some(descriptor) = FnDescriptor::new_opt(fn_def) { // If we have a calling expression let's find which argument we are on let mut current_parameter = None; diff --git a/crates/ra_analysis/src/job.rs b/crates/ra_analysis/src/job.rs index 2871f9839..57215c862 100644 --- a/crates/ra_analysis/src/job.rs +++ b/crates/ra_analysis/src/job.rs @@ -11,7 +11,7 @@ pub struct JobToken { } impl JobHandle { - pub fn new() -> (JobHandle, JobToken) { + pub fn new_pair() -> (JobHandle, JobToken) { let (sender_alive, receiver_alive) = bounded(0); let (sender_canceled, receiver_canceled) = bounded(0); let token = JobToken { diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index e0c637d65..3302e1151 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs @@ -62,7 +62,7 @@ fn get_signature(text: &str) -> (FnDescriptor, Option) { let (offset, code) = extract_offset(text); let code = code.as_str(); - let (_handle, token) = JobHandle::new(); + let (_handle, token) = JobHandle::new_pair(); let snap = analysis(&[("/lib.rs", code)]); snap.resolve_callable(FileId(1), offset, &token).unwrap() @@ -71,7 +71,7 @@ fn get_signature(text: &str) -> (FnDescriptor, Option) { #[test] fn test_resolve_module() { let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); - let (_handle, token) = JobHandle::new(); + let (_handle, token) = JobHandle::new_pair(); let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); assert_eq_dbg( r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs index 9088e5a60..84f036c7e 100644 --- a/crates/ra_editor/src/scope/fn_scope.rs +++ b/crates/ra_editor/src/scope/fn_scope.rs @@ -63,7 +63,7 @@ impl FnScopes { .syntax() .descendants() .filter_map(ast::BindPat::cast) - .filter_map(ScopeEntry::new); + .filter_map(ScopeEntry::new_opt); self.scopes[scope].entries.extend(entries); } fn add_params_bindings(&mut self, scope: ScopeId, params: Option) { @@ -88,7 +88,7 @@ pub struct ScopeEntry { } impl ScopeEntry { - fn new(pat: ast::BindPat) -> Option { + fn new_opt(pat: ast::BindPat) -> Option { if pat.name().is_some() { Some(ScopeEntry { syntax: pat.syntax().owned(), diff --git a/crates/ra_editor/src/scope/mod_scope.rs b/crates/ra_editor/src/scope/mod_scope.rs index 8d7e408f8..956ee0e2f 100644 --- a/crates/ra_editor/src/scope/mod_scope.rs +++ b/crates/ra_editor/src/scope/mod_scope.rs @@ -22,14 +22,14 @@ impl ModuleScope { let mut entries = Vec::new(); for item in items { let entry = match item { - ast::ModuleItem::StructDef(item) => Entry::new(item), - ast::ModuleItem::EnumDef(item) => Entry::new(item), - ast::ModuleItem::FnDef(item) => Entry::new(item), - ast::ModuleItem::ConstDef(item) => Entry::new(item), - ast::ModuleItem::StaticDef(item) => Entry::new(item), - ast::ModuleItem::TraitDef(item) => Entry::new(item), - ast::ModuleItem::TypeDef(item) => Entry::new(item), - ast::ModuleItem::Module(item) => Entry::new(item), + ast::ModuleItem::StructDef(item) => Entry::new_item(item), + ast::ModuleItem::EnumDef(item) => Entry::new_item(item), + ast::ModuleItem::FnDef(item) => Entry::new_item(item), + ast::ModuleItem::ConstDef(item) => Entry::new_item(item), + ast::ModuleItem::StaticDef(item) => Entry::new_item(item), + ast::ModuleItem::TraitDef(item) => Entry::new_item(item), + ast::ModuleItem::TypeDef(item) => Entry::new_item(item), + ast::ModuleItem::Module(item) => Entry::new_item(item), ast::ModuleItem::UseItem(item) => { if let Some(tree) = item.use_tree() { collect_imports(tree, &mut entries); @@ -50,7 +50,7 @@ impl ModuleScope { } impl Entry { - fn new<'a>(item: impl ast::NameOwner<'a>) -> Option { + fn new_item<'a>(item: impl ast::NameOwner<'a>) -> Option { let name = item.name()?; Some(Entry { node: name.syntax().owned(), diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index a11baf4aa..2623ab84e 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -355,7 +355,7 @@ impl<'a> PoolDispatcher<'a> { }; match req.cast::() { Ok((id, params)) => { - let (handle, token) = JobHandle::new(); + let (handle, token) = JobHandle::new_pair(); let world = self.world.snapshot(); let sender = self.sender.clone(); self.pool.spawn(move || { -- cgit v1.2.3 From bc774fe6cf9948bd554e3fb5b51398b9328e0f4e Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 13:39:46 -0400 Subject: clippy: needless_lifetimes --- crates/ra_analysis/src/descriptors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs index f64fcee16..98429326c 100644 --- a/crates/ra_analysis/src/descriptors.rs +++ b/crates/ra_analysis/src/descriptors.rs @@ -21,7 +21,7 @@ impl ModuleDescriptor { } } -fn modules<'a>(root: ast::Root<'a>) -> impl Iterator)> { +fn modules(root: ast::Root<'_>) -> impl Iterator)> { root.modules().filter_map(|module| { let name = module.name()?.text(); if !module.has_semi() { -- cgit v1.2.3 From fc8024de51261d252b1ad88566db6e246d14ee16 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Tue, 16 Oct 2018 14:08:52 -0400 Subject: clippy: type_complexity --- crates/ra_lsp_server/src/thread_watcher.rs | 10 ++++++---- crates/ra_syntax/src/reparsing.rs | 9 +++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/ra_lsp_server/src/thread_watcher.rs b/crates/ra_lsp_server/src/thread_watcher.rs index 67952eb74..6cc586456 100644 --- a/crates/ra_lsp_server/src/thread_watcher.rs +++ b/crates/ra_lsp_server/src/thread_watcher.rs @@ -16,8 +16,7 @@ impl Worker { I: Send + 'static, O: Send + 'static, { - let ((inp, out), inp_r, out_s) = worker_chan(buf); - let worker = Worker { inp, out }; + let (worker, inp_r, out_s) = worker_chan(buf); let watcher = ThreadWatcher::spawn(name, move || f(inp_r, out_s)); (worker, watcher) } @@ -66,11 +65,14 @@ impl ThreadWatcher { /// Sets up worker channels in a deadlock-avoind way. /// If one sets both input and output buffers to a fixed size, /// a worker might get stuck. -fn worker_chan(buf: usize) -> ((Sender, Receiver), Receiver, Sender) { +fn worker_chan(buf: usize) -> (Worker, Receiver, Sender) { let (input_sender, input_receiver) = bounded::(buf); let (output_sender, output_receiver) = unbounded::(); ( - (input_sender, output_receiver), + Worker { + inp: input_sender, + out: output_receiver, + }, input_receiver, output_sender, ) diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index a0014e016..377152de4 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs @@ -98,17 +98,18 @@ fn is_contextual_kw(text: &str) -> bool { } } -fn find_reparsable_node<'node>( - node: SyntaxNodeRef<'node>, +type ParseFn = fn(&mut Parser); +fn find_reparsable_node( + node: SyntaxNodeRef<'_>, range: TextRange, -) -> Option<(SyntaxNodeRef<'node>, fn(&mut Parser))> { +) -> Option<(SyntaxNodeRef<'_>, ParseFn)> { let node = algo::find_covering_node(node, range); return node .ancestors() .filter_map(|node| reparser(node).map(|r| (node, r))) .next(); - fn reparser(node: SyntaxNodeRef) -> Option { + fn reparser(node: SyntaxNodeRef) -> Option { let res = match node.kind() { BLOCK => grammar::block, NAMED_FIELD_DEF_LIST => grammar::named_field_def_list, -- cgit v1.2.3 From a5da770ec60a73abcc5350f25146be973540063f Mon Sep 17 00:00:00 2001 From: Alan Du Date: Wed, 17 Oct 2018 19:25:37 -0400 Subject: Fix function calls --- crates/ra_analysis/src/descriptors.rs | 3 +-- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_editor/src/typing.rs | 2 +- crates/ra_lsp_server/src/main.rs | 2 +- crates/ra_lsp_server/src/main_loop/handlers.rs | 4 ++-- crates/ra_lsp_server/src/project_model.rs | 1 - crates/ra_lsp_server/src/vfs.rs | 1 - crates/ra_syntax/src/lexer/ptr.rs | 2 +- crates/ra_syntax/src/reparsing.rs | 2 +- crates/ra_syntax/src/utils.rs | 2 +- 10 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs index 98429326c..dced99b07 100644 --- a/crates/ra_analysis/src/descriptors.rs +++ b/crates/ra_analysis/src/descriptors.rs @@ -183,8 +183,7 @@ impl Link { root: ast::Root<'a>, ) -> ast::Module<'a> { modules(root) - .filter(|(name, _)| name == &tree.link(self).name) - .next() + .find(|(name, _)| name == &tree.link(self).name) .unwrap() .1 } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 1c16852b8..b4faf0b5b 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -393,7 +393,7 @@ impl AnalysisImpl { // If we have a method call eat the first param since it's just self. if has_self { - commas = commas + 1; + commas += 1; } current_parameter = Some(commas); diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 50b52e7a1..5a457d148 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs @@ -58,7 +58,7 @@ pub fn join_lines(file: &File, range: TextRange) -> LocalEdit { pub fn on_enter(file: &File, offset: TextUnit) -> Option { let comment = find_leaf_at_offset(file.syntax(), offset) .left_biased() - .and_then(|it| ast::Comment::cast(it))?; + .and_then(ast::Comment::cast)?; if let ast::CommentFlavor::Multiline = comment.flavor() { return None; diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 9f62347f1..c07eb0140 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs @@ -18,7 +18,7 @@ fn main() -> Result<()> { .directory("log") .start()?; info!("lifecycle: server started"); - match ::std::panic::catch_unwind(|| main_inner()) { + match ::std::panic::catch_unwind(main_inner) { Ok(res) => { info!("lifecycle: terminating process with {:?}", res); res diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 49bd7895a..3e58e6f54 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -289,8 +289,8 @@ pub fn handle_runnables( .filter_map(|ws| { let tgt = ws.target_by_root(path)?; Some(( - tgt.package(ws).name(ws).clone(), - tgt.name(ws).clone(), + tgt.package(ws).name(ws), + tgt.name(ws), tgt.kind(ws), )) }) diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index d170ceb73..cedb67bae 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs @@ -173,7 +173,6 @@ pub fn workspace_loader() -> (Worker>, ThreadWat 1, |input_receiver, output_sender| { input_receiver - .into_iter() .map(|path| CargoWorkspace::from_cargo_metadata(path.as_path())) .for_each(|it| output_sender.send(it)) }, diff --git a/crates/ra_lsp_server/src/vfs.rs b/crates/ra_lsp_server/src/vfs.rs index 417a3c19a..6e317d854 100644 --- a/crates/ra_lsp_server/src/vfs.rs +++ b/crates/ra_lsp_server/src/vfs.rs @@ -24,7 +24,6 @@ pub fn roots_loader() -> (Worker)>, ThreadWatc 128, |input_receiver, output_sender| { input_receiver - .into_iter() .map(|path| { debug!("loading {} ...", path.as_path().display()); let events = load_root(path.as_path()); diff --git a/crates/ra_syntax/src/lexer/ptr.rs b/crates/ra_syntax/src/lexer/ptr.rs index fa79d8862..4c291b9c4 100644 --- a/crates/ra_syntax/src/lexer/ptr.rs +++ b/crates/ra_syntax/src/lexer/ptr.rs @@ -31,7 +31,7 @@ impl<'s> Ptr<'s> { /// For example, 0 will return the current token, 1 will return the next, etc. pub fn nth(&self, n: u32) -> Option { let mut chars = self.chars().peekable(); - chars.by_ref().skip(n as usize).next() + chars.by_ref().nth(n as usize) } /// Checks whether the current character is `c`. diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 377152de4..eae01b1d5 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs @@ -135,7 +135,7 @@ fn find_reparsable_node( } fn is_balanced(tokens: &[Token]) -> bool { - if tokens.len() == 0 + if tokens.is_empty() || tokens.first().unwrap().kind != L_CURLY || tokens.last().unwrap().kind != R_CURLY { diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index ca4160378..8ee02724d 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs @@ -5,7 +5,7 @@ use std::fmt::Write; /// Parse a file and create a string representation of the resulting parse tree. pub fn dump_tree(syntax: SyntaxNodeRef) -> String { - let mut errors: Vec<_> = syntax.root_data().iter().cloned().collect(); + let mut errors: Vec<_> = syntax.root_data().to_vec(); errors.sort_by_key(|e| e.offset); let mut err_pos = 0; let mut level = 0; -- cgit v1.2.3 From 6dd3fa6a947a4442e46ac042ff955a7f17bd6a0f Mon Sep 17 00:00:00 2001 From: Alan Du Date: Wed, 17 Oct 2018 19:27:49 -0400 Subject: clippy: cast_lossless --- crates/ra_lsp_server/src/conv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 8325e8c1e..bc0cf7c68 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -65,7 +65,7 @@ impl ConvWith for TextUnit { fn conv_with(self, line_index: &LineIndex) -> Position { let line_col = line_index.line_col(self); // TODO: UTF-16 - Position::new(line_col.line as u64, u32::from(line_col.col) as u64) + Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))) } } @@ -192,7 +192,7 @@ impl TryConvWith for SourceChange { .map(|it| it.edits.as_slice()) .unwrap_or(&[]); let line_col = translate_offset_with_edit(&*line_index, pos.offset, edits); - let position = Position::new(line_col.line as u64, u32::from(line_col.col) as u64); + let position = Position::new(u64::from(line_col.line), u64::from(u32::from(line_col.col))); Some(TextDocumentPositionParams { text_document: TextDocumentIdentifier::new(pos.file_id.try_conv_with(world)?), position, -- cgit v1.2.3 From 0857c22f263ff18418f939b57a7a2ab3f8aac2c1 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Sat, 20 Oct 2018 12:29:25 -0400 Subject: Revert "clippy: Fix new_ret_no_self" This reverts commit 2ae9dfa812ccf18867373f77a106161378a6d91d. --- crates/ra_analysis/src/descriptors.rs | 2 +- crates/ra_analysis/src/imp.rs | 2 +- crates/ra_analysis/src/job.rs | 2 +- crates/ra_analysis/tests/tests.rs | 4 ++-- crates/ra_editor/src/scope/fn_scope.rs | 4 ++-- crates/ra_editor/src/scope/mod_scope.rs | 18 +++++++++--------- crates/ra_lsp_server/src/main_loop/mod.rs | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/crates/ra_analysis/src/descriptors.rs b/crates/ra_analysis/src/descriptors.rs index dced99b07..3fca3e581 100644 --- a/crates/ra_analysis/src/descriptors.rs +++ b/crates/ra_analysis/src/descriptors.rs @@ -232,7 +232,7 @@ pub struct FnDescriptor { } impl FnDescriptor { - pub fn new_opt(node: ast::FnDef) -> Option { + pub fn new(node: ast::FnDef) -> Option { let name = node.name()?.text().to_string(); // Strip the body out for the label. diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index b4faf0b5b..2ed6694ba 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -362,7 +362,7 @@ impl AnalysisImpl { for (_, fs) in file_symbols { if fs.kind == FN_DEF { if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) { - if let Some(descriptor) = FnDescriptor::new_opt(fn_def) { + if let Some(descriptor) = FnDescriptor::new(fn_def) { // If we have a calling expression let's find which argument we are on let mut current_parameter = None; diff --git a/crates/ra_analysis/src/job.rs b/crates/ra_analysis/src/job.rs index 57215c862..2871f9839 100644 --- a/crates/ra_analysis/src/job.rs +++ b/crates/ra_analysis/src/job.rs @@ -11,7 +11,7 @@ pub struct JobToken { } impl JobHandle { - pub fn new_pair() -> (JobHandle, JobToken) { + pub fn new() -> (JobHandle, JobToken) { let (sender_alive, receiver_alive) = bounded(0); let (sender_canceled, receiver_canceled) = bounded(0); let token = JobToken { diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index 3302e1151..e0c637d65 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs @@ -62,7 +62,7 @@ fn get_signature(text: &str) -> (FnDescriptor, Option) { let (offset, code) = extract_offset(text); let code = code.as_str(); - let (_handle, token) = JobHandle::new_pair(); + let (_handle, token) = JobHandle::new(); let snap = analysis(&[("/lib.rs", code)]); snap.resolve_callable(FileId(1), offset, &token).unwrap() @@ -71,7 +71,7 @@ fn get_signature(text: &str) -> (FnDescriptor, Option) { #[test] fn test_resolve_module() { let snap = analysis(&[("/lib.rs", "mod foo;"), ("/foo.rs", "")]); - let (_handle, token) = JobHandle::new_pair(); + let (_handle, token) = JobHandle::new(); let symbols = snap.approximately_resolve_symbol(FileId(1), 4.into(), &token); assert_eq_dbg( r#"[(FileId(2), FileSymbol { name: "foo", node_range: [0; 0), kind: MODULE })]"#, diff --git a/crates/ra_editor/src/scope/fn_scope.rs b/crates/ra_editor/src/scope/fn_scope.rs index 84f036c7e..9088e5a60 100644 --- a/crates/ra_editor/src/scope/fn_scope.rs +++ b/crates/ra_editor/src/scope/fn_scope.rs @@ -63,7 +63,7 @@ impl FnScopes { .syntax() .descendants() .filter_map(ast::BindPat::cast) - .filter_map(ScopeEntry::new_opt); + .filter_map(ScopeEntry::new); self.scopes[scope].entries.extend(entries); } fn add_params_bindings(&mut self, scope: ScopeId, params: Option) { @@ -88,7 +88,7 @@ pub struct ScopeEntry { } impl ScopeEntry { - fn new_opt(pat: ast::BindPat) -> Option { + fn new(pat: ast::BindPat) -> Option { if pat.name().is_some() { Some(ScopeEntry { syntax: pat.syntax().owned(), diff --git a/crates/ra_editor/src/scope/mod_scope.rs b/crates/ra_editor/src/scope/mod_scope.rs index 956ee0e2f..8d7e408f8 100644 --- a/crates/ra_editor/src/scope/mod_scope.rs +++ b/crates/ra_editor/src/scope/mod_scope.rs @@ -22,14 +22,14 @@ impl ModuleScope { let mut entries = Vec::new(); for item in items { let entry = match item { - ast::ModuleItem::StructDef(item) => Entry::new_item(item), - ast::ModuleItem::EnumDef(item) => Entry::new_item(item), - ast::ModuleItem::FnDef(item) => Entry::new_item(item), - ast::ModuleItem::ConstDef(item) => Entry::new_item(item), - ast::ModuleItem::StaticDef(item) => Entry::new_item(item), - ast::ModuleItem::TraitDef(item) => Entry::new_item(item), - ast::ModuleItem::TypeDef(item) => Entry::new_item(item), - ast::ModuleItem::Module(item) => Entry::new_item(item), + ast::ModuleItem::StructDef(item) => Entry::new(item), + ast::ModuleItem::EnumDef(item) => Entry::new(item), + ast::ModuleItem::FnDef(item) => Entry::new(item), + ast::ModuleItem::ConstDef(item) => Entry::new(item), + ast::ModuleItem::StaticDef(item) => Entry::new(item), + ast::ModuleItem::TraitDef(item) => Entry::new(item), + ast::ModuleItem::TypeDef(item) => Entry::new(item), + ast::ModuleItem::Module(item) => Entry::new(item), ast::ModuleItem::UseItem(item) => { if let Some(tree) = item.use_tree() { collect_imports(tree, &mut entries); @@ -50,7 +50,7 @@ impl ModuleScope { } impl Entry { - fn new_item<'a>(item: impl ast::NameOwner<'a>) -> Option { + fn new<'a>(item: impl ast::NameOwner<'a>) -> Option { let name = item.name()?; Some(Entry { node: name.syntax().owned(), diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 2623ab84e..a11baf4aa 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -355,7 +355,7 @@ impl<'a> PoolDispatcher<'a> { }; match req.cast::() { Ok((id, params)) => { - let (handle, token) = JobHandle::new_pair(); + let (handle, token) = JobHandle::new(); let world = self.world.snapshot(); let sender = self.sender.clone(); self.pool.spawn(move || { -- cgit v1.2.3 From dc9ce8ff7494f641c7102785cdef95489f2fc3d6 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Mon, 22 Oct 2018 10:50:55 -0400 Subject: Rename new to new_item (to match new_impl) --- crates/ra_editor/src/scope/mod_scope.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/ra_editor/src/scope/mod_scope.rs b/crates/ra_editor/src/scope/mod_scope.rs index 8d7e408f8..956ee0e2f 100644 --- a/crates/ra_editor/src/scope/mod_scope.rs +++ b/crates/ra_editor/src/scope/mod_scope.rs @@ -22,14 +22,14 @@ impl ModuleScope { let mut entries = Vec::new(); for item in items { let entry = match item { - ast::ModuleItem::StructDef(item) => Entry::new(item), - ast::ModuleItem::EnumDef(item) => Entry::new(item), - ast::ModuleItem::FnDef(item) => Entry::new(item), - ast::ModuleItem::ConstDef(item) => Entry::new(item), - ast::ModuleItem::StaticDef(item) => Entry::new(item), - ast::ModuleItem::TraitDef(item) => Entry::new(item), - ast::ModuleItem::TypeDef(item) => Entry::new(item), - ast::ModuleItem::Module(item) => Entry::new(item), + ast::ModuleItem::StructDef(item) => Entry::new_item(item), + ast::ModuleItem::EnumDef(item) => Entry::new_item(item), + ast::ModuleItem::FnDef(item) => Entry::new_item(item), + ast::ModuleItem::ConstDef(item) => Entry::new_item(item), + ast::ModuleItem::StaticDef(item) => Entry::new_item(item), + ast::ModuleItem::TraitDef(item) => Entry::new_item(item), + ast::ModuleItem::TypeDef(item) => Entry::new_item(item), + ast::ModuleItem::Module(item) => Entry::new_item(item), ast::ModuleItem::UseItem(item) => { if let Some(tree) = item.use_tree() { collect_imports(tree, &mut entries); @@ -50,7 +50,7 @@ impl ModuleScope { } impl Entry { - fn new<'a>(item: impl ast::NameOwner<'a>) -> Option { + fn new_item<'a>(item: impl ast::NameOwner<'a>) -> Option { let name = item.name()?; Some(Entry { node: name.syntax().owned(), -- cgit v1.2.3