Skip to content

Commit

Permalink
Merge pull request rust-lang#2864 from flip1995/issue-2862
Browse files Browse the repository at this point in the history
Fix panic on map_clone lint
  • Loading branch information
oli-obk authored Jun 21, 2018
2 parents 25510cf + 6224e19 commit 5f5fa08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
ExprClosure(_, ref decl, closure_eid, _, _) => {
let body = cx.tcx.hir.body(closure_eid);
let closure_expr = remove_blocks(&body.value);
let ty = cx.tables.pat_ty(&body.arguments[0].pat);
if_chain! {
// nothing special in the argument, besides reference bindings
// (e.g. .map(|&x| x) )
Expand All @@ -45,6 +44,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// the method is being called on a known type (option or iterator)
if let Some(type_name) = get_type_name(cx, expr, &args[0]);
then {
// We know that body.arguments is not empty at this point
let ty = cx.tables.pat_ty(&body.arguments[0].pat);
// look for derefs, for .map(|x| *x)
if only_derefs(cx, &*closure_expr, arg_ident) &&
// .cloned() only removes one level of indirection, don't lint on more
Expand Down
14 changes: 14 additions & 0 deletions tests/run-pass/issue-2862.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub trait FooMap {
fn map<B, F: Fn() -> B>(&self, f: F) -> B;
}

impl FooMap for bool {
fn map<B, F: Fn() -> B>(&self, f: F) -> B {
f()
}
}

fn main() {
let a = true;
a.map(|| false);
}

0 comments on commit 5f5fa08

Please sign in to comment.