Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent structs with ".." from being rewritten with alignment
rustfmt should only support rewriting a struct in an expression position with alignment (non-default behavior) when there is no rest (with or without a base) and all of the fields are non-shorthand.
- Loading branch information
1 parent
8b58cce
commit d418057
Showing
15 changed files
with
458 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
a: i32, | ||
b: i32, | ||
c: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { a: 1_000, b: 1_000, .. } | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/source/issue-4926/deeply_nested_struct_with_long_field_names.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
really_really_long_field_a: i32, | ||
really_really_really_long_field_b: i32, | ||
really_really_really_really_long_field_c: i32, | ||
really_really_really_really_really_long_field_d: i32, | ||
really_really_really_really_really_really_long_field_e: i32, | ||
f: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { | ||
really_really_long_field_a: 10, | ||
really_really_really_long_field_b: 10, | ||
really_really_really_really_long_field_c: 10, | ||
really_really_really_really_really_long_field_d: 10, | ||
really_really_really_really_really_really_long_field_e: 10, .. | ||
} | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/source/issue-4926/deeply_nested_struct_with_many_fields.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
a: i32, | ||
b: i32, | ||
c: i32, | ||
d: i32, | ||
e: i32, | ||
f: i32, | ||
g: i32, | ||
h: i32, | ||
i: i32, | ||
j: i32, | ||
k: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { | ||
a: 1_000, b: 1_000, c: 1_000, d: 1_000, e: 1_000, f: 1_000, g: 1_000, h: 1_000, i: 1_000, j: 1_000, .. | ||
} | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
// rustfmt-enum_discrim_align_threshold: 30 | ||
// rustfmt-imports_layout: HorizontalVertical | ||
|
||
#[derive(Default)] | ||
struct InnerStructA { bbbbbbbbb: i32, cccccccc: i32 } | ||
|
||
enum SomeEnumNamedD { | ||
E(InnerStructA), | ||
F { | ||
ggggggggggggggggggggggggg: bool, | ||
h: bool, | ||
} | ||
} | ||
|
||
impl SomeEnumNamedD { | ||
fn f_variant() -> Self { | ||
Self::F { ggggggggggggggggggggggggg: true, h: true } | ||
} | ||
} | ||
|
||
fn main() { | ||
let kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk = SomeEnumNamedD::f_variant(); | ||
let something_we_care_about = matches!( | ||
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk, | ||
SomeEnumNamedD::F { | ||
ggggggggggggggggggggggggg: true, | ||
.. | ||
} | ||
); | ||
|
||
if something_we_care_about { | ||
println!("Yup it happened"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { a: i32, b: i32 } | ||
|
||
fn test(x: X) { | ||
let y = matches!(x, X { | ||
a: 1, | ||
.. | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
really_really_long_field_a: i32, | ||
really_really_really_long_field_b: i32, | ||
really_really_really_really_long_field_c: i32, | ||
really_really_really_really_really_long_field_d: i32, | ||
really_really_really_really_really_really_long_field_e: i32, | ||
f: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let y = matches!(x, X { | ||
really_really_long_field_a: 10, | ||
really_really_really_long_field_b: 10, | ||
really_really_really_really_long_field_c: 10, | ||
really_really_really_really_really_long_field_d: 10, | ||
really_really_really_really_really_really_long_field_e: 10, | ||
.. | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
a: i32, | ||
b: i32, | ||
c: i32, | ||
d: i32, | ||
e: i32, | ||
f: i32, | ||
g: i32, | ||
h: i32, | ||
i: i32, | ||
j: i32, | ||
k: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let y = matches!(x, X { | ||
a: 1_000, b: 1_000, c: 1_000, d: 1_000, e: 1_000, f: 1_000, g: 1_000, h: 1_000, i: 1_000, j: 1_000, .. | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
a: i32, | ||
b: i32, | ||
c: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { | ||
a: 1_000, | ||
b: 1_000, | ||
.. | ||
} | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/target/issue-4926/deeply_nested_struct_with_long_field_names.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
really_really_long_field_a: i32, | ||
really_really_really_long_field_b: i32, | ||
really_really_really_really_long_field_c: i32, | ||
really_really_really_really_really_long_field_d: i32, | ||
really_really_really_really_really_really_long_field_e: i32, | ||
f: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { | ||
really_really_long_field_a: 10, | ||
really_really_really_long_field_b: 10, | ||
really_really_really_really_long_field_c: 10, | ||
really_really_really_really_really_long_field_d: 10, | ||
really_really_really_really_really_really_long_field_e: 10, | ||
.. | ||
} | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/target/issue-4926/deeply_nested_struct_with_many_fields.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// rustfmt-struct_field_align_threshold: 30 | ||
|
||
struct X { | ||
a: i32, | ||
b: i32, | ||
c: i32, | ||
d: i32, | ||
e: i32, | ||
f: i32, | ||
g: i32, | ||
h: i32, | ||
i: i32, | ||
j: i32, | ||
k: i32, | ||
} | ||
|
||
fn test(x: X) { | ||
let d = { | ||
let e = { | ||
let f = { | ||
let g = { | ||
let h = { | ||
let i = { | ||
let j = { | ||
matches!( | ||
x, | ||
X { | ||
a: 1_000, | ||
b: 1_000, | ||
c: 1_000, | ||
d: 1_000, | ||
e: 1_000, | ||
f: 1_000, | ||
g: 1_000, | ||
h: 1_000, | ||
i: 1_000, | ||
j: 1_000, | ||
.. | ||
} | ||
) | ||
}; | ||
j | ||
}; | ||
i | ||
}; | ||
h | ||
}; | ||
g | ||
}; | ||
f | ||
}; | ||
e | ||
}; | ||
} |
Oops, something went wrong.