Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromRef triggers clippy::clone_of_ref_ptr #2826

Closed
1 task done
AlphaKeks opened this issue Jul 9, 2024 · 1 comment
Closed
1 task done

FromRef triggers clippy::clone_of_ref_ptr #2826

AlphaKeks opened this issue Jul 9, 2024 · 1 comment
Labels
A-axum-macros E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@AlphaKeks
Copy link
Contributor

  • I have looked for existing issues (including closed) about this

Bug Report

Version

0.7.5

Platform

Linux 6.6.34 #1-NixOS SMP PREEMPT_DYNAMIC Sun Jun 16 11:47:49 UTC 2024 x86_64 GNU/Linux

Description

When deriving FromRef, clippy will trigger clippy::clone_on_ref_ptr. This lint is allow-by-default, which is probably why nobody reported it yet.

You can reproduce the issue by adding axum@0.7.5 as a dependency with the macros feature enabled, and writing the following code:

use std::sync::Arc;

use axum::extract::FromRef;

#[derive(Clone, FromRef)]
pub struct MyState {
	substate: Arc<MySubstate>,
}

pub struct MySubstate {}

And then running clippy with the offending lint set to warn (or higher):

$ cargo clippy -- -Wclippy::clone_on_ref_ptr

warning: using `.clone()` on a ref-counted pointer
 --> src/lib.rs:7:12
  |
7 |     substate: Arc<MySubstate>,
  |               ^^^ help: try: `Arc::<MySubstate>::clone(&substate: Arc)`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_ref_ptr
  = note: requested on the command line with `-W clippy::clone-on-ref-ptr`

I would assume adding a clippy::clone_on_ref_ptr to the #[allow(…)] attribute on this line would fix the problem. I can open a PR if that's a fine solution.

@jplatte
Copy link
Member

jplatte commented Jul 9, 2024

I would assume adding a clippy::clone_on_ref_ptr to the #[allow(…)] attribute on this line would fix the problem. I can open a PR if that's a fine solution.

Sounds good!

@jplatte jplatte added E-easy Call for participation: Experience needed to fix: Easy / not much A-axum-macros labels Jul 9, 2024
AlphaKeks added a commit to AlphaKeks/axum that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum-macros E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

No branches or pull requests

2 participants