title: How do I over-align a variable in Rust?
body: <p>In my code, I have a type that is aligned to 1 byte, and a function that requires a type that is aligned to 8 bytes. The following hypothetical code shows this usage:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn use_bar(bar: &amp;mut [u64; 25]) {
      unimplemented!()
  }
  
  fn main() {
      let mut foo: [u8; 200] = get_foo();
  
      unsafe {
          // Option 1
          use_bar(mem::transmute::&lt;&amp;mut [u8; 200], &amp;mut [u64; 25]&gt;::(&amp;mut foo));
          // Option 2
          use_bar(&amp;mut *(&amp;mut foo as *mut [u8; 200] as *mut [u64; 25]));
      }
  }
  </code></pre>
  
  <p>Unfortunately, this doesn't necessarily work. If you ask clippy about the first option, it will tell you that transmuting references is a bad thing to do. Option 2 may work, however, it will then tell you that the alignment requirements for <code>[u64; 25]</code> are more strict (8 byte alignment) than for <code>[u8; 200]</code> (1 byte alignment) so this may cause undefined behaviour.</p>
  
  <p>Since I don't control the type returned by <code>get_foo()</code>, is there any way I can force <code>foo</code> to be 8 byte aligned? (other than wrapping it in a struct that is properly aligned)</p>