aboutsummaryrefslogtreecommitdiff
path: root/crates/base_db/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/base_db/src/input.rs')
-rw-r--r--crates/base_db/src/input.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index 02c7348ff..87f0a0ce5 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -108,24 +108,37 @@ impl ops::Deref for CrateName {
108} 108}
109 109
110#[derive(Debug, Clone, PartialEq, Eq, Hash)] 110#[derive(Debug, Clone, PartialEq, Eq, Hash)]
111pub struct CrateDisplayName(CrateName); 111pub struct CrateDisplayName {
112 // The name we use to display various paths (with `_`).
113 crate_name: CrateName,
114 // The name as specified in Cargo.toml (with `-`).
115 canonical_name: String,
116}
112 117
113impl From<CrateName> for CrateDisplayName { 118impl From<CrateName> for CrateDisplayName {
114 fn from(inner: CrateName) -> CrateDisplayName { 119 fn from(crate_name: CrateName) -> CrateDisplayName {
115 CrateDisplayName(inner) 120 let canonical_name = crate_name.to_string();
121 CrateDisplayName { crate_name, canonical_name }
116 } 122 }
117} 123}
118 124
119impl fmt::Display for CrateDisplayName { 125impl fmt::Display for CrateDisplayName {
120 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 126 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
121 write!(f, "{}", self.0) 127 write!(f, "{}", self.crate_name)
122 } 128 }
123} 129}
124 130
125impl ops::Deref for CrateDisplayName { 131impl ops::Deref for CrateDisplayName {
126 type Target = str; 132 type Target = str;
127 fn deref(&self) -> &str { 133 fn deref(&self) -> &str {
128 &*self.0 134 &*self.crate_name
135 }
136}
137
138impl CrateDisplayName {
139 pub fn from_canonical_name(canonical_name: String) -> CrateDisplayName {
140 let crate_name = CrateName::normalize_dashes(&canonical_name);
141 CrateDisplayName { crate_name, canonical_name }
129 } 142 }
130} 143}
131 144
@@ -155,7 +168,7 @@ pub struct CrateData {
155 /// 168 ///
156 /// For purposes of analysis, crates are anonymous (only names in 169 /// For purposes of analysis, crates are anonymous (only names in
157 /// `Dependency` matters), this name should only be used for UI. 170 /// `Dependency` matters), this name should only be used for UI.
158 pub display_name: Option<CrateName>, 171 pub display_name: Option<CrateDisplayName>,
159 pub cfg_options: CfgOptions, 172 pub cfg_options: CfgOptions,
160 pub env: Env, 173 pub env: Env,
161 pub dependencies: Vec<Dependency>, 174 pub dependencies: Vec<Dependency>,
@@ -184,7 +197,7 @@ impl CrateGraph {
184 &mut self, 197 &mut self,
185 file_id: FileId, 198 file_id: FileId,
186 edition: Edition, 199 edition: Edition,
187 display_name: Option<CrateName>, 200 display_name: Option<CrateDisplayName>,
188 cfg_options: CfgOptions, 201 cfg_options: CfgOptions,
189 env: Env, 202 env: Env,
190 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>, 203 proc_macro: Vec<(SmolStr, Arc<dyn tt::TokenExpander>)>,