Skip to content

Commit 58ca556

Browse files
committed
Update per comments
1 parent 89f1e2b commit 58ca556

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/expr.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ use std::cmp::min;
33

44
use itertools::Itertools;
55
use rustc_ast::token::{Delimiter, Lit, LitKind};
6-
use rustc_ast::{ast, ptr, token, ForLoopKind, MatchKind};
6+
use rustc_ast::{ForLoopKind, MatchKind, ast, ptr, token};
77
use rustc_span::{BytePos, Span};
88

99
use crate::chains::rewrite_chain;
1010
use crate::closures;
1111
use crate::comment::{
12-
combine_strs_with_missing_comments, contains_comment, recover_comment_removed, rewrite_comment,
13-
rewrite_missing_comment, CharClasses, FindUncommented,
12+
CharClasses, FindUncommented, combine_strs_with_missing_comments, contains_comment,
13+
recover_comment_removed, rewrite_comment, rewrite_missing_comment,
1414
};
1515
use crate::config::lists::*;
1616
use crate::config::{Config, ControlBraceStyle, HexLiteralCase, IndentStyle, StyleEdition};
1717
use crate::lists::{
18-
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
19-
struct_lit_tactic, write_list, ListFormatting, Separator,
18+
ListFormatting, Separator, definitive_tactic, itemize_list, shape_for_tactic,
19+
struct_lit_formatting, struct_lit_shape, struct_lit_tactic, write_list,
2020
};
21-
use crate::macros::{rewrite_macro, MacroPosition};
21+
use crate::macros::{MacroPosition, rewrite_macro};
2222
use crate::matches::rewrite_match;
2323
use crate::overflow::{self, IntoOverflowableItem, OverflowableItem};
24-
use crate::pairs::{rewrite_all_pairs, rewrite_pair, PairParts};
24+
use crate::pairs::{PairParts, rewrite_all_pairs, rewrite_pair};
2525
use crate::rewrite::{Rewrite, RewriteContext, RewriteError, RewriteErrorExt, RewriteResult};
2626
use crate::shape::{Indent, Shape};
2727
use crate::source_map::{LineRangeUtils, SpanUtils};
2828
use crate::spanned::Spanned;
2929
use crate::stmt;
30-
use crate::string::{rewrite_string, StringFormat};
31-
use crate::types::{rewrite_path, PathContext};
30+
use crate::string::{StringFormat, rewrite_string};
31+
use crate::types::{PathContext, rewrite_path};
3232
use crate::utils::{
3333
colon_spaces, contains_skip, count_newlines, filtered_str_fits, first_line_ends_with,
3434
inner_attributes, last_line_extendable, last_line_width, mk_sp, outer_attributes,
@@ -2124,25 +2124,24 @@ pub(crate) fn rewrite_assign_rhs_expr<R: Rewrite>(
21242124
rhs_kind: &RhsAssignKind<'_>,
21252125
rhs_tactics: RhsTactics,
21262126
) -> RewriteResult {
2127-
let get_lhs_last_line_shape = || {
2128-
let last_line = lhs.rsplitn(2, "\n").next().unwrap_or_default();
2127+
let get_rhs_shape = || {
2128+
let last_line = lhs.lines().last().unwrap_or_default();
21292129
let tab_spaces = context.config.tab_spaces();
21302130
let new_shape = shape
21312131
.block_indent(tab_spaces)
21322132
.saturating_sub_width(tab_spaces);
2133-
let extra_indent_string = new_shape.to_string(&context.config).to_string();
2134-
if last_line.starts_with(&extra_indent_string) {
2133+
let extra_indent_string = new_shape.to_string(&context.config);
2134+
if last_line.starts_with(extra_indent_string.as_ref()) {
21352135
new_shape
21362136
} else {
21372137
shape
21382138
}
21392139
};
21402140
let shape = if context.config.style_edition() >= StyleEdition::Edition2024 {
2141-
get_lhs_last_line_shape()
2141+
get_rhs_shape()
21422142
} else {
21432143
shape
21442144
};
2145-
21462145
let last_line_width = last_line_width(lhs).saturating_sub(if lhs.contains('\n') {
21472146
shape.indent.width()
21482147
} else {

src/shape.rs

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl Shape {
278278
offset_indent.to_string_inner(config, 0)
279279
}
280280

281+
/// similar to to_string_with_newline, except the result does not start with a new line
281282
pub(crate) fn to_string(&self, config: &Config) -> Cow<'static, str> {
282283
let mut offset_indent = self.indent;
283284
offset_indent.alignment = self.offset;

0 commit comments

Comments
 (0)