diff --git a/src/expr.rs b/src/expr.rs index 33a82da0f29f..7110d508d5d2 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -315,7 +315,9 @@ fn rewrite_binary_op(context: &RewriteContext, // 1 = space between lhs expr and operator let mut result = - try_opt!(lhs.rewrite(context, context.config.max_width - offset - 1 - operator_str.len(), offset)); + try_opt!(lhs.rewrite(context, + context.config.max_width - offset - 1 - operator_str.len(), + offset)); result.push(' '); result.push_str(&operator_str); diff --git a/src/items.rs b/src/items.rs index 0f7f44f8d99a..4b473dff4baa 100644 --- a/src/items.rs +++ b/src/items.rs @@ -467,8 +467,9 @@ impl<'a> FmtVisitor<'a> { // Make sure we do not exceed column limit // 4 = " = ," - assert!(self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4, - "Enum variant exceeded column limit"); + assert!( + self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4, + "Enum variant exceeded column limit"); } result @@ -768,7 +769,8 @@ impl<'a> FmtVisitor<'a> { } } - // TODO we farm this out, but this could spill over the column limit, so we ought to handle it properly + // TODO we farm this out, but this could spill over the column limit, so we + // ought to handle it properly. fn rewrite_fn_input(&self, arg: &ast::Arg) -> String { format!("{}: {}", pprust::pat_to_string(&arg.pat), diff --git a/src/lib.rs b/src/lib.rs index 252b3ad05b71..c296b3cda000 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -125,13 +125,13 @@ impl fmt::Display for ErrorKind { match *self { ErrorKind::LineOverflow => { write!(fmt, "line exceeded maximum length") - }, + } ErrorKind::TrailingWhitespace => { write!(fmt, "left behind trailing whitespace") - }, + } ErrorKind::BadIssue(issue) => { write!(fmt, "found {}", issue) - }, + } } } } @@ -142,6 +142,24 @@ struct FormattingError { kind: ErrorKind, } +impl FormattingError { + fn msg_prefix(&self) -> &str { + match self.kind { + ErrorKind::LineOverflow | + ErrorKind::TrailingWhitespace => "Rustfmt failed at", + ErrorKind::BadIssue(_) => "WARNING:", + } + } + + fn msg_suffix(&self) -> &str { + match self.kind { + ErrorKind::LineOverflow | + ErrorKind::TrailingWhitespace => "(sorry)", + ErrorKind::BadIssue(_) => "", + } + } +} + struct FormatReport { // Maps stringified file paths to their associated formatting errors file_error_map: HashMap>, @@ -153,10 +171,12 @@ impl fmt::Display for FormatReport { for (file, errors) in self.file_error_map.iter() { for error in errors { try!(write!(fmt, - "Rustfmt failed at {}:{}: {} (sorry)\n", + "{} {}:{}: {} {}\n", + error.msg_prefix(), file, error.line, - error.kind)); + error.kind, + error.msg_suffix())); } } Ok(()) diff --git a/src/types.rs b/src/types.rs index 6880cd8bcc2f..3ac82ae27ee1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -25,14 +25,17 @@ impl<'a> FmtVisitor<'a> { ..}) => { if bound_lifetimes.len() > 0 { format!("for<{}> {}: {}", - bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::>().connect(", "), + bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)) + .collect::>().connect(", "), pprust::ty_to_string(bounded_ty), - bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::>().connect(" + ")) + bounds.iter().map(|b| self.rewrite_ty_bound(b)) + .collect::>().connect(" + ")) } else { format!("{}: {}", pprust::ty_to_string(bounded_ty), - bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::>().connect(" + ")) + bounds.iter().map(|b| self.rewrite_ty_bound(b)) + .collect::>().connect(" + ")) } } &ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, @@ -40,7 +43,8 @@ impl<'a> FmtVisitor<'a> { ..}) => { format!("{}: {}", pprust::lifetime_to_string(lifetime), - bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::>().connect(" + ")) + bounds.iter().map(|l| pprust::lifetime_to_string(l)) + .collect::>().connect(" + ")) } &ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { format!("{} = {}", pprust::path_to_string(path), pprust::ty_to_string(ty)) @@ -55,7 +59,8 @@ impl<'a> FmtVisitor<'a> { format!("{}: {}", pprust::lifetime_to_string(&lifetime.lifetime), - lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::>().connect(" + ")) + lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l)) + .collect::>().connect(" + ")) } pub fn rewrite_ty_bound(&self, bound: &ast::TyParamBound) -> String { @@ -77,7 +82,8 @@ impl<'a> FmtVisitor<'a> { result.push_str(&token::get_ident(ty_param.ident)); if ty_param.bounds.len() > 0 { result.push_str(": "); - result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::>().connect(" + ")); + result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b)) + .collect::>().connect(" + ")); } if let Some(ref def) = ty_param.default { result.push_str(" = "); @@ -90,7 +96,8 @@ impl<'a> FmtVisitor<'a> { fn rewrite_poly_trait_ref(&self, t: &ast::PolyTraitRef) -> String { if t.bound_lifetimes.len() > 0 { format!("for<{}> {}", - t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::>().connect(", "), + t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)) + .collect::>().connect(", "), pprust::path_to_string(&t.trait_ref.path)) } else { diff --git a/src/visitor.rs b/src/visitor.rs index 1b1fd9d17c64..eb3c4be80f76 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -380,7 +380,9 @@ impl<'a> FmtVisitor<'a> { } Some(open_brace) => { debug!("FmtVisitor::format_mod: internal mod"); - debug!("... open_brace: {}, str: {:?}", open_brace, self.codemap.span_to_snippet(s)); + debug!("... open_brace: {}, str: {:?}", + open_brace, + self.codemap.span_to_snippet(s)); // Format everything until opening brace // TODO Shoud rewrite properly self.format_missing(s.lo + BytePos(open_brace as u32));