Skip to content

Commit e3df729

Browse files
committed
rustc: make mk_substs_trait take &[Kind] instead of &[Ty].
1 parent d47dc98 commit e3df729

File tree

16 files changed

+70
-98
lines changed

16 files changed

+70
-98
lines changed

src/librustc/traits/error_reporting.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
652652
&& fallback_has_occurred
653653
{
654654
let predicate = trait_predicate.map_bound(|mut trait_pred| {
655-
{
656-
let trait_ref = &mut trait_pred.trait_ref;
657-
let never_substs = trait_ref.substs;
658-
let mut unit_substs = Vec::with_capacity(never_substs.len());
659-
unit_substs.push(self.tcx.mk_nil().into());
660-
unit_substs.extend(&never_substs[1..]);
661-
trait_ref.substs = self.tcx.intern_substs(&unit_substs);
662-
}
655+
trait_pred.trait_ref.substs = self.tcx.mk_substs_trait(
656+
self.tcx.mk_nil(),
657+
&trait_pred.trait_ref.substs[1..],
658+
);
663659
trait_pred
664660
});
665661
let unit_obligation = Obligation {

src/librustc/traits/select.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3058,24 +3058,24 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30583058
obligation.predicate.def_id(),
30593059
obligation.recursion_depth + 1,
30603060
inner_source,
3061-
&[inner_target]));
3061+
&[inner_target.into()]));
30623062
}
30633063

30643064
// (.., T) -> (.., U).
30653065
(&ty::TyTuple(tys_a), &ty::TyTuple(tys_b)) => {
30663066
assert_eq!(tys_a.len(), tys_b.len());
30673067

30683068
// The last field of the tuple has to exist.
3069-
let (a_last, a_mid) = if let Some(x) = tys_a.split_last() {
3069+
let (&a_last, a_mid) = if let Some(x) = tys_a.split_last() {
30703070
x
30713071
} else {
30723072
return Err(Unimplemented);
30733073
};
3074-
let b_last = tys_b.last().unwrap();
3074+
let &b_last = tys_b.last().unwrap();
30753075

30763076
// Check that the source tuple with the target's
30773077
// last element is equal to the target.
3078-
let new_tuple = tcx.mk_tup(a_mid.iter().chain(Some(b_last)));
3078+
let new_tuple = tcx.mk_tup(a_mid.iter().cloned().chain(iter::once(b_last)));
30793079
let InferOk { obligations, .. } =
30803080
self.infcx.at(&obligation.cause, obligation.param_env)
30813081
.eq(target, new_tuple)
@@ -3089,7 +3089,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30893089
obligation.predicate.def_id(),
30903090
obligation.recursion_depth + 1,
30913091
a_last,
3092-
&[b_last]));
3092+
&[b_last.into()]));
30933093
}
30943094

30953095
_ => bug!()

src/librustc/traits/util.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use hir::def_id::DefId;
12-
use ty::subst::{Subst, Substs};
12+
use ty::subst::{Kind, Subst, Substs};
1313
use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
1414
use ty::outlives::Component;
1515
use util::nodemap::FxHashSet;
@@ -430,13 +430,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
430430
cause: ObligationCause<'tcx>,
431431
trait_def_id: DefId,
432432
recursion_depth: usize,
433-
param_ty: Ty<'tcx>,
434-
ty_params: &[Ty<'tcx>])
433+
self_ty: Ty<'tcx>,
434+
params: &[Kind<'tcx>])
435435
-> PredicateObligation<'tcx>
436436
{
437437
let trait_ref = ty::TraitRef {
438438
def_id: trait_def_id,
439-
substs: self.mk_substs_trait(param_ty, ty_params)
439+
substs: self.mk_substs_trait(self_ty, params)
440440
};
441441
predicate_for_trait_ref(cause, param_env, trait_ref, recursion_depth)
442442
}
@@ -512,7 +512,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
512512
};
513513
let trait_ref = ty::TraitRef {
514514
def_id: fn_trait_def_id,
515-
substs: self.mk_substs_trait(self_ty, &[arguments_tuple]),
515+
substs: self.mk_substs_trait(self_ty, &[arguments_tuple.into()]),
516516
};
517517
ty::Binder::bind((trait_ref, sig.skip_binder().output()))
518518
}

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2584,11 +2584,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25842584
}
25852585

25862586
pub fn mk_substs_trait(self,
2587-
s: Ty<'tcx>,
2588-
t: &[Ty<'tcx>])
2587+
self_ty: Ty<'tcx>,
2588+
rest: &[Kind<'tcx>])
25892589
-> &'tcx Substs<'tcx>
25902590
{
2591-
self.mk_substs(iter::once(s).chain(t.into_iter().cloned()).map(Kind::from))
2591+
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
25922592
}
25932593

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

src/librustc/ty/instance.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use hir::def_id::DefId;
1212
use ty::{self, Ty, TypeFoldable, Substs, TyCtxt};
13-
use ty::subst::Kind;
1413
use traits;
1514
use rustc_target::spec::abi::Abi;
1615
use util::ppaux;
@@ -361,7 +360,7 @@ fn fn_once_adapter_instance<'a, 'tcx>(
361360
let sig = substs.closure_sig(closure_did, tcx);
362361
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
363362
assert_eq!(sig.inputs().len(), 1);
364-
let substs = tcx.mk_substs([Kind::from(self_ty), sig.inputs()[0].into()].iter().cloned());
363+
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
365364

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

src/librustc/ty/sty.rs

+36-4
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,18 @@ impl<'tcx> TraitRef<'tcx> {
622622
// associated types.
623623
self.substs.types()
624624
}
625+
626+
pub fn from_method(tcx: TyCtxt<'_, '_, 'tcx>,
627+
trait_id: DefId,
628+
substs: &Substs<'tcx>)
629+
-> ty::TraitRef<'tcx> {
630+
let defs = tcx.generics_of(trait_id);
631+
632+
ty::TraitRef {
633+
def_id: trait_id,
634+
substs: tcx.intern_substs(&substs[..defs.params.len()])
635+
}
636+
}
625637
}
626638

627639
pub type PolyTraitRef<'tcx> = Binder<TraitRef<'tcx>>;
@@ -663,6 +675,18 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> {
663675
self.substs.types()
664676
}
665677

678+
pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>,
679+
trait_ref: ty::TraitRef<'tcx>)
680+
-> ty::ExistentialTraitRef<'tcx> {
681+
// Assert there is a Self.
682+
trait_ref.substs.type_at(0);
683+
684+
ty::ExistentialTraitRef {
685+
def_id: trait_ref.def_id,
686+
substs: tcx.intern_substs(&trait_ref.substs[1..])
687+
}
688+
}
689+
666690
/// Object types don't have a self-type specified. Therefore, when
667691
/// we convert the principal trait-ref into a normal trait-ref,
668692
/// you must give *some* self-type. A common choice is `mk_err()`
@@ -674,8 +698,7 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> {
674698

675699
ty::TraitRef {
676700
def_id: self.def_id,
677-
substs: tcx.mk_substs(
678-
iter::once(self_ty.into()).chain(self.substs.iter().cloned()))
701+
substs: tcx.mk_substs_trait(self_ty, self.substs)
679702
}
680703
}
681704
}
@@ -686,6 +709,16 @@ impl<'tcx> PolyExistentialTraitRef<'tcx> {
686709
pub fn def_id(&self) -> DefId {
687710
self.skip_binder().def_id
688711
}
712+
713+
/// Object types don't have a self-type specified. Therefore, when
714+
/// we convert the principal trait-ref into a normal trait-ref,
715+
/// you must give *some* self-type. A common choice is `mk_err()`
716+
/// or some skolemized type.
717+
pub fn with_self_ty(&self, tcx: TyCtxt<'_, '_, 'tcx>,
718+
self_ty: Ty<'tcx>)
719+
-> ty::PolyTraitRef<'tcx> {
720+
self.map_bound(|trait_ref| trait_ref.with_self_ty(tcx, self_ty))
721+
}
689722
}
690723

691724
/// Binder is a binder for higher-ranked lifetimes. It is part of the
@@ -1188,8 +1221,7 @@ impl<'a, 'tcx, 'gcx> ExistentialProjection<'tcx> {
11881221
ty::ProjectionPredicate {
11891222
projection_ty: ty::ProjectionTy {
11901223
item_def_id: self.item_def_id,
1191-
substs: tcx.mk_substs(
1192-
iter::once(self_ty.into()).chain(self.substs.iter().cloned())),
1224+
substs: tcx.mk_substs_trait(self_ty, self.substs),
11931225
},
11941226
ty: self.ty,
11951227
}

src/librustc/ty/subst.rs

-52
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
2020

2121
use core::intrinsics;
2222
use std::fmt;
23-
use std::iter;
2423
use std::marker::PhantomData;
2524
use std::mem;
2625
use std::num::NonZeroUsize;
@@ -543,54 +542,3 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
543542
self.tcx().mk_region(ty::fold::shift_region(*region, self.region_binders_passed))
544543
}
545544
}
546-
547-
// Helper methods that modify substitutions.
548-
549-
impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> {
550-
pub fn from_method(tcx: TyCtxt<'a, 'gcx, 'tcx>,
551-
trait_id: DefId,
552-
substs: &Substs<'tcx>)
553-
-> ty::TraitRef<'tcx> {
554-
let defs = tcx.generics_of(trait_id);
555-
556-
ty::TraitRef {
557-
def_id: trait_id,
558-
substs: tcx.intern_substs(&substs[..defs.params.len()])
559-
}
560-
}
561-
}
562-
563-
impl<'a, 'gcx, 'tcx> ty::ExistentialTraitRef<'tcx> {
564-
pub fn erase_self_ty(tcx: TyCtxt<'a, 'gcx, 'tcx>,
565-
trait_ref: ty::TraitRef<'tcx>)
566-
-> ty::ExistentialTraitRef<'tcx> {
567-
// Assert there is a Self.
568-
trait_ref.substs.type_at(0);
569-
570-
ty::ExistentialTraitRef {
571-
def_id: trait_ref.def_id,
572-
substs: tcx.intern_substs(&trait_ref.substs[1..])
573-
}
574-
}
575-
}
576-
577-
impl<'a, 'gcx, 'tcx> ty::PolyExistentialTraitRef<'tcx> {
578-
/// Object types don't have a self-type specified. Therefore, when
579-
/// we convert the principal trait-ref into a normal trait-ref,
580-
/// you must give *some* self-type. A common choice is `mk_err()`
581-
/// or some skolemized type.
582-
pub fn with_self_ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
583-
self_ty: Ty<'tcx>)
584-
-> ty::PolyTraitRef<'tcx> {
585-
// otherwise the escaping regions would be captured by the binder
586-
assert!(!self_ty.has_escaping_regions());
587-
588-
self.map_bound(|trait_ref| {
589-
ty::TraitRef {
590-
def_id: trait_ref.def_id,
591-
substs: tcx.mk_substs(
592-
iter::once(self_ty.into()).chain(trait_ref.substs.iter().cloned()))
593-
}
594-
})
595-
}
596-
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1375,9 +1375,10 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13751375
}
13761376

13771377
CastKind::Unsize => {
1378+
let &ty = ty;
13781379
let trait_ref = ty::TraitRef {
13791380
def_id: tcx.lang_items().coerce_unsized_trait().unwrap(),
1380-
substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty]),
1381+
substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty.into()]),
13811382
};
13821383

13831384
self.prove_trait_ref(trait_ref, location);

src/librustc_mir/build/matches/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
312312
},
313313
}
314314
let eq_def_id = self.hir.tcx().lang_items().eq_trait().unwrap();
315-
let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty]);
315+
let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty.into()]);
316316

317317
// take the argument by reference
318318
let region_scope = self.topmost_scope();

src/librustc_mir/hair/cx/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::infer::InferCtxt;
2424
use rustc::ty::layout::{IntegerExt, Size};
2525
use rustc::ty::subst::Subst;
2626
use rustc::ty::{self, Ty, TyCtxt, layout};
27-
use rustc::ty::subst::Substs;
27+
use rustc::ty::subst::{Kind, Substs};
2828
use syntax::ast::{self, LitKind};
2929
use syntax::attr;
3030
use syntax::symbol::Symbol;
@@ -235,7 +235,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> {
235235
trait_def_id: DefId,
236236
method_name: &str,
237237
self_ty: Ty<'tcx>,
238-
params: &[Ty<'tcx>])
238+
params: &[Kind<'tcx>])
239239
-> (Ty<'tcx>, Literal<'tcx>) {
240240
let method_name = Symbol::intern(method_name);
241241
let substs = self.tcx.mk_substs_trait(self_ty, params);

src/librustc_mir/monomorphize/mod.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::hir::def_id::DefId;
1212
use rustc::middle::lang_items::DropInPlaceFnLangItem;
1313
use rustc::traits;
1414
use rustc::ty::adjustment::CustomCoerceUnsized;
15-
use rustc::ty::subst::Kind;
1615
use rustc::ty::{self, Ty, TyCtxt};
1716

1817
pub use rustc::ty::Instance;
@@ -89,10 +88,7 @@ fn fn_once_adapter_instance<'a, 'tcx>(
8988
let sig = substs.closure_sig(closure_did, tcx);
9089
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
9190
assert_eq!(sig.inputs().len(), 1);
92-
let substs = tcx.mk_substs([
93-
Kind::from(self_ty),
94-
sig.inputs()[0].into(),
95-
].iter().cloned());
91+
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);
9692

9793
debug!("fn_once_adapter_shim: self_ty={:?} sig={:?}", self_ty, sig);
9894
Instance { def, substs }
@@ -164,7 +160,7 @@ pub fn custom_coerce_unsize_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
164160

165161
let trait_ref = ty::Binder::bind(ty::TraitRef {
166162
def_id: def_id,
167-
substs: tcx.mk_substs_trait(source_ty, &[target_ty])
163+
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()])
168164
});
169165

170166
match tcx.codegen_fulfill_obligation( (ty::ParamEnv::reveal_all(), trait_ref)) {

src/librustc_mir/util/elaborate_drops.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use rustc::mir::*;
1414
use rustc::middle::lang_items;
1515
use rustc::traits::Reveal;
1616
use rustc::ty::{self, Ty, TyCtxt};
17-
use rustc::ty::subst::{Kind, Substs};
17+
use rustc::ty::subst::Substs;
1818
use rustc::ty::util::IntTypeExt;
1919
use rustc_data_structures::indexed_vec::Idx;
2020
use util::patch::MirPatch;
2121

22-
use std::{iter, u32};
22+
use std::u32;
2323

2424
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
2525
pub enum DropFlagState {
@@ -520,7 +520,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
520520
let drop_trait = tcx.lang_items().drop_trait().unwrap();
521521
let drop_fn = tcx.associated_items(drop_trait).next().unwrap();
522522
let ty = self.place_ty(self.place);
523-
let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
523+
let substs = tcx.mk_substs_trait(ty, &[]);
524524

525525
let ref_ty = tcx.mk_ref(tcx.types.re_erased, ty::TypeAndMut {
526526
ty,

src/librustc_typeck/check/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
547547
coerce_unsized_did,
548548
0,
549549
coerce_source,
550-
&[coerce_target]));
550+
&[coerce_target.into()]));
551551

552552
let mut has_unsized_tuple_coercion = false;
553553

src/librustc_typeck/check/method/suggest.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5656

5757
self.autoderef(span, ty).any(|(ty, _)| {
5858
self.probe(|_| {
59-
let fn_once_substs = tcx.mk_substs_trait(ty,
60-
&[self.next_ty_var(TypeVariableOrigin::MiscVariable(span))]);
59+
let fn_once_substs = tcx.mk_substs_trait(ty, &[
60+
self.next_ty_var(TypeVariableOrigin::MiscVariable(span)).into()
61+
]);
6162
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
6263
let poly_trait_ref = trait_ref.to_poly_trait_ref();
6364
let obligation =

src/librustc_typeck/check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ use std::collections::hash_map::Entry;
116116
use std::cmp;
117117
use std::fmt::Display;
118118
use std::mem::replace;
119-
use std::iter;
120119
use std::ops::{self, Deref};
121120
use rustc_target::spec::abi::Abi;
122121
use syntax::ast;
@@ -1114,7 +1113,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
11141113
if id == fn_id {
11151114
match entry_type {
11161115
config::EntryMain => {
1117-
let substs = fcx.tcx.mk_substs(iter::once(Kind::from(declared_ret_ty)));
1116+
let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]);
11181117
let trait_ref = ty::TraitRef::new(term_id, substs);
11191118
let return_ty_span = decl.output.span();
11201119
let cause = traits::ObligationCause::new(

0 commit comments

Comments
 (0)