Format source codes

This commit is contained in:
Seiichi Uchida 2017-06-01 12:08:09 +09:00
parent 789abf063d
commit 10c3632078
3 changed files with 26 additions and 22 deletions

View File

@ -968,13 +968,15 @@ impl<'a> Rewrite for ControlFlow<'a> {
};
// for event in event
let between_kwd_cond = mk_sp(context.codemap.span_after(self.span, self.keyword.trim()),
self.pat
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
p.span.lo
} else {
context.codemap.span_before(self.span, self.matcher.trim())
}));
let between_kwd_cond = mk_sp(
context.codemap.span_after(self.span, self.keyword.trim()),
self.pat
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
p.span.lo
} else {
context.codemap.span_before(self.span, self.matcher.trim())
}),
);
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);

View File

@ -610,22 +610,24 @@ pub fn format_input<T: Write>(input: Input,
let mut report = FormatReport::new();
match format_ast(&krate,
&parse_session,
&main_file,
config,
|file_name, file| {
// For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad.
filemap::append_newline(file);
match format_ast(
&krate,
&parse_session,
&main_file,
config,
|file_name, file| {
// For some reason, the codemap does not include terminating
// newlines so we must add one on for each file. This is sad.
filemap::append_newline(file);
format_lines(file, file_name, config, &mut report);
format_lines(file, file_name, config, &mut report);
if let Some(ref mut out) = out {
return filemap::write_file(file, file_name, out, config);
if let Some(ref mut out) = out {
return filemap::write_file(file, file_name, out, config);
}
Ok(false)
}
Ok(false)
}) {
) {
Ok((file_map, has_diff)) => {
if report.has_warnings() {
summary.add_formatting_error();

View File

@ -205,10 +205,10 @@ pub fn rewrite_macro(mac: &ast::Mac,
context
.codemap
.span_after(mac.span, original_style.opener()),
mac.span.hi - BytePos(1)
mac.span.hi - BytePos(1),
),
context,
mac_shape
mac_shape,
));
Some(format!("{}{}", macro_name, rewrite))