diff --git a/crates/teloxide-macros/src/attr.rs b/crates/teloxide-macros/src/attr.rs index 9f872946..a52aff01 100644 --- a/crates/teloxide-macros/src/attr.rs +++ b/crates/teloxide-macros/src/attr.rs @@ -87,6 +87,17 @@ impl AttrValue { }) } + /// Unwraps this value if it's a nothing. + pub fn expect_none(self, option_name: &str) -> Result<()> { + match self { + AttrValue::None(_) => Ok(()), + _ => Err(compile_error_at( + &format!("The {option_name} option should not have a value, remove it"), + self.span(), + )), + } + } + // /// Unwraps this value if it's a path. // pub fn expect_path(self) -> Result { // self.expect("a path", |this| match this { @@ -124,7 +135,7 @@ impl AttrValue { /// #[blahblah(key = "puff", value = 12, nope )] /// ^^^^^^ ^^ ^ /// ``` - fn span(&self) -> Span { + pub fn span(&self) -> Span { match self { Self::Path(p) => p.span(), Self::Lit(l) => l.span(), diff --git a/crates/teloxide-macros/src/command_attr.rs b/crates/teloxide-macros/src/command_attr.rs index 5c916a7b..1e01aed1 100644 --- a/crates/teloxide-macros/src/command_attr.rs +++ b/crates/teloxide-macros/src/command_attr.rs @@ -104,7 +104,7 @@ impl CommandAttr { "rename" => Rename(value.expect_string()?), "parse_with" => ParseWith(ParserType::parse(value)?), "separator" => Separator(value.expect_string()?), - "hide" => Hide, + "hide" => value.expect_none("hide").map(|_| Hide)?, _ => { return Err(compile_error_at( "unexpected attribute name (expected one of `prefix`, `description`, \