Skip to content

Commit

Permalink
new to_iter lint, still WIP but should supercede the previous for_eac…
Browse files Browse the repository at this point in the history
…h lint
  • Loading branch information
Cameron-Low committed Mar 28, 2024
1 parent a1a586d commit 4f0f5a1
Show file tree
Hide file tree
Showing 14 changed files with 920 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
to_iter = { path = "lints/to_iter", features = ["rlib"] }
for_each = { path = "lints/for_each", features = ["rlib"] }
filter = { path = "lints/filter", features = ["rlib"] }
map = { path = "lints/map", features = ["rlib"] }
Expand All @@ -32,6 +33,7 @@ rustc_private = true
[workspace]
members = [
"lints/rayon_imports",
"lints/to_iter",
"lints/for_each",
"lints/filter",
"lints/map",
Expand Down
11 changes: 11 additions & 0 deletions lints/par_iter/ui/main.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,14 @@ fn mut_var_declared_in_closure() {
.collect();
println!("{:?}", doubled_numbers);
}

// should parallelize
fn return_loop() -> Option<()> {
let num_workers = 10;
let locals = vec![1, 2, 3, 4, 5];
(0..num_workers).into_par_iter().try_for_each(|index| {
let item = locals.get(index)?;
return Some(());
})?;
Some(())
}
11 changes: 11 additions & 0 deletions lints/par_iter/ui/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,14 @@ fn mut_var_declared_in_closure() {
.collect();
println!("{:?}", doubled_numbers);
}

// should parallelize
fn return_loop() -> Option<()> {
let num_workers = 10;
let locals = vec![1, 2, 3, 4, 5];
(0..num_workers).into_iter().try_for_each(|index| {
let item = locals.get(index)?;
return Some(());
})?;
Some(())
}
8 changes: 7 additions & 1 deletion lints/par_iter/ui/main.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,11 @@ LL ~ let doubled_numbers: Vec<i32> = numbers
LL + .into_par_iter()
|

warning: 14 warnings emitted
warning: found iterator that can be parallelized
--> $DIR/main.rs:486:5
|
LL | (0..num_workers).into_iter().try_for_each(|index| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using a parallel iterator: `(0..num_workers).into_par_iter()`

warning: 15 warnings emitted

1 change: 1 addition & 0 deletions lints/to_iter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
31 changes: 31 additions & 0 deletions lints/to_iter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "to_iter"
version = "0.1.0"
authors = ["authors go here"]
description = "description goes here"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
dylint_linting = "3.0.0"

clippy_utils = { workspace = true }
utils = { workspace = true }
[dev-dependencies]
dylint_testing = "3.0.0"

[package.metadata.rust-analyzer]
rustc_private = true

[features]
rlib = ["dylint_linting/constituent"]

[[example]]
name = "to_iter_main"
path = "ui/main.rs"

[lints]
workspace = true
17 changes: 17 additions & 0 deletions lints/to_iter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# template

### What it does

### Why is this bad?

### Known problems
Remove if none.

### Example
```rust
// example code where a warning is issued
```
Use instead:
```rust
// example code that does not raise a warning
```
Loading

0 comments on commit 4f0f5a1

Please sign in to comment.