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.
This commit is contained in:
Huon Wilson 2015-06-29 14:51:56 -07:00
parent fe283b4067
commit b1931e48a0
2 changed files with 11 additions and 2 deletions

View file

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

View file

@ -63,4 +63,8 @@ impl Baz {
}
}
fn all_fine() {
let _f = all_fine;
}
fn main() {}