Fix warnings for cloning references in generated code (#1676)

This commit is contained in:
Alexander Jackson 2023-01-05 13:50:02 +03:00 committed by GitHub
parent 2d8242b2c5
commit b6c282a2b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -3,7 +3,7 @@ use quote::quote_spanned;
use syn::{
parse::{Parse, ParseStream},
spanned::Spanned,
Field, ItemStruct, Token,
Field, ItemStruct, Token, Type,
};
use crate::attr_parsing::{combine_unary_attribute, parse_attrs, Combine};
@ -30,7 +30,11 @@ fn expand_field(state: &Ident, idx: usize, field: &Field) -> TokenStream {
let span = field.ty.span();
let body = if let Some(field_ident) = &field.ident {
quote_spanned! {span=> state.#field_ident.clone() }
if matches!(field_ty, Type::Reference(_)) {
quote_spanned! {span=> state.#field_ident }
} else {
quote_spanned! {span=> state.#field_ident.clone() }
}
} else {
let idx = syn::Index {
index: idx as _,

View file

@ -0,0 +1,10 @@
#![deny(noop_method_call)]
use axum_macros::FromRef;
#[derive(FromRef)]
struct State {
inner: &'static str,
}
fn main() {}