-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[drop tracking] Use parent expression for scope, not parent node #101217
Conversation
Previously we were just using the parent node as the scope for a temporary value, but it turns out this is too narrow. For example, in an expression like Foo { b: &42, a: async { 0 }.await, } the scope for the &42 was set to the ExprField node for `b: &42`, when we actually want to use the Foo struct expression. We fix this by recursively searching through parent nodes until we find a Node::Expr. It may be that we don't find one, and if so that's okay, we will just fall back on the enclosing temporary scope which is always sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases where this can have false positives? i.e. code that used to compile with drop-tracking no longer compiles?
let find_parent_expr = |mut hir_id| { | ||
let hir = self.fcx.tcx.hir(); | ||
hir_id = hir.find_parent_node(hir_id)?; | ||
loop { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
I don't think so. This is only observable if an await point is in the new wider scope but wasn't in the old narrower scope. In that case, MIR would have found the type and we should have gotten an ICE saying the types didn't match. At any rate, the old behavior was incorrect (as shown by how issue-73137.rs broke with drop tracking), so it seems better to correct that. |
00ba10c
to
f921f56
Compare
@bors r+ |
[drop tracking] Use parent expression for scope, not parent node Previously we were just using the parent node as the scope for a temporary value, but it turns out this is too narrow. For example, in an expression like Foo { b: &42, a: async { 0 }.await, } the scope for the &42 was set to the ExprField node for `b: &42`, when we actually want to use the Foo struct expression. We fix this by recursively searching through parent nodes until we find a Node::Expr. It may be that we don't find one, and if so that's okay, we will just fall back on the enclosing temporary scope which is always sufficient. Helps with rust-lang#97331 r? `@jyn514`
[drop tracking] Use parent expression for scope, not parent node Previously we were just using the parent node as the scope for a temporary value, but it turns out this is too narrow. For example, in an expression like Foo { b: &42, a: async { 0 }.await, } the scope for the &42 was set to the ExprField node for `b: &42`, when we actually want to use the Foo struct expression. We fix this by recursively searching through parent nodes until we find a Node::Expr. It may be that we don't find one, and if so that's okay, we will just fall back on the enclosing temporary scope which is always sufficient. Helps with rust-lang#97331 r? `@jyn514`
Rollup of 7 pull requests Successful merges: - rust-lang#99736 (Partially stabilize `bound_as_ref` by stabilizing `Bound::as_ref`) - rust-lang#100928 (Migrate rustc_metadata to SessionDiagnostics) - rust-lang#101217 ([drop tracking] Use parent expression for scope, not parent node ) - rust-lang#101325 (Windows RNG: Use `BCRYPT_RNG_ALG_HANDLE` by default) - rust-lang#101330 (Fix `std::collections::HashSet::drain` documentation) - rust-lang#101338 (Fix unsupported syntax in .manifest file) - rust-lang#101348 (Cleanup css theme) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Previously we were just using the parent node as the scope for a temporary value, but it turns out this is too narrow. For example, in an expression like
the scope for the &42 was set to the ExprField node for
b: &42
, when we actually want to use the Foo struct expression.We fix this by recursively searching through parent nodes until we find a Node::Expr. It may be that we don't find one, and if so that's okay, we will just fall back on the enclosing temporary scope which is always sufficient.
Helps with #97331
r? @jyn514