Skip to content

Commit fd417fe

Browse files
davidBar-Oncalebcartwright
authored andcommitted
Use rewrite_assign_rhs_with_comments by ControlFlow rewrite_pat_expr
1 parent 761adad commit fd417fe

File tree

1 file changed

+10
-50
lines changed

1 file changed

+10
-50
lines changed

src/formatting/expr.rs

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use crate::formatting::{
1111
chains::rewrite_chain,
1212
closures,
1313
comment::{
14-
combine_strs_with_missing_comments, comment_style, contains_comment,
15-
recover_comment_removed, rewrite_comment, rewrite_missing_comment, CharClasses,
16-
FindUncommented,
14+
combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
15+
rewrite_comment, rewrite_missing_comment, CharClasses, FindUncommented,
1716
},
1817
lists::{
1918
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
@@ -896,54 +895,15 @@ impl<'a> ControlFlow<'a> {
896895
.snippet_provider
897896
.span_after(self.span, self.connector.trim());
898897
let comments_span = mk_sp(comments_lo, expr.span.lo());
899-
900-
let missing_comments = match rewrite_missing_comment(comments_span, cond_shape, context)
901-
{
902-
None => "".to_owned(),
903-
Some(comment) if self.connector.is_empty() || comment.is_empty() => comment,
904-
// Handle same-line block comments:
905-
// if let Some(foo) = /*bar*/ baz { ... }
906-
// if let Some(ref /*def*/ mut /*abc*/ state)...
907-
Some(comment)
908-
if !comment_style(&comment, false).is_line_comment()
909-
&& !comment.contains('\n') =>
910-
{
911-
format!(" {}", comment)
912-
}
913-
// Handle sequence of multiple inline comments:
914-
// if let Some(n) =
915-
// // this is a test comment
916-
// // with another
917-
// foo { .... }
918-
Some(_) => {
919-
let newline = &cond_shape
920-
.indent
921-
.block_indent(context.config)
922-
.to_string_with_newline(context.config);
923-
let shape = pat_shape.block_indent(context.config.tab_spaces());
924-
let comment = format!(
925-
"{}{}",
926-
newline,
927-
rewrite_missing_comment(comments_span, shape, context)?,
928-
);
929-
let lhs = format!("{}{}{}{}", matcher, pat_string, self.connector, comment);
930-
let orig_rhs = Some(format!("{}{}", newline, expr.rewrite(context, shape)?));
931-
let rhs = choose_rhs(
932-
context,
933-
expr,
934-
cond_shape,
935-
orig_rhs,
936-
RhsTactics::Default,
937-
true,
938-
)?;
939-
return Some(format!("{}{}", lhs, rhs));
940-
}
941-
};
942-
let result = format!(
943-
"{}{}{}{}",
944-
matcher, pat_string, self.connector, missing_comments
898+
return rewrite_assign_rhs_with_comments(
899+
context,
900+
&format!("{}{}{}", matcher, pat_string, self.connector),
901+
expr,
902+
cond_shape,
903+
RhsTactics::Default,
904+
comments_span,
905+
true,
945906
);
946-
return rewrite_assign_rhs(context, result, expr, cond_shape);
947907
}
948908

949909
let expr_rw = expr.rewrite(context, cond_shape);

0 commit comments

Comments
 (0)