Skip to content

Commit 92fd430

Browse files
Use Display instead of a custom method
1 parent 059ed25 commit 92fd430

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

crates/ra_db/src/input.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hash::FxHashMap;
1414
use rustc_hash::FxHashSet;
1515

1616
use crate::{RelativePath, RelativePathBuf};
17+
use fmt::Display;
1718

1819
/// `FileId` is an integer which uniquely identifies a file. File paths are
1920
/// messy and system-dependent, so most of the code should work directly with
@@ -102,9 +103,11 @@ impl CrateName {
102103
pub fn normalize_dashes(name: &str) -> CrateName {
103104
Self(SmolStr::new(name.replace('-', "_")))
104105
}
106+
}
105107

106-
pub fn get_name(&self) -> String {
107-
self.0.to_string()
108+
impl Display for CrateName {
109+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110+
write!(f, "{}", self.0)
108111
}
109112
}
110113

crates/ra_hir_def/src/nameres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl CrateDefMap {
181181
db.crate_graph()[krate]
182182
.display_name
183183
.as_ref()
184-
.map(|name| name.get_name())
184+
.map(ToString::to_string)
185185
.unwrap_or_default()
186186
});
187187
let def_map = {

crates/ra_ide/src/hover.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,17 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
9494

9595
fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
9696
let mod_path = def.module(db).map(|module| {
97-
once(
98-
db.crate_graph()[module.krate().into()]
99-
.display_name
100-
.as_ref()
101-
.map(|name| name.get_name()),
102-
)
103-
.chain(
104-
module
105-
.path_to_root(db)
106-
.into_iter()
107-
.rev()
108-
.map(|it| it.name(db).map(|name| name.to_string())),
109-
)
110-
.chain(once(definition_owner_name(db, def)))
111-
.flatten()
112-
.join("::")
97+
once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string))
98+
.chain(
99+
module
100+
.path_to_root(db)
101+
.into_iter()
102+
.rev()
103+
.map(|it| it.name(db).map(|name| name.to_string())),
104+
)
105+
.chain(once(definition_owner_name(db, def)))
106+
.flatten()
107+
.join("::")
113108
});
114109
mod_path // FIXME: replace dashes with underscores in crate display name
115110
}

0 commit comments

Comments
 (0)