Skip to content

Commit 172aca4

Browse files
committed
fixup! Don't wrap comments that are part of a table
1 parent ca9d47c commit 172aca4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: rustfmt-core/rustfmt-lib/src/formatting/comment.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -869,9 +869,15 @@ fn has_url(s: &str) -> bool {
869869
}
870870

871871
/// Returns true if the given string may be part of a Markdown talble.
872-
fn is_table_item(s: &str) -> bool {
873-
// This function may return false positive, but should get its job done in most cases.
874-
s.trim_start().starts_with('|')
872+
fn is_table_item(mut s: &str) -> bool {
873+
// This function may return false positive, but should get its job done in most cases (i.e.
874+
// markdown tables with two column delimiters).
875+
s = s.trim_start();
876+
return s.starts_with('|')
877+
&& match s.rfind('|') {
878+
Some(0) | None => false,
879+
_ => true,
880+
};
875881
}
876882

877883
/// Given the span, rewrite the missing comment inside it if available.

0 commit comments

Comments
 (0)