Skip to content

Commit 17e1f23

Browse files
authored
Rollup merge of rust-lang#64817 - csmoe:closure, r=nikomatsakis
Replace ClosureSubsts with SubstsRef Addresses rust-lang#42340 part 3 rust-lang#59312 might benefit from this clean up. r? @nikomatsakis
2 parents 314fbf4 + 9b91bef commit 17e1f23

File tree

51 files changed

+151
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+151
-142
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
220220

221221
let ty_msg = match local_visitor.found_ty {
222222
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
223-
let fn_sig = substs.closure_sig(*def_id, self.tcx);
223+
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
224224
let args = closure_args(&fn_sig);
225225
let ret = fn_sig.output().skip_binder().to_string();
226226
format!(" for the closure `fn({}) -> {}`", args, ret)
@@ -255,7 +255,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
255255

256256
let suffix = match local_visitor.found_ty {
257257
Some(ty::TyS { kind: ty::Closure(def_id, substs), .. }) => {
258-
let fn_sig = substs.closure_sig(*def_id, self.tcx);
258+
let fn_sig = substs.as_closure().sig(*def_id, self.tcx);
259259
let ret = fn_sig.output().skip_binder().to_string();
260260

261261
if let Some(ExprKind::Closure(_, decl, body_id, ..)) = local_visitor.found_closure {

src/librustc/infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1504,9 +1504,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15041504
pub fn closure_kind(
15051505
&self,
15061506
closure_def_id: DefId,
1507-
closure_substs: ty::ClosureSubsts<'tcx>,
1507+
closure_substs: SubstsRef<'tcx>,
15081508
) -> Option<ty::ClosureKind> {
1509-
let closure_kind_ty = closure_substs.closure_kind_ty(closure_def_id, self.tcx);
1509+
let closure_kind_ty = closure_substs.as_closure().kind_ty(closure_def_id, self.tcx);
15101510
let closure_kind_ty = self.shallow_resolve(closure_kind_ty);
15111511
closure_kind_ty.to_opt_closure_kind()
15121512
}
@@ -1518,9 +1518,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15181518
pub fn closure_sig(
15191519
&self,
15201520
def_id: DefId,
1521-
substs: ty::ClosureSubsts<'tcx>,
1521+
substs: SubstsRef<'tcx>,
15221522
) -> ty::PolyFnSig<'tcx> {
1523-
let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx);
1523+
let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx);
15241524
let closure_sig_ty = self.shallow_resolve(closure_sig_ty);
15251525
closure_sig_ty.fn_sig(self.tcx)
15261526
}

src/librustc/infer/opaque_types/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,11 @@ where
722722
ty::Closure(def_id, ref substs) => {
723723
// Skip lifetime parameters of the enclosing item(s)
724724

725-
for upvar_ty in substs.upvar_tys(def_id, self.tcx) {
725+
for upvar_ty in substs.as_closure().upvar_tys(def_id, self.tcx) {
726726
upvar_ty.visit_with(self);
727727
}
728728

729-
substs.closure_sig_ty(def_id, self.tcx).visit_with(self);
729+
substs.as_closure().sig_ty(def_id, self.tcx).visit_with(self);
730730
}
731731

732732
ty::Generator(def_id, ref substs, _) => {
@@ -886,7 +886,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
886886

887887
let generics = self.tcx.generics_of(def_id);
888888
let substs =
889-
self.tcx.mk_substs(substs.substs.iter().enumerate().map(|(index, &kind)| {
889+
self.tcx.mk_substs(substs.iter().enumerate().map(|(index, &kind)| {
890890
if index < generics.parent_count {
891891
// Accommodate missing regions in the parent kinds...
892892
self.fold_kind_mapping_missing_regions_to_empty(kind)
@@ -896,7 +896,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
896896
}
897897
}));
898898

899-
self.tcx.mk_closure(def_id, ty::ClosureSubsts { substs })
899+
self.tcx.mk_closure(def_id, substs)
900900
}
901901

902902
ty::Generator(def_id, substs, movability) => {

src/librustc/middle/mem_categorization.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
740740
let ty = self.node_ty(fn_hir_id)?;
741741
let kind = match ty.kind {
742742
ty::Generator(..) => ty::ClosureKind::FnOnce,
743-
ty::Closure(closure_def_id, closure_substs) => {
743+
ty::Closure(closure_def_id, substs) => {
744744
match self.infcx {
745745
// During upvar inference we may not know the
746746
// closure kind, just use the LATTICE_BOTTOM value.
747747
Some(infcx) =>
748-
infcx.closure_kind(closure_def_id, closure_substs)
749-
.unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
748+
infcx.closure_kind(
749+
closure_def_id,
750+
substs
751+
).unwrap_or(ty::ClosureKind::LATTICE_BOTTOM),
750752

751753
None =>
752-
closure_substs.closure_kind(closure_def_id, self.tcx),
754+
substs.as_closure().kind(closure_def_id, self.tcx),
753755
}
754756
}
755757
_ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty),

src/librustc/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::ty::layout::VariantIdx;
1515
use crate::ty::print::{FmtPrinter, Printer};
1616
use crate::ty::subst::{Subst, SubstsRef};
1717
use crate::ty::{
18-
self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt,
18+
self, AdtDef, CanonicalUserTypeAnnotations, GeneratorSubsts, Region, Ty, TyCtxt,
1919
UserTypeAnnotationIndex,
2020
};
2121

@@ -2188,7 +2188,7 @@ pub enum AggregateKind<'tcx> {
21882188
/// active field index would identity the field `c`
21892189
Adt(&'tcx AdtDef, VariantIdx, SubstsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<usize>),
21902190

2191-
Closure(DefId, ClosureSubsts<'tcx>),
2191+
Closure(DefId, SubstsRef<'tcx>),
21922192
Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
21932193
}
21942194

src/librustc/mir/visit.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ty::subst::SubstsRef;
2-
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty};
2+
use crate::ty::{CanonicalUserTypeAnnotation, GeneratorSubsts, Ty};
33
use crate::mir::*;
44
use syntax_pos::Span;
55

@@ -230,12 +230,6 @@ macro_rules! make_mir_visitor {
230230
self.super_substs(substs);
231231
}
232232

233-
fn visit_closure_substs(&mut self,
234-
substs: & $($mutability)? ClosureSubsts<'tcx>,
235-
_: Location) {
236-
self.super_closure_substs(substs);
237-
}
238-
239233
fn visit_generator_substs(&mut self,
240234
substs: & $($mutability)? GeneratorSubsts<'tcx>,
241235
_: Location) {
@@ -627,7 +621,7 @@ macro_rules! make_mir_visitor {
627621
_,
628622
closure_substs
629623
) => {
630-
self.visit_closure_substs(closure_substs, location);
624+
self.visit_substs(closure_substs, location);
631625
}
632626
AggregateKind::Generator(
633627
_,
@@ -856,10 +850,6 @@ macro_rules! make_mir_visitor {
856850
_substs: & $($mutability)? GeneratorSubsts<'tcx>) {
857851
}
858852

859-
fn super_closure_substs(&mut self,
860-
_substs: & $($mutability)? ClosureSubsts<'tcx>) {
861-
}
862-
863853
// Convenience methods
864854

865855
fn visit_location(&mut self, body: & $($mutability)? Body<'tcx>, location: Location) {

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pub struct VtableGeneratorData<'tcx, N> {
619619
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, HashStable)]
620620
pub struct VtableClosureData<'tcx, N> {
621621
pub closure_def_id: DefId,
622-
pub substs: ty::ClosureSubsts<'tcx>,
622+
pub substs: SubstsRef<'tcx>,
623623
/// Nested obligations. This can be non-empty if the closure
624624
/// signature contains associated types.
625625
pub nested: Vec<N>

src/librustc/traits/project.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,8 @@ fn confirm_closure_candidate<'cx, 'tcx>(
13341334
) -> Progress<'tcx> {
13351335
let tcx = selcx.tcx();
13361336
let infcx = selcx.infcx();
1337-
let closure_sig_ty = vtable.substs.closure_sig_ty(vtable.closure_def_id, tcx);
1337+
let closure_sig_ty = vtable.substs
1338+
.as_closure().sig_ty(vtable.closure_def_id, tcx);
13381339
let closure_sig = infcx.shallow_resolve(closure_sig_ty).fn_sig(tcx);
13391340
let Normalized {
13401341
value: closure_sig,

src/librustc/traits/query/dropck_outlives.rs

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
213213
// check if *any* of those are trivial.
214214
ty::Tuple(ref tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t.expect_ty())),
215215
ty::Closure(def_id, ref substs) => substs
216+
.as_closure()
216217
.upvar_tys(def_id, tcx)
217218
.all(|t| trivial_dropck_outlives(tcx, t)),
218219

src/librustc/traits/select.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20512051
"assemble_unboxed_candidates: kind={:?} obligation={:?}",
20522052
kind, obligation
20532053
);
2054-
match self.infcx.closure_kind(closure_def_id, closure_substs) {
2054+
match self.infcx.closure_kind(
2055+
closure_def_id,
2056+
closure_substs
2057+
) {
20552058
Some(closure_kind) => {
20562059
debug!(
20572060
"assemble_unboxed_candidates: closure_kind = {:?}",
@@ -2669,7 +2672,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
26692672
ty::Closure(def_id, substs) => {
26702673
// (*) binder moved here
26712674
Where(ty::Binder::bind(
2672-
substs.upvar_tys(def_id, self.tcx()).collect(),
2675+
substs.as_closure().upvar_tys(def_id, self.tcx()).collect(),
26732676
))
26742677
}
26752678

@@ -2753,7 +2756,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
27532756
tys.iter().map(|k| k.expect_ty()).collect()
27542757
}
27552758

2756-
ty::Closure(def_id, ref substs) => substs.upvar_tys(def_id, self.tcx()).collect(),
2759+
ty::Closure(def_id, ref substs) => substs.as_closure()
2760+
.upvar_tys(def_id, self.tcx())
2761+
.collect(),
27572762

27582763
ty::Generator(def_id, ref substs, _) => {
27592764
let witness = substs.witness(def_id, self.tcx());
@@ -3370,17 +3375,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33703375
)?);
33713376

33723377
// FIXME: chalk
3378+
33733379
if !self.tcx().sess.opts.debugging_opts.chalk {
33743380
obligations.push(Obligation::new(
33753381
obligation.cause.clone(),
33763382
obligation.param_env,
3377-
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
3383+
ty::Predicate::ClosureKind(
3384+
closure_def_id,
3385+
substs,
3386+
kind
3387+
),
33783388
));
33793389
}
33803390

33813391
Ok(VtableClosureData {
33823392
closure_def_id,
3383-
substs: substs.clone(),
3393+
substs: substs,
33843394
nested: obligations,
33853395
})
33863396
}
@@ -3869,7 +3879,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
38693879
&mut self,
38703880
obligation: &TraitObligation<'tcx>,
38713881
closure_def_id: DefId,
3872-
substs: ty::ClosureSubsts<'tcx>,
3882+
substs: SubstsRef<'tcx>,
38733883
) -> ty::PolyTraitRef<'tcx> {
38743884
debug!(
38753885
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::traits;
2929
use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals};
3030
use crate::ty::{self, DefIdTree, Ty, TypeAndMut};
3131
use crate::ty::{TyS, TyKind, List};
32-
use crate::ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
32+
use crate::ty::{AdtKind, AdtDef, GeneratorSubsts, Region, Const};
3333
use crate::ty::{PolyFnSig, InferTy, ParamTy, ProjectionTy, ExistentialPredicate, Predicate};
3434
use crate::ty::RegionKind;
3535
use crate::ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid, ConstVid};
@@ -2502,7 +2502,7 @@ impl<'tcx> TyCtxt<'tcx> {
25022502
}
25032503

25042504
#[inline]
2505-
pub fn mk_closure(self, closure_id: DefId, closure_substs: ClosureSubsts<'tcx>)
2505+
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>)
25062506
-> Ty<'tcx> {
25072507
self.mk_ty(Closure(closure_id, closure_substs))
25082508
}

src/librustc/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl FlagComputation {
106106
&ty::Closure(_, ref substs) => {
107107
self.add_flags(TypeFlags::HAS_TY_CLOSURE);
108108
self.add_flags(TypeFlags::HAS_FREE_LOCAL_NAMES);
109-
self.add_substs(&substs.substs);
109+
self.add_substs(substs);
110110
}
111111

112112
&ty::Bound(debruijn, _) => {

src/librustc/ty/instance.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> Instance<'tcx> {
5959
// Shims currently have type FnPtr. Not sure this should remain.
6060
ty::FnPtr(_) => ty.fn_sig(tcx),
6161
ty::Closure(def_id, substs) => {
62-
let sig = substs.closure_sig(def_id, tcx);
62+
let sig = substs.as_closure().sig(def_id, tcx);
6363

6464
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
6565
sig.map_bound(|sig| tcx.mk_fn_sig(
@@ -315,14 +315,14 @@ impl<'tcx> Instance<'tcx> {
315315
pub fn resolve_closure(
316316
tcx: TyCtxt<'tcx>,
317317
def_id: DefId,
318-
substs: ty::ClosureSubsts<'tcx>,
318+
substs: ty::SubstsRef<'tcx>,
319319
requested_kind: ty::ClosureKind,
320320
) -> Instance<'tcx> {
321-
let actual_kind = substs.closure_kind(def_id, tcx);
321+
let actual_kind = substs.as_closure().kind(def_id, tcx);
322322

323323
match needs_fn_once_adapter_shim(actual_kind, requested_kind) {
324324
Ok(true) => Instance::fn_once_adapter_instance(tcx, def_id, substs),
325-
_ => Instance::new(def_id, substs.substs)
325+
_ => Instance::new(def_id, substs)
326326
}
327327
}
328328

@@ -335,7 +335,7 @@ impl<'tcx> Instance<'tcx> {
335335
pub fn fn_once_adapter_instance(
336336
tcx: TyCtxt<'tcx>,
337337
closure_did: DefId,
338-
substs: ty::ClosureSubsts<'tcx>,
338+
substs: ty::SubstsRef<'tcx>,
339339
) -> Instance<'tcx> {
340340
debug!("fn_once_adapter_shim({:?}, {:?})",
341341
closure_did,
@@ -348,7 +348,7 @@ impl<'tcx> Instance<'tcx> {
348348

349349
let self_ty = tcx.mk_closure(closure_did, substs);
350350

351-
let sig = substs.closure_sig(closure_did, tcx);
351+
let sig = substs.as_closure().sig(closure_did, tcx);
352352
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
353353
assert_eq!(sig.inputs().len(), 1);
354354
let substs = tcx.mk_substs_trait(self_ty, &[sig.inputs()[0].into()]);

src/librustc/ty/layout.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
674674
ty::Generator(def_id, substs, _) => self.generator_layout(ty, def_id, &substs)?,
675675

676676
ty::Closure(def_id, ref substs) => {
677-
let tys = substs.upvar_tys(def_id, tcx);
677+
let tys = substs.as_closure().upvar_tys(def_id, tcx);
678678
univariant(&tys.map(|ty| self.layout_of(ty)).collect::<Result<Vec<_>, _>>()?,
679679
&ReprOptions::default(),
680680
StructKind::AlwaysSized)?
@@ -2147,7 +2147,7 @@ where
21472147

21482148
// Tuples, generators and closures.
21492149
ty::Closure(def_id, ref substs) => {
2150-
substs.upvar_tys(def_id, tcx).nth(i).unwrap()
2150+
substs.as_closure().upvar_tys(def_id, tcx).nth(i).unwrap()
21512151
}
21522152

21532153
ty::Generator(def_id, ref substs, _) => {

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ pub enum Predicate<'tcx> {
11111111
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
11121112
/// for some substitutions `...` and `T` being a closure type.
11131113
/// Satisfied (or refuted) once we know the closure's kind.
1114-
ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind),
1114+
ClosureKind(DefId, SubstsRef<'tcx>, ClosureKind),
11151115

11161116
/// `T1 <: T2`
11171117
Subtype(PolySubtypePredicate<'tcx>),
@@ -1458,7 +1458,7 @@ impl<'tcx> Predicate<'tcx> {
14581458
WalkTysIter::None
14591459
}
14601460
ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => {
1461-
WalkTysIter::Types(closure_substs.substs.types())
1461+
WalkTysIter::Types(closure_substs.types())
14621462
}
14631463
ty::Predicate::ConstEvaluatable(_, substs) => {
14641464
WalkTysIter::Types(substs.types())

src/librustc/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'tcx> TyCtxt<'tcx> {
6262
// projection).
6363
match ty.kind {
6464
ty::Closure(def_id, ref substs) => {
65-
for upvar_ty in substs.upvar_tys(def_id, *self) {
65+
for upvar_ty in substs.as_closure().upvar_tys(def_id, *self) {
6666
self.compute_components(upvar_ty, out);
6767
}
6868
}

src/librustc/ty/print/obsolete.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use rustc::hir::def_id::DefId;
99
use rustc::mir::interpret::ConstValue;
1010
use rustc::ty::subst::SubstsRef;
11-
use rustc::ty::{self, ClosureSubsts, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
11+
use rustc::ty::{self, Const, GeneratorSubsts, Instance, Ty, TyCtxt};
1212
use rustc::{bug, hir};
1313
use std::fmt::Write;
1414
use std::iter;
@@ -154,8 +154,8 @@ impl DefPathBasedNames<'tcx> {
154154
self.push_type_name(sig.output(), output, debug);
155155
}
156156
}
157-
ty::Generator(def_id, GeneratorSubsts { ref substs }, _)
158-
| ty::Closure(def_id, ClosureSubsts { ref substs }) => {
157+
ty::Generator(def_id, GeneratorSubsts { substs }, _)
158+
| ty::Closure(def_id, substs) => {
159159
self.push_def_path(def_id, output);
160160
let generics = self.tcx.generics_of(self.tcx.closure_base_def_id(def_id));
161161
let substs = substs.truncate_to(self.tcx, generics);

0 commit comments

Comments
 (0)