mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
Use Display instead of a custom method
This commit is contained in:
parent
059ed25a3e
commit
92fd430dab
3 changed files with 17 additions and 19 deletions
|
@ -14,6 +14,7 @@ use rustc_hash::FxHashMap;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{RelativePath, RelativePathBuf};
|
use crate::{RelativePath, RelativePathBuf};
|
||||||
|
use fmt::Display;
|
||||||
|
|
||||||
/// `FileId` is an integer which uniquely identifies a file. File paths are
|
/// `FileId` is an integer which uniquely identifies a file. File paths are
|
||||||
/// messy and system-dependent, so most of the code should work directly with
|
/// messy and system-dependent, so most of the code should work directly with
|
||||||
|
@ -102,9 +103,11 @@ impl CrateName {
|
||||||
pub fn normalize_dashes(name: &str) -> CrateName {
|
pub fn normalize_dashes(name: &str) -> CrateName {
|
||||||
Self(SmolStr::new(name.replace('-', "_")))
|
Self(SmolStr::new(name.replace('-', "_")))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_name(&self) -> String {
|
impl Display for CrateName {
|
||||||
self.0.to_string()
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{}", self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl CrateDefMap {
|
||||||
db.crate_graph()[krate]
|
db.crate_graph()[krate]
|
||||||
.display_name
|
.display_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|name| name.get_name())
|
.map(ToString::to_string)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
});
|
});
|
||||||
let def_map = {
|
let def_map = {
|
||||||
|
|
|
@ -94,12 +94,7 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
|
||||||
|
|
||||||
fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
|
fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
|
||||||
let mod_path = def.module(db).map(|module| {
|
let mod_path = def.module(db).map(|module| {
|
||||||
once(
|
once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string))
|
||||||
db.crate_graph()[module.krate().into()]
|
|
||||||
.display_name
|
|
||||||
.as_ref()
|
|
||||||
.map(|name| name.get_name()),
|
|
||||||
)
|
|
||||||
.chain(
|
.chain(
|
||||||
module
|
module
|
||||||
.path_to_root(db)
|
.path_to_root(db)
|
||||||
|
|
Loading…
Reference in a new issue