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};
) -> 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>>;
/// 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