restrict toplevel_ref_arg to only functions (fixes #170)
This commit is contained in:
parent
7a870ad46b
commit
164907ece2
2 changed files with 8 additions and 1 deletions
|
@ -81,7 +81,11 @@ impl LintPass for TopLevelRefPass {
|
||||||
lint_array!(TOPLEVEL_REF_ARG)
|
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 {
|
for ref arg in &decl.inputs {
|
||||||
if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
|
if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
|
||||||
span_lint(cx,
|
span_lint(cx,
|
||||||
|
|
|
@ -11,5 +11,8 @@ fn the_answer(ref mut x: u8) { //~ ERROR `ref` directly on a function argument
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut x = 0;
|
let mut x = 0;
|
||||||
the_answer(x);
|
the_answer(x);
|
||||||
|
// Closures should not warn
|
||||||
|
let y = |ref x| { println!("{:?}", x) };
|
||||||
|
y(1u8);
|
||||||
println!("The answer is {}.", x);
|
println!("The answer is {}.", x);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue