From 048dad8c2e86006e53b3a134279729efb28b9e32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Wed, 17 Mar 2021 01:56:31 +0100 Subject: don't clone types that are copy (clippy::clone_on_copy) --- crates/hir_expand/src/hygiene.rs | 7 ++----- crates/ide/src/doc_links.rs | 4 ++-- crates/ide/src/goto_definition.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 2 +- .../ide_assists/src/handlers/extract_struct_from_enum_variant.rs | 7 ++----- crates/ide_completion/src/completions/pattern.rs | 4 ++-- crates/ide_completion/src/render.rs | 2 +- crates/ide_ssr/src/lib.rs | 7 ++----- crates/ide_ssr/src/matching.rs | 2 +- crates/mbe/src/benchmark.rs | 5 ++--- crates/mbe/src/parser.rs | 2 +- crates/rust-analyzer/src/diagnostics/to_proto.rs | 2 +- 12 files changed, 18 insertions(+), 28 deletions(-) diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs index c8ea81210..87cad326d 100644 --- a/crates/hir_expand/src/hygiene.rs +++ b/crates/hir_expand/src/hygiene.rs @@ -23,7 +23,7 @@ pub struct Hygiene { impl Hygiene { pub fn new(db: &dyn AstDatabase, file_id: HirFileId) -> Hygiene { - Hygiene { frames: Some(HygieneFrames::new(db, file_id.clone())) } + Hygiene { frames: Some(HygieneFrames::new(db, file_id)) } } pub fn new_unhygienic() -> Hygiene { @@ -129,10 +129,7 @@ impl HygieneInfo { mbe::Origin::Call => (&self.macro_arg.1, self.arg_start), mbe::Origin::Def => ( &self.macro_def.1, - self.def_start - .as_ref() - .expect("`Origin::Def` used with non-`macro_rules!` macro") - .clone(), + *self.def_start.as_ref().expect("`Origin::Def` used with non-`macro_rules!` macro"), ), }; diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 461e11060..5ea9fc4fb 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -93,7 +93,7 @@ pub(crate) fn remove_links(markdown: &str) -> String { let mut cb = |_: BrokenLink| { let empty = InlineStr::try_from("").unwrap(); - Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty))) + Some((CowStr::Inlined(empty), CowStr::Inlined(empty))) }; let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb)); let doc = doc.filter_map(move |evt| match evt { @@ -147,7 +147,7 @@ fn get_doc_link(db: &RootDatabase, definition: Definition) -> Option { _ => return None, }; - let ns = ItemInNs::from(target_def.clone()); + let ns = ItemInNs::from(target_def); let module = definition.module(db)?; let krate = module.krate(); diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 6986477a5..b71f4917c 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -102,7 +102,7 @@ fn extract_positioned_link_from_comment( None => comment_range.end(), } })?; - Some((def_link.to_string(), ns.clone())) + Some((def_link.to_string(), *ns)) } fn pick_best(tokens: TokenAtOffset) -> Option { diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 8cdc3688f..4f825523c 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -56,7 +56,7 @@ pub(super) fn ra_fixture( for range in inj.map_range_up(hl_range.range) { if let Some(range) = literal.map_range_up(range) { hl_range.range = range; - hl.add(hl_range.clone()); + hl.add(hl_range); } } } diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 335e0ed95..596c536a7 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs @@ -145,11 +145,8 @@ fn insert_import( variant_hir_name: &Name, ) -> Option<()> { let db = ctx.db(); - let mod_path = module.find_use_path_prefixed( - db, - enum_module_def.clone(), - ctx.config.insert_use.prefix_kind, - ); + let mod_path = + module.find_use_path_prefixed(db, *enum_module_def, ctx.config.insert_use.prefix_kind); if let Some(mut mod_path) = mod_path { mod_path.pop_segment(); mod_path.push_segment(variant_hir_name.clone()); diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index 46cef58f0..476eecff0 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs @@ -26,11 +26,11 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { let add_resolution = match &res { hir::ScopeDef::ModuleDef(def) => match def { hir::ModuleDef::Adt(hir::Adt::Struct(strukt)) => { - acc.add_struct_pat(ctx, strukt.clone(), Some(name.clone())); + acc.add_struct_pat(ctx, *strukt, Some(name.clone())); true } hir::ModuleDef::Variant(variant) if !ctx.is_irrefutable_pat_binding => { - acc.add_variant_pat(ctx, variant.clone(), Some(name.clone())); + acc.add_variant_pat(ctx, *variant, Some(name.clone())); true } hir::ModuleDef::Adt(hir::Adt::Enum(..)) diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 4e4923e0d..12921e12b 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs @@ -81,7 +81,7 @@ impl<'a> RenderContext<'a> { } fn snippet_cap(&self) -> Option { - self.completion.config.snippet_cap.clone() + self.completion.config.snippet_cap } fn db(&self) -> &'a RootDatabase { diff --git a/crates/ide_ssr/src/lib.rs b/crates/ide_ssr/src/lib.rs index 00585f448..47434f4af 100644 --- a/crates/ide_ssr/src/lib.rs +++ b/crates/ide_ssr/src/lib.rs @@ -139,11 +139,8 @@ impl<'db> MatchFinder<'db> { pub fn at_first_file(db: &'db ide_db::RootDatabase) -> Result, SsrError> { use ide_db::base_db::SourceDatabaseExt; use ide_db::symbol_index::SymbolsDatabase; - if let Some(first_file_id) = db - .local_roots() - .iter() - .next() - .and_then(|root| db.source_root(root.clone()).iter().next()) + if let Some(first_file_id) = + db.local_roots().iter().next().and_then(|root| db.source_root(*root).iter().next()) { Ok(MatchFinder::in_context( db, diff --git a/crates/ide_ssr/src/matching.rs b/crates/ide_ssr/src/matching.rs index e1adb381e..b3072fb9f 100644 --- a/crates/ide_ssr/src/matching.rs +++ b/crates/ide_ssr/src/matching.rs @@ -127,7 +127,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { restrict_range: &Option, sema: &'sema Semantics<'db, ide_db::RootDatabase>, ) -> Result { - let match_state = Matcher { sema, restrict_range: restrict_range.clone(), rule }; + let match_state = Matcher { sema, restrict_range: *restrict_range, rule }; // First pass at matching, where we check that node types and idents match. match_state.attempt_match_node(&mut Phase::First, &rule.pattern.node, code)?; match_state.validate_range(&sema.original_range(code))?; diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index bd8ea6452..ba814a2e1 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs @@ -165,7 +165,7 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt } Separator::Puncts(puncts) => { for it in puncts { - parent.token_trees.push(tt::Leaf::Punct(it.clone()).into()) + parent.token_trees.push(tt::Leaf::Punct(*it).into()) } } }; @@ -174,8 +174,7 @@ fn invocation_fixtures(rules: &FxHashMap) -> Vec<(String, tt } } Op::Subtree { tokens, delimiter } => { - let mut subtree = - tt::Subtree { delimiter: delimiter.clone(), token_trees: Vec::new() }; + let mut subtree = tt::Subtree { delimiter: *delimiter, token_trees: Vec::new() }; tokens.iter().for_each(|it| { collect_from_op(it, &mut subtree, seed); }); diff --git a/crates/mbe/src/parser.rs b/crates/mbe/src/parser.rs index 8671322e1..7b5b8ec16 100644 --- a/crates/mbe/src/parser.rs +++ b/crates/mbe/src/parser.rs @@ -262,7 +262,7 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option, RepeatKind), Par if puncts.len() == 3 { return Err(ParseError::InvalidRepeat); } - puncts.push(punct.clone()) + puncts.push(*punct) } _ => return Err(ParseError::InvalidRepeat), } diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index 0ad832c0e..76994de71 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -161,7 +161,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( return Vec::new(); } - let severity = diagnostic_severity(config, rd.level.clone(), rd.code.clone()); + let severity = diagnostic_severity(config, rd.level, rd.code.clone()); let mut source = String::from("rustc"); let mut code = rd.code.as_ref().map(|c| c.code.clone()); -- cgit v1.2.3