Skip to content

Commit

Permalink
Resolve assigning_clones clippy lint
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
dtolnay committed Mar 8, 2024
1 parent 1d106b1 commit f770921
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion impl/src/ast.rs
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions impl/src/expand.rs
Expand Up @@ -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! {
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit f770921

Please sign in to comment.