FIXME(eddyb) maybe move this to `attr`?
(
sym: &'a Symbols,
attrs: &'a [Attribute],
)
| 422 | |
| 423 | // FIXME(eddyb) maybe move this to `attr`? |
| 424 | pub(crate) fn parse_attrs_for_checking<'a>( |
| 425 | sym: &'a Symbols, |
| 426 | attrs: &'a [Attribute], |
| 427 | ) -> impl Iterator<Item = Result<(Span, SpirvAttribute), ParseAttrError>> + 'a { |
| 428 | attrs.iter().flat_map(move |attr| { |
| 429 | let (whole_attr_error, args) = match attr.kind { |
| 430 | AttrKind::Normal(ref normal) => { |
| 431 | // #[...] |
| 432 | let s = &normal.item.path.segments; |
| 433 | if s.len() > 1 && s[0].ident.name == sym.rust_gpu { |
| 434 | // #[rust_gpu ...] |
| 435 | if s.len() != 2 || s[1].ident.name != sym.spirv { |
| 436 | // #[rust_gpu::...] but not #[rust_gpu::spirv] |
| 437 | ( |
| 438 | Some(Err(( |
| 439 | attr.span, |
| 440 | "unknown `rust_gpu` attribute, expected `rust_gpu::spirv`" |
| 441 | .to_string(), |
| 442 | ))), |
| 443 | Default::default(), |
| 444 | ) |
| 445 | } else if let Some(args) = attr.meta_item_list() { |
| 446 | // #[rust_gpu::spirv(...)] |
| 447 | (None, args) |
| 448 | } else { |
| 449 | // #[rust_gpu::spirv] |
| 450 | ( |
| 451 | Some(Err(( |
| 452 | attr.span, |
| 453 | "#[rust_gpu::spirv(..)] attribute must have at least one argument" |
| 454 | .to_string(), |
| 455 | ))), |
| 456 | Default::default(), |
| 457 | ) |
| 458 | } |
| 459 | } else { |
| 460 | // #[...] but not #[rust_gpu ...] |
| 461 | (None, Default::default()) |
| 462 | } |
| 463 | } |
| 464 | AttrKind::DocComment(..) => (None, Default::default()), // doccomment |
| 465 | }; |
| 466 | |
| 467 | whole_attr_error |
| 468 | .into_iter() |
| 469 | .chain(args.into_iter().map(move |ref arg| { |
| 470 | let span = arg.span(); |
| 471 | let parsed_attr = if arg.has_name(sym.descriptor_set) { |
| 472 | SpirvAttribute::DescriptorSet(parse_attr_int_value(arg)?) |
| 473 | } else if arg.has_name(sym.binding) { |
| 474 | SpirvAttribute::Binding(parse_attr_int_value(arg)?) |
| 475 | } else if arg.has_name(sym.input_attachment_index) { |
| 476 | SpirvAttribute::InputAttachmentIndex(parse_attr_int_value(arg)?) |
| 477 | } else if arg.has_name(sym.spec_constant) { |
| 478 | SpirvAttribute::SpecConstant(parse_spec_constant_attr(sym, arg)?) |
| 479 | } else { |
| 480 | let name = match arg.ident() { |
| 481 | Some(i) => i, |
no test coverage detected