diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-11-29 13:10:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-29 13:10:35 +0100 |
| commit | c23e4ea8dcee4ac95b9fb386a804fa52fcba72b2 (patch) | |
| tree | 23ca12226ba51c601ea452bf7e0f2868a51b7726 /src | |
| parent | 3ed113cecee0e73552e9142b5bb3c65bef7835cf (diff) | |
| parent | 925274ab70c15ac5dcb3537e3473c29771ab7df5 (diff) | |
| download | rust-c23e4ea8dcee4ac95b9fb386a804fa52fcba72b2.tar.gz rust-c23e4ea8dcee4ac95b9fb386a804fa52fcba72b2.zip | |
Rollup merge of #56127 - rust-lang:oli-obk-patch-1, r=nikomatsakis
Update an outdated comment in mir building r? @eddyb
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/build/expr/as_temp.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index 8f50a1e9a21..2db9fb9cb99 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -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, |
