diff --git a/src/misc.rs b/src/misc.rs index 1fc41cf4862..82ea78d97e1 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -81,7 +81,11 @@ impl LintPass for TopLevelRefPass { lint_array!(TOPLEVEL_REF_ARG) } - fn check_fn(&mut self, cx: &Context, _: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) { + fn check_fn(&mut self, cx: &Context, k: FnKind, decl: &FnDecl, _: &Block, _: Span, _: NodeId) { + if let FnKind::FkFnBlock = k { + // Does not apply to closures + return + } for ref arg in &decl.inputs { if let PatIdent(BindByRef(_), _, _) = arg.pat.node { span_lint(cx, diff --git a/tests/compile-fail/toplevel_ref_arg.rs b/tests/compile-fail/toplevel_ref_arg.rs index cd4d46ee327..ea69a8cfa15 100644 --- a/tests/compile-fail/toplevel_ref_arg.rs +++ b/tests/compile-fail/toplevel_ref_arg.rs @@ -11,5 +11,8 @@ fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument fn main() { let mut x = 0; the_answer(x); + // Closures should not warn + let y = |ref x| { println!("{:?}", x) }; + y(1u8); println!("The answer is {}.", x); }