Run clippy

This commit is contained in:
sinkuu 2016-08-23 23:14:45 +09:00
parent bce26d51bd
commit a3c63fdef9
18 changed files with 104 additions and 114 deletions

View File

@ -123,15 +123,15 @@ enum TargetKind {
impl TargetKind { impl TargetKind {
fn is_lib(&self) -> bool { fn is_lib(&self) -> bool {
match self { match *self {
&TargetKind::Lib => true, TargetKind::Lib => true,
_ => false, _ => false,
} }
} }
fn is_bin(&self) -> bool { fn is_bin(&self) -> bool {
match self { match *self {
&TargetKind::Bin => true, TargetKind::Bin => true,
_ => false, _ => false,
} }
} }
@ -180,8 +180,8 @@ fn target_from_json(jtarget: &Json) -> Target {
} }
} }
fn format_files(files: &Vec<PathBuf>, fn format_files(files: &[PathBuf],
fmt_args: &Vec<String>, fmt_args: &[String],
verbosity: Verbosity) verbosity: Verbosity)
-> Result<ExitStatus, std::io::Error> { -> Result<ExitStatus, std::io::Error> {
let stdout = if verbosity == Verbosity::Quiet { let stdout = if verbosity == Verbosity::Quiet {

View File

@ -198,7 +198,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
match try!(determine_operation(&matches)) { match try!(determine_operation(&matches)) {
Operation::Help => { Operation::Help => {
print_usage(&opts, ""); print_usage(opts, "");
Ok(Summary::new()) Ok(Summary::new())
} }
Operation::Version => { Operation::Version => {

View File

@ -186,7 +186,7 @@ pub fn rewrite_chain(expr: &ast::Expr,
format!("\n{}", indent.to_string(context.config)) format!("\n{}", indent.to_string(context.config))
}; };
let first_connector = if extend || subexpr_list.len() == 0 { let first_connector = if extend || subexpr_list.is_empty() {
"" ""
} else if let ast::ExprKind::Try(_) = subexpr_list[0].node { } else if let ast::ExprKind::Try(_) = subexpr_list[0].node {
"" ""

View File

@ -45,18 +45,14 @@ pub fn output_checkstyle_file<T>(mut writer: T,
try!(write!(writer, "<file name=\"{}\">", filename)); try!(write!(writer, "<file name=\"{}\">", filename));
for mismatch in diff { for mismatch in diff {
for line in mismatch.lines { for line in mismatch.lines {
match line { // Do nothing with `DiffLine::Context` and `DiffLine::Resulting`.
DiffLine::Expected(ref str) => { if let DiffLine::Expected(ref str) = line {
let message = xml_escape_str(&str); let message = xml_escape_str(str);
try!(write!(writer, try!(write!(writer,
"<error line=\"{}\" severity=\"warning\" message=\"Should be \ "<error line=\"{}\" severity=\"warning\" message=\"Should be `{}`\" \
`{}`\" />", />",
mismatch.line_number, mismatch.line_number,
message)); message));
}
_ => {
// Do nothing with context and expected.
}
} }
} }
} }

View File

@ -94,7 +94,7 @@ pub fn rewrite_comment(orig: &str,
let mut result = opener.to_owned(); let mut result = opener.to_owned();
for line in lines { for line in lines {
if result == opener { if result == opener {
if line.len() == 0 { if line.is_empty() {
continue; continue;
} }
} else { } else {
@ -107,7 +107,7 @@ pub fn rewrite_comment(orig: &str,
let rewrite = rewrite_string(line, &fmt).unwrap_or(line.to_owned()); let rewrite = rewrite_string(line, &fmt).unwrap_or(line.to_owned());
result.push_str(&rewrite); result.push_str(&rewrite);
} else { } else {
if line.len() == 0 { if line.is_empty() {
// Remove space if this is an empty comment or a doc comment. // Remove space if this is an empty comment or a doc comment.
result.pop(); result.pop();
} }
@ -136,7 +136,7 @@ fn left_trim_comment_line(line: &str) -> &str {
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") || } else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") ||
line.starts_with("**") { line.starts_with("**") {
&line[2..] &line[2..]
} else if line.starts_with("*") { } else if line.starts_with('*') {
&line[1..] &line[1..]
} else { } else {
line line
@ -524,7 +524,7 @@ pub fn recover_comment_removed(new: String,
if changed_comment_content(&snippet, &new) { if changed_comment_content(&snippet, &new) {
// We missed some comments // We missed some comments
// Keep previous formatting if it satisfies the constrains // Keep previous formatting if it satisfies the constrains
return wrap_str(snippet, context.config.max_width, width, offset); wrap_str(snippet, context.config.max_width, width, offset)
} else { } else {
Some(new) Some(new)
} }

View File

@ -298,7 +298,7 @@ pub fn rewrite_array<'a, I>(expr_iter: I,
|item| item.span.lo, |item| item.span.lo,
|item| item.span.hi, |item| item.span.hi,
// 1 = [ // 1 = [
|item| item.rewrite(&inner_context, max_item_width, offset), |item| item.rewrite(inner_context, max_item_width, offset),
span.lo, span.lo,
span.hi) span.hi)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@ -493,7 +493,7 @@ fn and_one_line(x: Option<String>) -> Option<String> {
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> { fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
block_str.map(|block_str| { block_str.map(|block_str| {
if block_str.starts_with("{") && budget >= 2 && if block_str.starts_with('{') && budget >= 2 &&
(block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) { (block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2) {
"{}".to_owned() "{}".to_owned()
} else { } else {
@ -772,7 +772,7 @@ fn rewrite_if_else(context: &RewriteContext,
pat.map_or(cond.span.lo, pat.map_or(cond.span.lo,
|_| context.codemap.span_before(span, "let"))); |_| context.codemap.span_before(span, "let")));
let between_if_cond_comment = extract_comment(between_if_cond, &context, offset, width); let between_if_cond_comment = extract_comment(between_if_cond, context, offset, width);
let after_cond_comment = extract_comment(mk_sp(cond.span.hi, if_block.span.lo), let after_cond_comment = extract_comment(mk_sp(cond.span.hi, if_block.span.lo),
context, context,
@ -831,13 +831,13 @@ fn rewrite_if_else(context: &RewriteContext,
mk_sp(if_block.span.hi, mk_sp(if_block.span.hi,
context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else")); context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else"));
let between_if_else_block_comment = let between_if_else_block_comment =
extract_comment(between_if_else_block, &context, offset, width); extract_comment(between_if_else_block, context, offset, width);
let after_else = mk_sp(context.codemap let after_else = mk_sp(context.codemap
.span_after(mk_sp(if_block.span.hi, else_block.span.lo), .span_after(mk_sp(if_block.span.hi, else_block.span.lo),
"else"), "else"),
else_block.span.lo); else_block.span.lo);
let after_else_comment = extract_comment(after_else, &context, offset, width); let after_else_comment = extract_comment(after_else, context, offset, width);
let between_sep = match context.config.else_if_brace_style { let between_sep = match context.config.else_if_brace_style {
ElseIfBraceStyle::AlwaysNextLine | ElseIfBraceStyle::AlwaysNextLine |
@ -854,7 +854,7 @@ fn rewrite_if_else(context: &RewriteContext,
.map_or(between_sep, |str| &**str), .map_or(between_sep, |str| &**str),
after_else_comment.as_ref().map_or(after_sep, |str| &**str)) after_else_comment.as_ref().map_or(after_sep, |str| &**str))
.ok()); .ok());
result.push_str(&&try_opt!(rewrite)); result.push_str(&try_opt!(rewrite));
} }
Some(result) Some(result)
@ -1021,7 +1021,7 @@ fn rewrite_match(context: &RewriteContext,
// We couldn't format the arm, just reproduce the source. // We couldn't format the arm, just reproduce the source.
let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm))); let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm)));
result.push_str(&snippet); result.push_str(&snippet);
result.push_str(arm_comma(&context.config, &arm, &arm.body)); result.push_str(arm_comma(context.config, arm, &arm.body));
} }
} }
// BytePos(1) = closing match brace. // BytePos(1) = closing match brace.
@ -1102,7 +1102,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
.map(|p| p.rewrite(context, pat_budget, offset)) .map(|p| p.rewrite(context, pat_budget, offset))
.collect::<Option<Vec<_>>>()); .collect::<Option<Vec<_>>>());
let all_simple = pat_strs.iter().all(|p| pat_is_simple(&p)); let all_simple = pat_strs.iter().all(|p| pat_is_simple(p));
let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect(); let items: Vec<_> = pat_strs.into_iter().map(ListItem::from_str).collect();
let fmt = ListFormatting { let fmt = ListFormatting {
tactic: if all_simple { tactic: if all_simple {
@ -1145,7 +1145,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
ref x => x, ref x => x,
}; };
let comma = arm_comma(&context.config, self, body); let comma = arm_comma(context.config, self, body);
let alt_block_sep = String::from("\n") + &context.block_indent.to_string(context.config); let alt_block_sep = String::from("\n") + &context.block_indent.to_string(context.config);
// Let's try and get the arm body on the same line as the condition. // 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,
expr.rewrite(context, expr.rewrite(context,
try_opt!(context.config.max_width.checked_sub(pat_offset.width())), try_opt!(context.config.max_width.checked_sub(pat_offset.width())),
pat_offset); pat_offset);
result.push_str(&&try_opt!(expr_rewrite)); result.push_str(&try_opt!(expr_rewrite));
Some(result) Some(result)
} }
@ -1433,7 +1433,7 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
")", ")",
|item| item.span.lo, |item| item.span.lo,
|item| item.span.hi, |item| item.span.hi,
|item| item.rewrite(&inner_context, remaining_width, offset), |item| item.rewrite(inner_context, remaining_width, offset),
span.lo, span.lo,
span.hi); span.hi);
let mut item_vec: Vec<_> = items.collect(); let mut item_vec: Vec<_> = items.collect();
@ -1454,7 +1454,7 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
// first arguments. // first arguments.
if overflow_last { if overflow_last {
let inner_context = &RewriteContext { block_indent: context.block_indent, ..*context }; let inner_context = &RewriteContext { block_indent: context.block_indent, ..*context };
let rewrite = args.last().unwrap().rewrite(&inner_context, remaining_width, offset); let rewrite = args.last().unwrap().rewrite(inner_context, remaining_width, offset);
if let Some(rewrite) = rewrite { if let Some(rewrite) = rewrite {
let rewrite_first_line = Some(rewrite[..first_line_width(&rewrite)].to_owned()); let rewrite_first_line = Some(rewrite[..first_line_width(&rewrite)].to_owned());
@ -1557,8 +1557,8 @@ enum StructLitField<'a> {
"}", "}",
|item| { |item| {
match *item { match *item {
StructLitField::Regular(ref field) => field.span.lo, StructLitField::Regular(field) => field.span.lo,
StructLitField::Base(ref expr) => { StructLitField::Base(expr) => {
let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi); let last_field_hi = fields.last().map_or(span.lo, |field| field.span.hi);
let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo)); let snippet = context.snippet(mk_sp(last_field_hi, expr.span.lo));
let pos = snippet.find_uncommented("..").unwrap(); let pos = snippet.find_uncommented("..").unwrap();
@ -1568,19 +1568,19 @@ enum StructLitField<'a> {
}, },
|item| { |item| {
match *item { match *item {
StructLitField::Regular(ref field) => field.span.hi, StructLitField::Regular(field) => field.span.hi,
StructLitField::Base(ref expr) => expr.span.hi, StructLitField::Base(expr) => expr.span.hi,
} }
}, },
|item| { |item| {
match *item { match *item {
StructLitField::Regular(ref field) => { StructLitField::Regular(field) => {
rewrite_field(inner_context, rewrite_field(inner_context,
&field, field,
v_budget.checked_sub(1).unwrap_or(0), v_budget.checked_sub(1).unwrap_or(0),
indent) indent)
} }
StructLitField::Base(ref expr) => { StructLitField::Base(expr) => {
// 2 = .. // 2 = ..
expr.rewrite(inner_context, try_opt!(v_budget.checked_sub(2)), indent + 2) expr.rewrite(inner_context, try_opt!(v_budget.checked_sub(2)), indent + 2)
.map(|s| format!("..{}", s)) .map(|s| format!("..{}", s))
@ -1678,7 +1678,7 @@ fn rewrite_field(context: &RewriteContext,
match expr { match expr {
Some(e) => Some(format!("{}{}{}", name, separator, e)), Some(e) => Some(format!("{}{}{}", name, separator, e)),
None => { None => {
let expr_offset = offset.block_indent(&context.config); let expr_offset = offset.block_indent(context.config);
let expr = field.expr.rewrite(context, let expr = field.expr.rewrite(context,
try_opt!(context.config try_opt!(context.config
.max_width .max_width
@ -1843,7 +1843,7 @@ fn rewrite_assignment(context: &RewriteContext,
try_opt!(lhs.rewrite(context, max_width, offset)), try_opt!(lhs.rewrite(context, max_width, offset)),
operator_str); operator_str);
rewrite_assign_rhs(&context, lhs_str, rhs, width, offset) rewrite_assign_rhs(context, lhs_str, rhs, width, offset)
} }
// The left hand side must contain everything up to, and including, the // 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,
}; };
// 1 = space between operator and rhs. // 1 = space between operator and rhs.
let max_width = try_opt!(width.checked_sub(last_line_width + 1)); let max_width = try_opt!(width.checked_sub(last_line_width + 1));
let rhs = ex.rewrite(&context, max_width, offset + last_line_width + 1); let rhs = ex.rewrite(context, max_width, offset + last_line_width + 1);
fn count_line_breaks(src: &str) -> usize { fn count_line_breaks(src: &str) -> usize {
src.chars().filter(|&x| x == '\n').count() src.chars().filter(|&x| x == '\n').count()

View File

@ -21,10 +21,10 @@
use syntax::{ast, ptr}; use syntax::{ast, ptr};
fn path_of(a: &ast::ViewPath_) -> &ast::Path { fn path_of(a: &ast::ViewPath_) -> &ast::Path {
match a { match *a {
&ast::ViewPath_::ViewPathSimple(_, ref p) => p, ast::ViewPath_::ViewPathSimple(_, ref p) => p,
&ast::ViewPath_::ViewPathGlob(ref p) => p, ast::ViewPath_::ViewPathGlob(ref p) => p,
&ast::ViewPath_::ViewPathList(ref p, _) => p, ast::ViewPath_::ViewPathList(ref p, _) => p,
} }
} }
@ -203,7 +203,7 @@ pub fn format_imports(&mut self, use_items: &[ptr::P<ast::Item>]) {
// Fake out the formatter by setting `self.last_pos` to the appropriate location before // Fake out the formatter by setting `self.last_pos` to the appropriate location before
// each item before visiting it. // each item before visiting it.
self.last_pos = ordered.1; self.last_pos = ordered.1;
self.visit_item(&ordered.0); self.visit_item(ordered.0);
} }
self.last_pos = pos_after_last_use_item; self.last_pos = pos_after_last_use_item;
} }

View File

@ -22,11 +22,7 @@
// irrelevant outside the issues module // irrelevant outside the issues module
impl ReportTactic { impl ReportTactic {
fn is_enabled(&self) -> bool { fn is_enabled(&self) -> bool {
match *self { *self != ReportTactic::Never
ReportTactic::Always => true,
ReportTactic::Unnumbered => true,
ReportTactic::Never => false,
}
} }
} }

View File

@ -276,7 +276,7 @@ fn single_line_fn(&self, fn_str: &str, block: &ast::Block) -> Option<String> {
self.block_indent) self.block_indent)
.map(|s| s + suffix) .map(|s| s + suffix)
.or_else(|| Some(self.snippet(e.span))) .or_else(|| Some(self.snippet(e.span)))
} else if let Some(ref stmt) = block.stmts.first() { } else if let Some(stmt) = block.stmts.first() {
stmt.rewrite(&self.get_context(), stmt.rewrite(&self.get_context(),
self.config.max_width - self.block_indent.width(), self.config.max_width - self.block_indent.width(),
self.block_indent) self.block_indent)
@ -324,7 +324,7 @@ pub fn visit_enum(&mut self,
self.block_indent = self.block_indent.block_indent(self.config); self.block_indent = self.block_indent.block_indent(self.config);
let variant_list = self.format_variant_list(enum_def, body_start, span.hi - BytePos(1)); let variant_list = self.format_variant_list(enum_def, body_start, span.hi - BytePos(1));
match variant_list { match variant_list {
Some(ref body_str) => self.buffer.push_str(&body_str), Some(ref body_str) => self.buffer.push_str(body_str),
None => { None => {
if contains_comment(&enum_snippet[brace_pos..]) { if contains_comment(&enum_snippet[brace_pos..]) {
self.format_missing_no_indent(span.hi - BytePos(1)) self.format_missing_no_indent(span.hi - BytePos(1))
@ -554,7 +554,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
visitor.last_pos = item.span.lo + BytePos(open_pos as u32); visitor.last_pos = item.span.lo + BytePos(open_pos as u32);
for item in items { for item in items {
visitor.visit_impl_item(&item); visitor.visit_impl_item(item);
} }
visitor.format_missing(item.span.hi - BytePos(1)); visitor.format_missing(item.span.hi - BytePos(1));
@ -564,7 +564,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
result.push('\n'); result.push('\n');
result.push_str(&inner_indent_str); result.push_str(&inner_indent_str);
result.push_str(&trim_newlines(&visitor.buffer.to_string().trim())); result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
result.push('\n'); result.push('\n');
result.push_str(&outer_indent_str); result.push_str(&outer_indent_str);
} }
@ -581,7 +581,7 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
} }
fn is_impl_single_line(context: &RewriteContext, fn is_impl_single_line(context: &RewriteContext,
items: &Vec<ImplItem>, items: &[ImplItem],
result: &str, result: &str,
where_clause_str: &str, where_clause_str: &str,
item: &ast::Item) item: &ast::Item)
@ -713,7 +713,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
BraceStyle::PreferSameLine => result.push(' '), BraceStyle::PreferSameLine => result.push(' '),
BraceStyle::SameLineWhere => { BraceStyle::SameLineWhere => {
if !where_clause_str.is_empty() && if !where_clause_str.is_empty() &&
(trait_items.len() > 0 || result.contains('\n')) { (!trait_items.is_empty() || result.contains('\n')) {
result.push('\n'); result.push('\n');
result.push_str(&offset.to_string(context.config)); result.push_str(&offset.to_string(context.config));
} else { } else {
@ -732,7 +732,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
visitor.last_pos = item.span.lo + BytePos(open_pos as u32); visitor.last_pos = item.span.lo + BytePos(open_pos as u32);
for item in trait_items { for item in trait_items {
visitor.visit_trait_item(&item); visitor.visit_trait_item(item);
} }
visitor.format_missing(item.span.hi - BytePos(1)); visitor.format_missing(item.span.hi - BytePos(1));
@ -742,7 +742,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
result.push('\n'); result.push('\n');
result.push_str(&inner_indent_str); result.push_str(&inner_indent_str);
result.push_str(&trim_newlines(&visitor.buffer.to_string().trim())); result.push_str(trim_newlines(visitor.buffer.to_string().trim()));
result.push('\n'); result.push('\n');
result.push_str(&outer_indent_str); result.push_str(&outer_indent_str);
} else if result.contains('\n') { } else if result.contains('\n') {
@ -876,7 +876,7 @@ fn format_tuple_struct(context: &RewriteContext,
}; };
let where_clause_str = match generics { let where_clause_str = match generics {
Some(ref generics) => { Some(generics) => {
let generics_str = try_opt!(rewrite_generics(context, let generics_str = try_opt!(rewrite_generics(context,
generics, generics,
offset, offset,
@ -951,7 +951,7 @@ pub fn rewrite_type_alias(context: &RewriteContext,
-> Option<String> { -> Option<String> {
let mut result = String::new(); let mut result = String::new();
result.push_str(&format_visibility(&vis)); result.push_str(&format_visibility(vis));
result.push_str("type "); result.push_str("type ");
result.push_str(&ident.to_string()); result.push_str(&ident.to_string());
@ -1069,7 +1069,7 @@ pub fn rewrite_static(prefix: &str,
prefix.len() - 2, prefix.len() - 2,
context.block_indent)); context.block_indent));
if let Some(ref expr) = expr_opt { if let Some(expr) = expr_opt {
let lhs = format!("{}{} =", prefix, ty_str); let lhs = format!("{}{} =", prefix, ty_str);
// 1 = ; // 1 = ;
let remaining_width = context.config.max_width - context.block_indent.width() - 1; let remaining_width = context.config.max_width - context.block_indent.width() - 1;
@ -1090,7 +1090,7 @@ pub fn rewrite_associated_type(ident: ast::Ident,
let prefix = format!("type {}", ident); let prefix = format!("type {}", ident);
let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt { let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
let bounds: &[_] = &ty_param_bounds; let bounds: &[_] = ty_param_bounds;
let bound_str = try_opt!(bounds.iter() let bound_str = try_opt!(bounds.iter()
.map(|ty_bound| ty_bound.rewrite(context, context.config.max_width, indent)) .map(|ty_bound| ty_bound.rewrite(context, context.config.max_width, indent))
.intersperse(Some(" + ".to_string())) .intersperse(Some(" + ".to_string()))
@ -1374,7 +1374,7 @@ fn rewrite_fn_base(context: &RewriteContext,
FnArgLayoutStyle::Block => multi_line_arg_str, FnArgLayoutStyle::Block => multi_line_arg_str,
FnArgLayoutStyle::BlockAlways => true, FnArgLayoutStyle::BlockAlways => true,
_ => false, _ => false,
} && fd.inputs.len() > 0; } && !fd.inputs.is_empty();
if put_args_in_block { if put_args_in_block {
arg_indent = indent.block_indent(context.config); arg_indent = indent.block_indent(context.config);
@ -1410,7 +1410,7 @@ fn rewrite_fn_base(context: &RewriteContext,
let overlong_sig = sig_length > context.config.max_width; let overlong_sig = sig_length > context.config.max_width;
result.contains("\n") || multi_line_ret_str || overlong_sig result.contains('\n') || multi_line_ret_str || overlong_sig
} }
}; };
let ret_indent = if ret_should_indent { let ret_indent = if ret_should_indent {
@ -1647,7 +1647,7 @@ fn compute_budgets_for_args(context: &RewriteContext,
newline_brace: bool) newline_brace: bool)
-> Option<((usize, usize, Indent))> { -> Option<((usize, usize, Indent))> {
// Try keeping everything on the same line. // Try keeping everything on the same line.
if !result.contains("\n") { if !result.contains('\n') {
// 3 = `() `, space is before ret_string. // 3 = `() `, space is before ret_string.
let mut used_space = indent.width() + result.len() + ret_str_len + 3; let mut used_space = indent.width() + result.len() + ret_str_len + 3;
if !newline_brace { if !newline_brace {
@ -1710,8 +1710,8 @@ fn rewrite_generics(context: &RewriteContext,
// FIXME: might need to insert a newline if the generics are really long. // FIXME: might need to insert a newline if the generics are really long.
// Strings for the generics. // Strings for the generics.
let lt_strs = lifetimes.iter().map(|lt| lt.rewrite(&context, h_budget, offset)); let lt_strs = lifetimes.iter().map(|lt| lt.rewrite(context, h_budget, offset));
let ty_strs = tys.iter().map(|ty_param| ty_param.rewrite(&context, h_budget, offset)); let ty_strs = tys.iter().map(|ty_param| ty_param.rewrite(context, h_budget, offset));
// Extract comments between generics. // Extract comments between generics.
let lt_spans = lifetimes.iter().map(|l| { let lt_spans = lifetimes.iter().map(|l| {
@ -1743,7 +1743,7 @@ fn rewrite_trait_bounds(context: &RewriteContext,
indent: Indent, indent: Indent,
width: usize) width: usize)
-> Option<String> { -> Option<String> {
let bounds: &[_] = &type_param_bounds; let bounds: &[_] = type_param_bounds;
if bounds.is_empty() { if bounds.is_empty() {
return Some(String::new()); return Some(String::new());
@ -1801,7 +1801,7 @@ fn rewrite_where_clause(context: &RewriteContext,
terminator, terminator,
|pred| span_for_where_pred(pred).lo, |pred| span_for_where_pred(pred).lo,
|pred| span_for_where_pred(pred).hi, |pred| span_for_where_pred(pred).hi,
|pred| pred.rewrite(&context, budget, offset), |pred| pred.rewrite(context, budget, offset),
span_start, span_start,
span_end); span_end);
let item_vec = items.collect::<Vec<_>>(); let item_vec = items.collect::<Vec<_>>();
@ -1825,9 +1825,9 @@ fn rewrite_where_clause(context: &RewriteContext,
// If the brace is on the next line we don't need to count it otherwise it needs two // If the brace is on the next line we don't need to count it otherwise it needs two
// characters " {" // characters " {"
match brace_style { match brace_style {
BraceStyle::AlwaysNextLine => 0, BraceStyle::AlwaysNextLine |
BraceStyle::PreferSameLine => 2,
BraceStyle::SameLineWhere => 0, BraceStyle::SameLineWhere => 0,
BraceStyle::PreferSameLine => 2,
} }
} else if terminator == "=" { } else if terminator == "=" {
2 2

View File

@ -254,7 +254,7 @@ fn new() -> FormatReport {
} }
pub fn warning_count(&self) -> usize { pub fn warning_count(&self) -> usize {
self.file_error_map.iter().map(|(_, ref errors)| errors.len()).fold(0, |acc, x| acc + x) self.file_error_map.iter().map(|(_, errors)| errors.len()).fold(0, |acc, x| acc + x)
} }
pub fn has_warnings(&self) -> bool { pub fn has_warnings(&self) -> bool {
@ -392,9 +392,9 @@ fn parse_input(input: Input,
parse_session: &ParseSess) parse_session: &ParseSess)
-> Result<ast::Crate, Option<DiagnosticBuilder>> { -> Result<ast::Crate, Option<DiagnosticBuilder>> {
let result = match input { let result = match input {
Input::File(file) => parse::parse_crate_from_file(&file, Vec::new(), &parse_session), Input::File(file) => parse::parse_crate_from_file(&file, Vec::new(), parse_session),
Input::Text(text) => { Input::Text(text) => {
parse::parse_crate_from_source_str("stdin".to_owned(), text, Vec::new(), &parse_session) parse::parse_crate_from_source_str("stdin".to_owned(), text, Vec::new(), parse_session)
} }
}; };

View File

@ -357,7 +357,7 @@ fn next(&mut self) -> Option<Self::Item> {
// Post-comment // Post-comment
let next_start = match self.inner.peek() { let next_start = match self.inner.peek() {
Some(ref next_item) => (self.get_lo)(next_item), Some(next_item) => (self.get_lo)(next_item),
None => self.next_span_start, None => self.next_span_start,
}; };
let post_snippet = self.codemap let post_snippet = self.codemap
@ -420,7 +420,7 @@ fn next(&mut self) -> Option<Self::Item> {
let post_snippet_trimmed = if post_snippet.starts_with(',') { let post_snippet_trimmed = if post_snippet.starts_with(',') {
post_snippet[1..].trim_matches(white_space) post_snippet[1..].trim_matches(white_space)
} else if post_snippet.ends_with(",") { } else if post_snippet.ends_with(',') {
post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space) post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
} else { } else {
post_snippet post_snippet

View File

@ -111,7 +111,7 @@ pub fn rewrite_macro(mac: &ast::Mac,
_ => return None, _ => return None,
} }
let _ = parser.bump(); parser.bump();
if parser.token == Token::Eof { if parser.token == Token::Eof {
return None; return None;

View File

@ -118,7 +118,7 @@ fn replace_chars(string: &str) -> String {
let last_char = big_snippet[..(offset + big_diff)] let last_char = big_snippet[..(offset + big_diff)]
.chars() .chars()
.rev() .rev()
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c)) .skip_while(|rev_c| [' ', '\t'].contains(rev_c))
.next(); .next();
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c)); let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
@ -174,19 +174,17 @@ fn replace_chars(string: &str) -> String {
line_start = i + 1; line_start = i + 1;
last_wspace = None; last_wspace = None;
rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal; rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal;
} else { } else if c.is_whitespace() {
if c.is_whitespace() { if last_wspace.is_none() {
if last_wspace.is_none() { last_wspace = Some(i);
last_wspace = Some(i);
}
} else {
rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal;
last_wspace = None;
} }
} else {
rewrite_next_comment = rewrite_next_comment || kind == CodeCharKind::Normal;
last_wspace = None;
} }
} }
} }
process_last_snippet(self, &snippet[line_start..], &snippet); process_last_snippet(self, &snippet[line_start..], snippet);
} }
} }

View File

@ -64,11 +64,11 @@ fn module_file(id: ast::Ident,
dir_path: &Path, dir_path: &Path,
codemap: &codemap::CodeMap) codemap: &codemap::CodeMap)
-> PathBuf { -> PathBuf {
if let Some(path) = parser::Parser::submod_path_from_attr(attrs, &dir_path) { if let Some(path) = parser::Parser::submod_path_from_attr(attrs, dir_path) {
return path; return path;
} }
match parser::Parser::default_submod_path(id, &dir_path, codemap).result { match parser::Parser::default_submod_path(id, dir_path, codemap).result {
Ok(parser::ModulePathSuccess { path, .. }) => path, Ok(parser::ModulePathSuccess { path, .. }) => path,
Err(_) => panic!("Couldn't find module {}", id), Err(_) => panic!("Couldn't find module {}", id),
} }

View File

@ -153,7 +153,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
field_string.push_str(&offset.to_string(context.config)); field_string.push_str(&offset.to_string(context.config));
field_string.push_str(".."); field_string.push_str("..");
} else { } else {
if field_string.len() > 0 { if !field_string.is_empty() {
field_string.push_str(", "); field_string.push_str(", ");
} }
field_string.push_str(".."); field_string.push_str("..");

View File

@ -43,7 +43,7 @@ pub fn rewrite_path(context: &RewriteContext,
let mut span_lo = path.span.lo; let mut span_lo = path.span.lo;
if let Some(ref qself) = qself { if let Some(qself) = qself {
result.push('<'); result.push('<');
let fmt_ty = try_opt!(qself.ty.rewrite(context, width, offset)); let fmt_ty = try_opt!(qself.ty.rewrite(context, width, offset));
result.push_str(&fmt_ty); result.push_str(&fmt_ty);
@ -131,9 +131,9 @@ enum SegmentParam<'a> {
impl<'a> SegmentParam<'a> { impl<'a> SegmentParam<'a> {
fn get_span(&self) -> Span { fn get_span(&self) -> Span {
match *self { match *self {
SegmentParam::LifeTime(ref lt) => lt.span, SegmentParam::LifeTime(lt) => lt.span,
SegmentParam::Type(ref ty) => ty.span, SegmentParam::Type(ty) => ty.span,
SegmentParam::Binding(ref binding) => binding.span, SegmentParam::Binding(binding) => binding.span,
} }
} }
} }
@ -141,9 +141,9 @@ fn get_span(&self) -> Span {
impl<'a> Rewrite for SegmentParam<'a> { impl<'a> Rewrite for SegmentParam<'a> {
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> { fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
match *self { match *self {
SegmentParam::LifeTime(ref lt) => lt.rewrite(context, width, offset), SegmentParam::LifeTime(lt) => lt.rewrite(context, width, offset),
SegmentParam::Type(ref ty) => ty.rewrite(context, width, offset), SegmentParam::Type(ty) => ty.rewrite(context, width, offset),
SegmentParam::Binding(ref binding) => { SegmentParam::Binding(binding) => {
let mut result = format!("{} = ", binding.ident); let mut result = format!("{} = ", binding.ident);
let budget = try_opt!(width.checked_sub(result.len())); let budget = try_opt!(width.checked_sub(result.len()));
let rewrite = try_opt!(binding.ty.rewrite(context, budget, offset + result.len())); let rewrite = try_opt!(binding.ty.rewrite(context, budget, offset + result.len()));
@ -306,7 +306,7 @@ enum ArgumentKind<T>
FunctionRetTy::Default(..) => String::new(), FunctionRetTy::Default(..) => String::new(),
}; };
let infix = if output.len() > 0 && output.len() + list_str.len() > width { let infix = if !output.is_empty() && output.len() + list_str.len() > width {
format!("\n{}", (offset - 1).to_string(context.config)) format!("\n{}", (offset - 1).to_string(context.config))
} else { } else {
String::new() String::new()
@ -622,7 +622,7 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
result.push_str("> "); result.push_str("> ");
} }
result.push_str(&::utils::format_unsafety(bare_fn.unsafety)); result.push_str(::utils::format_unsafety(bare_fn.unsafety));
if bare_fn.abi != abi::Abi::Rust { if bare_fn.abi != abi::Abi::Rust {
result.push_str(&::utils::format_abi(bare_fn.abi, context.config.force_explicit_abi)); result.push_str(&::utils::format_abi(bare_fn.abi, context.config.force_explicit_abi));

View File

@ -251,7 +251,7 @@ pub fn wrap_str<S: AsRef<str>>(s: S, max_width: usize, width: usize, offset: Ind
} }
// The other lines must fit within the maximum width. // The other lines must fit within the maximum width.
if lines.find(|line| line.len() > max_width).is_some() { if lines.any(|line| line.len() > max_width) {
return None; return None;
} }

View File

@ -85,7 +85,7 @@ pub fn visit_block(&mut self, b: &ast::Block) {
// Check if this block has braces. // Check if this block has braces.
let snippet = self.snippet(b.span); let snippet = self.snippet(b.span);
let has_braces = snippet.starts_with("{") || snippet.starts_with("unsafe"); let has_braces = snippet.starts_with('{') || snippet.starts_with("unsafe");
let brace_compensation = if has_braces { BytePos(1) } else { BytePos(0) }; let brace_compensation = if has_braces { BytePos(1) } else { BytePos(0) };
self.last_pos = self.last_pos + brace_compensation; self.last_pos = self.last_pos + brace_compensation;
@ -93,7 +93,7 @@ pub fn visit_block(&mut self, b: &ast::Block) {
self.buffer.push_str("{"); self.buffer.push_str("{");
for stmt in &b.stmts { for stmt in &b.stmts {
self.visit_stmt(&stmt) self.visit_stmt(stmt)
} }
if let Some(ref e) = b.expr { if let Some(ref e) = b.expr {
@ -144,7 +144,7 @@ fn visit_fn(&mut self,
defaultness: ast::Defaultness) { defaultness: ast::Defaultness) {
let indent = self.block_indent; let indent = self.block_indent;
let rewrite = match fk { let rewrite = match fk {
visit::FnKind::ItemFn(ident, ref generics, unsafety, constness, abi, vis) => { visit::FnKind::ItemFn(ident, generics, unsafety, constness, abi, vis) => {
self.rewrite_fn(indent, self.rewrite_fn(indent,
ident, ident,
fd, fd,
@ -155,9 +155,9 @@ fn visit_fn(&mut self,
abi, abi,
vis, vis,
codemap::mk_sp(s.lo, b.span.lo), codemap::mk_sp(s.lo, b.span.lo),
&b) b)
} }
visit::FnKind::Method(ident, ref sig, vis) => { visit::FnKind::Method(ident, sig, vis) => {
self.rewrite_fn(indent, self.rewrite_fn(indent,
ident, ident,
fd, fd,
@ -168,7 +168,7 @@ fn visit_fn(&mut self,
sig.abi, sig.abi,
vis.unwrap_or(&ast::Visibility::Inherited), vis.unwrap_or(&ast::Visibility::Inherited),
codemap::mk_sp(s.lo, b.span.lo), codemap::mk_sp(s.lo, b.span.lo),
&b) b)
} }
visit::FnKind::Closure => None, visit::FnKind::Closure => None,
}; };
@ -374,7 +374,7 @@ pub fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
ast::TraitItemKind::Method(ref sig, Some(ref body)) => { ast::TraitItemKind::Method(ref sig, Some(ref body)) => {
self.visit_fn(visit::FnKind::Method(ti.ident, sig, None), self.visit_fn(visit::FnKind::Method(ti.ident, sig, None),
&sig.decl, &sig.decl,
&body, body,
ti.span, ti.span,
ti.id, ti.id,
ast::Defaultness::Final); ast::Defaultness::Final);
@ -516,7 +516,7 @@ fn walk_mod_items(&mut self, m: &ast::Mod) {
// `unwrap()` is safe here because we know `items_left` // `unwrap()` is safe here because we know `items_left`
// has elements from the loop condition // has elements from the loop condition
let (item, rest) = items_left.split_first().unwrap(); let (item, rest) = items_left.split_first().unwrap();
self.visit_item(&item); self.visit_item(item);
items_left = rest; items_left = rest;
} }
} }