Fixup formatting of tests and source
This commit is contained in:
parent
a4cdb68925
commit
486f8fd8e7
@ -194,7 +194,8 @@ fn has_newlines_before_after_comment(comment: &str) -> (&str, &str) {
|
||||
.rev()
|
||||
.take_while(|c| c.is_whitespace())
|
||||
.filter(|&c| c == '\n')
|
||||
.count() > 1
|
||||
.count()
|
||||
> 1
|
||||
};
|
||||
(if mlb { "\n" } else { "" }, if mla { "\n" } else { "" })
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ fn main() {
|
||||
|
||||
let exit_code = match execute(&opts) {
|
||||
Ok((exit_mode, summary)) => {
|
||||
if summary.has_operational_errors() || summary.has_parsing_errors()
|
||||
if summary.has_operational_errors()
|
||||
|| summary.has_parsing_errors()
|
||||
|| ((summary.has_diff || summary.has_check_errors())
|
||||
&& exit_mode == ExitCodeMode::Check)
|
||||
{
|
||||
|
@ -363,7 +363,8 @@ where
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.count() > 1
|
||||
.count()
|
||||
> 1
|
||||
}
|
||||
|
||||
fn is_block_closure_forced(context: &RewriteContext, expr: &ast::Expr) -> bool {
|
||||
|
12
src/expr.rs
12
src/expr.rs
@ -863,16 +863,16 @@ impl<'a> ControlFlow<'a> {
|
||||
&& context
|
||||
.config
|
||||
.width_heuristics()
|
||||
.single_line_if_else_max_width > 0
|
||||
.single_line_if_else_max_width
|
||||
> 0
|
||||
{
|
||||
let trial = self.rewrite_single_line(&pat_expr_string, context, shape.width);
|
||||
|
||||
if let Some(cond_str) = trial {
|
||||
if cond_str.len()
|
||||
<= context
|
||||
.config
|
||||
.width_heuristics()
|
||||
.single_line_if_else_max_width
|
||||
if cond_str.len() <= context
|
||||
.config
|
||||
.width_heuristics()
|
||||
.single_line_if_else_max_width
|
||||
{
|
||||
return Some((cond_str, 0));
|
||||
}
|
||||
|
@ -1382,7 +1382,8 @@ fn format_tuple_struct(
|
||||
)?;
|
||||
}
|
||||
|
||||
if !where_clause_str.is_empty() && !where_clause_str.contains('\n')
|
||||
if !where_clause_str.is_empty()
|
||||
&& !where_clause_str.contains('\n')
|
||||
&& (result.contains('\n')
|
||||
|| offset.block_indent + result.len() + where_clause_str.len() + 1
|
||||
> context.config.max_width())
|
||||
@ -2527,7 +2528,8 @@ fn rewrite_where_clause_rfc_style(
|
||||
&& comment_before.is_empty()
|
||||
&& comment_after.is_empty()
|
||||
&& !preds_str.contains('\n')
|
||||
&& 6 + preds_str.len() <= shape.width || where_single_line
|
||||
&& 6 + preds_str.len() <= shape.width
|
||||
|| where_single_line
|
||||
{
|
||||
Cow::from(" ")
|
||||
} else {
|
||||
@ -2737,7 +2739,8 @@ fn format_generics(
|
||||
false,
|
||||
)?;
|
||||
result.push_str(&where_clause_str);
|
||||
brace_pos == BracePos::ForceSameLine || brace_style == BraceStyle::PreferSameLine
|
||||
brace_pos == BracePos::ForceSameLine
|
||||
|| brace_style == BraceStyle::PreferSameLine
|
||||
|| (generics.where_clause.predicates.is_empty()
|
||||
&& trimmed_last_line_width(&result) == 1)
|
||||
} else {
|
||||
|
@ -97,11 +97,10 @@ impl ListItem {
|
||||
}
|
||||
|
||||
pub fn is_different_group(&self) -> bool {
|
||||
self.inner_as_ref().contains('\n') || self.pre_comment.is_some()
|
||||
|| self
|
||||
.post_comment
|
||||
.as_ref()
|
||||
.map_or(false, |s| s.contains('\n'))
|
||||
self.inner_as_ref().contains('\n') || self.pre_comment.is_some() || self
|
||||
.post_comment
|
||||
.as_ref()
|
||||
.map_or(false, |s| s.contains('\n'))
|
||||
}
|
||||
|
||||
pub fn is_multiline(&self) -> bool {
|
||||
|
@ -1107,23 +1107,22 @@ fn indent_macro_snippet(
|
||||
.min()?;
|
||||
|
||||
Some(
|
||||
first_line + "\n"
|
||||
+ &trimmed_lines
|
||||
.iter()
|
||||
.map(
|
||||
|&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
|
||||
_ if !trimmed => line.to_owned(),
|
||||
Some(original_indent_width) => {
|
||||
let new_indent_width = indent.width()
|
||||
+ original_indent_width.saturating_sub(min_prefix_space_width);
|
||||
let new_indent = Indent::from_width(context.config, new_indent_width);
|
||||
format!("{}{}", new_indent.to_string(context.config), line.trim())
|
||||
}
|
||||
None => String::new(),
|
||||
},
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
first_line + "\n" + &trimmed_lines
|
||||
.iter()
|
||||
.map(
|
||||
|&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
|
||||
_ if !trimmed => line.to_owned(),
|
||||
Some(original_indent_width) => {
|
||||
let new_indent_width = indent.width() + original_indent_width
|
||||
.saturating_sub(min_prefix_space_width);
|
||||
let new_indent = Indent::from_width(context.config, new_indent_width);
|
||||
format!("{}{}", new_indent.to_string(context.config), line.trim())
|
||||
}
|
||||
None => String::new(),
|
||||
},
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -320,15 +320,13 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
|
||||
ListTactic::HorizontalVertical,
|
||||
Separator::Comma,
|
||||
self.nested_shape.width,
|
||||
)
|
||||
== DefinitiveListTactic::Horizontal
|
||||
) == DefinitiveListTactic::Horizontal
|
||||
&& definitive_tactic(
|
||||
&list_items[num_args_before + 1..],
|
||||
ListTactic::HorizontalVertical,
|
||||
Separator::Comma,
|
||||
self.nested_shape.width,
|
||||
)
|
||||
== DefinitiveListTactic::Horizontal;
|
||||
) == DefinitiveListTactic::Horizontal;
|
||||
|
||||
if one_line {
|
||||
tactic = DefinitiveListTactic::SpecialMacro(num_args_before);
|
||||
|
@ -242,12 +242,13 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||
let item_length = items
|
||||
.iter()
|
||||
.take_while(|ppi| {
|
||||
item_kind.is_same_item_kind(&***ppi) && (!in_group || {
|
||||
let current = self.codemap.lookup_line_range(ppi.span());
|
||||
let in_same_group = current.lo < last.hi + 2;
|
||||
last = current;
|
||||
in_same_group
|
||||
})
|
||||
item_kind.is_same_item_kind(&***ppi)
|
||||
&& (!in_group || {
|
||||
let current = self.codemap.lookup_line_range(ppi.span());
|
||||
let in_same_group = current.lo < last.hi + 2;
|
||||
last = current;
|
||||
in_same_group
|
||||
})
|
||||
})
|
||||
.count();
|
||||
let items = &items[..item_length];
|
||||
|
@ -72,7 +72,8 @@ pub fn rewrite_string<'a>(
|
||||
// succeed.
|
||||
let mut max_chars = shape
|
||||
.width
|
||||
.checked_sub(fmt.opener.len() + ender_length + 1)? + 1;
|
||||
.checked_sub(fmt.opener.len() + ender_length + 1)?
|
||||
+ 1;
|
||||
|
||||
// Snip a line at a time from `orig` until it is used up. Push the snippet
|
||||
// onto result.
|
||||
|
@ -703,7 +703,8 @@ impl ConfigCodeBlock {
|
||||
.unwrap()
|
||||
.split('\n')
|
||||
.nth(0)
|
||||
.unwrap_or("") == "#![rustfmt::skip]";
|
||||
.unwrap_or("")
|
||||
== "#![rustfmt::skip]";
|
||||
|
||||
if self.config_name.is_none() && !fmt_skip {
|
||||
write_message(&format!(
|
||||
|
@ -295,11 +295,10 @@ pub fn mk_sp(lo: BytePos, hi: BytePos) -> Span {
|
||||
// Return true if the given span does not intersect with file lines.
|
||||
macro_rules! out_of_file_lines_range {
|
||||
($self:ident, $span:expr) => {
|
||||
!$self.config.file_lines().is_all()
|
||||
&& !$self
|
||||
.config
|
||||
.file_lines()
|
||||
.intersects(&$self.codemap.lookup_line_range($span))
|
||||
!$self.config.file_lines().is_all() && !$self
|
||||
.config
|
||||
.file_lines()
|
||||
.intersects(&$self.codemap.lookup_line_range($span))
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -173,11 +173,14 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
|
||||
let rest_span = mk_sp(init_last_pos, span.hi());
|
||||
let rest_str = rewrite_with_alignment(rest, context, shape, rest_span, one_line_width)?;
|
||||
Some(
|
||||
result + spaces + "\n"
|
||||
result
|
||||
+ spaces
|
||||
+ "\n"
|
||||
+ &shape
|
||||
.indent
|
||||
.block_indent(context.config)
|
||||
.to_string(context.config) + &rest_str,
|
||||
.to_string(context.config)
|
||||
+ &rest_str,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -14,15 +14,15 @@ fn foo() -> bool {
|
||||
self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner);
|
||||
|
||||
let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb
|
||||
/ (bbbbbb - function_call(x, *very_long_pointer, y)) + 1000;
|
||||
/ (bbbbbb - function_call(x, *very_long_pointer, y))
|
||||
+ 1000;
|
||||
|
||||
some_ridiculously_loooooooooooooooooooooong_function(
|
||||
10000 * 30000000000 + 40000 / 1002200000000 - 50000 * sqrt(-1),
|
||||
trivial_value,
|
||||
);
|
||||
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ a
|
||||
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ a + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
+ aaaaa);
|
||||
|
||||
{
|
||||
@ -358,7 +358,8 @@ fn issue1749() {
|
||||
{
|
||||
{
|
||||
if self.shape[(r as f32 + self.x_offset) as usize]
|
||||
[(c as f32 + self.y_offset) as usize] != 0
|
||||
[(c as f32 + self.y_offset) as usize]
|
||||
!= 0
|
||||
{
|
||||
// hello
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user