Skip to content

Commit 13a8e54

Browse files
fix: newline width calc in combine w/ comments (#4123)
1 parent e7d76f1 commit 13a8e54

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

rustfmt-core/rustfmt-lib/src/comment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) fn combine_strs_with_missing_comments(
188188
let missing_comment = rewrite_missing_comment(span, shape, context)?;
189189

190190
if missing_comment.is_empty() {
191-
if allow_extend && prev_str.len() + first_sep.len() + next_str.len() <= shape.width {
191+
if allow_extend && one_line_width <= shape.width {
192192
result.push_str(first_sep);
193193
} else if !prev_str.is_empty() {
194194
result.push_str(&indent.to_string_with_newline(config))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fn foo() {
2+
with_woff2_glyf_table("tests/fonts/woff2/SFNT-TTF-Composite.woff2", |glyf| {
3+
let actual = glyf
4+
.records
5+
.iter()
6+
.map(|glyph| match glyph {
7+
GlyfRecord::Parsed(
8+
found @ Glyph {
9+
data: GlyphData::Composite { .. },
10+
..
11+
},
12+
) => Some(found),
13+
_ => None,
14+
})
15+
.find(|candidate| candidate.is_some())
16+
.unwrap()
17+
.unwrap();
18+
19+
assert_eq!(*actual, expected)
20+
});
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
fn bindings() {
2+
let err = match (place_desc, explanation) {
3+
(
4+
Some(ref name),
5+
BorrowExplanation::MustBeValidFor {
6+
category:
7+
category @ (ConstraintCategory::Return
8+
| ConstraintCategory::CallArgument
9+
| ConstraintCategory::OpaqueType),
10+
from_closure: false,
11+
ref region_name,
12+
span,
13+
..
14+
},
15+
) if borrow_spans.for_generator() | borrow_spans.for_closure() => self
16+
.report_escaping_closure_capture(
17+
borrow_spans,
18+
borrow_span,
19+
region_name,
20+
category,
21+
span,
22+
&format!("`{}`", name),
23+
),
24+
(
25+
ref name,
26+
BorrowExplanation::MustBeValidFor {
27+
category: ConstraintCategory::Assignment,
28+
from_closure: false,
29+
region_name:
30+
RegionName {
31+
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, ref upvar_name),
32+
..
33+
},
34+
span,
35+
..
36+
},
37+
) => self.report_escaping_data(borrow_span, name, upvar_span, upvar_name, span),
38+
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
39+
location,
40+
&name,
41+
&borrow,
42+
drop_span,
43+
borrow_spans,
44+
explanation,
45+
),
46+
(None, explanation) => self.report_temporary_value_does_not_live_long_enough(
47+
location,
48+
&borrow,
49+
drop_span,
50+
borrow_spans,
51+
proper_span,
52+
explanation,
53+
),
54+
};
55+
}

0 commit comments

Comments
 (0)