Skip to content

Commit 444a0ff

Browse files
committed
globally introduce #! [deny(unreachable_pub)]
Signed-off-by: hi-rustin <[email protected]>
1 parent 0e163d2 commit 444a0ff

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

src/dist/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ pub(crate) const SUPPORTED_CONFIG_VERSIONS: [&str; 1] = ["1"];
88
pub(crate) const DEFAULT_CONFIG_VERSION: &str = "1";
99

1010
#[derive(Clone, Debug)]
11-
pub struct Config {
12-
pub config_version: String,
13-
pub components: Vec<Component>,
11+
pub(crate) struct Config {
12+
pub(crate) config_version: String,
13+
pub(crate) components: Vec<Component>,
1414
}
1515

1616
impl Config {

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(rust_2018_idioms)]
2+
#![deny(unreachable_pub)]
23
#![allow(
34
clippy::too_many_arguments,
45
clippy::type_complexity,

src/settings.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ impl SettingsFile {
7373
}
7474

7575
#[derive(Clone, Debug, PartialEq)]
76-
pub struct Settings {
77-
pub version: String,
78-
pub default_host_triple: Option<String>,
79-
pub default_toolchain: Option<String>,
80-
pub profile: Option<Profile>,
81-
pub overrides: BTreeMap<String, String>,
82-
pub pgp_keys: Option<String>,
83-
pub auto_self_update: Option<SelfUpdateMode>,
76+
pub(crate) struct Settings {
77+
pub(crate) version: String,
78+
pub(crate) default_host_triple: Option<String>,
79+
pub(crate) default_toolchain: Option<String>,
80+
pub(crate) profile: Option<Profile>,
81+
pub(crate) overrides: BTreeMap<String, String>,
82+
pub(crate) pgp_keys: Option<String>,
83+
pub(crate) auto_self_update: Option<SelfUpdateMode>,
8484
}
8585

8686
impl Default for Settings {

src/toolchain.rs

+40-38
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ enum InstalledPath<'a> {
4242
}
4343

4444
/// A fully resolved reference to a toolchain which may or may not exist
45-
pub struct Toolchain<'a> {
45+
pub(crate) struct Toolchain<'a> {
4646
cfg: &'a Cfg,
4747
name: String,
4848
path: PathBuf,
4949
dist_handler: Box<dyn Fn(crate::dist::Notification<'_>) + 'a>,
5050
}
5151

5252
/// Used by the `list_component` function
53-
pub struct ComponentStatus {
54-
pub component: Component,
55-
pub name: String,
56-
pub installed: bool,
57-
pub available: bool,
53+
pub(crate) struct ComponentStatus {
54+
pub(crate) component: Component,
55+
pub(crate) name: String,
56+
pub(crate) installed: bool,
57+
pub(crate) available: bool,
5858
}
5959

6060
#[derive(Clone, Debug)]
61-
pub enum UpdateStatus {
61+
pub(crate) enum UpdateStatus {
6262
Installed,
6363
Updated(String), // Stores the version of rustc *before* the update
6464
Unchanged,
@@ -110,7 +110,7 @@ impl<'a> Toolchain<'a> {
110110
})
111111
}
112112

113-
pub fn as_installed_common(&'a self) -> Result<InstalledCommonToolchain<'a>> {
113+
pub(crate) fn as_installed_common(&'a self) -> Result<InstalledCommonToolchain<'a>> {
114114
if !self.exists() {
115115
// Should be verify perhaps?
116116
return Err(RustupError::ToolchainNotInstalled(self.name.to_owned()).into());
@@ -130,10 +130,10 @@ impl<'a> Toolchain<'a> {
130130
pub(crate) fn cfg(&self) -> &Cfg {
131131
self.cfg
132132
}
133-
pub fn name(&self) -> &str {
133+
pub(crate) fn name(&self) -> &str {
134134
&self.name
135135
}
136-
pub fn path(&self) -> &Path {
136+
pub(crate) fn path(&self) -> &Path {
137137
&self.path
138138
}
139139
fn is_symlink(&self) -> bool {
@@ -145,7 +145,7 @@ impl<'a> Toolchain<'a> {
145145
/// Is there a filesystem component with the name of the toolchain in the toolchains dir - valid install or not.
146146
/// Used to determine whether this toolchain should be uninstallable.
147147
/// Custom and Distributable. Installed and uninstalled. (perhaps onstalled only?)
148-
pub fn exists(&self) -> bool {
148+
pub(crate) fn exists(&self) -> bool {
149149
// HACK: linked toolchains are symlinks, and, contrary to what std docs
150150
// lead me to believe `fs::metadata`, used by `is_directory` does not
151151
// seem to follow symlinks on windows.
@@ -159,11 +159,11 @@ impl<'a> Toolchain<'a> {
159159
/// Is there a valid usable toolchain with this name, either in the toolchains dir, or symlinked from it.
160160
// Could in future check for rustc perhaps.
161161
// Custom and Distributable. Installed only?
162-
pub fn verify(&self) -> Result<()> {
162+
pub(crate) fn verify(&self) -> Result<()> {
163163
utils::assert_is_directory(&self.path)
164164
}
165165
// Custom and Distributable. Installed only.
166-
pub fn remove(&self) -> Result<()> {
166+
pub(crate) fn remove(&self) -> Result<()> {
167167
if self.exists() || self.is_symlink() {
168168
(self.cfg.notify_handler)(Notification::UninstallingToolchain(&self.name));
169169
} else {
@@ -186,7 +186,7 @@ impl<'a> Toolchain<'a> {
186186
}
187187

188188
// Custom only
189-
pub fn is_custom(&self) -> bool {
189+
pub(crate) fn is_custom(&self) -> bool {
190190
Toolchain::is_custom_name(&self.name)
191191
}
192192

@@ -195,15 +195,15 @@ impl<'a> Toolchain<'a> {
195195
}
196196

197197
// Distributable only
198-
pub fn is_tracking(&self) -> bool {
198+
pub(crate) fn is_tracking(&self) -> bool {
199199
ToolchainDesc::from_str(&self.name)
200200
.ok()
201201
.map(|d| d.is_tracking())
202202
== Some(true)
203203
}
204204

205205
// Custom and Distributable. Installed only.
206-
pub fn doc_path(&self, relative: &str) -> Result<PathBuf> {
206+
pub(crate) fn doc_path(&self, relative: &str) -> Result<PathBuf> {
207207
self.verify()?;
208208

209209
let parts = vec!["share", "doc", "rust", "html"];
@@ -216,31 +216,31 @@ impl<'a> Toolchain<'a> {
216216
Ok(doc_dir)
217217
}
218218
// Custom and Distributable. Installed only.
219-
pub fn open_docs(&self, relative: &str) -> Result<()> {
219+
pub(crate) fn open_docs(&self, relative: &str) -> Result<()> {
220220
self.verify()?;
221221

222222
utils::open_browser(&self.doc_path(relative)?)
223223
}
224224
// Custom and Distributable. Installed only.
225-
pub fn make_default(&self) -> Result<()> {
225+
pub(crate) fn make_default(&self) -> Result<()> {
226226
self.cfg.set_default(&self.name)
227227
}
228228
// Custom and Distributable. Installed only.
229-
pub fn make_override(&self, path: &Path) -> Result<()> {
229+
pub(crate) fn make_override(&self, path: &Path) -> Result<()> {
230230
self.cfg.settings_file.with_mut(|s| {
231231
s.add_override(path, self.name.clone(), self.cfg.notify_handler.as_ref());
232232
Ok(())
233233
})
234234
}
235235
// Distributable and Custom. Installed only.
236-
pub fn binary_file(&self, name: &str) -> PathBuf {
236+
pub(crate) fn binary_file(&self, name: &str) -> PathBuf {
237237
let mut path = self.path.clone();
238238
path.push("bin");
239239
path.push(name.to_owned() + env::consts::EXE_SUFFIX);
240240
path
241241
}
242242
// Distributable and Custom. Installed only.
243-
pub fn rustc_version(&self) -> String {
243+
pub(crate) fn rustc_version(&self) -> String {
244244
if let Ok(installed) = self.as_installed_common() {
245245
let rustc_path = self.binary_file("rustc");
246246
if utils::is_file(&rustc_path) {
@@ -318,10 +318,10 @@ fn install_msg(bin: &str, toolchain: &str, is_default: bool) -> String {
318318
}
319319
}
320320
/// Newtype hosting functions that apply to both custom and distributable toolchains that are installed.
321-
pub struct InstalledCommonToolchain<'a>(&'a Toolchain<'a>);
321+
pub(crate) struct InstalledCommonToolchain<'a>(&'a Toolchain<'a>);
322322

323323
impl<'a> InstalledCommonToolchain<'a> {
324-
pub fn create_command<T: AsRef<OsStr>>(&self, binary: T) -> Result<Command> {
324+
pub(crate) fn create_command<T: AsRef<OsStr>>(&self, binary: T) -> Result<Command> {
325325
// Create the path to this binary within the current toolchain sysroot
326326
let binary = if let Some(binary_str) = binary.as_ref().to_str() {
327327
if binary_str.to_lowercase().ends_with(EXE_SUFFIX) {
@@ -423,7 +423,7 @@ impl<'a> InstalledCommonToolchain<'a> {
423423
// find the library in the install path.
424424
// Setting DYLD_LIBRARY_PATH can easily have unintended
425425
// consequences.
426-
pub const LOADER_PATH: &str = "DYLD_FALLBACK_LIBRARY_PATH";
426+
pub(crate) const LOADER_PATH: &str = "DYLD_FALLBACK_LIBRARY_PATH";
427427
}
428428
if cfg!(target_os = "macos")
429429
&& process()
@@ -461,10 +461,10 @@ impl<'a> InstalledCommonToolchain<'a> {
461461
}
462462

463463
/// Newtype to facilitate splitting out custom-toolchain specific code.
464-
pub struct CustomToolchain<'a>(&'a Toolchain<'a>);
464+
pub(crate) struct CustomToolchain<'a>(&'a Toolchain<'a>);
465465

466466
impl<'a> CustomToolchain<'a> {
467-
pub fn new(toolchain: &'a Toolchain<'a>) -> Result<CustomToolchain<'a>> {
467+
pub(crate) fn new(toolchain: &'a Toolchain<'a>) -> Result<CustomToolchain<'a>> {
468468
if toolchain.is_custom() {
469469
Ok(CustomToolchain(toolchain))
470470
} else {
@@ -476,7 +476,7 @@ impl<'a> CustomToolchain<'a> {
476476
}
477477

478478
// Not installed only.
479-
pub fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
479+
pub(crate) fn install_from_dir(&self, src: &Path, link: bool) -> Result<()> {
480480
let mut pathbuf = PathBuf::from(src);
481481

482482
pathbuf.push("lib");
@@ -505,10 +505,10 @@ impl<'a> InstalledToolchain<'a> for CustomToolchain<'a> {
505505
}
506506

507507
/// Newtype to facilitate splitting out distributable-toolchain specific code.
508-
pub struct DistributableToolchain<'a>(&'a Toolchain<'a>);
508+
pub(crate) struct DistributableToolchain<'a>(&'a Toolchain<'a>);
509509

510510
impl<'a> DistributableToolchain<'a> {
511-
pub fn new(toolchain: &'a Toolchain<'a>) -> Result<DistributableToolchain<'a>> {
511+
pub(crate) fn new(toolchain: &'a Toolchain<'a>) -> Result<DistributableToolchain<'a>> {
512512
if toolchain.is_custom() {
513513
Err(anyhow!(format!(
514514
"{} is a custom toolchain",
@@ -521,7 +521,9 @@ impl<'a> DistributableToolchain<'a> {
521521

522522
/// Temporary helper until we further split this into a newtype for
523523
/// InstalledDistributableToolchain - one where the type can protect component operations.
524-
pub fn new_for_components(toolchain: &'a Toolchain<'a>) -> Result<DistributableToolchain<'a>> {
524+
pub(crate) fn new_for_components(
525+
toolchain: &'a Toolchain<'a>,
526+
) -> Result<DistributableToolchain<'a>> {
525527
DistributableToolchain::new(toolchain).context(RustupError::ComponentsUnsupported(
526528
toolchain.name().to_string(),
527529
))
@@ -591,7 +593,7 @@ impl<'a> DistributableToolchain<'a> {
591593
// Create a command as a fallback for another toolchain. This is used
592594
// to give custom toolchains access to cargo
593595
// Installed only.
594-
pub fn create_fallback_command<T: AsRef<OsStr>>(
596+
pub(crate) fn create_fallback_command<T: AsRef<OsStr>>(
595597
&self,
596598
binary: T,
597599
primary_toolchain: &Toolchain<'_>,
@@ -764,7 +766,7 @@ impl<'a> DistributableToolchain<'a> {
764766
}
765767

766768
// Installed or not installed.
767-
pub fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
769+
pub(crate) fn install_from_dist_if_not_installed(&self) -> Result<UpdateStatus> {
768770
let update_hash = self.update_hash()?;
769771
(self.0.cfg.notify_handler)(Notification::LookingForToolchain(&self.0.name));
770772
if !self.0.exists() {
@@ -808,7 +810,7 @@ impl<'a> DistributableToolchain<'a> {
808810
}))
809811
}
810812

811-
pub fn list_components(&self) -> Result<Vec<ComponentStatus>> {
813+
pub(crate) fn list_components(&self) -> Result<Vec<ComponentStatus>> {
812814
if let Some(toolchain) = self.get_toolchain_desc_with_manifest()? {
813815
toolchain.list_components()
814816
} else {
@@ -864,7 +866,7 @@ impl<'a> DistributableToolchain<'a> {
864866
}
865867

866868
// Installed only.
867-
pub fn show_dist_version(&self) -> Result<Option<String>> {
869+
pub(crate) fn show_dist_version(&self) -> Result<Option<String>> {
868870
let update_hash = self.update_hash()?;
869871

870872
match crate::dist::dist::dl_v2_manifest(
@@ -878,20 +880,20 @@ impl<'a> DistributableToolchain<'a> {
878880
}
879881

880882
// Installed only.
881-
pub fn show_version(&self) -> Result<Option<String>> {
883+
pub(crate) fn show_version(&self) -> Result<Option<String>> {
882884
match self.get_manifest()? {
883885
Some(manifest) => Ok(Some(manifest.get_rust_version()?.to_string())),
884886
None => Ok(None),
885887
}
886888
}
887889

888890
// Installed only.
889-
fn update_hash(&self) -> Result<PathBuf> {
891+
pub(crate) fn update_hash(&self) -> Result<PathBuf> {
890892
self.0.cfg.get_hash_file(&self.0.name, true)
891893
}
892894

893895
// Installed only.
894-
pub fn guess_v1_manifest(&self) -> bool {
896+
pub(crate) fn guess_v1_manifest(&self) -> bool {
895897
let prefix = InstallPrefix::from(self.0.path().to_owned());
896898
// If all the v1 common components are present this is likely to be
897899
// a v1 manifest install. The v1 components are not called the same
@@ -912,7 +914,7 @@ impl<'a> DistributableToolchain<'a> {
912914
pub(crate) struct ToolchainDescWithManifest {
913915
toolchain: ToolchainDesc,
914916
manifestation: Manifestation,
915-
pub manifest: Manifest,
917+
pub(crate) manifest: Manifest,
916918
}
917919

918920
impl ToolchainDescWithManifest {

0 commit comments

Comments
 (0)