]> git.lizzy.rs Git - rust.git/commitdiff
Use Display instead of a custom method
authorKirill Bulatov <mail4score@gmail.com>
Mon, 16 Mar 2020 10:03:43 +0000 (12:03 +0200)
committerKirill Bulatov <mail4score@gmail.com>
Mon, 16 Mar 2020 10:03:43 +0000 (12:03 +0200)
crates/ra_db/src/input.rs
crates/ra_hir_def/src/nameres.rs
crates/ra_ide/src/hover.rs

index a6a831afae59e1c8a2d2e41f19b62226567af1b0..bde843001a64971296927b87924723660235ef56 100644 (file)
@@ -14,6 +14,7 @@
 use rustc_hash::FxHashSet;
 
 use crate::{RelativePath, RelativePathBuf};
+use fmt::Display;
 
 /// `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
@@ -102,9 +103,11 @@ pub fn new(name: &str) -> Result<CrateName, &str> {
     pub fn normalize_dashes(name: &str) -> CrateName {
         Self(SmolStr::new(name.replace('-', "_")))
     }
+}
 
-    pub fn get_name(&self) -> String {
-        self.0.to_string()
+impl Display for CrateName {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "{}", self.0)
     }
 }
 
index 87992854ae6e05ad94590bf1ee6521c3d4957092..03515309e081234d3ca8daaa23f1385a57625b81 100644 (file)
@@ -181,7 +181,7 @@ pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<
             db.crate_graph()[krate]
                 .display_name
                 .as_ref()
-                .map(|name| name.get_name())
+                .map(ToString::to_string)
                 .unwrap_or_default()
         });
         let def_map = {
index d1deca96b2dd2749b5e68392014d3a77c4ae3ebb..5b3760c1866929f8abacb39c29a9759e51a01707 100644 (file)
@@ -94,22 +94,17 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
 
 fn determine_mod_path(db: &RootDatabase, def: &Definition) -> Option<String> {
     let mod_path = def.module(db).map(|module| {
-        once(
-            db.crate_graph()[module.krate().into()]
-                .display_name
-                .as_ref()
-                .map(|name| name.get_name()),
-        )
-        .chain(
-            module
-                .path_to_root(db)
-                .into_iter()
-                .rev()
-                .map(|it| it.name(db).map(|name| name.to_string())),
-        )
-        .chain(once(definition_owner_name(db, def)))
-        .flatten()
-        .join("::")
+        once(db.crate_graph()[module.krate().into()].display_name.as_ref().map(ToString::to_string))
+            .chain(
+                module
+                    .path_to_root(db)
+                    .into_iter()
+                    .rev()
+                    .map(|it| it.name(db).map(|name| name.to_string())),
+            )
+            .chain(once(definition_owner_name(db, def)))
+            .flatten()
+            .join("::")
     });
     mod_path // FIXME: replace dashes with underscores in crate display name
 }