Skip to content

Commit ebf0de7

Browse files
authored
Don't bail out of formatting code blocks if lines are >100 chars (#4339)
2 parents 27b54e9 + 3ba8719 commit ebf0de7

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/formatting/utils.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,6 @@ pub(crate) fn format_code_block(code_snippet: &str, config: &Config) -> Option<F
792792
}
793793
let trimmed_line = if !is_indented {
794794
line
795-
} else if line.len() > config.max_width() {
796-
// If there are lines that are larger than max width, we cannot tell
797-
// whether we have succeeded but have some comments or strings that
798-
// are too long, or we have failed to format code block. We will be
799-
// conservative and just return `None` in this case.
800-
return None;
801795
} else if line.len() > indent_str.len() {
802796
// Make sure that the line has leading whitespaces.
803797
if line.starts_with(indent_str.as_ref()) {
@@ -885,13 +879,6 @@ mod test {
885879
assert!(test_format_inner(format_snippet, snippet, expected));
886880
}
887881

888-
#[test]
889-
fn test_format_code_block_fail() {
890-
#[rustfmt::skip]
891-
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
892-
assert!(format_code_block(code_block, &Config::default()).is_none());
893-
}
894-
895882
#[test]
896883
fn test_format_code_block() {
897884
// simple code block
@@ -942,5 +929,11 @@ false,
942929
)
943930
};";
944931
assert!(test_format_inner(format_code_block, code_block, expected));
932+
933+
#[rustfmt::skip]
934+
let code_block = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
935+
#[rustfmt::skip]
936+
let expected = "this_line_is_100_characters_long_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(x, y, z);";
937+
assert!(test_format_inner(format_code_block, code_block, expected));
945938
}
946939
}

tests/target/issue-4325.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
macro_rules! bad {
2+
() => {
3+
macro_rules! inner {
4+
() => {
5+
// This needs to have a width of over 100 characters to trigger the issue 12345678901
6+
("a", "B")
7+
};
8+
}
9+
};
10+
}

0 commit comments

Comments
 (0)