Skip to content

Suggest eprintln!(…) instead of writeln!(io::stderr(), …) #2083

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

Closed
killercup opened this issue Sep 25, 2017 · 2 comments
Closed

Suggest eprintln!(…) instead of writeln!(io::stderr(), …) #2083

killercup opened this issue Sep 25, 2017 · 2 comments
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-AST Type: Requires working with the AST

Comments

@killercup
Copy link
Member

The error versions of print! and println! have been stable since Rust 1.19. We should suggest using them!

Basically, this:

writeln!(&mut io::stderr(), "foo: {:?}", bar).unwrap();

can be replaced by

eprintln!("foo: {:?}", bar);

We should take care to only suggest this for the default stderr handle, and not, e.g., for one the programmer called .lock() on.

(Inspired by rust-lang/rust#44822)

@oli-obk oli-obk added L-unnecessary Lint: Warn about unnecessary code good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints T-AST Type: Requires working with the AST labels Sep 25, 2017
@ykrivopalov
Copy link

Maybe generalize it on both stdout/stderr:
io::stdout().write_fmt(format_args!(...)).unwrap(); => println!(...);
io::stderr().write_fmt(format_args!(...)).unwrap(); => eprintln!(...);

@oli-obk
Copy link
Contributor

oli-obk commented Oct 17, 2017

Reopening for adding a structured suggestion to the lint in the future

@oli-obk oli-obk reopened this Oct 17, 2017
@phansch phansch self-assigned this Nov 23, 2018
bors added a commit that referenced this issue Dec 12, 2018
…lip1995

Add suggestion for explicit_write lint

Closes #2083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-unnecessary Lint: Warn about unnecessary code T-AST Type: Requires working with the AST
Projects
None yet
Development

No branches or pull requests

5 participants