]> git.lizzy.rs Git - rust.git/commitdiff
Some clippy cleanups
authorkjeremy <kjeremy@gmail.com>
Wed, 6 Feb 2019 20:50:26 +0000 (15:50 -0500)
committerkjeremy <kjeremy@gmail.com>
Wed, 6 Feb 2019 20:50:26 +0000 (15:50 -0500)
15 files changed:
crates/ra_assists/src/introduce_variable.rs
crates/ra_hir/src/expr.rs
crates/ra_hir/src/expr/scope.rs
crates/ra_hir/src/impl_block.rs
crates/ra_hir/src/resolve.rs
crates/ra_hir/src/ty.rs
crates/ra_hir/src/ty/method_resolution.rs
crates/ra_ide_api/src/completion/completion_context.rs
crates/ra_ide_api/src/completion/completion_item.rs
crates/ra_ide_api/src/goto_definition.rs
crates/ra_ide_api/src/lib.rs
crates/ra_ide_api/src/rename.rs
crates/ra_ide_api/src/symbol_index.rs
crates/ra_lsp_server/src/conv.rs
crates/ra_lsp_server/src/main_loop/handlers.rs

index c937a816cdaecd2c25c95c43bc59c8009bc30ecd..f587b4fe6e1c2a80619cb7abe8df3b9ceb70260f 100644 (file)
@@ -8,7 +8,7 @@
 
 use crate::{AssistCtx, Assist};
 
-pub(crate) fn introduce_variable<'a>(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
+pub(crate) fn introduce_variable(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
     let node = ctx.covering_node();
     if !valid_covering_node(node) {
         return None;
@@ -61,13 +61,13 @@ fn valid_covering_node(node: &SyntaxNode) -> bool {
 /// Check wether the node is a valid expression which can be extracted to a variable.
 /// In general that's true for any expression, but in some cases that would produce invalid code.
 fn valid_target_expr(node: &SyntaxNode) -> Option<&ast::Expr> {
-    return match node.kind() {
+    match node.kind() {
         PATH_EXPR => None,
         BREAK_EXPR => ast::BreakExpr::cast(node).and_then(|e| e.expr()),
         RETURN_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
         LOOP_EXPR => ast::ReturnExpr::cast(node).and_then(|e| e.expr()),
         _ => ast::Expr::cast(node),
-    };
+    }
 }
 
 /// Returns the syntax node which will follow the freshly introduced var
index f9f702ae2bd276c493412065d0cb99691d32e08b..6826e966bff36a975cdd0a32a60c139e62354a5f 100644 (file)
@@ -805,7 +805,7 @@ fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId {
                 let lit = match child.flavor() {
                     LiteralFlavor::IntNumber { suffix } => {
                         let known_name = suffix
-                            .map(|s| Name::new(s))
+                            .map(Name::new)
                             .and_then(|name| UncertainIntTy::from_name(&name));
 
                         Literal::Int(
@@ -815,7 +815,7 @@ fn collect_expr(&mut self, expr: &ast::Expr) -> ExprId {
                     }
                     LiteralFlavor::FloatNumber { suffix } => {
                         let known_name = suffix
-                            .map(|s| Name::new(s))
+                            .map(Name::new)
                             .and_then(|name| UncertainFloatTy::from_name(&name));
 
                         Literal::Float(
@@ -910,7 +910,7 @@ fn collect_pat(&mut self, pat: &ast::Pat) -> PatId {
             }
             ast::PatKind::PathPat(p) => {
                 let path = p.path().and_then(Path::from_ast);
-                path.map(|path| Pat::Path(path)).unwrap_or(Pat::Missing)
+                path.map(Pat::Path).unwrap_or(Pat::Missing)
             }
             ast::PatKind::TuplePat(p) => {
                 let args = p.args().map(|p| self.collect_pat(p)).collect();
index 9202e367126edc5785e1b31a610b420bc892a941..368994bf7cf2de64474f695a0bb7c989c3e184b4 100644 (file)
@@ -105,7 +105,7 @@ fn add_bindings(&mut self, body: &Body, scope: ScopeId, pat: PatId) {
     fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) {
         let body = Arc::clone(&self.body);
         params
-            .into_iter()
+            .iter()
             .for_each(|pat| self.add_bindings(&body, scope, *pat));
     }
 
@@ -147,7 +147,7 @@ fn scope_chain<'a>(&'a self, node: &SyntaxNode) -> impl Iterator<Item = ScopeId>
         })
     }
 
-    pub fn scope_for_offset<'a>(&'a self, offset: TextUnit) -> Option<ScopeId> {
+    pub fn scope_for_offset(&self, offset: TextUnit) -> Option<ScopeId> {
         self.scopes
             .scope_for
             .iter()
index 738c58fbe88a9102add56fe7470309fa0f0b62da..094dbedb3593f43edf1763a8e4b3d3eb6c3de3b2 100644 (file)
@@ -72,7 +72,7 @@ fn impl_data(&self) -> &ImplData {
     }
 
     pub fn module(&self) -> Module {
-        self.module_impl_blocks.module.clone()
+        self.module_impl_blocks.module
     }
 
     pub fn target_trait_ref(&self) -> Option<&TypeRef> {
index 5ca7bacb5d86ed29979aafc7d08e59136f7c2a62..0f60d47423954b9a8552ad8cb21a6c8a5a5dc938 100644 (file)
@@ -78,7 +78,7 @@ pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resoluti
                 _ => return PerNs::none(),
             };
             let module_res = item_map.resolve_path(db, module, path);
-            module_res.map(|def| Resolution::Def(def))
+            module_res.map(Resolution::Def)
         }
     }
 
index cc5afad7533dca791ce3a2315656355c1e533d86..86a7f8b8378972144a529d2900b3afd17dda5b85 100644 (file)
@@ -1225,7 +1225,7 @@ fn infer_pat(&mut self, pat: PatId, expected: &Ty) -> Ty {
                     Ty::Tuple(ref tuple_args) => &**tuple_args,
                     _ => &[],
                 };
-                let expectations_iter = expectations.into_iter().chain(repeat(&Ty::Unknown));
+                let expectations_iter = expectations.iter().chain(repeat(&Ty::Unknown));
 
                 let inner_tys = args
                     .iter()
@@ -1398,10 +1398,10 @@ fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
                 let method_ty = self.insert_type_vars(method_ty);
                 let (expected_receiver_ty, param_tys, ret_ty) = match &method_ty {
                     Ty::FnPtr(sig) => {
-                        if sig.input.len() > 0 {
+                        if !sig.input.is_empty() {
                             (
                                 sig.input[0].clone(),
-                                sig.input[1..].iter().cloned().collect(),
+                                sig.input[1..].to_vec(),
                                 sig.output.clone(),
                             )
                         } else {
@@ -1411,7 +1411,7 @@ fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
                     Ty::FnDef { substs, sig, .. } => {
                         let ret_ty = sig.output.clone().subst(&substs);
 
-                        if sig.input.len() > 0 {
+                        if !sig.input.is_empty() {
                             let mut arg_iter = sig.input.iter().map(|ty| ty.clone().subst(&substs));
                             let receiver_ty = arg_iter.next().unwrap();
                             (receiver_ty, arg_iter.collect(), ret_ty)
index 2282286b0b83f69f3e14baab4719b72615eacffc..a7d4517eecf88ba7cb25ef257ce142003d8fc8e7 100644 (file)
@@ -113,7 +113,7 @@ pub(crate) fn impls_in_crate_query(
         krate: Crate,
     ) -> Arc<CrateImplBlocks> {
         let mut crate_impl_blocks = CrateImplBlocks {
-            krate: krate.clone(),
+            krate,
             impls: FxHashMap::default(),
             impls_by_trait: FxHashMap::default(),
         };
index 5d1851da649752328fc23c5c8bff36d07bcde3dd..8abab02215e3e694eb077c4cf36ceb83fd4eeb45 100644 (file)
@@ -130,12 +130,9 @@ fn classify_name_ref(&mut self, original_file: &'a SourceFile, name_ref: &ast::N
             .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() {
index bada6a33bf25cda892449f948371b08f2dd66626..92e6e78bf9a7ba4716d7ec7153af7b325f030363 100644 (file)
@@ -108,11 +108,11 @@ pub fn lookup(&self) -> &str {
         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 @@ pub(super) fn from_resolution(
         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,
index 88efcea2a57368808f4c36ad8b3729495dd1dbd8..681f36623d9fc96c83fcc6ded10660884d018067 100644 (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");
index 8beaba5de3b6d12dbd39d2c2b028e0a878ce432e..68d59aae19b38ce0ea4569dca853a2451cad05fd 100644 (file)
@@ -117,7 +117,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         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()
index db5ccf96945bde7e835ffbb0bfd161bfd5102763..1c9491a0a385e7a9f29b20431b425c195764635e 100644 (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)]
index 72c93f5304bcfe80312155f7e0c420799cc6bccd..9f939c650c9bd35ec01043f71284c5a21439412f 100644 (file)
@@ -137,7 +137,7 @@ fn cmp(s1: &FileSymbol, s2: &FileSymbol) -> Ordering {
         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 }
     }
 
index 17fa073406b286d1e324cc50d6139112f3f0f432..98138546622b08c89d7f63bc6999434d6052ec34 100644 (file)
@@ -169,10 +169,7 @@ impl ConvWith for TextEdit {
     type Output = Vec<lsp_types::TextEdit>;
 
     fn conv_with(self, line_index: &LineIndex) -> Vec<lsp_types::TextEdit> {
-        self.as_atoms()
-            .into_iter()
-            .map_conv_with(line_index)
-            .collect()
+        self.as_atoms().iter().map_conv_with(line_index).collect()
     }
 }
 
@@ -394,7 +391,7 @@ pub fn to_location_link(
         origin_selection_range: Some(target.range.conv_with(line_index)),
         target_uri,
         target_range,
-        target_selection_range: target_selection_range,
+        target_selection_range,
     };
     Ok(res)
 }
index ab2b81bf042b6c486b758f5ecdd9afd33051e4e1..aa55d12553327e28101ab69116d054adcd588c2b 100644 (file)
@@ -123,7 +123,7 @@ pub fn handle_on_type_formatting(
     let edit = edit.source_file_edits.pop().unwrap();
 
     let change: Vec<TextEdit> = edit.edit.conv_with(&line_index);
-    return Ok(Some(change));
+    Ok(Some(change))
 }
 
 pub fn handle_document_symbol(
@@ -319,7 +319,7 @@ pub fn handle_runnables(
         args: check_args,
         env: FxHashMap::default(),
     });
-    return Ok(res);
+    Ok(res)
 }
 
 pub fn handle_decorations(
@@ -622,10 +622,8 @@ pub fn handle_code_lens(
     // Gather runnables
     for runnable in world.analysis().runnables(file_id)? {
         let title = match &runnable.kind {
-            RunnableKind::Test { name: _ } | RunnableKind::TestMod { path: _ } => {
-                Some("▶️Run Test")
-            }
-            RunnableKind::Bench { name: _ } => Some("Run Bench"),
+            RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => Some("▶️Run Test"),
+            RunnableKind::Bench { .. } => Some("Run Bench"),
             _ => None,
         };
 
@@ -679,7 +677,7 @@ pub fn handle_code_lens(
             }),
     );
 
-    return Ok(Some(lenses));
+    Ok(Some(lenses))
 }
 
 #[derive(Debug, Serialize, Deserialize)]
@@ -722,22 +720,20 @@ pub fn handle_code_lens_resolve(world: ServerWorld, code_lens: CodeLens) -> Resu
                     to_value(locations).unwrap(),
                 ]),
             };
-            return Ok(CodeLens {
+            Ok(CodeLens {
                 range: code_lens.range,
                 command: Some(cmd),
                 data: None,
-            });
-        }
-        None => {
-            return Ok(CodeLens {
-                range: code_lens.range,
-                command: Some(Command {
-                    title: "Error".into(),
-                    ..Default::default()
-                }),
-                data: None,
-            });
+            })
         }
+        None => Ok(CodeLens {
+            range: code_lens.range,
+            command: Some(Command {
+                title: "Error".into(),
+                ..Default::default()
+            }),
+            data: None,
+        }),
     }
 }