From 8e01ff64fe5ed4e15a56dce2acd85574ae5a9d0c Mon Sep 17 00:00:00 2001 From: acdenisSK Date: Sat, 18 May 2019 19:58:38 +0200 Subject: [PATCH] Report errors from parsing group options, if any --- Cargo.toml | 1 + command_attr/src/structures.rs | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8dd0410444d..d77382b6c96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ optional = true version = "0.1" [dependencies.command_attr] +path = "./command_attr" version = "0.1.0-rc" optional = true diff --git a/command_attr/src/structures.rs b/command_attr/src/structures.rs index f8807d52dd2..445e964de6f 100644 --- a/command_attr/src/structures.rs +++ b/command_attr/src/structures.rs @@ -1,6 +1,6 @@ use crate::consts::{COMMAND, GROUP, GROUP_OPTIONS, CHECK}; use crate::util::{ - Argument, Array, AsOption, Expr, Field, IdentAccess, IdentExt2, LitExt, Object, ParseStreamExt, + Argument, Array, AsOption, Expr, Field, IdentAccess, IdentExt2, LitExt, Object, RefOrInstance, }; use proc_macro2::TokenStream as TokenStream2; @@ -731,20 +731,16 @@ impl Parse for Group { input.parse::()?; - let options = if let Ok(f) = input.try_parse::>>() { - if f.name != "options" { - return Err(Error::new( - f.name.span(), - "the options of a group must be labeled as `options`", - )); - } + let Field { name: oname, value: options } = input.parse::>>()?; - input.parse::()?; + if oname != "options" { + return Err(Error::new( + oname.span(), + "every group must have some `options`", + )); + } - Some(f.value) - } else { - None - }; + input.parse::()?; let commands = input.parse::()?; if commands != "commands" { @@ -789,7 +785,7 @@ impl Parse for Group { Ok(Group { name, - options: options.unwrap_or_default(), + options, commands: content.parse_terminated(Ident::parse_any)?, sub_groups, })