Skip to content
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

write!() -> writeln!() invalid when just printing a newline #6612

Closed
ChrisJefferson opened this issue Jan 20, 2021 · 4 comments
Closed

write!() -> writeln!() invalid when just printing a newline #6612

ChrisJefferson opened this issue Jan 20, 2021 · 4 comments
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ChrisJefferson
Copy link

ChrisJefferson commented Jan 20, 2021

This is visible on both stable and nightly. When advising changing write! to writeln!, the clippy outputs no string but still prints the comma. There has to either be no comma after out_file.

warning: using `write!()` with a format string that ends in a single newline
  --> src/gap_chat.rs:80:9
   |
80 |         write!(gap_channel.out_file, "\n").unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::write_with_newline)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline
help: use `writeln!()` instead
   |
80 |         writeln!(gap_channel.out_file, ).unwrap();
   |         ^^^^^^^                       --

warning: 1 warning emitted
@ChrisJefferson ChrisJefferson added the C-bug Category: Clippy is not doing the correct thing label Jan 20, 2021
@giraffate giraffate added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label Jan 20, 2021
@giraffate
Copy link
Contributor

giraffate commented Jan 20, 2021

Oh, it seems to work even if there is nothing after comma in writeln!. I didn't know that.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9d3870a528373142c2b00ca7f8c7bc7b

@giraffate giraffate added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages and removed I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Jan 20, 2021
@ChrisJefferson
Copy link
Author

ChrisJefferson commented Jan 21, 2021

Yes, at first I thought the bug was no empty string, then when I put an empty string in clippy said (correctly) "Hey, you can remove that empty string!".

@camsteffen camsteffen added the L-suggestion Lint: Improving, adding or fixing lint suggestions label Feb 1, 2021
@camsteffen camsteffen added good-first-issue These issues are a good way to get started with Clippy and removed C-bug Category: Clippy is not doing the correct thing labels Feb 18, 2021
@th1000s
Copy link
Contributor

th1000s commented May 6, 2021

Fixed in #7183 - however by manually constructing a Span which also removes the comma, not by making check_tts also return the comma as that function is already complex enough.

@GuillaumeGomez
Copy link
Member

@flip1995 Can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

6 participants