Some clippy cleanups

This commit is contained in:
kjeremy 2019-02-06 15:50:26 -05:00
parent c1e10a24fa
commit 6753051a45
15 changed files with 49 additions and 55 deletions

View file

@ -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() {

View file

@ -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,

View file

@ -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");

View file

@ -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()

View file

@ -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)]

View file

@ -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 }
}