From a1639d0d1ef201b2b9a425eddecfb41a25f10931 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Dec 2019 12:58:43 +0100 Subject: [PATCH] Remove more dead code --- crates/ra_assists/src/test_db.rs | 2 - crates/ra_hir/src/debug.rs | 94 -------------------------------- crates/ra_hir/src/lib.rs | 2 - crates/ra_ide/src/db.rs | 14 +---- 4 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 crates/ra_hir/src/debug.rs diff --git a/crates/ra_assists/src/test_db.rs b/crates/ra_assists/src/test_db.rs index 523259fd46..d5249f3088 100644 --- a/crates/ra_assists/src/test_db.rs +++ b/crates/ra_assists/src/test_db.rs @@ -43,5 +43,3 @@ impl FileLoader for TestDB { FileLoaderDelegate(self).relevant_crates(file_id) } } - -impl hir::debug::HirDebugHelper for TestDB {} diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs deleted file mode 100644 index 6cd5c8cb97..0000000000 --- a/crates/ra_hir/src/debug.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! XXX: This does not work at the moment. -//! -//! printf debugging infrastructure for rust-analyzer. -//! -//! When you print a hir type, like a module, using `eprintln!("{:?}", module)`, -//! you usually get back a numeric ID, which doesn't tell you much: -//! `Module(92)`. -//! -//! This module adds convenience `debug` methods to various types, which resolve -//! the id to a human-readable location info: -//! -//! ```not_rust -//! eprintln!("{:?}", module.debug(db)); -//! => -//! Module { name: collections, path: "liballoc/collections/mod.rs" } -//! ``` -//! -//! Note that to get this info, we might need to execute queries! So -//! -//! * don't use the `debug` methods for logging -//! * when debugging, be aware that interference is possible. - -use std::fmt; - -use hir_expand::HirFileId; -use ra_db::{CrateId, FileId}; - -use crate::{db::HirDatabase, Crate, Module, Name}; - -impl Crate { - pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { - debug_fn(move |fmt| db.debug_crate(self, fmt)) - } -} - -impl Module { - pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { - debug_fn(move |fmt| db.debug_module(self, fmt)) - } -} - -pub trait HirDebugHelper: HirDatabase { - fn crate_name(&self, _krate: CrateId) -> Option { - None - } - fn file_path(&self, _file_id: FileId) -> Option { - None - } -} - -pub trait HirDebugDatabase { - fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; - fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; - fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result; -} - -impl HirDebugDatabase for DB { - fn debug_crate(&self, krate: Crate, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut builder = fmt.debug_tuple("Crate"); - match self.crate_name(krate.id) { - Some(name) => builder.field(&name), - None => builder.field(&krate.id), - } - .finish() - } - - fn debug_module(&self, module: Module, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let file_id = module.definition_source(self).file_id.original_file(self); - let path = self.file_path(file_id).unwrap_or_else(|| "N/A".to_string()); - fmt.debug_struct("Module") - .field("name", &module.name(self).unwrap_or_else(Name::missing)) - .field("path", &path) - .finish() - } - - fn debug_hir_file_id(&self, file_id: HirFileId, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let original = file_id.original_file(self); - let path = self.file_path(original).unwrap_or_else(|| "N/A".to_string()); - let is_macro = file_id != original.into(); - fmt.debug_struct("HirFileId").field("path", &path).field("macro", &is_macro).finish() - } -} - -fn debug_fn(f: impl Fn(&mut fmt::Formatter<'_>) -> fmt::Result) -> impl fmt::Debug { - struct DebugFn(F); - - impl) -> fmt::Result> fmt::Debug for DebugFn { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - (&self.0)(fmt) - } - } - - DebugFn(f) -} diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 946299ba08..e7602ee305 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -26,8 +26,6 @@ macro_rules! impl_froms { } } -pub mod debug; - pub mod db; pub mod source_binder; diff --git a/crates/ra_ide/src/db.rs b/crates/ra_ide/src/db.rs index f739ebecd3..47d0aed6fb 100644 --- a/crates/ra_ide/src/db.rs +++ b/crates/ra_ide/src/db.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use ra_db::{ salsa::{self, Database, Durability}, Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, - SourceDatabase, SourceDatabaseExt, SourceRootId, + SourceDatabase, SourceRootId, }; use rustc_hash::FxHashMap; @@ -49,18 +49,6 @@ impl FileLoader for RootDatabase { } } -impl hir::debug::HirDebugHelper for RootDatabase { - fn crate_name(&self, krate: CrateId) -> Option { - self.debug_data.crate_names.get(&krate).cloned() - } - fn file_path(&self, file_id: FileId) -> Option { - let source_root_id = self.file_source_root(file_id); - let source_root_path = self.debug_data.root_paths.get(&source_root_id)?; - let file_path = self.file_relative_path(file_id); - Some(format!("{}/{}", source_root_path, file_path)) - } -} - impl salsa::Database for RootDatabase { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime