]> git.lizzy.rs Git - rust.git/commitdiff
Remove redundant clone()
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Wed, 25 Sep 2019 01:32:01 +0000 (10:32 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Wed, 25 Sep 2019 01:32:01 +0000 (10:32 +0900)
14 files changed:
crates/ra_assists/src/merge_match_arms.rs
crates/ra_cli/src/main.rs
crates/ra_hir/src/adt.rs
crates/ra_hir/src/code_model.rs
crates/ra_hir/src/from_source.rs
crates/ra_hir/src/nameres/collector.rs
crates/ra_hir/src/nameres/raw.rs
crates/ra_hir/src/source_binder.rs
crates/ra_hir/src/ty/infer.rs
crates/ra_hir/src/ty/method_resolution.rs
crates/ra_ide_api/src/completion/completion_context.rs
crates/ra_ide_api/src/completion/presentation.rs
crates/ra_ide_api/src/diagnostics.rs
crates/ra_ide_api/src/display/navigation_target.rs

index 225a48d3adc60ea953a0bbfe9f0e6213780f9ccf..3b6a99895d485953e8b73aba640cee7af9b39288 100644 (file)
@@ -8,7 +8,7 @@ pub(crate) fn merge_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<A
     // We check if the following match arm matches this one. We could, but don't,
     // compare to the previous match arm as well.
     let next = current_arm.syntax().next_sibling();
-    let next_arm = MatchArm::cast(next?.clone())?;
+    let next_arm = MatchArm::cast(next?)?;
 
     // Don't try to handle arms with guards for now - can add support for this later
     if current_arm.guard().is_some() || next_arm.guard().is_some() {
index 7aacf515d195d6079ba10ee9efaaf1a8973abdc9..8b91ba3e95fbd254599c919576e3bb32475977e4 100644 (file)
@@ -93,7 +93,7 @@ fn main() -> Result<()> {
                 (true, true) => Err("Invalid flags: -q conflicts with -v")?,
             };
             let memory_usage = matches.contains("--memory-usage");
-            let only = matches.value_from_str(["-o", "--only"])?.map(|v: String| v.to_owned());
+            let only: Option<String> = matches.value_from_str(["-o", "--only"])?;
             let path = {
                 let mut trailing = matches.free()?;
                 if trailing.len() != 1 {
index 56f2b7aa36d330a32de5ba44f5a5654973767e82..fbb4ff4d8483e1fde6b44c82184a90b9b7994013 100644 (file)
@@ -56,8 +56,7 @@ pub(crate) fn source_impl(
             .zip(db.enum_data(self.parent).variants.iter())
             .find(|(_syntax, (id, _))| *id == self.id)
             .unwrap()
-            .0
-            .to_owned();
+            .0;
         Source { file_id: src.file_id, ast }
     }
     pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
@@ -203,12 +202,8 @@ pub(crate) fn source_impl(&self, db: &(impl DefDatabase + AstDatabase)) -> Sourc
         };
 
         let field_sources = match struct_kind {
-            ast::StructKind::Tuple(fl) => {
-                fl.fields().map(|it| FieldSource::Pos(it.to_owned())).collect()
-            }
-            ast::StructKind::Named(fl) => {
-                fl.fields().map(|it| FieldSource::Named(it.to_owned())).collect()
-            }
+            ast::StructKind::Tuple(fl) => fl.fields().map(|it| FieldSource::Pos(it)).collect(),
+            ast::StructKind::Named(fl) => fl.fields().map(|it| FieldSource::Named(it)).collect(),
             ast::StructKind::Unit => Vec::new(),
         };
         let ast = field_sources
index 99c247a0b296e2bef6ba8137692cfddbe7520954..9fecba63d1a58538de0039e70e56c06135dff094 100644 (file)
@@ -161,7 +161,7 @@ pub(crate) fn new(
     ) -> ModuleSource {
         match (file_id, decl_id) {
             (Some(file_id), _) => {
-                let source_file = db.parse(file_id).tree().to_owned();
+                let source_file = db.parse(file_id).tree();
                 ModuleSource::SourceFile(source_file)
             }
             (None, Some(item_id)) => {
index f3194595f702915039631e2ab94b16b69831bf65..7b6d9b2407cbdd35b3abf90ab7c6c10ebe6eb1eb 100644 (file)
@@ -137,7 +137,7 @@ pub fn from_position(
         match &find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) {
             Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()),
             _ => {
-                let source_file = parse.tree().to_owned();
+                let source_file = parse.tree();
                 ModuleSource::SourceFile(source_file)
             }
         }
@@ -149,15 +149,15 @@ pub fn from_child_node(
         child: &SyntaxNode,
     ) -> ModuleSource {
         if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) {
-            ModuleSource::Module(m.clone())
+            ModuleSource::Module(m)
         } else {
-            let source_file = db.parse(file_id).tree().to_owned();
+            let source_file = db.parse(file_id).tree();
             ModuleSource::SourceFile(source_file)
         }
     }
 
     pub fn from_file_id(db: &(impl DefDatabase + AstDatabase), file_id: FileId) -> ModuleSource {
-        let source_file = db.parse(file_id).tree().to_owned();
+        let source_file = db.parse(file_id).tree();
         ModuleSource::SourceFile(source_file)
     }
 }
index 6b253ac409e0863bfa7c56dc913b615b572c72a9..ef7dc6ebe3f69ad7304a2ec49dbbd112b65eedc3 100644 (file)
@@ -166,7 +166,7 @@ fn define_macro(
         // In Rust, `#[macro_export]` macros are unconditionally visible at the
         // crate root, even if the parent modules is **not** visible.
         if export {
-            self.update(self.def_map.root, None, &[(name.clone(), Resolution::from_macro(macro_))]);
+            self.update(self.def_map.root, None, &[(name, Resolution::from_macro(macro_))]);
         }
     }
 
index 8bf883ac2fe88ac153276cd6a69a51064747fcce..29aaddbf1b020cf58e26b1ff641ec5f765321d13 100644 (file)
@@ -36,10 +36,7 @@ pub struct ImportSourceMap {
 
 impl ImportSourcePtr {
     fn to_node(self, file: &SourceFile) -> ImportSource {
-        self.map(
-            |ptr| ptr.to_node(file.syntax()).to_owned(),
-            |ptr| ptr.to_node(file.syntax()).to_owned(),
-        )
+        self.map(|ptr| ptr.to_node(file.syntax()), |ptr| ptr.to_node(file.syntax()))
     }
 }
 
index 296acc3642a49d9a0e8b368a04e537e625158237..bd4be843014088fbc7f25dee898d3a5bfe8aa8b5 100644 (file)
@@ -73,7 +73,7 @@ fn def_with_body_from_child_node(
         if let Some(def) = ast::ConstDef::cast(node.clone()) {
             return Some(Const { id: ctx.to_def(&def) }.into());
         }
-        if let Some(def) = ast::StaticDef::cast(node.clone()) {
+        if let Some(def) = ast::StaticDef::cast(node) {
             return Some(Static { id: ctx.to_def(&def) }.into());
         }
         None
index 378d2f829e13a38d0f2aa84c218285954301c93e..76b4b6faa459dd672ba393c0aeb461db62366b0d 100644 (file)
@@ -436,7 +436,7 @@ fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty {
 
     fn normalize_projection_ty(&mut self, proj_ty: ProjectionTy) -> Ty {
         let var = self.new_type_var();
-        let predicate = ProjectionPredicate { projection_ty: proj_ty.clone(), ty: var.clone() };
+        let predicate = ProjectionPredicate { projection_ty: proj_ty, ty: var.clone() };
         let obligation = Obligation::Projection(predicate);
         self.obligations.push(obligation);
         var
@@ -953,7 +953,7 @@ fn infer_expr_inner(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty {
                     arm_tys.push(self.infer_expr_inner(arm.expr, &expected));
                 }
 
-                let lub_ty = calculate_least_upper_bound(expected.ty.clone(), &arm_tys);
+                let lub_ty = calculate_least_upper_bound(expected.ty, &arm_tys);
 
                 for arm_ty in &arm_tys {
                     self.coerce(arm_ty, &lub_ty);
index 8b46b11a9c4d4ee0c28b732e1de319eaf63c1f18..a967d8a7f38c3d8c0deefc01ff92288a25a061e3 100644 (file)
@@ -290,7 +290,7 @@ pub(crate) fn implements_trait(
         return true;
     }
     let env = lower::trait_env(db, resolver);
-    let goal = generic_implements_goal(db, env.clone(), trait_, ty.clone());
+    let goal = generic_implements_goal(db, env, trait_, ty.clone());
     let solution = db.trait_solve(krate, goal);
 
     solution.is_some()
index 59bd3689b51668f62eb8ee9f2590633855cf4e63..57542152f730fe6c2bf6d461583ff741febe2813 100644 (file)
@@ -94,7 +94,7 @@ fn fill(&mut self, original_parse: &'a Parse<ast::SourceFile>, offset: TextUnit)
         // actual completion.
         let file = {
             let edit = AtomTextEdit::insert(offset, "intellijRulezz".to_string());
-            original_parse.reparse(&edit).tree().to_owned()
+            original_parse.reparse(&edit).tree()
         };
 
         // First, let's try to complete a reference to some declaration.
index ad414412b14f1fd8d1ea956a108a37659bc43787..b8aa433c181e9d254b59f529dc4b0252d1c896e4 100644 (file)
@@ -76,7 +76,7 @@ pub(crate) fn add_resolution(
                 None,
             ),
             ScopeDef::MacroDef(mac) => {
-                self.add_macro(ctx, Some(local_name.clone()), *mac);
+                self.add_macro(ctx, Some(local_name), *mac);
                 return;
             }
             ScopeDef::Unknown => {
index 1ae152e5b107917b7b3bf648e022f549e9e8df3f..93e1e7c2d4a6995af6a33027269c66a74936439f 100644 (file)
@@ -86,7 +86,7 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
             fix: Some(fix),
         })
     });
-    let source_file = db.parse(file_id).tree().to_owned();
+    let source_file = db.parse(file_id).tree();
     let src =
         hir::Source { file_id: file_id.into(), ast: hir::ModuleSource::SourceFile(source_file) };
     if let Some(m) = hir::Module::from_definition(db, src) {
index 11f73ccfd02e1128137a2edb9d7249301a46b8d1..d3e774bd0dbb3fe86919af06f457149c856332d2 100644 (file)
@@ -304,7 +304,7 @@ fn from_syntax(
 
 pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
     let parse = db.parse(symbol.file_id);
-    let node = symbol.ptr.to_node(parse.tree().syntax()).to_owned();
+    let node = symbol.ptr.to_node(parse.tree().syntax());
 
     visitor()
         .visit(|it: ast::FnDef| it.doc_comment_text())
@@ -326,7 +326,7 @@ pub(crate) fn docs_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option
 /// e.g. `struct Name`, `enum Name`, `fn Name`
 pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> Option<String> {
     let parse = db.parse(symbol.file_id);
-    let node = symbol.ptr.to_node(parse.tree().syntax()).to_owned();
+    let node = symbol.ptr.to_node(parse.tree().syntax());
 
     visitor()
         .visit(|node: ast::FnDef| node.short_label())