Skip to content

Commit e90b977

Browse files
committed
Fix FP in unnecessary_lazy_evaluations
1 parent c1664c5 commit e90b977

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

clippy_lints/src/utils/usage.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,27 @@ pub struct ParamBindingIdCollector {
116116
}
117117
impl<'tcx> ParamBindingIdCollector {
118118
fn collect_binding_hir_ids(body: &'tcx hir::Body<'tcx>) -> Vec<hir::HirId> {
119-
let mut finder = ParamBindingIdCollector {
120-
binding_hir_ids: Vec::new(),
121-
};
122-
finder.visit_body(body);
123-
finder.binding_hir_ids
119+
let mut hir_ids: Vec<hir::HirId> = Vec::new();
120+
for param in body.params.iter() {
121+
let mut finder = ParamBindingIdCollector {
122+
binding_hir_ids: Vec::new(),
123+
};
124+
finder.visit_param(param);
125+
for hir_id in &finder.binding_hir_ids {
126+
hir_ids.push(*hir_id);
127+
}
128+
}
129+
hir_ids
124130
}
125131
}
126132
impl<'tcx> intravisit::Visitor<'tcx> for ParamBindingIdCollector {
127133
type Map = Map<'tcx>;
128134

129-
fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
130-
if let hir::PatKind::Binding(_, hir_id, ..) = param.pat.kind {
135+
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
136+
if let hir::PatKind::Binding(_, hir_id, ..) = pat.kind {
131137
self.binding_hir_ids.push(hir_id);
132138
}
139+
intravisit::walk_pat(self, pat);
133140
}
134141

135142
fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {

tests/ui/unnecessary_lazy_eval_unfixable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ fn main() {
1515
}
1616
let _ = Ok(1).unwrap_or_else(|e::E| 2);
1717
let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);
18+
19+
// Fix #6343
20+
let arr = [(Some(1),)];
21+
Some(&0).and_then(|&i| arr[i].0);
1822
}

0 commit comments

Comments
 (0)