Skip to content

Commit aa53d09

Browse files
committed
new struct substsref
1 parent c751c7a commit aa53d09

File tree

26 files changed

+94
-69
lines changed

26 files changed

+94
-69
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
824824
if !has_default {
825825
break;
826826
}
827-
if self.tcx.type_of(def_id).subst(self.tcx, substs) != actual {
827+
if self.tcx.type_of(def_id).subst(self.tcx, &substs) != actual {
828828
break;
829829
}
830830
num_supplied_defaults += 1;

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 deletions
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 {
411+
for k in substs.iter() {
412412
match k.unpack() {
413413
UnpackedKind::Lifetime(lt) => bound_region(lt),
414414
UnpackedKind::Type(ty) => types.push(ty),
@@ -653,7 +653,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
653653
},
654654
));
655655

656-
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
656+
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs: substs.into() })
657657
}
658658

659659
_ => ty.super_fold_with(self),

src/librustc/infer/outlives/obligations.rs

Lines changed: 1 addition & 1 deletion
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 {
434+
for k in projection_ty.substs.iter() {
435435
match k.unpack() {
436436
UnpackedKind::Lifetime(lt) => {
437437
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);

src/librustc/infer/outlives/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
248248
debug!("projection_bounds(projection_ty={:?})", projection_ty);
249249
let tcx = self.tcx;
250250
self.region_bounds_declared_on_associated_item(projection_ty.item_def_id)
251-
.map(move |r| r.subst(tcx, projection_ty.substs))
251+
.map(move |r| r.subst(tcx, &projection_ty.substs))
252252
}
253253

254254
/// Given the `DefId` of an associated item, returns any region

src/librustc/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ impl<'tcx> Operand<'tcx> {
23202320
substs: SubstsRef<'tcx>,
23212321
span: Span,
23222322
) -> Self {
2323-
let ty = tcx.type_of(def_id).subst(tcx, substs);
2323+
let ty = tcx.type_of(def_id).subst(tcx, &substs);
23242324
Operand::Constant(box Constant {
23252325
span,
23262326
ty,
@@ -2539,7 +2539,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
25392539
ty::tls::with(|tcx| {
25402540
let substs = tcx.lift(&substs).expect("could not lift for printing");
25412541
FmtPrinter::new(tcx, f, Namespace::ValueNS)
2542-
.print_def_path(variant_def.def_id, substs)?;
2542+
.print_def_path(variant_def.def_id, &substs)?;
25432543
Ok(())
25442544
})?;
25452545

src/librustc/mir/tcx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> Rvalue<'tcx> {
195195
tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx)))
196196
}
197197
AggregateKind::Adt(def, _, substs, _, _) => {
198-
tcx.type_of(def.did).subst(tcx, substs)
198+
tcx.type_of(def.did).subst(tcx, &substs)
199199
}
200200
AggregateKind::Closure(did, substs) => {
201201
tcx.mk_closure(did, substs)

src/librustc/traits/codegen/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
9696
value,
9797
param_env,
9898
);
99-
let substituted = value.subst(self, param_substs);
99+
let substituted = value.subst(self, &param_substs);
100100
self.normalize_erasing_regions(param_env, substituted)
101101
}
102102
}

src/librustc/traits/coherence.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, '
9898

9999
let header = ty::ImplHeader {
100100
impl_def_id,
101-
self_ty: tcx.type_of(impl_def_id).subst(tcx, impl_substs),
102-
trait_ref: tcx.impl_trait_ref(impl_def_id).subst(tcx, impl_substs),
103-
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates,
101+
self_ty: tcx.type_of(impl_def_id).subst(tcx, &impl_substs),
102+
trait_ref: tcx.impl_trait_ref(impl_def_id).subst(tcx, &impl_substs),
103+
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs.into()).predicates,
104104
};
105105

106106
let Normalized { value: mut header, obligations } =

src/librustc/traits/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
305305
let impl_trait_ref = tcx
306306
.impl_trait_ref(def_id)
307307
.unwrap()
308-
.subst(tcx, impl_substs);
308+
.subst(tcx, &impl_substs);
309309

310310
let impl_self_ty = impl_trait_ref.self_ty();
311311

src/librustc/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
415415
}
416416
});
417417

418-
let result = receiver_ty.subst(self, substs);
418+
let result = receiver_ty.subst(self, &substs);
419419
debug!("receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}",
420420
receiver_ty, self_ty, method_def_id, result);
421421
result

src/librustc/traits/project.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
358358
}
359359

360360
let generic_ty = self.tcx().type_of(def_id);
361-
let concrete_ty = generic_ty.subst(self.tcx(), substs);
361+
let concrete_ty = generic_ty.subst(self.tcx(), &substs);
362362
self.depth += 1;
363363
let folded_ty = self.fold_ty(concrete_ty);
364364
self.depth -= 1;
@@ -412,7 +412,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
412412
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
413413
let substs = tcx.lift_to_global(&substs).unwrap();
414414
let evaluated = tcx.mk_const(evaluated);
415-
let evaluated = evaluated.subst(tcx, substs);
415+
let evaluated = evaluated.subst(tcx, &substs);
416416
return evaluated;
417417
}
418418
}
@@ -1498,7 +1498,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
14981498
tcx.type_of(assoc_ty.item.def_id)
14991499
};
15001500
Progress {
1501-
ty: ty.subst(tcx, substs),
1501+
ty: ty.subst(tcx, &substs),
15021502
obligations: nested,
15031503
}
15041504
}

src/librustc/traits/query/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
109109
}
110110

111111
let generic_ty = self.tcx().type_of(def_id);
112-
let concrete_ty = generic_ty.subst(self.tcx(), substs);
112+
let concrete_ty = generic_ty.subst(self.tcx(), &substs);
113113
self.anon_depth += 1;
114114
if concrete_ty == ty {
115115
bug!(
@@ -203,7 +203,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx
203203
if let Ok(evaluated) = tcx.const_eval(param_env.and(cid)) {
204204
let substs = tcx.lift_to_global(&substs).unwrap();
205205
let evaluated = tcx.mk_const(evaluated);
206-
let evaluated = evaluated.subst(tcx, substs);
206+
let evaluated = evaluated.subst(tcx, &substs);
207207
return evaluated;
208208
}
209209
}

src/librustc/traits/select.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24392439
Where(ty::Binder::bind(
24402440
sized_crit
24412441
.iter()
2442-
.map(|ty| ty.subst(self.tcx(), substs))
2442+
.map(|ty| ty.subst(self.tcx(), &substs))
24432443
.collect(),
24442444
))
24452445
}
@@ -2621,7 +2621,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26212621
// We can resolve the `impl Trait` to its concrete type,
26222622
// which enforces a DAG between the functions requiring
26232623
// the auto trait bounds in question.
2624-
vec![self.tcx().type_of(def_id).subst(self.tcx(), substs)]
2624+
vec![self.tcx().type_of(def_id).subst(self.tcx(), &substs)]
26252625
}
26262626
}
26272627
}
@@ -2900,7 +2900,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29002900
obligation.recursion_depth + 1,
29012901
obligation.param_env,
29022902
trait_def_id,
2903-
&trait_ref.substs,
2903+
trait_ref.substs,
29042904
)
29052905
});
29062906

@@ -2957,7 +2957,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29572957
recursion_depth,
29582958
param_env,
29592959
impl_def_id,
2960-
&substs.value,
2960+
substs.value,
29612961
);
29622962

29632963
debug!(
@@ -3101,7 +3101,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31013101
obligation.recursion_depth,
31023102
obligation.param_env,
31033103
trait_def_id,
3104-
&substs,
3104+
substs,
31053105
);
31063106

31073107
debug!(
@@ -3453,8 +3453,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34533453
}
34543454

34553455
// Extract Field<T> and Field<U> from Struct<T> and Struct<U>.
3456-
let inner_source = field.subst(tcx, substs_a);
3457-
let inner_target = field.subst(tcx, substs_b);
3456+
let inner_source = field.subst(tcx, &substs_a);
3457+
let inner_target = field.subst(tcx, &substs_b);
34583458

34593459
// Check that the source struct with the target's
34603460
// unsized parameters is equal to the target.
@@ -3465,7 +3465,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34653465
k
34663466
}
34673467
});
3468-
let new_struct = tcx.mk_adt(def, tcx.mk_substs(params));
3468+
let new_struct = tcx.mk_adt(def, tcx.mk_substs(params).into());
34693469
let InferOk { obligations, .. } = self.infcx
34703470
.at(&obligation.cause, obligation.param_env)
34713471
.eq(target, new_struct)
@@ -3573,7 +3573,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35733573
let impl_substs = self.infcx
35743574
.fresh_substs_for_item(obligation.cause.span, impl_def_id);
35753575

3576-
let impl_trait_ref = impl_trait_ref.subst(self.tcx(), impl_substs);
3576+
let impl_trait_ref = impl_trait_ref.subst(self.tcx(), &impl_substs);
35773577

35783578
let Normalized {
35793579
value: impl_trait_ref,
@@ -3791,7 +3791,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
37913791
param_env,
37923792
cause.clone(),
37933793
recursion_depth,
3794-
&predicate.subst(tcx, substs),
3794+
&predicate.subst(tcx, &substs),
37953795
);
37963796
predicate.obligations.into_iter().chain(Some(Obligation {
37973797
cause: cause.clone(),

src/librustc/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a,
361361
let impl_trait_ref =
362362
selcx.tcx().impl_trait_ref(impl_def_id).unwrap();
363363
let impl_trait_ref =
364-
impl_trait_ref.subst(selcx.tcx(), impl_substs);
364+
impl_trait_ref.subst(selcx.tcx(), &impl_substs);
365365
let Normalized { value: impl_trait_ref, obligations: normalization_obligations1 } =
366366
super::normalize(selcx, param_env, ObligationCause::dummy(), &impl_trait_ref);
367367

src/librustc/ty/codec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result<SubstsRef<'tcx>, D:
212212
{
213213
let len = decoder.read_usize()?;
214214
let tcx = decoder.tcx();
215-
Ok(tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))?)
215+
Ok(tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))?.into())
216216
}
217217

218218
#[inline]

src/librustc/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ 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())
575+
self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| InternalSubsts::empty().into())
576576
}
577577

578578
pub fn node_substs_opt(&self, id: hir::HirId) -> Option<SubstsRef<'tcx>> {
@@ -2835,7 +2835,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28352835
rest: &[Kind<'tcx>])
28362836
-> SubstsRef<'tcx>
28372837
{
2838-
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
2838+
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned())).into()
28392839
}
28402840

28412841
pub fn mk_clauses<I: InternAs<[Clause<'tcx>], Clauses<'tcx>>>(self, iter: I) -> I::Output {

src/librustc/ty/flags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl FlagComputation {
9696
&ty::Generator(_, ref substs, _) => {
9797
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
9898
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
99-
self.add_substs(&substs.substs);
99+
self.add_substs(substs.substs);
100100
}
101101

102102
&ty::GeneratorWitness(ref ts) => {
@@ -108,7 +108,7 @@ impl FlagComputation {
108108
&ty::Closure(_, ref substs) => {
109109
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
110110
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
111-
self.add_substs(&substs.substs);
111+
self.add_substs(substs.substs);
112112
}
113113

114114
&ty::Bound(debruijn, _) => {
@@ -268,7 +268,7 @@ impl FlagComputation {
268268
}
269269

270270
fn add_substs(&mut self, substs: SubstsRef<'_>) {
271-
for kind in substs {
271+
for kind in substs.iter() {
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, 'tcx> Instance<'tcx> {
8181
let pin_did = tcx.lang_items().pin_type().unwrap();
8282
let pin_adt_ref = tcx.adt_def(pin_did);
8383
let pin_substs = tcx.intern_substs(&[env_ty.into()]);
84-
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs);
84+
let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs.into());
8585

8686
sig.map_bound(|sig| {
8787
let state_did = tcx.lang_items().gen_state().unwrap();
@@ -90,7 +90,7 @@ impl<'a, 'tcx> Instance<'tcx> {
9090
sig.yield_ty.into(),
9191
sig.return_ty.into(),
9292
]);
93-
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
93+
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs.into());
9494

9595
tcx.mk_fn_sig(iter::once(env_ty),
9696
ret_ty,
@@ -177,7 +177,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
177177
ty::tls::with(|tcx| {
178178
let substs = tcx.lift(&self.substs).expect("could not lift for printing");
179179
FmtPrinter::new(tcx, &mut *f, Namespace::ValueNS)
180-
.print_def_path(self.def_id(), substs)?;
180+
.print_def_path(self.def_id(), &substs)?;
181181
Ok(())
182182
})?;
183183

src/librustc/ty/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
10311031
pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: SubstsRef<'tcx>)
10321032
-> InstantiatedPredicates<'tcx> {
10331033
InstantiatedPredicates {
1034-
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(),
1034+
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, &substs)).collect(),
10351035
}
10361036
}
10371037

@@ -1042,7 +1042,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
10421042
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
10431043
}
10441044
instantiated.predicates.extend(
1045-
self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)),
1045+
self.predicates.iter().map(|(p, _)| p.subst(tcx, &substs)),
10461046
);
10471047
}
10481048

@@ -2511,7 +2511,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
25112511
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}",
25122512
ty, adt_tys);
25132513
adt_tys.iter()
2514-
.map(|ty| ty.subst(tcx, substs))
2514+
.map(|ty| ty.subst(tcx, &substs))
25152515
.flat_map(|ty| self.sized_constraint_for_ty(tcx, ty))
25162516
.collect()
25172517
}
@@ -2559,7 +2559,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
25592559

25602560
impl<'a, 'gcx, 'tcx> FieldDef {
25612561
pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
2562-
tcx.type_of(self.did).subst(tcx, subst)
2562+
tcx.type_of(self.did).subst(tcx, &subst)
25632563
}
25642564
}
25652565

src/librustc/ty/print/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized {
159159
|cx: Self| if trait_qualify_parent {
160160
let trait_ref = ty::TraitRef::new(
161161
parent_def_id,
162-
cx.tcx().intern_substs(parent_substs),
162+
cx.tcx().intern_substs(parent_substs).into(),
163163
);
164164
cx.path_qualified(trait_ref.self_ty(), Some(trait_ref))
165165
} else {

0 commit comments

Comments
 (0)