diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-04-23 12:53:05 +0200 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2020-04-23 15:55:08 +0200 |
| commit | af44cdf04fddf4d18efee49c0c683cb4bbce71fa (patch) | |
| tree | d3e967dd0229bb51003535bb05aba1ecf135e312 /src/librustc_mir/interpret | |
| parent | 2b25c0cd815f032b2c0b34d7d2316fbb20eda8de (diff) | |
Disallow statics initializing themselves
Diffstat (limited to 'src/librustc_mir/interpret')
| -rw-r--r-- | src/librustc_mir/interpret/memory.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index bcad7855c37..43b2f0e9110 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -400,7 +400,16 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> { // We can still be zero-sized in this branch, in which case we have to // return `None`. - if size.bytes() == 0 { None } else { Some(ptr) } + if size.bytes() == 0 { + // We may be reading from a static. + // In order to ensure that `static FOO: Type = FOO;` causes a cycle error + // instead of magically pulling *any* ZST value from the ether, we need to + // trigger a read here. + self.get_raw(ptr.alloc_id)?; + None + } else { + Some(ptr) + } } }) } |
