Skip to content

Commit e93280e

Browse files
committed
simple ignore return
1 parent 1d23284 commit e93280e

File tree

6 files changed

+75
-103
lines changed

6 files changed

+75
-103
lines changed

lints/par_iter/src/lib.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ mod constants;
1515
mod utils;
1616
mod variable_check;
1717

18-
use clippy_utils::mir::expr_local;
19-
use clippy_utils::{expr_use_ctxt, get_parent_expr, get_trait_def_id, ExprUseNode};
18+
use clippy_utils::{get_parent_expr, get_trait_def_id};
2019
use rustc_data_structures::fx::FxHashSet;
2120
use rustc_errors::Applicability;
2221
use rustc_hir::intravisit::Visitor;
@@ -119,14 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for ParIter {
119118

120119
// TODO: this needs to change and find a better solutions for returns
121120
if let TyKind::Adt(_, _) = ty.kind() {
122-
if let Some(_local) = expr_local(cx.tcx, top_expr) {
123-
return;
124-
}
125-
if let Some(top_cx) = expr_use_ctxt(cx, top_expr) {
126-
if matches!(top_cx.node, ExprUseNode::Return(_)) {
127-
return;
128-
}
129-
}
121+
return;
130122
}
131123

132124
let mut validator = Validator { cx, is_valid: true };

lints/par_iter/ui/main.fixed

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -250,42 +250,6 @@ fn simple_fold() {
250250
println!("Sum: {}", sum);
251251
}
252252

253-
// should parallelize
254-
fn collect_at_end() {
255-
let people = vec![
256-
Person {
257-
name: "Alice".to_string(),
258-
age: 25,
259-
},
260-
Person {
261-
name: "Bob".to_string(),
262-
age: 35,
263-
},
264-
Person {
265-
name: "Carol".to_string(),
266-
age: 32,
267-
},
268-
];
269-
270-
let names: Vec<String> = people.par_iter().map(|p| p.name.clone()).collect();
271-
272-
println!("{:?}", names);
273-
}
274-
275-
// should parallelize
276-
fn mut_var_declared_in_closure() {
277-
let numbers = vec![1, 2, 3, 4, 5];
278-
let doubled_numbers: Vec<i32> = numbers
279-
.into_par_iter()
280-
.map(|num| {
281-
let mut doubled = num * 2; // Mutable variable inside the closure
282-
doubled += 1; // Modify the mutable variable
283-
doubled // Return the modified value
284-
})
285-
.collect();
286-
println!("{:?}", doubled_numbers);
287-
}
288-
289253
// no
290254
fn request_request_filter() {
291255
let case = Case {

lints/par_iter/ui/main.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -250,42 +250,6 @@ fn simple_fold() {
250250
println!("Sum: {}", sum);
251251
}
252252

253-
// should parallelize
254-
fn collect_at_end() {
255-
let people = vec![
256-
Person {
257-
name: "Alice".to_string(),
258-
age: 25,
259-
},
260-
Person {
261-
name: "Bob".to_string(),
262-
age: 35,
263-
},
264-
Person {
265-
name: "Carol".to_string(),
266-
age: 32,
267-
},
268-
];
269-
270-
let names: Vec<String> = people.iter().map(|p| p.name.clone()).collect();
271-
272-
println!("{:?}", names);
273-
}
274-
275-
// should parallelize
276-
fn mut_var_declared_in_closure() {
277-
let numbers = vec![1, 2, 3, 4, 5];
278-
let doubled_numbers: Vec<i32> = numbers
279-
.into_iter()
280-
.map(|num| {
281-
let mut doubled = num * 2; // Mutable variable inside the closure
282-
doubled += 1; // Modify the mutable variable
283-
doubled // Return the modified value
284-
})
285-
.collect();
286-
println!("{:?}", doubled_numbers);
287-
}
288-
289253
// no
290254
fn request_request_filter() {
291255
let case = Case {

lints/par_iter/ui/main.stderr

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,5 @@ error: found iterator that can be parallelized
4444
LL | numbers.iter().enumerate().for_each(|t| {
4545
| ^^^^^^^^^^^^^^ help: try using a parallel iterator: `numbers.par_iter()`
4646

47-
error: found iterator that can be parallelized
48-
--> $DIR/main.rs:270:30
49-
|
50-
LL | let names: Vec<String> = people.iter().map(|p| p.name.clone()).collect();
51-
| ^^^^^^^^^^^^^ help: try using a parallel iterator: `people.par_iter()`
52-
53-
error: found iterator that can be parallelized
54-
--> $DIR/main.rs:278:37
55-
|
56-
LL | let doubled_numbers: Vec<i32> = numbers
57-
| _____________________________________^
58-
LL | | .into_iter()
59-
| |____________________^
60-
|
61-
help: try using a parallel iterator
62-
|
63-
LL ~ let doubled_numbers: Vec<i32> = numbers
64-
LL + .into_par_iter()
65-
|
66-
67-
error: aborting due to 8 previous errors
47+
error: aborting due to 6 previous errors
6848

lints/par_iter/ui/main2.fixed

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,39 @@ fn main() {}
8585
// pub fn iter_returned_in_variable() {
8686
// let _: Range<i32> = (0..100).into_iter();
8787
// }
88+
89+
// // should parallelize
90+
// fn mut_var_declared_in_closure() {
91+
// let numbers = vec![1, 2, 3, 4, 5];
92+
// let doubled_numbers: Vec<i32> = numbers
93+
// .into_iter()
94+
// .map(|num| {
95+
// let mut doubled = num * 2; // Mutable variable inside the closure
96+
// doubled += 1; // Modify the mutable variable
97+
// doubled // Return the modified value
98+
// })
99+
// .collect();
100+
// println!("{:?}", doubled_numbers);
101+
// }
102+
//
103+
// // should parallelize
104+
// fn collect_at_end() {
105+
// let people = vec![
106+
// Person {
107+
// name: "Alice".to_string(),
108+
// age: 25,
109+
// },
110+
// Person {
111+
// name: "Bob".to_string(),
112+
// age: 35,
113+
// },
114+
// Person {
115+
// name: "Carol".to_string(),
116+
// age: 32,
117+
// },
118+
// ];
119+
120+
// let names: Vec<String> = people.iter().map(|p| p.name.clone()).collect();
121+
122+
// println!("{:?}", names);
123+
// }

lints/par_iter/ui/main2.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,39 @@ fn main() {}
8585
// pub fn iter_returned_in_variable() {
8686
// let _: Range<i32> = (0..100).into_iter();
8787
// }
88+
89+
// // should parallelize
90+
// fn mut_var_declared_in_closure() {
91+
// let numbers = vec![1, 2, 3, 4, 5];
92+
// let doubled_numbers: Vec<i32> = numbers
93+
// .into_iter()
94+
// .map(|num| {
95+
// let mut doubled = num * 2; // Mutable variable inside the closure
96+
// doubled += 1; // Modify the mutable variable
97+
// doubled // Return the modified value
98+
// })
99+
// .collect();
100+
// println!("{:?}", doubled_numbers);
101+
// }
102+
//
103+
// // should parallelize
104+
// fn collect_at_end() {
105+
// let people = vec![
106+
// Person {
107+
// name: "Alice".to_string(),
108+
// age: 25,
109+
// },
110+
// Person {
111+
// name: "Bob".to_string(),
112+
// age: 35,
113+
// },
114+
// Person {
115+
// name: "Carol".to_string(),
116+
// age: 32,
117+
// },
118+
// ];
119+
120+
// let names: Vec<String> = people.iter().map(|p| p.name.clone()).collect();
121+
122+
// println!("{:?}", names);
123+
// }

0 commit comments

Comments
 (0)