Skip to content

Commit 077625a

Browse files
committed
Allow only parentheses in #[reflect(...)]
Fixes #8906
1 parent 1fd3bfb commit 077625a

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

crates/bevy_reflect/derive/src/derive_data.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
};
1515
use bevy_macro_utils::ResultSifter;
1616
use quote::{format_ident, quote, ToTokens};
17-
use syn::token::Comma;
17+
use syn::{token::Comma, MacroDelimiter};
1818

1919
use crate::enum_utility::{EnumVariantOutputData, ReflectCloneVariantBuilder, VariantBuilder};
2020
use crate::field_attributes::CloneBehavior;
@@ -197,7 +197,16 @@ impl<'a> ReflectDerive<'a> {
197197
for attribute in &input.attrs {
198198
match &attribute.meta {
199199
Meta::List(meta_list) if meta_list.path.is_ident(REFLECT_ATTRIBUTE_NAME) => {
200-
container_attributes.parse_meta_list(meta_list, provenance.trait_)?;
200+
if let MacroDelimiter::Paren(_) = meta_list.delimiter {
201+
container_attributes.parse_meta_list(meta_list, provenance.trait_)?;
202+
} else {
203+
return Err(syn::Error::new(
204+
meta_list.delimiter.span().join(),
205+
format_args!(
206+
"`#[{REFLECT_ATTRIBUTE_NAME}(\"...\")]` must use parentheses `(` and `)`"
207+
),
208+
));
209+
}
201210
}
202211
Meta::NameValue(pair) if pair.path.is_ident(TYPE_PATH_ATTRIBUTE_NAME) => {
203212
let syn::Expr::Lit(syn::ExprLit {

crates/bevy_render/src/sync_world.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl Plugin for SyncWorldPlugin {
119119
/// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin
120120
/// [`SyncComponentPlugin`]: crate::sync_component::SyncComponentPlugin
121121
#[derive(Component, Copy, Clone, Debug, Default, Reflect)]
122-
#[reflect[Component, Default, Clone]]
122+
#[reflect(Component, Default, Clone)]
123123
#[component(storage = "SparseSet")]
124124
pub struct SyncToRenderWorld;
125125

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: "`#[reflect(...)]` now supports only parentheses"
3+
pull_requests: [21400]
4+
---
5+
6+
Previously, the `#[reflect(...)]` attribute of the `Reflect` derive macro
7+
supported parentheses, braces, or brackets, to standardize the syntax going
8+
forward, it now supports only parentheses.
9+
10+
```rust
11+
/// before
12+
#[derive(Clone, Reflect)
13+
#[reflect[Clone]]
14+
15+
/// after
16+
#[derive(Clone, Reflect)
17+
#[reflect(Clone)]
18+
19+
/// before
20+
#[derive(Clone, Reflect)
21+
#[reflect{Clone}]
22+
23+
/// after
24+
#[derive(Clone, Reflect)
25+
#[reflect(Clone)]
26+
```

0 commit comments

Comments
 (0)