Skip to content

Commit b4aa7c3

Browse files
authored
Rollup merge of rust-lang#129648 - nnethercote:unreachable_pub-2, r=Urgau
More `unreachable_pub` Add `unreachable_pub` checking to some more compiler crates. A follow-up to rust-lang#126013. r? `@Urgau`
2 parents 93992f1 + 22cdd63 commit b4aa7c3

File tree

112 files changed

+743
-703
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+743
-703
lines changed

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(panic_update_hook)]
1717
#![feature(result_flattening)]
1818
#![feature(rustdoc_internals)]
19+
#![warn(unreachable_pub)]
1920
// tidy-alphabetical-end
2021

2122
use std::cmp::max;

compiler/rustc_error_codes/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![deny(rustdoc::invalid_codeblock_attributes)]
77
#![doc(rust_logo)]
88
#![feature(rustdoc_internals)]
9+
#![warn(unreachable_pub)]
910
// tidy-alphabetical-end
1011

1112
// This higher-order macro defines the error codes that are in use. It is used

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![feature(rustc_attrs)]
55
#![feature(rustdoc_internals)]
66
#![feature(type_alias_impl_trait)]
7+
#![warn(unreachable_pub)]
78
// tidy-alphabetical-end
89

910
use std::borrow::Cow;

compiler/rustc_errors/src/diagnostic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
204204
}
205205

206206
#[derive(Clone, Debug, Encodable, Decodable)]
207-
pub struct DiagLocation {
207+
pub(crate) struct DiagLocation {
208208
file: Cow<'static, str>,
209209
line: u32,
210210
col: u32,

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ enum DisplaySuggestion {
23872387
impl FileWithAnnotatedLines {
23882388
/// Preprocess all the annotations so that they are grouped by file and by line number
23892389
/// This helps us quickly iterate over the whole message (including secondary file spans)
2390-
pub fn collect_annotations(
2390+
pub(crate) fn collect_annotations(
23912391
emitter: &dyn Emitter,
23922392
args: &FluentArgs<'_>,
23932393
msp: &MultiSpan,

compiler/rustc_errors/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(trait_alias)]
2626
#![feature(try_blocks)]
2727
#![feature(yeet_expr)]
28+
#![warn(unreachable_pub)]
2829
// tidy-alphabetical-end
2930

3031
extern crate self as rustc_errors;
@@ -1701,7 +1702,7 @@ impl DiagCtxtInner {
17011702
}
17021703

17031704
/// Translate `message` eagerly with `args` to `SubdiagMessage::Eager`.
1704-
pub fn eagerly_translate<'a>(
1705+
fn eagerly_translate<'a>(
17051706
&self,
17061707
message: DiagMessage,
17071708
args: impl Iterator<Item = DiagArg<'a>>,
@@ -1710,7 +1711,7 @@ impl DiagCtxtInner {
17101711
}
17111712

17121713
/// Translate `message` eagerly with `args` to `String`.
1713-
pub fn eagerly_translate_to_string<'a>(
1714+
fn eagerly_translate_to_string<'a>(
17141715
&self,
17151716
message: DiagMessage,
17161717
args: impl Iterator<Item = DiagArg<'a>>,

compiler/rustc_errors/src/lock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use std::any::Any;
1313

1414
#[cfg(windows)]
15-
pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
15+
pub(crate) fn acquire_global_lock(name: &str) -> Box<dyn Any> {
1616
use std::ffi::CString;
1717
use std::io;
1818

@@ -80,6 +80,6 @@ pub fn acquire_global_lock(name: &str) -> Box<dyn Any> {
8080
}
8181

8282
#[cfg(not(windows))]
83-
pub fn acquire_global_lock(_name: &str) -> Box<dyn Any> {
83+
pub(crate) fn acquire_global_lock(_name: &str) -> Box<dyn Any> {
8484
Box::new(())
8585
}

compiler/rustc_errors/src/markdown/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ enum ParseOpt {
7474
}
7575

7676
/// Parse a buffer
77-
pub fn entrypoint(txt: &str) -> MdStream<'_> {
77+
pub(crate) fn entrypoint(txt: &str) -> MdStream<'_> {
7878
let ctx = Context { top_block: true, prev: Prev::Newline };
7979
normalize(parse_recursive(txt.trim().as_bytes(), ctx), &mut Vec::new())
8080
}

compiler/rustc_errors/src/markdown/term.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ thread_local! {
1515
}
1616

1717
/// Print to terminal output to a buffer
18-
pub fn entrypoint(stream: &MdStream<'_>, buf: &mut Buffer) -> io::Result<()> {
18+
pub(crate) fn entrypoint(stream: &MdStream<'_>, buf: &mut Buffer) -> io::Result<()> {
1919
#[cfg(not(test))]
2020
if let Some((w, _)) = termize::dimensions() {
2121
WIDTH.with(|c| c.set(std::cmp::min(w, DEFAULT_COLUMN_WIDTH)));
@@ -47,7 +47,7 @@ fn write_stream(
4747
Ok(())
4848
}
4949

50-
pub fn write_tt(tt: &MdTree<'_>, buf: &mut Buffer, indent: usize) -> io::Result<()> {
50+
fn write_tt(tt: &MdTree<'_>, buf: &mut Buffer, indent: usize) -> io::Result<()> {
5151
match tt {
5252
MdTree::CodeBlock { txt, lang: _ } => {
5353
buf.set_color(ColorSpec::new().set_dimmed(true))?;

compiler/rustc_errors/src/snippet.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ use rustc_macros::{Decodable, Encodable};
55
use crate::{Level, Loc};
66

77
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
8-
pub struct Line {
8+
pub(crate) struct Line {
99
pub line_index: usize,
1010
pub annotations: Vec<Annotation>,
1111
}
1212

1313
#[derive(Clone, Copy, Debug, PartialOrd, Ord, PartialEq, Eq, Default)]
14-
pub struct AnnotationColumn {
14+
pub(crate) struct AnnotationColumn {
1515
/// the (0-indexed) column for *display* purposes, counted in characters, not utf-8 bytes
1616
pub display: usize,
1717
/// the (0-indexed) column in the file, counted in characters, not utf-8 bytes.
@@ -31,13 +31,13 @@ pub struct AnnotationColumn {
3131
}
3232

3333
impl AnnotationColumn {
34-
pub fn from_loc(loc: &Loc) -> AnnotationColumn {
34+
pub(crate) fn from_loc(loc: &Loc) -> AnnotationColumn {
3535
AnnotationColumn { display: loc.col_display, file: loc.col.0 }
3636
}
3737
}
3838

3939
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
40-
pub struct MultilineAnnotation {
40+
pub(crate) struct MultilineAnnotation {
4141
pub depth: usize,
4242
pub line_start: usize,
4343
pub line_end: usize,
@@ -49,19 +49,19 @@ pub struct MultilineAnnotation {
4949
}
5050

5151
impl MultilineAnnotation {
52-
pub fn increase_depth(&mut self) {
52+
pub(crate) fn increase_depth(&mut self) {
5353
self.depth += 1;
5454
}
5555

5656
/// Compare two `MultilineAnnotation`s considering only the `Span` they cover.
57-
pub fn same_span(&self, other: &MultilineAnnotation) -> bool {
57+
pub(crate) fn same_span(&self, other: &MultilineAnnotation) -> bool {
5858
self.line_start == other.line_start
5959
&& self.line_end == other.line_end
6060
&& self.start_col == other.start_col
6161
&& self.end_col == other.end_col
6262
}
6363

64-
pub fn as_start(&self) -> Annotation {
64+
pub(crate) fn as_start(&self) -> Annotation {
6565
Annotation {
6666
start_col: self.start_col,
6767
end_col: AnnotationColumn {
@@ -76,7 +76,7 @@ impl MultilineAnnotation {
7676
}
7777
}
7878

79-
pub fn as_end(&self) -> Annotation {
79+
pub(crate) fn as_end(&self) -> Annotation {
8080
Annotation {
8181
start_col: AnnotationColumn {
8282
// these might not correspond to the same place anymore,
@@ -91,7 +91,7 @@ impl MultilineAnnotation {
9191
}
9292
}
9393

94-
pub fn as_line(&self) -> Annotation {
94+
pub(crate) fn as_line(&self) -> Annotation {
9595
Annotation {
9696
start_col: Default::default(),
9797
end_col: Default::default(),
@@ -103,7 +103,7 @@ impl MultilineAnnotation {
103103
}
104104

105105
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
106-
pub enum AnnotationType {
106+
pub(crate) enum AnnotationType {
107107
/// Annotation under a single line of code
108108
Singleline,
109109

@@ -129,7 +129,7 @@ pub enum AnnotationType {
129129
}
130130

131131
#[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)]
132-
pub struct Annotation {
132+
pub(crate) struct Annotation {
133133
/// Start column.
134134
/// Note that it is important that this field goes
135135
/// first, so that when we sort, we sort orderings by start
@@ -152,12 +152,12 @@ pub struct Annotation {
152152

153153
impl Annotation {
154154
/// Whether this annotation is a vertical line placeholder.
155-
pub fn is_line(&self) -> bool {
155+
pub(crate) fn is_line(&self) -> bool {
156156
matches!(self.annotation_type, AnnotationType::MultilineLine(_))
157157
}
158158

159159
/// Length of this annotation as displayed in the stderr output
160-
pub fn len(&self) -> usize {
160+
pub(crate) fn len(&self) -> usize {
161161
// Account for usize underflows
162162
if self.end_col.display > self.start_col.display {
163163
self.end_col.display - self.start_col.display
@@ -166,7 +166,7 @@ impl Annotation {
166166
}
167167
}
168168

169-
pub fn has_label(&self) -> bool {
169+
pub(crate) fn has_label(&self) -> bool {
170170
if let Some(ref label) = self.label {
171171
// Consider labels with no text as effectively not being there
172172
// to avoid weird output with unnecessary vertical lines, like:
@@ -184,7 +184,7 @@ impl Annotation {
184184
}
185185
}
186186

187-
pub fn takes_space(&self) -> bool {
187+
pub(crate) fn takes_space(&self) -> bool {
188188
// Multiline annotations always have to keep vertical space.
189189
matches!(
190190
self.annotation_type,
@@ -194,7 +194,7 @@ impl Annotation {
194194
}
195195

196196
#[derive(Debug)]
197-
pub struct StyledString {
197+
pub(crate) struct StyledString {
198198
pub text: String,
199199
pub style: Style,
200200
}

compiler/rustc_errors/src/styled_buffer.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::snippet::{Style, StyledString};
44

55
#[derive(Debug)]
6-
pub struct StyledBuffer {
6+
pub(crate) struct StyledBuffer {
77
lines: Vec<Vec<StyledChar>>,
88
}
99

@@ -22,12 +22,12 @@ impl StyledChar {
2222
}
2323

2424
impl StyledBuffer {
25-
pub fn new() -> StyledBuffer {
25+
pub(crate) fn new() -> StyledBuffer {
2626
StyledBuffer { lines: vec![] }
2727
}
2828

2929
/// Returns content of `StyledBuffer` split by lines and line styles
30-
pub fn render(&self) -> Vec<Vec<StyledString>> {
30+
pub(crate) fn render(&self) -> Vec<Vec<StyledString>> {
3131
// Tabs are assumed to have been replaced by spaces in calling code.
3232
debug_assert!(self.lines.iter().all(|r| !r.iter().any(|sc| sc.chr == '\t')));
3333

@@ -70,7 +70,7 @@ impl StyledBuffer {
7070
/// Sets `chr` with `style` for given `line`, `col`.
7171
/// If `line` does not exist in our buffer, adds empty lines up to the given
7272
/// and fills the last line with unstyled whitespace.
73-
pub fn putc(&mut self, line: usize, col: usize, chr: char, style: Style) {
73+
pub(crate) fn putc(&mut self, line: usize, col: usize, chr: char, style: Style) {
7474
self.ensure_lines(line);
7575
if col >= self.lines[line].len() {
7676
self.lines[line].resize(col + 1, StyledChar::SPACE);
@@ -81,7 +81,7 @@ impl StyledBuffer {
8181
/// Sets `string` with `style` for given `line`, starting from `col`.
8282
/// If `line` does not exist in our buffer, adds empty lines up to the given
8383
/// and fills the last line with unstyled whitespace.
84-
pub fn puts(&mut self, line: usize, col: usize, string: &str, style: Style) {
84+
pub(crate) fn puts(&mut self, line: usize, col: usize, string: &str, style: Style) {
8585
let mut n = col;
8686
for c in string.chars() {
8787
self.putc(line, n, c, style);
@@ -91,7 +91,7 @@ impl StyledBuffer {
9191

9292
/// For given `line` inserts `string` with `style` before old content of that line,
9393
/// adding lines if needed
94-
pub fn prepend(&mut self, line: usize, string: &str, style: Style) {
94+
pub(crate) fn prepend(&mut self, line: usize, string: &str, style: Style) {
9595
self.ensure_lines(line);
9696
let string_len = string.chars().count();
9797

@@ -107,7 +107,7 @@ impl StyledBuffer {
107107

108108
/// For given `line` inserts `string` with `style` after old content of that line,
109109
/// adding lines if needed
110-
pub fn append(&mut self, line: usize, string: &str, style: Style) {
110+
pub(crate) fn append(&mut self, line: usize, string: &str, style: Style) {
111111
if line >= self.lines.len() {
112112
self.puts(line, 0, string, style);
113113
} else {
@@ -116,14 +116,14 @@ impl StyledBuffer {
116116
}
117117
}
118118

119-
pub fn num_lines(&self) -> usize {
119+
pub(crate) fn num_lines(&self) -> usize {
120120
self.lines.len()
121121
}
122122

123123
/// Set `style` for `line`, `col_start..col_end` range if:
124124
/// 1. That line and column range exist in `StyledBuffer`
125125
/// 2. `overwrite` is `true` or existing style is `Style::NoStyle` or `Style::Quotation`
126-
pub fn set_style_range(
126+
pub(crate) fn set_style_range(
127127
&mut self,
128128
line: usize,
129129
col_start: usize,
@@ -139,7 +139,7 @@ impl StyledBuffer {
139139
/// Set `style` for `line`, `col` if:
140140
/// 1. That line and column exist in `StyledBuffer`
141141
/// 2. `overwrite` is `true` or existing style is `Style::NoStyle` or `Style::Quotation`
142-
pub fn set_style(&mut self, line: usize, col: usize, style: Style, overwrite: bool) {
142+
fn set_style(&mut self, line: usize, col: usize, style: Style, overwrite: bool) {
143143
if let Some(ref mut line) = self.lines.get_mut(line) {
144144
if let Some(StyledChar { style: s, .. }) = line.get_mut(col) {
145145
if overwrite || matches!(s, Style::NoStyle | Style::Quotation) {

compiler/rustc_expand/src/errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub(crate) struct ModuleMultipleCandidates {
350350

351351
#[derive(Diagnostic)]
352352
#[diag(expand_trace_macro)]
353-
pub struct TraceMacro {
353+
pub(crate) struct TraceMacro {
354354
#[primary_span]
355355
pub span: Span,
356356
}
@@ -402,14 +402,14 @@ pub(crate) struct CustomAttributePanickedHelp {
402402

403403
#[derive(Diagnostic)]
404404
#[diag(expand_proc_macro_derive_tokens)]
405-
pub struct ProcMacroDeriveTokens {
405+
pub(crate) struct ProcMacroDeriveTokens {
406406
#[primary_span]
407407
pub span: Span,
408408
}
409409

410410
#[derive(Diagnostic)]
411411
#[diag(expand_duplicate_matcher_binding)]
412-
pub struct DuplicateMatcherBinding {
412+
pub(crate) struct DuplicateMatcherBinding {
413413
#[primary_span]
414414
#[label]
415415
pub span: Span,
@@ -421,7 +421,7 @@ pub struct DuplicateMatcherBinding {
421421
#[diag(expand_missing_fragment_specifier)]
422422
#[note]
423423
#[help(expand_valid)]
424-
pub struct MissingFragmentSpecifier {
424+
pub(crate) struct MissingFragmentSpecifier {
425425
#[primary_span]
426426
pub span: Span,
427427
#[suggestion(
@@ -437,7 +437,7 @@ pub struct MissingFragmentSpecifier {
437437
#[derive(Diagnostic)]
438438
#[diag(expand_invalid_fragment_specifier)]
439439
#[help]
440-
pub struct InvalidFragmentSpecifier {
440+
pub(crate) struct InvalidFragmentSpecifier {
441441
#[primary_span]
442442
pub span: Span,
443443
pub fragment: Ident,
@@ -446,7 +446,7 @@ pub struct InvalidFragmentSpecifier {
446446

447447
#[derive(Diagnostic)]
448448
#[diag(expand_expected_paren_or_brace)]
449-
pub struct ExpectedParenOrBrace<'a> {
449+
pub(crate) struct ExpectedParenOrBrace<'a> {
450450
#[primary_span]
451451
pub span: Span,
452452
pub token: Cow<'a, str>,
@@ -479,7 +479,7 @@ pub(crate) struct GlobDelegationTraitlessQpath {
479479
#[derive(Diagnostic)]
480480
#[diag(expand_proc_macro_back_compat)]
481481
#[note]
482-
pub struct ProcMacroBackCompat {
482+
pub(crate) struct ProcMacroBackCompat {
483483
pub crate_name: String,
484484
pub fixed_version: String,
485485
}

0 commit comments

Comments
 (0)