bevy_derive: Fix #[deref]
breaking other attributes (#9551)
# Objective Fixes #9550 ## Solution Removes a check that asserts that _all_ attribute metas are path-only, rather than just the `#[deref]` attribute itself. --- ## Changelog - Fixes an issue where deriving `Deref` with `#[deref]` on a field causes other attributes to sometimes result in a compile error --------- Co-authored-by: François <mockersf@gmail.com>
This commit is contained in:
parent
5012a0fd57
commit
b7d68873ec
@ -68,10 +68,12 @@ fn get_deref_field(ast: &DeriveInput, is_mut: bool) -> syn::Result<(Member, &Typ
|
|||||||
let mut selected_field: Option<(Member, &Type)> = None;
|
let mut selected_field: Option<(Member, &Type)> = None;
|
||||||
for (index, field) in data_struct.fields.iter().enumerate() {
|
for (index, field) in data_struct.fields.iter().enumerate() {
|
||||||
for attr in &field.attrs {
|
for attr in &field.attrs {
|
||||||
if !attr.meta.require_path_only()?.is_ident(DEREF_ATTR) {
|
if !attr.meta.path().is_ident(DEREF_ATTR) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attr.meta.require_path_only()?;
|
||||||
|
|
||||||
if selected_field.is_some() {
|
if selected_field.is_some() {
|
||||||
return Err(syn::Error::new_spanned(
|
return Err(syn::Error::new_spanned(
|
||||||
attr,
|
attr,
|
||||||
|
@ -5,9 +5,13 @@ struct TupleStruct(usize, #[deref] String);
|
|||||||
|
|
||||||
#[derive(Deref)]
|
#[derive(Deref)]
|
||||||
struct Struct {
|
struct Struct {
|
||||||
|
// Works with other attributes
|
||||||
|
#[cfg(test)]
|
||||||
foo: usize,
|
foo: usize,
|
||||||
#[deref]
|
#[deref]
|
||||||
bar: String,
|
bar: String,
|
||||||
|
/// Also works with doc comments.
|
||||||
|
baz: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -15,8 +19,10 @@ fn main() {
|
|||||||
let _: &String = &*value;
|
let _: &String = &*value;
|
||||||
|
|
||||||
let value = Struct {
|
let value = Struct {
|
||||||
|
#[cfg(test)]
|
||||||
foo: 123,
|
foo: 123,
|
||||||
bar: "Hello world!".to_string(),
|
bar: "Hello world!".to_string(),
|
||||||
|
baz: 321,
|
||||||
};
|
};
|
||||||
let _: &String = &*value;
|
let _: &String = &*value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user