From b1931e48a01b418b4b1ba6c747f2c99a5b10d96f Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Mon, 29 Jun 2015 14:51:56 -0700 Subject: [PATCH] lint: only consider actual calls as unconditional recursion. Specifically, just mentioning the function name as a value is fine, as long as it isn't called, e.g. `fn main() { let _ = main; }`. Closes #21705. --- src/librustc_lint/builtin.rs | 9 +++++++-- src/test/compile-fail/lint-unconditional-recursion.rs | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index db48608823d..3d5eb422b63 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1973,8 +1973,13 @@ impl LintPass for UnconditionalRecursion { fn_id: ast::NodeId, _: ast::Ident, id: ast::NodeId) -> bool { - tcx.def_map.borrow().get(&id) - .map_or(false, |def| def.def_id() == local_def(fn_id)) + match tcx.map.get(id) { + ast_map::NodeExpr(&ast::Expr { node: ast::ExprCall(ref callee, _), .. }) => { + tcx.def_map.borrow().get(&callee.id) + .map_or(false, |def| def.def_id() == local_def(fn_id)) + } + _ => false + } } // check if the method call `id` refers to method `method_id` diff --git a/src/test/compile-fail/lint-unconditional-recursion.rs b/src/test/compile-fail/lint-unconditional-recursion.rs index 0c3d1c6adea..0cd71aebd63 100644 --- a/src/test/compile-fail/lint-unconditional-recursion.rs +++ b/src/test/compile-fail/lint-unconditional-recursion.rs @@ -63,4 +63,8 @@ impl Baz { } } +fn all_fine() { + let _f = all_fine; +} + fn main() {}