Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'a> FmtVisitor<'a> {
};

let comment_width = ::std::cmp::min(
self.config.comment_width(),
self.config.comment_width() - self.block_indent.width(),
self.config.max_width() - self.block_indent.width(),
);
let comment_shape = Shape::legacy(comment_width, comment_indent);
Expand Down
29 changes: 11 additions & 18 deletions tests/source/issue-5023.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
// rustfmt-wrap_comments: true

// below we try and force a split at a byte in the middle of a multi-byte
// character. The two parts of the first line are constructed such that:
// 1) the entire line is longer than `$comment_width`
// 2) the length of the second part is such that:
// `$comment_width - 3 + $length` is positive _and_ less than the number of
// bytes in the multi-byte char

// xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// 是

/// A comment to test special unicode characters on boundaries
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here this goes to the next line
fn main() {
if xxx {
let xxx = xxx
.into_iter()
.filter(|(xxx, xxx)| {
if let Some(x) = Some(1) {
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
if false {
return true;
}
}
false
})
.collect();
}
}
fn main() {}
7 changes: 7 additions & 0 deletions tests/source/issue_6801.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// rustfmt-wrap_comments: true

fn foo() {
// this is a comment that could be broken right on max_comment and should break before that

()
}
30 changes: 12 additions & 18 deletions tests/target/issue-5023.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
// rustfmt-wrap_comments: true

// below we try and force a split at a byte in the middle of a multi-byte
// character. The two parts of the first line are constructed such that:
// 1) the entire line is longer than `$comment_width`
// 2) the length of the second part is such that:
// `$comment_width - 3 + $length` is positive _and_ less than the number of
// bytes in the multi-byte char

// xxxxxxxxxx
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// 是

/// A comment to test special unicode characters on boundaries
/// 是,是,是,是,是,是,是,是,是,是,是,是 it should break right here
/// this goes to the next line
fn main() {
if xxx {
let xxx = xxx
.into_iter()
.filter(|(xxx, xxx)| {
if let Some(x) = Some(1) {
// xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
// xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
// 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
if false {
return true;
}
}
false
})
.collect();
}
}
fn main() {}
8 changes: 8 additions & 0 deletions tests/target/issue_6801.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true

fn foo() {
// this is a comment that could be broken right on max_comment and should
// break before that

()
}
8 changes: 4 additions & 4 deletions tests/target/trailing_comments/hard_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn lorem_ipsum() {
// nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci
// bibendum enim, a sagittis nulla nunc quis elit. Phasellus augue. Nunc
// suscipit, magna tincidunt lacinia faucibus, lacus tellus ornare purus, a
// pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor faucibus.
// In hac habitasse platea dictumst. Vivamus a orci at nulla tristique
// condimentum. Donec arcu quam, dictum accumsan, convallis accumsan, cursus sit
// amet, ipsum. In pharetra sagittis nunc.
// pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor
// faucibus. In hac habitasse platea dictumst. Vivamus a orci at nulla
// tristique condimentum. Donec arcu quam, dictum accumsan, convallis
// accumsan, cursus sit amet, ipsum. In pharetra sagittis nunc.
let b = baz();

let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0]
Expand Down
8 changes: 4 additions & 4 deletions tests/target/trailing_comments/soft_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn foo() {
// nunc. Mauris consequat, enim vitae venenatis sollicitudin, dolor orci
// bibendum enim, a sagittis nulla nunc quis elit. Phasellus augue. Nunc
// suscipit, magna tincidunt lacinia faucibus, lacus tellus ornare purus, a
// pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor faucibus.
// In hac habitasse platea dictumst. Vivamus a orci at nulla tristique
// condimentum. Donec arcu quam, dictum accumsan, convallis accumsan, cursus sit
// amet, ipsum. In pharetra sagittis nunc.
// pulvinar lacus orci eget nibh. Maecenas sed nibh non lacus tempor
// faucibus. In hac habitasse platea dictumst. Vivamus a orci at nulla
// tristique condimentum. Donec arcu quam, dictum accumsan, convallis
// accumsan, cursus sit amet, ipsum. In pharetra sagittis nunc.
let b = baz();

let normalized = self.ctfont.all_traits().normalized_weight(); // [-1.0, 1.0]
Expand Down
3 changes: 2 additions & 1 deletion tests/target/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ fn foo() {
let s = "this line goes to 100: ͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶͶ";
let s = 42;

// a comment of length 80, with the starting sigil: ҘҘҘҘҘҘҘҘҘҘ ҘҘҘҘҘҘҘҘҘҘҘҘҘҘ
// a comment of length 80, with the starting sigil: ҘҘҘҘҘҘҘҘҘҘ
// ҘҘҘҘҘҘҘҘҘҘҘҘҘҘ
let s = 42;
}

Expand Down
Loading