Skip to content

Enable unreachable_pub lint #3546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::types::{rewrite_path, PathContext};
use crate::utils::{count_newlines, mk_sp};

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

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

/// Returns attributes that are within `outer_span`.
pub fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> Vec<ast::Attribute> {
pub(crate) fn filter_inline_attrs(
attrs: &[ast::Attribute],
outer_span: Span,
) -> Vec<ast::Attribute> {
attrs
.iter()
.filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi())
Expand Down
2 changes: 1 addition & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use crate::utils::{
trimmed_last_line_width, wrap_str,
};

pub fn rewrite_chain(
pub(crate) fn rewrite_chain(
expr: &ast::Expr,
context: &RewriteContext<'_>,
shape: Shape,
Expand Down
6 changes: 3 additions & 3 deletions src/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::rustfmt_diff::{DiffLine, Mismatch};
///
/// Note that emitting checkstyle output is not stable and may removed in a
/// future version of Rustfmt.
pub fn header() -> String {
pub(crate) fn header() -> String {
let mut xml_heading = String::new();
xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xml_heading.push_str("\n");
Expand All @@ -19,11 +19,11 @@ pub fn header() -> String {
///
/// Note that emitting checkstyle output is not stable and may removed in a
/// future version of Rustfmt.
pub fn footer() -> String {
pub(crate) fn footer() -> String {
"</checkstyle>\n".to_owned()
}

pub fn output_checkstyle_file<T>(
pub(crate) fn output_checkstyle_file<T>(
mut writer: T,
filename: &Path,
diff: Vec<Mismatch>,
Expand Down
6 changes: 3 additions & 3 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
// statement without needing a semi-colon), then adding or removing braces
// can change whether it is treated as an expression or statement.

pub fn rewrite_closure(
pub(crate) fn rewrite_closure(
capture: ast::CaptureBy,
asyncness: ast::IsAsync,
movability: ast::Movability,
Expand Down Expand Up @@ -286,7 +286,7 @@ fn rewrite_closure_fn_decl(

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

/// Returns `true` if the given vector of arguments has more than one `ast::ExprKind::Closure`.
pub fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
pub(crate) fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool {
args.iter()
.filter_map(OverflowableItem::to_expr)
.filter(|expr| match expr.node {
Expand Down
64 changes: 32 additions & 32 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn is_custom_comment(comment: &str) -> bool {
}

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

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

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

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

pub fn opener(&self) -> &'a str {
pub(crate) fn opener(&self) -> &'a str {
match *self {
CommentStyle::DoubleSlash => "// ",
CommentStyle::TripleSlash => "/// ",
Expand All @@ -85,7 +85,7 @@ impl<'a> CommentStyle<'a> {
}
}

pub fn closer(&self) -> &'a str {
pub(crate) fn closer(&self) -> &'a str {
match *self {
CommentStyle::DoubleSlash
| CommentStyle::TripleSlash
Expand All @@ -96,7 +96,7 @@ impl<'a> CommentStyle<'a> {
}
}

pub fn line_start(&self) -> &'a str {
pub(crate) fn line_start(&self) -> &'a str {
match *self {
CommentStyle::DoubleSlash => "// ",
CommentStyle::TripleSlash => "/// ",
Expand All @@ -107,7 +107,7 @@ impl<'a> CommentStyle<'a> {
}
}

pub fn to_str_tuplet(&self) -> (&'a str, &'a str, &'a str) {
pub(crate) fn to_str_tuplet(&self) -> (&'a str, &'a str, &'a str) {
(self.opener(), self.closer(), self.line_start())
}
}
Expand Down Expand Up @@ -143,7 +143,7 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle<'_> {
}

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

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

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

pub fn rewrite_comment(
pub(crate) fn rewrite_comment(
orig: &str,
block_style: bool,
shape: Shape,
Expand Down Expand Up @@ -845,7 +845,7 @@ fn has_url(s: &str) -> bool {

/// Given the span, rewrite the missing comment inside it if available.
/// Note that the given span must only include comments (or leading/trailing whitespaces).
pub fn rewrite_missing_comment(
pub(crate) fn rewrite_missing_comment(
span: Span,
shape: Shape,
context: &RewriteContext<'_>,
Expand All @@ -862,7 +862,7 @@ pub fn rewrite_missing_comment(
/// Recover the missing comments in the specified span, if available.
/// The layout of the comments will be preserved as long as it does not break the code
/// and its total width does not exceed the max width.
pub fn recover_missing_comment_in_span(
pub(crate) fn recover_missing_comment_in_span(
span: Span,
shape: Shape,
context: &RewriteContext<'_>,
Expand Down Expand Up @@ -964,7 +964,7 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a s
}
}

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

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

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

pub struct CharClasses<T>
pub(crate) struct CharClasses<T>
where
T: Iterator,
T::Item: RichChar,
Expand All @@ -1027,7 +1027,7 @@ where
status: CharClassesStatus,
}

pub trait RichChar {
pub(crate) trait RichChar {
fn get_char(&self) -> char;
}

Expand Down Expand Up @@ -1073,7 +1073,7 @@ enum CharClassesStatus {

/// Distinguish between functional part of code and comments
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum CodeCharKind {
pub(crate) enum CodeCharKind {
Normal,
Comment,
}
Expand All @@ -1082,7 +1082,7 @@ pub enum CodeCharKind {
/// describing opening and closing of comments for ease when chunking
/// code from tagged characters
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
pub enum FullCodeCharKind {
pub(crate) enum FullCodeCharKind {
Normal,
/// The first character of a comment, there is only one for a comment (always '/')
StartComment,
Expand All @@ -1106,7 +1106,7 @@ pub enum FullCodeCharKind {
}

impl FullCodeCharKind {
pub fn is_comment(self) -> bool {
pub(crate) fn is_comment(self) -> bool {
match self {
FullCodeCharKind::StartComment
| FullCodeCharKind::InComment
Expand All @@ -1119,7 +1119,7 @@ impl FullCodeCharKind {
}

/// Returns true if the character is inside a comment
pub fn inside_comment(self) -> bool {
pub(crate) fn inside_comment(self) -> bool {
match self {
FullCodeCharKind::InComment
| FullCodeCharKind::StartStringCommented
Expand All @@ -1129,12 +1129,12 @@ impl FullCodeCharKind {
}
}

pub fn is_string(self) -> bool {
pub(crate) fn is_string(self) -> bool {
self == FullCodeCharKind::InString || self == FullCodeCharKind::StartString
}

/// Returns true if the character is within a commented string
pub fn is_commented_string(self) -> bool {
pub(crate) fn is_commented_string(self) -> bool {
self == FullCodeCharKind::InStringCommented
|| self == FullCodeCharKind::StartStringCommented
}
Expand All @@ -1153,7 +1153,7 @@ where
T: Iterator,
T::Item: RichChar,
{
pub fn new(base: T) -> CharClasses<T> {
pub(crate) fn new(base: T) -> CharClasses<T> {
CharClasses {
base: multipeek(base),
status: CharClassesStatus::Normal,
Expand Down Expand Up @@ -1336,13 +1336,13 @@ where

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

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

impl<'a> CommentCodeSlices<'a> {
pub fn new(slice: &'a str) -> CommentCodeSlices<'a> {
pub(crate) fn new(slice: &'a str) -> CommentCodeSlices<'a> {
CommentCodeSlices {
slice,
last_slice_kind: CodeCharKind::Comment,
Expand Down Expand Up @@ -1536,7 +1536,7 @@ impl<'a> Iterator for CommentCodeSlices<'a> {

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

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