mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Format source codes
This commit is contained in:
parent
b49269ad39
commit
dcc7f32152
30
src/items.rs
30
src/items.rs
@ -1161,21 +1161,23 @@ pub fn rewrite_type_alias(context: &RewriteContext,
|
||||
.unwrap_or(0);
|
||||
let type_indent = indent + line_width;
|
||||
// Try to fit the type on the same line
|
||||
let ty_str = try_opt!(ty.rewrite(context, Shape::legacy(budget, type_indent))
|
||||
.or_else(|| {
|
||||
// The line was too short, try to put the type on the next line
|
||||
let ty_str = try_opt!(
|
||||
ty.rewrite(context, Shape::legacy(budget, type_indent))
|
||||
.or_else(|| {
|
||||
// The line was too short, try to put the type on the next line
|
||||
|
||||
// Remove the space after '='
|
||||
result.pop();
|
||||
let type_indent = indent.block_indent(context.config);
|
||||
result.push('\n');
|
||||
result.push_str(&type_indent.to_string(context.config));
|
||||
let budget = try_opt!(context
|
||||
.config
|
||||
.max_width()
|
||||
.checked_sub(type_indent.width() + ";".len()));
|
||||
ty.rewrite(context, Shape::legacy(budget, type_indent))
|
||||
}));
|
||||
// Remove the space after '='
|
||||
result.pop();
|
||||
let type_indent = indent.block_indent(context.config);
|
||||
result.push('\n');
|
||||
result.push_str(&type_indent.to_string(context.config));
|
||||
let budget = try_opt!(context
|
||||
.config
|
||||
.max_width()
|
||||
.checked_sub(type_indent.width() + ";".len()));
|
||||
ty.rewrite(context, Shape::legacy(budget, type_indent))
|
||||
})
|
||||
);
|
||||
result.push_str(&ty_str);
|
||||
result.push_str(";");
|
||||
Some(result)
|
||||
|
51
src/types.rs
51
src/types.rs
@ -376,13 +376,15 @@ impl Rewrite for ast::WherePredicate {
|
||||
// 6 = "for<> ".len()
|
||||
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
|
||||
let budget = try_opt!(shape.width.checked_sub(used_width));
|
||||
let bounds_str: String = try_opt!(bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound
|
||||
.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>())
|
||||
let bounds_str: String = try_opt!(
|
||||
bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget, shape.indent + used_width))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()
|
||||
)
|
||||
.join(joiner);
|
||||
|
||||
if context.config.spaces_within_angle_brackets() && lifetime_str.len() > 0 {
|
||||
@ -401,13 +403,15 @@ impl Rewrite for ast::WherePredicate {
|
||||
};
|
||||
let used_width = type_str.len() + colon.len();
|
||||
let budget = try_opt!(shape.width.checked_sub(used_width));
|
||||
let bounds_str: String = try_opt!(bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound
|
||||
.rewrite(context, Shape::legacy(budget, shape.indent + used_width))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>())
|
||||
let bounds_str: String = try_opt!(
|
||||
bounds
|
||||
.iter()
|
||||
.map(|ty_bound| {
|
||||
ty_bound.rewrite(context,
|
||||
Shape::legacy(budget, shape.indent + used_width))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()
|
||||
)
|
||||
.join(joiner);
|
||||
|
||||
format!("{}{}{}", type_str, colon, bounds_str)
|
||||
@ -701,15 +705,16 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
|
||||
// 6 = "for<> ".len(), 4 = "for<".
|
||||
// This doesn't work out so nicely for mutliline situation with lots of
|
||||
// rightward drift. If that is a problem, we could use the list stuff.
|
||||
result.push_str(&try_opt!(bare_fn
|
||||
.lifetimes
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.rewrite(context,
|
||||
Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>())
|
||||
.join(", "));
|
||||
result.push_str(&try_opt!(
|
||||
bare_fn
|
||||
.lifetimes
|
||||
.iter()
|
||||
.map(|l| {
|
||||
l.rewrite(context,
|
||||
Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>()
|
||||
).join(", "));
|
||||
result.push_str("> ");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user