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:
Gino Valente 2023-08-28 10:36:18 -07:00 committed by GitHub
parent 5012a0fd57
commit b7d68873ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -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;
for (index, field) in data_struct.fields.iter().enumerate() {
for attr in &field.attrs {
if !attr.meta.require_path_only()?.is_ident(DEREF_ATTR) {
if !attr.meta.path().is_ident(DEREF_ATTR) {
continue;
}
attr.meta.require_path_only()?;
if selected_field.is_some() {
return Err(syn::Error::new_spanned(
attr,

View file

@ -5,9 +5,13 @@ struct TupleStruct(usize, #[deref] String);
#[derive(Deref)]
struct Struct {
// Works with other attributes
#[cfg(test)]
foo: usize,
#[deref]
bar: String,
/// Also works with doc comments.
baz: i32,
}
fn main() {
@ -15,8 +19,10 @@ fn main() {
let _: &String = &*value;
let value = Struct {
#[cfg(test)]
foo: 123,
bar: "Hello world!".to_string(),
baz: 321,
};
let _: &String = &*value;
}