Ensure the generated name doesn't collide with existing constants. If it does, append a numeric suffix.
(name: &str, existing: &[String])
| 347 | /// Ensure the generated name doesn't collide with existing constants. |
| 348 | /// If it does, append a numeric suffix. |
| 349 | fn deduplicate_constant_name(name: &str, existing: &[String]) -> String { |
| 350 | if !existing.iter().any(|e| e == name) { |
| 351 | return name.to_string(); |
| 352 | } |
| 353 | for i in 1u32.. { |
| 354 | let candidate = format!("{}_{}", name, i); |
| 355 | if !existing.iter().any(|e| e == &candidate) { |
| 356 | return candidate; |
| 357 | } |
| 358 | } |
| 359 | unreachable!() |
| 360 | } |
| 361 | |
| 362 | // ─── AST helpers ──────────────────────────────────────────────────────────── |
| 363 |