Don't apply the function args heuristic to tuple lits.

Closes #450
Closes #510
This commit is contained in:
Nick Cameron 2016-03-14 20:51:06 +13:00
parent 204e732c1b
commit 9d8ce54428
10 changed files with 46 additions and 81 deletions

View File

@ -236,8 +236,7 @@ fn rewrite_method_call(method_name: ast::Ident,
.map(|ty| ty.rewrite(context, width, offset))
.collect());
(types.last().unwrap().span.hi,
format!("::<{}>", type_list.join(", ")))
(types.last().unwrap().span.hi, format!("::<{}>", type_list.join(", ")))
};
let callee_str = format!(".{}{}", method_name, type_str);

View File

@ -501,9 +501,7 @@ fn next(&mut self) -> Option<Self::Item> {
CodeCharKind::Comment => CodeCharKind::Normal,
CodeCharKind::Normal => CodeCharKind::Comment,
};
let res = (kind,
self.last_slice_end,
&self.slice[self.last_slice_end..sub_slice_end]);
let res = (kind, self.last_slice_end, &self.slice[self.last_slice_end..sub_slice_end]);
self.last_slice_end = sub_slice_end;
self.last_slice_kind = kind;

View File

@ -18,7 +18,7 @@
use {Indent, Spanned};
use rewrite::{Rewrite, RewriteContext};
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic,
DefinitiveListTactic, definitive_tactic, ListItem, format_fn_args};
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list};
use string::{StringFormat, rewrite_string};
use utils::{CodeMapSpanUtils, extra_offset, last_line_width, wrap_str, binary_search,
first_line_width, semicolon_for_stmt};
@ -1336,9 +1336,7 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
// Replace the stub with the full overflowing last argument if the rewrite
// succeeded and its first line fits with the other arguments.
match (overflow_last, tactic, placeholder) {
(true,
DefinitiveListTactic::Horizontal,
placeholder @ Some(..)) => {
(true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
item_vec[arg_count - 1].item = placeholder;
}
(true, _, _) => {
@ -1511,8 +1509,7 @@ enum StructLitField<'a> {
outer_indent))
};
match (context.config.struct_lit_style,
context.config.struct_lit_multiline_style) {
match (context.config.struct_lit_style, context.config.struct_lit_multiline_style) {
(StructLitStyle::Block, _) if fields_str.contains('\n') || fields_str.len() > h_budget => {
format_on_newline()
}
@ -1583,7 +1580,7 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
list_lo,
span.hi - BytePos(1));
let budget = try_opt!(width.checked_sub(2));
let list_str = try_opt!(format_fn_args(items, budget, indent, context.config));
let list_str = try_opt!(format_item_list(items, budget, indent, context.config));
Some(format!("({})", list_str))
}

View File

@ -1401,9 +1401,7 @@ fn compute_budgets_for_args(context: &RewriteContext,
let multi_line_budget = context.config.max_width -
(indent.width() + result.len() + "()".len());
return (one_line_budget,
multi_line_budget,
indent + result.len() + 1);
return (one_line_budget, multi_line_budget, indent + result.len() + 1);
}
}

View File

@ -19,7 +19,6 @@ fn solve_inline_size_constraints(&self,
}
};
// FIXME(#501): tuple width heuristic may not be optimal for patterns.
let (inline_start, inline_size, margin_inline_start, margin_inline_end) =
match (inline_start, inline_end, computed_inline_size) {
(MaybeAuto::Auto, MaybeAuto::Auto, MaybeAuto::Auto) => {

View File

@ -305,8 +305,7 @@ fn get_target(file_name: &str, target: Option<&str>, write_mode: Option<WriteMod
let file_path = Path::new(file_name);
let (source_path_prefix, target_path_prefix) = match write_mode {
Some(WriteMode::Coverage) => {
(Path::new("tests/coverage-source/"),
"tests/coverage-target/")
(Path::new("tests/coverage-source/"), "tests/coverage-target/")
}
_ => (Path::new("tests/source/"), "tests/target/"),
};

View File

@ -9,8 +9,7 @@ fn main() {
b: WithType, // argument
// ignored
_| {
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
};
let block_body = move |xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,

View File

@ -4,40 +4,37 @@ fn solve_inline_size_constraints(&self,
input: &ISizeConstraintInput)
-> ISizeConstraintSolution {
let (inline_start,
inline_size,
margin_inline_start,
margin_inline_end) = match (inline_startssssssxxxxxxsssssxxxxxxxxxssssssxxx,
inline_startssssssxxxxxxsssssxxxxxxxxxssssssxxx) {
(MaybeAuto::Auto, MaybeAuto::Auto, MaybeAuto::Auto) => {
let margin_start = inline_start_margin.specified_or_zero();
let margin_end = inline_end_margin.specified_or_zero();
// Now it is the same situation as inline-start Specified and inline-end
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
(margin_start + margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
let (inline_start, inline_size, margin_inline_start, margin_inline_end) =
match (inline_startssssssxxxxxxsssssxxxxxxxxxssssssxxx,
inline_startssssssxxxxxxsssssxxxxxxxxxssssssxxx) {
(MaybeAuto::Auto, MaybeAuto::Auto, MaybeAuto::Auto) => {
let margin_start = inline_start_margin.specified_or_zero();
let margin_end = inline_end_margin.specified_or_zero();
// Now it is the same situation as inline-start Specified and inline-end
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
(margin_start +
margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
// FIXME(#501): tuple width heuristic may not be optimal for patterns.
let (inline_start,
inline_size,
margin_inline_start,
margin_inline_end) = match (inline_start, inline_end, computed_inline_size) {
(MaybeAuto::Auto, MaybeAuto::Auto, MaybeAuto::Auto) => {
let margin_start = inline_start_margin.specified_or_zero();
let margin_end = inline_end_margin.specified_or_zero();
// Now it is the same situation as inline-start Specified and inline-end
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
(margin_start + margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
let (inline_start, inline_size, margin_inline_start, margin_inline_end) =
match (inline_start, inline_end, computed_inline_size) {
(MaybeAuto::Auto, MaybeAuto::Auto, MaybeAuto::Auto) => {
let margin_start = inline_start_margin.specified_or_zero();
let margin_end = inline_end_margin.specified_or_zero();
// Now it is the same situation as inline-start Specified and inline-end
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
(margin_start +
margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
}
}

View File

@ -32,16 +32,7 @@ fn foo() {
}
// Test that earlier patterns can take the guard space
(aaaa,
bbbbb,
ccccccc,
aaaaa,
bbbbbbbb,
cccccc,
aaaa,
bbbbbbbb,
cccccc,
dddddd) |
(aaaa, bbbbb, ccccccc, aaaaa, bbbbbbbb, cccccc, aaaa, bbbbbbbb, cccccc, dddddd) |
Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
_ => {}
@ -75,22 +66,13 @@ fn main() {
fn main() {
match r {
Variableeeeeeeeeeeeeeeeee => {
("variable",
vec!["id", "name", "qualname", "value", "type", "scopeid"],
true,
true)
("variable", vec!["id", "name", "qualname", "value", "type", "scopeid"], true, true)
}
Enummmmmmmmmmmmmmmmmmmmm => {
("enum",
vec!["id", "qualname", "scopeid", "value"],
true,
true)
("enum", vec!["id", "qualname", "scopeid", "value"], true, true)
}
Variantttttttttttttttttttttttt => {
("variant",
vec!["id", "name", "qualname", "type", "value", "scopeid"],
true,
true)
("variant", vec!["id", "name", "qualname", "type", "value", "scopeid"], true, true)
}
};

View File

@ -2,9 +2,7 @@
fn foo() {
let a = (a, a, a, a, a);
let aaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaa,
aaaaaaaaaaaaaa);
let aaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaa, aaaaaaaaaaaaaa);
let aaaaaaaaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaa,
@ -26,7 +24,6 @@ fn a() {
}
fn b() {
((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
bbbbbbbbbbbbbbbbbb)
}