Format source codes
This commit is contained in:
parent
c06d487712
commit
b8f11a4e3c
14 changed files with 79 additions and 78 deletions
|
@ -319,8 +319,8 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> &'a str {
|
||||||
} else {
|
} else {
|
||||||
&line[opener.trim_right().len()..]
|
&line[opener.trim_right().len()..]
|
||||||
}
|
}
|
||||||
} else if line.starts_with("/* ") || line.starts_with("// ") ||
|
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") ||
|
||||||
line.starts_with("//!") || line.starts_with("///") ||
|
line.starts_with("///") ||
|
||||||
line.starts_with("** ") || line.starts_with("/*!") ||
|
line.starts_with("** ") || line.starts_with("/*!") ||
|
||||||
(line.starts_with("/**") && !line.starts_with("/**/"))
|
(line.starts_with("/**") && !line.starts_with("/**/"))
|
||||||
{
|
{
|
||||||
|
|
30
src/expr.rs
30
src/expr.rs
|
@ -729,9 +729,10 @@ fn and_one_line(x: Option<String>) -> Option<String> {
|
||||||
|
|
||||||
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
|
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
|
||||||
debug!("nop_block_collapse {:?} {}", block_str, budget);
|
debug!("nop_block_collapse {:?} {}", block_str, budget);
|
||||||
block_str.map(|block_str| if block_str.starts_with('{') &&
|
block_str.map(|block_str| if block_str.starts_with('{') && budget >= 2 &&
|
||||||
budget >= 2 &&
|
(block_str[1..]
|
||||||
(block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2)
|
.find(|c: char| !c.is_whitespace())
|
||||||
|
.unwrap() == block_str.len() - 2)
|
||||||
{
|
{
|
||||||
"{}".to_owned()
|
"{}".to_owned()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1509,8 +1510,8 @@ impl Rewrite for ast::Arm {
|
||||||
let pats_str = format!("{}{}", pats_str, guard_str);
|
let pats_str = format!("{}{}", pats_str, guard_str);
|
||||||
|
|
||||||
let (mut extend, body) = match body.node {
|
let (mut extend, body) = match body.node {
|
||||||
ast::ExprKind::Block(ref block) if !is_unsafe_block(block) &&
|
ast::ExprKind::Block(ref block)
|
||||||
is_simple_block(block, context.codemap) &&
|
if !is_unsafe_block(block) && is_simple_block(block, context.codemap) &&
|
||||||
context.config.wrap_match_arms() => {
|
context.config.wrap_match_arms() => {
|
||||||
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
|
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
|
||||||
(false, &**expr)
|
(false, &**expr)
|
||||||
|
@ -2539,21 +2540,10 @@ pub fn rewrite_assign_rhs<S: Into<String>>(
|
||||||
|
|
||||||
// FIXME: DRY!
|
// FIXME: DRY!
|
||||||
match (rhs, new_rhs) {
|
match (rhs, new_rhs) {
|
||||||
(Some(ref orig_rhs), Some(ref replacement_rhs)) if count_line_breaks(
|
(Some(ref orig_rhs), Some(ref replacement_rhs))
|
||||||
orig_rhs,
|
if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 ||
|
||||||
) >
|
(orig_rhs.rewrite(context, shape).is_none() &&
|
||||||
count_line_breaks(
|
replacement_rhs.rewrite(context, new_shape).is_some()) => {
|
||||||
replacement_rhs,
|
|
||||||
) + 1 ||
|
|
||||||
(orig_rhs
|
|
||||||
.rewrite(context, shape)
|
|
||||||
.is_none() &&
|
|
||||||
replacement_rhs
|
|
||||||
.rewrite(
|
|
||||||
context,
|
|
||||||
new_shape,
|
|
||||||
)
|
|
||||||
.is_some()) => {
|
|
||||||
result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
|
result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
|
||||||
result.push_str(replacement_rhs);
|
result.push_str(replacement_rhs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1468,9 +1468,9 @@ impl Rewrite for ast::StructField {
|
||||||
Some(ref ty) if ty.contains('\n') => {
|
Some(ref ty) if ty.contains('\n') => {
|
||||||
let new_ty = rewrite_type_in_next_line();
|
let new_ty = rewrite_type_in_next_line();
|
||||||
match new_ty {
|
match new_ty {
|
||||||
Some(ref new_ty) if !new_ty.contains('\n') &&
|
Some(ref new_ty)
|
||||||
new_ty.len() + type_offset.width() <=
|
if !new_ty.contains('\n') &&
|
||||||
context.config.max_width() => {
|
new_ty.len() + type_offset.width() <= context.config.max_width() => {
|
||||||
Some(format!(
|
Some(format!(
|
||||||
"{}\n{}{}",
|
"{}\n{}{}",
|
||||||
result,
|
result,
|
||||||
|
@ -2688,7 +2688,8 @@ fn format_generics(
|
||||||
let same_line_brace = force_same_line_brace ||
|
let same_line_brace = force_same_line_brace ||
|
||||||
(generics.where_clause.predicates.is_empty() && trimmed_last_line_width(&result) == 1);
|
(generics.where_clause.predicates.is_empty() && trimmed_last_line_width(&result) == 1);
|
||||||
if !same_line_brace &&
|
if !same_line_brace &&
|
||||||
(brace_style == BraceStyle::SameLineWhere || brace_style == BraceStyle::AlwaysNextLine)
|
(brace_style == BraceStyle::SameLineWhere ||
|
||||||
|
brace_style == BraceStyle::AlwaysNextLine)
|
||||||
{
|
{
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
result.push_str(&offset.block_only().to_string(context.config));
|
result.push_str(&offset.block_only().to_string(context.config));
|
||||||
|
|
|
@ -206,8 +206,8 @@ fn rewrite_segment(
|
||||||
|
|
||||||
let params = if let Some(ref params) = segment.parameters {
|
let params = if let Some(ref params) = segment.parameters {
|
||||||
match **params {
|
match **params {
|
||||||
ast::PathParameters::AngleBracketed(ref data) if !data.lifetimes.is_empty() ||
|
ast::PathParameters::AngleBracketed(ref data)
|
||||||
!data.types.is_empty() ||
|
if !data.lifetimes.is_empty() || !data.types.is_empty() ||
|
||||||
!data.bindings.is_empty() => {
|
!data.bindings.is_empty() => {
|
||||||
let param_list = data.lifetimes
|
let param_list = data.lifetimes
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -546,7 +546,8 @@ 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(source!(self, span).lo);
|
self.format_missing_with_indent(source!(self, span).lo);
|
||||||
self.failed = match rewrite {
|
self.failed = match rewrite {
|
||||||
Some(ref s) if s.rewrite(
|
Some(ref s)
|
||||||
|
if s.rewrite(
|
||||||
&self.get_context(),
|
&self.get_context(),
|
||||||
Shape::indented(self.block_indent, self.config),
|
Shape::indented(self.block_indent, self.config),
|
||||||
).is_none() => true,
|
).is_none() => true,
|
||||||
|
|
|
@ -7,8 +7,8 @@ fn foo() -> bool {
|
||||||
let referenced = &5;
|
let referenced = &5;
|
||||||
|
|
||||||
let very_long_variable_name = (a + first + simple + test);
|
let very_long_variable_name = (a + first + simple + test);
|
||||||
let very_long_variable_name =
|
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA +
|
||||||
(a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c);
|
BBBBBBBBBBBBBBBBB + b + c);
|
||||||
|
|
||||||
let is_internalxxxx = self.codemap.span_to_filename(s) ==
|
let is_internalxxxx = self.codemap.span_to_filename(s) ==
|
||||||
self.codemap.span_to_filename(m.inner);
|
self.codemap.span_to_filename(m.inner);
|
||||||
|
@ -20,8 +20,10 @@ fn foo() -> bool {
|
||||||
10000 * 30000000000 + 40000 / 1002200000000 - 50000 * sqrt(-1),
|
10000 * 30000000000 + 40000 / 1002200000000 - 50000 * sqrt(-1),
|
||||||
trivial_value,
|
trivial_value,
|
||||||
);
|
);
|
||||||
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + a +
|
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaa))))))))) ;
|
a +
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
|
||||||
|
aaaaa)))))))));
|
||||||
|
|
||||||
{
|
{
|
||||||
for _ in 0..10 {}
|
for _ in 0..10 {}
|
||||||
|
|
|
@ -96,7 +96,12 @@ fn foo<g: G>() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo<L: Loooooooooooooooooooooong, G: Geeeeeeeeeeeneric, I: iiiiiiiiis, L: Looooooooooooooooong>() {
|
fn foo<
|
||||||
|
L: Loooooooooooooooooooooong,
|
||||||
|
G: Geeeeeeeeeeeneric,
|
||||||
|
I: iiiiiiiiis,
|
||||||
|
L: Looooooooooooooooong,
|
||||||
|
>() {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,13 +67,18 @@ fn main() {
|
||||||
vec![a, b; c];
|
vec![a, b; c];
|
||||||
vec![a; b, c];
|
vec![a; b, c];
|
||||||
|
|
||||||
vec![a;
|
vec![
|
||||||
|
a;
|
||||||
(|x| {
|
(|x| {
|
||||||
let y = x + 1;
|
let y = x + 1;
|
||||||
let z = y + 1;
|
let z = y + 1;
|
||||||
z
|
z
|
||||||
})(2)];
|
})(2)
|
||||||
vec![a; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx];
|
];
|
||||||
|
vec![
|
||||||
|
a;
|
||||||
|
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
];
|
||||||
vec![a; unsafe { x + 1 }];
|
vec![a; unsafe { x + 1 }];
|
||||||
|
|
||||||
unknown_bracket_macro__comma_should_not_be_stripped![
|
unknown_bracket_macro__comma_should_not_be_stripped![
|
||||||
|
|
|
@ -37,10 +37,8 @@ fn foo() {
|
||||||
Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
|
Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() >
|
ast::PathParameters::AngleBracketedParameters(ref data)
|
||||||
0 ||
|
if data.lifetimes.len() > 0 || data.types.len() > 0 || data.bindings.len() > 0 => {}
|
||||||
data.types.len() > 0 ||
|
|
||||||
data.bindings.len() > 0 => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let whatever = match something {
|
let whatever = match something {
|
||||||
|
@ -316,16 +314,15 @@ fn issue386() {
|
||||||
|
|
||||||
fn guards() {
|
fn guards() {
|
||||||
match foo {
|
match foo {
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
barrrrrrrrrrrr => {}
|
if foooooooooooooo && barrrrrrrrrrrr => {}
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
barrrrrrrrrrrr => {}
|
if foooooooooooooo && barrrrrrrrrrrr => {}
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
if fooooooooooooooooooooo &&
|
if fooooooooooooooooooooo &&
|
||||||
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {
|
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
|
||||||
{}
|
cccccccccccccccccccccccccccccccccccccccc) => {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue