This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -806,7 +806,8 @@ impl<'a> CommentRewrite<'a> {
806806 let should_wrap_comment = self . fmt . config . wrap_comments ( )
807807 && !is_markdown_header_doc_comment
808808 && unicode_str_width ( line) > self . fmt . shape . width
809- && !has_url ( line) ;
809+ && !has_url ( line)
810+ && !is_table_item ( line) ;
810811
811812 if should_wrap_comment {
812813 match rewrite_string ( line, & self . fmt , self . max_width ) {
@@ -941,6 +942,18 @@ fn has_url(s: &str) -> bool {
941942 || REFERENCE_LINK_URL . is_match ( s)
942943}
943944
945+ /// Returns true if the given string may be part of a Markdown talble.
946+ fn is_table_item ( mut s : & str ) -> bool {
947+ // This function may return false positive, but should get its job done in most cases (i.e.
948+ // markdown tables with two column delimiters).
949+ s = s. trim_start ( ) ;
950+ return s. starts_with ( '|' )
951+ && match s. rfind ( '|' ) {
952+ Some ( 0 ) | None => false ,
953+ _ => true ,
954+ } ;
955+ }
956+
944957/// Given the span, rewrite the missing comment inside it if available.
945958/// Note that the given span must only include comments (or leading/trailing whitespaces).
946959pub ( crate ) fn rewrite_missing_comment (
Original file line number Diff line number Diff line change 1+ // rustfmt-wrap_comments: true
2+
3+ /// Table that is > 80 symbols:
4+ ///
5+ /// | table | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
6+ /// |-------|-----------------------------------------------------------------------------|
7+ /// | val | x |
8+ pub struct Item ;
9+
10+ /// Table that is > 80 symbols:
11+ ///
12+ /// | table | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
13+ /// |-------|-----------------------------------------------------------------------------
14+ /// | val | x
15+ pub struct Item ;
You can’t perform that action at this time.
0 commit comments