Skip to content

Fix broken tests under CRLF environment. #2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use types::join_bounds;
use utils::{colon_spaces, contains_skip, end_typaram, first_line_width, format_abi,
format_constness, format_defaultness, format_mutability, format_unsafety,
format_visibility, is_attributes_extendable, last_line_contains_single_line_comment,
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, stmt_expr,
trim_newlines, trimmed_last_line_width};
last_line_used_width, last_line_width, mk_sp, semicolon_for_expr, starts_with_newline,
stmt_expr, trim_newlines, trimmed_last_line_width};
use vertical::rewrite_with_alignment;
use visitor::FmtVisitor;

Expand Down Expand Up @@ -1940,7 +1940,7 @@ fn rewrite_fn_base(
// Try to preserve the layout of the original snippet.
let original_starts_with_newline = snippet
.find(|c| c != ' ')
.map_or(false, |i| snippet[i..].starts_with('\n'));
.map_or(false, |i| starts_with_newline(&snippet[i..]));
let original_ends_with_newline = snippet
.rfind(|c| c != ' ')
.map_or(false, |i| snippet[i..].ends_with('\n'));
Expand Down
4 changes: 2 additions & 2 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use comment::{find_comment_end, rewrite_comment, FindUncommented};
use config::{Config, IndentStyle};
use rewrite::RewriteContext;
use shape::{Indent, Shape};
use utils::{first_line_width, last_line_width, mk_sp};
use utils::{first_line_width, last_line_width, mk_sp, starts_with_newline};

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

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

if !formatted_comment.starts_with('\n') {
if !starts_with_newline(&formatted_comment) {
let mut comment_alignment =
post_comment_alignment(item_max_width, inner_item.len());
if first_line_width(&formatted_comment) + last_line_width(&result)
Expand Down
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,7 @@ pub fn isatty() -> bool {
kernel32::GetConsoleMode(handle, &mut out) != 0
}
}

pub fn starts_with_newline(s: &str) -> bool {
s.starts_with('\n') || s.starts_with("\r\n")
}