mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
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
2 changed files with 9 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue