Skip to content

Commit 084e837

Browse files
committed
Rollup merge of rust-lang#56127 - rust-lang:oli-obk-patch-1, r=nikomatsakis
Update an outdated comment in mir building r? @eddyb
2 parents 5fc9d68 + 925274a commit 084e837

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/librustc_mir/build/expr/as_temp.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8585

8686
unpack!(block = this.into(&Place::Local(temp), block, expr));
8787

88-
// In constants, temp_lifetime is None. We should not need to drop
89-
// anything because no values with a destructor can be created in
90-
// a constant at this time, even if the type may need dropping.
88+
// In constants, temp_lifetime is None for temporaries that live for the
89+
// 'static lifetime. Thus we do not drop these temporaries and simply leak them.
90+
// This is equivalent to what `let x = &foo();` does in functions. The temporary
91+
// is lifted to their surrounding scope. In a function that means the temporary lives
92+
// until just before the function returns. In constants that means it outlives the
93+
// constant's initialization value computation. Anything outliving a constant
94+
// must have the `'static` lifetime and live forever.
95+
// Anything with a shorter lifetime (e.g the `&foo()` in `bar(&foo())` or anything
96+
// within a block will keep the regular drops just like runtime code.
9197
if let Some(temp_lifetime) = temp_lifetime {
9298
this.schedule_drop_storage_and_value(
9399
expr_span,

0 commit comments

Comments
 (0)