Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cc97eaf

Browse files
authored
Merge pull request rust-lang#3546 from bash/unreachable-pub
Enable unreachable_pub lint
2 parents 4bc5911 + d1c1f8e commit cc97eaf

34 files changed

+428
-373
lines changed

src/attr.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::types::{rewrite_path, PathContext};
1515
use crate::utils::{count_newlines, mk_sp};
1616

1717
/// Returns attributes on the given statement.
18-
pub fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
18+
pub(crate) fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
1919
match stmt.node {
2020
ast::StmtKind::Local(ref local) => &local.attrs,
2121
ast::StmtKind::Item(ref item) => &item.attrs,
@@ -24,7 +24,7 @@ pub fn get_attrs_from_stmt(stmt: &ast::Stmt) -> &[ast::Attribute] {
2424
}
2525
}
2626

27-
pub fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
27+
pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
2828
match stmt.node {
2929
ast::StmtKind::Local(ref local) => local.span,
3030
ast::StmtKind::Item(ref item) => item.span,
@@ -37,7 +37,10 @@ pub fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
3737
}
3838

3939
/// Returns attributes that are within `outer_span`.
40-
pub fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> Vec<ast::Attribute> {
40+
pub(crate) fn filter_inline_attrs(
41+
attrs: &[ast::Attribute],
42+
outer_span: Span,
43+
) -> Vec<ast::Attribute> {
4144
attrs
4245
.iter()
4346
.filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi())

src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use crate::utils::{
7474
trimmed_last_line_width, wrap_str,
7575
};
7676

77-
pub fn rewrite_chain(
77+
pub(crate) fn rewrite_chain(
7878
expr: &ast::Expr,
7979
context: &RewriteContext<'_>,
8080
shape: Shape,

src/checkstyle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::rustfmt_diff::{DiffLine, Mismatch};
77
///
88
/// Note that emitting checkstyle output is not stable and may removed in a
99
/// future version of Rustfmt.
10-
pub fn header() -> String {
10+
pub(crate) fn header() -> String {
1111
let mut xml_heading = String::new();
1212
xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
1313
xml_heading.push_str("\n");
@@ -19,11 +19,11 @@ pub fn header() -> String {
1919
///
2020
/// Note that emitting checkstyle output is not stable and may removed in a
2121
/// future version of Rustfmt.
22-
pub fn footer() -> String {
22+
pub(crate) fn footer() -> String {
2323
"</checkstyle>\n".to_owned()
2424
}
2525

26-
pub fn output_checkstyle_file<T>(
26+
pub(crate) fn output_checkstyle_file<T>(
2727
mut writer: T,
2828
filename: &Path,
2929
diff: Vec<Mismatch>,

src/closures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
2323
// statement without needing a semi-colon), then adding or removing braces
2424
// can change whether it is treated as an expression or statement.
2525

26-
pub fn rewrite_closure(
26+
pub(crate) fn rewrite_closure(
2727
capture: ast::CaptureBy,
2828
asyncness: ast::IsAsync,
2929
movability: ast::Movability,
@@ -286,7 +286,7 @@ fn rewrite_closure_fn_decl(
286286

287287
// Rewriting closure which is placed at the end of the function call's arg.
288288
// Returns `None` if the reformatted closure 'looks bad'.
289-
pub fn rewrite_last_closure(
289+
pub(crate) fn rewrite_last_closure(
290290
context: &RewriteContext<'_>,
291291
expr: &ast::Expr,
292292
shape: Shape,
@@ -351,7 +351,7 @@ pub fn rewrite_last_closure(
351351
}
352352

353353
/// Returns `true` if the given vector of arguments has more than one `ast::ExprKind::Closure`.
354-
pub fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
354+
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
355355
args.iter()
356356
.filter_map(OverflowableItem::to_expr)
357357
.filter(|expr| match expr.node {

src/comment.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn is_custom_comment(comment: &str) -> bool {
2525
}
2626

2727
#[derive(Copy, Clone, PartialEq, Eq)]
28-
pub enum CommentStyle<'a> {
28+
pub(crate) enum CommentStyle<'a> {
2929
DoubleSlash,
3030
TripleSlash,
3131
Doc,
@@ -45,7 +45,7 @@ fn custom_opener(s: &str) -> &str {
4545

4646
impl<'a> CommentStyle<'a> {
4747
/// Returns `true` if the commenting style covers a line only.
48-
pub fn is_line_comment(&self) -> bool {
48+
pub(crate) fn is_line_comment(&self) -> bool {
4949
match *self {
5050
CommentStyle::DoubleSlash
5151
| CommentStyle::TripleSlash
@@ -56,7 +56,7 @@ impl<'a> CommentStyle<'a> {
5656
}
5757

5858
/// Returns `true` if the commenting style can span over multiple lines.
59-
pub fn is_block_comment(&self) -> bool {
59+
pub(crate) fn is_block_comment(&self) -> bool {
6060
match *self {
6161
CommentStyle::SingleBullet | CommentStyle::DoubleBullet | CommentStyle::Exclamation => {
6262
true
@@ -66,14 +66,14 @@ impl<'a> CommentStyle<'a> {
6666
}
6767

6868
/// Returns `true` if the commenting style is for documentation.
69-
pub fn is_doc_comment(&self) -> bool {
69+
pub(crate) fn is_doc_comment(&self) -> bool {
7070
match *self {
7171
CommentStyle::TripleSlash | CommentStyle::Doc => true,
7272
_ => false,
7373
}
7474
}
7575

76-
pub fn opener(&self) -> &'a str {
76+
pub(crate) fn opener(&self) -> &'a str {
7777
match *self {
7878
CommentStyle::DoubleSlash => "// ",
7979
CommentStyle::TripleSlash => "/// ",
@@ -85,7 +85,7 @@ impl<'a> CommentStyle<'a> {
8585
}
8686
}
8787

88-
pub fn closer(&self) -> &'a str {
88+
pub(crate) fn closer(&self) -> &'a str {
8989
match *self {
9090
CommentStyle::DoubleSlash
9191
| CommentStyle::TripleSlash
@@ -96,7 +96,7 @@ impl<'a> CommentStyle<'a> {
9696
}
9797
}
9898

99-
pub fn line_start(&self) -> &'a str {
99+
pub(crate) fn line_start(&self) -> &'a str {
100100
match *self {
101101
CommentStyle::DoubleSlash => "// ",
102102
CommentStyle::TripleSlash => "/// ",
@@ -107,7 +107,7 @@ impl<'a> CommentStyle<'a> {
107107
}
108108
}
109109

110-
pub fn to_str_tuplet(&self) -> (&'a str, &'a str, &'a str) {
110+
pub(crate) fn to_str_tuplet(&self) -> (&'a str, &'a str, &'a str) {
111111
(self.opener(), self.closer(), self.line_start())
112112
}
113113
}
@@ -143,7 +143,7 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle<'_> {
143143
}
144144

145145
/// Returns true if the last line of the passed string finishes with a block-comment.
146-
pub fn is_last_comment_block(s: &str) -> bool {
146+
pub(crate) fn is_last_comment_block(s: &str) -> bool {
147147
s.trim_end().ends_with("*/")
148148
}
149149

@@ -152,7 +152,7 @@ pub fn is_last_comment_block(s: &str) -> bool {
152152
/// recovered. If `allow_extend` is true and there is no comment between the two
153153
/// strings, then they will be put on a single line as long as doing so does not
154154
/// exceed max width.
155-
pub fn combine_strs_with_missing_comments(
155+
pub(crate) fn combine_strs_with_missing_comments(
156156
context: &RewriteContext<'_>,
157157
prev_str: &str,
158158
next_str: &str,
@@ -239,11 +239,11 @@ pub fn combine_strs_with_missing_comments(
239239
Some(result)
240240
}
241241

242-
pub fn rewrite_doc_comment(orig: &str, shape: Shape, config: &Config) -> Option<String> {
242+
pub(crate) fn rewrite_doc_comment(orig: &str, shape: Shape, config: &Config) -> Option<String> {
243243
identify_comment(orig, false, shape, config, true)
244244
}
245245

246-
pub fn rewrite_comment(
246+
pub(crate) fn rewrite_comment(
247247
orig: &str,
248248
block_style: bool,
249249
shape: Shape,
@@ -845,7 +845,7 @@ fn has_url(s: &str) -> bool {
845845

846846
/// Given the span, rewrite the missing comment inside it if available.
847847
/// Note that the given span must only include comments (or leading/trailing whitespaces).
848-
pub fn rewrite_missing_comment(
848+
pub(crate) fn rewrite_missing_comment(
849849
span: Span,
850850
shape: Shape,
851851
context: &RewriteContext<'_>,
@@ -862,7 +862,7 @@ pub fn rewrite_missing_comment(
862862
/// Recover the missing comments in the specified span, if available.
863863
/// The layout of the comments will be preserved as long as it does not break the code
864864
/// and its total width does not exceed the max width.
865-
pub fn recover_missing_comment_in_span(
865+
pub(crate) fn recover_missing_comment_in_span(
866866
span: Span,
867867
shape: Shape,
868868
context: &RewriteContext<'_>,
@@ -964,7 +964,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
964964
}
965965
}
966966

967-
pub trait FindUncommented {
967+
pub(crate) trait FindUncommented {
968968
fn find_uncommented(&self, pat: &str) -> Option<usize>;
969969
}
970970

@@ -997,7 +997,7 @@ impl FindUncommented for str {
997997
// is expected to be prefixed by a comment, including delimiters.
998998
// Good: `/* /* inner */ outer */ code();`
999999
// Bad: `code(); // hello\n world!`
1000-
pub fn find_comment_end(s: &str) -> Option<usize> {
1000+
pub(crate) fn find_comment_end(s: &str) -> Option<usize> {
10011001
let mut iter = CharClasses::new(s.char_indices());
10021002
for (kind, (i, _c)) in &mut iter {
10031003
if kind == FullCodeCharKind::Normal || kind == FullCodeCharKind::InString {
@@ -1014,11 +1014,11 @@ pub fn find_comment_end(s: &str) -> Option<usize> {
10141014
}
10151015

10161016
/// Returns `true` if text contains any comment.
1017-
pub fn contains_comment(text: &str) -> bool {
1017+
pub(crate) fn contains_comment(text: &str) -> bool {
10181018
CharClasses::new(text.chars()).any(|(kind, _)| kind.is_comment())
10191019
}
10201020

1021-
pub struct CharClasses<T>
1021+
pub(crate) struct CharClasses<T>
10221022
where
10231023
T: Iterator,
10241024
T::Item: RichChar,
@@ -1027,7 +1027,7 @@ where
10271027
status: CharClassesStatus,
10281028
}
10291029

1030-
pub trait RichChar {
1030+
pub(crate) trait RichChar {
10311031
fn get_char(&self) -> char;
10321032
}
10331033

@@ -1073,7 +1073,7 @@ enum CharClassesStatus {
10731073

10741074
/// Distinguish between functional part of code and comments
10751075
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
1076-
pub enum CodeCharKind {
1076+
pub(crate) enum CodeCharKind {
10771077
Normal,
10781078
Comment,
10791079
}
@@ -1082,7 +1082,7 @@ pub enum CodeCharKind {
10821082
/// describing opening and closing of comments for ease when chunking
10831083
/// code from tagged characters
10841084
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
1085-
pub enum FullCodeCharKind {
1085+
pub(crate) enum FullCodeCharKind {
10861086
Normal,
10871087
/// The first character of a comment, there is only one for a comment (always '/')
10881088
StartComment,
@@ -1106,7 +1106,7 @@ pub enum FullCodeCharKind {
11061106
}
11071107

11081108
impl FullCodeCharKind {
1109-
pub fn is_comment(self) -> bool {
1109+
pub(crate) fn is_comment(self) -> bool {
11101110
match self {
11111111
FullCodeCharKind::StartComment
11121112
| FullCodeCharKind::InComment
@@ -1119,7 +1119,7 @@ impl FullCodeCharKind {
11191119
}
11201120

11211121
/// Returns true if the character is inside a comment
1122-
pub fn inside_comment(self) -> bool {
1122+
pub(crate) fn inside_comment(self) -> bool {
11231123
match self {
11241124
FullCodeCharKind::InComment
11251125
| FullCodeCharKind::StartStringCommented
@@ -1129,12 +1129,12 @@ impl FullCodeCharKind {
11291129
}
11301130
}
11311131

1132-
pub fn is_string(self) -> bool {
1132+
pub(crate) fn is_string(self) -> bool {
11331133
self == FullCodeCharKind::InString || self == FullCodeCharKind::StartString
11341134
}
11351135

11361136
/// Returns true if the character is within a commented string
1137-
pub fn is_commented_string(self) -> bool {
1137+
pub(crate) fn is_commented_string(self) -> bool {
11381138
self == FullCodeCharKind::InStringCommented
11391139
|| self == FullCodeCharKind::StartStringCommented
11401140
}
@@ -1153,7 +1153,7 @@ where
11531153
T: Iterator,
11541154
T::Item: RichChar,
11551155
{
1156-
pub fn new(base: T) -> CharClasses<T> {
1156+
pub(crate) fn new(base: T) -> CharClasses<T> {
11571157
CharClasses {
11581158
base: multipeek(base),
11591159
status: CharClassesStatus::Normal,
@@ -1336,13 +1336,13 @@ where
13361336

13371337
/// An iterator over the lines of a string, paired with the char kind at the
13381338
/// end of the line.
1339-
pub struct LineClasses<'a> {
1339+
pub(crate) struct LineClasses<'a> {
13401340
base: iter::Peekable<CharClasses<std::str::Chars<'a>>>,
13411341
kind: FullCodeCharKind,
13421342
}
13431343

13441344
impl<'a> LineClasses<'a> {
1345-
pub fn new(s: &'a str) -> Self {
1345+
pub(crate) fn new(s: &'a str) -> Self {
13461346
LineClasses {
13471347
base: CharClasses::new(s.chars()).peekable(),
13481348
kind: FullCodeCharKind::Normal,
@@ -1458,14 +1458,14 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> {
14581458
/// Iterator over an alternating sequence of functional and commented parts of
14591459
/// a string. The first item is always a, possibly zero length, subslice of
14601460
/// functional text. Line style comments contain their ending newlines.
1461-
pub struct CommentCodeSlices<'a> {
1461+
pub(crate) struct CommentCodeSlices<'a> {
14621462
slice: &'a str,
14631463
last_slice_kind: CodeCharKind,
14641464
last_slice_end: usize,
14651465
}
14661466

14671467
impl<'a> CommentCodeSlices<'a> {
1468-
pub fn new(slice: &'a str) -> CommentCodeSlices<'a> {
1468+
pub(crate) fn new(slice: &'a str) -> CommentCodeSlices<'a> {
14691469
CommentCodeSlices {
14701470
slice,
14711471
last_slice_kind: CodeCharKind::Comment,
@@ -1536,7 +1536,7 @@ impl<'a> Iterator for CommentCodeSlices<'a> {
15361536

15371537
/// Checks is `new` didn't miss any comment from `span`, if it removed any, return previous text
15381538
/// (if it fits in the width/offset, else return `None`), else return `new`
1539-
pub fn recover_comment_removed(
1539+
pub(crate) fn recover_comment_removed(
15401540
new: String,
15411541
span: Span,
15421542
context: &RewriteContext<'_>,
@@ -1560,7 +1560,7 @@ pub fn recover_comment_removed(
15601560
}
15611561
}
15621562

1563-
pub fn filter_normal_code(code: &str) -> String {
1563+
pub(crate) fn filter_normal_code(code: &str) -> String {
15641564
let mut buffer = String::with_capacity(code.len());
15651565
LineClasses::new(code).for_each(|(kind, line)| match kind {
15661566
FullCodeCharKind::Normal

0 commit comments

Comments
 (0)