Skip to content

Commit c9819ce

Browse files
authored
Merge pull request #1135 from sinkuu/clippy
Run clippy
2 parents bce26d5 + a3c63fd commit c9819ce

18 files changed

+104
-114
lines changed

src/bin/cargo-fmt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ enum TargetKind {
123123

124124
impl TargetKind {
125125
fn is_lib(&self) -> bool {
126-
match self {
127-
&TargetKind::Lib => true,
126+
match *self {
127+
TargetKind::Lib => true,
128128
_ => false,
129129
}
130130
}
131131

132132
fn is_bin(&self) -> bool {
133-
match self {
134-
&TargetKind::Bin => true,
133+
match *self {
134+
TargetKind::Bin => true,
135135
_ => false,
136136
}
137137
}
@@ -180,8 +180,8 @@ fn target_from_json(jtarget: &Json) -> Target {
180180
}
181181
}
182182

183-
fn format_files(files: &Vec<PathBuf>,
184-
fmt_args: &Vec<String>,
183+
fn format_files(files: &[PathBuf],
184+
fmt_args: &[String],
185185
verbosity: Verbosity)
186186
-> Result<ExitStatus, std::io::Error> {
187187
let stdout = if verbosity == Verbosity::Quiet {

src/bin/rustfmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
198198

199199
match try!(determine_operation(&matches)) {
200200
Operation::Help => {
201-
print_usage(&opts, "");
201+
print_usage(opts, "");
202202
Ok(Summary::new())
203203
}
204204
Operation::Version => {

src/chains.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub fn rewrite_chain(expr: &ast::Expr,
186186
format!("\n{}", indent.to_string(context.config))
187187
};
188188

189-
let first_connector = if extend || subexpr_list.len() == 0 {
189+
let first_connector = if extend || subexpr_list.is_empty() {
190190
""
191191
} else if let ast::ExprKind::Try(_) = subexpr_list[0].node {
192192
""

src/checkstyle.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,14 @@ pub fn output_checkstyle_file<T>(mut writer: T,
4545
try!(write!(writer, "<file name=\"{}\">", filename));
4646
for mismatch in diff {
4747
for line in mismatch.lines {
48-
match line {
49-
DiffLine::Expected(ref str) => {
50-
let message = xml_escape_str(&str);
51-
try!(write!(writer,
52-
"<error line=\"{}\" severity=\"warning\" message=\"Should be \
53-
`{}`\" />",
54-
mismatch.line_number,
55-
message));
56-
}
57-
_ => {
58-
// Do nothing with context and expected.
59-
}
48+
// Do nothing with `DiffLine::Context` and `DiffLine::Resulting`.
49+
if let DiffLine::Expected(ref str) = line {
50+
let message = xml_escape_str(str);
51+
try!(write!(writer,
52+
"<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
53+
/>",
54+
mismatch.line_number,
55+
message));
6056
}
6157
}
6258
}

src/comment.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn rewrite_comment(orig: &str,
9494
let mut result = opener.to_owned();
9595
for line in lines {
9696
if result == opener {
97-
if line.len() == 0 {
97+
if line.is_empty() {
9898
continue;
9999
}
100100
} else {
@@ -107,7 +107,7 @@ pub fn rewrite_comment(orig: &str,
107107
let rewrite = rewrite_string(line, &fmt).unwrap_or(line.to_owned());
108108
result.push_str(&rewrite);
109109
} else {
110-
if line.len() == 0 {
110+
if line.is_empty() {
111111
// Remove space if this is an empty comment or a doc comment.
112112
result.pop();
113113
}
@@ -136,7 +136,7 @@ fn left_trim_comment_line(line: &str) -> &str {
136136
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") ||
137137
line.starts_with("**") {
138138
&line[2..]
139-
} else if line.starts_with("*") {
139+
} else if line.starts_with('*') {
140140
&line[1..]
141141
} else {
142142
line
@@ -524,7 +524,7 @@ pub fn recover_comment_removed(new: String,
524524
if changed_comment_content(&snippet, &new) {
525525
// We missed some comments
526526
// Keep previous formatting if it satisfies the constrains
527-
return wrap_str(snippet, context.config.max_width, width, offset);
527+
wrap_str(snippet, context.config.max_width, width, offset)
528528
} else {
529529
Some(new)
530530
}

src/expr.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I,
298298
|item| item.span.lo,
299299
|item| item.span.hi,
300300
// 1 = [
301-
|item| item.rewrite(&inner_context, max_item_width, offset),
301+
|item| item.rewrite(inner_context, max_item_width, offset),
302302
span.lo,
303303
span.hi)
304304
.collect::<Vec<_>>();
@@ -493,7 +493,7 @@ fn and_one_line(x: Option<String>) -> Option<String> {
493493

494494
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
495495
block_str.map(|block_str| {
496-
if block_str.starts_with("{") && budget >= 2 &&
496+
if block_str.starts_with('{') && budget >= 2 &&
497497
(block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) {
498498
"{}".to_owned()
499499
} else {
@@ -772,7 +772,7 @@ fn rewrite_if_else(context: &RewriteContext,
772772
pat.map_or(cond.span.lo,
773773
|_| context.codemap.span_before(span, "let")));
774774

775-
let between_if_cond_comment = extract_comment(between_if_cond, &context, offset, width);
775+
let between_if_cond_comment = extract_comment(between_if_cond, context, offset, width);
776776

777777
let after_cond_comment = extract_comment(mk_sp(cond.span.hi, if_block.span.lo),
778778
context,
@@ -831,13 +831,13 @@ fn rewrite_if_else(context: &RewriteContext,
831831
mk_sp(if_block.span.hi,
832832
context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else"));
833833
let between_if_else_block_comment =
834-
extract_comment(between_if_else_block, &context, offset, width);
834+
extract_comment(between_if_else_block, context, offset, width);
835835

836836
let after_else = mk_sp(context.codemap
837837
.span_after(mk_sp(if_block.span.hi, else_block.span.lo),
838838
"else"),
839839
else_block.span.lo);
840-
let after_else_comment = extract_comment(after_else, &context, offset, width);
840+
let after_else_comment = extract_comment(after_else, context, offset, width);
841841

842842
let between_sep = match context.config.else_if_brace_style {
843843
ElseIfBraceStyle::AlwaysNextLine |
@@ -854,7 +854,7 @@ fn rewrite_if_else(context: &RewriteContext,
854854
.map_or(between_sep, |str| &**str),
855855
after_else_comment.as_ref().map_or(after_sep, |str| &**str))
856856
.ok());
857-
result.push_str(&&try_opt!(rewrite));
857+
result.push_str(&try_opt!(rewrite));
858858
}
859859

860860
Some(result)
@@ -1021,7 +1021,7 @@ fn rewrite_match(context: &RewriteContext,
10211021
// We couldn't format the arm, just reproduce the source.
10221022
let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm)));
10231023
result.push_str(&snippet);
1024-
result.push_str(arm_comma(&context.config, &arm, &arm.body));
1024+
result.push_str(arm_comma(context.config, arm, &arm.body));
10251025
}
10261026
}
10271027
// BytePos(1) = closing match brace.
@@ -1102,7 +1102,7 @@ impl Rewrite for ast::Arm {
11021102
.map(|p| p.rewrite(context, pat_budget, offset))
11031103
.collect::<Option<Vec<_>>>());
11041104

1105-
let all_simple = pat_strs.iter().all(|p| pat_is_simple(&p));
1105+
let all_simple = pat_strs.iter().all(|p| pat_is_simple(p));
11061106
let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
11071107
let fmt = ListFormatting {
11081108
tactic: if all_simple {
@@ -1145,7 +1145,7 @@ impl Rewrite for ast::Arm {
11451145
ref x => x,
11461146
};
11471147

1148-
let comma = arm_comma(&context.config, self, body);
1148+
let comma = arm_comma(context.config, self, body);
11491149
let alt_block_sep = String::from("\n") + &context.block_indent.to_string(context.config);
11501150

11511151
// Let's try and get the arm body on the same line as the condition.
@@ -1305,7 +1305,7 @@ fn rewrite_pat_expr(context: &RewriteContext,
13051305
expr.rewrite(context,
13061306
try_opt!(context.config.max_width.checked_sub(pat_offset.width())),
13071307
pat_offset);
1308-
result.push_str(&&try_opt!(expr_rewrite));
1308+
result.push_str(&try_opt!(expr_rewrite));
13091309

13101310
Some(result)
13111311
}
@@ -1433,7 +1433,7 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
14331433
")",
14341434
|item| item.span.lo,
14351435
|item| item.span.hi,
1436-
|item| item.rewrite(&inner_context, remaining_width, offset),
1436+
|item| item.rewrite(inner_context, remaining_width, offset),
14371437
span.lo,
14381438
span.hi);
14391439
let mut item_vec: Vec<_> = items.collect();
@@ -1454,7 +1454,7 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
14541454
// first arguments.
14551455
if overflow_last {
14561456
let inner_context = &RewriteContext { block_indent: context.block_indent, ..*context };
1457-
let rewrite = args.last().unwrap().rewrite(&inner_context, remaining_width, offset);
1457+
let rewrite = args.last().unwrap().rewrite(inner_context, remaining_width, offset);
14581458

14591459
if let Some(rewrite) = rewrite {
14601460
let rewrite_first_line = Some(rewrite[..first_line_width(&rewrite)].to_owned());
@@ -1557,8 +1557,8 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
15571557
"}",
15581558
|item| {
15591559
match *item {
1560-
StructLitField::Regular(ref field) => field.span.lo,
1561-
StructLitField::Base(ref expr) => {
1560+
StructLitField::Regular(field) => field.span.lo,
1561+
StructLitField::Base(expr) => {
15621562
let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi);
15631563
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo));
15641564
let pos = snippet.find_uncommented("..").unwrap();
@@ -1568,19 +1568,19 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
15681568
},
15691569
|item| {
15701570
match *item {
1571-
StructLitField::Regular(ref field) => field.span.hi,
1572-
StructLitField::Base(ref expr) => expr.span.hi,
1571+
StructLitField::Regular(field) => field.span.hi,
1572+
StructLitField::Base(expr) => expr.span.hi,
15731573
}
15741574
},
15751575
|item| {
15761576
match *item {
1577-
StructLitField::Regular(ref field) => {
1577+
StructLitField::Regular(field) => {
15781578
rewrite_field(inner_context,
1579-
&field,
1579+
field,
15801580
v_budget.checked_sub(1).unwrap_or(0),
15811581
indent)
15821582
}
1583-
StructLitField::Base(ref expr) => {
1583+
StructLitField::Base(expr) => {
15841584
// 2 = ..
15851585
expr.rewrite(inner_context, try_opt!(v_budget.checked_sub(2)), indent + 2)
15861586
.map(|s| format!("..{}", s))
@@ -1678,7 +1678,7 @@ fn rewrite_field(context: &RewriteContext,
16781678
match expr {
16791679
Some(e) => Some(format!("{}{}{}", name, separator, e)),
16801680
None => {
1681-
let expr_offset = offset.block_indent(&context.config);
1681+
let expr_offset = offset.block_indent(context.config);
16821682
let expr = field.expr.rewrite(context,
16831683
try_opt!(context.config
16841684
.max_width
@@ -1843,7 +1843,7 @@ fn rewrite_assignment(context: &RewriteContext,
18431843
try_opt!(lhs.rewrite(context, max_width, offset)),
18441844
operator_str);
18451845

1846-
rewrite_assign_rhs(&context, lhs_str, rhs, width, offset)
1846+
rewrite_assign_rhs(context, lhs_str, rhs, width, offset)
18471847
}
18481848

18491849
// The left hand side must contain everything up to, and including, the
@@ -1863,7 +1863,7 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
18631863
};
18641864
// 1 = space between operator and rhs.
18651865
let max_width = try_opt!(width.checked_sub(last_line_width + 1));
1866-
let rhs = ex.rewrite(&context, max_width, offset + last_line_width + 1);
1866+
let rhs = ex.rewrite(context, max_width, offset + last_line_width + 1);
18671867

18681868
fn count_line_breaks(src: &str) -> usize {
18691869
src.chars().filter(|&x| x == '\n').count()

src/imports.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use std::cmp::{self, Ordering};
2121
use syntax::{ast, ptr};
2222

2323
fn path_of(a: &ast::ViewPath_) -> &ast::Path {
24-
match a {
25-
&ast::ViewPath_::ViewPathSimple(_, ref p) => p,
26-
&ast::ViewPath_::ViewPathGlob(ref p) => p,
27-
&ast::ViewPath_::ViewPathList(ref p, _) => p,
24+
match *a {
25+
ast::ViewPath_::ViewPathSimple(_, ref p) => p,
26+
ast::ViewPath_::ViewPathGlob(ref p) => p,
27+
ast::ViewPath_::ViewPathList(ref p, _) => p,
2828
}
2929
}
3030

@@ -203,7 +203,7 @@ impl<'a> FmtVisitor<'a> {
203203
// Fake out the formatter by setting `self.last_pos` to the appropriate location before
204204
// each item before visiting it.
205205
self.last_pos = ordered.1;
206-
self.visit_item(&ordered.0);
206+
self.visit_item(ordered.0);
207207
}
208208
self.last_pos = pos_after_last_use_item;
209209
}

src/issues.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ const FIX_ME_CHARS: &'static [char] = &['F', 'I', 'X', 'M', 'E'];
2222
// irrelevant outside the issues module
2323
impl ReportTactic {
2424
fn is_enabled(&self) -> bool {
25-
match *self {
26-
ReportTactic::Always => true,
27-
ReportTactic::Unnumbered => true,
28-
ReportTactic::Never => false,
29-
}
25+
*self != ReportTactic::Never
3026
}
3127
}
3228

0 commit comments

Comments
 (0)