about summary refs log tree commit diff
path: root/src/libproc_macro
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-05-10 16:27:32 +0000
committerbors <bors@rust-lang.org>2018-05-10 16:27:32 +0000
commit9e3caa23f99816caf3c2fb69ff5c88b512fb1b38 (patch)
tree38b311241c6f301f34b1a7894e1cc0bda4519029 /src/libproc_macro
parent0a223d139cd26e5bfab23a478a5cad845eaab131 (diff)
parent221b7ca3c27df5bb4729a7060e169c0a34dab9d0 (diff)
downloadrust-9e3caa23f99816caf3c2fb69ff5c88b512fb1b38.tar.gz
rust-9e3caa23f99816caf3c2fb69ff5c88b512fb1b38.zip
Auto merge of #49823 - Zoxc:term-str, r=alexcrichton
Remove usages of Term::as_str and mark it for removal

Returning references to rustc internal data structures is a bad idea since their lifetimes are unrelated to the lifetimes of proc_macro values.

See https://github.com/rust-lang/rust/pull/46972 and the `Taming thread-local storage` section of https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606

r? @alexcrichton
Diffstat (limited to 'src/libproc_macro')
-rw-r--r--src/libproc_macro/lib.rs5
-rw-r--r--src/libproc_macro/quote.rs2
2 files changed, 4 insertions, 3 deletions
diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs
index 8451e5987e9..c55df9b39b8 100644
--- a/src/libproc_macro/lib.rs
+++ b/src/libproc_macro/lib.rs
@@ -755,6 +755,7 @@ impl Term {
         }
     }
 
+    // FIXME: Remove this, do not stabilize
     /// Get a reference to the interned string.
     #[unstable(feature = "proc_macro", issue = "38356")]
     pub fn as_str(&self) -> &str {
@@ -779,7 +780,7 @@ impl Term {
 #[unstable(feature = "proc_macro", issue = "38356")]
 impl fmt::Display for Term {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        self.as_str().fmt(f)
+        self.sym.as_str().fmt(f)
     }
 }
 
@@ -1176,7 +1177,7 @@ impl TokenTree {
             },
             self::TokenTree::Term(tt) => {
                 let ident = ast::Ident::new(tt.sym, tt.span.0);
-                let sym_str = tt.sym.as_str();
+                let sym_str = tt.sym.to_string();
                 let token = if sym_str.starts_with("'") {
                     Lifetime(ident)
                 } else if sym_str.starts_with("r#") {
diff --git a/src/libproc_macro/quote.rs b/src/libproc_macro/quote.rs
index d1f8e75192a..70f0b078399 100644
--- a/src/libproc_macro/quote.rs
+++ b/src/libproc_macro/quote.rs
@@ -183,7 +183,7 @@ impl Quote for Op {
 
 impl Quote for Term {
     fn quote(self) -> TokenStream {
-        quote!(::Term::new((quote self.as_str()), (quote self.span())))
+        quote!(::Term::new((quote self.sym.as_str()), (quote self.span())))
     }
 }