Skip to content

Commit 8cc80d7

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

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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. Now it supports only parentheses.
8+
9+
```rust
10+
/// before
11+
#[derive(Clone, Reflect)
12+
#[reflect[Clone]]
13+
14+
/// after
15+
#[derive(Clone, Reflect)
16+
#[reflect(Clone)]
17+
18+
/// before
19+
#[derive(Clone, Reflect)
20+
#[reflect{Clone}]
21+
22+
/// after
23+
#[derive(Clone, Reflect)
24+
#[reflect(Clone)]
25+
```

0 commit comments

Comments
 (0)