Skip to content

Commit 99f14a8

Browse files
authored
Merge pull request #2029 from wada314/fix-crlf
Fix broken tests under CRLF environment.
2 parents 81f0e9c + 25d2671 commit 99f14a8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use types::join_bounds;
3333
use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi,
3434
format_constness, format_defaultness, format_mutability, format_unsafety,
3535
format_visibility, is_attributes_extendable, last_line_contains_single_line_comment,
36-
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, stmt_expr,
37-
trim_newlines, trimmed_last_line_width};
36+
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
37+
stmt_expr, trim_newlines, trimmed_last_line_width};
3838
use vertical::rewrite_with_alignment;
3939
use visitor::FmtVisitor;
4040

@@ -1985,7 +1985,7 @@ fn rewrite_fn_base(
19851985
// Try to preserve the layout of the original snippet.
19861986
let original_starts_with_newline = snippet
19871987
.find(|c| c != ' ')
1988-
.map_or(false, |i| snippet[i..].starts_with('\n'));
1988+
.map_or(false, |i| starts_with_newline(&snippet[i..]));
19891989
let original_ends_with_newline = snippet
19901990
.rfind(|c| c != ' ')
19911991
.map_or(false, |i| snippet[i..].ends_with('\n'));

src/lists.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use comment::{find_comment_end, rewrite_comment, FindUncommented};
1717
use config::{Config, IndentStyle};
1818
use rewrite::RewriteContext;
1919
use shape::{Indent, Shape};
20-
use utils::{first_line_width, last_line_width, mk_sp};
20+
use utils::{first_line_width, last_line_width, mk_sp, starts_with_newline};
2121

2222
/// Formatting tactic for lists. This will be cast down to a
2323
/// `DefinitiveListTactic` depending on the number and length of the items and
@@ -425,7 +425,7 @@ where
425425

426426
let mut formatted_comment = try_opt!(rewrite_post_comment(&mut item_max_width));
427427

428-
if !formatted_comment.starts_with('\n') {
428+
if !starts_with_newline(&formatted_comment) {
429429
let mut comment_alignment =
430430
post_comment_alignment(item_max_width, inner_item.len());
431431
if first_line_width(&formatted_comment) + last_line_width(&result)

src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,7 @@ pub fn isatty() -> bool {
495495
kernel32::GetConsoleMode(handle, &mut out) != 0
496496
}
497497
}
498+
499+
pub fn starts_with_newline(s: &str) -> bool {
500+
s.starts_with('\n') || s.starts_with("\r\n")
501+
}

0 commit comments

Comments
 (0)