Skip to content

Commit 1dd0f35

Browse files
authored
Rollup merge of #154741 - Zalathar:unreachable-pub, r=jieyouxu
Enforce `#![warn(unreachable_pub)]` in compiletest source The actual public API surface of compiletest is restricted to two specific modules, `cli` and `rustdoc_gui_test`. Other items have no reason to be `pub`. There should be no change to compiletest behaviour.
2 parents c2d0094 + 14c7788 commit 1dd0f35

14 files changed

Lines changed: 314 additions & 311 deletions

File tree

src/tools/compiletest/src/common.rs

Lines changed: 158 additions & 158 deletions
Large diffs are not rendered by default.

src/tools/compiletest/src/directives.rs

Lines changed: 102 additions & 102 deletions
Large diffs are not rendered by default.

src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ mod tests;
1313

1414
/// The value of an `aux-crate` directive.
1515
#[derive(Clone, Debug, Default, PartialEq, Eq)]
16-
pub struct AuxCrate {
16+
pub(crate) struct AuxCrate {
1717
/// Contains `--extern` modifiers, if any. See the tracking issue for more
1818
/// info: <https://github.com/rust-lang/rust/issues/98405>
1919
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`.
20-
pub extern_modifiers: Option<String>,
20+
pub(crate) extern_modifiers: Option<String>,
2121
/// With `aux-crate: foo=bar.rs` this will be `foo`.
2222
/// With `aux-crate: noprelude:foo=bar.rs` this will be `foo`.
23-
pub name: String,
23+
pub(crate) name: String,
2424
/// With `aux-crate: foo=bar.rs` this will be `bar.rs`.
25-
pub path: String,
25+
pub(crate) path: String,
2626
}
2727

2828
/// The value of a `proc-macro` directive.
@@ -31,9 +31,9 @@ pub(crate) struct ProcMacro {
3131
/// Contains `--extern` modifiers, if any. See the tracking issue for more
3232
/// info: <https://github.com/rust-lang/rust/issues/98405>
3333
/// With `proc-macro: noprelude:bar.rs` this will be `noprelude`.
34-
pub extern_modifiers: Option<String>,
34+
pub(crate) extern_modifiers: Option<String>,
3535
/// With `proc-macro: bar.rs` this will be `bar.rs`.
36-
pub path: String,
36+
pub(crate) path: String,
3737
}
3838

3939
/// Properties parsed from `aux-*` test directives.

src/tools/compiletest/src/edition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::fatal;
22

33
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
4-
pub enum Edition {
4+
pub(crate) enum Edition {
55
// Note that the ordering here is load-bearing, as we want the future edition to be greater than
66
// any year-based edition.
77
Year(u32),
@@ -23,7 +23,7 @@ impl From<u32> for Edition {
2323
}
2424
}
2525

26-
pub fn parse_edition(mut input: &str) -> Edition {
26+
pub(crate) fn parse_edition(mut input: &str) -> Edition {
2727
input = input.trim();
2828
if input == "future" {
2929
Edition::Future

src/tools/compiletest/src/errors.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use regex::Regex;
99
use tracing::*;
1010

1111
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
12-
pub enum ErrorKind {
12+
pub(crate) enum ErrorKind {
1313
Help,
1414
Error,
1515
Note,
@@ -21,7 +21,7 @@ pub enum ErrorKind {
2121
}
2222

2323
impl ErrorKind {
24-
pub fn from_compiler_str(s: &str) -> ErrorKind {
24+
pub(crate) fn from_compiler_str(s: &str) -> ErrorKind {
2525
match s {
2626
"help" => ErrorKind::Help,
2727
"error" | "error: internal compiler error" => ErrorKind::Error,
@@ -45,7 +45,7 @@ impl ErrorKind {
4545
})
4646
}
4747

48-
pub fn expect_from_user_str(s: &str) -> ErrorKind {
48+
pub(crate) fn expect_from_user_str(s: &str) -> ErrorKind {
4949
ErrorKind::from_user_str(s).unwrap_or_else(|| {
5050
panic!(
5151
"unexpected diagnostic kind `{s}`, expected \
@@ -70,16 +70,16 @@ impl fmt::Display for ErrorKind {
7070
}
7171

7272
#[derive(Debug)]
73-
pub struct Error {
74-
pub line_num: Option<usize>,
75-
pub column_num: Option<usize>,
73+
pub(crate) struct Error {
74+
pub(crate) line_num: Option<usize>,
75+
pub(crate) column_num: Option<usize>,
7676
/// What kind of message we expect (e.g., warning, error, suggestion).
77-
pub kind: ErrorKind,
78-
pub msg: String,
77+
pub(crate) kind: ErrorKind,
78+
pub(crate) msg: String,
7979
/// For some `Error`s, like secondary lines of multi-line diagnostics, line annotations
8080
/// are not mandatory, even if they would otherwise be mandatory for primary errors.
8181
/// Only makes sense for "actual" errors, not for "expected" errors.
82-
pub require_annotation: bool,
82+
pub(crate) require_annotation: bool,
8383
}
8484

8585
/// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE"
@@ -92,7 +92,7 @@ pub struct Error {
9292
///
9393
/// If revision is not None, then we look
9494
/// for `//[X]~` instead, where `X` is the current revision.
95-
pub fn load_errors(testfile: &Utf8Path, revision: Option<&str>) -> Vec<Error> {
95+
pub(crate) fn load_errors(testfile: &Utf8Path, revision: Option<&str>) -> Vec<Error> {
9696
let rdr = BufReader::new(File::open(testfile.as_std_path()).unwrap());
9797

9898
// `last_nonfollow_error` tracks the most recently seen

src/tools/compiletest/src/json.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ struct DiagnosticCode {
8383
code: String,
8484
}
8585

86-
pub fn rustfix_diagnostics_only(output: &str) -> String {
86+
pub(crate) fn rustfix_diagnostics_only(output: &str) -> String {
8787
output
8888
.lines()
8989
.filter(|line| line.starts_with('{') && serde_json::from_str::<Diagnostic>(line).is_ok())
9090
.collect()
9191
}
9292

93-
pub fn extract_rendered(output: &str) -> String {
93+
pub(crate) fn extract_rendered(output: &str) -> String {
9494
output
9595
.lines()
9696
.filter_map(|line| {
@@ -137,7 +137,7 @@ pub fn extract_rendered(output: &str) -> String {
137137
.collect()
138138
}
139139

140-
pub fn parse_output(file_name: &str, output: &str) -> Vec<Error> {
140+
pub(crate) fn parse_output(file_name: &str, output: &str) -> Vec<Error> {
141141
let mut errors = Vec::new();
142142
for line in output.lines() {
143143
// Compiler can emit non-json lines in non-`--error-format=json` modes,

src/tools/compiletest/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#![crate_name = "compiletest"]
2+
#![warn(unreachable_pub)]
23

34
#[cfg(test)]
45
mod tests;
56

7+
// Public modules needed by the compiletest binary or by `rustdoc-gui-test`.
68
pub mod cli;
9+
pub mod rustdoc_gui_test;
10+
711
mod common;
812
mod debuggers;
913
mod diagnostics;
@@ -17,7 +21,6 @@ mod panic_hook;
1721
mod raise_fd_limit;
1822
mod read2;
1923
mod runtest;
20-
pub mod rustdoc_gui_test;
2124
mod util;
2225

2326
use core::panic;

src/tools/compiletest/src/output_capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::panic::RefUnwindSafe;
33
use std::sync::Mutex;
44

5-
pub trait ConsoleOut: fmt::Debug + RefUnwindSafe {
5+
pub(crate) trait ConsoleOut: fmt::Debug + RefUnwindSafe {
66
fn write_fmt(&self, args: fmt::Arguments<'_>);
77
}
88

src/tools/compiletest/src/raise_fd_limit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#[cfg(target_vendor = "apple")]
88
#[allow(non_camel_case_types)]
99
// FIXME(#139616): document caller contract.
10-
pub unsafe fn raise_fd_limit() {
10+
pub(crate) unsafe fn raise_fd_limit() {
1111
use std::ptr::null_mut;
1212
use std::{cmp, io};
1313

@@ -54,4 +54,4 @@ pub unsafe fn raise_fd_limit() {
5454
}
5555

5656
#[cfg(not(target_vendor = "apple"))]
57-
pub unsafe fn raise_fd_limit() {}
57+
pub(crate) unsafe fn raise_fd_limit() {}

src/tools/compiletest/src/read2.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ mod tests;
77
use std::io::{self, Write};
88
use std::process::{Child, Output};
99

10-
pub use self::imp::read2;
10+
use self::imp::read2;
1111

1212
#[derive(Copy, Clone, Debug)]
13-
pub enum Truncated {
13+
pub(crate) enum Truncated {
1414
Yes,
1515
No,
1616
}
1717

18-
pub fn read2_abbreviated(
18+
pub(crate) fn read2_abbreviated(
1919
mut child: Child,
2020
filter_paths_from_len: &[String],
2121
) -> io::Result<(Output, Truncated)> {
@@ -138,7 +138,7 @@ mod imp {
138138
use std::io::{self, Read};
139139
use std::process::{ChildStderr, ChildStdout};
140140

141-
pub fn read2(
141+
pub(crate) fn read2(
142142
out_pipe: ChildStdout,
143143
err_pipe: ChildStderr,
144144
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
@@ -160,7 +160,7 @@ mod imp {
160160
use std::process::{ChildStderr, ChildStdout};
161161
use std::{io, mem};
162162

163-
pub fn read2(
163+
pub(crate) fn read2(
164164
mut out_pipe: ChildStdout,
165165
mut err_pipe: ChildStderr,
166166
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),
@@ -247,7 +247,7 @@ mod imp {
247247
done: bool,
248248
}
249249

250-
pub fn read2(
250+
pub(crate) fn read2(
251251
out_pipe: ChildStdout,
252252
err_pipe: ChildStderr,
253253
data: &mut dyn FnMut(bool, &mut Vec<u8>, bool),

0 commit comments

Comments
 (0)