diff --git a/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server.rs b/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server.rs index 2e5751756a7..46882845a80 100644 --- a/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server.rs +++ b/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server.rs @@ -83,10 +83,9 @@ impl server::FreeFunctions for RustAnalyzer { s: &str, ) -> Result, ()> { // FIXME: keep track of LitKind and Suffix - let symbol = ThreadLocalSymbolInterner::intern(s); Ok(bridge::Literal { kind: bridge::LitKind::Err, - symbol, + symbol: Symbol::intern(s), suffix: None, span: tt::TokenId::unspecified(), }) @@ -124,7 +123,7 @@ impl server::TokenStream for RustAnalyzer { bridge::TokenTree::Ident(ident) => { // FIXME: handle raw idents - let text = ThreadLocalSymbolInterner::get_cloned(&ident.sym); + let text = ident.sym.text(); let ident: tt::Ident = tt::Ident { text, id: ident.span }; let leaf = tt::Leaf::from(ident); let tree = TokenTree::from(leaf); @@ -198,7 +197,7 @@ impl server::TokenStream for RustAnalyzer { .map(|tree| match tree { tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => { bridge::TokenTree::Ident(bridge::Ident { - sym: ThreadLocalSymbolInterner::intern(&ident.text), + sym: Symbol::intern(&ident.text), // FIXME: handle raw idents is_raw: false, span: ident.id, @@ -208,7 +207,7 @@ impl server::TokenStream for RustAnalyzer { bridge::TokenTree::Literal(bridge::Literal { // FIXME: handle literal kinds kind: bridge::LitKind::Err, - symbol: ThreadLocalSymbolInterner::intern(&lit.text), + symbol: Symbol::intern(&lit.text), // FIXME: handle suffixes suffix: None, span: lit.id, @@ -402,11 +401,11 @@ impl server::Server for RustAnalyzer { } fn intern_symbol(ident: &str) -> Self::Symbol { - ThreadLocalSymbolInterner::intern(&tt::SmolStr::from(ident)) + Symbol::intern(&tt::SmolStr::from(ident)) } fn with_symbol_string(symbol: &Self::Symbol, f: impl FnOnce(&str)) { - ThreadLocalSymbolInterner::with(symbol, |s| f(s.as_str())) + f(symbol.text().as_str()) } } @@ -450,10 +449,9 @@ impl LiteralFormatter { } fn with_symbol_and_suffix(&self, f: impl FnOnce(&str, &str) -> R) -> R { - ThreadLocalSymbolInterner::with(&self.0.symbol, |symbol| match self.0.suffix.as_ref() { - Some(suffix) => ThreadLocalSymbolInterner::with(suffix, |suffix| f(symbol, suffix)), - None => f(symbol, ""), - }) + let symbol = self.0.symbol.text(); + let suffix = self.0.suffix.map(|s| s.text()).unwrap_or_default(); + f(symbol.as_str(), suffix.as_str()) } } diff --git a/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server/symbol.rs b/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server/symbol.rs index 294ef76c24a..51dfba2ea9f 100644 --- a/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server/symbol.rs +++ b/crates/proc-macro-srv/src/abis/abi_sysroot/ra_server/symbol.rs @@ -11,6 +11,16 @@ thread_local! { #[derive(Hash, Eq, PartialEq, Copy, Clone)] pub struct Symbol(u32); +impl Symbol { + pub fn intern(data: &str) -> Symbol { + SYMBOL_INTERNER.with(|i| i.borrow_mut().intern(data)) + } + + pub fn text(&self) -> SmolStr { + SYMBOL_INTERNER.with(|i| i.borrow().get(self).clone()) + } +} + #[derive(Default)] struct SymbolInterner { idents: HashMap, @@ -34,19 +44,3 @@ impl SymbolInterner { &self.ident_data[sym.0 as usize] } } - -pub(super) struct ThreadLocalSymbolInterner; - -impl ThreadLocalSymbolInterner { - pub(super) fn intern(data: &str) -> Symbol { - SYMBOL_INTERNER.with(|i| i.borrow_mut().intern(data)) - } - - pub(super) fn with(sym: &Symbol, f: impl FnOnce(&SmolStr) -> T) -> T { - SYMBOL_INTERNER.with(|i| f(i.borrow().get(sym))) - } - - pub(super) fn get_cloned(sym: &Symbol) -> SmolStr { - Self::with(sym, |s| s.clone()) - } -}