about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-03-16 08:50:19 +0100
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2019-03-31 03:11:55 +0200
commit438f6b04c6fe2daf7f6000294edd50c26f6da619 (patch)
treefe697b4619ad01961eb6da664adc49f8d7a80155
parentbefeeb7c083c9e5edddc86563cc461185d897a13 (diff)
downloadrust-438f6b04c6fe2daf7f6000294edd50c26f6da619.tar.gz
rust-438f6b04c6fe2daf7f6000294edd50c26f6da619.zip
Fix lifetime on LocalInternedString::get function
-rw-r--r--src/libsyntax/parse/parser.rs8
-rw-r--r--src/libsyntax/print/pp.rs11
-rw-r--r--src/libsyntax_ext/proc_macro_server.rs6
-rw-r--r--src/libsyntax_pos/symbol.rs6
4 files changed, 20 insertions, 11 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index ae8e57d54de..af069b527b0 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2165,9 +2165,11 @@ impl<'a> Parser<'a> {
                     suffix,
                 ) = self.token {
                     let suffix = suffix.and_then(|s| {
-                        let s = s.as_str().get();
-                        if ["f32", "f64"].contains(&s) {
-                            Some(s)
+                        let s = s.as_str();
+                        if s == "f32" {
+                            Some("f32")
+                        } else if s == "f64" {
+                            Some("f64")
                         } else {
                             None
                         }
diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs
index d8a8cbb655b..740ca229030 100644
--- a/src/libsyntax/print/pp.rs
+++ b/src/libsyntax/print/pp.rs
@@ -369,7 +369,7 @@ impl<'a> Printer<'a> {
         Ok(())
     }
 
-    fn pretty_print_string(&mut self, s: Cow<'static, str>, len: isize) -> io::Result<()> {
+    fn pretty_print_string<'s>(&mut self, s: Cow<'s, str>, len: isize) -> io::Result<()> {
         if self.scan_stack.is_empty() {
             debug!("pp String('{}')/print Vec<{},{}>",
                    s, self.left, self.right);
@@ -378,7 +378,10 @@ impl<'a> Printer<'a> {
             debug!("pp String('{}')/buffer Vec<{},{}>",
                    s, self.left, self.right);
             self.advance_right();
-            self.buf[self.right] = BufEntry { token: Token::String(s, len), size: len };
+            self.buf[self.right] = BufEntry {
+                token: Token::String(s.into_owned().into(), len),
+                size: len
+            };
             self.right_total += len;
             self.check_stream()
         }
@@ -576,7 +579,7 @@ impl<'a> Printer<'a> {
         }
     }
 
-    pub fn print_string(&mut self, s: Cow<'static, str>, len: isize) -> io::Result<()> {
+    pub fn print_string(&mut self, s: Cow<'_, str>, len: isize) -> io::Result<()> {
         debug!("print String({})", s);
         // assert!(len <= space);
         self.space -= len;
@@ -641,7 +644,7 @@ impl<'a> Printer<'a> {
         self.pretty_print_eof()
     }
 
-    pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S) -> io::Result<()> {
+    pub fn word<'s, S: Into<Cow<'s, str>>>(&mut self, wrd: S) -> io::Result<()> {
         let s = wrd.into();
         let len = s.len() as isize;
         self.pretty_print_string(s, len)
diff --git a/src/libsyntax_ext/proc_macro_server.rs b/src/libsyntax_ext/proc_macro_server.rs
index f902e8169b6..09dce775790 100644
--- a/src/libsyntax_ext/proc_macro_server.rs
+++ b/src/libsyntax_ext/proc_macro_server.rs
@@ -336,11 +336,11 @@ impl Ident {
         }
     }
     fn new(sym: Symbol, is_raw: bool, span: Span) -> Ident {
-        let string = sym.as_str().get();
-        if !Self::is_valid(string) {
+        let string = sym.as_str();
+        if !Self::is_valid(&string) {
             panic!("`{:?}` is not a valid identifier", string)
         }
-        if is_raw && !ast::Ident::from_str(string).can_be_raw() {
+        if is_raw && !ast::Ident::from_interned_str(sym.as_interned_str()).can_be_raw() {
             panic!("`{}` cannot be a raw identifier", string);
         }
         Ident { sym, is_raw, span }
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index f61aa4284d2..393f52e7de5 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -524,7 +524,11 @@ impl LocalInternedString {
         }
     }
 
-    pub fn get(&self) -> &'static str {
+    pub fn get(&self) -> &str {
+        // This returns a valid string since we ensure that `self` outlives the interner
+        // by creating the interner on a thread which outlives threads which can access it.
+        // This type cannot move to a thread which outlives the interner since it does
+        // not implement Send.
         self.string
     }
 }