Merge pull request #923 from TheAwiteb/fix-hide-attr-bug-work-as-MetaNameValueStr

Fix hide attr bug work as meta name value str
This commit is contained in:
Waffle Maybe 2023-09-09 08:54:23 +00:00 committed by GitHub
commit 9b7e5957cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -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<Path> {
// 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(),

View file

@ -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`, \