Skip to content

Commit 65550ca

Browse files
IamTheCarlBromeon
authored andcommitted
Expanded rust_safe_name to have full vocabulary.
Signed-off-by: Jan Haller <[email protected]>
1 parent 9b48dee commit 65550ca

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)