Skip to content

Commit 489eb23

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 0249125 + 22cdd63 commit 489eb23

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 16 additions & 16 deletions
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
}

0 commit comments

Comments
 (0)