Skip to content

Commit 35be953

Browse files
bors[bot]Bromeon
andauthored
Merge #840
840: Fix unresolved enum name in bindings generator r=Bromeon a=Bromeon Example: when using godot-rust with the VoxelTools engine module, the api.json has many nested `Result` types. In some occurrences, these identifiers are prefixed with the containing class, e.g. `VoxelStreamResult`. However, some references to these type names are not using the prefixed identifier, thus creating compile errors (see commit message for details). This PR addresses this by prefixing other occurrences, when enums are constructed. Co-authored-by: Jan Haller <[email protected]>
2 parents b2a9832 + 8270899 commit 35be953

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

bindings_generator/src/api.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use heck::ToPascalCase as _;
1+
use super::classes::generate_enum_name;
2+
use miniserde::Deserialize;
23
use proc_macro2::TokenStream;
34
use quote::{format_ident, quote};
45
use std::collections::{HashMap, HashSet};
56

6-
use miniserde::Deserialize;
77
miniserde::make_place!(Place);
88

99
pub struct Api {
@@ -400,7 +400,8 @@ impl Ty {
400400
// Enums may reference known types (above list), check if it's a known type first
401401
let mut split = ty[5..].split("::");
402402
let class_name = split.next().unwrap();
403-
let name = format_ident!("{}", split.next().unwrap().to_pascal_case());
403+
let enum_raw_name = split.next().unwrap();
404+
let name = format_ident!("{}", generate_enum_name(class_name, enum_raw_name));
404405
let module = format_ident!("{}", module_name_from_class_name(class_name));
405406
// Is it a known type?
406407
match Ty::from_src(class_name) {

bindings_generator/src/classes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub(crate) fn generate_enums(class: &GodotClass) -> TokenStream {
143143
}
144144
}
145145

146-
fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
146+
pub(crate) fn generate_enum_name(class_name: &str, enum_name: &str) -> String {
147147
// In order to not pollute the API with more Result types,
148148
// rename the Result enum used by Search to SearchResult.
149149
// to_pascal_case() is used to make the enums more rust-like.

0 commit comments

Comments
 (0)