]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #49210 - oli-obk:pango_crash, r=eddyb
authorbors <bors@rust-lang.org>
Thu, 22 Mar 2018 20:02:14 +0000 (20:02 +0000)
committerbors <bors@rust-lang.org>
Thu, 22 Mar 2018 20:02:14 +0000 (20:02 +0000)
Fix the conversion between bit representations and i128 representations

fixes #49181

the `Discr` type now encodes the bit representation instead of `i128` or `u128` casted to `u128`.

r? @eddyb

1  2 
src/librustc/ty/mod.rs

diff --combined src/librustc/ty/mod.rs
index 95c5cd377d71f4c190adf60e2eca2374be9d3f5a,9ffdccefae58569bfcc0c1acb9ee1aa06ba2e848..643155ef7782c31055af1dee72e9bbcaaaaa8220
@@@ -34,7 -34,6 +34,7 @@@ use ty
  use ty::subst::{Subst, Substs};
  use ty::util::{IntTypeExt, Discr};
  use ty::walk::TypeWalker;
 +use util::captures::Captures;
  use util::nodemap::{NodeSet, DefIdMap, FxHashMap};
  
  use serialize::{self, Encodable, Encoder};
@@@ -1887,7 -1886,6 +1887,6 @@@ impl<'a, 'gcx, 'tcx> AdtDef 
      ) -> Option<Discr<'tcx>> {
          let param_env = ParamEnv::empty();
          let repr_type = self.repr.discr_type();
-         let bit_size = layout::Integer::from_attr(tcx, repr_type).size().bits();
          let substs = Substs::identity_for_item(tcx.global_tcx(), expr_did);
          let instance = ty::Instance::new(expr_did, substs);
          let cid = GlobalId {
          match tcx.const_eval(param_env.and(cid)) {
              Ok(&ty::Const {
                  val: ConstVal::Value(Value::ByVal(PrimVal::Bytes(b))),
-                 ..
+                 ty,
              }) => {
                  trace!("discriminants: {} ({:?})", b, repr_type);
-                 let ty = repr_type.to_ty(tcx);
-                 if repr_type.is_signed() {
-                     let val = b as i128;
-                     // sign extend to i128
-                     let amt = 128 - bit_size;
-                     let val = (val << amt) >> amt;
-                     Some(Discr {
-                         val: val as u128,
-                         ty,
-                     })
-                 } else {
-                     Some(Discr {
-                         val: b,
-                         ty,
-                     })
-                 }
+                 Some(Discr {
+                     val: b,
+                     ty,
+                 })
              },
              Ok(&ty::Const {
                  val: ConstVal::Value(other),
      }
  
      #[inline]
 -    pub fn discriminants(&'a self, tcx: TyCtxt<'a, 'gcx, 'tcx>)
 -                         -> impl Iterator<Item=Discr<'tcx>> + 'a {
 +    pub fn discriminants(
 +        &'a self,
 +        tcx: TyCtxt<'a, 'gcx, 'tcx>,
 +    ) -> impl Iterator<Item=Discr<'tcx>> + Captures<'gcx> + 'a {
          let repr_type = self.repr.discr_type();
          let initial = repr_type.initial_discriminant(tcx.global_tcx());
          let mut prev_discr = None::<Discr<'tcx>>;
@@@ -2293,9 -2277,7 +2280,9 @@@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, '
      /// Returns an iterator of the def-ids for all body-owners in this
      /// crate. If you would prefer to iterate over the bodies
      /// themselves, you can do `self.hir.krate().body_ids.iter()`.
 -    pub fn body_owners(self) -> impl Iterator<Item = DefId> + 'a {
 +    pub fn body_owners(
 +        self,
 +    ) -> impl Iterator<Item = DefId> + Captures<'tcx> + Captures<'gcx> + 'a {
          self.hir.krate()
                  .body_ids
                  .iter()
          }
      }
  
 -    #[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
 -    pub fn associated_items(self, def_id: DefId)
 -                            -> impl Iterator<Item = ty::AssociatedItem> + 'a {
 +    pub fn associated_items(
 +        self,
 +        def_id: DefId,
 +    ) -> impl Iterator<Item = ty::AssociatedItem> + 'a {
          let def_ids = self.associated_item_def_ids(def_id);
 -        (0..def_ids.len()).map(move |i| self.associated_item(def_ids[i]))
 +        Box::new((0..def_ids.len()).map(move |i| self.associated_item(def_ids[i])))
 +            as Box<dyn Iterator<Item = ty::AssociatedItem> + 'a>
      }
  
      /// Returns true if the impls are the same polarity and are implementing