Format source codes

This commit is contained in:
Seiichi Uchida 2017-05-15 22:55:45 +09:00
parent 79ba34c607
commit 762db5138e
7 changed files with 49 additions and 50 deletions

View File

@ -1961,14 +1961,14 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
// 3 = "(" + ",)"
let nested_shape = try_opt!(shape.sub_width(3)).visual_indent(1);
return items
.next()
.unwrap()
.rewrite(context, nested_shape)
.map(|s| if context.config.spaces_within_parens {
format!("( {}, )", s)
} else {
format!("({},)", s)
});
.next()
.unwrap()
.rewrite(context, nested_shape)
.map(|s| if context.config.spaces_within_parens {
format!("( {}, )", s)
} else {
format!("({},)", s)
});
}
let list_lo = context.codemap.span_after(span, "(");

View File

@ -131,16 +131,16 @@ impl BadIssueSeeker {
todo_idx += 1;
if todo_idx == TO_DO_CHARS.len() {
return Seeking::Number {
issue: Issue {
issue_type: IssueType::Todo,
missing_number: if let ReportTactic::Unnumbered = self.report_todo {
true
} else {
false
},
},
part: NumberPart::OpenParen,
};
issue: Issue {
issue_type: IssueType::Todo,
missing_number: if let ReportTactic::Unnumbered = self.report_todo {
true
} else {
false
},
},
part: NumberPart::OpenParen,
};
}
fixme_idx = 0;
} else if self.report_fixme.is_enabled() && c == FIX_ME_CHARS[fixme_idx] {
@ -149,17 +149,16 @@ impl BadIssueSeeker {
fixme_idx += 1;
if fixme_idx == FIX_ME_CHARS.len() {
return Seeking::Number {
issue: Issue {
issue_type: IssueType::Fixme,
missing_number: if let ReportTactic::Unnumbered =
self.report_fixme {
true
} else {
false
},
},
part: NumberPart::OpenParen,
};
issue: Issue {
issue_type: IssueType::Fixme,
missing_number: if let ReportTactic::Unnumbered = self.report_fixme {
true
} else {
false
},
},
part: NumberPart::OpenParen,
};
}
todo_idx = 0;
} else {
@ -182,10 +181,10 @@ impl BadIssueSeeker {
return IssueClassification::Bad(issue);
} else if c == ')' {
return if let NumberPart::CloseParen = part {
IssueClassification::Good
} else {
IssueClassification::Bad(issue)
};
IssueClassification::Good
} else {
IssueClassification::Bad(issue)
};
}
match part {

View File

@ -1104,7 +1104,7 @@ fn format_tuple_struct(context: &RewriteContext,
// know that earlier, so the where clause will not be indented properly.
result.push('\n');
result.push_str(&(offset.block_only() + (context.config.tab_spaces - 1))
.to_string(context.config));
.to_string(context.config));
}
result.push_str(&where_clause_str);

View File

@ -94,13 +94,13 @@ pub fn rewrite_macro(mac: &ast::Mac,
if mac.node.tts.is_empty() && !contains_comment(&context.snippet(mac.span)) {
return match style {
MacroStyle::Parens if position == MacroPosition::Item => {
Some(format!("{}();", macro_name))
}
MacroStyle::Parens => Some(format!("{}()", macro_name)),
MacroStyle::Brackets => Some(format!("{}[]", macro_name)),
MacroStyle::Braces => Some(format!("{}{{}}", macro_name)),
};
MacroStyle::Parens if position == MacroPosition::Item => {
Some(format!("{}();", macro_name))
}
MacroStyle::Parens => Some(format!("{}()", macro_name)),
MacroStyle::Brackets => Some(format!("{}[]", macro_name)),
MacroStyle::Braces => Some(format!("{}{{}}", macro_name)),
};
}
let mut parser = tts_to_parser(context.parse_session, mac.node.tts.clone());

View File

@ -138,8 +138,8 @@ impl<'a> FmtVisitor<'a> {
if rewrite_next_comment &&
!self.config
.file_lines
.intersects_range(file_name, cur_line, cur_line + subslice_num_lines) {
.file_lines
.intersects_range(file_name, cur_line, cur_line + subslice_num_lines) {
rewrite_next_comment = false;
}
@ -164,7 +164,7 @@ impl<'a> FmtVisitor<'a> {
Shape::legacy(comment_width,
self.block_indent),
self.config)
.unwrap());
.unwrap());
last_wspace = None;
line_start = offset + subslice.len();
@ -172,9 +172,9 @@ impl<'a> FmtVisitor<'a> {
if let Some('/') = subslice.chars().skip(1).next() {
// check that there are no contained block comments
if !subslice
.split('\n')
.map(|s| s.trim_left())
.any(|s| s.len() > 2 && &s[0..2] == "/*") {
.split('\n')
.map(|s| s.trim_left())
.any(|s| s.len() > 2 && &s[0..2] == "/*") {
// Add a newline after line comments
self.buffer.push_str("\n");
}

View File

@ -595,7 +595,7 @@ impl Rewrite for ast::Ty {
Mutability::Immutable => "*const ",
};
rewrite_unary_prefix(context, prefix, &*mt.ty, shape, self.span)
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
}
ast::TyKind::Rptr(ref lifetime, ref mt) => {
let mut_str = format_mutability(mt.mutbl);

View File

@ -50,8 +50,8 @@ impl<'a> FmtVisitor<'a> {
// FIXME(#434): Move this check to somewhere more central, eg Rewrite.
if !self.config
.file_lines
.intersects(&self.codemap.lookup_line_range(stmt.span)) {
.file_lines
.intersects(&self.codemap.lookup_line_range(stmt.span)) {
return;
}