Skip to content

Commit 25d2671

Browse files
committed
Fix broken tests under CRLF env.
1 parent 687acdf commit 25d2671

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
@@ -31,8 +31,8 @@ use types::join_bounds;
3131
use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi,
3232
format_constness, format_defaultness, format_mutability, format_unsafety,
3333
format_visibility, is_attributes_extendable, last_line_contains_single_line_comment,
34-
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, stmt_expr,
35-
trim_newlines, trimmed_last_line_width};
34+
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
35+
stmt_expr, trim_newlines, trimmed_last_line_width};
3636
use vertical::rewrite_with_alignment;
3737
use visitor::FmtVisitor;
3838

@@ -1940,7 +1940,7 @@ fn rewrite_fn_base(
19401940
// Try to preserve the layout of the original snippet.
19411941
let original_starts_with_newline = snippet
19421942
.find(|c| c != ' ')
1943-
.map_or(false, |i| snippet[i..].starts_with('\n'));
1943+
.map_or(false, |i| starts_with_newline(&snippet[i..]));
19441944
let original_ends_with_newline = snippet
19451945
.rfind(|c| c != ' ')
19461946
.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
@@ -493,3 +493,7 @@ pub fn isatty() -> bool {
493493
kernel32::GetConsoleMode(handle, &mut out) != 0
494494
}
495495
}
496+
497+
pub fn starts_with_newline(s: &str) -> bool {
498+
s.starts_with('\n') || s.starts_with("\r\n")
499+
}

0 commit comments

Comments
 (0)