Skip to content

Commit 5ce82e1

Browse files
ytmimicalebcartwright
authored andcommitted
Prevent trailing whitespace in where clause bound predicate
resolves 5012 resolves 4850 This behavior was noticed when using the ``trailing_comma = "Never"`` configuration option (5012). This behavior was also noticed when using default configurations (4850). rustfmt would add a trailing space to where clause bounds that had an empty right hand side. Now no trailing space is added to the end of these where clause bounds.
1 parent a4d7011 commit 5ce82e1

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/expr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,9 @@ fn choose_rhs<R: Rewrite>(
19621962
has_rhs_comment: bool,
19631963
) -> Option<String> {
19641964
match orig_rhs {
1965+
Some(ref new_str) if new_str.is_empty() => {
1966+
return Some(String::new());
1967+
}
19651968
Some(ref new_str)
19661969
if !new_str.contains('\n') && unicode_str_width(new_str) <= shape.width =>
19671970
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-trailing_comma: Always
2+
3+
pub struct Matrix<T, const R: usize, const C: usize,>
4+
where
5+
[T; R * C]:,
6+
{
7+
contents: [T; R * C],
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-trailing_comma: Never
2+
3+
pub struct Matrix<T, const R: usize, const C: usize>
4+
where
5+
[T; R * C]:
6+
{
7+
contents: [T; R * C]
8+
}

tests/target/issue_4850.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
impl ThisIsALongStructNameToPushTheWhereToWrapLolololol where
2+
[(); this_is_a_long_const_function_name()]:
3+
{
4+
}

0 commit comments

Comments
 (0)