Skip to content

Commit b610118

Browse files
committed
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 rust-lang/cargo#5034.
1 parent e7f9086 commit b610118

File tree

34 files changed

+157
-158
lines changed

34 files changed

+157
-158
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
CARGO_NET_RETRY: 10
1313
CI: 1
1414
RUST_BACKTRACE: short
15-
RUSTFLAGS: -D warnings
15+
RUSTFLAGS: "-D warnings " # -W unreachable-pub"
1616
RUSTUP_MAX_RETRIES: 10
1717

1818
jobs:

.github/workflows/metrics.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
env:
88
CARGO_INCREMENTAL: 0
99
CARGO_NET_RETRY: 10
10-
RUSTFLAGS: -D warnings
10+
RUSTFLAGS: "-D warnings " # -W unreachable-pub"
1111
RUSTUP_MAX_RETRIES: 10
1212

1313
jobs:

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
env:
1212
CARGO_INCREMENTAL: 0
1313
CARGO_NET_RETRY: 10
14-
RUSTFLAGS: -D warnings
14+
RUSTFLAGS: "-D warnings " # -W unreachable-pub"
1515
RUSTUP_MAX_RETRIES: 10
1616

1717
jobs:

.github/workflows/rustdoc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
env:
88
CARGO_INCREMENTAL: 0
99
CARGO_NET_RETRY: 10
10-
RUSTFLAGS: -D warnings
10+
RUSTFLAGS: "-D warnings " # -W unreachable-pub"
1111
RUSTUP_MAX_RETRIES: 10
1212

1313
jobs:

crates/base_db/src/input.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use cfg::CfgOptions;
1212
use rustc_hash::{FxHashMap, FxHashSet};
1313
use syntax::SmolStr;
1414
use tt::TokenExpander;
15-
use vfs::{file_set::FileSet, VfsPath};
16-
17-
pub use vfs::FileId;
15+
use vfs::{file_set::FileSet, FileId, VfsPath};
1816

1917
/// Files are grouped into source roots. A source root is a directory on the
2018
/// file systems which is watched for changes. Typically it corresponds to a

crates/base_db/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub use crate::{
1414
change::Change,
1515
input::{
1616
CrateData, CrateDisplayName, CrateGraph, CrateId, CrateName, Dependency, Edition, Env,
17-
FileId, ProcMacroId, SourceRoot, SourceRootId,
17+
ProcMacroId, SourceRoot, SourceRootId,
1818
},
1919
};
2020
pub use salsa;
21-
pub use vfs::{file_set::FileSet, VfsPath};
21+
pub use vfs::{file_set::FileSet, FileId, VfsPath};
2222

2323
#[macro_export]
2424
macro_rules! impl_intern_key {

crates/hir_def/src/body/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ pub(crate) struct LowerCtx {
4545
}
4646

4747
impl LowerCtx {
48-
pub fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self {
48+
pub(crate) fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self {
4949
LowerCtx { hygiene: Hygiene::new(db.upcast(), file_id) }
5050
}
51-
pub fn with_hygiene(hygiene: &Hygiene) -> Self {
51+
pub(crate) fn with_hygiene(hygiene: &Hygiene) -> Self {
5252
LowerCtx { hygiene: hygiene.clone() }
5353
}
5454

55-
pub fn lower_path(&self, ast: ast::Path) -> Option<Path> {
55+
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
5656
Path::from_src(ast, &self.hygiene)
5757
}
5858
}

crates/hir_def/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@ impl AsMacroCall for InFile<&ast::MacroCall> {
486486
/// Helper wrapper for `AstId` with `ModPath`
487487
#[derive(Clone, Debug, Eq, PartialEq)]
488488
struct AstIdWithPath<T: ast::AstNode> {
489-
pub ast_id: AstId<T>,
490-
pub path: path::ModPath,
489+
ast_id: AstId<T>,
490+
path: path::ModPath,
491491
}
492492

493493
impl<T: ast::AstNode> AstIdWithPath<T> {
494-
pub fn new(file_id: HirFileId, ast_id: FileAstId<T>, path: path::ModPath) -> AstIdWithPath<T> {
494+
fn new(file_id: HirFileId, ast_id: FileAstId<T>, path: path::ModPath) -> AstIdWithPath<T> {
495495
AstIdWithPath { ast_id: AstId::new(file_id, ast_id), path }
496496
}
497497
}

crates/hir_def/src/nameres/collector.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ enum ImportSource {
122122

123123
#[derive(Clone, Debug, Eq, PartialEq)]
124124
struct Import {
125-
pub path: ModPath,
126-
pub alias: Option<ImportAlias>,
127-
pub visibility: RawVisibility,
128-
pub is_glob: bool,
129-
pub is_prelude: bool,
130-
pub is_extern_crate: bool,
131-
pub is_macro_use: bool,
125+
path: ModPath,
126+
alias: Option<ImportAlias>,
127+
visibility: RawVisibility,
128+
is_glob: bool,
129+
is_prelude: bool,
130+
is_extern_crate: bool,
131+
is_macro_use: bool,
132132
source: ImportSource,
133133
}
134134

crates/hir_def/src/test_db.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{db::DefDatabase, ModuleDefId};
2525
crate::db::DefDatabaseStorage
2626
)]
2727
#[derive(Default)]
28-
pub struct TestDB {
28+
pub(crate) struct TestDB {
2929
storage: salsa::Storage<TestDB>,
3030
events: Mutex<Option<Vec<salsa::Event>>>,
3131
}
@@ -72,7 +72,7 @@ impl FileLoader for TestDB {
7272
}
7373

7474
impl TestDB {
75-
pub fn module_for_file(&self, file_id: FileId) -> crate::ModuleId {
75+
pub(crate) fn module_for_file(&self, file_id: FileId) -> crate::ModuleId {
7676
for &krate in self.relevant_crates(file_id).iter() {
7777
let crate_def_map = self.crate_def_map(krate);
7878
for (local_id, data) in crate_def_map.modules.iter() {
@@ -84,13 +84,13 @@ impl TestDB {
8484
panic!("Can't find module for file")
8585
}
8686

87-
pub fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> {
87+
pub(crate) fn log(&self, f: impl FnOnce()) -> Vec<salsa::Event> {
8888
*self.events.lock().unwrap() = Some(Vec::new());
8989
f();
9090
self.events.lock().unwrap().take().unwrap()
9191
}
9292

93-
pub fn log_executed(&self, f: impl FnOnce()) -> Vec<String> {
93+
pub(crate) fn log_executed(&self, f: impl FnOnce()) -> Vec<String> {
9494
let events = self.log(f);
9595
events
9696
.into_iter()
@@ -105,7 +105,7 @@ impl TestDB {
105105
.collect()
106106
}
107107

108-
pub fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> {
108+
pub(crate) fn extract_annotations(&self) -> FxHashMap<FileId, Vec<(TextRange, String)>> {
109109
let mut files = Vec::new();
110110
let crate_graph = self.crate_graph();
111111
for krate in crate_graph.iter() {
@@ -129,7 +129,7 @@ impl TestDB {
129129
.collect()
130130
}
131131

132-
pub fn diagnostics<F: FnMut(&dyn Diagnostic)>(&self, mut cb: F) {
132+
pub(crate) fn diagnostics<F: FnMut(&dyn Diagnostic)>(&self, mut cb: F) {
133133
let crate_graph = self.crate_graph();
134134
for krate in crate_graph.iter() {
135135
let crate_def_map = self.crate_def_map(krate);
@@ -148,7 +148,7 @@ impl TestDB {
148148
}
149149
}
150150

151-
pub fn check_diagnostics(&self) {
151+
pub(crate) fn check_diagnostics(&self) {
152152
let db: &TestDB = self;
153153
let annotations = db.extract_annotations();
154154
assert!(!annotations.is_empty());

0 commit comments

Comments
 (0)