]> git.lizzy.rs Git - rust.git/commitdiff
restrict toplevel_ref_arg to only functions (fixes #170)
authorManish Goregaokar <manishsmail@gmail.com>
Sun, 16 Aug 2015 11:54:03 +0000 (17:24 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Sun, 16 Aug 2015 11:54:03 +0000 (17:24 +0530)
src/misc.rs
tests/compile-fail/toplevel_ref_arg.rs

index 1fc41cf486222941f2888a99ff400d5a32ef48e8..82ea78d97e1c4cdbb1bdb75d306c4f1b5342a1d9 100644 (file)
@@ -81,7 +81,11 @@ fn get_lints(&self) -> LintArray {
         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,
index cd4d46ee3276e3244838cf79d1b3229be69a55b9..ea69a8cfa15f6f0c26a5b32e270402b8a7f3cf2a 100644 (file)
@@ -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);
 }