-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
false negative write_with_newline: format string that starts with \n #8741
Comments
@rustbot label +good-first-issue |
@rustbot claim |
Here are some positive test cases: // These should be fine
write!(v, "");
write!(v, "Hello");
writeln!(v, "Hello");
writeln!(v, "Hello\n");
writeln!(v, "Hello {}\n", "world");
write!(v, "Issue\n{}", 1265);
write!(v, "{}", 1265);
write!(v, "\n{}", 1275);
write!(v, "\n\n");
write!(v, "like eof\n\n");
write!(v, "Hello {} {}\n\n", "world", "#2");
writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
writeln!(v, "\nbla\n\n"); // #3126 It seems that write! with multiple \n is allowed by the rule, and it seems like a feature not a bug? I'm not sure whether to fix it. The variable |
Hmm, so it looks like we bail out as soon as there's more than one write!(
output,
"\nSummary of: {} ({} total)\n",
path.display(),
bin_cache
.total_size()
.file_size(file_size_opts::DECIMAL)
.unwrap()
));
)
.unwrap(); |
I’m not sure whether it’s better that only allow multiple line-breaks at the end, instead of allow an internal/begin line-break and a line-break at the end. |
If the answer is yes, I’d like to implement it :( |
🤣 I don't even remember writing that... it has been some time |
Hey everyone 👋🏻, I ended up here because I was looking for an issue to work on, but it looks like #8518 addressed this. Ignoring strings with multiple newlines makes sense to me, FWIW. I guess this issue should be closed now (?). |
Summary
If a format string starts with a
\n
, the lint does not seem to fire.I had a quick glance at the lint code but I didn't see anything that would indicate that this is intentional.
Lint Name
clippy::write_with_newline
Reproducer
I tried this code:
would expect a warning here since we can write
writeln!(s, "\n{}")
Version
The text was updated successfully, but these errors were encountered: