Skip to content

Commit 6685596

Browse files
committed
rm indoc, ignore expanded macros
1 parent ba320c7 commit 6685596

11 files changed

+131
-163
lines changed

Diff for: Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ clap = { version = "3.1", features = ["derive"] }
4646
clippy_utils = { path = "clippy_utils" }
4747
derive-new = "0.5"
4848
if_chain = "1.0"
49-
indoc = "1.0"
5049
itertools = "0.10.1"
5150
quote = "1.0"
5251
serde = { version = "1.0.125", features = ["derive"] }

Diff for: clippy_lints/src/format_args.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
164164
}
165165

166166
fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_site: Span) {
167+
if args.format_string.span.from_expansion() {
168+
return;
169+
}
170+
167171
let mut fixes = Vec::new();
168172
// If any of the arguments are referenced by an index number,
169173
// and that argument is not a simple variable and cannot be inlined,
@@ -204,17 +208,17 @@ fn check_one_arg(cx: &LateContext<'_>, param: &FormatParam<'_>, fixes: &mut Vec<
204208
&& let [segment] = segments
205209
{
206210
let replacement = match param.usage {
207-
FormatParamUsage::Argument => segment.ident.name.to_string(),
211+
FormatParamUsage::Argument => segment.ident.name.to_string(),
208212
FormatParamUsage::Width => format!("{}$", segment.ident.name),
209213
FormatParamUsage::Precision => format!(".{}$", segment.ident.name),
210-
};
211-
fixes.push((param.span, replacement));
212-
let arg_span = expand_past_previous_comma(cx, *span);
213-
fixes.push((arg_span, String::new()));
214-
true // successful inlining, continue checking
215-
} else {
216-
// if we can't inline a numbered argument, we can't continue
217-
param.kind != Numbered
214+
};
215+
fixes.push((param.span, replacement));
216+
let arg_span = expand_past_previous_comma(cx, *span);
217+
fixes.push((arg_span, String::new()));
218+
true // successful inlining, continue checking
219+
} else {
220+
// if we can't inline a numbered argument, we can't continue
221+
param.kind != Numbered
218222
}
219223
}
220224

Diff for: tests/compile-test.rs

-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static TEST_DEPENDENCIES: &[&str] = &[
3737
"tokio",
3838
"parking_lot",
3939
"rustc_semver",
40-
"indoc",
4140
];
4241

4342
// Test dependencies may need an `extern crate` here to ensure that they show up
@@ -53,8 +52,6 @@ extern crate futures;
5352
#[allow(unused_extern_crates)]
5453
extern crate if_chain;
5554
#[allow(unused_extern_crates)]
56-
extern crate indoc;
57-
#[allow(unused_extern_crates)]
5855
extern crate itertools;
5956
#[allow(unused_extern_crates)]
6057
extern crate parking_lot;

Diff for: tests/ui/format_args.fixed

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![allow(clippy::print_literal)]
77
#![warn(clippy::to_string_in_format_args)]
88

9-
use indoc::{indoc, printdoc};
109
use std::io::{stdout, Write};
1110
use std::ops::Deref;
1211
use std::panic::Location;
@@ -113,8 +112,6 @@ fn main() {
113112
println!("error: something failed at {}", my_other_macro!());
114113
// https://github.com/rust-lang/rust-clippy/issues/7903
115114
println!("{foo}{foo:?}", foo = "foo".to_string());
116-
println!(indoc!("{}"), Location::caller());
117-
printdoc!("{}", Location::caller().to_string());
118115
}
119116

120117
fn issue8643(vendor_id: usize, product_id: usize, name: &str) {

Diff for: tests/ui/format_args.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![allow(clippy::print_literal)]
77
#![warn(clippy::to_string_in_format_args)]
88

9-
use indoc::{indoc, printdoc};
109
use std::io::{stdout, Write};
1110
use std::ops::Deref;
1211
use std::panic::Location;
@@ -113,8 +112,6 @@ fn main() {
113112
println!("error: something failed at {}", my_other_macro!());
114113
// https://github.com/rust-lang/rust-clippy/issues/7903
115114
println!("{foo}{foo:?}", foo = "foo".to_string());
116-
println!(indoc!("{}"), Location::caller().to_string());
117-
printdoc!("{}", Location::caller().to_string());
118115
}
119116

120117
fn issue8643(vendor_id: usize, product_id: usize, name: &str) {

Diff for: tests/ui/format_args.stderr

+24-30
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,142 @@
11
error: `to_string` applied to a type that implements `Display` in `format!` args
2-
--> $DIR/format_args.rs:75:72
2+
--> $DIR/format_args.rs:74:72
33
|
44
LL | let _ = format!("error: something failed at {}", Location::caller().to_string());
55
| ^^^^^^^^^^^^ help: remove this
66
|
77
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
88

99
error: `to_string` applied to a type that implements `Display` in `write!` args
10-
--> $DIR/format_args.rs:79:27
10+
--> $DIR/format_args.rs:78:27
1111
|
1212
LL | Location::caller().to_string()
1313
| ^^^^^^^^^^^^ help: remove this
1414

1515
error: `to_string` applied to a type that implements `Display` in `writeln!` args
16-
--> $DIR/format_args.rs:84:27
16+
--> $DIR/format_args.rs:83:27
1717
|
1818
LL | Location::caller().to_string()
1919
| ^^^^^^^^^^^^ help: remove this
2020

2121
error: `to_string` applied to a type that implements `Display` in `print!` args
22-
--> $DIR/format_args.rs:86:63
22+
--> $DIR/format_args.rs:85:63
2323
|
2424
LL | print!("error: something failed at {}", Location::caller().to_string());
2525
| ^^^^^^^^^^^^ help: remove this
2626

2727
error: `to_string` applied to a type that implements `Display` in `println!` args
28-
--> $DIR/format_args.rs:87:65
28+
--> $DIR/format_args.rs:86:65
2929
|
3030
LL | println!("error: something failed at {}", Location::caller().to_string());
3131
| ^^^^^^^^^^^^ help: remove this
3232

3333
error: `to_string` applied to a type that implements `Display` in `eprint!` args
34-
--> $DIR/format_args.rs:88:64
34+
--> $DIR/format_args.rs:87:64
3535
|
3636
LL | eprint!("error: something failed at {}", Location::caller().to_string());
3737
| ^^^^^^^^^^^^ help: remove this
3838

3939
error: `to_string` applied to a type that implements `Display` in `eprintln!` args
40-
--> $DIR/format_args.rs:89:66
40+
--> $DIR/format_args.rs:88:66
4141
|
4242
LL | eprintln!("error: something failed at {}", Location::caller().to_string());
4343
| ^^^^^^^^^^^^ help: remove this
4444

4545
error: `to_string` applied to a type that implements `Display` in `format_args!` args
46-
--> $DIR/format_args.rs:90:77
46+
--> $DIR/format_args.rs:89:77
4747
|
4848
LL | let _ = format_args!("error: something failed at {}", Location::caller().to_string());
4949
| ^^^^^^^^^^^^ help: remove this
5050

5151
error: `to_string` applied to a type that implements `Display` in `assert!` args
52-
--> $DIR/format_args.rs:91:70
52+
--> $DIR/format_args.rs:90:70
5353
|
5454
LL | assert!(true, "error: something failed at {}", Location::caller().to_string());
5555
| ^^^^^^^^^^^^ help: remove this
5656

5757
error: `to_string` applied to a type that implements `Display` in `assert_eq!` args
58-
--> $DIR/format_args.rs:92:73
58+
--> $DIR/format_args.rs:91:73
5959
|
6060
LL | assert_eq!(0, 0, "error: something failed at {}", Location::caller().to_string());
6161
| ^^^^^^^^^^^^ help: remove this
6262

6363
error: `to_string` applied to a type that implements `Display` in `assert_ne!` args
64-
--> $DIR/format_args.rs:93:73
64+
--> $DIR/format_args.rs:92:73
6565
|
6666
LL | assert_ne!(0, 0, "error: something failed at {}", Location::caller().to_string());
6767
| ^^^^^^^^^^^^ help: remove this
6868

6969
error: `to_string` applied to a type that implements `Display` in `panic!` args
70-
--> $DIR/format_args.rs:94:63
70+
--> $DIR/format_args.rs:93:63
7171
|
7272
LL | panic!("error: something failed at {}", Location::caller().to_string());
7373
| ^^^^^^^^^^^^ help: remove this
7474

7575
error: `to_string` applied to a type that implements `Display` in `println!` args
76-
--> $DIR/format_args.rs:95:20
76+
--> $DIR/format_args.rs:94:20
7777
|
7878
LL | println!("{}", X(1).to_string());
7979
| ^^^^^^^^^^^^^^^^ help: use this: `*X(1)`
8080

8181
error: `to_string` applied to a type that implements `Display` in `println!` args
82-
--> $DIR/format_args.rs:96:20
82+
--> $DIR/format_args.rs:95:20
8383
|
8484
LL | println!("{}", Y(&X(1)).to_string());
8585
| ^^^^^^^^^^^^^^^^^^^^ help: use this: `***Y(&X(1))`
8686

8787
error: `to_string` applied to a type that implements `Display` in `println!` args
88-
--> $DIR/format_args.rs:97:24
88+
--> $DIR/format_args.rs:96:24
8989
|
9090
LL | println!("{}", Z(1).to_string());
9191
| ^^^^^^^^^^^^ help: remove this
9292

9393
error: `to_string` applied to a type that implements `Display` in `println!` args
94-
--> $DIR/format_args.rs:98:20
94+
--> $DIR/format_args.rs:97:20
9595
|
9696
LL | println!("{}", x.to_string());
9797
| ^^^^^^^^^^^^^ help: use this: `**x`
9898

9999
error: `to_string` applied to a type that implements `Display` in `println!` args
100-
--> $DIR/format_args.rs:99:20
100+
--> $DIR/format_args.rs:98:20
101101
|
102102
LL | println!("{}", x_ref.to_string());
103103
| ^^^^^^^^^^^^^^^^^ help: use this: `***x_ref`
104104

105105
error: `to_string` applied to a type that implements `Display` in `println!` args
106-
--> $DIR/format_args.rs:101:39
106+
--> $DIR/format_args.rs:100:39
107107
|
108108
LL | println!("{foo}{bar}", foo = "foo".to_string(), bar = "bar");
109109
| ^^^^^^^^^^^^ help: remove this
110110

111111
error: `to_string` applied to a type that implements `Display` in `println!` args
112-
--> $DIR/format_args.rs:102:52
112+
--> $DIR/format_args.rs:101:52
113113
|
114114
LL | println!("{foo}{bar}", foo = "foo", bar = "bar".to_string());
115115
| ^^^^^^^^^^^^ help: remove this
116116

117117
error: `to_string` applied to a type that implements `Display` in `println!` args
118-
--> $DIR/format_args.rs:103:39
118+
--> $DIR/format_args.rs:102:39
119119
|
120120
LL | println!("{foo}{bar}", bar = "bar".to_string(), foo = "foo");
121121
| ^^^^^^^^^^^^ help: remove this
122122

123123
error: `to_string` applied to a type that implements `Display` in `println!` args
124-
--> $DIR/format_args.rs:104:52
124+
--> $DIR/format_args.rs:103:52
125125
|
126126
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string());
127127
| ^^^^^^^^^^^^ help: remove this
128128

129-
error: `to_string` applied to a type that implements `Display` in `println!` args
130-
--> $DIR/format_args.rs:116:46
131-
|
132-
LL | println!(indoc!("{}"), Location::caller().to_string());
133-
| ^^^^^^^^^^^^ help: remove this
134-
135129
error: `to_string` applied to a type that implements `Display` in `format!` args
136-
--> $DIR/format_args.rs:145:38
130+
--> $DIR/format_args.rs:142:38
137131
|
138132
LL | let x = format!("{} {}", a, b.to_string());
139133
| ^^^^^^^^^^^^ help: remove this
140134

141135
error: `to_string` applied to a type that implements `Display` in `println!` args
142-
--> $DIR/format_args.rs:159:24
136+
--> $DIR/format_args.rs:156:24
143137
|
144138
LL | println!("{}", original[..10].to_string());
145139
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use this: `&original[..10]`
146140

147-
error: aborting due to 24 previous errors
141+
error: aborting due to 23 previous errors
148142

Diff for: tests/ui/format_args_unfixable.rs

-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![warn(clippy::format_in_format_args)]
44
#![warn(clippy::to_string_in_format_args)]
55

6-
use indoc::{indoc, printdoc};
76
use std::io::{stdout, Error, ErrorKind, Write};
87
use std::ops::Deref;
98
use std::panic::Location;
@@ -51,11 +50,6 @@ fn main() {
5150
assert_eq!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
5251
assert_ne!(0, 0, "error: {}", format!("something failed at {}", Location::caller()));
5352
panic!("error: {}", format!("something failed at {}", Location::caller()));
54-
panic!(
55-
indoc!("error: {}"),
56-
format!("something failed at {}", Location::caller())
57-
);
58-
printdoc!("error: {}", format!("something failed at {}", Location::caller()));
5953

6054
// negative tests
6155
println!("error: {}", format_args!("something failed at {}", Location::caller()));

0 commit comments

Comments
 (0)