mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 06:45:23 +00:00
shader struct name replacing (#2484)
Co-authored-by: Firestar99 <4696087-firestar99@users.noreply.gitlab.com>
This commit is contained in:
parent
37e6120d3c
commit
1b7dfc9814
@ -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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user