Skip to content

Some clippy changes #2975

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 1 commit into from
Aug 30, 2018
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
18 changes: 8 additions & 10 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ fn rewrite_comment_inner(

const RUSTFMT_CUSTOM_COMMENT_PREFIX: &str = "//#### ";

fn hide_sharp_behind_comment<'a>(s: &'a str) -> Cow<'a, str> {
fn hide_sharp_behind_comment(s: &str) -> Cow<str> {
if s.trim_left().starts_with("# ") {
Cow::from(format!("{}{}", RUSTFMT_CUSTOM_COMMENT_PREFIX, s))
} else {
Expand Down Expand Up @@ -823,20 +823,20 @@ pub enum FullCodeCharKind {
}

impl FullCodeCharKind {
pub fn is_comment(&self) -> bool {
match *self {
pub fn is_comment(self) -> bool {
match self {
FullCodeCharKind::StartComment
| FullCodeCharKind::InComment
| FullCodeCharKind::EndComment => true,
_ => false,
}
}

pub fn is_string(&self) -> bool {
*self == FullCodeCharKind::InString
pub fn is_string(self) -> bool {
self == FullCodeCharKind::InString
}

fn to_codecharkind(&self) -> CodeCharKind {
fn to_codecharkind(self) -> CodeCharKind {
if self.is_comment() {
CodeCharKind::Comment
} else {
Expand Down Expand Up @@ -987,9 +987,7 @@ impl<'a> Iterator for LineClasses<'a> {
type Item = (FullCodeCharKind, String);

fn next(&mut self) -> Option<Self::Item> {
if self.base.peek().is_none() {
return None;
}
self.base.peek()?;

let mut line = String::new();

Expand Down Expand Up @@ -1174,7 +1172,7 @@ pub fn filter_normal_code(code: &str) -> String {
}
_ => (),
});
if !code.ends_with("\n") && buffer.ends_with("\n") {
if !code.ends_with('\n') && buffer.ends_with('\n') {
buffer.pop();
}
buffer
Expand Down
4 changes: 2 additions & 2 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ macro_rules! create_config {
}
)+

pub fn set<'a>(&'a mut self) -> ConfigSetter<'a> {
pub fn set(&mut self) -> ConfigSetter {
ConfigSetter(self)
}

pub fn was_set<'a>(&'a self) -> ConfigWasSet<'a> {
pub fn was_set(&self) -> ConfigWasSet {
ConfigWasSet(self)
}

Expand Down
8 changes: 4 additions & 4 deletions src/config/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ pub enum SeparatorPlace {
impl_enum_serialize_and_deserialize!(SeparatorPlace, Front, Back);

impl SeparatorPlace {
pub fn is_front(&self) -> bool {
*self == SeparatorPlace::Front
pub fn is_front(self) -> bool {
self == SeparatorPlace::Front
}

pub fn is_back(&self) -> bool {
*self == SeparatorPlace::Back
pub fn is_back(self) -> bool {
self == SeparatorPlace::Back
}

pub fn from_tactic(
Expand Down
4 changes: 2 additions & 2 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ pub enum Separator {
}

impl Separator {
pub fn len(&self) -> usize {
match *self {
pub fn len(self) -> usize {
match self {
// 2 = `, `
Separator::Comma => 2,
// 3 = ` | `
Expand Down
2 changes: 1 addition & 1 deletion src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn rewrite_match_pattern(
guard,
shape,
trimmed_last_line_width(&pats_str),
pats_str.contains("\n"),
pats_str.contains('\n'),
)?;

Some(format!("{}{}", pats_str, guard_str))
Expand Down
2 changes: 1 addition & 1 deletion src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
// 1 = "("
let combine_arg_with_callee = self.items.len() == 1
&& self.items[0].to_expr().is_some()
&& self.ident.len() + 1 <= self.context.config.tab_spaces();
&& self.ident.len() < self.context.config.tab_spaces();
let overflow_last = combine_arg_with_callee || can_be_overflowed(self.context, self.items);

// Replace the last item with its first line to see if it fits with
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl Rewrite for ast::GenericBounds {
}

let span = mk_sp(self.get(0)?.span().lo(), self.last()?.span().hi());
let has_paren = context.snippet(span).starts_with("(");
let has_paren = context.snippet(span).starts_with('(');
let bounds_shape = if has_paren {
shape.offset_left(1)?.sub_width(1)?
} else {
Expand Down