Merge "Upgrade rust/crates/proc-macro2 to 1.0.29" am: 8129d0cb0c

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/proc-macro2/+/1833322

Change-Id: Idf9e14368ab65ac919aec3a0e2d0f50de6970a3f
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 0b4ad97..b4a0dce 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
 {
   "git": {
-    "sha1": "93c4df24e2d5ef9ddff484a7086f2e0018a13507"
+    "sha1": "4fc89676e7bdef2ba68e8a1383d07df0bb7bbeb0"
   }
 }
diff --git a/Android.bp b/Android.bp
index 3118612..8933a44 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,4 @@
-// This file is generated by cargo2android.py --run --dependencies --tests --host-first-multilib --features=default,span-locations.
+// This file is generated by cargo2android.py --run --tests --host-first-multilib --features=default,span-locations.
 // Do not modify this file as changes will be overridden on upgrade.
 
 package {
@@ -40,6 +40,8 @@
 rust_library_host {
     name: "libproc_macro2",
     crate_name: "proc_macro2",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.29",
     srcs: ["src/lib.rs"],
     edition: "2018",
     features: [
@@ -50,6 +52,7 @@
     cfgs: [
         "hygiene",
         "lexerror_display",
+        "literal_from_str",
         "proc_macro_span",
         "span_locations",
         "use_proc_macro",
@@ -64,6 +67,8 @@
 rust_test_host {
     name: "proc-macro2_host_test_src_lib",
     crate_name: "proc_macro2",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.29",
     srcs: ["src/lib.rs"],
     test_suites: ["general-tests"],
     auto_gen_config: true,
@@ -79,6 +84,7 @@
     cfgs: [
         "hygiene",
         "lexerror_display",
+        "literal_from_str",
         "proc_macro_span",
         "span_locations",
         "use_proc_macro",
@@ -93,6 +99,8 @@
 rust_defaults {
     name: "proc-macro2_test_defaults",
     crate_name: "proc_macro2",
+    cargo_env_compat: true,
+    cargo_pkg_version: "1.0.29",
     test_suites: ["general-tests"],
     auto_gen_config: true,
     edition: "2018",
@@ -104,6 +112,7 @@
     cfgs: [
         "hygiene",
         "lexerror_display",
+        "literal_from_str",
         "proc_macro_span",
         "span_locations",
         "use_proc_macro",
@@ -160,8 +169,3 @@
         unit_test: true,
     },
 }
-
-// dependent_library ["feature_list"]
-//   proc-macro2-1.0.28
-//   quote-1.0.9
-//   unicode-xid-0.2.2 "default"
diff --git a/Cargo.toml b/Cargo.toml
index 4285fc8..901c787 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
 [package]
 edition = "2018"
 name = "proc-macro2"
-version = "1.0.28"
+version = "1.0.29"
 authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"]
 description = "A substitute implementation of the compiler's `proc_macro` API to decouple\ntoken-based libraries from the procedural macro use case.\n"
 documentation = "https://docs.rs/proc-macro2"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 254063e..543dca5 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
 [package]
 name = "proc-macro2"
-version = "1.0.28" # remember to update html_root_url
+version = "1.0.29" # remember to update html_root_url
 authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"]
 license = "MIT OR Apache-2.0"
 readme = "README.md"
diff --git a/METADATA b/METADATA
index fee70d5..e87d081 100644
--- a/METADATA
+++ b/METADATA
@@ -7,13 +7,13 @@
   }
   url {
     type: ARCHIVE
-    value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.28.crate"
+    value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.29.crate"
   }
-  version: "1.0.28"
+  version: "1.0.29"
   license_type: NOTICE
   last_upgrade_date {
     year: 2021
-    month: 8
-    day: 9
+    month: 9
+    day: 22
   }
 }
diff --git a/build.rs b/build.rs
index 815292e..f32d5c8 100644
--- a/build.rs
+++ b/build.rs
@@ -78,6 +78,10 @@
         println!("cargo:rustc-cfg=hygiene");
     }
 
+    if version.minor >= 54 {
+        println!("cargo:rustc-cfg=literal_from_str");
+    }
+
     let target = env::var("TARGET").unwrap();
     if !enable_use_proc_macro(&target) {
         return;
diff --git a/src/lib.rs b/src/lib.rs
index d494ce8..1d35bfd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -78,7 +78,7 @@
 //! a different thread.
 
 // Proc-macro2 types in rustdoc of other crates get linked to here.
-#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.28")]
+#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.29")]
 #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))]
 #![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))]
 #![cfg_attr(doc_cfg, feature(doc_cfg))]
diff --git a/src/wrapper.rs b/src/wrapper.rs
index 2829dd7..dc93873 100644
--- a/src/wrapper.rs
+++ b/src/wrapper.rs
@@ -921,18 +921,25 @@
 
     fn from_str(repr: &str) -> Result<Self, Self::Err> {
         if inside_proc_macro() {
-            // TODO: use libproc_macro's FromStr impl once it is available in
-            // rustc. https://github.com/rust-lang/rust/pull/84717
-            let tokens = proc_macro_parse(repr)?;
-            let mut iter = tokens.into_iter();
-            if let (Some(proc_macro::TokenTree::Literal(literal)), None) =
-                (iter.next(), iter.next())
+            #[cfg(literal_from_str)]
             {
-                if literal.to_string().len() == repr.len() {
-                    return Ok(Literal::Compiler(literal));
-                }
+                proc_macro::Literal::from_str(repr)
+                    .map(Literal::Compiler)
+                    .map_err(LexError::Compiler)
             }
-            Err(LexError::call_site())
+            #[cfg(not(literal_from_str))]
+            {
+                let tokens = proc_macro_parse(repr)?;
+                let mut iter = tokens.into_iter();
+                if let (Some(proc_macro::TokenTree::Literal(literal)), None) =
+                    (iter.next(), iter.next())
+                {
+                    if literal.to_string().len() == repr.len() {
+                        return Ok(Literal::Compiler(literal));
+                    }
+                }
+                Err(LexError::call_site())
+            }
         } else {
             let literal = fallback::Literal::from_str(repr)?;
             Ok(Literal::Fallback(literal))