diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 1df60dfc63e..b89731273f7 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -220,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let ty_msg = match local_visitor.found_ty { Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => { - let fn_sig = substs.closure_sig(*def_id, self.tcx); + let fn_sig = substs.as_closure().sig(*def_id, self.tcx); let args = closure_args(&fn_sig); let ret = fn_sig.output().skip_binder().to_string(); format!(" for the closure `fn({}) -> {}`", args, ret) @@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let suffix = match local_visitor.found_ty { Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => { - let fn_sig = substs.closure_sig(*def_id, self.tcx); + let fn_sig = substs.as_closure().sig(*def_id, self.tcx); let ret = fn_sig.output().skip_binder().to_string(); if let Some(ExprKind::Closure(_, decl, body_id, ..)) = local_visitor.found_closure { diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 1f75ebbd348..ea9e931ad83 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1504,9 +1504,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn closure_kind( &self, closure_def_id: DefId, - closure_substs: ty::ClosureSubsts<'tcx>, + closure_substs: SubstsRef<'tcx>, ) -> Option { - let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx); + let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self.tcx); let closure_kind_ty = self.shallow_resolve(closure_kind_ty); closure_kind_ty.to_opt_closure_kind() } @@ -1518,9 +1518,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn closure_sig( &self, def_id: DefId, - substs: ty::ClosureSubsts<'tcx>, + substs: SubstsRef<'tcx>, ) -> ty::PolyFnSig<'tcx> { - let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx); + let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx); let closure_sig_ty = self.shallow_resolve(closure_sig_ty); closure_sig_ty.fn_sig(self.tcx) } diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 2e19c9c24e9..e7205dd47a6 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -722,11 +722,11 @@ where ty::Closure(def_id, ref substs) => { // Skip lifetime parameters of the enclosing item(s) - for upvar_ty in substs.upvar_tys(def_id, self.tcx) { + for upvar_ty in substs.as_closure().upvar_tys(def_id, self.tcx) { upvar_ty.visit_with(self); } - substs.closure_sig_ty(def_id, self.tcx).visit_with(self); + substs.as_closure().sig_ty(def_id, self.tcx).visit_with(self); } ty::Generator(def_id, ref substs, _) => { @@ -886,7 +886,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { let generics = self.tcx.generics_of(def_id); let substs = - self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| { + self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| { if index < generics.parent_count { // Accommodate missing regions in the parent kinds... self.fold_kind_mapping_missing_regions_to_empty(kind) @@ -896,7 +896,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { } })); - self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs }) + self.tcx.mk_closure(def_id, substs) } ty::Generator(def_id, substs, movability) => { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3f5f54c9463..355bf97e6ed 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -740,16 +740,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let ty = self.node_ty(fn_hir_id)?; let kind = match ty.kind { ty::Generator(..) => ty::ClosureKind::FnOnce, - ty::Closure(closure_def_id, closure_substs) => { + ty::Closure(closure_def_id, substs) => { match self.infcx { // During upvar inference we may not know the // closure kind, just use the LATTICE_BOTTOM value. Some(infcx) => - infcx.closure_kind(closure_def_id, closure_substs) - .unwrap_or(ty::ClosureKind::LATTICE_BOTTOM), + infcx.closure_kind( + closure_def_id, + substs + ).unwrap_or(ty::ClosureKind::LATTICE_BOTTOM), None => - closure_substs.closure_kind(closure_def_id, self.tcx), + substs.as_closure().kind(closure_def_id, self.tcx), } } _ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty), diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6664e16895a..59b4f240733 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx; use crate::ty::print::{FmtPrinter, Printer}; use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{ - self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt, + self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt, UserTypeAnnotationIndex, }; @@ -2188,7 +2188,7 @@ pub enum AggregateKind<'tcx> { /// active field index would identity the field `c` Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option, Option), - Closure(DefId, ClosureSubsts<'tcx>), + Closure(DefId, SubstsRef<'tcx>), Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability), } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index bfbeeebd1e2..ed8086b8faf 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -1,5 +1,5 @@ use crate::ty::subst::SubstsRef; -use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty}; +use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty}; use crate::mir::*; use syntax_pos::Span; @@ -230,12 +230,6 @@ macro_rules! make_mir_visitor { self.super_substs(substs); } - fn visit_closure_substs(&mut self, - substs: & $($mutability)? ClosureSubsts<'tcx>, - _: Location) { - self.super_closure_substs(substs); - } - fn visit_generator_substs(&mut self, substs: & $($mutability)? GeneratorSubsts<'tcx>, _: Location) { @@ -627,7 +621,7 @@ macro_rules! make_mir_visitor { _, closure_substs ) => { - self.visit_closure_substs(closure_substs, location); + self.visit_substs(closure_substs, location); } AggregateKind::Generator( _, @@ -856,10 +850,6 @@ macro_rules! make_mir_visitor { _substs: & $($mutability)? GeneratorSubsts<'tcx>) { } - fn super_closure_substs(&mut self, - _substs: & $($mutability)? ClosureSubsts<'tcx>) { - } - // Convenience methods fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index accbbe3643e..7f194c2fbbc 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -619,7 +619,7 @@ pub struct VtableGeneratorData<'tcx, N> { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)] pub struct VtableClosureData<'tcx, N> { pub closure_def_id: DefId, - pub substs: ty::ClosureSubsts<'tcx>, + pub substs: SubstsRef<'tcx>, /// Nested obligations. This can be non-empty if the closure /// signature contains associated types. pub nested: Vec diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 57077bcdffa..a7bb29c699e 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -1334,7 +1334,8 @@ fn confirm_closure_candidate<'cx, 'tcx>( ) -> Progress<'tcx> { let tcx = selcx.tcx(); let infcx = selcx.infcx(); - let closure_sig_ty = vtable.substs.closure_sig_ty(vtable.closure_def_id, tcx); + let closure_sig_ty = vtable.substs + .as_closure().sig_ty(vtable.closure_def_id, tcx); let closure_sig = infcx.shallow_resolve(closure_sig_ty).fn_sig(tcx); let Normalized { value: closure_sig, diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index aa30541610e..eaf5971e459 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -213,6 +213,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { // check if *any* of those are trivial. ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())), ty::Closure(def_id, ref substs) => substs + .as_closure() .upvar_tys(def_id, tcx) .all(|t| trivial_dropck_outlives(tcx, t)), diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index ef79417c6f0..1fae2a2fe8d 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -2051,7 +2051,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { "assemble_unboxed_candidates: kind={:?} obligation={:?}", kind, obligation ); - match self.infcx.closure_kind(closure_def_id, closure_substs) { + match self.infcx.closure_kind( + closure_def_id, + closure_substs + ) { Some(closure_kind) => { debug!( "assemble_unboxed_candidates: closure_kind = {:?}", @@ -2669,7 +2672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Closure(def_id, substs) => { // (*) binder moved here Where(ty::Binder::bind( - substs.upvar_tys(def_id, self.tcx()).collect(), + substs.as_closure().upvar_tys(def_id, self.tcx()).collect(), )) } @@ -2753,7 +2756,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { tys.iter().map(|k| k.expect_ty()).collect() } - ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(), + ty::Closure(def_id, ref substs) => substs.as_closure() + .upvar_tys(def_id, self.tcx()) + .collect(), ty::Generator(def_id, ref substs, _) => { let witness = substs.witness(def_id, self.tcx()); @@ -3370,17 +3375,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { )?); // FIXME: chalk + if !self.tcx().sess.opts.debugging_opts.chalk { obligations.push(Obligation::new( obligation.cause.clone(), obligation.param_env, - ty::Predicate::ClosureKind(closure_def_id, substs, kind), + ty::Predicate::ClosureKind( + closure_def_id, + substs, + kind + ), )); } Ok(VtableClosureData { closure_def_id, - substs: substs.clone(), + substs: substs, nested: obligations, }) } @@ -3869,7 +3879,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { &mut self, obligation: &TraitObligation<'tcx>, closure_def_id: DefId, - substs: ty::ClosureSubsts<'tcx>, + substs: SubstsRef<'tcx>, ) -> ty::PolyTraitRef<'tcx> { debug!( "closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})", diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 42d45c5dfd3..5aad6c1dc18 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -29,7 +29,7 @@ use crate::traits; use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals}; use crate::ty::{self, DefIdTree, Ty, TypeAndMut}; use crate::ty::{TyS, TyKind, List}; -use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const}; +use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const}; use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate}; use crate::ty::RegionKind; use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid}; @@ -2502,7 +2502,7 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>) + pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty(Closure(closure_id, closure_substs)) } diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 6e43aa6a25d..b513ef5a966 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -106,7 +106,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); } &ty::Bound(debruijn, _) => { diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 741830f205c..34f806b15c0 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -59,7 +59,7 @@ impl<'tcx> Instance<'tcx> { // Shims currently have type FnPtr. Not sure this should remain. ty::FnPtr(_) => ty.fn_sig(tcx), ty::Closure(def_id, substs) => { - let sig = substs.closure_sig(def_id, tcx); + let sig = substs.as_closure().sig(def_id, tcx); let env_ty = tcx.closure_env_ty(def_id, substs).unwrap(); sig.map_bound(|sig| tcx.mk_fn_sig( @@ -315,14 +315,14 @@ impl<'tcx> Instance<'tcx> { pub fn resolve_closure( tcx: TyCtxt<'tcx>, def_id: DefId, - substs: ty::ClosureSubsts<'tcx>, + substs: ty::SubstsRef<'tcx>, requested_kind: ty::ClosureKind, ) -> Instance<'tcx> { - let actual_kind = substs.closure_kind(def_id, tcx); + let actual_kind = substs.as_closure().kind(def_id, tcx); match needs_fn_once_adapter_shim(actual_kind, requested_kind) { Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs), - _ => Instance::new(def_id, substs.substs) + _ => Instance::new(def_id, substs) } } @@ -335,7 +335,7 @@ impl<'tcx> Instance<'tcx> { pub fn fn_once_adapter_instance( tcx: TyCtxt<'tcx>, closure_did: DefId, - substs: ty::ClosureSubsts<'tcx>, + substs: ty::SubstsRef<'tcx>, ) -> Instance<'tcx> { debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, @@ -348,7 +348,7 @@ impl<'tcx> Instance<'tcx> { let self_ty = tcx.mk_closure(closure_did, substs); - let sig = substs.closure_sig(closure_did, tcx); + let sig = substs.as_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()]); diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 6b22ded49f3..6e01e1bf26a 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -674,7 +674,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?, ty::Closure(def_id, ref substs) => { - let tys = substs.upvar_tys(def_id, tcx); + let tys = substs.as_closure().upvar_tys(def_id, tcx); univariant(&tys.map(|ty| self.layout_of(ty)).collect::, _>>()?, &ReprOptions::default(), StructKind::AlwaysSized)? @@ -2147,7 +2147,7 @@ where // Tuples, generators and closures. ty::Closure(def_id, ref substs) => { - substs.upvar_tys(def_id, tcx).nth(i).unwrap() + substs.as_closure().upvar_tys(def_id, tcx).nth(i).unwrap() } ty::Generator(def_id, ref substs, _) => { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d2dc07374ed..cfd859c33c2 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -1111,7 +1111,7 @@ pub enum Predicate<'tcx> { /// No direct syntax. May be thought of as `where T: FnFoo<...>` /// for some substitutions `...` and `T` being a closure type. /// Satisfied (or refuted) once we know the closure's kind. - ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind), + ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind), /// `T1 <: T2` Subtype(PolySubtypePredicate<'tcx>), @@ -1458,7 +1458,7 @@ impl<'tcx> Predicate<'tcx> { WalkTysIter::None } ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => { - WalkTysIter::Types(closure_substs.substs.types()) + WalkTysIter::Types(closure_substs.types()) } ty::Predicate::ConstEvaluatable(_, substs) => { WalkTysIter::Types(substs.types()) diff --git a/src/librustc/ty/outlives.rs b/src/librustc/ty/outlives.rs index 9a2e30f7f45..3ea767d5115 100644 --- a/src/librustc/ty/outlives.rs +++ b/src/librustc/ty/outlives.rs @@ -62,7 +62,7 @@ impl<'tcx> TyCtxt<'tcx> { // projection). match ty.kind { ty::Closure(def_id, ref substs) => { - for upvar_ty in substs.upvar_tys(def_id, *self) { + for upvar_ty in substs.as_closure().upvar_tys(def_id, *self) { self.compute_components(upvar_ty, out); } } diff --git a/src/librustc/ty/print/obsolete.rs b/src/librustc/ty/print/obsolete.rs index d7d43b8203f..21c018d9ee6 100644 --- a/src/librustc/ty/print/obsolete.rs +++ b/src/librustc/ty/print/obsolete.rs @@ -8,7 +8,7 @@ use rustc::hir::def_id::DefId; use rustc::mir::interpret::ConstValue; use rustc::ty::subst::SubstsRef; -use rustc::ty::{self, ClosureSubsts, Const, GeneratorSubsts, Instance, Ty, TyCtxt}; +use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt}; use rustc::{bug, hir}; use std::fmt::Write; use std::iter; @@ -154,8 +154,8 @@ impl DefPathBasedNames<'tcx> { self.push_type_name(sig.output(), output, debug); } } - ty::Generator(def_id, GeneratorSubsts { ref substs }, _) - | ty::Closure(def_id, ClosureSubsts { ref substs }) => { + ty::Generator(def_id, GeneratorSubsts { substs }, _) + | ty::Closure(def_id, substs) => { self.push_def_path(def_id, output); let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id)); let substs = substs.truncate_to(self.tcx, generics); diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index 0adb7562697..ad4be788dae 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -649,7 +649,7 @@ pub trait PrettyPrinter<'tcx>: p!(in_binder(&types)); } ty::Closure(did, substs) => { - let upvar_tys = substs.upvar_tys(did, self.tcx()); + let upvar_tys = substs.as_closure().upvar_tys(did, self.tcx()); p!(write("[closure")); // FIXME(eddyb) should use `def_span`. @@ -689,8 +689,8 @@ pub trait PrettyPrinter<'tcx>: if self.tcx().sess.verbose() { p!(write( " closure_kind_ty={:?} closure_sig_ty={:?}", - substs.closure_kind_ty(did, self.tcx()), - substs.closure_sig_ty(did, self.tcx()) + substs.as_closure().kind(did, self.tcx()), + substs.as_closure().sig_ty(did, self.tcx()) )); } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index 3bd61e34554..5489c6f5d5a 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -442,7 +442,7 @@ pub fn super_relate_tys>( // the (anonymous) type of the same closure expression. So // all of their regions should be equated. let substs = relation.relate(&a_substs, &b_substs)?; - Ok(tcx.mk_closure(a_id, substs)) + Ok(tcx.mk_closure(a_id, &substs)) } (&ty::RawPtr(ref a_mt), &ty::RawPtr(ref b_mt)) => diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index e105c44d09a..3f09bf749ed 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -159,7 +159,7 @@ pub enum TyKind<'tcx> { /// The anonymous type of a closure. Used to represent the type of /// `|a| a`. - Closure(DefId, ClosureSubsts<'tcx>), + Closure(DefId, SubstsRef<'tcx>), /// The anonymous type of a generator. Used to represent the type of /// `|a| yield a`. @@ -305,8 +305,8 @@ static_assert_size!(TyKind<'_>, 24); /// type parameters is similar, but the role of CK and CS are /// different. CK represents the "yield type" and CS represents the /// "return type" of the generator. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, - Debug, RustcEncodable, RustcDecodable, HashStable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, + RustcEncodable, RustcDecodable, HashStable)] pub struct ClosureSubsts<'tcx> { /// Lifetime and type parameters from the enclosing function, /// concatenated with the types of the upvars. @@ -357,7 +357,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 kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).closure_kind_ty } @@ -365,7 +365,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 sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> { self.split(def_id, tcx).closure_sig_ty } @@ -374,7 +374,7 @@ impl<'tcx> ClosureSubsts<'tcx> { /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_kind()`. - pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind { + pub fn kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind { self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap() } @@ -383,8 +383,8 @@ impl<'tcx> ClosureSubsts<'tcx> { /// there are no type variables. /// /// If you have an inference context, use `infcx.closure_sig()`. - pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { - let ty = self.closure_sig_ty(def_id, tcx); + pub fn sig(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> { + let ty = self.sig_ty(def_id, tcx); match ty.kind { ty::FnPtr(sig) => sig, _ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty.kind), @@ -569,7 +569,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { #[derive(Debug, Copy, Clone)] pub enum UpvarSubsts<'tcx> { - Closure(ClosureSubsts<'tcx>), + Closure(SubstsRef<'tcx>), Generator(GeneratorSubsts<'tcx>), } @@ -578,10 +578,10 @@ impl<'tcx> UpvarSubsts<'tcx> { pub fn upvar_tys( self, def_id: DefId, - tcx: TyCtxt<'_>, + tcx: TyCtxt<'tcx>, ) -> impl Iterator> + 'tcx { let upvar_kinds = match self { - UpvarSubsts::Closure(substs) => substs.split(def_id, tcx).upvar_kinds, + UpvarSubsts::Closure(substs) => substs.as_closure().split(def_id, tcx).upvar_kinds, UpvarSubsts::Generator(substs) => substs.split(def_id, tcx).upvar_kinds, }; upvar_kinds.iter().map(|t| { @@ -2148,7 +2148,7 @@ impl<'tcx> TyS<'tcx> { Adt(_, substs) | Opaque(_, substs) => { out.extend(substs.regions()) } - Closure(_, ClosureSubsts { ref substs }) | + Closure(_, ref substs ) | Generator(_, GeneratorSubsts { ref substs }, _) => { out.extend(substs.regions()) } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index e5bee3cfbd0..537192b0a2e 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -5,6 +5,7 @@ use crate::infer::canonical::Canonical; use crate::ty::{self, Lift, List, Ty, TyCtxt, InferConst, ParamConst}; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use crate::mir::interpret::ConstValue; +use crate::ty::sty::ClosureSubsts; use rustc_serialize::{self, Encodable, Encoder, Decodable, Decoder}; use syntax_pos::{Span, DUMMY_SP}; @@ -183,6 +184,16 @@ pub type InternalSubsts<'tcx> = List>; pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>; impl<'a, 'tcx> InternalSubsts<'tcx> { + /// Interpret these substitutions as the substitutions of a closure type. + /// Closure substitutions have a particular structure controlled by the + /// compiler that encodes information like the signature and closure kind; + /// see `ty::ClosureSubsts` struct for more comments. + pub fn as_closure(&'a self) -> ClosureSubsts<'a> { + ClosureSubsts { + substs: self, + } + } + /// Creates a `InternalSubsts` that maps each generic parameter to itself. pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> { Self::for_item(tcx, def_id, |param, _| { diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index c4d8e452441..d0e95a18c59 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -642,12 +642,12 @@ impl<'tcx> TyCtxt<'tcx> { /// wrapped in a binder. pub fn closure_env_ty(self, closure_def_id: DefId, - closure_substs: ty::ClosureSubsts<'tcx>) + closure_substs: SubstsRef<'tcx>) -> Option>> { let closure_ty = self.mk_closure(closure_def_id, closure_substs); let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv); - let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self); + let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self); let closure_kind = closure_kind_ty.to_opt_closure_kind()?; let env_ty = match closure_kind { ty::ClosureKind::Fn => self.mk_imm_ref(self.mk_region(env_region), closure_ty), @@ -1108,7 +1108,9 @@ fn needs_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx> // Structural recursion. ty::Array(ty, _) | ty::Slice(ty) => needs_drop(ty), - ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, tcx).any(needs_drop), + ty::Closure(def_id, ref substs) => { + substs.as_closure().upvar_tys(def_id, tcx).any(needs_drop) + } // Pessimistically assume that all generators will require destructors // as we don't know if a destructor is a noop or not until after the MIR diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 12f0d80cd0e..1895ab83674 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -111,7 +111,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { stack.extend(substs.types().rev()); } ty::Closure(_, ref substs) => { - stack.extend(substs.substs.types().rev()); + stack.extend(substs.types().rev()); } ty::Generator(_, ref substs, _) => { stack.extend(substs.substs.types().rev()); diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 020926e7c8d..ecb075e30b1 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -347,7 +347,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { // anyway, except via auto trait matching (which // only inspects the upvar types). subtys.skip_current_subtree(); // subtree handled by compute_projection - for upvar_ty in substs.upvar_tys(def_id, self.infcx.tcx) { + for upvar_ty in substs.as_closure().upvar_tys(def_id, self.infcx.tcx) { self.compute(upvar_ty); } } diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 544d6794e21..e69f4b6aca1 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -6,7 +6,7 @@ use super::utils::{debug_context, DIB, span_start, get_namespace_for_item, create_DIArray, is_node_local_to_unit}; use super::namespace::mangled_name_of_instance; use super::type_names::compute_debuginfo_type_name; -use super::{CrateDebugContext}; +use super::CrateDebugContext; use crate::abi; use crate::value::Value; use rustc_codegen_ssa::traits::*; @@ -682,7 +682,7 @@ pub fn type_metadata( } ty::Closure(def_id, substs) => { - let upvar_tys : Vec<_> = substs.upvar_tys(def_id, cx.tcx).collect(); + let upvar_tys : Vec<_> = substs.as_closure().upvar_tys(def_id, cx.tcx).collect(); let containing_scope = get_namespace_for_item(cx, def_id); prepare_tuple_metadata(cx, t, diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 2a563e8290e..5787447d623 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -615,7 +615,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( }; let (def_id, upvar_substs) = match closure_layout.ty.kind { - ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)), + ty::Closure(def_id, substs) => (def_id, + UpvarSubsts::Closure(substs)), ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)), _ => bug!("upvar debuginfo with non-closure arg0 type `{}`", closure_layout.ty) }; diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 9b69383b455..6ffa561f3fe 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -201,7 +201,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { match operand.layout.ty.kind { ty::Closure(def_id, substs) => { let instance = Instance::resolve_closure( - bx.cx().tcx(), def_id, substs, ty::ClosureKind::FnOnce); + bx.cx().tcx(), + def_id, + substs, + ty::ClosureKind::FnOnce); OperandValue::Immediate(bx.cx().get_fn(instance)) } _ => { diff --git a/src/librustc_codegen_utils/symbol_names/legacy.rs b/src/librustc_codegen_utils/symbol_names/legacy.rs index a9866c8c0b2..5bcb3b4ceb3 100644 --- a/src/librustc_codegen_utils/symbol_names/legacy.rs +++ b/src/librustc_codegen_utils/symbol_names/legacy.rs @@ -224,7 +224,7 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> { ty::Opaque(def_id, substs) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) | - ty::Closure(def_id, ty::ClosureSubsts { substs }) | + ty::Closure(def_id, substs) | ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => { self.print_def_path(def_id, substs) } diff --git a/src/librustc_codegen_utils/symbol_names/v0.rs b/src/librustc_codegen_utils/symbol_names/v0.rs index a63236305dc..2ad699d7c6f 100644 --- a/src/librustc_codegen_utils/symbol_names/v0.rs +++ b/src/librustc_codegen_utils/symbol_names/v0.rs @@ -414,7 +414,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { ty::Opaque(def_id, substs) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) | - ty::Closure(def_id, ty::ClosureSubsts { substs }) | + ty::Closure(def_id, substs) | ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => { self = self.print_def_path(def_id, substs)?; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index a86bc283ced..49577b56b14 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1437,7 +1437,7 @@ impl EncodeContext<'tcx> { } ty::Closure(def_id, substs) => { - let sig = substs.closure_sig(def_id, self.tcx); + let sig = substs.as_closure().sig(def_id, self.tcx); let data = ClosureData { sig: self.lazy(sig) }; EntryKind::Closure(self.lazy(data)) } diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index bf5bddadd16..431361fa5a8 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -341,7 +341,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { ty::Closure(def_id, closure_substs) if def_id == self.mir_def_id && upvar_field.is_some() => { - let closure_kind_ty = closure_substs.closure_kind_ty(def_id, self.infcx.tcx); + let closure_kind_ty = closure_substs + .as_closure().kind_ty(def_id, self.infcx.tcx); let closure_kind = closure_kind_ty.to_opt_closure_kind(); let capture_description = match closure_kind { Some(ty::ClosureKind::Fn) => { diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index 1e5f613aedc..0e22ead62d1 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -12,7 +12,7 @@ use rustc::mir::{ SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UserTypeProjection, }; use rustc::ty::fold::TypeFoldable; -use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty}; +use rustc::ty::{self, GeneratorSubsts, RegionVid, Ty}; use rustc::ty::subst::SubstsRef; pub(super) fn generate_constraints<'cx, 'tcx>( @@ -98,13 +98,6 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> { self.super_generator_substs(substs); } - /// We sometimes have `closure_substs` within an rvalue, or within a - /// call. Make them live at the location where they appear. - fn visit_closure_substs(&mut self, substs: &ClosureSubsts<'tcx>, location: Location) { - self.add_regular_live_constraint(*substs, location); - self.super_closure_substs(substs); - } - fn visit_statement( &mut self, statement: &Statement<'tcx>, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index a23afd2242c..7362ae9c638 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -875,7 +875,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { if let Some(ty::ReFree(free_region)) = self.to_error_region(fr) { if let ty::BoundRegion::BrEnv = free_region.bound_region { if let DefiningTy::Closure(def_id, substs) = self.universal_regions.defining_ty { - let closure_kind_ty = substs.closure_kind_ty(def_id, infcx.tcx); + let closure_kind_ty = substs.as_closure().kind_ty(def_id, infcx.tcx); return Some(ty::ClosureKind::FnMut) == closure_kind_ty.to_opt_closure_kind(); } } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 8b1ba59c6df..6fb976e0d84 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -300,7 +300,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { }; let region_name = self.synthesize_region_name(renctx); - let closure_kind_ty = substs.closure_kind_ty(def_id, tcx); + let closure_kind_ty = substs.as_closure().kind_ty(def_id, tcx); let note = match closure_kind_ty.to_opt_closure_kind() { Some(ty::ClosureKind::Fn) => { "closure implements `Fn`, so references to captured variables \ diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index 315c369716e..014335711a5 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,5 +1,5 @@ use rustc::ty::subst::SubstsRef; -use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable}; +use rustc::ty::{self, GeneratorSubsts, Ty, TypeFoldable}; use rustc::mir::{Location, Body, Promoted}; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; @@ -96,16 +96,4 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> { debug!("visit_generator_substs: substs={:?}", substs); } - - fn visit_closure_substs(&mut self, substs: &mut ClosureSubsts<'tcx>, location: Location) { - debug!( - "visit_closure_substs(substs={:?}, location={:?})", - substs, - location - ); - - *substs = self.renumber_regions(substs); - - debug!("visit_closure_substs: substs={:?}", substs); - } } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index adc3381a1e7..f55889794c2 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -781,10 +781,10 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { ty::Adt(adt_def, substs) if !adt_def.is_enum() => (&adt_def.variants[VariantIdx::new(0)], substs), ty::Closure(def_id, substs) => { - return match substs.upvar_tys(def_id, tcx).nth(field.index()) { + return match substs.as_closure().upvar_tys(def_id, tcx).nth(field.index()) { Some(ty) => Ok(ty), None => Err(FieldAccessError::OutOfRange { - field_count: substs.upvar_tys(def_id, tcx).count(), + field_count: substs.as_closure().upvar_tys(def_id, tcx).count(), }), } } @@ -1952,10 +1952,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } AggregateKind::Closure(def_id, substs) => { - match substs.upvar_tys(def_id, tcx).nth(field_index) { + match substs.as_closure().upvar_tys(def_id, tcx).nth(field_index) { Some(ty) => Ok(ty), None => Err(FieldAccessError::OutOfRange { - field_count: substs.upvar_tys(def_id, tcx).count(), + field_count: substs.as_closure().upvar_tys(def_id, tcx).count(), }), } } @@ -2068,7 +2068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => { let sig = match op.ty(body, tcx).kind { ty::Closure(def_id, substs) => { - substs.closure_sig_ty(def_id, tcx).fn_sig(tcx) + substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx) } _ => bug!(), }; @@ -2540,7 +2540,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // desugaring. A closure gets desugared to a struct, and // these extra requirements are basically like where // clauses on the struct. - AggregateKind::Closure(def_id, ty::ClosureSubsts { substs }) + AggregateKind::Closure(def_id, substs) | AggregateKind::Generator(def_id, ty::GeneratorSubsts { substs }, _) => { self.prove_closure_bounds(tcx, *def_id, substs, location) } diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index b4470582b71..e3efacff66a 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -19,7 +19,7 @@ use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc::middle::lang_items; use rustc::ty::fold::TypeFoldable; use rustc::ty::subst::{InternalSubsts, SubstsRef, Subst}; -use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty, TyCtxt}; +use rustc::ty::{self, GeneratorSubsts, RegionVid, Ty, TyCtxt}; use rustc::util::nodemap::FxHashMap; use rustc_index::vec::{Idx, IndexVec}; use rustc_errors::DiagnosticBuilder; @@ -85,7 +85,7 @@ pub struct UniversalRegions<'tcx> { pub enum DefiningTy<'tcx> { /// The MIR is a closure. The signature is found via /// `ClosureSubsts::closure_sig_ty`. - Closure(DefId, ty::ClosureSubsts<'tcx>), + Closure(DefId, SubstsRef<'tcx>), /// The MIR is a generator. The signature is that generators take /// no parameters and return the result of @@ -109,7 +109,9 @@ impl<'tcx> DefiningTy<'tcx> { /// match up with the upvar order in the HIR, typesystem, and MIR. pub fn upvar_tys(self, tcx: TyCtxt<'tcx>) -> impl Iterator> + 'tcx { match self { - DefiningTy::Closure(def_id, substs) => Either::Left(substs.upvar_tys(def_id, tcx)), + DefiningTy::Closure(def_id, substs) => Either::Left( + substs.as_closure().upvar_tys(def_id, tcx) + ), DefiningTy::Generator(def_id, substs, _) => { Either::Right(Either::Left(substs.upvar_tys(def_id, tcx))) } @@ -312,7 +314,7 @@ impl<'tcx> UniversalRegions<'tcx> { err.note(&format!( "defining type: {:?} with closure substs {:#?}", def_id, - &substs.substs[..] + &substs[..] )); // FIXME: It'd be nice to print the late-bound regions @@ -546,7 +548,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let fr_substs = match defining_ty { - DefiningTy::Closure(_, ClosureSubsts { ref substs }) + DefiningTy::Closure(_, ref substs) | DefiningTy::Generator(_, GeneratorSubsts { ref substs }, _) => { // In the case of closures, we rely on the fact that // the first N elements in the ClosureSubsts are @@ -582,7 +584,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { match defining_ty { DefiningTy::Closure(def_id, substs) => { assert_eq!(self.mir_def_id, def_id); - let closure_sig = substs.closure_sig_ty(def_id, tcx).fn_sig(tcx); + let closure_sig = substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx); let inputs_and_output = closure_sig.inputs_and_output(); let closure_ty = tcx.closure_env_ty(def_id, substs).unwrap(); ty::Binder::fuse( diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index db314cb5faf..e6f7a042f1c 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -506,7 +506,8 @@ fn make_mirror_unadjusted<'a, 'tcx>( hir::ExprKind::Closure(..) => { let closure_ty = cx.tables().expr_ty(expr); let (def_id, substs, movability) = match closure_ty.kind { - ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs), None), + ty::Closure(def_id, substs) => (def_id, + UpvarSubsts::Closure(substs), None), ty::Generator(def_id, substs, movability) => { (def_id, UpvarSubsts::Generator(substs), Some(movability)) } @@ -1011,7 +1012,7 @@ fn convert_var( }); Expr { ty: closure_ty, - temp_lifetime: temp_lifetime, + temp_lifetime, span: expr.span, kind: ExprKind::Deref { arg: Expr { diff --git a/src/librustc_mir/interpret/intrinsics/type_name.rs b/src/librustc_mir/interpret/intrinsics/type_name.rs index a8b4d65e7d4..dc3b7694c35 100644 --- a/src/librustc_mir/interpret/intrinsics/type_name.rs +++ b/src/librustc_mir/interpret/intrinsics/type_name.rs @@ -67,7 +67,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { | ty::Opaque(def_id, substs) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::UnnormalizedProjection(ty::ProjectionTy { item_def_id: def_id, substs }) - | ty::Closure(def_id, ty::ClosureSubsts { substs }) + | ty::Closure(def_id, substs) | ty::Generator(def_id, ty::GeneratorSubsts { substs }, _) => self.print_def_path(def_id, substs), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 9c58e2aa16c..3ac837dd330 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -581,7 +581,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { match source_ty.kind { ty::Closure(def_id, substs) => { let instance = Instance::resolve_closure( - self.tcx, def_id, substs, ty::ClosureKind::FnOnce); + self.tcx, def_id, + substs, ty::ClosureKind::FnOnce); if should_monomorphize_locally(self.tcx, &instance) { self.output.push(create_fn_mono_item(instance)); } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 7303880602e..d089eafbb07 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -320,7 +320,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - ty::Closure(def_id, substs) => { builder.tuple_like_shim( dest, src, - substs.upvar_tys(def_id, tcx) + substs.as_closure().upvar_tys(def_id, tcx) ) } ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()), diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 37b9398f9cb..bdbf040276d 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -788,7 +788,7 @@ where let ty = self.place_ty(self.place); match ty.kind { ty::Closure(def_id, substs) => { - let tys : Vec<_> = substs.upvar_tys(def_id, self.tcx()).collect(); + let tys : Vec<_> = substs.as_closure().upvar_tys(def_id, self.tcx()).collect(); self.open_drop_for_tuple(&tys) } // Note that `elaborate_drops` only drops the upvars of a generator, diff --git a/src/librustc_traits/chalk_context/program_clauses/builtin.rs b/src/librustc_traits/chalk_context/program_clauses/builtin.rs index 6790f14f69b..13bbe021ccf 100644 --- a/src/librustc_traits/chalk_context/program_clauses/builtin.rs +++ b/src/librustc_traits/chalk_context/program_clauses/builtin.rs @@ -266,7 +266,10 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>( let closure_ty = generic_types::closure(tcx, def_id); let upvar_tys: Vec<_> = match &closure_ty.kind { ty::Closure(_, substs) => { - substs.upvar_tys(def_id, tcx).map(|ty| GenericArg::from(ty)).collect() + substs.as_closure() + .upvar_tys(def_id, tcx) + .map(|ty| GenericArg::from(ty)) + .collect() }, _ => bug!(), }; diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index a36b381bed3..7db1a7413c7 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -193,7 +193,7 @@ fn dtorck_constraint_for_ty<'tcx>( .map(|ty| dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ty.expect_ty())) .collect(), - ty::Closure(def_id, substs) => substs + ty::Closure(def_id, substs) => substs.as_closure() .upvar_tys(def_id, tcx) .map(|ty| dtorck_constraint_for_ty(tcx, span, for_ty, depth + 1, ty)) .collect(), diff --git a/src/librustc_traits/generic_types.rs b/src/librustc_traits/generic_types.rs index e4d15a35137..91ca6415bdc 100644 --- a/src/librustc_traits/generic_types.rs +++ b/src/librustc_traits/generic_types.rs @@ -69,9 +69,7 @@ crate fn fn_def(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> { } crate fn closure(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> { - tcx.mk_closure(def_id, ty::ClosureSubsts { - substs: InternalSubsts::bound_vars_for_item(tcx, def_id), - }) + tcx.mk_closure(def_id, InternalSubsts::bound_vars_for_item(tcx, def_id)) } crate fn generator(tcx: TyCtxt<'tcx>, def_id: DefId) -> Ty<'tcx> { diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 290b87388eb..300b730b5bb 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -7,6 +7,7 @@ use hir::def::Res; use hir::def_id::{DefId, LOCAL_CRATE}; use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; +use rustc::ty::subst::SubstsRef; use rustc::{infer, traits}; use rustc::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_target::spec::abi; @@ -480,7 +481,7 @@ pub struct DeferredCallResolution<'tcx> { adjustments: Vec>, fn_sig: ty::FnSig<'tcx>, closure_def_id: DefId, - closure_substs: ty::ClosureSubsts<'tcx>, + closure_substs: SubstsRef<'tcx>, } impl<'a, 'tcx> DeferredCallResolution<'tcx> { diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 162555cd3ce..03f0860c660 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -132,7 +132,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return self.tcx.mk_generator(expr_def_id, substs, movability); } - let substs = ty::ClosureSubsts { substs }; let closure_type = self.tcx.mk_closure(expr_def_id, substs); debug!( @@ -161,14 +160,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_eqtype( expr.span, sig_fn_ptr_ty, - substs.closure_sig_ty(expr_def_id, self.tcx), + substs.as_closure().sig_ty(expr_def_id, self.tcx), ); if let Some(kind) = opt_kind { self.demand_eqtype( expr.span, kind.to_ty(self.tcx), - substs.closure_kind_ty(expr_def_id, self.tcx), + substs.as_closure().kind_ty(expr_def_id, self.tcx), ); } diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 56962d53a64..3a89cddda23 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -61,7 +61,7 @@ use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::adjustment::{ Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast }; -use rustc::ty::{self, TypeAndMut, Ty, ClosureSubsts}; +use rustc::ty::{self, TypeAndMut, Ty, subst::SubstsRef}; use rustc::ty::fold::TypeFoldable; use rustc::ty::error::TypeError; use rustc::ty::relate::RelateResult; @@ -727,7 +727,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { fn coerce_closure_to_fn(&self, a: Ty<'tcx>, def_id_a: DefId, - substs_a: ClosureSubsts<'tcx>, + substs_a: SubstsRef<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> { //! Attempts to coerce from the type of a non-capturing closure diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 880998ab72e..7380bf7536d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4217,7 +4217,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Closure(def_id, substs) => { // We don't use `closure_sig` to account for malformed closures like // `|_: [_; continue]| {}` and instead we don't suggest anything. - let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx); + let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx); (def_id, match closure_sig_ty.kind { ty::FnPtr(sig) => sig, _ => return false, diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 71ea938a803..3f218e1d9fa 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -96,7 +96,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Extract the type of the closure. let ty = self.node_ty(closure_hir_id); let (closure_def_id, substs) = match ty.kind { - ty::Closure(def_id, substs) => (def_id, UpvarSubsts::Closure(substs)), + ty::Closure(def_id, substs) => ( + def_id, + UpvarSubsts::Closure(substs) + ), ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)), ty::Error => { // #51714: skip analysis when we have already encountered type errors @@ -190,7 +193,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Unify the (as yet unbound) type variable in the closure // substs with the kind we inferred. let inferred_kind = delegate.current_closure_kind; - let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx); + let closure_kind_ty = closure_substs + .as_closure().kind_ty(closure_def_id, self.tcx); self.demand_eqtype(span, inferred_kind.to_ty(self.tcx), closure_kind_ty); // If we have an origin, store it. diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 8c3d6357f0b..d973106058e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -1362,10 +1362,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option, def_id: DefId) -> ty::PolyFnSig<'_> { // the signature of a closure, you should use the // `closure_sig` method on the `ClosureSubsts`: // - // closure_substs.closure_sig(def_id, tcx) + // closure_substs.sig(def_id, tcx) // // or, inside of an inference context, you can use //