Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Reject empty struct types. (#1826)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy authored Apr 14, 2022
1 parent 170faab commit f11d27a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,8 @@ pub enum TypeInner {

/// User-defined structure.
///
/// There must always be at least one member.
///
/// A `Struct` type is [`DATA`], and the types of its members must be
/// `DATA` as well.
///
Expand Down
6 changes: 6 additions & 0 deletions src/valid/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ pub enum TypeError {
size: u32,
span: u32,
},
#[error("Structure types must have at least one member")]
EmptyStruct,
}

// Only makes sense if `flags.contains(HOST_SHARED)`
Expand Down Expand Up @@ -451,6 +453,10 @@ impl super::Validator {
}
}
Ti::Struct { ref members, span } => {
if members.is_empty() {
return Err(TypeError::EmptyStruct);
}

let mut ti = TypeInfo::new(
TypeFlags::DATA
| TypeFlags::SIZED
Expand Down
8 changes: 8 additions & 0 deletions tests/wgsl-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,14 @@ fn invalid_structs() {
..
})
}

check_validation_error! {
"struct Empty {}":
Err(naga::valid::ValidationError::Type {
error: naga::valid::TypeError::EmptyStruct,
..
})
}
}

#[test]
Expand Down

0 comments on commit f11d27a

Please sign in to comment.