mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Option to pack fn args on fewer lines
This commit is contained in:
parent
71d24e91e3
commit
89cda8d43a
@ -11,7 +11,7 @@
|
||||
extern crate toml;
|
||||
|
||||
use {NewlineStyle, BraceStyle, ReturnIndent, StructLitStyle};
|
||||
use lists::SeparatorTactic;
|
||||
use lists::{SeparatorTactic, ListTactic};
|
||||
use issues::ReportTactic;
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
@ -26,6 +26,25 @@ pub enum BlockIndentStyle {
|
||||
|
||||
impl_enum_decodable!(BlockIndentStyle, Inherit, Tabbed, Visual);
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
pub enum Density {
|
||||
// Fit as much on one line as possible.
|
||||
Compressed,
|
||||
// Use more lines.
|
||||
Tall,
|
||||
}
|
||||
|
||||
impl_enum_decodable!(Density, Compressed, Tall);
|
||||
|
||||
impl Density {
|
||||
pub fn to_list_tactic(self) -> ListTactic {
|
||||
match self {
|
||||
Density::Compressed => ListTactic::Mixed,
|
||||
Density::Tall => ListTactic::HorizontalVertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! create_config {
|
||||
($($i:ident: $ty:ty),+ $(,)*) => (
|
||||
#[derive(RustcDecodable, Clone)]
|
||||
@ -70,6 +89,7 @@ create_config! {
|
||||
fn_brace_style: BraceStyle,
|
||||
fn_return_indent: ReturnIndent,
|
||||
fn_args_paren_newline: bool,
|
||||
fn_args_layout: Density,
|
||||
struct_trailing_comma: SeparatorTactic,
|
||||
struct_lit_trailing_comma: SeparatorTactic,
|
||||
struct_lit_style: StructLitStyle,
|
||||
@ -94,6 +114,7 @@ impl Default for Config {
|
||||
fn_brace_style: BraceStyle::SameLineWhere,
|
||||
fn_return_indent: ReturnIndent::WithArgs,
|
||||
fn_args_paren_newline: true,
|
||||
fn_args_layout: Density::Tall,
|
||||
struct_trailing_comma: SeparatorTactic::Vertical,
|
||||
struct_lit_trailing_comma: SeparatorTactic::Vertical,
|
||||
struct_lit_style: StructLitStyle::BlockIndent,
|
||||
|
@ -342,7 +342,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
}
|
||||
|
||||
let fmt = ListFormatting {
|
||||
tactic: ListTactic::HorizontalVertical,
|
||||
tactic: self.config.fn_args_layout.to_list_tactic(),
|
||||
separator: ",",
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
indent: arg_indent,
|
||||
|
@ -6,6 +6,7 @@ newline_style = "Unix"
|
||||
fn_brace_style = "SameLineWhere"
|
||||
fn_return_indent = "WithArgs"
|
||||
fn_args_paren_newline = true
|
||||
fn_args_layout = "Tall"
|
||||
struct_trailing_comma = "Vertical"
|
||||
struct_lit_trailing_comma = "Vertical"
|
||||
struct_lit_style = "BlockIndent"
|
||||
|
13
tests/source/fn-custom.rs
Normal file
13
tests/source/fn-custom.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Test some of the ways function signatures can be customised.
|
||||
|
||||
// Test compressed layout of args.
|
||||
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
|
||||
foo();
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
|
||||
foo();
|
||||
}
|
||||
}
|
15
tests/target/fn-custom.rs
Normal file
15
tests/target/fn-custom.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// rustfmt-fn_args_layout: Compressed
|
||||
// Test some of the ways function signatures can be customised.
|
||||
|
||||
// Test compressed layout of args.
|
||||
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
|
||||
d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
|
||||
foo();
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn foo(self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
|
||||
d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
|
||||
foo();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user