-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
inline_format_args.rs
101 lines (95 loc) · 3.53 KB
/
inline_format_args.rs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// run-rustfix
#![allow(clippy::eq_op)]
#![allow(clippy::format_in_format_args)]
#![allow(clippy::print_literal)]
#![allow(named_arguments_used_positionally)]
#![allow(unused_variables)]
#![warn(clippy::inline_format_args)]
fn tester(fn_arg: i32) {
let local_value = 1;
let local_value2 = 2.0;
let local_opt:Option<i32> = Some(3);
let width = 4;
let prec = 5;
let val = 6;
// make sure this file hasn't been corrupted with tabs converted to spaces
assert_eq!(" ", "\t \t");
println!("val='{}'", local_value);
println!("val='{ }'", local_value);
println!("val='{ }'", local_value);
println!("val='{ }'", local_value);
println!("val='{ }'", local_value);
println!("val='{\t }'", local_value);
println!("val='{\n }'", local_value);
println!("val='{
}'", local_value);
println!("val='{local_value}'", local_value=local_value);
println!("val='{local_value}'", local_value=fn_arg);
println!("{}", local_value);
println!("{}", fn_arg);
println!("{:?}", local_value);
println!("{:#?}", local_value);
println!("{:4}", local_value);
println!("{:04}", local_value);
println!("{:<3}", local_value);
println!("{:#010x}", local_value);
println!("{:.1}", local_value2);
println!("Hello {} is {:.*}", "x", local_value, local_value2);
println!("{0}", local_value);
println!("{0:?}", local_value);
println!("{0:#?}", local_value);
println!("{0:04}", local_value);
println!("{0:<3}", local_value);
println!("{0:#010x}", local_value);
println!("{0:.1}", local_value2);
println!("{0} {0}", local_value);
println!("{} {}", local_value, local_value2);
println!("{1} {} {0} {}", local_value, local_value2);
println!("{0} {1}", local_value, local_value2);
println!("{1} {0}", local_value, local_value2);
println!("{1} {0} {1} {0}", local_value, local_value2);
println!("{}", local_opt.unwrap());
println!("{}, {}", local_value, local_opt.unwrap());
println!("{1} {0}", "str", local_value);
println!("{v}", v = local_value);
println!("{local_value:0$}", width);
println!("{local_value:w$}", w = width);
println!("{local_value:.0$}", prec);
println!("{local_value:.p$}", p = prec);
println!("{:0$}", width);
println!("{}", val);
println!("{}", v = val);
println!("{:0$}", v = val);
println!("{0:0$}", v = val);
println!("{:0$.0$}", v = val);
println!("{0:0$.0$}", v = val);
println!("{0:0$.v$}", v = val);
println!("{0:v$.0$}", v = val);
println!("{v:0$.0$}", v = val);
println!("{v:v$.0$}", v = val);
println!("{v:0$.v$}", v = val);
println!("{v:v$.v$}", v = val);
println!("{:w$}", w = width);
println!("{:.0$}", prec);
println!("{:.p$}", p = prec);
println!("{:0$.1$}", width, prec);
println!("{:0$.w$}", width, w = prec);
println!("{:1$.2$}", local_value2, width, prec);
// These cases crash rustc, but they were fixed in a recent nightly
// https://github.com/rust-lang/rust/issues/99633
// TODO: uncomment these once clippy switches to the 1.63+ (64+?)
// println!("{:p$.w$}", local_value, w = width, p = prec);
// println!("{:p$.w$}", p = width, w = prec);
println!("{}", format!("{}", local_value));
// Should not be changed
println!(concat!("nope ", "{}"), local_value);
println!("val='{local_value}'");
println!("val='{local_value }'");
println!("val='{local_value }'"); // with tab
println!("val='{local_value\n}'");
println!("val='{local_value
}'");
}
fn main() {
tester(42);
}