(
sym: &Symbols,
arg: &NestedMetaItem,
)
| 505 | } |
| 506 | |
| 507 | fn parse_spec_constant_attr( |
| 508 | sym: &Symbols, |
| 509 | arg: &NestedMetaItem, |
| 510 | ) -> Result<SpecConstant, ParseAttrError> { |
| 511 | let mut id = None; |
| 512 | let mut default = None; |
| 513 | |
| 514 | if let Some(attrs) = arg.meta_item_list() { |
| 515 | for attr in attrs { |
| 516 | if attr.has_name(sym.id) { |
| 517 | if id.is_none() { |
| 518 | id = Some(parse_attr_int_value(attr)?); |
| 519 | } else { |
| 520 | return Err((attr.span(), "`id` may only be specified once".into())); |
| 521 | } |
| 522 | } else if attr.has_name(sym.default) { |
| 523 | if default.is_none() { |
| 524 | default = Some(parse_attr_int_value(attr)?); |
| 525 | } else { |
| 526 | return Err((attr.span(), "`default` may only be specified once".into())); |
| 527 | } |
| 528 | } else { |
| 529 | return Err((attr.span(), "expected `id = ...` or `default = ...`".into())); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | Ok(SpecConstant { |
| 534 | id: id.ok_or_else(|| (arg.span(), "expected `spec_constant(id = ...)`".into()))?, |
| 535 | default, |
| 536 | }) |
| 537 | } |
| 538 | |
| 539 | fn parse_attr_int_value(arg: &NestedMetaItem) -> Result<u32, ParseAttrError> { |
| 540 | let arg = match arg.meta_item() { |
no test coverage detected