MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / parse_spec_constant_attr

Function parse_spec_constant_attr

crates/rustc_codegen_spirv/src/symbols.rs:507–537  ·  view source on GitHub ↗
(
    sym: &Symbols,
    arg: &NestedMetaItem,
)

Source from the content-addressed store, hash-verified

505}
506
507fn 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
539fn parse_attr_int_value(arg: &NestedMetaItem) -> Result<u32, ParseAttrError> {
540 let arg = match arg.meta_item() {

Callers 1

parse_attrs_for_checkingFunction · 0.85

Calls 2

parse_attr_int_valueFunction · 0.85
spanMethod · 0.80

Tested by

no test coverage detected