remove closure_block_indent_threshold option
This commit is contained in:
parent
7ff2cb23f5
commit
e6800bf27d
@ -266,40 +266,6 @@ let files = fs::read_dir("tests/coverage/source")
|
||||
|
||||
See also [`chain_width`](#chain_width).
|
||||
|
||||
## `closure_block_indent_threshold`
|
||||
|
||||
How many lines a closure must have before it is block indented. -1 means never use block indent.
|
||||
|
||||
- **Default value**: `7`
|
||||
- **Possible values**: `-1`, or any positive integer
|
||||
|
||||
#### Closures shorter than `closure_block_indent_threshold`:
|
||||
```rust
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
});
|
||||
```
|
||||
|
||||
#### Closures longer than `closure_block_indent_threshold`:
|
||||
```rust
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
println!("consectetur");
|
||||
println!("adipiscing");
|
||||
println!("elit");
|
||||
});
|
||||
```
|
||||
|
||||
**Note**: This option only takes effect when `fn_call_indent` is set to `"Visual"`.
|
||||
|
||||
## `combine_control_expr`
|
||||
|
||||
Combine control expressions with function calls.
|
||||
|
@ -13,8 +13,7 @@ use syntax::codemap::Span;
|
||||
use syntax::parse::classify;
|
||||
|
||||
use codemap::SpanUtils;
|
||||
use expr::{block_contains_comment, is_simple_block, is_unsafe_block, need_block_indent,
|
||||
rewrite_cond, ToExpr};
|
||||
use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond, ToExpr};
|
||||
use items::{span_hi_for_arg, span_lo_for_arg};
|
||||
use lists::{definitive_tactic, itemize_list, write_list, DefinitiveListTactic, ListFormatting,
|
||||
ListTactic, Separator, SeparatorPlace, SeparatorTactic};
|
||||
@ -22,7 +21,7 @@ use rewrite::{Rewrite, RewriteContext};
|
||||
use shape::Shape;
|
||||
use utils::{last_line_width, left_most_sub_expr, stmt_expr};
|
||||
|
||||
// This functions is pretty messy because of the rules around closures and blocks:
|
||||
// This module is pretty messy because of the rules around closures and blocks:
|
||||
// FIXME - the below is probably no longer true in full.
|
||||
// * if there is a return type, then there must be braces,
|
||||
// * given a closure with braces, whether that is parsed to give an inner block
|
||||
@ -31,6 +30,8 @@ use utils::{last_line_width, left_most_sub_expr, stmt_expr};
|
||||
// * if the first expression in the body ends with a block (i.e., is a
|
||||
// statement without needing a semi-colon), then adding or removing braces
|
||||
// can change whether it is treated as an expression or statement.
|
||||
|
||||
|
||||
pub fn rewrite_closure(
|
||||
capture: ast::CaptureBy,
|
||||
fn_decl: &ast::FnDecl,
|
||||
@ -137,21 +138,6 @@ fn rewrite_closure_block(
|
||||
context: &RewriteContext,
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
// Start with visual indent, then fall back to block indent if the
|
||||
// closure is large.
|
||||
let block_threshold = context.config.closure_block_indent_threshold();
|
||||
if block_threshold >= 0 {
|
||||
if let Some(block_str) = block.rewrite(context, shape) {
|
||||
if block_str.matches('\n').count() <= block_threshold as usize
|
||||
&& !need_block_indent(&block_str, shape)
|
||||
{
|
||||
return Some(format!("{} {}", prefix, block_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The body of the closure is big enough to be block indented, that
|
||||
// means we must re-format.
|
||||
let block_shape = shape.block();
|
||||
let block_str = block.rewrite(context, block_shape)?;
|
||||
Some(format!("{} {}", prefix, block_str))
|
||||
|
@ -621,9 +621,6 @@ create_config! {
|
||||
indentation level as the match keyword";
|
||||
match_pattern_separator_break_point: SeparatorPlace, SeparatorPlace::Back, false,
|
||||
"Put a match sub-patterns' separator in front or back.";
|
||||
closure_block_indent_threshold: isize, 7, false,
|
||||
"How many lines a closure must have before it is block indented. \
|
||||
-1 means never use block indent.";
|
||||
space_before_type_annotation: bool, false, false,
|
||||
"Leave a space before the colon in a type annotation";
|
||||
space_after_type_annotation_colon: bool, true, false,
|
||||
|
@ -1851,7 +1851,7 @@ where
|
||||
))
|
||||
}
|
||||
|
||||
pub fn need_block_indent(s: &str, shape: Shape) -> bool {
|
||||
fn need_block_indent(s: &str, shape: Shape) -> bool {
|
||||
s.lines().skip(1).any(|s| {
|
||||
s.find(|c| !char::is_whitespace(c))
|
||||
.map_or(false, |w| w + 1 < shape.indent.width())
|
||||
|
@ -1,5 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: -1
|
||||
|
||||
fn issue1755() {
|
||||
b.iter(|| dfkljdklgjdlkfgjdlkgjldkjfgkdjgldjfgkljdfklgjlkdjfgkljdflkgjlkdfjgdjfsas::expect("parse"));
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: 10
|
||||
// Closure block indent threshold
|
||||
|
||||
fn main() {
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
});
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: 2
|
||||
// Closure block indent threshold
|
||||
|
||||
fn main() {
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
});
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: -1
|
||||
|
||||
fn issue1755() {
|
||||
b.iter(|| {
|
||||
dfkljdklgjdlkfgjdlkgjldkjfgkdjgldjfgkljdfklgjlkdjfgkljdflkgjlkdfjgdjfsas::expect("parse")
|
||||
});
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: 10
|
||||
// Closure block indent threshold
|
||||
|
||||
fn main() {
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
});
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
// rustfmt-closure_block_indent_threshold: 2
|
||||
// Closure block indent threshold
|
||||
|
||||
fn main() {
|
||||
lorem_ipsum(|| {
|
||||
println!("lorem");
|
||||
println!("ipsum");
|
||||
println!("dolor");
|
||||
println!("sit");
|
||||
println!("amet");
|
||||
});
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user