Skip to content

Commit

Permalink
impl IntoIterator for SubstsRef
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Apr 27, 2019
1 parent ccabeca commit 6a6887a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T

impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for ty::subst::SubstsRef<'tcx>
{
type KeyType = <&'tcx ty::List<ty::subst::Kind<'tcx>> as ToStableHashKey<StableHashingContext<'a>>>::KeyType;
type KeyType = <&'tcx ty::List<ty::subst::Kind<'tcx>>
as ToStableHashKey<StableHashingContext<'a>>>::KeyType;

#[inline]
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Self::KeyType {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
substs,
item_def_id: _,
}) => {
for k in substs.iter() {
for k in substs {
match k.unpack() {
UnpackedKind::Lifetime(lt) => bound_region(lt),
UnpackedKind::Type(ty) => types.push(ty),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ where
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
debug!("projection_must_outlive: no declared bounds");

for k in projection_ty.substs.iter() {
for k in projection_ty.substs {
match k.unpack() {
UnpackedKind::Lifetime(lt) => {
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let predicate = trait_predicate.map_bound(|mut trait_pred| {
trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
self.tcx.mk_unit(),
SubstsRef::from_slice(self.tcx, &trait_pred.trait_ref.substs[1..]),
SubstsRef::from_slice(
self.tcx,
&trait_pred.trait_ref.substs[1..],
),
);
trait_pred
});
Expand Down
10 changes: 6 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ impl<'tcx> TypeckTables<'tcx> {

pub fn node_substs(&self, id: hir::HirId) -> SubstsRef<'tcx> {
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| InternalSubsts::empty().into())
self.node_substs.get(&id.local_id).cloned().unwrap_or_else(
|| InternalSubsts::empty().into()
)
}

pub fn node_substs_opt(&self, id: hir::HirId) -> Option<SubstsRef<'tcx>> {
Expand Down Expand Up @@ -942,7 +944,7 @@ impl<'tcx> CommonTypes<'tcx> {
};

CommonTypes {
unit: mk(Tuple(List::empty())),
unit: mk(Tuple(SubstsRef::empty())),
bool: mk(Bool),
char: mk(Char),
never: mk(Never),
Expand Down Expand Up @@ -2577,13 +2579,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
#[inline]
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
self.mk_ty(Tuple(self.intern_substs(&kinds)))
self.mk_ty(Tuple(self.intern_substs(&kinds).into()))
}

pub fn mk_tup<I: InternAs<[Ty<'tcx>], Ty<'tcx>>>(self, iter: I) -> I::Output {
iter.intern_with(|ts| {
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
self.mk_ty(Tuple(self.intern_substs(&kinds)))
self.mk_ty(Tuple(self.intern_substs(&kinds).into()))
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl FlagComputation {
self.add_ty(ty);
}

&ty::Tuple(ref substs) => {
&ty::Tuple(substs) => {
self.add_substs(substs);
}

Expand Down Expand Up @@ -268,7 +268,7 @@ impl FlagComputation {
}

fn add_substs(&mut self, substs: SubstsRef<'_>) {
for kind in substs.iter() {
for kind in substs {
match kind.unpack() {
UnpackedKind::Type(ty) => self.add_ty(ty),
UnpackedKind::Lifetime(lt) => self.add_region(lt),
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,10 @@ fn fn_once_adapter_instance<'a, 'tcx>(
let sig = substs.closure_sig(closure_did, tcx);
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
assert_eq!(sig.inputs().len(), 1);
let substs = tcx.mk_substs_trait(self_ty, SubstsRef::from_slice(tcx, &[sig.inputs()[0].into()]));
let substs = tcx.mk_substs_trait(
self_ty,
SubstsRef::from_slice(tcx, &[sig.inputs()[0].into()]),
);

debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
Instance { def, substs }
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ impl<'tcx> From<&'tcx InternalSubsts<'tcx>> for SubstsRef<'tcx> {
}
}

impl<'tcx> IntoIterator for SubstsRef<'tcx> {
type Item = &'tcx Kind<'tcx>;
type IntoIter = <&'tcx InternalSubsts<'tcx> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()
}
}

BraceStructLiftImpl! {
impl<'tcx> Lift<'tcx> for SubstsRef<'tcx> {
type Lifted = SubstsRef<'tcx>;
Expand Down

0 comments on commit 6a6887a

Please sign in to comment.