rust/tests/ui/explicit_write.rs
Yuri Astrakhan eb3970285b fallout: fix tests to allow uninlined_format_args
In order to switch `clippy::uninlined_format_args` from pedantic to
style, all existing tests must not raise a warning. I did not want to
change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

changelog: none
2022-10-02 15:13:22 -04:00

67 lines
2.1 KiB
Rust

// run-rustfix
#![warn(clippy::explicit_write)]
#![allow(unused_imports)]
#![allow(clippy::uninlined_format_args)]
fn stdout() -> String {
String::new()
}
fn stderr() -> String {
String::new()
}
macro_rules! one {
() => {
1
};
}
fn main() {
// these should warn
{
use std::io::Write;
write!(std::io::stdout(), "test").unwrap();
write!(std::io::stderr(), "test").unwrap();
writeln!(std::io::stdout(), "test").unwrap();
writeln!(std::io::stderr(), "test").unwrap();
std::io::stdout().write_fmt(format_args!("test")).unwrap();
std::io::stderr().write_fmt(format_args!("test")).unwrap();
// including newlines
writeln!(std::io::stdout(), "test\ntest").unwrap();
writeln!(std::io::stderr(), "test\ntest").unwrap();
let value = 1;
writeln!(std::io::stderr(), "with {}", value).unwrap();
writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
writeln!(std::io::stderr(), "with {value}").unwrap();
writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
let width = 2;
writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
}
// these should not warn, different destination
{
use std::fmt::Write;
let mut s = String::new();
write!(s, "test").unwrap();
write!(s, "test").unwrap();
writeln!(s, "test").unwrap();
writeln!(s, "test").unwrap();
s.write_fmt(format_args!("test")).unwrap();
s.write_fmt(format_args!("test")).unwrap();
write!(stdout(), "test").unwrap();
write!(stderr(), "test").unwrap();
writeln!(stdout(), "test").unwrap();
writeln!(stderr(), "test").unwrap();
stdout().write_fmt(format_args!("test")).unwrap();
stderr().write_fmt(format_args!("test")).unwrap();
}
// these should not warn, no unwrap
{
use std::io::Write;
std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
}
}