1
Fork 0

Merge pull request #664 from marcusklaas/fix-reformat-failurez

Don't include failed item rewrites in missed spans
This commit is contained in:
Nick Cameron 2015-12-07 08:33:02 +13:00
commit db72e0390c
3 changed files with 11 additions and 6 deletions

View file

@ -191,6 +191,7 @@ impl<'a> FmtVisitor<'a> {
} }
_ => { _ => {
if self.visit_attrs(&item.attrs) { if self.visit_attrs(&item.attrs) {
self.push_rewrite(item.span, None);
return; return;
} }
} }
@ -377,11 +378,9 @@ impl<'a> FmtVisitor<'a> {
fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) { fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
self.format_missing_with_indent(span.lo); self.format_missing_with_indent(span.lo);
let result = rewrite.unwrap_or_else(|| self.snippet(span));
if let Some(res) = rewrite { self.buffer.push_str(&result);
self.buffer.push_str(&res); self.last_pos = span.hi;
self.last_pos = span.hi;
}
} }
pub fn from_codemap(parse_session: &'a ParseSess, pub fn from_codemap(parse_session: &'a ParseSess,

View file

@ -85,3 +85,9 @@ fn inner() {
#![inline] #![inline]
x x
} }
#[cfg_attr(rustfmt, rustfmt_skip)]
fn foo(a: i32) -> i32 {
// comment
if a > 0 { 1 } else { 2 }
}