Skip to content

Commit 4f0f5a1

Browse files
committed
new to_iter lint, still WIP but should supercede the previous for_each lint
1 parent a1a586d commit 4f0f5a1

14 files changed

+920
-3
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ publish = false
1414
crate-type = ["cdylib"]
1515

1616
[dependencies]
17+
to_iter = { path = "lints/to_iter", features = ["rlib"] }
1718
for_each = { path = "lints/for_each", features = ["rlib"] }
1819
filter = { path = "lints/filter", features = ["rlib"] }
1920
map = { path = "lints/map", features = ["rlib"] }
@@ -32,6 +33,7 @@ rustc_private = true
3233
[workspace]
3334
members = [
3435
"lints/rayon_imports",
36+
"lints/to_iter",
3537
"lints/for_each",
3638
"lints/filter",
3739
"lints/map",

lints/par_iter/ui/main.fixed

+11
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,14 @@ fn mut_var_declared_in_closure() {
478478
.collect();
479479
println!("{:?}", doubled_numbers);
480480
}
481+
482+
// should parallelize
483+
fn return_loop() -> Option<()> {
484+
let num_workers = 10;
485+
let locals = vec![1, 2, 3, 4, 5];
486+
(0..num_workers).into_par_iter().try_for_each(|index| {
487+
let item = locals.get(index)?;
488+
return Some(());
489+
})?;
490+
Some(())
491+
}

lints/par_iter/ui/main.rs

+11
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,14 @@ fn mut_var_declared_in_closure() {
478478
.collect();
479479
println!("{:?}", doubled_numbers);
480480
}
481+
482+
// should parallelize
483+
fn return_loop() -> Option<()> {
484+
let num_workers = 10;
485+
let locals = vec![1, 2, 3, 4, 5];
486+
(0..num_workers).into_iter().try_for_each(|index| {
487+
let item = locals.get(index)?;
488+
return Some(());
489+
})?;
490+
Some(())
491+
}

lints/par_iter/ui/main.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,11 @@ LL ~ let doubled_numbers: Vec<i32> = numbers
123123
LL + .into_par_iter()
124124
|
125125

126-
warning: 14 warnings emitted
126+
warning: found iterator that can be parallelized
127+
--> $DIR/main.rs:486:5
128+
|
129+
LL | (0..num_workers).into_iter().try_for_each(|index| {
130+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using a parallel iterator: `(0..num_workers).into_par_iter()`
131+
132+
warning: 15 warnings emitted
127133

lints/to_iter/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

lints/to_iter/Cargo.toml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "to_iter"
3+
version = "0.1.0"
4+
authors = ["authors go here"]
5+
description = "description goes here"
6+
edition = "2021"
7+
publish = false
8+
9+
[lib]
10+
crate-type = ["cdylib", "rlib"]
11+
12+
[dependencies]
13+
dylint_linting = "3.0.0"
14+
15+
clippy_utils = { workspace = true }
16+
utils = { workspace = true }
17+
[dev-dependencies]
18+
dylint_testing = "3.0.0"
19+
20+
[package.metadata.rust-analyzer]
21+
rustc_private = true
22+
23+
[features]
24+
rlib = ["dylint_linting/constituent"]
25+
26+
[[example]]
27+
name = "to_iter_main"
28+
path = "ui/main.rs"
29+
30+
[lints]
31+
workspace = true

lints/to_iter/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# template
2+
3+
### What it does
4+
5+
### Why is this bad?
6+
7+
### Known problems
8+
Remove if none.
9+
10+
### Example
11+
```rust
12+
// example code where a warning is issued
13+
```
14+
Use instead:
15+
```rust
16+
// example code that does not raise a warning
17+
```

0 commit comments

Comments
 (0)