Skip to content

Commit ebdd925

Browse files
committed
Address review comments
1 parent 9968398 commit ebdd925

13 files changed

+357
-343
lines changed

tests/compile-test.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
165165
fn run_ui() {
166166
let mut config = base_config("ui");
167167
config.rustfix_coverage = true;
168+
// use tests/clippy.toml
168169
let _g = VarGuard::set("CARGO_MANIFEST_DIR", fs::canonicalize("tests").unwrap());
169170
let _threads = VarGuard::set(
170171
"RUST_TEST_THREADS",
@@ -384,13 +385,17 @@ fn check_rustfix_coverage() {
384385
let missing_coverage_path = Path::new("target/debug/test/ui/rustfix_missing_coverage.txt");
385386

386387
if let Ok(missing_coverage_contents) = std::fs::read_to_string(missing_coverage_path) {
387-
assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.is_sorted());
388+
assert!(RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.iter().is_sorted_by_key(Path::new));
388389

389390
for rs_path in missing_coverage_contents.lines() {
390-
let filename = rs_path.strip_prefix("tests/ui/").unwrap();
391+
let filename = Path::new(rs_path).strip_prefix("tests/ui/").unwrap();
391392
assert!(
392-
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS.binary_search(&filename).is_ok(),
393-
"`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation",
393+
RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS
394+
.binary_search_by_key(&filename, Path::new)
395+
.is_ok(),
396+
"`{}` runs `MachineApplicable` diagnostics but is missing a `run-rustfix` annotation. \
397+
Please either add `// run-rustfix` at the top of file or add the file to \
398+
`RUSTFIX_COVERAGE_KNOWN_EXCEPTIONS`.",
394399
rs_path,
395400
);
396401
}

tests/ui/needless_late_init.fixed

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// run-rustfix
22
#![feature(let_chains)]
3-
#![allow(unused, clippy::nonminimal_bool, clippy::let_unit_value, clippy::let_and_return)]
3+
#![allow(
4+
unused,
5+
clippy::assign_op_pattern,
6+
clippy::let_and_return,
7+
clippy::let_unit_value,
8+
clippy::nonminimal_bool
9+
)]
410

511
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
612
use std::rc::Rc;
@@ -230,3 +236,23 @@ fn does_not_lint() {
230236
let y = SignificantDrop;
231237
x = SignificantDrop;
232238
}
239+
240+
mod fixable {
241+
#![allow(dead_code)]
242+
243+
fn main() {
244+
245+
let a = "zero";
246+
247+
248+
249+
let b = 1;
250+
let c = 2;
251+
252+
253+
let d: usize = 1;
254+
255+
256+
let e = format!("{}", d);
257+
}
258+
}

tests/ui/needless_late_init.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// run-rustfix
22
#![feature(let_chains)]
3-
#![allow(unused, clippy::nonminimal_bool, clippy::let_unit_value, clippy::let_and_return)]
3+
#![allow(
4+
unused,
5+
clippy::assign_op_pattern,
6+
clippy::let_and_return,
7+
clippy::let_unit_value,
8+
clippy::nonminimal_bool
9+
)]
410

511
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
612
use std::rc::Rc;
@@ -230,3 +236,23 @@ fn does_not_lint() {
230236
let y = SignificantDrop;
231237
x = SignificantDrop;
232238
}
239+
240+
mod fixable {
241+
#![allow(dead_code)]
242+
243+
fn main() {
244+
let a;
245+
a = "zero";
246+
247+
let b;
248+
let c;
249+
b = 1;
250+
c = 2;
251+
252+
let d: usize;
253+
d = 1;
254+
255+
let e;
256+
e = format!("{}", d);
257+
}
258+
}

tests/ui/needless_late_init.stderr

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unneeded late initialization
2-
--> $DIR/needless_late_init.rs:16:5
2+
--> $DIR/needless_late_init.rs:22:5
33
|
44
LL | let a;
55
| ^^^^^^
@@ -21,7 +21,7 @@ LL | };
2121
| +
2222

2323
error: unneeded late initialization
24-
--> $DIR/needless_late_init.rs:25:5
24+
--> $DIR/needless_late_init.rs:31:5
2525
|
2626
LL | let b;
2727
| ^^^^^^
@@ -42,7 +42,7 @@ LL | };
4242
| +
4343

4444
error: unneeded late initialization
45-
--> $DIR/needless_late_init.rs:32:5
45+
--> $DIR/needless_late_init.rs:38:5
4646
|
4747
LL | let d;
4848
| ^^^^^^
@@ -63,7 +63,7 @@ LL | };
6363
| +
6464

6565
error: unneeded late initialization
66-
--> $DIR/needless_late_init.rs:40:5
66+
--> $DIR/needless_late_init.rs:46:5
6767
|
6868
LL | let e;
6969
| ^^^^^^
@@ -84,7 +84,7 @@ LL | };
8484
| +
8585

8686
error: unneeded late initialization
87-
--> $DIR/needless_late_init.rs:47:5
87+
--> $DIR/needless_late_init.rs:53:5
8888
|
8989
LL | let f;
9090
| ^^^^^^
@@ -100,7 +100,7 @@ LL + 1 => "three",
100100
|
101101

102102
error: unneeded late initialization
103-
--> $DIR/needless_late_init.rs:53:5
103+
--> $DIR/needless_late_init.rs:59:5
104104
|
105105
LL | let g: usize;
106106
| ^^^^^^^^^^^^^
@@ -120,7 +120,7 @@ LL | };
120120
| +
121121

122122
error: unneeded late initialization
123-
--> $DIR/needless_late_init.rs:61:5
123+
--> $DIR/needless_late_init.rs:67:5
124124
|
125125
LL | let x;
126126
| ^^^^^^ created here
@@ -134,7 +134,7 @@ LL | let x = 1;
134134
| ~~~~~
135135

136136
error: unneeded late initialization
137-
--> $DIR/needless_late_init.rs:65:5
137+
--> $DIR/needless_late_init.rs:71:5
138138
|
139139
LL | let x;
140140
| ^^^^^^ created here
@@ -148,7 +148,7 @@ LL | let x = SignificantDrop;
148148
| ~~~~~
149149

150150
error: unneeded late initialization
151-
--> $DIR/needless_late_init.rs:69:5
151+
--> $DIR/needless_late_init.rs:75:5
152152
|
153153
LL | let x;
154154
| ^^^^^^ created here
@@ -162,7 +162,7 @@ LL | let x = SignificantDrop;
162162
| ~~~~~
163163

164164
error: unneeded late initialization
165-
--> $DIR/needless_late_init.rs:88:5
165+
--> $DIR/needless_late_init.rs:94:5
166166
|
167167
LL | let a;
168168
| ^^^^^^
@@ -183,7 +183,7 @@ LL | };
183183
| +
184184

185185
error: unneeded late initialization
186-
--> $DIR/needless_late_init.rs:105:5
186+
--> $DIR/needless_late_init.rs:111:5
187187
|
188188
LL | let a;
189189
| ^^^^^^
@@ -203,5 +203,72 @@ help: add a semicolon after the `match` expression
203203
LL | };
204204
| +
205205

206-
error: aborting due to 11 previous errors
206+
error: unneeded late initialization
207+
--> $DIR/needless_late_init.rs:244:9
208+
|
209+
LL | let a;
210+
| ^^^^^^ created here
211+
LL | a = "zero";
212+
| ^^^^^^^^^^ initialised here
213+
|
214+
help: declare `a` here
215+
|
216+
LL | let a = "zero";
217+
| ~~~~~
218+
219+
error: unneeded late initialization
220+
--> $DIR/needless_late_init.rs:247:9
221+
|
222+
LL | let b;
223+
| ^^^^^^ created here
224+
LL | let c;
225+
LL | b = 1;
226+
| ^^^^^ initialised here
227+
|
228+
help: declare `b` here
229+
|
230+
LL | let b = 1;
231+
| ~~~~~
232+
233+
error: unneeded late initialization
234+
--> $DIR/needless_late_init.rs:248:9
235+
|
236+
LL | let c;
237+
| ^^^^^^ created here
238+
LL | b = 1;
239+
LL | c = 2;
240+
| ^^^^^ initialised here
241+
|
242+
help: declare `c` here
243+
|
244+
LL | let c = 2;
245+
| ~~~~~
246+
247+
error: unneeded late initialization
248+
--> $DIR/needless_late_init.rs:252:9
249+
|
250+
LL | let d: usize;
251+
| ^^^^^^^^^^^^^ created here
252+
LL | d = 1;
253+
| ^^^^^ initialised here
254+
|
255+
help: declare `d` here
256+
|
257+
LL | let d: usize = 1;
258+
| ~~~~~~~~~~~~
259+
260+
error: unneeded late initialization
261+
--> $DIR/needless_late_init.rs:255:9
262+
|
263+
LL | let e;
264+
| ^^^^^^ created here
265+
LL | e = format!("{}", d);
266+
| ^^^^^^^^^^^^^^^^^^^^ initialised here
267+
|
268+
help: declare `e` here
269+
|
270+
LL | let e = format!("{}", d);
271+
| ~~~~~
272+
273+
error: aborting due to 16 previous errors
207274

tests/ui/needless_late_init_fixable.fixed

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/ui/needless_late_init_fixable.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/ui/needless_late_init_fixable.stderr

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)