remove ClosureSubsts with SubstsRef

This commit is contained in:
csmoe 2019-09-26 16:11:23 +00:00
parent eab060f4da
commit 1f8e1d8aea
20 changed files with 37 additions and 29 deletions

View file

@ -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) => {

View file

@ -745,7 +745,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
// During upvar inference we may not know the
// closure kind, just use the LATTICE_BOTTOM value.
Some(infcx) =>
infcx.closure_kind(closure_def_id, ty::ClosureSubsts::from_ref(closure_substs))
infcx.closure_kind(closure_def_id,
ty::ClosureSubsts::from_ref(closure_substs))
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
None =>

View file

@ -218,7 +218,7 @@ impl<'tcx> Rvalue<'tcx> {
tcx.type_of(def.did).subst(tcx, substs)
}
AggregateKind::Closure(did, substs) => {
tcx.mk_closure(did, substs)
tcx.mk_closure(did, &substs.substs)
}
AggregateKind::Generator(did, substs, movability) => {
tcx.mk_generator(did, substs, movability)

View file

@ -2051,7 +2051,8 @@ 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,
ty::ClosureSubsts::from_ref(closure_substs)) {
Some(closure_kind) => {
debug!(
"assemble_unboxed_candidates: closure_kind = {:?}",
@ -3375,7 +3376,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::Predicate::ClosureKind(closure_def_id, ty::ClosureSubsts::from_ref(substs.clone()), kind),
ty::Predicate::ClosureKind(closure_def_id,
ty::ClosureSubsts::from_ref(substs.clone()), kind),
));
}
@ -3876,7 +3878,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",
obligation, closure_def_id, substs,
);
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
let closure_type = self.infcx.closure_sig(closure_def_id,
ty::ClosureSubsts::from_ref(substs));
debug!(
"closure_trait_ref_unnormalized: closure_type = {:?}",

View file

@ -402,7 +402,7 @@ impl<'a, 'tcx> InternalSubsts<'tcx> {
) -> impl Iterator<Item = Ty<'a>> + 'a {
let SplitClosureSubsts { upvar_kinds, .. } = self.split(def_id, tcx);
upvar_kinds.iter().map(|t| {
if let UnpackedKind::Type(ty) = t.unpack() {
if let GenericArgKind::Type(ty) = t.unpack() {
ty
} else {
bug!("upvar should be type")

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(rustc::ty::ClosureSubsts::from_ref(substs))),
ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
_ => bug!("upvar debuginfo with non-closure arg0 type `{}`", closure_layout.ty)
};

View file

@ -201,7 +201,9 @@ 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,
rustc::ty::ClosureSubsts::from_ref(substs),
ty::ClosureKind::FnOnce);
OperandValue::Immediate(bx.cx().get_fn(instance))
}
_ => {

View file

@ -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)
}

View file

@ -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)?;
}

View file

@ -509,7 +509,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
.replace_free_regions_with_nll_infer_vars(FR, &defining_ty);
match defining_ty.kind {
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id, substs),
ty::Closure(def_id, substs) => DefiningTy::Closure(def_id,
rustc::ty::ClosureSubsts::from_ref(substs)),
ty::Generator(def_id, substs, movability) => {
DefiningTy::Generator(def_id, substs, movability)
}
@ -584,7 +585,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
assert_eq!(self.mir_def_id, def_id);
let closure_sig = substs.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();
let closure_ty = tcx.closure_env_ty(def_id, substs.substs).unwrap();
ty::Binder::fuse(
closure_ty,
inputs_and_output,

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(rustc::ty::ClosureSubsts::from_ref(substs)), None),
ty::Generator(def_id, substs, movability) => {
(def_id, UpvarSubsts::Generator(substs), Some(movability))
}
@ -1002,7 +1003,8 @@ fn convert_var(
let region = cx.tcx.mk_region(region);
let self_expr = if let ty::Closure(_, closure_substs) = closure_ty.kind {
match cx.infcx.closure_kind(closure_def_id, closure_substs).unwrap() {
match cx.infcx.closure_kind(closure_def_id,
rustc::ty::ClosureSubsts::from_ref(closure_substs)).unwrap() {
ty::ClosureKind::Fn => {
let ref_closure_ty = cx.tcx.mk_ref(region,
ty::TypeAndMut {
@ -1011,7 +1013,7 @@ fn convert_var(
});
Expr {
ty: closure_ty,
temp_lifetime: temp_lifetime,
temp_lifetime,
span: expr.span,
kind: ExprKind::Deref {
arg: Expr {

View file

@ -75,7 +75,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let instance = ty::Instance::resolve_closure(
*self.tcx,
def_id,
substs,
rustc::ty::ClosureSubsts::from_ref(substs),
ty::ClosureKind::FnOnce,
);
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));

View file

@ -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, &[]),

View file

@ -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,
rustc::ty::ClosureSubsts::from_ref(substs), ty::ClosureKind::FnOnce);
if should_monomorphize_locally(self.tcx, &instance) {
self.output.push(create_fn_mono_item(instance));
}

View file

@ -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> {

View file

@ -103,6 +103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Check whether this is a call to a closure where we
// haven't yet decided on whether the closure is fn vs
// fnmut vs fnonce. If so, we have to defer further processing.
let substs = rustc::ty::ClosureSubsts::from_ref(substs);
if self.closure_kind(def_id, substs).is_none() {
let closure_ty = self.closure_sig(def_id, substs);
let fn_sig = self

View file

@ -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!(

View file

@ -237,7 +237,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
// Non-capturing closures are coercible to
// function pointers or unsafe function pointers.
// It cannot convert closures that require unsafe.
self.coerce_closure_to_fn(a, def_id_a, substs_a, b)
self.coerce_closure_to_fn(a, def_id_a,
rustc::ty::ClosureSubsts::from_ref(substs_a), b)
}
_ => {
// Otherwise, just use unification rules.

View file

@ -96,7 +96,8 @@ 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(rustc::ty::ClosureSubsts::from_ref(substs))),
ty::Generator(def_id, substs, _) => (def_id, UpvarSubsts::Generator(substs)),
ty::Error => {
// #51714: skip analysis when we have already encountered type errors

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)
}