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
This commit is contained in:
David Tolnay 2024-03-07 21:37:42 -08:00
parent 1d106b169c
commit f770921a4f
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 3 additions and 3 deletions

View file

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

View file

@ -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 => {