Skip to content

Commit

Permalink
Fix FP in unnecessary_lazy_evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
giraffate committed Nov 23, 2020
1 parent 0402c6a commit cdbf639
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 14 additions & 7 deletions clippy_lints/src/utils/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,27 @@ pub struct ParamBindingIdCollector {
}
impl<'tcx> ParamBindingIdCollector {
fn collect_binding_hir_ids(body: &'tcx hir::Body<'tcx>) -> Vec<hir::HirId> {
let mut finder = ParamBindingIdCollector {
binding_hir_ids: Vec::new(),
};
finder.visit_body(body);
finder.binding_hir_ids
let mut hir_ids: Vec<hir::HirId> = Vec::new();
for param in body.params.iter() {
let mut finder = ParamBindingIdCollector {
binding_hir_ids: Vec::new(),
};
finder.visit_param(param);
for hir_id in &finder.binding_hir_ids {
hir_ids.push(*hir_id);
}
}
hir_ids
}
}
impl<'tcx> intravisit::Visitor<'tcx> for ParamBindingIdCollector {
type Map = Map<'tcx>;

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
if let hir::PatKind::Binding(_, hir_id, ..) = param.pat.kind {
fn visit_pat(&mut self, pat: &'tcx hir::Pat<'tcx>) {
if let hir::PatKind::Binding(_, hir_id, ..) = pat.kind {
self.binding_hir_ids.push(hir_id);
}
intravisit::walk_pat(self, pat);
}

fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/unnecessary_lazy_eval_unfixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ fn main() {
}
let _ = Ok(1).unwrap_or_else(|e::E| 2);
let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2);

// Fix #6343
let arr = [(Some(1),)];
Some(&0).and_then(|&i| arr[i].0);
}

0 comments on commit cdbf639

Please sign in to comment.