mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-24 12:54:00 +00:00
Bootstrap it. Hard.
This commit is contained in:
parent
cd158cecc8
commit
eae2921e14
55
src/expr.rs
55
src/expr.rs
@ -136,14 +136,20 @@ impl Rewrite for ast::Expr {
|
||||
Some(ident) => format!(" {}", ident.node),
|
||||
None => String::new(),
|
||||
};
|
||||
wrap_str(format!("continue{}", id_str), context.config.max_width, width, offset)
|
||||
wrap_str(format!("continue{}", id_str),
|
||||
context.config.max_width,
|
||||
width,
|
||||
offset)
|
||||
}
|
||||
ast::ExprKind::Break(ref opt_ident) => {
|
||||
let id_str = match *opt_ident {
|
||||
Some(ident) => format!(" {}", ident.node),
|
||||
None => String::new(),
|
||||
};
|
||||
wrap_str(format!("break{}", id_str), context.config.max_width, width, offset)
|
||||
wrap_str(format!("break{}", id_str),
|
||||
context.config.max_width,
|
||||
width,
|
||||
offset)
|
||||
}
|
||||
ast::ExprKind::Closure(capture, ref fn_decl, ref body, _) => {
|
||||
rewrite_closure(capture, fn_decl, body, self.span, context, width, offset)
|
||||
@ -684,11 +690,8 @@ fn extract_comment(span: Span,
|
||||
-> Option<String> {
|
||||
let comment_str = context.snippet(span);
|
||||
if contains_comment(&comment_str) {
|
||||
let comment = try_opt!(rewrite_comment(comment_str.trim(),
|
||||
false,
|
||||
width,
|
||||
offset,
|
||||
context.config));
|
||||
let comment =
|
||||
try_opt!(rewrite_comment(comment_str.trim(), false, width, offset, context.config));
|
||||
Some(format!("\n{indent}{}\n{indent}",
|
||||
comment,
|
||||
indent = offset.to_string(context.config)))
|
||||
@ -788,14 +791,11 @@ fn rewrite_if_else(context: &RewriteContext,
|
||||
}
|
||||
};
|
||||
|
||||
let between_if_else_block = mk_sp(if_block.span.hi,
|
||||
context.codemap.span_before(mk_sp(if_block.span.hi,
|
||||
else_block.span.lo),
|
||||
"else"));
|
||||
let between_if_else_block_comment = extract_comment(between_if_else_block,
|
||||
&context,
|
||||
offset,
|
||||
width);
|
||||
let between_if_else_block =
|
||||
mk_sp(if_block.span.hi,
|
||||
context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else"));
|
||||
let between_if_else_block_comment =
|
||||
extract_comment(between_if_else_block, &context, offset, width);
|
||||
|
||||
let after_else = mk_sp(context.codemap
|
||||
.span_after(mk_sp(if_block.span.hi, else_block.span.lo),
|
||||
@ -922,11 +922,8 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
|
||||
}
|
||||
let missed_str = missed_str[first..].trim();
|
||||
if !missed_str.is_empty() {
|
||||
let comment = try_opt!(rewrite_comment(&missed_str,
|
||||
false,
|
||||
width,
|
||||
arm_indent,
|
||||
context.config));
|
||||
let comment =
|
||||
try_opt!(rewrite_comment(&missed_str, false, width, arm_indent, context.config));
|
||||
result.push('\n');
|
||||
result.push_str(arm_indent_str);
|
||||
result.push_str(&comment);
|
||||
@ -1150,10 +1147,9 @@ impl Rewrite for ast::Arm {
|
||||
let body_budget = try_opt!(width.checked_sub(context.config.tab_spaces));
|
||||
let indent = context.block_indent.block_indent(context.config);
|
||||
let inner_context = &RewriteContext { block_indent: indent, ..*context };
|
||||
let next_line_body = try_opt!(nop_block_collapse(body.rewrite(inner_context,
|
||||
body_budget,
|
||||
indent),
|
||||
body_budget));
|
||||
let next_line_body =
|
||||
try_opt!(nop_block_collapse(body.rewrite(inner_context, body_budget, indent),
|
||||
body_budget));
|
||||
let indent_str = offset.block_indent(context.config).to_string(context.config);
|
||||
let (body_prefix, body_suffix) = if context.config.wrap_match_arms {
|
||||
if context.config.match_block_trailing_comma {
|
||||
@ -1766,10 +1762,10 @@ pub fn rewrite_unary_suffix<R: Rewrite>(context: &RewriteContext,
|
||||
offset: Indent)
|
||||
-> Option<String> {
|
||||
rewrite.rewrite(context, try_opt!(width.checked_sub(suffix.len())), offset)
|
||||
.map(|mut r| {
|
||||
r.push_str(suffix);
|
||||
r
|
||||
})
|
||||
.map(|mut r| {
|
||||
r.push_str(suffix);
|
||||
r
|
||||
})
|
||||
}
|
||||
|
||||
fn rewrite_unary_op(context: &RewriteContext,
|
||||
@ -1848,7 +1844,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
|
||||
// FIXME: DRY!
|
||||
match (rhs, new_rhs) {
|
||||
(Some(ref orig_rhs), Some(ref replacement_rhs))
|
||||
if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 => {
|
||||
if count_line_breaks(orig_rhs) >
|
||||
count_line_breaks(replacement_rhs) + 1 => {
|
||||
result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
|
||||
result.push_str(replacement_rhs);
|
||||
}
|
||||
|
35
src/items.rs
35
src/items.rs
@ -66,11 +66,8 @@ impl Rewrite for ast::Local {
|
||||
let budget = try_opt!(width.checked_sub(context.block_indent.width() + 1));
|
||||
|
||||
// 1 = trailing semicolon;
|
||||
result = try_opt!(rewrite_assign_rhs(&context,
|
||||
result,
|
||||
ex,
|
||||
budget,
|
||||
context.block_indent));
|
||||
result =
|
||||
try_opt!(rewrite_assign_rhs(&context, result, ex, budget, context.block_indent));
|
||||
}
|
||||
|
||||
result.push(';');
|
||||
@ -656,18 +653,17 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
|
||||
|
||||
let has_body = !trait_items.is_empty();
|
||||
|
||||
let where_density = if (context.config.where_density == Density::Compressed &&
|
||||
(!result.contains('\n') ||
|
||||
context.config.fn_args_layout == FnArgLayoutStyle::Block)) ||
|
||||
(context.config.fn_args_layout == FnArgLayoutStyle::Block &&
|
||||
result.is_empty()) ||
|
||||
(context.config.where_density == Density::CompressedIfEmpty &&
|
||||
!has_body &&
|
||||
!result.contains('\n')) {
|
||||
Density::Compressed
|
||||
} else {
|
||||
Density::Tall
|
||||
};
|
||||
let where_density =
|
||||
if (context.config.where_density == Density::Compressed &&
|
||||
(!result.contains('\n') ||
|
||||
context.config.fn_args_layout == FnArgLayoutStyle::Block)) ||
|
||||
(context.config.fn_args_layout == FnArgLayoutStyle::Block && result.is_empty()) ||
|
||||
(context.config.where_density == Density::CompressedIfEmpty && !has_body &&
|
||||
!result.contains('\n')) {
|
||||
Density::Compressed
|
||||
} else {
|
||||
Density::Tall
|
||||
};
|
||||
|
||||
let where_budget = try_opt!(context.config
|
||||
.max_width
|
||||
@ -1134,9 +1130,8 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf,
|
||||
let mut_str = format_mutability(m);
|
||||
match lt {
|
||||
Some(ref l) => {
|
||||
let lifetime_str = try_opt!(l.rewrite(context,
|
||||
usize::max_value(),
|
||||
Indent::empty()));
|
||||
let lifetime_str =
|
||||
try_opt!(l.rewrite(context, usize::max_value(), Indent::empty()));
|
||||
Some(format!("&{} {}self", lifetime_str, mut_str))
|
||||
}
|
||||
None => Some(format!("&{}self", mut_str)),
|
||||
|
@ -403,11 +403,8 @@ pub fn format_input(input: Input, config: &Config) -> (Summary, FileMap, FormatR
|
||||
let mut summary = Summary::new();
|
||||
let codemap = Rc::new(CodeMap::new());
|
||||
|
||||
let tty_handler = Handler::with_tty_emitter(ColorConfig::Auto,
|
||||
None,
|
||||
true,
|
||||
false,
|
||||
codemap.clone());
|
||||
let tty_handler =
|
||||
Handler::with_tty_emitter(ColorConfig::Auto, None, true, false, codemap.clone());
|
||||
let mut parse_session = ParseSess::with_span_handler(tty_handler, codemap.clone());
|
||||
|
||||
let main_file = match input {
|
||||
|
@ -307,11 +307,8 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
|
||||
comment.trim().contains('\n') ||
|
||||
comment.trim().len() > width;
|
||||
|
||||
let formatted_comment = try_opt!(rewrite_comment(comment,
|
||||
block_style,
|
||||
width,
|
||||
offset,
|
||||
formatting.config));
|
||||
let formatted_comment =
|
||||
try_opt!(rewrite_comment(comment, block_style, width, offset, formatting.config));
|
||||
|
||||
result.push(' ');
|
||||
result.push_str(&formatted_comment);
|
||||
|
@ -144,10 +144,8 @@ impl Rewrite for Pat {
|
||||
|f| f.node.rewrite(context, budget, offset),
|
||||
context.codemap.span_after(self.span, "{"),
|
||||
self.span.hi);
|
||||
let mut field_string = try_opt!(format_item_list(items,
|
||||
budget,
|
||||
offset,
|
||||
context.config));
|
||||
let mut field_string =
|
||||
try_opt!(format_item_list(items, budget, offset, context.config));
|
||||
if elipses {
|
||||
if field_string.contains('\n') {
|
||||
field_string.push_str(",\n");
|
||||
|
13
src/types.rs
13
src/types.rs
@ -375,12 +375,8 @@ impl Rewrite for ast::WherePredicate {
|
||||
// 3 = " = ".len()
|
||||
let used_width = 3 + ty_str.len();
|
||||
let budget = try_opt!(width.checked_sub(used_width));
|
||||
let path_str = try_opt!(rewrite_path(context,
|
||||
false,
|
||||
None,
|
||||
path,
|
||||
budget,
|
||||
offset + used_width));
|
||||
let path_str =
|
||||
try_opt!(rewrite_path(context, false, None, path, budget, offset + used_width));
|
||||
format!("{} = {}", path_str, ty_str)
|
||||
}
|
||||
};
|
||||
@ -538,9 +534,8 @@ impl Rewrite for ast::Ty {
|
||||
Some(match *lifetime {
|
||||
Some(ref lifetime) => {
|
||||
let lt_budget = try_opt!(width.checked_sub(2 + mut_len));
|
||||
let lt_str = try_opt!(lifetime.rewrite(context,
|
||||
lt_budget,
|
||||
offset + 2 + mut_len));
|
||||
let lt_str =
|
||||
try_opt!(lifetime.rewrite(context, lt_budget, offset + 2 + mut_len));
|
||||
let lt_len = lt_str.len();
|
||||
let budget = try_opt!(width.checked_sub(2 + mut_len + lt_len));
|
||||
format!("&{} {}{}",
|
||||
|
@ -249,7 +249,6 @@ fn ranges() {
|
||||
let x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||
let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ... bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||
let z = ... x ;
|
||||
let infi_range_2 = ... ;
|
||||
|
||||
a ... b
|
||||
|
||||
|
@ -36,7 +36,7 @@ fn main() {
|
||||
do_something()
|
||||
}
|
||||
|
||||
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaaaa } else { bbbbbbbbbb };
|
||||
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa } else { bbbbbbbbbb };
|
||||
|
||||
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaa } else {
|
||||
bbbbbbbbbb };
|
||||
|
@ -1,9 +1,5 @@
|
||||
fn main() -> &'static str {
|
||||
let too_many_lines = "H\
|
||||
e\
|
||||
l\
|
||||
l\
|
||||
o";
|
||||
let too_many_lines = "Hello";
|
||||
let leave_me = "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
|
||||
s
|
||||
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj";
|
||||
|
@ -137,21 +137,18 @@ fn issue587() {
|
||||
fn try_shorthand() {
|
||||
let x = expr?;
|
||||
let y = expr.kaas()?.test();
|
||||
let loooooooooooooooooooooooooooooooooooooooooong = does_this?
|
||||
.look?
|
||||
.good?
|
||||
.should_we_break?
|
||||
.after_the_first_question_mark?;
|
||||
let loooooooooooooooooooooooooooooooooooooooooong =
|
||||
does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
|
||||
let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
|
||||
let zzzz = expr?.another?.another?.another?.another?;
|
||||
let aaa = x??????????????????????????????????????????????????????????????????????????;
|
||||
|
||||
let y = a.very
|
||||
.loooooooooooooooooooooooooooooooooooooong()
|
||||
.chain()
|
||||
.inside()
|
||||
.weeeeeeeeeeeeeee()?
|
||||
.test()
|
||||
.0
|
||||
.x;
|
||||
.loooooooooooooooooooooooooooooooooooooong()
|
||||
.chain()
|
||||
.inside()
|
||||
.weeeeeeeeeeeeeee()?
|
||||
.test()
|
||||
.0
|
||||
.x;
|
||||
}
|
||||
|
@ -46,23 +46,18 @@ fn main() {
|
||||
do_something_else();
|
||||
};
|
||||
|
||||
let arg_test = |big_argument_name, test123| {
|
||||
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
|
||||
};
|
||||
let arg_test =
|
||||
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
|
||||
|
||||
let arg_test = |big_argument_name, test123| {
|
||||
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
|
||||
};
|
||||
let arg_test =
|
||||
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
|
||||
|
||||
let simple_closure = move || -> () {};
|
||||
|
||||
let closure = |input: Ty| -> Option<String> { foo() };
|
||||
|
||||
let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1,
|
||||
aaaaaaaaaaaaaaaaaaaaaaarg2|
|
||||
-> Strong {
|
||||
"sup".to_owned()
|
||||
};
|
||||
let closure_with_return_type =
|
||||
|aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
|
||||
|
||||
|arg1, arg2, _, _, arg3, arg4| {
|
||||
let temp = arg4 + arg3;
|
||||
|
@ -202,10 +202,8 @@ fn arrays() {
|
||||
item: 3,
|
||||
}]);
|
||||
|
||||
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
zzzzzzzzzzzzzzzzzz,
|
||||
q];
|
||||
let z =
|
||||
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
|
||||
|
||||
[1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
|
||||
}
|
||||
@ -273,7 +271,6 @@ fn ranges() {
|
||||
let y =
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
|
||||
let z = ...x;
|
||||
let infi_range_2 = ...;
|
||||
|
||||
a...b
|
||||
|
||||
|
@ -55,10 +55,8 @@ fn main() {
|
||||
.go_to_next_line_with_tab()
|
||||
.go_to_next_line_with_tab();
|
||||
|
||||
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyy,
|
||||
zzzzzzzzzzzzzzzzzz,
|
||||
q];
|
||||
let z =
|
||||
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
|
||||
|
||||
fn generic<T>(arg: T) -> &SomeType
|
||||
where T: Fn(// First arg
|
||||
|
@ -41,7 +41,7 @@ fn main() {
|
||||
}
|
||||
|
||||
let x = if veeeeeeeeery_loooooong_condition() {
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
} else {
|
||||
bbbbbbbbbb
|
||||
};
|
||||
|
@ -1,13 +1,11 @@
|
||||
const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES |
|
||||
FILE_READ_EA | SYNCHRONIZE;
|
||||
|
||||
static boolnames: &'static [&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo", "gn", "hc",
|
||||
"km", "hs", "in", "db", "da", "mir", "msgr", "os",
|
||||
"eslok", "xt", "hz", "ul", "xon", "nxon", "mc5i",
|
||||
"chts", "nrrmc", "npc", "ndscr", "ccc", "bce",
|
||||
"hls", "xhpa", "crxm", "daisy", "xvpa", "sam",
|
||||
"cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT",
|
||||
"OTNL", "OTpt", "OTxr"];
|
||||
static boolnames: &'static [&'static str] =
|
||||
&["bw", "am", "xsb", "xhp", "xenl", "eo", "gn", "hc", "km", "hs", "in", "db", "da", "mir",
|
||||
"msgr", "os", "eslok", "xt", "hz", "ul", "xon", "nxon", "mc5i", "chts", "nrrmc", "npc",
|
||||
"ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy", "xvpa", "sam", "cpix", "lpix",
|
||||
"OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
|
||||
|
||||
static mut name: SomeType =
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
|
||||
|
@ -1,9 +1,5 @@
|
||||
fn main() -> &'static str {
|
||||
let too_many_lines = "H\
|
||||
e\
|
||||
l\
|
||||
l\
|
||||
o";
|
||||
let too_many_lines = "Hello";
|
||||
let leave_me = "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
|
||||
s
|
||||
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj";
|
||||
|
@ -4,13 +4,13 @@ fn main() {
|
||||
let x = some_expr()?;
|
||||
|
||||
let y = a.very
|
||||
.loooooooooooooooooooooooooooooooooooooong()
|
||||
.chain()
|
||||
.inside()
|
||||
.weeeeeeeeeeeeeee()?
|
||||
.test()
|
||||
.0
|
||||
.x;
|
||||
.loooooooooooooooooooooooooooooooooooooong()
|
||||
.chain()
|
||||
.inside()
|
||||
.weeeeeeeeeeeeeee()?
|
||||
.test()
|
||||
.0
|
||||
.x;
|
||||
}
|
||||
|
||||
fn test() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
fn main() {
|
||||
let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait<AA,
|
||||
BB,
|
||||
CC>;
|
||||
let xxxxxxxxxxx =
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait<AA, BB, CC>;
|
||||
|
||||
let xxxxxxxxxxxxxxx =
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
|
||||
|
Loading…
Reference in New Issue
Block a user