Skip to content

Commit c1c1354

Browse files
Merge #832
832: C argument names that conflict with rust keywords are given a gd_ prefix. r=Bromeon a=IamTheCarl Fixes: #753 This feature existed in previous iterations of godot-rust, but this patch improves the implementation to cover all known keywords as of today. Co-authored-by: I am the Carl <[email protected]>
2 parents 9b48dee + 65550ca commit c1c1354

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

bindings_generator/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,28 @@ fn generate_class_bindings(
158158
}
159159
}
160160

161+
#[rustfmt::skip]
161162
fn rust_safe_name(name: &str) -> proc_macro2::Ident {
163+
// Keywords obtained from https://doc.rust-lang.org/reference/keywords.html
162164
match name {
163-
"use" => format_ident!("_use"),
164-
"type" => format_ident!("_type"),
165-
"loop" => format_ident!("_loop"),
166-
"in" => format_ident!("_in"),
167-
"override" => format_ident!("_override"),
168-
"where" => format_ident!("_where"),
169-
"enum" => format_ident!("_enum"),
170-
name => format_ident!("{}", name),
165+
// Lexer 2015
166+
"as" | "break" | "const" | "continue" | "crate" | "else" | "enum" | "extern" | "false" | "fn" | "for" |
167+
"if" | "impl" | "in" | "let" | "loop" | "match" | "mod" | "move" | "mut" | "pub" | "ref" | "return" |
168+
"self" | "Self" | "static" | "struct" | "super" | "trait" | "true" | "type" | "unsafe" | "use" |
169+
"where" | "while" |
170+
171+
// Lexer 2018
172+
"async" | "await" | "dyn" |
173+
174+
// Lexer 2018+
175+
"try" |
176+
177+
// Reserved words
178+
"abstract" | "become" | "box" | "do" | "final" | "macro" | "override" | "priv" | "typeof" |
179+
"unsized" | "virtual" | "yield"
180+
=> format_ident!("{}_", name),
181+
182+
_ => format_ident!("{}", name)
171183
}
172184
}
173185

0 commit comments

Comments
 (0)