<p dir="auto">See the derived implementations at the bottom of <a href="http://doc.rust-lang.org/1.0.0-beta.3/std/num/struct.Wrapping.html" rel="nofollow">http://doc.rust-lang.org/1.0.0-beta.3/std/num/struct.Wrapping.html</a> for example.</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="impl&lt;T&gt; Clone for Wrapping&lt;T&gt; where T: Clone + Clone"><pre class="notranslate"><span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-smi">Clone</span> <span class="pl-k">for</span> <span class="pl-smi">Wrapping</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-k">where</span> <span class="pl-smi">T</span><span class="pl-kos">:</span> <span class="pl-smi">Clone</span> + <span class="pl-smi">Clone</span><span class="pl-kos"></span></pre></div>
<p dir="auto">This is now a tracking issue for <a href="https://github.com/rust-lang/rfcs/blob/master/text/1240-repr-packed-unsafe-ref.md">RFC 1240</a>, "Taking a reference into a struct marked <code class="notranslate">repr(packed)</code> should become <code class="notranslate">unsafe</code>", but originally it was a bug report that led to the development of that RFC. The original miscompilation did not involve references, but it has been fixed; the reference case is the one that remains open. A lot of the discussion is hence outdated; <a href="https://github.com/rust-lang/rust/issues/27060#issuecomment-786124358" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/27060/hovercard">this</a> is the current state.</p>
<hr>
<details><summary>Original Issue Description</summary>
<p dir="auto">(This code actually works <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2021&amp;gist=baa653df7e8938f20c7f5448ffef64c1" rel="nofollow">fine on today's nightly</a>.)</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#![feature(simd, test)]

extern crate test;

// simd types require high alignment or the CPU faults
#[simd]
#[derive(Debug, Copy, Clone)]
struct f32x4(f32, f32, f32, f32);

#[repr(packed)]
#[derive(Copy, Clone)]
struct Unalign&lt;T&gt;(T);

struct Breakit {
    x: u8,
    y: Unalign&lt;f32x4&gt;
}

fn main() {
    let val = Breakit { x: 0, y: Unalign(f32x4(0.0, 0.0, 0.0, 0.0)) };

    test::black_box(&amp;val);

    println!(&quot;before&quot;);

    let ok = val.y;
    test::black_box(ok.0);

    println!(&quot;middle&quot;);

    let bad = val.y.0;
    test::black_box(bad);

    println!(&quot;after&quot;);
}"><pre class="notranslate"><span class="pl-c1">#!<span class="pl-kos">[</span>feature<span class="pl-kos">(</span>simd<span class="pl-kos">,</span> test<span class="pl-kos">)</span><span class="pl-kos">]</span></span>

<span class="pl-k">extern</span> <span class="pl-k">crate</span> test<span class="pl-kos">;</span>

<span class="pl-c">// simd types require high alignment or the CPU faults</span>
<span class="pl-c1">#<span class="pl-kos">[</span>simd<span class="pl-kos">]</span></span>
<span class="pl-c1">#<span class="pl-kos">[</span>derive<span class="pl-kos">(</span><span class="pl-v">Debug</span><span class="pl-kos">,</span> <span class="pl-v">Copy</span><span class="pl-kos">,</span> <span class="pl-v">Clone</span><span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">struct</span> <span class="pl-smi">f32x4</span><span class="pl-kos">(</span><span class="pl-smi">f32</span><span class="pl-kos">,</span> <span class="pl-smi">f32</span><span class="pl-kos">,</span> <span class="pl-smi">f32</span><span class="pl-kos">,</span> <span class="pl-smi">f32</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c1">#<span class="pl-kos">[</span>repr<span class="pl-kos">(</span>packed<span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-c1">#<span class="pl-kos">[</span>derive<span class="pl-kos">(</span><span class="pl-v">Copy</span><span class="pl-kos">,</span> <span class="pl-v">Clone</span><span class="pl-kos">)</span><span class="pl-kos">]</span></span>
<span class="pl-k">struct</span> <span class="pl-smi">Unalign</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-smi">T</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">struct</span> <span class="pl-smi">Breakit</span> <span class="pl-kos">{</span>
    <span class="pl-c1">x</span><span class="pl-kos">:</span> <span class="pl-smi">u8</span><span class="pl-kos">,</span>
    <span class="pl-c1">y</span><span class="pl-kos">:</span> <span class="pl-smi">Unalign</span><span class="pl-kos">&lt;</span><span class="pl-smi">f32x4</span><span class="pl-kos">&gt;</span>
<span class="pl-kos">}</span>

<span class="pl-k">fn</span> <span class="pl-en">main</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> val = <span class="pl-smi">Breakit</span> <span class="pl-kos">{</span> <span class="pl-c1">x</span><span class="pl-kos">:</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-c1">y</span><span class="pl-kos">:</span> <span class="pl-v">Unalign</span><span class="pl-kos">(</span><span class="pl-en">f32x4</span><span class="pl-kos">(</span><span class="pl-c1">0.0</span><span class="pl-kos">,</span> <span class="pl-c1">0.0</span><span class="pl-kos">,</span> <span class="pl-c1">0.0</span><span class="pl-kos">,</span> <span class="pl-c1">0.0</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">}</span><span class="pl-kos">;</span>

    test<span class="pl-kos">::</span><span class="pl-en">black_box</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span>val<span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"before"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">let</span> ok = val<span class="pl-kos">.</span><span class="pl-c1">y</span><span class="pl-kos">;</span>
    test<span class="pl-kos">::</span><span class="pl-en">black_box</span><span class="pl-kos">(</span>ok<span class="pl-kos">.</span><span class="pl-c1">0</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"middle"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-k">let</span> bad = val<span class="pl-kos">.</span><span class="pl-c1">y</span><span class="pl-kos">.</span><span class="pl-c1">0</span><span class="pl-kos">;</span>
    test<span class="pl-kos">::</span><span class="pl-en">black_box</span><span class="pl-kos">(</span>bad<span class="pl-kos">)</span><span class="pl-kos">;</span>

    <span class="pl-en">println</span><span class="pl-en">!</span><span class="pl-kos">(</span><span class="pl-s">"after"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Will print, on playpen:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="before
middle
playpen: application terminated abnormally with signal 4 (Illegal instruction)"><pre class="notranslate"><code class="notranslate">before
middle
playpen: application terminated abnormally with signal 4 (Illegal instruction)
</code></pre></div>
<p dir="auto">The assembly for the <code class="notranslate">ok</code> load is:</p>
<div class="highlight highlight-source-assembly notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    movups  49(%rsp), %xmm0
    movaps  %xmm0, (%rsp)
    #APP
    #NO_APP"><pre class="notranslate"><span class="pl-en">    </span><span class="pl-k">movups</span><span class="pl-en">  </span><span class="pl-c1">49</span><span class="pl-en">(%</span><span class="pl-v">rsp</span><span class="pl-en">)</span><span class="pl-s1">,</span><span class="pl-en"> %</span><span class="pl-v">xmm0</span>
<span class="pl-en">    </span><span class="pl-k">movaps</span><span class="pl-en">  %</span><span class="pl-v">xmm0</span><span class="pl-s1">,</span><span class="pl-en"> (%</span><span class="pl-v">rsp</span><span class="pl-en">)</span>
<span class="pl-en">    #APP</span>
<span class="pl-en">    #NO_APP</span></pre></div>
<p dir="auto">But for the <code class="notranslate">bad</code> one, it is</p>
<div class="highlight highlight-source-assembly notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    movaps  49(%rsp), %xmm0
    movaps  %xmm0, (%rsp)
    #APP
    #NO_APP"><pre class="notranslate"><span class="pl-en">    </span><span class="pl-k">movaps</span><span class="pl-en">  </span><span class="pl-c1">49</span><span class="pl-en">(%</span><span class="pl-v">rsp</span><span class="pl-en">)</span><span class="pl-s1">,</span><span class="pl-en"> %</span><span class="pl-v">xmm0</span>
<span class="pl-en">    </span><span class="pl-k">movaps</span><span class="pl-en">  %</span><span class="pl-v">xmm0</span><span class="pl-s1">,</span><span class="pl-en"> (%</span><span class="pl-v">rsp</span><span class="pl-en">)</span>
<span class="pl-en">    #APP</span>
<span class="pl-en">    #NO_APP</span></pre></div>
<p dir="auto">Specifically, the <code class="notranslate">movups</code> (unaligned) became a <code class="notranslate">movaps</code> (aligned), but the pointer isn't actually aligned, hence the CPU faults.</p>
</details>