Skip to content

Commit

Permalink
replace &'tcx Substs with SubstsRef
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe authored and csmoe committed Feb 26, 2019
1 parent ea43c3c commit ccfa5d6
Show file tree
Hide file tree
Showing 55 changed files with 213 additions and 211 deletions.
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use crate::traits::query::{
};
use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef,
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;

// erase!() just makes tokens go away. It's used to specify which macro argument
// is repeated (i.e., which sub-expression of the macro we are in) but don't need
Expand Down Expand Up @@ -661,7 +661,7 @@ define_dep_nodes!( <'tcx>
[] TypeOpNormalizePolyFnSig(CanonicalTypeOpNormalizeGoal<'tcx, PolyFnSig<'tcx>>),
[] TypeOpNormalizeFnSig(CanonicalTypeOpNormalizeGoal<'tcx, FnSig<'tcx>>),

[] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
[] SubstituteNormalizeAndTestPredicates { key: (DefId, SubstsRef<'tcx>) },
[] MethodAutoderefSteps(CanonicalTyGoal<'tcx>),

[input] TargetFeaturesWhitelist,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::ty::{IntType, UintType};
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::error::TypeError;
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::traits::{Obligation, PredicateObligations};

use syntax::ast;
Expand Down Expand Up @@ -373,9 +373,9 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '

fn relate_item_substs(&mut self,
item_def_id: DefId,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>)
-> RelateResult<'tcx, SubstsRef<'tcx>>
{
if self.ambient_variance == ty::Variance::Invariant {
// Avoid fetching the variance if we are in an invariant
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::hir::def_id::DefId;

use crate::ty::{self, Ty, TyCtxt};
use crate::ty::TyVar;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::ty::relate::{self, Relate, RelateResult, TypeRelation};

/// Ensures `a` is made equal to `b`. Returns `a` on success.
Expand Down Expand Up @@ -33,9 +33,9 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx>

fn relate_item_substs(&mut self,
_item_def_id: DefId,
a_subst: &'tcx Substs<'tcx>,
b_subst: &'tcx Substs<'tcx>)
-> RelateResult<'tcx, &'tcx Substs<'tcx>>
a_subst: SubstsRef<'tcx>,
b_subst: SubstsRef<'tcx>)
-> RelateResult<'tcx, SubstsRef<'tcx>>
{
// N.B., once we are equating types, we don't care about
// variance, so don't try to lookup the variance here. This
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::infer::{SubregionOrigin, TypeTrace};
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty;
use crate::ty::error::ExpectedFound;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::util::ppaux::RegionHighlightMode;

impl NiceRegionError<'me, 'gcx, 'tcx> {
Expand Down Expand Up @@ -175,8 +175,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
sub_placeholder: Option<ty::Region<'tcx>>,
sup_placeholder: Option<ty::Region<'tcx>>,
trait_def_id: DefId,
expected_substs: &'tcx Substs<'tcx>,
actual_substs: &'tcx Substs<'tcx>,
expected_substs: SubstsRef<'tcx>,
actual_substs: SubstsRef<'tcx>,
) -> DiagnosticBuilder<'me> {
debug!(
"try_report_placeholders_trait(\
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Substs};
use crate::ty::subst::{Kind, Substs, SubstsRef};
use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners};
use crate::ty::{FloatVid, IntVid, TyVid};
use crate::util::nodemap::FxHashMap;
Expand Down Expand Up @@ -1088,7 +1088,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) -> &'tcx Substs<'tcx> {
pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'tcx> {
Substs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param))
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/infer/opaque_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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, Substs, UnpackedKind};
use crate::ty::subst::{Kind, Substs, SubstsRef, UnpackedKind};
use crate::util::nodemap::DefIdMap;

pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
Expand All @@ -30,7 +30,7 @@ pub struct OpaqueTypeDecl<'tcx> {
/// fn foo<'a, 'b, T>() -> Foo<'a, T>
///
/// then `substs` would be `['a, T]`.
pub substs: &'tcx Substs<'tcx>,
pub substs: SubstsRef<'tcx>,

/// The type variable that represents the value of the abstract type
/// that we require. In other words, after we compile this function,
Expand Down Expand Up @@ -740,7 +740,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
&mut self,
ty: Ty<'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
) -> Ty<'tcx> {
let infcx = self.infcx;
let tcx = infcx.tcx;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/exported_symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
use std::cmp;
use std::mem;
use crate::ty;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;

/// The SymbolExportLevel of a symbols specifies from which kinds of crates
/// the symbol will be exported. `C` symbols will be exported from any
Expand Down Expand Up @@ -33,7 +33,7 @@ impl SymbolExportLevel {
#[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)]
pub enum ExportedSymbol<'tcx> {
NonGeneric(DefId),
Generic(DefId, &'tcx Substs<'tcx>),
Generic(DefId, SubstsRef<'tcx>),
NoDefId(ty::SymbolName),
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use syntax::ast::{self, Name};
use syntax::symbol::InternedString;
use syntax_pos::{Span, DUMMY_SP};
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::layout::VariantIdx;
use crate::ty::{
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
Expand Down Expand Up @@ -2151,7 +2151,7 @@ impl<'tcx> Operand<'tcx> {
pub fn function_handle<'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
span: Span,
) -> Self {
let ty = tcx.type_of(def_id).subst(tcx, substs);
Expand Down Expand Up @@ -2247,7 +2247,7 @@ pub enum AggregateKind<'tcx> {
Adt(
&'tcx AdtDef,
VariantIdx,
&'tcx Substs<'tcx>,
SubstsRef<'tcx>,
Option<UserTypeAnnotationIndex>,
Option<usize>,
),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

use crate::mir::*;
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, SubstsRef};
use crate::ty::{self, AdtDef, Ty, TyCtxt};
use crate::ty::layout::VariantIdx;
use crate::hir;
Expand All @@ -17,7 +17,7 @@ pub enum PlaceTy<'tcx> {

/// Downcast to a particular variant of an enum.
Downcast { adt_def: &'tcx AdtDef,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
variant_index: VariantIdx },
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hir::def_id::DefId;
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
use crate::mir::*;
use syntax_pos::Span;
Expand Down Expand Up @@ -238,7 +238,7 @@ macro_rules! make_mir_visitor {
}

fn visit_substs(&mut self,
substs: & $($mutability)? &'tcx Substs<'tcx>,
substs: & $($mutability)? SubstsRef<'tcx>,
_: Location) {
self.super_substs(substs);
}
Expand Down Expand Up @@ -889,7 +889,7 @@ macro_rules! make_mir_visitor {
fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::LazyConst<'tcx>) {
}

fn super_substs(&mut self, _substs: & $($mutability)? &'tcx Substs<'tcx>) {
fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) {
}

fn super_generator_substs(&mut self,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::mir::interpret::ErrorHandled;
use rustc_data_structures::sync::Lrc;
use syntax::ast;
use syntax_pos::{Span, DUMMY_SP};
use crate::ty::subst::Substs;
use crate::ty::subst::{Substs, SubstsRef};
use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate};
use crate::ty::error::{ExpectedFound, TypeError};
use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor};
Expand Down Expand Up @@ -565,7 +565,7 @@ pub enum Vtable<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct VtableImplData<'tcx, N> {
pub impl_def_id: DefId,
pub substs: &'tcx Substs<'tcx>,
pub substs: SubstsRef<'tcx>,
pub nested: Vec<N>
}

Expand Down Expand Up @@ -622,7 +622,7 @@ pub struct VtableFnPointerData<'tcx, N> {
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)]
pub struct VtableTraitAliasData<'tcx, N> {
pub alias_def_id: DefId,
pub substs: &'tcx Substs<'tcx>,
pub substs: SubstsRef<'tcx>,
pub nested: Vec<N>,
}

Expand Down Expand Up @@ -963,7 +963,7 @@ fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}

fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
key: (DefId, &'tcx Substs<'tcx>))
key: (DefId, SubstsRef<'tcx>))
-> bool
{
debug!("substitute_normalize_and_test_predicates(key={:?})",
Expand All @@ -983,7 +983,7 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx
fn vtable_methods<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
trait_ref: ty::PolyTraitRef<'tcx>)
-> Lrc<Vec<Option<(DefId, &'tcx Substs<'tcx>)>>>
-> Lrc<Vec<Option<(DefId, SubstsRef<'tcx>)>>>
{
debug!("vtable_methods({:?})", trait_ref);

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::middle::lang_items;
use crate::mir::interpret::GlobalId;
use crate::ty::fast_reject;
use crate::ty::relate::TypeRelation;
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, Substs, SubstsRef};
use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable};

use crate::hir;
Expand Down Expand Up @@ -2944,7 +2944,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
fn vtable_impl(
&mut self,
impl_def_id: DefId,
mut substs: Normalized<'tcx, &'tcx Substs<'tcx>>,
mut substs: Normalized<'tcx, SubstsRef<'tcx>>,
cause: ObligationCause<'tcx>,
recursion_depth: usize,
param_env: ty::ParamEnv<'tcx>,
Expand Down Expand Up @@ -3538,7 +3538,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
impl_def_id: DefId,
obligation: &TraitObligation<'tcx>,
snapshot: &CombinedSnapshot<'_, 'tcx>,
) -> Normalized<'tcx, &'tcx Substs<'tcx>> {
) -> Normalized<'tcx, SubstsRef<'tcx>> {
match self.match_impl(impl_def_id, obligation, snapshot) {
Ok(substs) => substs,
Err(()) => {
Expand All @@ -3556,7 +3556,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
impl_def_id: DefId,
obligation: &TraitObligation<'tcx>,
snapshot: &CombinedSnapshot<'_, 'tcx>,
) -> Result<Normalized<'tcx, &'tcx Substs<'tcx>>, ()> {
) -> Result<Normalized<'tcx, SubstsRef<'tcx>>, ()> {
let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap();

// Before we create the substitutions and everything, first
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_data_structures::sync::Lrc;
use syntax_pos::DUMMY_SP;
use crate::traits::select::IntercrateAmbiguityCause;
use crate::ty::{self, TyCtxt, TypeFoldable};
use crate::ty::subst::{Subst, Substs};
use crate::ty::subst::{Subst, Substs, SubstsRef};

use super::{SelectionContext, FulfillmentContext};
use super::util::impl_trait_ref_and_oblig;
Expand Down Expand Up @@ -73,9 +73,9 @@ pub struct OverlapError {
pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
source_impl: DefId,
source_substs: &'tcx Substs<'tcx>,
source_substs: SubstsRef<'tcx>,
target_node: specialization_graph::Node)
-> &'tcx Substs<'tcx> {
-> SubstsRef<'tcx> {
debug!("translate_substs({:?}, {:?}, {:?}, {:?})",
param_env, source_impl, source_substs, target_node);
let source_trait_ref = infcx.tcx
Expand Down Expand Up @@ -114,9 +114,9 @@ pub fn find_associated_item<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
item: &ty::AssociatedItem,
substs: &'tcx Substs<'tcx>,
substs: SubstsRef<'tcx>,
impl_data: &super::VtableImplData<'tcx, ()>,
) -> (DefId, &'tcx Substs<'tcx>) {
) -> (DefId, SubstsRef<'tcx>) {
debug!("find_associated_item({:?}, {:?}, {:?}, {:?})",
param_env, item, substs, impl_data);
assert!(!substs.needs_infer());
Expand Down Expand Up @@ -214,7 +214,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
source_trait_ref: ty::TraitRef<'tcx>,
target_impl: DefId)
-> Result<&'tcx Substs<'tcx>, ()> {
-> Result<SubstsRef<'tcx>, ()> {
debug!("fulfill_implication({:?}, trait_ref={:?} |- {:?} applies)",
param_env, source_trait_ref, target_impl);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/adjustment.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::hir;
use crate::hir::def_id::DefId;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;


/// Represents coercing a value to a different type of value.
Expand Down Expand Up @@ -98,7 +98,7 @@ pub struct OverloadedDeref<'tcx> {

impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> {
pub fn method_call(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, source: Ty<'tcx>)
-> (DefId, &'tcx Substs<'tcx>) {
-> (DefId, SubstsRef<'tcx>) {
let trait_def_id = match self.mutbl {
hir::MutImmutable => tcx.lang_items().deref_trait(),
hir::MutMutable => tcx.lang_items().deref_mut_trait()
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
use std::hash::Hash;
use std::intrinsics;
use crate::ty::{self, Ty, TyCtxt};
use crate::ty::subst::Substs;
use crate::ty::subst::SubstsRef;
use crate::mir::interpret::Allocation;

/// The shorthand encoding uses an enum's variant index `usize`
Expand Down Expand Up @@ -185,7 +185,7 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
}

#[inline]
pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result<&'tcx Substs<'tcx>, D::Error>
pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result<SubstsRef<'tcx>, D::Error>
where D: TyDecoder<'a, 'tcx>,
'tcx: 'a,
{
Expand Down Expand Up @@ -281,7 +281,7 @@ macro_rules! implement_ty_decoder {
use $crate::infer::canonical::CanonicalVarInfos;
use $crate::ty;
use $crate::ty::codec::*;
use $crate::ty::subst::Substs;
use $crate::ty::subst::SubstsRef;
use $crate::hir::def_id::{CrateNum};
use crate::rustc_serialize::{Decoder, SpecializedDecoder};
use std::borrow::Cow;
Expand Down Expand Up @@ -344,9 +344,9 @@ macro_rules! implement_ty_decoder {
}
}

impl<$($typaram),*> SpecializedDecoder<&'tcx Substs<'tcx>>
impl<$($typaram),*> SpecializedDecoder<SubstsRef<'tcx>>
for $DecoderName<$($typaram),*> {
fn specialized_decode(&mut self) -> Result<&'tcx Substs<'tcx>, Self::Error> {
fn specialized_decode(&mut self) -> Result<SubstsRef<'tcx>, Self::Error> {
decode_substs(self)
}
}
Expand Down
Loading

0 comments on commit ccfa5d6

Please sign in to comment.