Rollup merge of #64817 - csmoe:closure, r=nikomatsakis

Replace ClosureSubsts with SubstsRef

Addresses https://github.com/rust-lang/rust/issues/42340 part 3
https://github.com/rust-lang/rust/pull/59312 might benefit from this clean up.
r? @nikomatsakis
This commit is contained in:
Mazdak Farrokhzad
2019-10-04 07:24:34 +02:00
committed by GitHub
51 changed files with 151 additions and 142 deletions
@@ -220,7 +220,7 @@ pub fn need_type_info_err(
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 @@ pub fn need_type_info_err(
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 {
+4 -4
View File
@@ -1504,9 +1504,9 @@ pub fn type_is_copy_modulo_regions(
pub fn closure_kind(
&self,
closure_def_id: DefId,
closure_substs: ty::ClosureSubsts<'tcx>,
closure_substs: SubstsRef<'tcx>,
) -> Option<ty::ClosureKind> {
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 @@ pub fn closure_kind(
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)
}
+4 -4
View File
@@ -722,11 +722,11 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
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 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'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 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
}
}));
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
self.tcx.mk_closure(def_id, substs)
}
ty::Generator(def_id, substs, movability) => {
+6 -4
View File
@@ -740,16 +740,18 @@ fn cat_upvar(
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),
+2 -2
View File
@@ -15,7 +15,7 @@
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<UserTypeAnnotationIndex>, Option<usize>),
Closure(DefId, ClosureSubsts<'tcx>),
Closure(DefId, SubstsRef<'tcx>),
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
}
+2 -12
View File
@@ -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 @@ fn visit_substs(&mut self,
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 @@ fn super_rvalue(&mut self,
_,
closure_substs
) => {
self.visit_closure_substs(closure_substs, location);
self.visit_substs(closure_substs, location);
}
AggregateKind::Generator(
_,
@@ -856,10 +850,6 @@ fn super_generator_substs(&mut self,
_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) {
+1 -1
View File
@@ -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<N>
+2 -1
View File
@@ -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,
@@ -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)),
+16 -6
View File
@@ -2051,7 +2051,10 @@ fn assemble_closure_candidates(
"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 @@ fn copy_clone_conditions(
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 @@ fn constituent_types_for_ty(&self, t: Ty<'tcx>) -> Vec<Ty<'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 @@ fn confirm_closure_candidate(
)?);
// 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 @@ fn closure_trait_ref_unnormalized(
&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={:?})",
+2 -2
View File
@@ -29,7 +29,7 @@
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 @@ pub fn mk_projection(self,
}
#[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))
}
+1 -1
View File
@@ -106,7 +106,7 @@ fn add_kind(&mut self, kind: &ty::TyKind<'_>) {
&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, _) => {
+6 -6
View File
@@ -59,7 +59,7 @@ fn fn_sig_noadjust(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'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 @@ pub fn resolve_for_vtable(
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 @@ pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'t
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 @@ pub fn fn_once_adapter_instance(
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()]);
+2 -2
View File
@@ -674,7 +674,7 @@ fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx LayoutDetails, Layou
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::<Result<Vec<_>, _>>()?,
&ReprOptions::default(),
StructKind::AlwaysSized)?
@@ -2147,7 +2147,7 @@ fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout {
// 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, _) => {
+2 -2
View File
@@ -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 @@ pub fn walk_tys(&'a self) -> impl Iterator<Item = Ty<'tcx>> + 'a {
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())
+1 -1
View File
@@ -62,7 +62,7 @@ pub fn push_outlives_components(&self, ty0: Ty<'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);
}
}
+3 -3
View File
@@ -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 @@ pub fn push_type_name(&self, t: Ty<'tcx>, output: &mut String, debug: bool) {
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);
+3 -3
View File
@@ -649,7 +649,7 @@ fn pretty_print_type(
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 @@ fn pretty_print_type(
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())
));
}
+1 -1
View File
@@ -442,7 +442,7 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
// 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)) =>
+12 -12
View File
@@ -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 @@ pub enum TyKind<'tcx> {
/// 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 @@ pub fn upvar_tys(
/// 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 @@ pub fn closure_kind_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'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 @@ pub fn closure_sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'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 @@ pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::ClosureKind {
/// 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 @@ pub fn prefix_tys(self, def_id: DefId, tcx: TyCtxt<'tcx>) -> impl Iterator<Item
#[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<Item = Ty<'tcx>> + '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 @@ pub fn discriminant_for_variant(
Adt(_, substs) | Opaque(_, substs) => {
out.extend(substs.regions())
}
Closure(_, ClosureSubsts { ref substs }) |
Closure(_, ref substs ) |
Generator(_, GeneratorSubsts { ref substs }, _) => {
out.extend(substs.regions())
}
+11
View File
@@ -5,6 +5,7 @@
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 @@ fn decode<D: Decoder>(d: &mut D) -> Result<GenericArg<'tcx>, D::Error> {
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, _| {
+5 -3
View File
@@ -642,12 +642,12 @@ pub fn closure_base_def_id(self, def_id: DefId) -> DefId {
/// wrapped in a binder.
pub fn closure_env_ty(self,
closure_def_id: DefId,
closure_substs: ty::ClosureSubsts<'tcx>)
closure_substs: SubstsRef<'tcx>)
-> Option<ty::Binder<Ty<'tcx>>>
{
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
+1 -1
View File
@@ -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());
+1 -1
View File
@@ -347,7 +347,7 @@ fn compute(&mut self, ty0: Ty<'tcx>) -> bool {
// 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);
}
}
@@ -6,7 +6,7 @@
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,
+2 -1
View File
@@ -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)
};
+4 -1
View File
@@ -201,7 +201,10 @@ pub fn codegen_rvalue_operand(
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))
}
_ => {
@@ -224,7 +224,7 @@ fn print_type(
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)
}
@@ -414,7 +414,7 @@ fn print_type(
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)?;
}
+1 -1
View File
@@ -1437,7 +1437,7 @@ fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'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))
}
+2 -1
View File
@@ -341,7 +341,8 @@ fn report_cannot_move_from_borrowed_content(
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) => {
@@ -12,7 +12,7 @@
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 @@ fn visit_generator_substs(&mut self, substs: &GeneratorSubsts<'tcx>, location: L
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>,
@@ -875,7 +875,7 @@ fn retrieve_closure_constraint_info(
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();
}
}
@@ -300,7 +300,7 @@ fn give_name_from_error_region(
};
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 \
+1 -13
View File
@@ -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 @@ fn visit_generator_substs(&mut self,
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);
}
}
@@ -781,10 +781,10 @@ fn field_ty(
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 @@ fn aggregate_field_ty(
}
}
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 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
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 @@ fn prove_aggregate_predicates(
// 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)
}
@@ -19,7 +19,7 @@
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<Item = Ty<'tcx>> + '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 @@ pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
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 @@ fn compute_indices(
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 @@ fn compute_inputs_and_output(
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(
+3 -2
View File
@@ -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 {
@@ -67,7 +67,7 @@ fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
| 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, &[]),
+2 -1
View File
@@ -581,7 +581,8 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) {
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));
}
+1 -1
View File
@@ -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()),
+1 -1
View File
@@ -788,7 +788,7 @@ fn open_drop(&mut self) -> BasicBlock {
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,
@@ -266,7 +266,10 @@ fn builtin_impl_clause(
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!(),
};
+1 -1
View File
@@ -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(),
+1 -3
View File
@@ -69,9 +69,7 @@
}
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> {
+2 -1
View File
@@ -7,6 +7,7 @@
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<Adjustment<'tcx>>,
fn_sig: ty::FnSig<'tcx>,
closure_def_id: DefId,
closure_substs: ty::ClosureSubsts<'tcx>,
closure_substs: SubstsRef<'tcx>,
}
impl<'a, 'tcx> DeferredCallResolution<'tcx> {
+2 -3
View File
@@ -132,7 +132,6 @@ fn check_closure(
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 @@ fn check_closure(
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),
);
}
+2 -2
View File
@@ -61,7 +61,7 @@
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 @@ fn coerce_from_fn_item(&self,
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
+1 -1
View File
@@ -4217,7 +4217,7 @@ fn suggest_fn_call(
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,
+6 -2
View File
@@ -96,7 +96,10 @@ fn analyze_closure(
// 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 @@ fn analyze_closure(
// 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.
+2 -5
View File
@@ -1362,10 +1362,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option<Ty<
return Some(tcx.typeck_tables_of(def_id).node_type(hir_id));
}
let substs = ty::ClosureSubsts {
substs: InternalSubsts::identity_for_item(tcx, def_id),
};
let substs = InternalSubsts::identity_for_item(tcx, def_id);
tcx.mk_closure(def_id, substs)
}
@@ -1858,7 +1855,7 @@ fn fn_sig(tcx: TyCtxt<'_>, 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
//