Skip to content

[drop tracking] Use parent expression for scope, not parent node #101217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions compiler/rustc_typeck/src/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks! I didn't know about that method. I think that's way cleaner, so I rewrote my code to use that. I also added a doc comment to find_parent_node to point people towards parent_iter when more appropriate.

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
Expand All @@ -409,8 +421,9 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
}) {
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id)
} else {
debug!("parent_node: {:?}", self.fcx.tcx.hir().find_parent_node(expr.hir_id));
match self.fcx.tcx.hir().find_parent_node(expr.hir_id) {
let parent_expr = find_parent_expr(expr.hir_id);
debug!("parent_expr: {:?}", parent_expr);
match parent_expr {
Some(parent) => Some(Scope { id: parent.local_id, data: ScopeData::Node }),
None => {
self.rvalue_scopes.temporary_scope(self.region_scope_tree, expr.hir_id.local_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ impl<'tcx> expr_use_visitor::Delegate<'tcx> for ExprUseDelegate<'tcx> {
bk: rustc_middle::ty::BorrowKind,
) {
debug!(
"borrow: place_with_id = {place_with_id:?}, diag_expr_id={diag_expr_id:?}, \
borrow_kind={bk:?}"
"borrow: place_with_id = {place_with_id:#?}, diag_expr_id={diag_expr_id:#?}, \
borrow_kind={bk:#?}"
);

self.borrow_place(place_with_id);
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/async-await/issue-73137.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

// run-pass
// edition:2018
// revisions: normal drop-tracking
// [normal]compile-flags: -Zdrop-tracking=no
// [drop-tracking]compile-flags: -Zdrop-tracking

#![allow(dead_code)]
use std::future::Future;
Expand Down