Format source codes
This commit is contained in:
parent
789abf063d
commit
10c3632078
3 changed files with 26 additions and 22 deletions
16
src/expr.rs
16
src/expr.rs
|
@ -968,13 +968,15 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// for event in event
|
// for event in event
|
||||||
let between_kwd_cond = mk_sp(context.codemap.span_after(self.span, self.keyword.trim()),
|
let between_kwd_cond = mk_sp(
|
||||||
self.pat
|
context.codemap.span_after(self.span, self.keyword.trim()),
|
||||||
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
|
self.pat
|
||||||
p.span.lo
|
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
|
||||||
} else {
|
p.span.lo
|
||||||
context.codemap.span_before(self.span, self.matcher.trim())
|
} else {
|
||||||
}));
|
context.codemap.span_before(self.span, self.matcher.trim())
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
|
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
|
||||||
|
|
||||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -610,22 +610,24 @@ pub fn format_input<T: Write>(input: Input,
|
||||||
|
|
||||||
let mut report = FormatReport::new();
|
let mut report = FormatReport::new();
|
||||||
|
|
||||||
match format_ast(&krate,
|
match format_ast(
|
||||||
&parse_session,
|
&krate,
|
||||||
&main_file,
|
&parse_session,
|
||||||
config,
|
&main_file,
|
||||||
|file_name, file| {
|
config,
|
||||||
// For some reason, the codemap does not include terminating
|
|file_name, file| {
|
||||||
// newlines so we must add one on for each file. This is sad.
|
// For some reason, the codemap does not include terminating
|
||||||
filemap::append_newline(file);
|
// 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 {
|
if let Some(ref mut out) = out {
|
||||||
return filemap::write_file(file, file_name, out, config);
|
return filemap::write_file(file, file_name, out, config);
|
||||||
|
}
|
||||||
|
Ok(false)
|
||||||
}
|
}
|
||||||
Ok(false)
|
) {
|
||||||
}) {
|
|
||||||
Ok((file_map, has_diff)) => {
|
Ok((file_map, has_diff)) => {
|
||||||
if report.has_warnings() {
|
if report.has_warnings() {
|
||||||
summary.add_formatting_error();
|
summary.add_formatting_error();
|
||||||
|
|
|
@ -205,10 +205,10 @@ pub fn rewrite_macro(mac: &ast::Mac,
|
||||||
context
|
context
|
||||||
.codemap
|
.codemap
|
||||||
.span_after(mac.span, original_style.opener()),
|
.span_after(mac.span, original_style.opener()),
|
||||||
mac.span.hi - BytePos(1)
|
mac.span.hi - BytePos(1),
|
||||||
),
|
),
|
||||||
context,
|
context,
|
||||||
mac_shape
|
mac_shape,
|
||||||
));
|
));
|
||||||
|
|
||||||
Some(format!("{}{}", macro_name, rewrite))
|
Some(format!("{}{}", macro_name, rewrite))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue