From 6753051a45e067fb8267f7ecbbf1b894558718d1 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Wed, 6 Feb 2019 15:50:26 -0500 Subject: Some clippy cleanups --- crates/ra_ide_api/src/completion/completion_context.rs | 9 +++------ crates/ra_ide_api/src/completion/completion_item.rs | 6 +++--- crates/ra_ide_api/src/goto_definition.rs | 6 +++++- crates/ra_ide_api/src/lib.rs | 2 +- crates/ra_ide_api/src/rename.rs | 8 ++++---- crates/ra_ide_api/src/symbol_index.rs | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index 5d1851da6..8abab0221 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -130,12 +130,9 @@ impl<'a> CompletionContext<'a> { .ancestors() .take_while(|it| it.kind() != SOURCE_FILE && it.kind() != MODULE) .find_map(ast::FnDef::cast); - match (self.module, self.function_syntax) { - (Some(module), Some(fn_def)) => { - let function = source_binder::function_from_module(self.db, module, fn_def); - self.function = Some(function); - } - _ => (), + if let (Some(module), Some(fn_def)) = (self.module, self.function_syntax) { + let function = source_binder::function_from_module(self.db, module, fn_def); + self.function = Some(function); } let parent = match name_ref.syntax().parent() { diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index bada6a33b..92e6e78bf 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -108,11 +108,11 @@ impl CompletionItem { self.lookup .as_ref() .map(|it| it.as_str()) - .unwrap_or(self.label()) + .unwrap_or_else(|| self.label()) } pub fn insert_text_format(&self) -> InsertTextFormat { - self.insert_text_format.clone() + self.insert_text_format } pub fn insert_text(&self) -> String { match &self.insert_text { @@ -217,7 +217,7 @@ impl Builder { let def = resolution .as_ref() .take_types() - .or(resolution.as_ref().take_values()); + .or_else(|| resolution.as_ref().take_values()); let def = match def { None => return self, Some(it) => it, diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 88efcea2a..681f36623 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -89,7 +89,11 @@ pub(crate) fn reference_definition( .and_then(hir::Path::from_ast) { let resolved = resolver.resolve_path(db, &path); - match resolved.clone().take_types().or(resolved.take_values()) { + match resolved + .clone() + .take_types() + .or_else(|| resolved.take_values()) + { Some(Resolution::Def(def)) => return Exact(NavigationTarget::from_def(db, def)), Some(Resolution::LocalBinding(pat)) => { let body = resolver.body().expect("no body for local binding"); diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 8beaba5de..68d59aae1 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -117,7 +117,7 @@ impl fmt::Debug for AnalysisChange { if !self.libraries_added.is_empty() { d.field("libraries_added", &self.libraries_added.len()); } - if !self.crate_graph.is_some() { + if self.crate_graph.is_none() { d.field("crate_graph", &self.crate_graph); } d.finish() diff --git a/crates/ra_ide_api/src/rename.rs b/crates/ra_ide_api/src/rename.rs index db5ccf969..1c9491a0a 100644 --- a/crates/ra_ide_api/src/rename.rs +++ b/crates/ra_ide_api/src/rename.rs @@ -95,12 +95,12 @@ fn rename_mod( }; source_file_edits.push(edit); - return Some(SourceChange { + Some(SourceChange { label: "rename".to_string(), source_file_edits, file_system_edits, cursor_position: None, - }); + }) } fn rename_reference( @@ -124,12 +124,12 @@ fn rename_reference( return None; } - return Some(SourceChange { + Some(SourceChange { label: "rename".to_string(), source_file_edits: edit, file_system_edits: Vec::new(), cursor_position: None, - }); + }) } #[cfg(test)] diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index 72c93f530..9f939c650 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs @@ -137,7 +137,7 @@ impl SymbolIndex { symbols.par_sort_by(cmp); symbols.dedup_by(|s1, s2| cmp(s1, s2) == Ordering::Equal); let names = symbols.iter().map(|it| it.name.as_str().to_lowercase()); - let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap(); + let map = fst::Map::from_iter(names.zip(0u64..)).unwrap(); SymbolIndex { symbols, map } } -- cgit v1.2.3