Skip to content

Commit 53a753e

Browse files
authored
Rollup merge of rust-lang#122748 - nnethercote:rustc_session-pub, r=jackh726
Reduce `pub` usage in `rustc_session`. In particular, almost none of the errors in `errors.rs` are used outside the crate. r? `@jackh726`
2 parents d7209bf + de38888 commit 53a753e

File tree

2 files changed

+130
-132
lines changed

2 files changed

+130
-132
lines changed

compiler/rustc_session/src/config.rs

+26-28
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub struct LocationDetail {
313313
}
314314

315315
impl LocationDetail {
316-
pub fn all() -> Self {
316+
pub(crate) fn all() -> Self {
317317
Self { file: true, line: true, column: true }
318318
}
319319
}
@@ -549,7 +549,7 @@ impl OutputTypes {
549549
OutputTypes(BTreeMap::from_iter(entries.iter().map(|&(k, ref v)| (k, v.clone()))))
550550
}
551551

552-
pub fn get(&self, key: &OutputType) -> Option<&Option<OutFileName>> {
552+
pub(crate) fn get(&self, key: &OutputType) -> Option<&Option<OutFileName>> {
553553
self.0.get(key)
554554
}
555555

@@ -662,10 +662,6 @@ impl Externs {
662662
pub fn iter(&self) -> BTreeMapIter<'_, String, ExternEntry> {
663663
self.0.iter()
664664
}
665-
666-
pub fn len(&self) -> usize {
667-
self.0.len()
668-
}
669665
}
670666

671667
impl ExternEntry {
@@ -854,13 +850,13 @@ impl OutFileName {
854850

855851
#[derive(Clone, Hash, Debug, HashStable_Generic, Encodable, Decodable)]
856852
pub struct OutputFilenames {
857-
pub out_directory: PathBuf,
853+
pub(crate) out_directory: PathBuf,
858854
/// Crate name. Never contains '-'.
859855
crate_stem: String,
860856
/// Typically based on `.rs` input file name. Any '-' is preserved.
861857
filestem: String,
862858
pub single_output_file: Option<OutFileName>,
863-
pub temps_directory: Option<PathBuf>,
859+
temps_directory: Option<PathBuf>,
864860
pub outputs: OutputTypes,
865861
}
866862

@@ -898,7 +894,7 @@ impl OutputFilenames {
898894

899895
/// Gets the output path where a compilation artifact of the given type
900896
/// should be placed on disk.
901-
pub fn output_path(&self, flavor: OutputType) -> PathBuf {
897+
fn output_path(&self, flavor: OutputType) -> PathBuf {
902898
let extension = flavor.extension();
903899
match flavor {
904900
OutputType::Metadata => {
@@ -1092,7 +1088,7 @@ impl Options {
10921088
|| self.unstable_opts.query_dep_graph
10931089
}
10941090

1095-
pub fn file_path_mapping(&self) -> FilePathMapping {
1091+
pub(crate) fn file_path_mapping(&self) -> FilePathMapping {
10961092
file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
10971093
}
10981094

@@ -1173,14 +1169,14 @@ pub enum Passes {
11731169
}
11741170

11751171
impl Passes {
1176-
pub fn is_empty(&self) -> bool {
1172+
fn is_empty(&self) -> bool {
11771173
match *self {
11781174
Passes::Some(ref v) => v.is_empty(),
11791175
Passes::All => false,
11801176
}
11811177
}
11821178

1183-
pub fn extend(&mut self, passes: impl IntoIterator<Item = String>) {
1179+
pub(crate) fn extend(&mut self, passes: impl IntoIterator<Item = String>) {
11841180
match *self {
11851181
Passes::Some(ref mut v) => v.extend(passes),
11861182
Passes::All => {}
@@ -1206,7 +1202,7 @@ pub struct BranchProtection {
12061202
pub pac_ret: Option<PacRet>,
12071203
}
12081204

1209-
pub const fn default_lib_output() -> CrateType {
1205+
pub(crate) const fn default_lib_output() -> CrateType {
12101206
CrateType::Rlib
12111207
}
12121208

@@ -1584,15 +1580,15 @@ pub fn build_target_config(
15841580
}
15851581

15861582
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
1587-
pub enum OptionStability {
1583+
enum OptionStability {
15881584
Stable,
15891585
Unstable,
15901586
}
15911587

15921588
pub struct RustcOptGroup {
15931589
pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
1594-
pub name: &'static str,
1595-
pub stability: OptionStability,
1590+
name: &'static str,
1591+
stability: OptionStability,
15961592
}
15971593

15981594
impl RustcOptGroup {
@@ -1628,8 +1624,8 @@ mod opt {
16281624

16291625
use super::RustcOptGroup;
16301626

1631-
pub type R = RustcOptGroup;
1632-
pub type S = &'static str;
1627+
type R = RustcOptGroup;
1628+
type S = &'static str;
16331629

16341630
fn stable<F>(name: S, f: F) -> R
16351631
where
@@ -1649,32 +1645,34 @@ mod opt {
16491645
if a.len() > b.len() { a } else { b }
16501646
}
16511647

1652-
pub fn opt_s(a: S, b: S, c: S, d: S) -> R {
1648+
pub(crate) fn opt_s(a: S, b: S, c: S, d: S) -> R {
16531649
stable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
16541650
}
1655-
pub fn multi_s(a: S, b: S, c: S, d: S) -> R {
1651+
pub(crate) fn multi_s(a: S, b: S, c: S, d: S) -> R {
16561652
stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
16571653
}
1658-
pub fn flag_s(a: S, b: S, c: S) -> R {
1654+
pub(crate) fn flag_s(a: S, b: S, c: S) -> R {
16591655
stable(longer(a, b), move |opts| opts.optflag(a, b, c))
16601656
}
1661-
pub fn flagmulti_s(a: S, b: S, c: S) -> R {
1657+
pub(crate) fn flagmulti_s(a: S, b: S, c: S) -> R {
16621658
stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
16631659
}
16641660

1665-
pub fn opt(a: S, b: S, c: S, d: S) -> R {
1661+
fn opt(a: S, b: S, c: S, d: S) -> R {
16661662
unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
16671663
}
1668-
pub fn multi(a: S, b: S, c: S, d: S) -> R {
1664+
pub(crate) fn multi(a: S, b: S, c: S, d: S) -> R {
16691665
unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
16701666
}
16711667
}
1668+
16721669
static EDITION_STRING: LazyLock<String> = LazyLock::new(|| {
16731670
format!(
16741671
"Specify which edition of the compiler to use when compiling code. \
16751672
The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE_EDITION}."
16761673
)
16771674
});
1675+
16781676
/// Returns the "short" subset of the rustc command line options,
16791677
/// including metadata for each option, such as whether the option is
16801678
/// part of the stable long-term interface for rustc.
@@ -1864,9 +1862,9 @@ pub fn parse_color(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> Col
18641862
/// Possible json config files
18651863
pub struct JsonConfig {
18661864
pub json_rendered: HumanReadableErrorType,
1867-
pub json_artifact_notifications: bool,
1865+
json_artifact_notifications: bool,
18681866
pub json_unused_externs: JsonUnusedExterns,
1869-
pub json_future_incompat: bool,
1867+
json_future_incompat: bool,
18701868
}
18711869

18721870
/// Report unused externs in event stream
@@ -2992,7 +2990,7 @@ pub mod nightly_options {
29922990
is_nightly_build(matches.opt_str("crate-name").as_deref())
29932991
}
29942992

2995-
pub fn is_nightly_build(krate: Option<&str>) -> bool {
2993+
fn is_nightly_build(krate: Option<&str>) -> bool {
29962994
UnstableFeatures::from_environment(krate).is_nightly_build()
29972995
}
29982996

@@ -3199,7 +3197,7 @@ pub(crate) mod dep_tracking {
31993197
use std::num::NonZero;
32003198
use std::path::PathBuf;
32013199

3202-
pub trait DepTrackingHash {
3200+
pub(crate) trait DepTrackingHash {
32033201
fn hash(
32043202
&self,
32053203
hasher: &mut DefaultHasher,

0 commit comments

Comments
 (0)