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:
@@ -1973,9 +1973,14 @@ impl LintPass for UnconditionalRecursion {
|
||||
fn_id: ast::NodeId,
|
||||
_: ast::Ident,
|
||||
id: ast::NodeId) -> bool {
|
||||
tcx.def_map.borrow().get(&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`
|
||||
// (with name `method_name` contained in impl `impl_id`).
|
||||
|
||||
@@ -63,4 +63,8 @@ impl Baz {
|
||||
}
|
||||
}
|
||||
|
||||
fn all_fine() {
|
||||
let _f = all_fine;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
Reference in New Issue
Block a user