restrict toplevel_ref_arg to only functions (fixes #170)

This commit is contained in:
Manish Goregaokar 2015-08-16 17:24:03 +05:30
parent 7a870ad46b
commit 164907ece2
2 changed files with 8 additions and 1 deletions

View file

@ -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,

View 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);
}