Skip to content

Commit

Permalink
Auto merge of #17604 - Veykril:tt-symbols, r=Veykril
Browse files Browse the repository at this point in the history
More symbol usage
  • Loading branch information
bors committed Jul 16, 2024
2 parents dec95cf + 2346a80 commit 566f927
Show file tree
Hide file tree
Showing 95 changed files with 676 additions and 493 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/base-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ stdx.workspace = true
syntax.workspace = true
vfs.workspace = true
span.workspace = true
intern.workspace = true

[lints]
workspace = true
34 changes: 17 additions & 17 deletions crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use std::{fmt, mem, ops};

use cfg::CfgOptions;
use intern::Symbol;
use la_arena::{Arena, Idx, RawIdx};
use rustc_hash::{FxHashMap, FxHashSet};
use span::Edition;
use syntax::SmolStr;
use triomphe::Arc;
use vfs::{file_set::FileSet, AbsPathBuf, AnchoredPath, FileId, VfsPath};

Expand Down Expand Up @@ -99,8 +99,8 @@ impl fmt::Debug for CrateGraph {

pub type CrateId = Idx<CrateData>;

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

impl CrateName {
/// Creates a crate name, checking for dashes in the string provided.
Expand All @@ -110,16 +110,16 @@ impl CrateName {
if name.contains('-') {
Err(name)
} else {
Ok(Self(SmolStr::new(name)))
Ok(Self(Symbol::intern(name)))
}
}

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

pub fn as_smol_str(&self) -> &SmolStr {
pub fn symbol(&self) -> &Symbol {
&self.0
}
}
Expand All @@ -133,19 +133,19 @@ impl fmt::Display for CrateName {
impl ops::Deref for CrateName {
type Target = str;
fn deref(&self) -> &str {
&self.0
self.0.as_str()
}
}

/// Origin of the crates.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CrateOrigin {
/// Crates that are from the rustc workspace.
Rustc { name: String },
Rustc { name: Symbol },
/// Crates that are workspace members.
Local { repo: Option<String>, name: Option<String> },
Local { repo: Option<String>, name: Option<Symbol> },
/// Crates that are non member libraries.
Library { repo: Option<String>, name: String },
Library { repo: Option<String>, name: Symbol },
/// Crates that are provided by the language, like std, core, proc-macro, ...
Lang(LangCrateOrigin),
}
Expand Down Expand Up @@ -201,16 +201,16 @@ impl fmt::Display for LangCrateOrigin {
}
}

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

impl CrateDisplayName {
pub fn canonical_name(&self) -> &str {
pub fn canonical_name(&self) -> &Symbol {
&self.canonical_name
}
pub fn crate_name(&self) -> &CrateName {
Expand All @@ -220,7 +220,7 @@ impl CrateDisplayName {

impl From<CrateName> for CrateDisplayName {
fn from(crate_name: CrateName) -> CrateDisplayName {
let canonical_name = crate_name.to_string();
let canonical_name = crate_name.0.clone();
CrateDisplayName { crate_name, canonical_name }
}
}
Expand All @@ -239,9 +239,9 @@ impl ops::Deref for CrateDisplayName {
}

impl CrateDisplayName {
pub fn from_canonical_name(canonical_name: String) -> CrateDisplayName {
let crate_name = CrateName::normalize_dashes(&canonical_name);
CrateDisplayName { crate_name, canonical_name }
pub fn from_canonical_name(canonical_name: &str) -> CrateDisplayName {
let crate_name = CrateName::normalize_dashes(canonical_name);
CrateDisplayName { crate_name, canonical_name: Symbol::intern(canonical_name) }
}
}

Expand Down
Loading

0 comments on commit 566f927

Please sign in to comment.