]> git.lizzy.rs Git - rust.git/blob - tests/ui/write_with_newline.rs
Stabilize tool lints
[rust.git] / tests / ui / write_with_newline.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11
12
13 #![allow(clippy::write_literal)]
14 #![warn(clippy::write_with_newline)]
15
16 use std::io::Write;
17
18 fn main() {
19     let mut v = Vec::new();
20
21     // These should fail
22     write!(&mut v, "Hello\n");
23     write!(&mut v, "Hello {}\n", "world");
24     write!(&mut v, "Hello {} {}\n", "world", "#2");
25     write!(&mut v, "{}\n", 1265);
26
27     // These should be fine
28     write!(&mut v, "");
29     write!(&mut v, "Hello");
30     writeln!(&mut v, "Hello");
31     writeln!(&mut v, "Hello\n");
32     writeln!(&mut v, "Hello {}\n", "world");
33     write!(&mut v, "Issue\n{}", 1265);
34     write!(&mut v, "{}", 1265);
35     write!(&mut v, "\n{}", 1275);
36     write!(&mut v, "\n\n");
37     write!(&mut v, "like eof\n\n");
38     write!(&mut v, "Hello {} {}\n\n", "world", "#2");
39     writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
40     writeln!(&mut v, "\nbla\n\n"); // #3126
41 }