stabilise fn_args_density (#3581)
This commit is contained in:
parent
19220942d3
commit
e6b60a40d5
@ -2,9 +2,12 @@
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Change option `format_doc_comment` to `format_code_in_doc_comment`.
|
||||
- `use_small_heuristics` changed to be an enum and stabilised. Configuration
|
||||
options are now ready for 1.0.
|
||||
- Stabilise `fn_args_density` configuration option and rename it to `fn_args_layout` #3581
|
||||
|
||||
## [1.2.2] 2019-04-24
|
||||
|
||||
|
@ -629,13 +629,13 @@ trailing whitespaces.
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No (tracking issue: #3392)
|
||||
|
||||
## `fn_args_density`
|
||||
## `fn_args_layout`
|
||||
|
||||
Argument density in functions
|
||||
Control the layout of arguments in a function
|
||||
|
||||
- **Default value**: `"Tall"`
|
||||
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
|
||||
- **Stable**: No (tracking issue: #3375)
|
||||
- **Stable**: Yes
|
||||
|
||||
#### `"Tall"` (default):
|
||||
|
||||
|
@ -17,6 +17,7 @@ Open a pull request that closes the tracking issue. The tracking issue is listed
|
||||
|
||||
- Update the `Config` enum marking the option as stable.
|
||||
- Update the the `Configuration.md` file marking the option as stable.
|
||||
- Update `CHANGELOG.md` marking the option as stable.
|
||||
|
||||
## After the stabilisation
|
||||
|
||||
|
@ -92,7 +92,8 @@ create_config! {
|
||||
the same line with the pattern of arms";
|
||||
force_multiline_blocks: bool, false, false,
|
||||
"Force multiline closure bodies and match arms to be wrapped in a block";
|
||||
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
|
||||
fn_args_layout: Density, Density::Tall, true,
|
||||
"Control the layout of arguments in a function";
|
||||
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
|
||||
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
|
||||
"Brace style for control flow constructs";
|
||||
@ -501,7 +502,7 @@ struct_field_align_threshold = 0
|
||||
enum_discrim_align_threshold = 0
|
||||
match_arm_blocks = true
|
||||
force_multiline_blocks = false
|
||||
fn_args_density = "Tall"
|
||||
fn_args_layout = "Tall"
|
||||
brace_style = "SameLineWhere"
|
||||
control_brace_style = "AlwaysSameLine"
|
||||
trailing_semicolon = true
|
||||
|
@ -58,10 +58,11 @@ pub enum IndentStyle {
|
||||
|
||||
#[config_type]
|
||||
/// How to place a list-like items.
|
||||
/// FIXME: Issue-3581: this should be renamed to ItemsLayout when publishing 2.0
|
||||
pub enum Density {
|
||||
/// Fit as much on one line as possible.
|
||||
Compressed,
|
||||
/// Use more lines.
|
||||
/// Items are placed horizontally if sufficient space, vertically otherwise.
|
||||
Tall,
|
||||
/// Place every item on a separate line.
|
||||
Vertical,
|
||||
|
28
src/items.rs
28
src/items.rs
@ -15,7 +15,7 @@ use crate::comment::{
|
||||
FindUncommented,
|
||||
};
|
||||
use crate::config::lists::*;
|
||||
use crate::config::{BraceStyle, Config, Density, IndentStyle, Version};
|
||||
use crate::config::{BraceStyle, Config, IndentStyle, Version};
|
||||
use crate::expr::{
|
||||
format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
|
||||
ExprType, RhsTactics,
|
||||
@ -703,7 +703,7 @@ pub(crate) fn format_impl(
|
||||
&generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
Shape::legacy(where_budget, offset.block_only()),
|
||||
Density::Vertical,
|
||||
false,
|
||||
"{",
|
||||
where_span_end,
|
||||
self_ty.span.hi(),
|
||||
@ -1044,11 +1044,7 @@ pub(crate) fn format_trait(
|
||||
|
||||
// Rewrite where-clause.
|
||||
if !generics.where_clause.predicates.is_empty() {
|
||||
let where_density = if context.config.indent_style() == IndentStyle::Block {
|
||||
Density::Compressed
|
||||
} else {
|
||||
Density::Tall
|
||||
};
|
||||
let where_on_new_line = context.config.indent_style() != IndentStyle::Block;
|
||||
|
||||
let where_budget = context.budget(last_line_width(&result));
|
||||
let pos_before_where = if generic_bounds.is_empty() {
|
||||
@ -1062,7 +1058,7 @@ pub(crate) fn format_trait(
|
||||
&generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
Shape::legacy(where_budget, offset.block_only()),
|
||||
where_density,
|
||||
where_on_new_line,
|
||||
"{",
|
||||
None,
|
||||
pos_before_where,
|
||||
@ -1171,7 +1167,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> {
|
||||
&self.generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
shape,
|
||||
Density::Compressed,
|
||||
false,
|
||||
";",
|
||||
None,
|
||||
self.generics.where_clause.span.lo(),
|
||||
@ -1423,7 +1419,7 @@ fn format_tuple_struct(
|
||||
&generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
Shape::legacy(where_budget, offset.block_only()),
|
||||
Density::Compressed,
|
||||
false,
|
||||
";",
|
||||
None,
|
||||
body_hi,
|
||||
@ -1499,7 +1495,7 @@ fn rewrite_type_prefix(
|
||||
&generics.where_clause,
|
||||
context.config.brace_style(),
|
||||
Shape::legacy(where_budget, indent),
|
||||
Density::Vertical,
|
||||
false,
|
||||
"=",
|
||||
None,
|
||||
generics.span.hi(),
|
||||
@ -2258,7 +2254,7 @@ fn rewrite_fn_base(
|
||||
where_clause,
|
||||
context.config.brace_style(),
|
||||
Shape::indented(indent, context.config),
|
||||
Density::Tall,
|
||||
true,
|
||||
"{",
|
||||
Some(span.hi()),
|
||||
pos_before_where,
|
||||
@ -2390,7 +2386,7 @@ fn rewrite_args(
|
||||
&arg_items,
|
||||
context
|
||||
.config
|
||||
.fn_args_density()
|
||||
.fn_args_layout()
|
||||
.to_list_tactic(arg_items.len()),
|
||||
Separator::Comma,
|
||||
one_line_budget,
|
||||
@ -2677,7 +2673,7 @@ fn rewrite_where_clause(
|
||||
where_clause: &ast::WhereClause,
|
||||
brace_style: BraceStyle,
|
||||
shape: Shape,
|
||||
density: Density,
|
||||
on_new_line: bool,
|
||||
terminator: &str,
|
||||
span_end: Option<BytePos>,
|
||||
span_end_before_where: BytePos,
|
||||
@ -2757,7 +2753,7 @@ fn rewrite_where_clause(
|
||||
} else {
|
||||
terminator.len()
|
||||
};
|
||||
if density == Density::Tall
|
||||
if on_new_line
|
||||
|| preds_str.contains('\n')
|
||||
|| shape.indent.width() + " where ".len() + preds_str.len() + end_length > shape.width
|
||||
{
|
||||
@ -2848,7 +2844,7 @@ fn format_generics(
|
||||
&generics.where_clause,
|
||||
brace_style,
|
||||
Shape::legacy(budget, offset.block_only()),
|
||||
Density::Tall,
|
||||
true,
|
||||
"{",
|
||||
Some(span.hi()),
|
||||
span_end_before_where,
|
||||
|
@ -246,10 +246,7 @@ where
|
||||
let total_sep_len = sep.len() * sep_count.saturating_sub(1);
|
||||
let real_total = total_width + total_sep_len;
|
||||
|
||||
if real_total <= limit
|
||||
&& !pre_line_comments
|
||||
&& !items.into_iter().any(|item| item.as_ref().is_multiline())
|
||||
{
|
||||
if real_total <= limit && !items.into_iter().any(|item| item.as_ref().is_multiline()) {
|
||||
DefinitiveListTactic::Horizontal
|
||||
} else {
|
||||
match tactic {
|
||||
|
@ -3,7 +3,7 @@ comment_width = 80
|
||||
tab_spaces = 2
|
||||
newline_style = "Unix"
|
||||
brace_style = "SameLineWhere"
|
||||
fn_args_density = "Tall"
|
||||
fn_args_layout = "Tall"
|
||||
trailing_comma = "Vertical"
|
||||
indent_style = "Block"
|
||||
report_todo = "Always"
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Compressed
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Tall
|
||||
// rustfmt-fn_args_layout: Tall
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,5 +1,5 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
// rustfmt-brace_style: AlwaysNextLine
|
||||
|
||||
// Case with only one variable.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Compressed
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Test some of the ways function signatures can be customised.
|
||||
|
||||
// Test compressed layout of args.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
|
||||
// Empty list should stay on one line.
|
||||
fn do_bar(
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Compressed
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Tall
|
||||
// rustfmt-fn_args_layout: Tall
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
// Function arguments density
|
||||
|
||||
trait Lorem {
|
@ -1,5 +1,5 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
// rustfmt-brace_style: AlwaysNextLine
|
||||
|
||||
// Case with only one variable.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Compressed
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Test some of the ways function signatures can be customised.
|
||||
|
||||
// Test compressed layout of args.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-fn_args_density: Vertical
|
||||
// rustfmt-fn_args_layout: Vertical
|
||||
|
||||
// Empty list should stay on one line.
|
||||
fn do_bar() -> u8 {
|
Loading…
x
Reference in New Issue
Block a user