Skip to content

Commit 2dda3da

Browse files
committed
Changes per review comments (v2)
1 parent cc0daad commit 2dda3da

File tree

2 files changed

+42
-32
lines changed

2 files changed

+42
-32
lines changed

src/formatting/expr.rs

+12-31
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,16 @@ pub(crate) fn rewrite_rhs_expr<R: Rewrite>(
19731973
)
19741974
}
19751975

1976+
fn rewrite_assign_rhs_expr<R: Rewrite>(
1977+
context: &RewriteContext<'_>,
1978+
lhs: &str,
1979+
ex: &R,
1980+
shape: Shape,
1981+
rhs_tactics: RhsTactics,
1982+
) -> Option<String> {
1983+
rewrite_rhs_expr(context, &lhs, ex, shape, rhs_tactics, "=")
1984+
}
1985+
19761986
pub(crate) fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
19771987
context: &RewriteContext<'_>,
19781988
lhs: S,
@@ -1981,7 +1991,7 @@ pub(crate) fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
19811991
rhs_tactics: RhsTactics,
19821992
) -> Option<String> {
19831993
let lhs = lhs.into();
1984-
let rhs = rewrite_rhs_expr(context, &lhs, ex, shape, rhs_tactics, "=")?;
1994+
let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_tactics)?;
19851995
Some(lhs + &rhs)
19861996
}
19871997

@@ -2001,7 +2011,7 @@ pub(crate) fn rewrite_assign_rhs_with_comments<S: Into<String>, R: Rewrite>(
20012011
} else {
20022012
shape
20032013
};
2004-
let rhs = rewrite_rhs_expr(context, &lhs, ex, shape, rhs_tactics, "=")?;
2014+
let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_tactics)?;
20052015

20062016
if contains_comment {
20072017
let rhs = rhs.trim_start();
@@ -2011,35 +2021,6 @@ pub(crate) fn rewrite_assign_rhs_with_comments<S: Into<String>, R: Rewrite>(
20112021
}
20122022
}
20132023

2014-
pub(crate) fn rewrite_trait_rhs_with_comments<S: Into<String>, R: Rewrite>(
2015-
context: &RewriteContext<'_>,
2016-
lhs: S,
2017-
ex: &R,
2018-
shape: Shape,
2019-
rhs_tactics: RhsTactics,
2020-
between_span: Span,
2021-
allow_extend: bool,
2022-
) -> Option<String> {
2023-
let lhs = lhs.into();
2024-
let contains_comment = contains_comment(context.snippet(between_span));
2025-
2026-
let rhs = rewrite_rhs_expr(context, &lhs, ex, shape, rhs_tactics, ":")?;
2027-
2028-
if contains_comment {
2029-
let rhs = rhs.trim_start();
2030-
combine_strs_with_missing_comments(
2031-
context,
2032-
&lhs,
2033-
&rhs,
2034-
between_span,
2035-
shape.block_left(context.config.tab_spaces())?,
2036-
allow_extend,
2037-
)
2038-
} else {
2039-
Some(lhs + &rhs)
2040-
}
2041-
}
2042-
20432024
fn choose_rhs<R: Rewrite>(
20442025
context: &RewriteContext<'_>,
20452026
expr: &R,

src/formatting/items.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::formatting::{
1919
},
2020
expr::{
2121
is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
22-
rewrite_assign_rhs_with_comments, rewrite_trait_rhs_with_comments, RhsTactics,
22+
rewrite_assign_rhs_with_comments, rewrite_rhs_expr, RhsTactics,
2323
},
2424
lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator},
2525
macros::{rewrite_macro, MacroPosition},
@@ -1114,6 +1114,35 @@ fn format_struct(
11141114
}
11151115
}
11161116

1117+
pub(crate) fn rewrite_trait_rhs_with_comments<S: Into<String>, R: Rewrite>(
1118+
context: &RewriteContext<'_>,
1119+
lhs: S,
1120+
ex: &R,
1121+
shape: Shape,
1122+
rhs_tactics: RhsTactics,
1123+
between_span: Span,
1124+
allow_extend: bool,
1125+
) -> Option<String> {
1126+
let lhs = lhs.into();
1127+
let contains_comment = contains_comment(context.snippet(between_span));
1128+
1129+
let rhs = rewrite_rhs_expr(context, &lhs, ex, shape, rhs_tactics, ":")?;
1130+
1131+
if contains_comment {
1132+
let rhs = rhs.trim_start();
1133+
combine_strs_with_missing_comments(
1134+
context,
1135+
&lhs,
1136+
&rhs,
1137+
between_span,
1138+
shape.block_left(context.config.tab_spaces())?,
1139+
allow_extend,
1140+
)
1141+
} else {
1142+
Some(lhs + &rhs)
1143+
}
1144+
}
1145+
11171146
pub(crate) fn format_trait(
11181147
context: &RewriteContext<'_>,
11191148
item: &ast::Item,

0 commit comments

Comments
 (0)