mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Merge pull request #19822 from Veykril/push-mzzluystvwls
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
minor: Remote dangling file
This commit is contained in:
commit
59ef84506d
2 changed files with 1 additions and 49 deletions
|
|
@ -16,9 +16,8 @@ mod token_stream;
|
|||
pub use token_stream::TokenStream;
|
||||
|
||||
pub mod rust_analyzer_span;
|
||||
// mod symbol;
|
||||
pub mod token_id;
|
||||
// pub use symbol::*;
|
||||
|
||||
use tt::Spacing;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
//! Symbol interner for proc-macro-srv
|
||||
|
||||
use std::{cell::RefCell, collections::HashMap, thread::LocalKey};
|
||||
|
||||
thread_local! {
|
||||
pub(crate) static SYMBOL_INTERNER: RefCell<SymbolInterner> = Default::default();
|
||||
}
|
||||
|
||||
// ID for an interned symbol.
|
||||
#[derive(Hash, Eq, PartialEq, Copy, Clone)]
|
||||
pub struct Symbol(u32);
|
||||
|
||||
pub(crate) type SymbolInternerRef = &'static LocalKey<RefCell<SymbolInterner>>;
|
||||
|
||||
impl Symbol {
|
||||
pub(super) fn intern(interner: SymbolInternerRef, data: &str) -> Symbol {
|
||||
interner.with(|i| i.borrow_mut().intern(data))
|
||||
}
|
||||
|
||||
pub(super) fn text(&self, interner: SymbolInternerRef) -> SmolStr {
|
||||
interner.with(|i| i.borrow().get(self).clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct SymbolInterner {
|
||||
idents: HashMap<SmolStr, u32>,
|
||||
ident_data: Vec<SmolStr>,
|
||||
}
|
||||
|
||||
impl SymbolInterner {
|
||||
fn intern(&mut self, data: &str) -> Symbol {
|
||||
if let Some(index) = self.idents.get(data) {
|
||||
return Symbol(*index);
|
||||
}
|
||||
|
||||
let index = self.idents.len() as u32;
|
||||
let data = SmolStr::from(data);
|
||||
self.ident_data.push(data.clone());
|
||||
self.idents.insert(data, index);
|
||||
Symbol(index)
|
||||
}
|
||||
|
||||
fn get(&self, sym: &Symbol) -> &SmolStr {
|
||||
&self.ident_data[sym.0 as usize]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue