shader struct name replacing (#2484)

Co-authored-by: Firestar99 <4696087-firestar99@users.noreply.gitlab.com>
This commit is contained in:
Firestar99 2024-03-03 15:47:23 +01:00 committed by GitHub
parent 37e6120d3c
commit 1b7dfc9814
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -690,9 +690,15 @@ impl TypeStruct {
.iter() .iter()
.find_map(|instruction| match instruction { .find_map(|instruction| match instruction {
Instruction::Name { name, .. } => { Instruction::Name { name, .. } => {
// rust-gpu uses fully qualified rust paths as names which contain `:`. // Replace chars that could potentially cause the ident to be invalid with "_".
// I sady don't know how to check against all kinds of invalid ident chars. // For example, Rust-GPU names structs by their fully qualified rust name (e.g.
let name = name.replace(':', "_"); // "foo::bar::MyStruct") in which the ":" is an invalid character for idents.
let mut name =
name.replace(|c: char| !(c.is_ascii_alphanumeric() || c == '_'), "_");
if name.starts_with(|c: char| !c.is_ascii_alphabetic()) {
name.insert(0, '_');
}
// Worst case: invalid idents will get the UnnamedX name below // Worst case: invalid idents will get the UnnamedX name below
syn::parse_str(&name).ok() syn::parse_str(&name).ok()
} }