fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![warn(clippy::explicit_write)] 2#![allow(unused_imports)] 3#![allow(clippy::uninlined_format_args)] 4 5fn stdout() -> String { 6 String::new() 7} 8 9fn stderr() -> String { 10 String::new() 11} 12 13macro_rules! one { 14 () => { 15 1 16 }; 17} 18 19fn main() { 20 // these should warn 21 { 22 use std::io::Write; 23 print!("test"); 24 eprint!("test"); 25 println!("test"); 26 eprintln!("test"); 27 print!("test"); 28 eprint!("test"); 29 30 // including newlines 31 println!("test\ntest"); 32 eprintln!("test\ntest"); 33 34 let value = 1; 35 eprintln!("with {}", value); 36 eprintln!("with {} {}", 2, value); 37 eprintln!("with {value}"); 38 eprintln!("macro arg {}", one!()); 39 let width = 2; 40 eprintln!("{:w$}", value, w = width); 41 } 42 // these should not warn, different destination 43 { 44 use std::fmt::Write; 45 let mut s = String::new(); 46 write!(s, "test").unwrap(); 47 write!(s, "test").unwrap(); 48 writeln!(s, "test").unwrap(); 49 writeln!(s, "test").unwrap(); 50 s.write_fmt(format_args!("test")).unwrap(); 51 s.write_fmt(format_args!("test")).unwrap(); 52 write!(stdout(), "test").unwrap(); 53 write!(stderr(), "test").unwrap(); 54 writeln!(stdout(), "test").unwrap(); 55 writeln!(stderr(), "test").unwrap(); 56 stdout().write_fmt(format_args!("test")).unwrap(); 57 stderr().write_fmt(format_args!("test")).unwrap(); 58 } 59 // these should not warn, no unwrap 60 { 61 use std::io::Write; 62 std::io::stdout().write_fmt(format_args!("test")).expect("no stdout"); 63 std::io::stderr().write_fmt(format_args!("test")).expect("no stderr"); 64 } 65}