Skip to content

Commit 6a6887a

Browse files
committed
impl IntoIterator for SubstsRef
1 parent ccabeca commit 6a6887a

File tree

8 files changed

+28
-11
lines changed

8 files changed

+28
-11
lines changed

src/librustc/ich/impls_ty.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T
5656

5757
impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for ty::subst::SubstsRef<'tcx>
5858
{
59-
type KeyType = <&'tcx ty::List<ty::subst::Kind<'tcx>> as ToStableHashKey<StableHashingContext<'a>>>::KeyType;
59+
type KeyType = <&'tcx ty::List<ty::subst::Kind<'tcx>>
60+
as ToStableHashKey<StableHashingContext<'a>>>::KeyType;
6061

6162
#[inline]
6263
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Self::KeyType {

src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
408408
substs,
409409
item_def_id: _,
410410
}) => {
411-
for k in substs.iter() {
411+
for k in substs {
412412
match k.unpack() {
413413
UnpackedKind::Lifetime(lt) => bound_region(lt),
414414
UnpackedKind::Type(ty) => types.push(ty),

src/librustc/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ where
431431
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
432432
debug!("projection_must_outlive: no declared bounds");
433433

434-
for k in projection_ty.substs.iter() {
434+
for k in projection_ty.substs {
435435
match k.unpack() {
436436
UnpackedKind::Lifetime(lt) => {
437437
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);

src/librustc/traits/error_reporting.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
716716
let predicate = trait_predicate.map_bound(|mut trait_pred| {
717717
trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
718718
self.tcx.mk_unit(),
719-
SubstsRef::from_slice(self.tcx, &trait_pred.trait_ref.substs[1..]),
719+
SubstsRef::from_slice(
720+
self.tcx,
721+
&trait_pred.trait_ref.substs[1..],
722+
),
720723
);
721724
trait_pred
722725
});

src/librustc/ty/context.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ impl<'tcx> TypeckTables<'tcx> {
572572

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

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

944946
CommonTypes {
945-
unit: mk(Tuple(List::empty())),
947+
unit: mk(Tuple(SubstsRef::empty())),
946948
bool: mk(Bool),
947949
char: mk(Char),
948950
never: mk(Never),
@@ -2577,13 +2579,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25772579
#[inline]
25782580
pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
25792581
let kinds: Vec<_> = ts.into_iter().map(|&t| Kind::from(t)).collect();
2580-
self.mk_ty(Tuple(self.intern_substs(&kinds)))
2582+
self.mk_ty(Tuple(self.intern_substs(&kinds).into()))
25812583
}
25822584

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

src/librustc/ty/flags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl FlagComputation {
195195
self.add_ty(ty);
196196
}
197197

198-
&ty::Tuple(ref substs) => {
198+
&ty::Tuple(substs) => {
199199
self.add_substs(substs);
200200
}
201201

@@ -268,7 +268,7 @@ impl FlagComputation {
268268
}
269269

270270
fn add_substs(&mut self, substs: SubstsRef<'_>) {
271-
for kind in substs.iter() {
271+
for kind in substs {
272272
match kind.unpack() {
273273
UnpackedKind::Type(ty) => self.add_ty(ty),
274274
UnpackedKind::Lifetime(lt) => self.add_region(lt),

src/librustc/ty/instance.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ fn fn_once_adapter_instance<'a, 'tcx>(
459459
let sig = substs.closure_sig(closure_did, tcx);
460460
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
461461
assert_eq!(sig.inputs().len(), 1);
462-
let substs = tcx.mk_substs_trait(self_ty, SubstsRef::from_slice(tcx, &[sig.inputs()[0].into()]));
462+
let substs = tcx.mk_substs_trait(
463+
self_ty,
464+
SubstsRef::from_slice(tcx, &[sig.inputs()[0].into()]),
465+
);
463466

464467
debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
465468
Instance { def, substs }

src/librustc/ty/subst.rs

+8
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ impl<'tcx> From<&'tcx InternalSubsts<'tcx>> for SubstsRef<'tcx> {
210210
}
211211
}
212212

213+
impl<'tcx> IntoIterator for SubstsRef<'tcx> {
214+
type Item = &'tcx Kind<'tcx>;
215+
type IntoIter = <&'tcx InternalSubsts<'tcx> as IntoIterator>::IntoIter;
216+
fn into_iter(self) -> Self::IntoIter {
217+
self.inner.into_iter()
218+
}
219+
}
220+
213221
BraceStructLiftImpl! {
214222
impl<'tcx> Lift<'tcx> for SubstsRef<'tcx> {
215223
type Lifted = SubstsRef<'tcx>;

0 commit comments

Comments
 (0)