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>>(&mut self, wrd: S) -> io::Result<()> { + pub fn word<'s, S: Into>>(&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 } }