Skip to content

Commit 9e3caa2

Browse files
committed
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 #46972 and the `Taming thread-local storage` section of https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606 r? @alexcrichton
2 parents 0a223d1 + 221b7ca commit 9e3caa2

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

Diff for: src/libproc_macro/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ impl Term {
755755
}
756756
}
757757

758+
// FIXME: Remove this, do not stabilize
758759
/// Get a reference to the interned string.
759760
#[unstable(feature = "proc_macro", issue = "38356")]
760761
pub fn as_str(&self) -> &str {
@@ -779,7 +780,7 @@ impl Term {
779780
#[unstable(feature = "proc_macro", issue = "38356")]
780781
impl fmt::Display for Term {
781782
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
782-
self.as_str().fmt(f)
783+
self.sym.as_str().fmt(f)
783784
}
784785
}
785786

@@ -1176,7 +1177,7 @@ impl TokenTree {
11761177
},
11771178
self::TokenTree::Term(tt) => {
11781179
let ident = ast::Ident::new(tt.sym, tt.span.0);
1179-
let sym_str = tt.sym.as_str();
1180+
let sym_str = tt.sym.to_string();
11801181
let token = if sym_str.starts_with("'") {
11811182
Lifetime(ident)
11821183
} else if sym_str.starts_with("r#") {

Diff for: src/libproc_macro/quote.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Quote for Op {
183183

184184
impl Quote for Term {
185185
fn quote(self) -> TokenStream {
186-
quote!(::Term::new((quote self.as_str()), (quote self.span())))
186+
quote!(::Term::new((quote self.sym.as_str()), (quote self.span())))
187187
}
188188
}
189189

Diff for: src/test/compile-fail-fulldeps/proc-macro/auxiliary/attributes-included.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn assert_doc(slice: &mut &[TokenTree]) {
8686
}
8787

8888
match &tokens[0] {
89-
TokenTree::Term(tt) => assert_eq!("doc", tt.as_str()),
89+
TokenTree::Term(tt) => assert_eq!("doc", &*tt.to_string()),
9090
_ => panic!("expected `doc`"),
9191
}
9292
match &tokens[1] {
@@ -118,11 +118,11 @@ fn assert_invoc(slice: &mut &[TokenTree]) {
118118

119119
fn assert_foo(slice: &mut &[TokenTree]) {
120120
match &slice[0] {
121-
TokenTree::Term(tt) => assert_eq!(tt.as_str(), "fn"),
121+
TokenTree::Term(tt) => assert_eq!(&*tt.to_string(), "fn"),
122122
_ => panic!("expected fn"),
123123
}
124124
match &slice[1] {
125-
TokenTree::Term(tt) => assert_eq!(tt.as_str(), "foo"),
125+
TokenTree::Term(tt) => assert_eq!(&*tt.to_string(), "foo"),
126126
_ => panic!("expected foo"),
127127
}
128128
match &slice[2] {

Diff for: src/test/run-pass-fulldeps/auxiliary/cond_plugin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn cond(input: TokenStream) -> TokenStream {
3333
panic!("Invalid macro usage in cond: {}", cond);
3434
}
3535
let is_else = match test {
36-
TokenTree::Term(word) => word.as_str() == "else",
36+
TokenTree::Term(word) => &*word.to_string() == "else",
3737
_ => false,
3838
};
3939
conds.push(if is_else || input.peek().is_none() {

0 commit comments

Comments
 (0)