Escape getter identifier to use type keyword. am: 5be7b7bc14 am: 183572a69f

Original change: https://android-review.googlesource.com/c/platform/system/tools/sysprop/+/2743738

Change-Id: I34529732afa30a8967482e6245e3394aa5e4a30e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/RustGen.cpp b/RustGen.cpp
index 4390db5..a1e7314 100644
--- a/RustGen.cpp
+++ b/RustGen.cpp
@@ -368,7 +368,8 @@
       writer.Write("impl std::str::FromStr for %s {\n", enum_type.c_str());
       writer.Indent();
       writer.Write("type Err = String;\n\n");
-      writer.Write("fn from_str(s: &str) -> Result<Self, Self::Err> {\n");
+      writer.Write(
+          "fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {\n");
       writer.Indent();
       writer.Write("match s {\n");
       writer.Indent();
@@ -412,7 +413,9 @@
     writer.Write("/// Returns the value of the property '%s' if set.\n",
                  prop.prop_name().c_str());
     if (prop.deprecated()) writer.Write("%s\n", kDeprecated);
-    writer.Write("pub fn %s() -> Result<Option<%s>> {\n", prop_id.c_str(),
+    // Escape prop id if it is similar to `type` keyword.
+    std::string identifier = (prop_id == "type") ? "r#" + prop_id : prop_id;
+    writer.Write("pub fn %s() -> Result<Option<%s>> {\n", identifier.c_str(),
                  prop_return_type.c_str());
     writer.Indent();
     // Try original property.
diff --git a/tests/RustGenTest.cpp b/tests/RustGenTest.cpp
index ce58c0b..fdddf93 100644
--- a/tests/RustGenTest.cpp
+++ b/tests/RustGenTest.cpp
@@ -340,7 +340,7 @@
 impl std::str::FromStr for TestEnumValues {
     type Err = String;
 
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
+    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
         match s {
             "a" => Ok(TestEnumValues::A),
             "b" => Ok(TestEnumValues::B),
@@ -477,7 +477,7 @@
 impl std::str::FromStr for ElValues {
     type Err = String;
 
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
+    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
         match s {
             "enu" => Ok(ElValues::Enu),
             "mva" => Ok(ElValues::Mva),