servo: Merge #10674 - Avoid generating parameter names that are Rust keywords (from KiChjang:codegen-avoid-rust-keywords); r=Manishearth
authorKeith Yeung <kungfukeith11@gmail.com>
Mon, 18 Apr 2016 04:41:13 +0500
changeset 338554 695dff3081c62ca8900d081a05b589b66df72adf
parent 338553 4e98e59deea7fec255ad98581060cfc1fab6d772
child 338555 8a6e55212441ffb3bd42e833b0f04a04c1ccf9a0
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #10674 - Avoid generating parameter names that are Rust keywords (from KiChjang:codegen-avoid-rust-keywords); r=Manishearth Source-Repo: https://github.com/servo/servo Source-Revision: f93379ff4e33a74922b859ac2be14c43c58ec24f
servo/components/script/dom/bindings/codegen/CodegenRust.py
--- a/servo/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/servo/components/script/dom/bindings/codegen/CodegenRust.py
@@ -31,16 +31,23 @@ from Configuration import (
 
 AUTOGENERATED_WARNING_COMMENT = \
     "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
 FINALIZE_HOOK_NAME = '_finalize'
 TRACE_HOOK_NAME = '_trace'
 CONSTRUCT_HOOK_NAME = '_constructor'
 HASINSTANCE_HOOK_NAME = '_hasInstance'
 
+RUST_KEYWORDS = {"abstract", "alignof", "as", "become", "box", "break", "const", "continue",
+                 "else", "enum", "extern", "false", "final", "fn", "for", "if", "impl", "in",
+                 "let", "loop", "macro", "match", "mod", "move", "mut", "offsetof", "override",
+                 "priv", "proc", "pub", "pure", "ref", "return", "static", "self", "sizeof",
+                 "struct", "super", "true", "trait", "type", "typeof", "unsafe", "unsized",
+                 "use", "virtual", "where", "while", "yield"}
+
 
 def replaceFileIfChanged(filename, newContents):
     """
     Read a copy of the old file, so that we don't touch it if it hasn't changed.
     Returns True if the file was updated, false otherwise.
     """
     # XXXjdm This doesn't play well with make right now.
     #       Force the file to always be updated, or else changing CodegenRust.py
@@ -5242,17 +5249,17 @@ class CGDictionary(CGThing):
             "    },\n"
             "}\n}") % (member.identifier.name, indent(conversion), indent(default))
 
         return CGGeneric(conversion)
 
     @staticmethod
     def makeMemberName(name):
         # Can't use Rust keywords as member names.
-        if name == "type":
+        if name in RUST_KEYWORDS:
             return name + "_"
         return name
 
     @staticmethod
     def getDictionaryDependencies(dictionary):
         deps = set()
         if dictionary.parent:
             deps.add(dictionary.parent)