From d44c3cd15009797ef37ba03abf35a4482980bd10 Mon Sep 17 00:00:00 2001 From: Yilin Wei Date: Sun, 2 Jan 2022 23:28:18 +0000 Subject: [PATCH] Fix error message for the `Component` macro's `component` `storage` attribute. (#3534) # Objective Fixes the error message for the `component` attribute when users use the wrong literals. --- crates/bevy_ecs/macros/src/component.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/bevy_ecs/macros/src/component.rs b/crates/bevy_ecs/macros/src/component.rs index d1d58615964aa..ab1e52bdb88d9 100644 --- a/crates/bevy_ecs/macros/src/component.rs +++ b/crates/bevy_ecs/macros/src/component.rs @@ -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 { let meta_items = bevy_macro_utils::parse_attrs(ast, COMPONENT)?; @@ -58,14 +62,14 @@ fn parse_component_attr(ast: &DeriveInput) -> Result { 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 ), )) }