blob: e7f208e78d203e783c71a00d77fdcb06b7d4532d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#![allow(unused)]
#![warn(clippy::read_line_without_trim)]
fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
input.pop();
let _x: i32 = input.parse().unwrap(); // don't trigger here, newline character is popped
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x: i32 = input.trim_end().parse().unwrap();
//~^ read_line_without_trim
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<i32>().unwrap();
//~^ read_line_without_trim
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<u32>().unwrap();
//~^ read_line_without_trim
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<f32>().unwrap();
//~^ read_line_without_trim
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let _x = input.trim_end().parse::<bool>().unwrap();
//~^ read_line_without_trim
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
// this is actually ok, so don't lint here
let _x = input.parse::<String>().unwrap();
// comparing with string literals
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
if input.trim_end() == "foo" {
//~^ read_line_without_trim
println!("This will never ever execute!");
}
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
if input.trim_end().ends_with("foo") {
//~^ read_line_without_trim
println!("Neither will this");
}
}
|