Skip to content

Commit

Permalink
Fix error message for the Component macro's component storage a…
Browse files Browse the repository at this point in the history
…ttribute. (#3534)

# Objective

Fixes the error message for the `component` attribute when users use the wrong literals.
  • Loading branch information
yilinwei committed Jan 2, 2022
1 parent a6d3cd9 commit d44c3cd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/bevy_ecs/macros/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ enum StorageTy {
SparseSet,
}

// values for `storage` attribute
const TABLE: &str = "Table";
const SPARSE_SET: &str = "SparseSet";

fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
let meta_items = bevy_macro_utils::parse_attrs(ast, COMPONENT)?;

Expand All @@ -58,14 +62,14 @@ fn parse_component_attr(ast: &DeriveInput) -> Result<Attrs> {
match meta {
Meta(NameValue(m)) if m.path == STORAGE => {
attrs.storage = match get_lit_str(STORAGE, &m.lit)?.value().as_str() {
"Table" => StorageTy::Table,
"SparseSet" => StorageTy::SparseSet,
TABLE => StorageTy::Table,
SPARSE_SET => StorageTy::SparseSet,
s => {
return Err(Error::new_spanned(
m.lit,
format!(
"Invalid storage type `{}`, expected 'table' or 'sparse'.",
s
"Invalid storage type `{}`, expected '{}' or '{}'.",
s, TABLE, SPARSE_SET
),
))
}
Expand Down

0 comments on commit d44c3cd

Please sign in to comment.