Skip to content

Commit 87d5992

Browse files
committed
ignore multiline cases
1 parent ddde8fe commit 87d5992

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

clippy_lints/src/format_args.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,12 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> {
337337
fn check_trailing_comma(&self) {
338338
let span = self.macro_call.span;
339339
if let Some(src) = span.get_source_text(self.cx)
340+
&& !src.contains('\n')
340341
&& let Some(src) = src.strip_suffix([')', ']', '}'])
341-
&& let src = src.trim_end_matches(|c: char| c.is_whitespace() && c != '\n')
342+
&& let src = src.trim_end_matches(|c: char| c.is_whitespace())
342343
&& let Some(src) = src.strip_suffix(',')
343344
{
344-
let src = src.trim_end_matches(|c: char| c.is_whitespace() && c != '\n');
345+
let src = src.trim_end_matches(|c: char| c.is_whitespace());
345346
span_lint_and_sugg(
346347
self.cx,
347348
UNNECESSARY_TRAILING_COMMA,

tests/ui/unnecessary_trailing_comma.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ fn simple() {
6262
"very long string to prevent fmt from making it into a single line: {}",
6363
1,
6464
);
65+
66+
print!("{}"
67+
, 1
68+
,);
6569
}
6670

6771
// The macro invocation itself should never be fixed

tests/ui/unnecessary_trailing_comma.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ fn simple() {
6262
"very long string to prevent fmt from making it into a single line: {}",
6363
1,
6464
);
65+
66+
print!("{}"
67+
, 1
68+
,);
6569
}
6670

6771
// The macro invocation itself should never be fixed

0 commit comments

Comments
 (0)