Use parent_iter instead of a find_parent_node loop
This commit is contained in:
parent
b9d3f65412
commit
f921f5626d
2 changed files with 10 additions and 13 deletions
|
@ -387,18 +387,6 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
|
|||
ty.needs_drop(self.fcx.tcx, self.fcx.param_env)
|
||||
};
|
||||
|
||||
let find_parent_expr = |mut hir_id| {
|
||||
let hir = self.fcx.tcx.hir();
|
||||
hir_id = hir.find_parent_node(hir_id)?;
|
||||
loop {
|
||||
if let hir::Node::Expr(_) = self.fcx.tcx.hir().find(hir_id)? {
|
||||
return Some(hir_id);
|
||||
} else {
|
||||
hir_id = hir.find_parent_node(hir_id)?;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Typically, the value produced by an expression is consumed by its parent in some way,
|
||||
// so we only have to check if the parent contains a yield (note that the parent may, for
|
||||
// example, store the value into a local variable, but then we already consider local
|
||||
|
@ -421,7 +409,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
|
|||
}) {
|
||||
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id)
|
||||
} else {
|
||||
let parent_expr = find_parent_expr(expr.hir_id);
|
||||
let parent_expr = self
|
||||
.fcx
|
||||
.tcx
|
||||
.hir()
|
||||
.parent_iter(expr.hir_id)
|
||||
.find(|(_, node)| matches!(node, hir::Node::Expr(_)))
|
||||
.map(|(id, _)| id);
|
||||
debug!("parent_expr: {:?}", parent_expr);
|
||||
match parent_expr {
|
||||
Some(parent) => Some(Scope { id: parent.local_id, data: ScopeData::Node }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue