Skip to content

Commit fa4ef4d

Browse files
committed
Merge pull request #139 from nrc/todo-sorry
Don't apologise if its not our fault in warnings
2 parents e4a6f96 + f2bcee9 commit fa4ef4d

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

src/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ fn rewrite_binary_op(context: &RewriteContext,
315315

316316
// 1 = space between lhs expr and operator
317317
let mut result =
318-
try_opt!(lhs.rewrite(context, context.config.max_width - offset - 1 - operator_str.len(), offset));
318+
try_opt!(lhs.rewrite(context,
319+
context.config.max_width - offset - 1 - operator_str.len(),
320+
offset));
319321

320322
result.push(' ');
321323
result.push_str(&operator_str);

src/items.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ impl<'a> FmtVisitor<'a> {
467467

468468
// Make sure we do not exceed column limit
469469
// 4 = " = ,"
470-
assert!(self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4,
471-
"Enum variant exceeded column limit");
470+
assert!(
471+
self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4,
472+
"Enum variant exceeded column limit");
472473
}
473474

474475
result
@@ -768,7 +769,8 @@ impl<'a> FmtVisitor<'a> {
768769
}
769770
}
770771

771-
// TODO we farm this out, but this could spill over the column limit, so we ought to handle it properly
772+
// TODO we farm this out, but this could spill over the column limit, so we
773+
// ought to handle it properly.
772774
fn rewrite_fn_input(&self, arg: &ast::Arg) -> String {
773775
format!("{}: {}",
774776
pprust::pat_to_string(&arg.pat),

src/lib.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ impl fmt::Display for ErrorKind {
125125
match *self {
126126
ErrorKind::LineOverflow => {
127127
write!(fmt, "line exceeded maximum length")
128-
},
128+
}
129129
ErrorKind::TrailingWhitespace => {
130130
write!(fmt, "left behind trailing whitespace")
131-
},
131+
}
132132
ErrorKind::BadIssue(issue) => {
133133
write!(fmt, "found {}", issue)
134-
},
134+
}
135135
}
136136
}
137137
}
@@ -142,6 +142,24 @@ struct FormattingError {
142142
kind: ErrorKind,
143143
}
144144

145+
impl FormattingError {
146+
fn msg_prefix(&self) -> &str {
147+
match self.kind {
148+
ErrorKind::LineOverflow |
149+
ErrorKind::TrailingWhitespace => "Rustfmt failed at",
150+
ErrorKind::BadIssue(_) => "WARNING:",
151+
}
152+
}
153+
154+
fn msg_suffix(&self) -> &str {
155+
match self.kind {
156+
ErrorKind::LineOverflow |
157+
ErrorKind::TrailingWhitespace => "(sorry)",
158+
ErrorKind::BadIssue(_) => "",
159+
}
160+
}
161+
}
162+
145163
struct FormatReport {
146164
// Maps stringified file paths to their associated formatting errors
147165
file_error_map: HashMap<String, Vec<FormattingError>>,
@@ -153,10 +171,12 @@ impl fmt::Display for FormatReport {
153171
for (file, errors) in self.file_error_map.iter() {
154172
for error in errors {
155173
try!(write!(fmt,
156-
"Rustfmt failed at {}:{}: {} (sorry)\n",
174+
"{} {}:{}: {} {}\n",
175+
error.msg_prefix(),
157176
file,
158177
error.line,
159-
error.kind));
178+
error.kind,
179+
error.msg_suffix()));
160180
}
161181
}
162182
Ok(())

src/types.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,26 @@ impl<'a> FmtVisitor<'a> {
2525
..}) => {
2626
if bound_lifetimes.len() > 0 {
2727
format!("for<{}> {}: {}",
28-
bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::<Vec<_>>().connect(", "),
28+
bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l))
29+
.collect::<Vec<_>>().connect(", "),
2930
pprust::ty_to_string(bounded_ty),
30-
bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + "))
31+
bounds.iter().map(|b| self.rewrite_ty_bound(b))
32+
.collect::<Vec<_>>().connect(" + "))
3133

3234
} else {
3335
format!("{}: {}",
3436
pprust::ty_to_string(bounded_ty),
35-
bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + "))
37+
bounds.iter().map(|b| self.rewrite_ty_bound(b))
38+
.collect::<Vec<_>>().connect(" + "))
3639
}
3740
}
3841
&ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
3942
ref bounds,
4043
..}) => {
4144
format!("{}: {}",
4245
pprust::lifetime_to_string(lifetime),
43-
bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::<Vec<_>>().connect(" + "))
46+
bounds.iter().map(|l| pprust::lifetime_to_string(l))
47+
.collect::<Vec<_>>().connect(" + "))
4448
}
4549
&ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
4650
format!("{} = {}", pprust::path_to_string(path), pprust::ty_to_string(ty))
@@ -55,7 +59,8 @@ impl<'a> FmtVisitor<'a> {
5559

5660
format!("{}: {}",
5761
pprust::lifetime_to_string(&lifetime.lifetime),
58-
lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::<Vec<_>>().connect(" + "))
62+
lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l))
63+
.collect::<Vec<_>>().connect(" + "))
5964
}
6065

6166
pub fn rewrite_ty_bound(&self, bound: &ast::TyParamBound) -> String {
@@ -77,7 +82,8 @@ impl<'a> FmtVisitor<'a> {
7782
result.push_str(&token::get_ident(ty_param.ident));
7883
if ty_param.bounds.len() > 0 {
7984
result.push_str(": ");
80-
result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + "));
85+
result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b))
86+
.collect::<Vec<_>>().connect(" + "));
8187
}
8288
if let Some(ref def) = ty_param.default {
8389
result.push_str(" = ");
@@ -90,7 +96,8 @@ impl<'a> FmtVisitor<'a> {
9096
fn rewrite_poly_trait_ref(&self, t: &ast::PolyTraitRef) -> String {
9197
if t.bound_lifetimes.len() > 0 {
9298
format!("for<{}> {}",
93-
t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::<Vec<_>>().connect(", "),
99+
t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l))
100+
.collect::<Vec<_>>().connect(", "),
94101
pprust::path_to_string(&t.trait_ref.path))
95102

96103
} else {

src/visitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ impl<'a> FmtVisitor<'a> {
380380
}
381381
Some(open_brace) => {
382382
debug!("FmtVisitor::format_mod: internal mod");
383-
debug!("... open_brace: {}, str: {:?}", open_brace, self.codemap.span_to_snippet(s));
383+
debug!("... open_brace: {}, str: {:?}",
384+
open_brace,
385+
self.codemap.span_to_snippet(s));
384386
// Format everything until opening brace
385387
// TODO Shoud rewrite properly
386388
self.format_missing(s.lo + BytePos(open_brace as u32));

0 commit comments

Comments
 (0)