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

Rustc and clippy warnings generated by derive(FromRef) #1674

Closed
1 task done
Garmelon opened this issue Jan 3, 2023 · 0 comments · Fixed by #1676
Closed
1 task done

Rustc and clippy warnings generated by derive(FromRef) #1674

Garmelon opened this issue Jan 3, 2023 · 0 comments · Fixed by #1676
Labels
A-axum-macros C-enhancement Category: A PR with an enhancement E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@Garmelon
Copy link

Garmelon commented Jan 3, 2023

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

Bug Report

Version

  • axum v0.6.1
  • axum-core v0.3.0
  • axum-macros v0.3.0 (proc-macro)

Platform

Linux alpha 6.1.1 #1-NixOS SMP PREEMPT_DYNAMIC Wed Dec 21 16:48:12 UTC 2022 x86_64 GNU/Linux

Crates

axum-macros

Description

When deriving FromRef for &'static Something, the following lints are triggered by the generated code:

  • clippy::clone_double_ref (deny by default)
  • noop_method_call (allow by default)

I expect the generated code to cause no errors, possibly by suppressing the ones mentioned above.

Minimal example:

#![warn(noop_method_call)]

#[derive(axum::extract::FromRef)]
struct State {
    foo: &'static str,
}
@davidpdrsn davidpdrsn added A-axum-macros C-enhancement Category: A PR with an enhancement E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. labels Jan 3, 2023
alexander-jackson added a commit to alexander-jackson/axum that referenced this issue Jan 3, 2023
In tokio-rs#1674, it was pointed out that `axum-macros` causes some `clippy`
warnings (and some `rustc` lints to fail) as the `FromRef` macro
generates code which clones reference types unnecessarily.

This seems to be when generating the body of the trait implementation,
but since we have the type information from `syn` at that point it's
relatively simple to resolve these.

This change:
* Avoids using `.clone` if we are generating the implementation for a
  reference type field
* Adds a simple UI test to ensure this compiles with the `rustc` lint
  set to deny

Fixes tokio-rs#1674.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-axum-macros C-enhancement Category: A PR with an enhancement E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants