]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/ty/mod.rs
Auto merge of #39999 - bitshifter:struct_align, r=eddyb
[rust.git] / src / librustc / ty / mod.rs
index 5c0889976c21a7bd8f462030899ac58b51429368..5be73542b931dd5a73c17c4c761ba2a8e4b7fe9e 100644 (file)
@@ -37,6 +37,7 @@
 use std::borrow::Cow;
 use std::cell::{Cell, RefCell, Ref};
 use std::collections::BTreeMap;
+use std::cmp;
 use std::hash::{Hash, Hasher};
 use std::ops::Deref;
 use std::rc::Rc;
@@ -1470,10 +1471,12 @@ pub enum AdtKind { Struct, Union, Enum }
 #[derive(Copy, Clone, Eq, PartialEq, RustcEncodable, RustcDecodable, Default)]
 pub struct ReprOptions {
     pub int: Option<attr::IntType>,
+    pub align: u16,
     pub flags: ReprFlags,
 }
 
 impl_stable_hash_for!(struct ReprOptions {
+    align,
     int,
     flags
 });
@@ -1482,7 +1485,7 @@ impl ReprOptions {
     pub fn new(tcx: TyCtxt, did: DefId) -> ReprOptions {
         let mut flags = ReprFlags::empty();
         let mut size = None;
-
+        let mut max_align = 0;
         for attr in tcx.get_attrs(did).iter() {
             for r in attr::find_repr_attrs(tcx.sess.diagnostic(), attr) {
                 flags.insert(match r {
@@ -1493,6 +1496,10 @@ pub fn new(tcx: TyCtxt, did: DefId) -> ReprOptions {
                         size = Some(i);
                         ReprFlags::empty()
                     },
+                    attr::ReprAlign(align) => {
+                        max_align = cmp::max(align, max_align);
+                        ReprFlags::empty()
+                    },
                 });
             }
         }
@@ -1506,7 +1513,7 @@ pub fn new(tcx: TyCtxt, did: DefId) -> ReprOptions {
         if !tcx.consider_optimizing(|| format!("Reorder fields of {:?}", tcx.item_path_str(did))) {
             flags.insert(ReprFlags::IS_LINEAR);
         }
-        ReprOptions { int: size, flags: flags }
+        ReprOptions { int: size, align: max_align, flags: flags }
     }
 
     #[inline]