@@ -261,17 +261,23 @@ use syn::*;
261
261
/// Trait that sanitizes name avoiding rust keywords and the like.
262
262
trait SanitizeName {
263
263
/// Sanitize a name; avoiding Rust keywords and the like.
264
- fn sanitize ( & self ) -> String ;
264
+ fn sanitize ( self ) -> String ;
265
265
}
266
266
267
267
impl SanitizeName for String {
268
- fn sanitize ( & self ) -> String {
269
- match self . as_str ( ) {
270
- "fn" => "fn_" . to_owned ( ) ,
271
- "in" => "in_" . to_owned ( ) ,
272
- "match" => "match_" . to_owned ( ) ,
273
- "mod" => "mod_" . to_owned ( ) ,
274
- _ => self . to_owned ( ) ,
268
+ fn sanitize ( self ) -> String {
269
+ const KEYWORDS : [ & ' static str ; 52 ] =
270
+ [ "abstract" , "alignof" , "as" , "become" , "box" , "break" , "const" , "continue" , "crate" ,
271
+ "do" , "else" , "enum" , "extern" , "false" , "final" , "fn" , "for" , "if" , "impl" , "in" ,
272
+ "let" , "loop" , "macro" , "match" , "mod" , "move" , "mut" , "offsetof" , "override" ,
273
+ "priv" , "proc" , "pub" , "pure" , "ref" , "return" , "Self" , "self" , "sizeof" , "static" ,
274
+ "struct" , "super" , "trait" , "true" , "type" , "typeof" , "unsafe" , "unsized" , "use" ,
275
+ "virtual" , "where" , "while" , "yield" ] ;
276
+
277
+ if KEYWORDS . contains ( & self . as_str ( ) ) {
278
+ self + "_"
279
+ } else {
280
+ self
275
281
}
276
282
}
277
283
}
0 commit comments