Skip to content

Commit

Permalink
Rollup merge of rust-lang#56127 - rust-lang:oli-obk-patch-1, r=nikoma…
Browse files Browse the repository at this point in the history
…tsakis

Update an outdated comment in mir building

r? @eddyb
  • Loading branch information
kennytm authored Nov 27, 2018
2 parents 41232f6 + 925274a commit bb35aad
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/librustc_mir/build/expr/as_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

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

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

0 comments on commit bb35aad

Please sign in to comment.