mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-21 22:56:46 +01:00
Fix warnings for cloning references in generated code (#1676)
This commit is contained in:
parent
2d8242b2c5
commit
b6c282a2b7
2 changed files with 16 additions and 2 deletions
|
@ -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 _,
|
||||
|
|
10
axum-macros/tests/from_ref/pass/reference-types.rs
Normal file
10
axum-macros/tests/from_ref/pass/reference-types.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#![deny(noop_method_call)]
|
||||
|
||||
use axum_macros::FromRef;
|
||||
|
||||
#[derive(FromRef)]
|
||||
struct State {
|
||||
inner: &'static str,
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in a new issue