diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index ec1b0da681074..420962c4730d5 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -54,6 +54,20 @@ impl<'a, 'gcx, T> ToStableHashKey> for &'gcx ty::List ToStableHashKey> for ty::subst::SubstsRef<'tcx> +{ + type KeyType = <&'tcx ty::List> + as ToStableHashKey>>::KeyType; + + #[inline] + fn to_stable_hash_key(&self, hcx: &StableHashingContext<'a>) -> Self::KeyType { + let mut hasher = StableHasher::new(); + let mut hcx: StableHashingContext<'a> = hcx.clone(); + self.hash_stable(&mut hcx, &mut hasher); + hasher.finish() + } +} + impl<'a, 'gcx> HashStable> for ty::subst::Kind<'gcx> { fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, @@ -62,6 +76,20 @@ impl<'a, 'gcx> HashStable> for ty::subst::Kind<'gcx> { } } +impl<'a, 'gcx> HashStable> for ty::subst::SubstsRef<'gcx> { + fn hash_stable( + &self, + hcx: &mut StableHashingContext<'a>, + hasher: &mut StableHasher, + ) { + let ty::subst::SubstsRef { + inner + } = self; + + inner.hash_stable(hcx, hasher); + } +} + impl<'a> HashStable> for ty::RegionKind { fn hash_stable(&self, diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 6b2b0c24c77a9..4c993e28767a2 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -447,7 +447,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { use hir::def_id::CrateNum; use hir::map::DisambiguatedDefPathData; use ty::print::Printer; - use ty::subst::Kind; struct AbsolutePathPrinter<'a, 'gcx, 'tcx> { tcx: TyCtxt<'a, 'gcx, 'tcx>, @@ -523,7 +522,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn path_generic_args( self, print_prefix: impl FnOnce(Self) -> Result, - _args: &[Kind<'tcx>], + _args: SubstsRef<'tcx>, ) -> Result { print_prefix(self) } @@ -535,7 +534,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if !(did1.is_local() || did2.is_local()) && did1.krate != did2.krate { let abs_path = |def_id| { AbsolutePathPrinter { tcx: self.tcx } - .print_def_path(def_id, &[]) + .print_def_path(def_id, SubstsRef::empty()) }; // We compare strings because DefPath can be different diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index e9b80c56e0c5c..c7a1d901c8f30 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -18,7 +18,7 @@ use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine}; use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric}; use crate::ty::fold::TypeFoldable; use crate::ty::relate::RelateResult; -use crate::ty::subst::{Kind, InternalSubsts, SubstsRef}; +use crate::ty::subst::{Kind, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners}; use crate::ty::{FloatVid, IntVid, TyVid}; use crate::util::nodemap::FxHashMap; @@ -1100,7 +1100,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// Given a set of generics defined on a type or impl, returns a substitution mapping each /// type/region parameter to a fresh inference variable. pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'tcx> { - InternalSubsts::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param)) + SubstsRef::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param)) } /// Returns `true` if errors have been reported since this infcx was diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index be9460ad86fc4..044938259048e 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -8,7 +8,7 @@ use crate::traits::{self, PredicateObligation}; use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind}; use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder}; use crate::ty::outlives::Component; -use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, UnpackedKind}; +use crate::ty::subst::{Kind, SubstsRef, UnpackedKind}; use crate::util::nodemap::DefIdMap; pub type OpaqueTypeMap<'tcx> = DefIdMap>; @@ -469,7 +469,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // lifetimes with 'static and remapping only those used in the // `impl Trait` return type, resulting in the parameters // shifting. - let id_substs = InternalSubsts::identity_for_item(gcx, def_id); + let id_substs = SubstsRef::identity_for_item(gcx, def_id); let map: FxHashMap, Kind<'gcx>> = opaque_defn .substs .iter() @@ -653,7 +653,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx> }, )); - self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs }) + self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs: substs.into() }) } _ => ty.super_fold_with(self), diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs index e1ad5aeea19fc..2e45cbd529fb0 100644 --- a/src/librustc/infer/outlives/verify.rs +++ b/src/librustc/infer/outlives/verify.rs @@ -2,7 +2,7 @@ use crate::hir::def_id::DefId; use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::{GenericKind, VerifyBound}; use crate::traits; -use crate::ty::subst::{Subst, InternalSubsts}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, Ty, TyCtxt}; use crate::util::captures::Captures; @@ -292,7 +292,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { .iter() .map(|(p, _)| *p) .collect(); - let identity_substs = InternalSubsts::identity_for_item(tcx, assoc_item_def_id); + let identity_substs = SubstsRef::identity_for_item(tcx, assoc_item_def_id); let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs); self.collect_outlives_from_predicate_list( move |ty| ty == identity_proj, diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index f5cb4cfa29f5c..c01cbdbd323b0 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -25,7 +25,7 @@ use crate::lint::levels::{LintLevelSets, LintLevelsBuilder}; use crate::middle::privacy::AccessLevels; use crate::rustc_serialize::{Decoder, Decodable, Encoder, Encodable}; use crate::session::{config, early_error, Session}; -use crate::ty::{self, print::Printer, subst::Kind, TyCtxt, Ty}; +use crate::ty::{self, print::Printer, subst::SubstsRef, TyCtxt, Ty}; use crate::ty::layout::{LayoutError, LayoutOf, TyLayout}; use crate::util::nodemap::FxHashMap; use crate::util::common::time; @@ -873,14 +873,14 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> { fn path_generic_args( self, print_prefix: impl FnOnce(Self) -> Result, - _args: &[Kind<'tcx>], + _args: SubstsRef<'tcx>, ) -> Result { print_prefix(self) } } AbsolutePathPrinter { tcx: self.tcx } - .print_def_path(def_id, &[]) + .print_def_path(def_id, SubstsRef::empty()) .unwrap() } } diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index e93351197fe47..90071e402db76 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -89,7 +89,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { let trait_ref = ty::TraitRef { def_id: trait_did, - substs: tcx.mk_substs_trait(ty, &[]), + substs: tcx.mk_substs_trait(ty, SubstsRef::empty()), }; let trait_pred = ty::Binder::bind(trait_ref); @@ -306,7 +306,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { predicates.push_back(ty::Binder::bind(ty::TraitPredicate { trait_ref: ty::TraitRef { def_id: trait_did, - substs: infcx.tcx.mk_substs_trait(ty, &[]), + substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()), }, })); diff --git a/src/librustc/traits/coherence.rs b/src/librustc/traits/coherence.rs index 35d8e2beef557..989bd2ba9e4a0 100644 --- a/src/librustc/traits/coherence.rs +++ b/src/librustc/traits/coherence.rs @@ -100,7 +100,7 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, ' impl_def_id, self_ty: tcx.type_of(impl_def_id).subst(tcx, impl_substs), trait_ref: tcx.impl_trait_ref(impl_def_id).subst(tcx, impl_substs), - predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs).predicates, + predicates: tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs.into()).predicates, }; let Normalized { value: mut header, obligations } = diff --git a/src/librustc/traits/engine.rs b/src/librustc/traits/engine.rs index 2f019d823ff5d..0e615fe34b4ad 100644 --- a/src/librustc/traits/engine.rs +++ b/src/librustc/traits/engine.rs @@ -1,5 +1,6 @@ use crate::infer::InferCtxt; use crate::ty::{self, Ty, TyCtxt, ToPredicate}; +use crate::ty::subst::SubstsRef; use crate::traits::Obligation; use crate::hir::def_id::DefId; @@ -28,7 +29,7 @@ pub trait TraitEngine<'tcx>: 'tcx { ) { let trait_ref = ty::TraitRef { def_id, - substs: infcx.tcx.mk_substs_trait(ty, &[]), + substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()), }; self.register_predicate_obligation(infcx, Obligation { cause, diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 76a751536523d..983c122de0689 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -28,7 +28,7 @@ use crate::ty::GenericParamDefKind; use crate::ty::error::ExpectedFound; use crate::ty::fast_reject; use crate::ty::fold::TypeFolder; -use crate::ty::subst::Subst; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::SubtypePredicate; use crate::util::nodemap::{FxHashMap, FxHashSet}; @@ -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(), - &trait_pred.trait_ref.substs[1..], + SubstsRef::from_slice( + self.tcx, + &trait_pred.trait_ref.substs[1..], + ), ); trait_pred }); @@ -972,7 +975,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { if let ty::Ref(_, t_type, _) = trait_type.sty { trait_type = t_type; - let substs = self.tcx.mk_substs_trait(trait_type, &[]); + let substs = self.tcx.mk_substs_trait(trait_type, SubstsRef::empty()); let new_trait_ref = ty::TraitRef::new(trait_ref.def_id, substs); let new_obligation = Obligation::new(ObligationCause::dummy(), obligation.param_env, diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index b875bfdfa9fa4..4d2b1bf7c8c80 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -29,7 +29,7 @@ use crate::mir::interpret::ErrorHandled; use rustc_macros::HashStable; use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; -use crate::ty::subst::{InternalSubsts, SubstsRef}; +use crate::ty::subst::SubstsRef; use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use crate::ty::error::{ExpectedFound, TypeError}; use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor}; @@ -654,7 +654,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'gcx, 'tcx>( let trait_ref = ty::TraitRef { def_id, - substs: infcx.tcx.mk_substs_trait(ty, &[]), + substs: infcx.tcx.mk_substs_trait(ty, SubstsRef::empty()), }; let obligation = Obligation { param_env, @@ -1008,7 +1008,7 @@ fn vtable_methods<'a, 'tcx>( // the method may have some early-bound lifetimes, add // regions for those let substs = trait_ref.map_bound(|trait_ref| - InternalSubsts::for_item(tcx, def_id, |param, _| + SubstsRef::for_item(tcx, def_id, |param, _| match param.kind { GenericParamDefKind::Lifetime => tcx.types.re_erased.into(), GenericParamDefKind::Type { .. } | diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 1c8ea5c7b9c5b..94598c4592668 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -15,7 +15,7 @@ use crate::hir::def_id::DefId; use crate::lint; use crate::traits::{self, Obligation, ObligationCause}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate}; -use crate::ty::subst::{Subst, InternalSubsts}; +use crate::ty::subst::{Subst, SubstsRef}; use std::borrow::Cow; use std::iter::{self}; use syntax::ast::{self, Name}; @@ -407,7 +407,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { self, receiver_ty: Ty<'tcx>, self_ty: Ty<'tcx>, method_def_id: DefId ) -> Ty<'tcx> { debug!("receiver_for_self_ty({:?}, {:?}, {:?})", receiver_ty, self_ty, method_def_id); - let substs = InternalSubsts::for_item(self, method_def_id, |param, _| { + let substs = SubstsRef::for_item(self, method_def_id, |param, _| { if param.index == 0 { self_ty.into() } else { @@ -555,12 +555,15 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { // Self: Unsize let unsize_predicate = ty::TraitRef { def_id: unsize_did, - substs: self.mk_substs_trait(self.mk_self_type(), &[unsized_self_ty.into()]), + substs: self.mk_substs_trait( + self.mk_self_type(), + SubstsRef::from_slice(self, &[unsized_self_ty.into()]), + ), }.to_predicate(); // U: Trait let trait_predicate = { - let substs = InternalSubsts::for_item( + let substs = SubstsRef::for_item( self, method.container.assert_trait(), |param, _| { @@ -592,7 +595,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { let obligation = { let predicate = ty::TraitRef { def_id: dispatch_from_dyn_did, - substs: self.mk_substs_trait(receiver_ty, &[unsized_receiver_ty.into()]), + substs: self.mk_substs_trait( + receiver_ty, + SubstsRef::from_slice(self, &[unsized_receiver_ty.into()]), + ), }.to_predicate(); Obligation::new( diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 882635e21f57c..edbced7f660a8 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -19,7 +19,7 @@ use crate::mir::interpret::{GlobalId, ConstValue}; use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap}; use rustc_macros::HashStable; use syntax::ast::Ident; -use crate::ty::subst::{Subst, InternalSubsts}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt}; use crate::ty::fold::{TypeFoldable, TypeFolder}; use crate::util::common::FN_OUTPUT_NAME; @@ -402,7 +402,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a, let tcx = self.selcx.tcx().global_tcx(); if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) { if substs.needs_infer() || substs.has_placeholders() { - let identity_substs = InternalSubsts::identity_for_item(tcx, def_id); + let identity_substs = SubstsRef::identity_for_item(tcx, def_id); let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs); if let Some(instance) = instance { let cid = GlobalId { @@ -1492,7 +1492,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>( } let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node); let ty = if let ty::AssociatedKind::Existential = assoc_ty.item.kind { - let item_substs = InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id); + let item_substs = SubstsRef::identity_for_item(tcx, assoc_ty.item.def_id); tcx.mk_opaque(assoc_ty.item.def_id, item_substs) } else { tcx.type_of(assoc_ty.item.def_id) diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 9940249da8ba9..ff6a6b3832226 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -9,7 +9,7 @@ use crate::mir::interpret::{GlobalId, ConstValue}; use crate::traits::project::Normalized; use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; use crate::ty::fold::{TypeFoldable, TypeFolder}; -use crate::ty::subst::{Subst, InternalSubsts}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, Ty, TyCtxt}; use super::NoSolution; @@ -193,7 +193,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx let tcx = self.infcx.tcx.global_tcx(); if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) { if substs.needs_infer() || substs.has_placeholders() { - let identity_substs = InternalSubsts::identity_for_item(tcx, def_id); + let identity_substs = SubstsRef::identity_for_item(tcx, def_id); let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs); if let Some(instance) = instance { let cid = GlobalId { diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 8beabe058cf4f..4e28e19d384c8 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -2674,7 +2674,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { trait_def_id, recursion_depth, normalized_ty, - &[], + SubstsRef::empty(), ); obligations.push(skol_obligation); obligations @@ -2900,7 +2900,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation.recursion_depth + 1, obligation.param_env, trait_def_id, - &trait_ref.substs, + trait_ref.substs, ) }); @@ -2957,7 +2957,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { recursion_depth, param_env, impl_def_id, - &substs.value, + substs.value, ); debug!( @@ -3101,7 +3101,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation.recursion_depth, obligation.param_env, trait_def_id, - &substs, + substs, ); debug!( @@ -3389,7 +3389,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // We can only make objects from sized types. let tr = ty::TraitRef { def_id: tcx.require_lang_item(lang_items::SizedTraitLangItem), - substs: tcx.mk_substs_trait(source, &[]), + substs: tcx.mk_substs_trait(source, SubstsRef::empty()), }; nested.push(predicate_to_obligation(tr.to_predicate())); @@ -3447,7 +3447,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { }); let substs = tcx.mk_substs(params); for &ty in fields.split_last().unwrap().1 { - if ty.subst(tcx, substs).references_error() { + if ty.subst(tcx, SubstsRef::from_slice(tcx, &substs)).references_error() { return Err(Unimplemented); } } @@ -3465,7 +3465,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { k } }); - let new_struct = tcx.mk_adt(def, tcx.mk_substs(params)); + let new_struct = tcx.mk_adt(def, tcx.mk_substs(params).into()); let InferOk { obligations, .. } = self.infcx .at(&obligation.cause, obligation.param_env) .eq(target, new_struct) @@ -3479,7 +3479,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation.predicate.def_id(), obligation.recursion_depth + 1, inner_source, - &[inner_target.into()], + SubstsRef::from_slice(tcx, &[inner_target.into()]), )); } @@ -3513,7 +3513,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation.predicate.def_id(), obligation.recursion_depth + 1, a_last.expect_ty(), - &[b_last.into()], + SubstsRef::from_slice(tcx, &[b_last.into()]), )); } diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 384a5862cde0c..c7f77d06fc38a 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -19,7 +19,7 @@ use rustc_data_structures::fx::FxHashSet; use syntax_pos::DUMMY_SP; use crate::traits::select::IntercrateAmbiguityCause; use crate::ty::{self, TyCtxt, TypeFoldable}; -use crate::ty::subst::{Subst, InternalSubsts, SubstsRef}; +use crate::ty::subst::{Subst, SubstsRef}; use super::{SelectionContext, FulfillmentContext}; use super::util::impl_trait_ref_and_oblig; @@ -80,7 +80,7 @@ pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, let source_trait_ref = infcx.tcx .impl_trait_ref(source_impl) .unwrap() - .subst(infcx.tcx, &source_substs); + .subst(infcx.tcx, source_substs); // translate the Self and Param parts of the substitution, since those // vary across impls @@ -398,7 +398,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_, '_, '_>, impl_def_id: DefId) -> Option< let mut w = "impl".to_owned(); - let substs = InternalSubsts::identity_for_item(tcx, impl_def_id); + let substs = SubstsRef::identity_for_item(tcx, impl_def_id); // FIXME: Currently only handles ?Sized. // Needs to support ?Move and ?DynSized when they are implemented. diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 90f62a4d132c7..94abfd1264efa 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -3,7 +3,7 @@ use crate::hir::def_id::DefId; use crate::traits::specialize::specialization_graph::NodeItem; use crate::ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef}; use crate::ty::outlives::Component; -use crate::ty::subst::{Kind, Subst, SubstsRef}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::util::nodemap::FxHashSet; use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized}; @@ -421,7 +421,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { trait_def_id: DefId, recursion_depth: usize, self_ty: Ty<'tcx>, - params: &[Kind<'tcx>]) + params: SubstsRef<'tcx>) -> PredicateObligation<'tcx> { let trait_ref = ty::TraitRef { @@ -502,7 +502,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { }; let trait_ref = ty::TraitRef { def_id: fn_trait_def_id, - substs: self.mk_substs_trait(self_ty, &[arguments_tuple.into()]), + substs: self.mk_substs_trait( + self_ty, + SubstsRef::from_slice(self, &[arguments_tuple.into()]), + ), }; ty::Binder::bind((trait_ref, sig.skip_binder().output())) } @@ -515,7 +518,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { { let trait_ref = ty::TraitRef { def_id: fn_trait_def_id, - substs: self.mk_substs_trait(self_ty, &[]), + substs: self.mk_substs_trait(self_ty, SubstsRef::empty()), }; ty::Binder::bind((trait_ref, sig.skip_binder().yield_ty, sig.skip_binder().return_ty)) } diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index 0843a3a55fc41..4291987ee0acc 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -112,7 +112,7 @@ impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> { }; let method_def_id = tcx.associated_items(trait_def_id.unwrap()) .find(|m| m.kind == ty::AssociatedKind::Method).unwrap().def_id; - (method_def_id, tcx.mk_substs_trait(source, &[])) + (method_def_id, tcx.mk_substs_trait(source, SubstsRef::empty())) } } diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index a76cc3dfdec02..2914c7ca14cbd 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -212,7 +212,7 @@ pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result, D: { let len = decoder.read_usize()?; let tcx = decoder.tcx(); - Ok(tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))?) + Ok(tcx.mk_substs((0..len).map(|_| Decodable::decode(decoder)))?.into()) } #[inline] diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 132477547a0d8..11c7c9f77d511 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -25,7 +25,6 @@ use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::{self, Mir, interpret, ProjectionKind}; use crate::mir::interpret::{ConstValue, Allocation}; -use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, Subst}; use crate::ty::ReprOptions; use crate::traits; use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals}; @@ -41,7 +40,8 @@ use crate::ty::GenericParamDefKind; use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx}; use crate::ty::query; use crate::ty::steal::Steal; -use crate::ty::subst::{UserSubsts, UnpackedKind}; +use crate::ty::subst::{UserSubsts, UnpackedKind, SubstsRef, InternalSubsts}; +use crate::ty::subst::{Kind, Subst}; use crate::ty::{BoundVar, BindingMode}; use crate::ty::CanonicalPolyFnSig; use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet}; @@ -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()) + self.node_substs.get(&id.local_id).cloned().unwrap_or_else( + || SubstsRef::empty().into() + ) } pub fn node_substs_opt(&self, id: hir::HirId) -> Option> { @@ -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), @@ -2505,7 +2507,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> { let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem); let adt_def = self.adt_def(def_id); - let substs = InternalSubsts::for_item(self, def_id, |param, substs| { + let substs = SubstsRef::for_item(self, def_id, |param, substs| { match param.kind { GenericParamDefKind::Lifetime | GenericParamDefKind::Const => { @@ -2516,7 +2518,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { ty.into() } else { assert!(has_default); - self.type_of(param.def_id).subst(self, substs).into() + self.type_of(param.def_id).subst( + self, + SubstsRef::from_slice(self, substs), + ).into() } } } @@ -2574,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], 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())) }) } @@ -2826,16 +2831,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn mk_substs], - &'tcx List>>>(self, iter: I) -> I::Output { + &'tcx List>>>(self, iter: I) -> I::Output { iter.intern_with(|xs| self.intern_substs(xs)) } pub fn mk_substs_trait(self, self_ty: Ty<'tcx>, - rest: &[Kind<'tcx>]) + rest: SubstsRef<'tcx>) -> SubstsRef<'tcx> { - self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned())) + self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned())).into() } pub fn mk_clauses], Clauses<'tcx>>>(self, iter: I) -> I::Output { diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index cb4724adc932c..dd450026899c5 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -96,7 +96,7 @@ impl FlagComputation { &ty::Generator(_, ref substs, _) => { self.add_flags(TypeFlags::HAS_TY_CLOSURE); self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); - self.add_substs(&substs.substs); + self.add_substs(substs.substs); } &ty::GeneratorWitness(ref ts) => { @@ -108,7 +108,7 @@ impl FlagComputation { &ty::Closure(_, ref substs) => { self.add_flags(TypeFlags::HAS_TY_CLOSURE); self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES); - self.add_substs(&substs.substs); + self.add_substs(substs.substs); } &ty::Bound(debruijn, _) => { @@ -195,7 +195,7 @@ impl FlagComputation { self.add_ty(ty); } - &ty::Tuple(ref substs) => { + &ty::Tuple(substs) => { self.add_substs(substs); } diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index f54e69f352a4e..a22aa5b69001a 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -81,7 +81,7 @@ impl<'a, 'tcx> Instance<'tcx> { let pin_did = tcx.lang_items().pin_type().unwrap(); let pin_adt_ref = tcx.adt_def(pin_did); let pin_substs = tcx.intern_substs(&[env_ty.into()]); - let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs); + let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs.into()); sig.map_bound(|sig| { let state_did = tcx.lang_items().gen_state().unwrap(); @@ -90,7 +90,7 @@ impl<'a, 'tcx> Instance<'tcx> { sig.yield_ty.into(), sig.return_ty.into(), ]); - let ret_ty = tcx.mk_adt(state_adt_ref, state_substs); + let ret_ty = tcx.mk_adt(state_adt_ref, state_substs.into()); tcx.mk_fn_sig(iter::once(env_ty), ret_ty, @@ -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, &[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 } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index b9c908b04d640..06dc87301e8fb 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -26,7 +26,7 @@ use crate::session::CrateDisambiguator; use crate::traits::{self, Reveal}; use crate::ty; use crate::ty::layout::VariantIdx; -use crate::ty::subst::{Subst, InternalSubsts, SubstsRef}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::util::{IntTypeExt, Discr}; use crate::ty::walk::TypeWalker; use crate::util::captures::Captures; @@ -1199,7 +1199,7 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> { // from the substitution and the value being substituted into, and // this trick achieves that). - let substs = &trait_ref.skip_binder().substs; + let substs = trait_ref.skip_binder().substs; match *self { Predicate::Trait(ref binder) => Predicate::Trait(binder.map_bound(|data| data.subst(tcx, substs))), @@ -1422,8 +1422,8 @@ impl<'tcx> Predicate<'tcx> { /// cases this is skipping over a binder, so late-bound regions /// with depth 0 are bound by the predicate. pub fn walk_tys(&'a self) -> impl Iterator> + 'a { - match *self { - ty::Predicate::Trait(ref data) => { + match self { + ty::Predicate::Trait(data) => { WalkTysIter::InputTypes(data.skip_binder().input_types()) } ty::Predicate::Subtype(binder) => { @@ -1436,7 +1436,7 @@ impl<'tcx> Predicate<'tcx> { ty::Predicate::RegionOutlives(..) => { WalkTysIter::None } - ty::Predicate::Projection(ref data) => { + ty::Predicate::Projection(data) => { let inner = data.skip_binder(); WalkTysIter::ProjectionTypes( inner.projection_ty.substs.types().chain(Some(inner.ty))) @@ -2356,7 +2356,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { ) -> Option> { let param_env = ParamEnv::empty(); let repr_type = self.repr.discr_type(); - let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), expr_did); + let substs = SubstsRef::identity_for_item(tcx.global_tcx(), expr_did); let instance = ty::Instance::new(expr_did, substs); let cid = GlobalId { instance, @@ -2535,7 +2535,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { }; let sized_predicate = Binder::dummy(TraitRef { def_id: sized_trait, - substs: tcx.mk_substs_trait(ty, &[]) + substs: tcx.mk_substs_trait(ty, SubstsRef::empty()) }).to_predicate(); let predicates = &tcx.predicates_of(self.did).predicates; if predicates.iter().any(|(p, _)| *p == sized_predicate) { diff --git a/src/librustc/ty/print/mod.rs b/src/librustc/ty/print/mod.rs index d5d4f64844463..4bf0ebd411f72 100644 --- a/src/librustc/ty/print/mod.rs +++ b/src/librustc/ty/print/mod.rs @@ -1,7 +1,7 @@ use crate::hir::map::{DefPathData, DisambiguatedDefPathData}; use crate::hir::def_id::{CrateNum, DefId}; use crate::ty::{self, DefIdTree, Ty, TyCtxt}; -use crate::ty::subst::{Kind, Subst}; +use crate::ty::subst::{Kind, Subst, SubstsRef}; use rustc_data_structures::fx::FxHashSet; @@ -37,14 +37,14 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { fn print_def_path( self, def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, ) -> Result { self.default_print_def_path(def_id, substs) } fn print_impl_path( self, impl_def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, self_ty: Ty<'tcx>, trait_ref: Option>, ) -> Result { @@ -91,7 +91,7 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { fn path_generic_args( self, print_prefix: impl FnOnce(Self) -> Result, - args: &[Kind<'tcx>], + args: SubstsRef<'tcx>, ) -> Result; // Defaults (should not be overriden): @@ -99,7 +99,7 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { fn default_print_def_path( self, def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, ) -> Result { debug!("default_print_def_path: def_id={:?}, substs={:?}", def_id, substs); let key = self.tcx().def_key(def_id); @@ -129,7 +129,10 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { let mut trait_qualify_parent = false; if !substs.is_empty() { let generics = self.tcx().generics_of(def_id); - parent_substs = &substs[..generics.parent_count.min(substs.len())]; + parent_substs = SubstsRef::from_slice( + self.tcx(), + &substs[..generics.parent_count.min(substs.len())], + ); match key.disambiguated_data.data { // Closures' own generics are only captures, don't print them. @@ -159,7 +162,7 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { |cx: Self| if trait_qualify_parent { let trait_ref = ty::TraitRef::new( parent_def_id, - cx.tcx().intern_substs(parent_substs), + cx.tcx().intern_substs(&parent_substs).into(), ); cx.path_qualified(trait_ref.self_ty(), Some(trait_ref)) } else { @@ -174,8 +177,8 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { fn generic_args_to_print( &self, generics: &'tcx ty::Generics, - substs: &'tcx [Kind<'tcx>], - ) -> &'tcx [Kind<'tcx>] { + substs: SubstsRef<'tcx>, + ) -> SubstsRef<'tcx> { let mut own_params = generics.parent_count..generics.count(); // Don't print args for `Self` parameters (of traits). @@ -196,13 +199,13 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { } }).count(); - &substs[own_params] + SubstsRef::from_slice(self.tcx(), &substs[own_params]) } fn default_print_impl_path( self, impl_def_id: DefId, - _substs: &'tcx [Kind<'tcx>], + _substs: SubstsRef<'tcx>, self_ty: Ty<'tcx>, impl_trait_ref: Option>, ) -> Result { @@ -231,7 +234,7 @@ pub trait Printer<'gcx: 'tcx, 'tcx>: Sized { // trait-type, then fallback to a format that identifies // the module more clearly. self.path_append_impl( - |cx| cx.print_def_path(parent_def_id, &[]), + |cx| cx.print_def_path(parent_def_id, SubstsRef::empty()), &key.disambiguated_data, self_ty, impl_trait_ref, diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index e5803b7be4f63..6e206f84694da 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -5,7 +5,7 @@ use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use crate::middle::cstore::{ExternCrate, ExternCrateSource}; use crate::middle::region; use crate::ty::{self, DefIdTree, ParamConst, Ty, TyCtxt, TypeFoldable}; -use crate::ty::subst::{Kind, Subst, UnpackedKind}; +use crate::ty::subst::{Kind, Subst, UnpackedKind, SubstsRef}; use crate::mir::interpret::ConstValue; use syntax::symbol::{keywords, Symbol}; @@ -178,7 +178,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: fn print_value_path( self, def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, ) -> Result { self.print_def_path(def_id, substs) } @@ -264,7 +264,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: }) => { debug!("try_print_visible_def_path: def_id={:?}", def_id); return Ok((if !span.is_dummy() { - self.print_def_path(def_id, &[])? + self.print_def_path(def_id, SubstsRef::empty())? } else { self.path_crate(cnum)? }, true)); @@ -511,7 +511,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: } } ty::Foreign(def_id) => { - p!(print_def_path(def_id, &[])); + p!(print_def_path(def_id, SubstsRef::empty())); } ty::Projection(ref data) => p!(print(data)), ty::UnnormalizedProjection(ref data) => { @@ -691,7 +691,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: let mut first = true; if let Some(principal) = predicates.principal() { - p!(print_def_path(principal.def_id, &[])); + p!(print_def_path(principal.def_id, SubstsRef::empty())); let mut resugared = false; @@ -775,7 +775,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: } first = false; - p!(print_def_path(def_id, &[])); + p!(print_def_path(def_id, SubstsRef::empty())); } Ok(self) @@ -880,7 +880,7 @@ impl TyCtxt<'_, '_, '_> { debug!("def_path_str: def_id={:?}, ns={:?}", def_id, ns); let mut s = String::new(); let _ = FmtPrinter::new(self, &mut s, ns) - .print_def_path(def_id, &[]); + .print_def_path(def_id, SubstsRef::empty()); s } } @@ -906,7 +906,7 @@ impl Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> { fn print_def_path( mut self, def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, ) -> Result { define_scoped_cx!(self); @@ -935,7 +935,7 @@ impl Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> { let parent_def_id = DefId { index: key.parent.unwrap(), ..def_id }; let span = self.tcx.def_span(def_id); - self = self.print_def_path(parent_def_id, &[])?; + self = self.print_def_path(parent_def_id, SubstsRef::empty())?; // HACK(eddyb) copy of `path_append` to avoid // constructing a `DisambiguatedDefPathData`. @@ -1060,7 +1060,7 @@ impl Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> { fn path_generic_args( mut self, print_prefix: impl FnOnce(Self) -> Result, - args: &[Kind<'tcx>], + args: SubstsRef<'tcx>, ) -> Result { self = print_prefix(self)?; @@ -1093,7 +1093,7 @@ impl PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> fn print_value_path( mut self, def_id: DefId, - substs: &'tcx [Kind<'tcx>], + substs: SubstsRef<'tcx>, ) -> Result { let was_in_value = std::mem::replace(&mut self.in_value, true); self = self.print_def_path(def_id, substs)?; @@ -1496,7 +1496,7 @@ define_print_and_forward_display! { ty::ExistentialPredicate::Trait(x) => p!(print(x)), ty::ExistentialPredicate::Projection(x) => p!(print(x)), ty::ExistentialPredicate::AutoTrait(def_id) => { - p!(print_def_path(def_id, &[])); + p!(print_def_path(def_id, SubstsRef::empty())); } } } @@ -1583,12 +1583,12 @@ define_print_and_forward_display! { ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")), ty::Predicate::ObjectSafe(trait_def_id) => { p!(write("the trait `"), - print_def_path(trait_def_id, &[]), + print_def_path(trait_def_id, SubstsRef::empty()), write("` is object-safe")) } ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => { p!(write("the closure `"), - print_value_path(closure_def_id, &[]), + print_value_path(closure_def_id, SubstsRef::empty()), write("` implements the trait `{}`", kind)) } ty::Predicate::ConstEvaluatable(def_id, substs) => { diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 1f5a39cbef14e..b235d18798250 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -130,12 +130,12 @@ pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, { let tcx = relation.tcx(); - let params = a_subst.iter().zip(b_subst).enumerate().map(|(i, (a, b))| { + let params = a_subst.iter().zip(b_subst.iter()).enumerate().map(|(i, (a, b))| { let variance = variances.map_or(ty::Invariant, |v| v[i]); relation.relate_with_variance(variance, a, b) }); - Ok(tcx.mk_substs(params)?) + Ok(tcx.mk_substs(params)?.into()) } impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { @@ -222,7 +222,7 @@ impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> { let substs = relation.relate(&a.substs, &b.substs)?; Ok(ty::ProjectionTy { item_def_id: a.item_def_id, - substs: &substs, + substs: substs, }) } } @@ -631,7 +631,7 @@ impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> { -> RelateResult<'tcx, SubstsRef<'tcx>> where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a { - relate_substs(relation, None, a, b) + relate_substs(relation, None, *a, *b) } } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 9aaff33e93339..2e1df29828fc2 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -7,6 +7,7 @@ use crate::hir::def::Namespace; use crate::mir::ProjectionKind; use crate::mir::interpret::ConstValue; use crate::ty::{self, Lift, Ty, TyCtxt, ConstVid}; +use crate::ty::subst::SubstsRef; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::ty::print::{FmtPrinter, Printer}; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -36,7 +37,7 @@ impl fmt::Debug for ty::TraitDef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::tls::with(|tcx| { FmtPrinter::new(tcx, f, Namespace::TypeNS) - .print_def_path(self.def_id, &[])?; + .print_def_path(self.def_id, SubstsRef::empty())?; Ok(()) }) } @@ -46,7 +47,7 @@ impl fmt::Debug for ty::AdtDef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { ty::tls::with(|tcx| { FmtPrinter::new(tcx, f, Namespace::TypeNS) - .print_def_path(self.did, &[])?; + .print_def_path(self.did, SubstsRef::empty())?; Ok(()) }) } @@ -486,7 +487,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ProjectionTy<'a> { tcx.lift(&self.substs).map(|substs| { ty::ProjectionTy { item_def_id: self.item_def_id, - substs, + substs: substs.clone(), } }) } @@ -510,7 +511,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ExistentialProjection<'a> { fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { tcx.lift(&self.substs).map(|substs| { ty::ExistentialProjection { - substs, + substs: substs.clone(), ty: tcx.lift(&self.ty).expect("type must lift when substs do"), item_def_id: self.item_def_id, } @@ -543,7 +544,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::Predicate<'a> { ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => { tcx.lift(&closure_substs) .map(|closure_substs| ty::Predicate::ClosureKind(closure_def_id, - closure_substs, + closure_substs.clone(), kind)) } ty::Predicate::ObjectSafe(trait_def_id) => { @@ -596,7 +597,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ClosureSubsts<'a> { type Lifted = ty::ClosureSubsts<'tcx>; fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { tcx.lift(&self.substs).map(|substs| { - ty::ClosureSubsts { substs } + ty::ClosureSubsts { substs: substs.clone() } }) } } @@ -605,7 +606,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::GeneratorSubsts<'a> { type Lifted = ty::GeneratorSubsts<'tcx>; fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { tcx.lift(&self.substs).map(|substs| { - ty::GeneratorSubsts { substs } + ty::GeneratorSubsts { substs: substs.clone() } }) } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 1e8f3ebd0ddca..55d53c57ed637 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -8,7 +8,7 @@ use crate::middle::region; use polonius_engine::Atom; use rustc_data_structures::indexed_vec::Idx; use rustc_macros::HashStable; -use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, Kind, UnpackedKind}; +use crate::ty::subst::{Subst, SubstsRef, UnpackedKind}; use crate::ty::{self, AdtDef, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable}; use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv}; use crate::util::captures::Captures; @@ -322,31 +322,31 @@ pub struct ClosureSubsts<'tcx> { struct SplitClosureSubsts<'tcx> { closure_kind_ty: Ty<'tcx>, closure_sig_ty: Ty<'tcx>, - upvar_kinds: &'tcx [Kind<'tcx>], + upvar_kinds: SubstsRef<'tcx>, } impl<'tcx> ClosureSubsts<'tcx> { /// Divides the closure substs into their respective /// components. Single source of truth with respect to the /// ordering. - fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitClosureSubsts<'tcx> { + fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> SplitClosureSubsts<'tcx> { let generics = tcx.generics_of(def_id); let parent_len = generics.parent_count; SplitClosureSubsts { closure_kind_ty: self.substs.type_at(parent_len), closure_sig_ty: self.substs.type_at(parent_len + 1), - upvar_kinds: &self.substs[parent_len + 2..], + upvar_kinds: SubstsRef::from_slice(tcx, &self.substs[parent_len + 2..]), } } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> + pub fn upvar_tys(&self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> impl Iterator> + 'tcx { - let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx); + let SplitClosureSubsts { upvar_kinds, .. } = &self.split(def_id, tcx); upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { - ty + ty.clone() } else { bug!("upvar should be type") } @@ -356,7 +356,7 @@ impl<'tcx> ClosureSubsts<'tcx> { /// Returns the closure kind for this closure; may return a type /// variable during inference. To get the closure kind during /// inference, use `infcx.closure_kind(def_id, substs)`. - pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { self.split(def_id, tcx).closure_kind_ty } @@ -364,7 +364,7 @@ impl<'tcx> ClosureSubsts<'tcx> { /// closure; may contain type variables during inference. To get /// the closure signature during inference, use /// `infcx.fn_sig(def_id)`. - pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { self.split(def_id, tcx).closure_sig_ty } @@ -401,18 +401,18 @@ struct SplitGeneratorSubsts<'tcx> { yield_ty: Ty<'tcx>, return_ty: Ty<'tcx>, witness: Ty<'tcx>, - upvar_kinds: &'tcx [Kind<'tcx>], + upvar_kinds: SubstsRef<'tcx>, } impl<'tcx> GeneratorSubsts<'tcx> { - fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> SplitGeneratorSubsts<'tcx> { + fn split(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> SplitGeneratorSubsts<'tcx> { let generics = tcx.generics_of(def_id); let parent_len = generics.parent_count; SplitGeneratorSubsts { yield_ty: self.substs.type_at(parent_len), return_ty: self.substs.type_at(parent_len + 1), witness: self.substs.type_at(parent_len + 2), - upvar_kinds: &self.substs[parent_len + 3..], + upvar_kinds: SubstsRef::from_slice(tcx, &self.substs[parent_len + 3..]), } } @@ -421,18 +421,18 @@ impl<'tcx> GeneratorSubsts<'tcx> { /// It contains a tuple of all the types that could end up on a generator frame. /// The state transformation MIR pass may only produce layouts which mention types /// in this tuple. Upvars are not counted here. - pub fn witness(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn witness(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { self.split(def_id, tcx).witness } #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> + pub fn upvar_tys(&self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> impl Iterator> + 'tcx { - let SplitGeneratorSubsts { upvar_kinds, .. } = self.split(def_id, tcx); - upvar_kinds.iter().map(|t| { + let SplitGeneratorSubsts { upvar_kinds, .. } = &self.split(def_id, tcx); + upvar_kinds.clone().iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { - ty + ty.clone() } else { bug!("upvar should be type") } @@ -440,12 +440,12 @@ impl<'tcx> GeneratorSubsts<'tcx> { } /// Returns the type representing the yield type of the generator. - pub fn yield_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn yield_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { self.split(def_id, tcx).yield_ty } /// Returns the type representing the return type of the generator. - pub fn return_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> Ty<'tcx> { + pub fn return_ty(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> Ty<'tcx> { self.split(def_id, tcx).return_ty } @@ -455,13 +455,13 @@ impl<'tcx> GeneratorSubsts<'tcx> { /// N.B., some bits of the code prefers to see this wrapped in a /// binder, but it never contains bound regions. Probably this /// function should be removed. - pub fn poly_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> PolyGenSig<'tcx> { + pub fn poly_sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> PolyGenSig<'tcx> { ty::Binder::dummy(self.sig(def_id, tcx)) } /// Returns the "generator signature", which consists of its yield /// and return types. - pub fn sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> GenSig<'tcx> { + pub fn sig(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> GenSig<'tcx> { ty::GenSig { yield_ty: self.yield_ty(def_id, tcx), return_ty: self.return_ty(def_id, tcx), @@ -508,7 +508,7 @@ pub enum UpvarSubsts<'tcx> { impl<'tcx> UpvarSubsts<'tcx> { #[inline] - pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, '_>) -> + pub fn upvar_tys(self, def_id: DefId, tcx: TyCtxt<'_, '_, 'tcx>) -> impl Iterator> + 'tcx { let upvar_kinds = match self { @@ -517,7 +517,7 @@ impl<'tcx> UpvarSubsts<'tcx> { }; upvar_kinds.iter().map(|t| { if let UnpackedKind::Type(ty) = t.unpack() { - ty + ty.clone() } else { bug!("upvar should be type") } @@ -567,7 +567,7 @@ impl<'a, 'gcx, 'tcx> Binder> { ExistentialPredicate::AutoTrait(did) => { let trait_ref = Binder(ty::TraitRef { def_id: did, - substs: tcx.mk_substs_trait(self_ty, &[]), + substs: tcx.mk_substs_trait(self_ty, SubstsRef::empty()), }); trait_ref.to_predicate() } @@ -693,7 +693,7 @@ impl<'tcx> TraitRef<'tcx> { pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> { TraitRef { def_id, - substs: InternalSubsts::identity_for_item(tcx, def_id), + substs: SubstsRef::identity_for_item(tcx, def_id), } } @@ -718,7 +718,7 @@ impl<'tcx> TraitRef<'tcx> { ty::TraitRef { def_id: trait_id, - substs: tcx.intern_substs(&substs[..defs.params.len()]) + substs: tcx.intern_substs(&substs[..defs.params.len()]).into() } } } @@ -771,7 +771,7 @@ impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> { ty::ExistentialTraitRef { def_id: trait_ref.def_id, - substs: tcx.intern_substs(&trait_ref.substs[1..]) + substs: tcx.intern_substs(&trait_ref.substs[1..]).into() } } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index ed3da31fb89bd..cd6c401b122a3 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -180,17 +180,68 @@ impl<'tcx> Decodable for Kind<'tcx> { /// A substitution mapping generic parameters to new values. pub type InternalSubsts<'tcx> = List>; -pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>; +impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List> {} -impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { - /// Creates a `InternalSubsts` that maps each generic parameter to itself. +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash)] +pub struct SubstsRef<'tcx> { + pub inner: &'tcx InternalSubsts<'tcx>, +} + +impl<'tcx> From<&'tcx InternalSubsts<'tcx>> for SubstsRef<'tcx> { + fn from(inner: &'tcx InternalSubsts<'tcx>) -> Self { + Self { inner } + } +} + +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<'a, 'tcx> Lift<'tcx> for SubstsRef<'a> { + type Lifted = SubstsRef<'tcx>; + inner, + } +} + +impl<'tcx> core::ops::Deref for SubstsRef<'tcx> { + type Target = [Kind<'tcx>]; + + #[inline] + fn deref(&self) -> &Self::Target { + self.inner + } +} + +impl<'a, 'gcx, 'tcx> SubstsRef<'tcx> { + pub fn empty() -> Self { + Self { + inner: InternalSubsts::empty() + } + } + + /// Creates a `SubstsRef` from a slice of `Kind`. + pub fn from_slice( + tcx: TyCtxt<'a, 'gcx, 'tcx>, + substs: &[Kind<'tcx>], + ) -> Self { + Self { + inner: tcx.mk_substs(substs.iter()) + } + } + + /// Creates a `SubstsRef` that maps each generic parameter to itself. pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> SubstsRef<'tcx> { Self::for_item(tcx, def_id, |param, _| { tcx.mk_param_from_def(param) }) } - /// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked + /// Creates a `SubstsRef` that maps each generic parameter to a higher-ranked /// var bound at index `0`. For types, we use a `BoundVar` index equal to /// the type parameter index. For regions, we use the `BoundRegion::BrNamed` /// variant (which has a `DefId`). @@ -228,7 +279,7 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { }) } - /// Creates a `InternalSubsts` for generic parameter definitions, + /// Creates a `SubstsRef` for generic parameter definitions, /// by calling closures to obtain each kind. /// The closures get to observe the `InternalSubsts` as they're /// being built, which can be used to correctly @@ -243,7 +294,7 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { let count = defs.count(); let mut substs = SmallVec::with_capacity(count); Self::fill_item(&mut substs, tcx, defs, &mut mk_kind); - tcx.intern_substs(&substs) + tcx.intern_substs(&substs).into() } pub fn extend_to(&self, @@ -377,12 +428,12 @@ impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { target_substs: SubstsRef<'tcx>) -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); - tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned()) + tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned()).into() } pub fn truncate_to(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> { - tcx.mk_substs(self.iter().take(generics.count()).cloned()) + tcx.mk_substs(self.iter().take(generics.count()).cloned()).into() } } @@ -393,9 +444,9 @@ impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { // If folding doesn't change the substs, it's faster to avoid // calling `mk_substs` and instead reuse the existing substs. if params[..] == self[..] { - self + *self } else { - folder.tcx().intern_substs(¶ms) + folder.tcx().intern_substs(¶ms).into() } } @@ -415,28 +466,30 @@ impl<'tcx> serialize::UseSpecializedDecodable for SubstsRef<'tcx> {} pub trait Subst<'tcx>: Sized { fn subst<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &[Kind<'tcx>]) -> Self { + substs: SubstsRef<'tcx>) -> Self { self.subst_spanned(tcx, substs, None) } fn subst_spanned<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &[Kind<'tcx>], + substs: SubstsRef<'tcx>, span: Option) -> Self; } impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T { fn subst_spanned<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &[Kind<'tcx>], + substs: SubstsRef<'tcx>, span: Option) -> T { - let mut folder = SubstFolder { tcx, - substs, - span, - root_ty: None, - ty_stack_depth: 0, - binders_passed: 0 }; + let mut folder = SubstFolder { + tcx, + substs, + span, + root_ty: None, + ty_stack_depth: 0, + binders_passed: 0, + }; (*self).fold_with(&mut folder) } } @@ -446,7 +499,7 @@ impl<'tcx, T:TypeFoldable<'tcx>> Subst<'tcx> for T { struct SubstFolder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &'a [Kind<'tcx>], + substs: SubstsRef<'tcx>, /// The location for which the substitution is performed, if available. span: Option, diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 2db2ef59a6ba0..62fe89935c04a 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -7,7 +7,7 @@ use crate::mir::interpret::{sign_extend, truncate}; use crate::ich::NodeIdHashingMode; use crate::traits::{self, ObligationCause}; use crate::ty::{self, DefIdTree, Ty, TyCtxt, GenericParamDefKind, TypeFoldable}; -use crate::ty::subst::{Subst, InternalSubsts, SubstsRef, UnpackedKind}; +use crate::ty::subst::{Subst, SubstsRef, UnpackedKind}; use crate::ty::query::TyCtxtAt; use crate::ty::TyKind::*; use crate::ty::layout::{Integer, IntegerExt}; @@ -599,7 +599,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Given the `DefId` of some item that has no type or const parameters, make /// a suitable "empty substs" for it. pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> SubstsRef<'tcx> { - InternalSubsts::for_item(self, item_def_id, |param, _| { + SubstsRef::for_item(self, item_def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => self.types.re_erased.into(), GenericParamDefKind::Type { .. } => { diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 234407a7c4eaf..5345455a1ed82 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -2,6 +2,7 @@ //! WARNING: this does not keep track of the region depth. use crate::ty::{self, Ty}; +use crate::ty::subst::SubstsRef; use smallvec::{self, SmallVec}; use crate::mir::interpret::ConstValue; @@ -69,7 +70,7 @@ pub fn walk_shallow<'tcx>(ty: Ty<'tcx>) -> smallvec::IntoIter(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { - match parent_ty.sty { + match &parent_ty.sty { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str | ty::Infer(_) | ty::Param(_) | ty::Never | ty::Error | ty::Placeholder(..) | ty::Bound(..) | ty::Foreign(..) => { @@ -84,24 +85,24 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { ty::Slice(ty) => { stack.push(ty); } - ty::RawPtr(ref mt) => { + ty::RawPtr(mt) => { stack.push(mt.ty); } ty::Ref(_, ty, _) => { stack.push(ty); } - ty::Projection(ref data) | ty::UnnormalizedProjection(ref data) => { + ty::Projection(data) | ty::UnnormalizedProjection(data) => { stack.extend(data.substs.types().rev()); } - ty::Dynamic(ref obj, ..) => { + ty::Dynamic(obj, ..) => { stack.extend(obj.iter().rev().flat_map(|predicate| { - let (substs, opt_ty) = match *predicate.skip_binder() { + let (substs, opt_ty) = match predicate.skip_binder() { ty::ExistentialPredicate::Trait(tr) => (tr.substs, None), ty::ExistentialPredicate::Projection(p) => (p.substs, Some(p.ty)), ty::ExistentialPredicate::AutoTrait(_) => // Empty iterator - (ty::InternalSubsts::empty(), None), + (SubstsRef::empty(), None), }; substs.types().rev().chain(opt_ty) @@ -110,10 +111,10 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { ty::Adt(_, substs) | ty::Opaque(_, substs) => { stack.extend(substs.types().rev()); } - ty::Closure(_, ref substs) => { + ty::Closure(_, substs) => { stack.extend(substs.substs.types().rev()); } - ty::Generator(_, ref substs, _) => { + ty::Generator(_, substs, _) => { stack.extend(substs.substs.types().rev()); } ty::GeneratorWitness(ts) => { diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index b793b37fb2ae1..1991c262e32e8 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -222,7 +222,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { let cause = self.cause(cause); let trait_ref = ty::TraitRef { def_id: self.infcx.tcx.require_lang_item(lang_items::SizedTraitLangItem), - substs: self.infcx.tcx.mk_substs_trait(subty, &[]), + substs: self.infcx.tcx.mk_substs_trait(subty, SubstsRef::empty()), }; self.out.push(traits::Obligation::new(cause, self.param_env, trait_ref.to_predicate())); }