@@ -198,8 +198,32 @@ impl<'a> Helper<'a> {
198198 Pointer ( t) => Self :: Indirection ( IndirectionKind :: Pointer , t) ,
199199 Atomic ( t) => Self :: Indirection ( IndirectionKind :: Atomic , t) ,
200200 Array ( len, item) => Self :: Array ( len, item) ,
201- Struct ( name, fields) => Self :: Container ( ContainerKind :: Struct , name, fields) ,
202- Union ( name, members) => Self :: Container ( ContainerKind :: Union , name, members) ,
201+ Struct ( name, fields) => {
202+ if !verify_name ( name) {
203+ panic ! ( "Struct name was not a valid identifier" ) ;
204+ }
205+ Self :: Container ( ContainerKind :: Struct , name, fields)
206+ }
207+ Union ( name, members) => {
208+ if !verify_name ( name) {
209+ panic ! ( "Union name was not a valid identifier" ) ;
210+ }
211+ Self :: Container ( ContainerKind :: Union , name, members)
212+ }
203213 }
204214 }
205215}
216+
217+ /// Check whether the name is a valid identifier
218+ const fn verify_name ( name : & str ) -> bool {
219+ let bytes = name. as_bytes ( ) ;
220+ let mut i = 0 ;
221+ while i < bytes. len ( ) {
222+ let byte = bytes[ i] ;
223+ if !( byte. is_ascii_alphanumeric ( ) || byte == b'_' ) {
224+ return false ;
225+ }
226+ i += 1 ;
227+ }
228+ true
229+ }
0 commit comments