From f770921a4fc7fc972b9fe00a841831b886e83f10 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 7 Mar 2024 21:37:42 -0800 Subject: [PATCH] Resolve assigning_clones clippy lint warning: assigning the result of `Clone::clone()` may be inefficient --> impl/src/ast.rs:85:21 | 85 | *display = attrs.display.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `display.clone_from(&attrs.display)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones = note: `#[warn(clippy::assigning_clones)]` on by default warning: assigning the result of `Clone::clone()` may be inefficient --> impl/src/expand.rs:158:9 | 158 | display_implied_bounds = display.implied_bounds.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `display_implied_bounds.clone_from(&display.implied_bounds)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones warning: assigning the result of `Clone::clone()` may be inefficient --> impl/src/expand.rs:402:21 | 402 | display_implied_bounds = display.implied_bounds.clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `display_implied_bounds.clone_from(&display.implied_bounds)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones --- impl/src/ast.rs | 2 +- impl/src/expand.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/impl/src/ast.rs b/impl/src/ast.rs index 9e06928..4739d58 100644 --- a/impl/src/ast.rs +++ b/impl/src/ast.rs @@ -82,7 +82,7 @@ impl<'a> Enum<'a> { .map(|node| { let mut variant = Variant::from_syn(node, &scope, span)?; if let display @ None = &mut variant.attrs.display { - *display = attrs.display.clone(); + display.clone_from(&attrs.display); } if let Some(display) = &mut variant.attrs.display { display.expand_shorthand(&variant.fields); diff --git a/impl/src/expand.rs b/impl/src/expand.rs index 1b44513..296b567 100644 --- a/impl/src/expand.rs +++ b/impl/src/expand.rs @@ -155,7 +155,7 @@ fn impl_struct(input: Struct) -> TokenStream { ::core::fmt::Display::fmt(&self.#only_field, __formatter) }) } else if let Some(display) = &input.attrs.display { - display_implied_bounds = display.implied_bounds.clone(); + display_implied_bounds.clone_from(&display.implied_bounds); let use_as_display = use_as_display(display.has_bonus_display); let pat = fields_pat(&input.fields); Some(quote! { @@ -399,7 +399,7 @@ fn impl_enum(input: Enum) -> TokenStream { let mut display_implied_bounds = Set::new(); let display = match &variant.attrs.display { Some(display) => { - display_implied_bounds = display.implied_bounds.clone(); + display_implied_bounds.clone_from(&display.implied_bounds); display.to_token_stream() } None => {