Skip to content

Commit 064e6ed

Browse files
committed
Auto merge of rust-lang#17604 - Veykril:tt-symbols, r=Veykril
More symbol usage
2 parents 6c10c85 + 41451a2 commit 064e6ed

File tree

95 files changed

+676
-493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+676
-493
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ name = "base-db"
7070
version = "0.0.0"
7171
dependencies = [
7272
"cfg",
73+
"intern",
7374
"la-arena 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
7475
"lz4_flex",
7576
"rustc-hash",
@@ -970,6 +971,7 @@ dependencies = [
970971
"crossbeam-channel",
971972
"hir-expand",
972973
"ide-db",
974+
"intern",
973975
"itertools",
974976
"paths",
975977
"proc-macro-api",

src/tools/rust-analyzer/crates/base-db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ stdx.workspace = true
2727
syntax.workspace = true
2828
vfs.workspace = true
2929
span.workspace = true
30+
intern.workspace = true
3031

3132
[lints]
3233
workspace = true

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use std::{fmt, mem, ops};
1010

1111
use cfg::CfgOptions;
12+
use intern::Symbol;
1213
use la_arena::{Arena, Idx, RawIdx};
1314
use rustc_hash::{FxHashMap, FxHashSet};
1415
use span::Edition;
15-
use syntax::SmolStr;
1616
use triomphe::Arc;
1717
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};
1818

@@ -99,8 +99,8 @@ impl fmt::Debug for CrateGraph {
9999

100100
pub type CrateId = Idx<CrateData>;
101101

102-
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
103-
pub struct CrateName(SmolStr);
102+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
103+
pub struct CrateName(Symbol);
104104

105105
impl CrateName {
106106
/// Creates a crate name, checking for dashes in the string provided.
@@ -110,16 +110,16 @@ impl CrateName {
110110
if name.contains('-') {
111111
Err(name)
112112
} else {
113-
Ok(Self(SmolStr::new(name)))
113+
Ok(Self(Symbol::intern(name)))
114114
}
115115
}
116116

117117
/// Creates a crate name, unconditionally replacing the dashes with underscores.
118118
pub fn normalize_dashes(name: &str) -> CrateName {
119-
Self(SmolStr::new(name.replace('-', "_")))
119+
Self(Symbol::intern(&name.replace('-', "_")))
120120
}
121121

122-
pub fn as_smol_str(&self) -> &SmolStr {
122+
pub fn symbol(&self) -> &Symbol {
123123
&self.0
124124
}
125125
}
@@ -133,19 +133,19 @@ impl fmt::Display for CrateName {
133133
impl ops::Deref for CrateName {
134134
type Target = str;
135135
fn deref(&self) -> &str {
136-
&self.0
136+
self.0.as_str()
137137
}
138138
}
139139

140140
/// Origin of the crates.
141141
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
142142
pub enum CrateOrigin {
143143
/// Crates that are from the rustc workspace.
144-
Rustc { name: String },
144+
Rustc { name: Symbol },
145145
/// Crates that are workspace members.
146-
Local { repo: Option<String>, name: Option<String> },
146+
Local { repo: Option<String>, name: Option<Symbol> },
147147
/// Crates that are non member libraries.
148-
Library { repo: Option<String>, name: String },
148+
Library { repo: Option<String>, name: Symbol },
149149
/// Crates that are provided by the language, like std, core, proc-macro, ...
150150
Lang(LangCrateOrigin),
151151
}
@@ -201,16 +201,16 @@ impl fmt::Display for LangCrateOrigin {
201201
}
202202
}
203203

204-
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
204+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
205205
pub struct CrateDisplayName {
206206
// The name we use to display various paths (with `_`).
207207
crate_name: CrateName,
208208
// The name as specified in Cargo.toml (with `-`).
209-
canonical_name: String,
209+
canonical_name: Symbol,
210210
}
211211

212212
impl CrateDisplayName {
213-
pub fn canonical_name(&self) -> &str {
213+
pub fn canonical_name(&self) -> &Symbol {
214214
&self.canonical_name
215215
}
216216
pub fn crate_name(&self) -> &CrateName {
@@ -220,7 +220,7 @@ impl CrateDisplayName {
220220

221221
impl From<CrateName> for CrateDisplayName {
222222
fn from(crate_name: CrateName) -> CrateDisplayName {
223-
let canonical_name = crate_name.to_string();
223+
let canonical_name = crate_name.0.clone();
224224
CrateDisplayName { crate_name, canonical_name }
225225
}
226226
}
@@ -239,9 +239,9 @@ impl ops::Deref for CrateDisplayName {
239239
}
240240

241241
impl CrateDisplayName {
242-
pub fn from_canonical_name(canonical_name: String) -> CrateDisplayName {
243-
let crate_name = CrateName::normalize_dashes(&canonical_name);
244-
CrateDisplayName { crate_name, canonical_name }
242+
pub fn from_canonical_name(canonical_name: &str) -> CrateDisplayName {
243+
let crate_name = CrateName::normalize_dashes(canonical_name);
244+
CrateDisplayName { crate_name, canonical_name: Symbol::intern(canonical_name) }
245245
}
246246
}
247247

0 commit comments

Comments
 (0)