|
2 | 2 | //!
|
3 | 3 | //! The attribute-checking parts of this try to follow `rustc_passes::check_attr`.
|
4 | 4 |
|
5 |
| -use crate::symbols::Symbols; |
| 5 | +use crate::symbols::{Symbols, parse_attrs_for_checking}; |
6 | 6 | use rspirv::spirv::{BuiltIn, ExecutionMode, ExecutionModel, StorageClass};
|
7 | 7 | use rustc_hir as hir;
|
8 | 8 | use rustc_hir::def_id::LocalModDefId;
|
@@ -146,12 +146,16 @@ impl AggregatedSpirvAttributes {
|
146 | 146 | ///
|
147 | 147 | /// Any errors for malformed/duplicate attributes will have been reported
|
148 | 148 | /// prior to codegen, by the `attr` check pass.
|
149 |
| - pub fn parse<'tcx>(tcx: TyCtxt<'tcx>, sym: &Symbols, attrs: &'tcx [Attribute]) -> Self { |
| 149 | + pub fn parse<'tcx>( |
| 150 | + tcx: TyCtxt<'tcx>, |
| 151 | + sym: &Symbols, |
| 152 | + attrs: impl Iterator<Item = &'tcx Attribute>, |
| 153 | + ) -> Self { |
150 | 154 | let mut aggregated_attrs = Self::default();
|
151 | 155 |
|
152 | 156 | // NOTE(eddyb) `span_delayed_bug` ensures that if attribute checking fails
|
153 | 157 | // to see an attribute error, it will cause an ICE instead.
|
154 |
| - for parse_attr_result in crate::symbols::parse_attrs_for_checking(sym, attrs) { |
| 158 | + for parse_attr_result in parse_attrs_for_checking(sym, attrs) { |
155 | 159 | let (span, parsed_attr) = match parse_attr_result {
|
156 | 160 | Ok(span_and_parsed_attr) => span_and_parsed_attr,
|
157 | 161 | Err((span, msg)) => {
|
@@ -276,10 +280,8 @@ impl CheckSpirvAttrVisitor<'_> {
|
276 | 280 | fn check_spirv_attributes(&self, hir_id: HirId, target: Target) {
|
277 | 281 | let mut aggregated_attrs = AggregatedSpirvAttributes::default();
|
278 | 282 |
|
279 |
| - let parse_attrs = |attrs| crate::symbols::parse_attrs_for_checking(&self.sym, attrs); |
280 |
| - |
281 | 283 | let attrs = self.tcx.hir_attrs(hir_id);
|
282 |
| - for parse_attr_result in parse_attrs(attrs) { |
| 284 | + for parse_attr_result in parse_attrs_for_checking(&self.sym, attrs.into_iter()) { |
283 | 285 | let (span, parsed_attr) = match parse_attr_result {
|
284 | 286 | Ok(span_and_parsed_attr) => span_and_parsed_attr,
|
285 | 287 | Err((span, msg)) => {
|
@@ -324,9 +326,12 @@ impl CheckSpirvAttrVisitor<'_> {
|
324 | 326 | | SpirvAttribute::SpecConstant(_) => match target {
|
325 | 327 | Target::Param => {
|
326 | 328 | let parent_hir_id = self.tcx.parent_hir_id(hir_id);
|
327 |
| - let parent_is_entry_point = parse_attrs(self.tcx.hir_attrs(parent_hir_id)) |
328 |
| - .filter_map(|r| r.ok()) |
329 |
| - .any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_))); |
| 329 | + let parent_is_entry_point = parse_attrs_for_checking( |
| 330 | + &self.sym, |
| 331 | + self.tcx.hir_attrs(parent_hir_id).iter(), |
| 332 | + ) |
| 333 | + .filter_map(|r| r.ok()) |
| 334 | + .any(|(_, attr)| matches!(attr, SpirvAttribute::Entry(_))); |
330 | 335 | if !parent_is_entry_point {
|
331 | 336 | self.tcx.dcx().span_err(
|
332 | 337 | span,
|
|
0 commit comments