From b6101184537b1165cfdd5fc473e04ad4c5b7bffa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Nov 2020 13:13:32 +0100 Subject: Deny unreachable-pub It's very useful when `pub` is equivalent to "this is crate's public API", let's enforce this! Ideally, we should enforce it for local `cargo test`, and only during CI, but that needs https://github.com/rust-lang/cargo/issues/5034. --- crates/hir_def/src/body/lower.rs | 6 +++--- crates/hir_def/src/lib.rs | 6 +++--- crates/hir_def/src/nameres/collector.rs | 14 +++++++------- crates/hir_def/src/test_db.rs | 14 +++++++------- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index ddc267b83..1deaa90f2 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -45,14 +45,14 @@ pub(crate) struct LowerCtx { } impl LowerCtx { - pub fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { + pub(crate) fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { LowerCtx { hygiene: Hygiene::new(db.upcast(), file_id) } } - pub fn with_hygiene(hygiene: &Hygiene) -> Self { + pub(crate) fn with_hygiene(hygiene: &Hygiene) -> Self { LowerCtx { hygiene: hygiene.clone() } } - pub fn lower_path(&self, ast: ast::Path) -> Option { + pub(crate) fn lower_path(&self, ast: ast::Path) -> Option { Path::from_src(ast, &self.hygiene) } } diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index f24a1dd77..1b22d1eec 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs @@ -486,12 +486,12 @@ impl AsMacroCall for InFile<&ast::MacroCall> { /// Helper wrapper for `AstId` with `ModPath` #[derive(Clone, Debug, Eq, PartialEq)] struct AstIdWithPath { - pub ast_id: AstId, - pub path: path::ModPath, + ast_id: AstId, + path: path::ModPath, } impl AstIdWithPath { - pub fn new(file_id: HirFileId, ast_id: FileAstId, path: path::ModPath) -> AstIdWithPath { + fn new(file_id: HirFileId, ast_id: FileAstId, path: path::ModPath) -> AstIdWithPath { AstIdWithPath { ast_id: AstId::new(file_id, ast_id), path } } } diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 1ff45d244..59b6644c3 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -122,13 +122,13 @@ enum ImportSource { #[derive(Clone, Debug, Eq, PartialEq)] struct Import { - pub path: ModPath, - pub alias: Option, - pub visibility: RawVisibility, - pub is_glob: bool, - pub is_prelude: bool, - pub is_extern_crate: bool, - pub is_macro_use: bool, + path: ModPath, + alias: Option, + visibility: RawVisibility, + is_glob: bool, + is_prelude: bool, + is_extern_crate: bool, + is_macro_use: bool, source: ImportSource, } diff --git a/crates/hir_def/src/test_db.rs b/crates/hir_def/src/test_db.rs index 2b36c824a..00fe711fe 100644 --- a/crates/hir_def/src/test_db.rs +++ b/crates/hir_def/src/test_db.rs @@ -25,7 +25,7 @@ use crate::{db::DefDatabase, ModuleDefId}; crate::db::DefDatabaseStorage )] #[derive(Default)] -pub struct TestDB { +pub(crate) struct TestDB { storage: salsa::Storage, events: Mutex>>, } @@ -72,7 +72,7 @@ impl FileLoader for TestDB { } impl TestDB { - pub fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { + pub(crate) fn module_for_file(&self, file_id: FileId) -> crate::ModuleId { for &krate in self.relevant_crates(file_id).iter() { let crate_def_map = self.crate_def_map(krate); for (local_id, data) in crate_def_map.modules.iter() { @@ -84,13 +84,13 @@ impl TestDB { panic!("Can't find module for file") } - pub fn log(&self, f: impl FnOnce()) -> Vec { + pub(crate) fn log(&self, f: impl FnOnce()) -> Vec { *self.events.lock().unwrap() = Some(Vec::new()); f(); self.events.lock().unwrap().take().unwrap() } - pub fn log_executed(&self, f: impl FnOnce()) -> Vec { + pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec { let events = self.log(f); events .into_iter() @@ -105,7 +105,7 @@ impl TestDB { .collect() } - pub fn extract_annotations(&self) -> FxHashMap> { + pub(crate) fn extract_annotations(&self) -> FxHashMap> { let mut files = Vec::new(); let crate_graph = self.crate_graph(); for krate in crate_graph.iter() { @@ -129,7 +129,7 @@ impl TestDB { .collect() } - pub fn diagnostics(&self, mut cb: F) { + pub(crate) fn diagnostics(&self, mut cb: F) { let crate_graph = self.crate_graph(); for krate in crate_graph.iter() { let crate_def_map = self.crate_def_map(krate); @@ -148,7 +148,7 @@ impl TestDB { } } - pub fn check_diagnostics(&self) { + pub(crate) fn check_diagnostics(&self) { let db: &TestDB = self; let annotations = db.extract_annotations(); assert!(!annotations.is_empty()); -- cgit v1.2.3