Skip to content

Commit ccabeca

Browse files
committed
purge Kind slice with SubstsRef
1 parent 7f1eb7f commit ccabeca

29 files changed

+158
-107
lines changed

src/librustc/ich/impls_ty.rs

+13
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ impl<'a, 'gcx, T> ToStableHashKey<StableHashingContext<'a>> for &'gcx ty::List<T
5454
}
5555
}
5656

57+
impl<'a, 'tcx> ToStableHashKey<StableHashingContext<'a>> for ty::subst::SubstsRef<'tcx>
58+
{
59+
type KeyType = <&'tcx ty::List<ty::subst::Kind<'tcx>> as ToStableHashKey<StableHashingContext<'a>>>::KeyType;
60+
61+
#[inline]
62+
fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Self::KeyType {
63+
let mut hasher = StableHasher::new();
64+
let mut hcx: StableHashingContext<'a> = hcx.clone();
65+
self.hash_stable(&mut hcx, &mut hasher);
66+
hasher.finish()
67+
}
68+
}
69+
5770
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::subst::Kind<'gcx> {
5871
fn hash_stable<W: StableHasherResult>(&self,
5972
hcx: &mut StableHashingContext<'a>,

src/librustc/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
535535
if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate {
536536
let abs_path = |def_id| {
537537
AbsolutePathPrinter { tcx: self.tcx }
538-
.print_def_path(def_id, &[])
538+
.print_def_path(def_id, SubstsRef::empty())
539539
};
540540

541541
// We compare strings because DefPath can be different
@@ -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/outlives/verify.rs

+1-1
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/lint/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
2525
use crate::middle::privacy::AccessLevels;
2626
use crate::rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
2727
use crate::session::{config, early_error, Session};
28-
use crate::ty::{self, print::Printer, subst::Kind, TyCtxt, Ty};
28+
use crate::ty::{self, print::Printer, subst::{Kind, SubstsRef}, TyCtxt, Ty};
2929
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
3030
use crate::util::nodemap::FxHashMap;
3131
use crate::util::common::time;
@@ -822,7 +822,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
822822
) -> Result<Self::Path, Self::Error> {
823823
if trait_ref.is_none() {
824824
if let ty::Adt(def, substs) = self_ty.sty {
825-
return self.print_def_path(def.did, &substs);
825+
return self.print_def_path(def.did, substs);
826826
}
827827
}
828828

@@ -880,7 +880,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
880880
}
881881

882882
AbsolutePathPrinter { tcx: self.tcx }
883-
.print_def_path(def_id, &[])
883+
.print_def_path(def_id, SubstsRef::empty())
884884
.unwrap()
885885
}
886886
}

src/librustc/mir/mod.rs

+2-2
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

+1-1
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/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
8989

9090
let trait_ref = ty::TraitRef {
9191
def_id: trait_did,
92-
substs: tcx.mk_substs_trait(ty, &[]),
92+
substs: tcx.mk_substs_trait(ty, SubstsRef::empty()),
9393
};
9494

9595
let trait_pred = ty::Binder::bind(trait_ref);
@@ -306,7 +306,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
306306
predicates.push_back(ty::Binder::bind(ty::TraitPredicate {
307307
trait_ref: ty::TraitRef {
308308
def_id: trait_did,
309-
substs: infcx.tcx.mk_substs_trait(ty, &[]),
309+
substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()),
310310
},
311311
}));
312312

src/librustc/traits/codegen/mod.rs

+1-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ 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),
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),
103103
predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs.into()).predicates,
104104
};
105105

src/librustc/traits/engine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::infer::InferCtxt;
22
use crate::ty::{self, Ty, TyCtxt, ToPredicate};
3+
use crate::ty::subst::SubstsRef;
34
use crate::traits::Obligation;
45
use crate::hir::def_id::DefId;
56

@@ -28,7 +29,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
2829
) {
2930
let trait_ref = ty::TraitRef {
3031
def_id,
31-
substs: infcx.tcx.mk_substs_trait(ty, &[]),
32+
substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()),
3233
};
3334
self.register_predicate_obligation(infcx, Obligation {
3435
cause,

src/librustc/traits/error_reporting.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty::GenericParamDefKind;
2828
use crate::ty::error::ExpectedFound;
2929
use crate::ty::fast_reject;
3030
use crate::ty::fold::TypeFolder;
31-
use crate::ty::subst::Subst;
31+
use crate::ty::subst::{Subst, SubstsRef};
3232
use crate::ty::SubtypePredicate;
3333
use crate::util::nodemap::{FxHashMap, FxHashSet};
3434

@@ -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

@@ -716,7 +716,7 @@ 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-
&trait_pred.trait_ref.substs[1..],
719+
SubstsRef::from_slice(self.tcx, &trait_pred.trait_ref.substs[1..]),
720720
);
721721
trait_pred
722722
});
@@ -972,7 +972,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
972972
if let ty::Ref(_, t_type, _) = trait_type.sty {
973973
trait_type = t_type;
974974

975-
let substs = self.tcx.mk_substs_trait(trait_type, &[]);
975+
let substs = self.tcx.mk_substs_trait(trait_type, SubstsRef::empty());
976976
let new_trait_ref = ty::TraitRef::new(trait_ref.def_id, substs);
977977
let new_obligation = Obligation::new(ObligationCause::dummy(),
978978
obligation.param_env,

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>(
654654

655655
let trait_ref = ty::TraitRef {
656656
def_id,
657-
substs: infcx.tcx.mk_substs_trait(ty, &[]),
657+
substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()),
658658
};
659659
let obligation = Obligation {
660660
param_env,

src/librustc/traits/object_safety.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::hir::def_id::DefId;
1515
use crate::lint;
1616
use crate::traits::{self, Obligation, ObligationCause};
1717
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate};
18-
use crate::ty::subst::{Subst, InternalSubsts};
18+
use crate::ty::subst::{Subst, InternalSubsts, SubstsRef};
1919
use std::borrow::Cow;
2020
use std::iter::{self};
2121
use syntax::ast::{self, Name};
@@ -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
@@ -555,7 +555,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
555555
// Self: Unsize<U>
556556
let unsize_predicate = ty::TraitRef {
557557
def_id: unsize_did,
558-
substs: self.mk_substs_trait(self.mk_self_type(), &[unsized_self_ty.into()]),
558+
substs: self.mk_substs_trait(
559+
self.mk_self_type(),
560+
SubstsRef::from_slice(self, &[unsized_self_ty.into()]),
561+
),
559562
}.to_predicate();
560563

561564
// U: Trait<Arg1, ..., ArgN>
@@ -592,7 +595,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
592595
let obligation = {
593596
let predicate = ty::TraitRef {
594597
def_id: dispatch_from_dyn_did,
595-
substs: self.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]),
598+
substs: self.mk_substs_trait(
599+
receiver_ty,
600+
SubstsRef::from_slice(self, &[unsized_receiver_ty.into()]),
601+
),
596602
}.to_predicate();
597603

598604
Obligation::new(

src/librustc/traits/project.rs

+3-3
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

+2-2
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

+11-11
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
}
@@ -2674,7 +2674,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26742674
trait_def_id,
26752675
recursion_depth,
26762676
normalized_ty,
2677-
&[],
2677+
SubstsRef::empty(),
26782678
);
26792679
obligations.push(skol_obligation);
26802680
obligations
@@ -3389,7 +3389,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
33893389
// We can only make objects from sized types.
33903390
let tr = ty::TraitRef {
33913391
def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem),
3392-
substs: tcx.mk_substs_trait(source, &[]),
3392+
substs: tcx.mk_substs_trait(source, SubstsRef::empty()),
33933393
};
33943394
nested.push(predicate_to_obligation(tr.to_predicate()));
33953395

@@ -3447,14 +3447,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34473447
});
34483448
let substs = tcx.mk_substs(params);
34493449
for &ty in fields.split_last().unwrap().1 {
3450-
if ty.subst(tcx, substs).references_error() {
3450+
if ty.subst(tcx, SubstsRef::from_slice(tcx, &substs)).references_error() {
34513451
return Err(Unimplemented);
34523452
}
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.
@@ -3479,7 +3479,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
34793479
obligation.predicate.def_id(),
34803480
obligation.recursion_depth + 1,
34813481
inner_source,
3482-
&[inner_target.into()],
3482+
SubstsRef::from_slice(tcx, &[inner_target.into()]),
34833483
));
34843484
}
34853485

@@ -3513,7 +3513,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35133513
obligation.predicate.def_id(),
35143514
obligation.recursion_depth + 1,
35153515
a_last.expect_ty(),
3516-
&[b_last.into()],
3516+
SubstsRef::from_slice(tcx, &[b_last.into()]),
35173517
));
35183518
}
35193519

@@ -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/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
8080
let source_trait_ref = infcx.tcx
8181
.impl_trait_ref(source_impl)
8282
.unwrap()
83-
.subst(infcx.tcx, &source_substs);
83+
.subst(infcx.tcx, source_substs);
8484

8585
// translate the Self and Param parts of the substitution, since those
8686
// vary across impls

0 commit comments

Comments
 (0)