1
Fork 0

Tidy up some overrunning lines

This commit is contained in:
Nick Cameron 2015-07-16 14:23:48 +12:00
commit f2bcee9d87
4 changed files with 25 additions and 12 deletions

View file

@ -315,7 +315,9 @@ fn rewrite_binary_op(context: &RewriteContext,
// 1 = space between lhs expr and operator // 1 = space between lhs expr and operator
let mut result = 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(' ');
result.push_str(&operator_str); result.push_str(&operator_str);

View file

@ -467,8 +467,9 @@ impl<'a> FmtVisitor<'a> {
// Make sure we do not exceed column limit // Make sure we do not exceed column limit
// 4 = " = ," // 4 = " = ,"
assert!(self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4, assert!(
"Enum variant exceeded column limit"); self.config.max_width >= vis.len() + name.len() + expr_snippet.len() + 4,
"Enum variant exceeded column limit");
} }
result 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 { fn rewrite_fn_input(&self, arg: &ast::Arg) -> String {
format!("{}: {}", format!("{}: {}",
pprust::pat_to_string(&arg.pat), pprust::pat_to_string(&arg.pat),

View file

@ -25,14 +25,17 @@ impl<'a> FmtVisitor<'a> {
..}) => { ..}) => {
if bound_lifetimes.len() > 0 { if bound_lifetimes.len() > 0 {
format!("for<{}> {}: {}", format!("for<{}> {}: {}",
bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::<Vec<_>>().connect(", "), bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l))
.collect::<Vec<_>>().connect(", "),
pprust::ty_to_string(bounded_ty), pprust::ty_to_string(bounded_ty),
bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + ")) bounds.iter().map(|b| self.rewrite_ty_bound(b))
.collect::<Vec<_>>().connect(" + "))
} else { } else {
format!("{}: {}", format!("{}: {}",
pprust::ty_to_string(bounded_ty), pprust::ty_to_string(bounded_ty),
bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + ")) bounds.iter().map(|b| self.rewrite_ty_bound(b))
.collect::<Vec<_>>().connect(" + "))
} }
} }
&ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime, &ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate{ref lifetime,
@ -40,7 +43,8 @@ impl<'a> FmtVisitor<'a> {
..}) => { ..}) => {
format!("{}: {}", format!("{}: {}",
pprust::lifetime_to_string(lifetime), pprust::lifetime_to_string(lifetime),
bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::<Vec<_>>().connect(" + ")) bounds.iter().map(|l| pprust::lifetime_to_string(l))
.collect::<Vec<_>>().connect(" + "))
} }
&ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => { &ast::WherePredicate::EqPredicate(ast::WhereEqPredicate{ref path, ref ty, ..}) => {
format!("{} = {}", pprust::path_to_string(path), pprust::ty_to_string(ty)) format!("{} = {}", pprust::path_to_string(path), pprust::ty_to_string(ty))
@ -55,7 +59,8 @@ impl<'a> FmtVisitor<'a> {
format!("{}: {}", format!("{}: {}",
pprust::lifetime_to_string(&lifetime.lifetime), pprust::lifetime_to_string(&lifetime.lifetime),
lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l)).collect::<Vec<_>>().connect(" + ")) lifetime.bounds.iter().map(|l| pprust::lifetime_to_string(l))
.collect::<Vec<_>>().connect(" + "))
} }
pub fn rewrite_ty_bound(&self, bound: &ast::TyParamBound) -> String { 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)); result.push_str(&token::get_ident(ty_param.ident));
if ty_param.bounds.len() > 0 { if ty_param.bounds.len() > 0 {
result.push_str(": "); result.push_str(": ");
result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b)).collect::<Vec<_>>().connect(" + ")); result.push_str(&ty_param.bounds.iter().map(|b| self.rewrite_ty_bound(b))
.collect::<Vec<_>>().connect(" + "));
} }
if let Some(ref def) = ty_param.default { if let Some(ref def) = ty_param.default {
result.push_str(" = "); result.push_str(" = ");
@ -90,7 +96,8 @@ impl<'a> FmtVisitor<'a> {
fn rewrite_poly_trait_ref(&self, t: &ast::PolyTraitRef) -> String { fn rewrite_poly_trait_ref(&self, t: &ast::PolyTraitRef) -> String {
if t.bound_lifetimes.len() > 0 { if t.bound_lifetimes.len() > 0 {
format!("for<{}> {}", format!("for<{}> {}",
t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l)).collect::<Vec<_>>().connect(", "), t.bound_lifetimes.iter().map(|l| self.rewrite_lifetime_def(l))
.collect::<Vec<_>>().connect(", "),
pprust::path_to_string(&t.trait_ref.path)) pprust::path_to_string(&t.trait_ref.path))
} else { } else {

View file

@ -380,7 +380,9 @@ impl<'a> FmtVisitor<'a> {
} }
Some(open_brace) => { Some(open_brace) => {
debug!("FmtVisitor::format_mod: internal mod"); 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 // Format everything until opening brace
// TODO Shoud rewrite properly // TODO Shoud rewrite properly
self.format_missing(s.lo + BytePos(open_brace as u32)); self.format_missing(s.lo + BytePos(open_brace as u32));