diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2015-06-29 14:51:56 -0700 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2015-06-29 15:59:37 -0700 |
| commit | b1931e48a01b418b4b1ba6c747f2c99a5b10d96f (patch) | |
| tree | 72652bc05c7b06793c3278b5e27ad3f6690d8c76 | |
| parent | fe283b4067769a9bc653855842fd8279e95e1f3e (diff) | |
| download | rust-b1931e48a01b418b4b1ba6c747f2c99a5b10d96f.tar.gz rust-b1931e48a01b418b4b1ba6c747f2c99a5b10d96f.zip | |
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.
| -rw-r--r-- | src/librustc_lint/builtin.rs | 9 | ||||
| -rw-r--r-- | 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() {} |
