Skip to content

Commit 925274a

Browse files
authored
Update as_temp.rs
1 parent 5a2a251 commit 925274a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/librustc_mir/build/expr/as_temp.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
8686
unpack!(block = this.into(&Place::Local(temp), block, expr));
8787

8888
// In constants, temp_lifetime is None for temporaries that live for the
89-
// entire constant. Thus we do not drop these temporaries and simply leak them.
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.
9095
// Anything with a shorter lifetime (e.g the `&foo()` in `bar(&foo())` or anything
9196
// within a block will keep the regular drops just like runtime code.
9297
if let Some(temp_lifetime) = temp_lifetime {

0 commit comments

Comments
 (0)