Assert that non-extended temporaries and super let
bindings have scopes
#147471
+16
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR clarifies a point of confusion in the compiler: all bodies have an outer temporary drop scope, including
static
andconst
item bodies1. Whenever a temporary should be dropped in its enclosing temporary scope, it should have a temporary scope to be dropped in so that its drop can be scheduled2. As such, I've updated some relevant comments and madeScopeTree::default_temporary_scope
andRvalueScopes::temporary_scope
panic when an enclosing temporary scope isn't found instead of allowing potential bugs where potentially-drop-sensitive temporaries are effectively given static lifetimes.Since non-extended
super let
bindings are dropped in their block's enclosing temporary scope, this applies to them as well: the enclosing temporary scope should exist.Footnotes
See https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir_analysis/src/check/region.rs#L773-L778 for non-
fn
/closure bodies. Thethis.cx.var_parent = None;
enables lifetime extension to'static
lifetimes and theScopeData::Destruction
scope ensures non-extended temporaries are dropped in the body expression's scope. ↩For certain borrowed temporaries, drops that don't require running destructors may later be removed by constant promotion. That is unrelated to this PR. ↩