Skip to content

Commit

Permalink
Merge #812
Browse files Browse the repository at this point in the history
812: Extend safe name filter to support Godot 3.4 API r=Bromeon a=lufterc

This PR adds 'enum' keyword to rust_safe_name filter and also makes use of this filter for rusty_method_name variable in bindings generator. It allows to build godot-rust with latest stable Godot 3.4 API.

A bit of context: when trying to build bindings for latest stable Godot API, the following errors are produced:
```
error: expected expression, found keyword `enum`
1972 | ..., self . this . sys () . as_ptr () , class . into () , enum . into () , no_inheritance) ; StringArray :: from_sys (ret) } } # [doc = "...
     |                                                           ^^^^ expected expression

error: expected identifier, found keyword `type`
2302 | ... } # [doc = ""] # [doc = ""] # [inline] pub fn type (& self) -> GodotString { unsafe { let method_bind : * mut sys :: godot_method_bin...
     |                                                   ^^^^ expected identifier, found keyword
```
It seems that newer API version introduces more keyword collisions which this patch aims to fix.

Co-authored-by: lufterc <[email protected]>
  • Loading branch information
bors[bot] and mivort authored Nov 8, 2021
2 parents cc96860 + d64f175 commit 06110f9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions bindings_generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn rust_safe_name(name: &str) -> proc_macro2::Ident {
"in" => format_ident!("_in"),
"override" => format_ident!("_override"),
"where" => format_ident!("_where"),
"enum" => format_ident!("_enum"),
name => format_ident!("{}", name),
}
}
Expand Down
2 changes: 1 addition & 1 deletion bindings_generator/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ pub(crate) fn generate_methods(

icalls.insert(icall_name.clone(), method_sig);

let rusty_name = format_ident!("{}", rusty_method_name);
let rusty_name = rust_safe_name(rusty_method_name);

let maybe_unsafe: TokenStream;
let maybe_unsafe_reason: &str;
Expand Down

0 comments on commit 06110f9

Please sign in to comment.